/**
  *  テンプレートのスケルトンを生成する
  *
  *  @access public
  *  @param  string  $forward_name   テンプレート名
  *  @param  string  $skelton        スケルトンファイル名
  *  @return true|Ethna_Error        true:成功 Ethna_Error:失敗
  */
 function &generate($forward_name, $skelton = null)
 {
     $tpl_dir = $this->ctl->getTemplatedir();
     if ($tpl_dir[strlen($tpl_dir) - 1] != '/') {
         $tpl_dir .= '/';
     }
     $tpl_path = $this->ctl->getDefaultForwardPath($forward_name);
     // entity
     $entity = $tpl_dir . $tpl_path;
     Ethna_Util::mkdir(dirname($entity), 0755);
     // skelton
     if ($skelton === null) {
         $skelton = 'skel.template.tpl';
     }
     // macro
     $macro = array();
     // add '_' for tpl and no user macro for tpl
     $macro['_project_id'] = $this->ctl->getAppId();
     // generate
     if (file_exists($entity)) {
         printf("file [%s] already exists -> skip\n", $entity);
     } else {
         if ($this->_generateFile($skelton, $entity, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $entity);
         } else {
             printf("template file(s) successfully created [%s]\n", $entity);
         }
     }
     $true = true;
     return $true;
 }
 /**
  *  ビューのスケルトンを生成する
  *
  *  @access public
  *  @param  string  $forward_name   ビュー名
  *  @param  string  $skelton        スケルトンファイル名
  *  @return true|Ethna_Error        true:成功 Ethna_Error:失敗
  */
 function &generate($forward_name, $skelton = null, $gateway = GATEWAY_WWW)
 {
     $view_dir = $this->ctl->getViewdir();
     $view_class = $this->ctl->getDefaultViewClass($forward_name, $gateway);
     $view_path = $this->ctl->getDefaultViewPath($forward_name);
     // entity
     $entity = $view_dir . $view_path;
     Ethna_Util::mkdir(dirname($entity), 0755);
     // skelton
     if ($skelton === null) {
         $skelton = 'skel.view.php';
     }
     // macro
     $macro = array();
     $macro['project_id'] = $this->ctl->getAppId();
     $macro['forward_name'] = $forward_name;
     $macro['view_class'] = $view_class;
     $macro['view_path'] = $view_path;
     // user macro
     $user_macro = $this->_getUserMacro();
     $macro = array_merge($macro, $user_macro);
     // generate
     if (file_exists($entity)) {
         printf("file [%s] already exists -> skip\n", $entity);
     } else {
         if ($this->_generateFile($skelton, $entity, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $entity);
         } else {
             printf("view script(s) successfully created [%s]\n", $entity);
         }
     }
     $true = true;
     return $true;
 }
 /**
  * ScaffoldSmartyPlugin を生成する
  * 
  * @access public
  */
 function &generate()
 {
     $app_dir = $this->ctl->getDirectory('app');
     $app_path = ucfirst($this->ctl->getAppId()) . '_ScaffoldSmartyPlugin.php';
     $macro = array();
     $macro['project_id'] = $this->ctl->getAppId();
     $macro['file_path'] = $app_path;
     $user_macro = $this->_getUserMacro();
     $macro = array_merge($macro, $user_macro);
     // ファイル生成
     $filePath = "{$app_dir}/{$app_path}";
     Ethna_Util::mkdir(dirname($filePath), 0755);
     $skelton = "skel.scaffold-smartyPlugin.php";
     if (file_exists($filePath)) {
         printf("file [%s] already exists -> skip\n", $filePath);
     } else {
         if ($this->_generateFile($skelton, $filePath, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $filePath);
         } else {
             printf("action script(s) successfully created [%s]\n", $filePath);
         }
     }
     $true = true;
     return $true;
 }
Exemple #4
0
 /**
  *  Constructor for Ethna_Renderer_Smarty3
  *
  *  @access public
  */
 public function __construct($controller)
 {
     parent::__construct($controller);
     // get renderer config
     $smarty_config = isset($this->config['smarty3']) ? $this->config['smarty3'] : array();
     $this->loadEngine($smarty_config);
     $this->engine = new Smarty();
     // Configurerd by controller
     $template_dir = $controller->getTemplatedir();
     $compile_dir = $controller->getDirectory('template_c');
     $this->setTemplateDir($template_dir);
     $this->compile_dir = $compile_dir;
     $this->engine->template_dir = $template_dir;
     $this->engine->compile_dir = $compile_dir;
     $this->engine->compile_id = md5($this->template_dir);
     if (isset($smarty_config['left_delimiter'])) {
         $this->engine->left_delimiter = $smarty_config['left_delimiter'];
     }
     if (isset($smarty_config['right_delimiter'])) {
         $this->engine->right_delimiter = $smarty_config['right_delimiter'];
     }
     // make compile dir
     if (is_dir($this->engine->compile_dir) === false) {
         Ethna_Util::mkdir($this->engine->compile_dir, 0755);
     }
     $this->engine->inheritance = true;
     $this->engine->plugins_dir = array_merge($controller->getDirectory('plugins'), array(ETHNA_BASE . '/class/Plugin/Smarty', SMARTY_DIR . 'plugins'));
 }
