<?php
require_once 'HTML/Template/IT.php';
require_once('common/session/class-HTTPRequest.php');
require_once('common/util/class-EnvironmentFactory.php');
require_once('common/util/class-Config.php');
⁄**
*
*
*
* @author Darryl Patterson
* @copyright Euro RSCG 4D
*
*⁄
class Module {
⁄**
* Environmentを保持
*
* @var Environment
*⁄
var $env;
⁄**
* Configを保持
*
* @var Config
*⁄
var $config;
⁄**
* 言語ラベルを保持
*
* @var array
*⁄
var $langLabels;
⁄**
* モジュール名。普通はサブクラスのコンストラクタで設定。
*
* @var string
*⁄
var $moduleName;
⁄**
* 要求されたアクションを処理するテンプレート
*
* @var HTML_Template_IT
*⁄
var $tpl;
⁄**
* アクション指定が無い時にモジュールで呼ばれるデフォルトアクション
*
* @var string
*⁄
var $defaultAction;
⁄**
* デバッグ用メッセージのon⁄off。
*
* @var boolean
*⁄
var $debug;
function Module($moduleName = 'Default')
{
$this->config = Config::instance();
$this->debug = false;
$envFactory = new EnvironmentFactory(
$this->config->getEnvironmentClassName());
$this->env = $envFactory->createInstance();
$this->moduleName = $moduleName;
$this->langLabels = array();
$this->defaultAction = 'defaultAction';
$this->loadLang();
$templatePath = $this->config->applicationRoot .
'include⁄tpl⁄' . $this->moduleName;
$this->tpl = new HTML_Template_IT($templatePath);
}
⁄**
* ブラウザのリクエストを処理し、ブラウザにコンテンツを返す。
*
* @return string
* @abstract
*⁄
function getHandledRequest() {}
⁄**
* モジュールで実行するアクションの認証。
* 各モジュールはリクエストを好きなやり方で認証できる。
* 普通はハンドラに呼び出される。
*
* @param string $action
* @return boolean
*⁄
function authenticateAction() {
return true;
}
function loadTemplate($action)
{
$this->tpl->loadTemplatefile($action . '.tpl',true,true);
$this->tpl->setVariable('FORCE', '');
$this->tpl->setVariable('LANG', $this->env->lang);
}
function getTemplate()
{
foreach ($this->langLabels as $key => $label){
$key = 'LANG_' . $key;
$this->tpl->setVariable($key, $label);
}
return $this->tpl->get();
}
function loadLang()
{
$langPath = $this->config->applicationRoot .
'include⁄lang⁄' . $this->env->lang . '.txt';
$langLinesGlobal = file($langPath);
if ($langLinesGlobal === false){
echo 'Error loading global language file.';
exit;
}
$langPath = $this->config->applicationRoot .'include⁄lang⁄' .
$this->moduleName . '⁄' .$this->env->lang . '.txt';
$langLinesModule = file($langPath);
if ($langLinesModule === false){
echo 'Error loading the module\'s ''language file.';
exit;
}
$langLines = array_merge($langLinesGlobal,$langLinesModule);
foreach($langLines as $line){
if (trim($line) == '' ||
substr($line, 0, 1) == '#'){
continue;
}
$tokens = explode('=', $line);
$key = $tokens[0];
array_shift($tokens);
$val = implode('=', $tokens);
$this->langLabels[trim($key)] = trim($val);
}
}
function getLanguageLabel($key)
{
if (isset($this->langLabels[$key])){
return $this->langLabels[$key];
}
return '';
}
}
?>
|
|