* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * @version 1.0.0 */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.plugin.plugin' ); /** * 金魚屋 Smarty プラグイン */ class plgSystemKingyoyaSmarty extends JPlugin { /** * Constructor * * For php4 compatability we must not use the __constructor as a constructor for plugins * because func_get_args ( void ) returns a copy of all passed arguments NOT references. * This causes problems with cross-referencing necessary for the observer design pattern. * * @access protected * @param object $subject The object to observe * @param array $config An array that holds the plugin configuration * @since 1.0 */ function plgSystemKingyoyaSmarty( &$subject, $params ) { parent::__construct($subject, $params); } /** * 初期化後処理 */ function onAfterInitialise() { $smarty_dir = $this->params->get('smarty_dir', 'smarty'); $smarty_path = realpath(JPATH_SITE.DS.$smarty_dir); $smarty_path or $smarty_path = realpath($smarty_dir); if (!$smarty_path) { trigger_error("Smarty dir not exists: {$smarty_dir}", E_USER_WARNING); return; } $smarty_path .= DS; $smarty_class_path = realpath($smarty_path.'Smarty.class.php'); if (!$smarty_class_path) { trigger_error("Smarty class not exists: {$smarty_dir}", E_USER_WARNING); return; } define('SMARTY_DIR', $smarty_path); if ($smarty_core_dir = $this->params->get('smarty_core_dir')) { $smarty_core_path = realpath(JPATH_SITE.DS.$smarty_core_dir); $smarty_core_path or $smarty_core_path = realpath($smarty_core_path); if (!$smarty_core_path) { trigger_error("Smarty core dir not exists: {$smarty_core_dir}", E_USER_WARNING); return; } define('SMARTY_CORE_DIR', $smarty_core_path); } require_once $smarty_class_path; $smarty =& getKingyoyaSmarty(); $keys = array( 'pathes' => array( 'template_dir' ,'compile_dir' ,'config_dir' ,'cache_dir' ) ,'list' => array( 'plugins_dir' ,'secure_dir' ,'trusted_dir' ,'default_modifiers' ) ,'default' => array( 'left_delimiter' ,'right_delimiter' ,'debug_tpl' ,'debugging_ctl' ,'caching' ,'cache_lifetime' ,'cache_handler_func' ,'default_template_handler_func' ,'php_handling' ,'compiler_class' ,'error_reporting' ,'compile_id' ,'default_resource_type' ) ,'boolean' => array( 'debugging' ,'compile_check' ,'force_compile' ,'cache_modified_check' ,'security' ,'request_use_auto_globals' ,'use_sub_dirs' ,'config_overwrite' ,'config_booleanize' ,'config_read_hidden' ,'config_fix_newlines' ) ); /* * 基本設定 */ foreach ($keys['default'] as $key) { $smarty->$key = $this->params->get($key); } /* * 真偽設定 */ foreach ($keys['boolean'] as $key) { $smarty->$key = (boolean) $this->params->get($key); } /* * リスト設定 */ foreach ($keys['list'] as $key) { if ($value = $this->params->get($key)) { $smarty->$key = explode("\n", $this->params->get($key)); } } /* * パス設定 */ foreach ($keys['pathes'] as $key) { $value = $this->params->get($key); $path = realpath(JPATH_SITE.DS.$value); $path or $path = realpath($value); $path and $smarty->$key = $path; } /* * セキュリティ設定 */ if ($value = $this->params->get('security_settings_php_handling')) { $smarty->security_settings['PHP_HANDLING'] = (boolean) $value; } if ($value = $this->params->get('security_settings_if_funcs')) { $smarty->security_settings['IF_FUNCS'] = explode("\n", $value); } if ($value = $this->params->get('security_settings_include_any')) { $smarty->security_settings['INCLUDE_ANY'] = (boolean) $value; } if ($value = $this->params->get('security_settings_modifier_funcs')) { $smarty->security_settings['MODIFIER_FUNCS'] = explode("\n", $value); } if ($value = $this->params->get('security_settings_allow_constants')) { $smarty->security_settings['ALLOW_CONSTANTS'] = (boolean) $value; } /* * その他設定 */ if ($value = $this->params->get('request_vars_order')) { $smarty->request_vars_order = $value; } return; } } /** * Smarty オブジェクトを取得 * @return Smarty */ function & getKingyoyaSmarty() { static $smarty; if ($smarty) return $smarty; $smarty = new Smarty(); return $smarty; }