Exemple #5
0
 /**
  *  Ethna_Renderer_Smartyクラスのコンストラクタ
  *
  *  @access public
  */
 public function __construct($controller)
 {
     parent::__construct($controller);
     $this->engine = new Smarty();
     // ディレクトリ関連は Controllerによって実行時に設定
     // TODO: iniファイルによって上書き可にするかは要検討
     $template_dir = $controller->getTemplatedir();
     $compile_dir = $controller->getDirectory('template_c');
     $this->setTemplateDir($template_dir);
     $this->compile_dir = $compile_dir;
     $this->engine->template_dir = $this->template_dir;
     $this->engine->compile_dir = $this->compile_dir;
     $this->engine->compile_id = md5($this->template_dir);
     //  デリミタは Ethna_Config を見る
     $smarty_config = isset($this->config['smarty']) ? $this->config['smarty'] : array();
     if (array_key_exists('left_delimiter', $smarty_config)) {
         $this->engine->left_delimiter = $smarty_config['left_delimiter'];
     }
     if (array_key_exists('right_delimiter', $smarty_config)) {
         $this->engine->right_delimiter = $smarty_config['right_delimiter'];
     }
     // コンパイルディレクトリは必須なので一応がんばってみる
     if (is_dir($this->engine->compile_dir) === false) {
         Ethna_Util::mkdir($this->engine->compile_dir, 0755);
     }
     $this->engine->plugins_dir = array_merge($controller->getDirectory('plugins'), array(ETHNA_BASE . '/class/Plugin/Smarty', SMARTY_DIR . 'plugins'));
 }
Exemple #6
0
 /**
  *  テンプレートのスケルトンを生成する
  *
  *  @access public
  *  @param  string  $forward_name   テンプレート名
  *  @param  string  $skelton        スケルトンファイル名
  *  @param  string  $locale         ロケール名
  *  @param  string  $encoding       エンコーディング
  *  @return true|Ethna_Error        true:成功 Ethna_Error:失敗
  */
 function generate($forward_name, $skelton = null, $locale, $encoding)
 {
     //  ロケールが指定された場合は、それを優先する
     if (!empty($locale)) {
         $this->ctl->setLocale($locale);
     }
     //  ロケール名がディレクトリに含まれていない場合は、
     //  ディレクトリがないためなのでそれを補正
     $tpl_dir = $this->ctl->getTemplatedir();
     $tpl_path = $this->ctl->getDefaultForwardPath($forward_name);
     // entity
     $entity = $tpl_dir . '/' . $tpl_path;
     Ethna_Util::mkdir(dirname($entity), 0755);
     // skelton
     if ($skelton === null) {
         $skelton = 'skel.template.tpl';
     }
     // macro
     $macro = array();
     // add '_' for tpl and no user macro for tpl
     $macro['_project_id'] = $this->ctl->getAppId();
     $macro['client_enc'] = $encoding;
     // generate
     if (file_exists($entity)) {
         printf("file [%s] already exists -> skip\n", $entity);
     } else {
         if ($this->_generateFile($skelton, $entity, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $entity);
         } else {
             printf("template file(s) successfully created [%s]\n", $entity);
         }
     }
     $true = true;
     return $true;
 }
Exemple #7
0
 /**
  *  アプリケーションオブジェクトのスケルトンを生成する
  *
  *  @access public
  *  @param  string  $table_name     テーブル名
  *  @return bool    true:成功 false:失敗
  */
 function generate($table_name)
 {
     $table_id = preg_replace_callback('/_(.)/', function (array $matches) {
         return strtoupper($matches[1]);
     }, ucfirst($table_name));
     $app_dir = $this->ctl->getDirectory('app');
     $app_path = ucfirst($this->ctl->getAppId()) . '_' . $table_id . '.php';
     $macro = array();
     $macro['project_id'] = $this->ctl->getAppId();
     $macro['app_path'] = $app_path;
     $macro['app_object'] = ucfirst($this->ctl->getAppId()) . '_' . $table_id;
     $user_macro = $this->_getUserMacro();
     $macro = array_merge($macro, $user_macro);
     $path = "{$app_dir}/{$app_path}";
     Ethna_Util::mkdir(dirname($path), 0755);
     if (file_exists($path)) {
         printf("file [%s] already exists -> skip\n", $path);
     } else {
         if ($this->_generateFile("skel.app_object.php", $path, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $path);
         } else {
             printf("app-object script(s) successfully created [%s]\n", $path);
         }
     }
 }
 /**
  * ScaffoldActionForm を生成する
  * 
  * @access public
  * @param $model string テーブル名
  * @param $modelDefine array モデル定義
  * @param $formDef array フォーム定義
  */
 function &generate($model, $modelDefine, $formDef)
 {
     $table_id = $this->_getTableId($model);
     $project_id = $this->ctl->getAppId();
     $dir = $this->ctl->getDirectory('action_form');
     if ($dir == null) {
         $dir = $this->ctl->getDirectory('app') . "/action_form/";
     }
     $file = "{$project_id}_{$table_id}_ActionForm.php";
     // Macro
     $macro = array();
     $macro['model'] = $model;
     $macro['modelName'] = $table_id;
     $macro['modelUName'] = strtoupper($table_id);
     $macro['project_id'] = $project_id;
     $macro['column_name_file'] = $this->_getColumnNamePath($table_id);
     $macro['form_define'] = $this->_getActionFormDefine($formDef);
     $user_macro = $this->_getUserMacro();
     $macro = array_merge($macro, $user_macro);
     $skelton = "skel.scaffold-actionform.php";
     // ファイル生成
     $path = "{$dir}{$file}";
     Ethna_Util::mkdir(dirname($path), 0755);
     if (file_exists($path)) {
         printf("file [%s] already exists -> skip\n", $path);
     } else {
         if ($this->_generateFile($skelton, $path, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $path);
         } else {
             printf("action script(s) successfully created [%s]\n", $path);
         }
     }
     $true = true;
     return $true;
 }
 /**
  * ScaffoldAppObject を生成する
  * 
  * @access public
  * @param $table_name string テーブル名
  */
 function &generate($table_name)
 {
     $table_id = $this->_getTableId($table_name);
     $app_dir = $this->ctl->getDirectory('app');
     $app_path = ucfirst($this->ctl->getAppId()) . '_' . $table_id . '.php';
     $baseClass_path = ucfirst($this->ctl->getAppId()) . '_AppBase_AppObject.php';
     // マクロ
     $macro = array();
     $macro['model'] = $table_name;
     $macro['modelName'] = $table_id;
     $macro['modelUName'] = strtoupper($table_id);
     $macro['project_id'] = $this->ctl->getAppId();
     $macro['app_path'] = $app_path;
     $macro['app_object'] = ucfirst($this->ctl->getAppId()) . '_' . $table_id;
     $macro['column_name_file'] = $this->_getColumnNamePath($table_id);
     $macro['base_class_file'] = $baseClass_path;
     $user_macro = $this->_getUserMacro();
     $macro = array_merge($macro, $user_macro);
     // ファイル生成
     $path = "{$app_dir}/{$app_path}";
     Ethna_Util::mkdir(dirname($path), 0755);
     if (file_exists($path)) {
         printf("file [%s] already exists -> skip\n", $path);
     } else {
         if ($this->_generateFile("skel.scaffold-appobject.php", $path, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $path);
         } else {
             printf("app-object script(s) successfully created [%s]\n", $path);
         }
     }
     $true = true;
     return $true;
 }
Exemple #10
0
 /**
  *  Ethna_Renderer_Smartyクラスのコンストラクタ
  *
  *  @access public
  */
 public function __construct($controller)
 {
     parent::__construct($controller);
     // get renderer config
     $smarty_config = $this->config;
     // load template engine
     $this->loadEngine($smarty_config);
     $this->engine = new Smarty();
     // ディレクトリ関連は Controllerによって実行時に設定
     $template_dir = $controller->getTemplatedir();
     $compile_dir = $controller->getDirectory('template_c');
     $this->setTemplateDir($template_dir);
     $this->compile_dir = $compile_dir;
     $this->engine->template_dir = $this->template_dir;
     $this->engine->compile_dir = $this->compile_dir;
     $this->engine->compile_id = md5($this->template_dir);
     // delimiter setting
     $this->engine->left_delimiter = $smarty_config['left_delimiter'];
     $this->engine->right_delimiter = $smarty_config['right_delimiter'];
     // コンパイルディレクトリは必須なので一応がんばってみる
     if (is_dir($this->engine->compile_dir) === false) {
         Ethna_Util::mkdir($this->engine->compile_dir, 0755);
     }
     $this->engine->plugins_dir = array_merge($controller->getDirectory('plugins'), array(ETHNA_BASE . '/class/Plugin/Smarty', SMARTY_DIR . 'plugins'));
 }
 function testCachemanagerLocalfile()
 {
     $ctl =& Ethna_Controller::getInstance();
     $plugin =& $ctl->getPlugin();
     $cm = $plugin->getPlugin('Cachemanager', 'Localfile');
     // 文字列のキャッシュ
     $string_key = 'string_key';
     $string_value = "cache\ncontent";
     $cm->set($string_key, $string_value, mktime(0, 0, 0, 7, 1, 2000));
     $cache_string = $cm->get($string_key);
     $this->assertTrue($cm->isCached($string_key));
     $this->assertEqual(mktime(0, 0, 0, 7, 1, 2000), $cm->getLastModified($string_key));
     $this->assertTrue($string_value, $cache_string);
     // 整数のキャッシュ + namespace
     $int_key = 'int_key';
     $int_value = 777;
     $namespace = 'test';
     $cm->set($int_key, $int_value, mktime(0, 0, 0, 7, 1, 2000), $namespace);
     $cache_int = $cm->get($int_key, mktime(0, 0, 0, 7, 1, 2000), $namespace);
     $this->assertTrue($cm->isCached($int_key, mktime(0, 0, 0, 7, 1, 2000), $namespace));
     $this->assertTrue($int_value, $cache_int);
     // オブジェクトのキャッシュ
     $object_key = 'object_key';
     $object_value =& $cm;
     $cm->set($object_key, $object_value);
     $this->assertTrue($cm->isCached($object_key));
     // キャッシュされたインスタンス
     $cache_object = $cm->get($object_key);
     $this->assertTrue($string_value, $cache_object->get($string_key));
     // キャッシュのクリアをテスト
     $cm->clear($object_key);
     $this->assertFalse($cm->isCached($object_key));
     // キャッシュされていないのに呼び出そうとした場合
     $nocache_key = 'nocache_key';
     $cm->clear($nocache_key);
     $pear_error = $cm->get($nocache_key);
     $this->assertEqual(E_CACHE_NO_VALUE, $pear_error->getCode());
     $this->assertEqual('fopen failed', $pear_error->getMessage());
     // ファイルに読み込み権限がない場合
     Ethna_Util::chmod($cm->_getCacheFile(null, $string_key), 0222);
     $pear_error = $cm->get($string_key);
     $this->assertEqual(E_CACHE_NO_VALUE, $pear_error->getCode());
     $this->assertEqual('fopen failed', $pear_error->getMessage());
     Ethna_Util::chmod($cm->_getCacheFile(null, $string_key), 0666);
     // lifetime切れの場合
     $pear_error = $cm->get($string_key, 1);
     $this->assertEqual(E_CACHE_EXPIRED, $pear_error->getCode());
     $this->assertEqual('fopen failed', $pear_error->getMessage());
     // ディレクトリ名と同じファイルがあってディレクトリが作成できない場合
     $tmp_key = 'tmpkey';
     $tmp_dirname = $cm->_getCacheDir(null, $tmp_key);
     Ethna_Util::mkdir(dirname($tmp_dirname), 0777);
     $tmp_file = fopen($tmp_dirname, 'w');
     fclose($tmp_file);
     $pear_error = $cm->set($tmp_key, $string_value);
     $this->assertEqual(E_USER_WARNING, $pear_error->getCode());
     $this->assertEqual("mkdir({$tmp_dirname}) failed", $pear_error->getMessage());
     $this->rm($cm->backend->getTmpdir());
 }
 /**
  * ScaffoldTemplates を生成する
  * 
  * @access public
  * @param string $baseAction ベースのアクション名
  * @param string  $model モデル名
  * @param array $modelDefine モデル定義
  * @param string $idDefine 主キー名
  * @param array $formDef フォーム定義
  */
 function &generate($baseAction, $model, $modelDefine, $idDefine, $formDef)
 {
     // Template Directory
     $tpl_dir = $this->ctl->getTemplatedir();
     if ($tpl_dir[strlen($tpl_dir) - 1] != '/') {
         $tpl_dir .= '/';
     }
     $table_id = $this->_getTableId($model);
     // Generating Templates
     $templates = array('list' => array('title' => sprintf("Listing {model_name model='%s'}", $table_id), 'template' => 'list', 'headerTag' => $this->_getListHeaderTags($modelDefine, $table_id), 'mainTag' => $this->_getListMainTags($modelDefine, $table_id)), 'read' => array('title' => sprintf("Show {model_name model='%s'}", $table_id), 'template' => 'item', 'itemTag' => $this->_getItemMainTag($modelDefine, $table_id)), 'form_create' => array('title' => sprintf("New {model_name model='%s'}", $table_id), 'template' => 'form', 'formTag' => $this->_getFormMainTag($formDef, null, array($idDefine)), 'action' => $this->_getFullAction($baseAction, 'create_do')), 'form_update' => array('title' => sprintf("Editing {model_name model='%s'}", $table_id), 'template' => 'form', 'formTag' => $this->_getFormMainTag($formDef, null, array($idDefine)), 'action' => $this->_getFullAction($baseAction, 'update_do')), 'delete' => array('title' => sprintf("Are you sure?", $model), 'template' => 'delete', 'itemTag' => $this->_getItemMainTag($modelDefine, $table_id)), '_errorbox' => array('_fileName' => '_errorMessages.tpl.html', 'template' => 'errorMessages'), '_noticebox' => array('_fileName' => '_noticeMessages.tpl.html', 'template' => 'noticeMessages'));
     // Create BoxFilePath
     foreach ($templates as $name => $value) {
         if ($name[0] == '_') {
             $tpl_path = $this->ctl->getDefaultForwardPath($this->_getFullAction($baseAction, 'test'));
             $path = explode("/", $tpl_path);
             $path[count($path) - 1] = $value['_fileName'];
             $templates[$name]['path'] = implode("/", $path);
         }
     }
     // Project OverAll Macro
     $projMacro = array();
     $projMacro['listAction'] = $this->_getFullAction($baseAction, 'index');
     $projMacro['readAction'] = $this->_getFullAction($baseAction, 'read');
     $projMacro['createAction'] = $this->_getFullAction($baseAction, 'create');
     $projMacro['createDoAction'] = $this->_getFullAction($baseAction, 'create_do');
     $projMacro['updateAction'] = $this->_getFullAction($baseAction, 'update');
     $projMacro['updateDoAction'] = $this->_getFullAction($baseAction, 'update_do');
     $projMacro['deleteAction'] = $this->_getFullAction($baseAction, 'delete');
     $projMacro['deleteDoAction'] = $this->_getFullAction($baseAction, 'delete_do');
     $projMacro['errorBoxFile'] = $templates['_errorbox']['path'];
     $projMacro['noticeBoxFile'] = $templates['_noticebox']['path'];
     $projMacro['model'] = $model;
     $projMacro['modelName'] = ucfirst($table_id);
     $projMacro['modelPK'] = $idDefine;
     $projMacro['project_id'] = $this->ctl->getAppId();
     foreach ($templates as $name => $value) {
         $tpl_path = $this->ctl->getDefaultForwardPath($this->_getFullAction($baseAction, $name));
         // FormBox TemplateFile.
         if (isset($value['path'])) {
             $tpl_path = $value['path'];
         }
         $macro = array_merge($value, $projMacro);
         // ファイル生成
         Ethna_Util::mkdir(dirname("{$tpl_dir}/{$tpl_path}"), 0755);
         $skel = "skel.scaffold-template-{$value['template']}.tpl";
         if (file_exists("{$tpl_dir}{$tpl_path}")) {
             printf("file [%s] already exists -> skip\n", "{$tpl_dir}{$tpl_path}");
         } else {
             if ($this->_generateFile($skel, "{$tpl_dir}{$tpl_path}", $macro) == false) {
                 printf("[warning] file creation failed [%s]\n", "{$tpl_dir}{$tpl_path}");
             } else {
                 printf("template file(s) successfully created [%s]\n", "{$tpl_dir}{$tpl_path}");
             }
         }
     }
     $true = true;
     return $true;
 }
/**
 *  smarty function:ユニークIDを生成する(double postチェック用)
 *
 *  sample:
 *  <code>
 *  {uniqid}
 *  </code>
 *  <code>
 *  <input type="hidden" name="uniqid" value="a0f24f75e...e48864d3e">
 *  </code>
 *
 *  @param  string  $type   表示タイプ("get" or "post"−デフォルト="post")
 *  @see    isDuplicatePost
 */
function smarty_function_uniqid($params, &$smarty)
{
    $uniqid = Ethna_Util::getRandom();
    if (isset($params['type']) && $params['type'] == 'get') {
        return "uniqid={$uniqid}";
    } else {
        return "<input type=\"hidden\" name=\"uniqid\" value=\"{$uniqid}\" />\n";
    }
}
 /**
  * ScaffoldViews を生成する
  * 
  * @access public
  * @param $baseAction string ベースのアクション名
  * @param $model string モデル名
  * @param $modelDefine array モデル定義
  * @param $formDef array フォーム定義
  */
 function &generate($baseAction, $model, $modelDefine, $idDefine, $formDef)
 {
     $table_id = $this->_getTableId($model);
     $columnName_path = $this->_getColumnNamePath($table_id);
     // Viewを生成
     $views = array("list" => array('helper' => $this->_getFullAction($baseAction, 'create_do')), "read" => array('helper' => $this->_getFullAction($baseAction, 'create_do')), "form_create" => array('helper' => $this->_getFullAction($baseAction, 'create_do')), "form_update" => array('helper' => $this->_getFullAction($baseAction, 'update_do')), "delete" => array('helper' => $this->_getFullAction($baseAction, 'create_do')));
     foreach ($views as $name => $value) {
         $forward_name = $this->_getFullAction($baseAction, $name);
         $view_dir = $this->ctl->getViewdir();
         $view_class = $this->ctl->getDefaultViewClass($forward_name, false);
         $view_path = $this->ctl->getDefaultViewPath($forward_name, false);
         $macro = $value;
         $macro['model'] = $model;
         $macro['modelName'] = ucfirst($table_id);
         $macro['modelUName'] = strtoupper($table_id);
         $macro['modelPK'] = $idDefine;
         $macro['project_id'] = $this->ctl->getAppId();
         $macro['forward_name'] = $forward_name;
         $macro['view_class'] = $view_class;
         $macro['view_path'] = $view_path;
         $macro['column_name_file'] = $columnName_path;
         $user_macro = $this->_getUserMacro();
         $macro = array_merge($macro, $user_macro);
         Ethna_Util::mkdir(dirname("{$view_dir}/{$view_path}"), 0755);
         if ($name == 'list') {
             $skelton = 'skel.scaffold-view-list.php';
         } else {
             if ($name == 'delete') {
                 $skelton = 'skel.scaffold-view-delete.php';
             } else {
                 if ($name == 'read') {
                     $skelton = 'skel.scaffold-view-item.php';
                 } else {
                     if ($name == 'form_create') {
                         $skelton = 'skel.scaffold-view-formCreate.php';
                     } else {
                         if ($name == 'form_update') {
                             $skelton = 'skel.scaffold-view-formUpdate.php';
                         }
                     }
                 }
             }
         }
         if (file_exists("{$view_dir}{$view_path}")) {
             printf("file [%s] already exists -> skip\n", "{$view_dir}{$view_path}");
         } else {
             if ($this->_generateFile($skelton, "{$view_dir}{$view_path}", $macro) == false) {
                 printf("[warning] file creation failed [%s]\n", "{$view_dir}{$view_path}");
             } else {
                 printf("view script(s) successfully created [%s]\n", "{$view_dir}{$view_path}");
             }
         }
     }
     $true = true;
     return $true;
 }
 function testIsAbsolute()
 {
     $absolute_paths = array('/root', '/home/user/giza');
     $invalid_params = array('', false, true, '0x1');
     foreach ($absolute_paths as $path) {
         $this->assertTrue(Ethna_Util::isAbsolute($path));
     }
     foreach ($invalid_params as $path) {
         $this->assertFalse(Ethna_Util::isAbsolute($path));
     }
 }
Exemple #16
0
 /**
  *  preprocess before forwarding.
  *
  *  @access public
  */
 function preforward()
 {
     parent::preforward();
     $cookie_path = str_replace(rtrim($_SERVER['DOCUMENT_ROOT'], '/'), '', $this->af->get('xoops_root_path'));
     !$cookie_path and $cookie_path = '/';
     $xoops_url = sprintf('http://%s%s', $_SERVER['SERVER_NAME'], $cookie_path);
     $this->af->setApp('xoops_cookie_path', $cookie_path);
     $this->af->setApp('xoops_url', $xoops_url);
     $this->af->setApp('prefix', Ethna_Util::getRandom(6));
     $this->af->setApp('salt', Ethna_Util::getRandom(8));
 }
 function perform()
 {
     if (!is_writable($this->config->get('data_dir'))) {
         $this->ae->add('error', $this->config->get('data_dir') . 'に書き込み権限がありません');
         return 'error';
     }
     $fl =& $this->backend->getManager('FileList');
     $file_list =& $fl->scandir($this->config->get('data_dir'));
     $files = count($file_list);
     if ($files === 0) {
         $id = 1;
     } else {
         if ($files >= $this->config->get('project_limit')) {
             $this->ae->add('error', 'これ以上フォームを追加できません');
             return 'project';
         }
         list($id) = sscanf($file_list[0], '%03d.cgi');
         ++$id;
     }
     $data_file = sprintf('%03d.cgi', $id);
     $data_file_path = $this->config->get('data_dir') . $data_file;
     $name = $this->af->get('name');
     $file = $this->af->get('file');
     if ($file === '') {
         $file = Ethna_Util::getRandom(6);
     }
     if ($file !== basename($file, $this->config->get('mobile_suffix'))) {
         $this->ae->add('error', $this->config->get('mobile_suffix') . 'は予約語につき変更して下さい');
         return 'project';
     }
     $file_p = $this->config->get('publish_dir') . $file . '.php';
     $file_m = $this->config->get('publish_dir') . $file . $this->config->get('mobile_suffix') . '.php';
     if (is_file($file_p) || is_file($file_m)) {
         $this->ae->add('error', $file . 'は使用中につき変更して下さい');
         return 'project';
     }
     $data =& $this->backend->getManager('Data');
     $data->load($data_file_path);
     $data->set('file', $file);
     $data->set('name', $name);
     $data->set('mailto', '');
     $data->set('body', '先にテンプレートを作成して下さい。');
     $data->set('receipt', '先にテンプレートを作成して下さい。');
     $data->set('attr', array());
     if (!$data->write()) {
         $this->ae->add('error', $data_file_path . 'に書き込めませんでした');
         return 'error';
     }
     array_unshift($file_list, $data_file);
     $this->af->clearFormVars();
     return 'project';
 }
Exemple #18
0
 /**
  * @test
  */
 public function checkMailAddressInvalid()
 {
     // @がない
     $this->assertFalse(Ethna_Util::checkMailAddress('hogefuga.net'));
     // @の前に文字がない
     $this->assertFalse(Ethna_Util::checkMailAddress('@hogefuga.net'));
     // @の後に文字がない
     $this->assertFalse(Ethna_Util::checkMailAddress('hogefuga.net@'));
     // 先頭文字が許されていない
     $this->assertFalse(Ethna_Util::checkMailAddress('*****@*****.**'));
     // 末尾文字が不正
     $this->assertFalse(Ethna_Util::checkMailAddress('hoge@fuga.net.'));
 }
Exemple #19
0
 /**
  *  アクションのスケルトンを生成する
  *
  *  @access public
  *  @param  string  $action_name    アクション名
  *  @param  string  $skelton        スケルトンファイル名
  *  @param  int     $gateway        ゲートウェイ
  *  @return true|Ethna_Error        true:成功 Ethna_Error:失敗
  */
 function generate($action_name, $skelton = null, $gateway = GATEWAY_WWW)
 {
     $action_dir = $this->ctl->getActiondir($gateway);
     $action_class = $this->ctl->getDefaultActionClass($action_name, $gateway);
     $action_form = $this->ctl->getDefaultFormClass($action_name, $gateway);
     $action_path = $this->ctl->getDefaultActionPath($action_name);
     // entity
     $entity = $action_dir . $action_path;
     Ethna_Util::mkdir(dirname($entity), 0755);
     // skelton
     if ($skelton === null) {
         switch ($gateway) {
             case GATEWAY_WWW:
                 $skelton = "skel.action.php";
                 break;
             case GATEWAY_CLI:
                 $skelton = "skel.action_cli.php";
                 break;
             case GATEWAY_XMLRPC:
                 $skelton = "skel.action_xmlrpc.php";
                 break;
             default:
                 $err = Ethna::raiseError('unknown gateway.');
                 return $err;
         }
     }
     // macro
     $macro = array();
     $macro['project_id'] = $this->ctl->getAppId();
     $macro['action_name'] = $action_name;
     $macro['action_class'] = $action_class;
     $macro['action_form'] = $action_form;
     $macro['action_path'] = $action_path;
     // user macro
     $user_macro = $this->_getUserMacro();
     $macro = array_merge($macro, $user_macro);
     // generate
     if (file_exists($entity)) {
         printf("file [%s] already exists -> skip\n", $entity);
     } else {
         if ($this->_generateFile($skelton, $entity, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $entity);
         } else {
             printf("action script(s) successfully created [%s]\n", $entity);
         }
     }
     $true = true;
     return $true;
 }
 /**
  *	CRCFIDの初期化と設定を行う。セッション開始されてなければならない
  *
  *	@access	public
  *	@access	public
  *	@return	bool	true:成功 false:失敗
  */
 function setCSRF()
 {
     $c =& Ethna_Controller::getInstance();
     $session = $c->getSession();
     if (!$session->isStart(true)) {
         return false;
     }
     if (is_Null($session->get('__CSRF__'))) {
         $session->set('__CSRF__', Ethna_Util::getRandom());
     }
     $csrfid = $session->get('__CSRF__');
     $form = $c->getActionForm();
     $form->setApp('csrfid', $csrfid);
     return true;
 }
 function testGetEra()
 {
     unset($GLOBALS['_Ethna_controller']);
     $tmp_ctl =& new Ethna_Controller();
     //  昭和63年
     $last_showa_t = mktime(0, 0, 0, 12, 31, 1988);
     $r = Ethna_Util::getEra($last_showa_t);
     $this->assertEqual('昭和', $r[0]);
     $this->assertEqual(63, $r[1]);
     //  平成元年
     $first_heisei_t = mktime(0, 0, 0, 1, 1, 1989);
     $r = Ethna_Util::getEra($first_heisei_t);
     $this->assertEqual('平成', $r[0]);
     $this->assertEqual(1, $r[1]);
 }
Exemple #22
0
 public function testGetEra()
 {
     unset($GLOBALS['_Ethna_controller']);
     // NOTE(chobie): Ethna_Utilは内部的にControllerを使う
     $controller = new Ethna_Controller_Dummy();
     //  昭和63年
     $last_showa_t = mktime(0, 0, 0, 12, 31, 1988);
     $r = Ethna_Util::getEra($last_showa_t);
     $this->assertEquals('昭和', $r[0]);
     $this->assertEquals(63, $r[1]);
     //  平成元年
     $first_heisei_t = mktime(0, 0, 0, 1, 1, 1989);
     $r = Ethna_Util::getEra($first_heisei_t);
     $this->assertEquals('平成', $r[0]);
     $this->assertEquals(1, $r[1]);
 }
 /**
  *  プラグインを生成する
  *
  *  @access public
  *  @param  string  $type       プラグインの$type
  *  @param  string  $name       プラグインの$name
  *  @param  bool    $overwrite  上書きオプション
  *  @return bool    true:成功 false:失敗
  */
 function generate($type, $name, $overwrite = false)
 {
     $appid = $this->ctl->getAppId();
     $plugin =& $this->ctl->getPlugin();
     list($class, $plugin_dir, $plugin_path) = $plugin->getPluginNaming($type, $name, $appid);
     $macro = array();
     $macro['project_id'] = $appid;
     $macro['application_id'] = $appid;
     $user_macro = $this->_getUserMacro();
     $macro = array_merge($macro, $user_macro);
     Ethna_Util::mkdir(dirname("{$plugin_dir}/{$plugin_path}"), 0755);
     if ($this->_generateFile("skel.plugin.{$type}_{$name}.php", "{$plugin_dir}/{$plugin_path}", $macro, $overwrite) == false) {
         printf("[warning] file creation failed [%s]\n", "{$plugin_dir}/{$plugin_path}");
     } else {
         printf("plugin script(s) successfully created [%s]\n", "{$plugin_dir}/{$plugin_path}");
     }
 }
 /**
  *  Ethna_Renderer_Smartyクラスのコンストラクタ
  *
  *  @access public
  */
 function Ethna_Renderer_Smarty(&$controller)
 {
     parent::Ethna_Renderer($controller);
     $this->engine =& new Smarty();
     $template_dir = $controller->getTemplatedir();
     $compile_dir = $controller->getDirectory('template_c');
     $this->setTemplateDir($template_dir);
     $this->compile_dir = $compile_dir;
     $this->engine->template_dir = $this->template_dir;
     $this->engine->compile_dir = $this->compile_dir;
     $this->engine->compile_id = md5($this->template_dir);
     // 一応がんばってみる
     if (is_dir($this->engine->compile_dir) === false) {
         Ethna_Util::mkdir($this->engine->compile_dir, 0755);
     }
     $this->engine->plugins_dir = array_merge($controller->getDirectory('plugins'), array(ETHNA_BASE . '/class/Plugin/Smarty', SMARTY_DIR . 'plugins'));
 }
Exemple #25
0
 /**
  *  アクション用テストのスケルトンを生成する
  *  (現在のところ GATEWAY_WWW のみ対応)
  *
  *  @access public
  *  @param  string  $action_name    アクション名
  *  @param  string  $skelton        スケルトンファイル名
  *  @param  int     $gateway        ゲートウェイ
  *  @return true|Ethna_Error        true:成功 Ethna_Error:失敗
  */
 function &generate($action_name, $skelton = null, $gateway = GATEWAY_WWW)
 {
     $action_dir = $this->ctl->getActiondir($gateway);
     $action_class = $this->ctl->getDefaultActionClass($action_name, $gateway);
     $action_form = $this->ctl->getDefaultFormClass($action_name, $gateway);
     $action_path = $this->ctl->getDefaultActionPath($action_name . 'Test');
     // entity
     $entity = $action_dir . $action_path;
     Ethna_Util::mkdir(dirname($entity), 0755);
     // skelton
     if ($skelton === null) {
         $skelton = 'skel.action_test.php';
     }
     // macro
     $macro = array();
     $macro['project_id'] = $this->ctl->getAppId();
     $macro['action_name'] = $action_name;
     $macro['action_class'] = $action_class;
     $macro['action_form'] = $action_form;
     $macro['action_path'] = $action_path;
     // user macro
     $user_macro = $this->_getUserMacro();
     $macro = array_merge($macro, $user_macro);
     // original action script existence check.
     $original_action_path = $this->ctl->getDefaultActionPath($action_name);
     $original_action_entity = $action_dir . $original_action_path;
     if (!file_exists($original_action_entity)) {
         printf("\n");
         printf("[!!!!warning!!!!] original action script was not found.\n");
         printf("[!!!!warning!!!!] You must generate it by the following command :\n");
         printf("[!!!!warning!!!!] ethna add-action %s\n\n", $action_name);
     }
     // generate
     if (file_exists($entity)) {
         printf("file [%s] already exists -> skip\n", $entity);
     } else {
         if ($this->_generateFile($skelton, $entity, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $entity);
         } else {
             printf("action test(s) successfully created [%s]\n", $entity);
         }
     }
     $true = true;
     return $true;
 }
Exemple #26
0
 /**
  *  clear cache files.
  *
  *  @access public
  *  @todo   implement Ethna_Renderer::clear_cache();
  *  @todo   implement Ethna_Plugin_Cachemanager::clear_cache();
  *  @todo   avoid echo, printf
  */
 function perform()
 {
     $r = $this->_getopt(array('basedir=', 'any-tmp-files', 'smarty', 'pear', 'cachemanager'));
     if (Ethna::isError($r)) {
         return $r;
     }
     list($args, ) = $r;
     $basedir = isset($args['basedir']) ? realpath(end($args['basedir'])) : getcwd();
     $controller = Ethna_Handle::getAppController($basedir);
     if (Ethna::isError($controller)) {
         return $controller;
     }
     $tmp_dir = $controller->getDirectory('tmp');
     if (isset($args['smarty']) || isset($args['any-tmp-files'])) {
         echo "cleaning smarty caches, compiled templates...";
         $renderer = $controller->getRenderer();
         if (strtolower(get_class($renderer)) == "ethna_renderer_smarty") {
             $renderer->getEngine()->clear_all_cache();
             $renderer->getEngine()->clear_compiled_tpl();
         }
         echo " done\n";
     }
     if (isset($args['cachemanager']) || isset($args['any-tmp-files'])) {
         echo "cleaning Ethna_Plugin_Cachemanager caches...";
         $cache_dir = sprintf("%s/cache", $tmp_dir);
         Ethna_Util::purgeDir($cache_dir);
         echo " done\n";
     }
     if (isset($args['any-tmp-files'])) {
         echo "cleaning tmp dirs...";
         // purge only entries in tmp.
         if ($dh = opendir($tmp_dir)) {
             while (($entry = readdir($dh)) !== false) {
                 if ($entry === '.' || $entry === '..') {
                     continue;
                 }
                 Ethna_Util::purgeDir("{$tmp_dir}/{$entry}");
             }
             closedir($dh);
         }
         echo " done\n";
     }
     return true;
 }
Exemple #27
0
 /**
  *  Ethna_Renderer_Smartyクラスのコンストラクタ
  *
  *  @access public
  */
 public function __construct(string $template_dir, array $option)
 {
     parent::__construct($template_dir, $option);
     $this->engine = new Smarty();
     // ディレクトリ関連は Kernelによって実行時に設定
     $compile_dir = $option['template_c'];
     $this->compile_dir = $compile_dir;
     $this->engine->template_dir = $this->template_dir;
     $this->engine->compile_dir = $this->compile_dir;
     $this->engine->compile_id = md5($this->template_dir);
     // delimiter setting
     $this->engine->left_delimiter = $this->config['left_delimiter'];
     $this->engine->right_delimiter = $this->config['right_delimiter'];
     // コンパイルディレクトリは必須なので一応がんばってみる
     if (is_dir($this->engine->compile_dir) === false) {
         Ethna_Util::mkdir($this->engine->compile_dir, 0755);
     }
     $this->engine->plugins_dir = array_merge($option['plugins'], array(ETHNA_BASE . '/src/Plugin/Smarty', SMARTY_DIR . 'plugins'));
 }
 /**
  * ScaffoldColumnDefine を生成する
  * 
  * @access public
  * @param string $model モデル名
  * @param array $modelDefine モデル定義
  */
 function &generate($model, $modelDefine)
 {
     $table_id = $this->_getTableId($model);
     $file = ucfirst($this->ctl->getAppId()) . '_' . $table_id . '_ColumnName.php';
     // Directory
     $dir = $this->ctl->getDirectory('column_name');
     if ($dir == null) {
         $dir = $this->ctl->getDirectory('app') . "/column_name/";
     }
     // ModelName
     $modelUName = strtoupper($table_id);
     $modelName = ucfirst(strtolower($table_id));
     // ColumnName
     foreach ($modelDefine as $name => $def) {
         $columnUName = strtoupper($name);
         $columnName = ucfirst(strtolower($name));
         $columnDefine[] = "define('SCAFFOLD_COLUMN_NAME_{$modelUName}_{$columnUName}', \"{$columnName}\");";
     }
     // Macro Setting
     $macro = array();
     $macro['modelNameDefine'] = "define('SCAFFOLD_MODEL_NAME_{$modelUName}', \"{$modelName}\");";
     $macro['columnNameDefine'] = implode("\n", $columnDefine);
     $macro['model'] = $model;
     $macro['project_id'] = $this->ctl->getAppId();
     $macro['app_path'] = $file;
     $macro = array_merge($macro, $this->_getUserMacro());
     // Creating File
     $skelton = "skel.scaffold-ColumnNameDefine.php";
     $path = "{$dir}{$file}";
     Ethna_Util::mkdir(dirname($path), 0755);
     if (file_exists($path)) {
         printf("file [%s] already exists -> skip\n", $path);
     } else {
         if ($this->_generateFile($skelton, $path, $macro) == false) {
             printf("[warning] file creation failed [%s]\n", $path);
         } else {
             printf("ColumnName script(s) successfully created [%s]\n", $path);
         }
     }
     $true = true;
     return $true;
 }
Exemple #29
0
 /**
  *  Ethna_Renderer_Rhacoクラスのコンストラクタ
  *
  *  @access public
  */
 public function __construct($controller)
 {
     parent::__construct($controller);
     $this->template_dir = $controller->getTemplatedir() . '/';
     $this->compile_dir = $controller->getDirectory('template_c');
     Rhaco::constant('TEMPLATE_PATH', $this->template_dir);
     $this->engine = new TemplateParser_Ethna();
     /*
             $this->setTemplateDir($template_dir);
             $this->compile_dir = $compile_dir;
     */
     $this->engine->template_dir = $this->template_dir;
     $this->engine->compile_dir = $this->compile_dir;
     $this->engine->compile_id = md5($this->template_dir);
     // 一応がんばってみる
     if (is_dir($this->engine->compile_dir) === false) {
         Ethna_Util::mkdir($this->engine->compile_dir, 0755);
     }
     $this->_setDefaultPlugin();
 }
Exemple #30
0
 /**
  *  preprocess before forwarding.
  *
  *  @access public
  */
 public function preforward()
 {
     $start = $this->af->get('start');
     error_log('start:' . $start);
     if ($start === NULL) {
         $start = 0;
     }
     if ($start < 0) {
         $start = 0;
     }
     $count = 5;
     $bm = new BoardManager();
     $um = new UserManager();
     $boardlist = $bm->boardlist($this->backend);
     krsort($boardlist);
     $total = count($boardlist);
     $display_posts = array();
     for ($i = $start; $i < $start + $count && $i < $total; $i++) {
         $cur = current(array_slice($boardlist, $i, 1, true));
         array_push($display_posts, $bm->addUrl($cur));
     }
     if ($start > 0) {
         $this->af->setApp('hasprev', true);
         $this->af->setApp('prev', $start - $count);
     } else {
         $this->af->setApp('hasprev', false);
     }
     if ($start + $count < $total) {
         $this->af->setApp('hasnext', true);
         $this->af->setApp('next', $start + $count);
         $this->af->setApp('last', (ceil($total / $count) - 1) * $count);
     } else {
         $this->af->setApp('hasnext', false);
     }
     $this->af->setApp('posts', $display_posts);
     $this->af->setApp('link', '/?action_board=true');
     $this->af->setApp('count', $count);
     $this->af->setApp('current', $start);
     $this->af->setApp('pager', Ethna_Util::getDirectLinkList($total, $start, $count));
     return 'board';
 }