NobuNobu
nobun****@users*****
2006年 1月 27日 (金) 23:38:08 JST
Index: xoops2jp/html/class/XCube_EventManager.class.php diff -u xoops2jp/html/class/XCube_EventManager.class.php:1.1.2.5 xoops2jp/html/class/XCube_EventManager.class.php:1.1.2.6 --- xoops2jp/html/class/XCube_EventManager.class.php:1.1.2.5 Thu Nov 17 14:38:15 2005 +++ xoops2jp/html/class/XCube_EventManager.class.php Fri Jan 27 23:38:08 2006 @@ -1,126 +1,160 @@ -<?php - -require_once XOOPS_ROOT_PATH."/class/XCube_Event.class.php"; - -/** - * This class manages plural events. - * This class supports substitute registration for speedup. - */ -class XCube_EventManager -{ - var $_mEvents=array(); - - var $_mReserveEventList=array(); - var $_mRegistedFlags=array(); - var $_mProxyRegisters=array(); - - function XCube_EventManager() - { - } - - function prepare() - { - } - - function add($eventName,&$delegate) - { - if(!isset($this->_mEvents[$eventName])) - $this->_mEvents[$eventName] = new XCube_Event($eventName); - - $this->_mEvents[$eventName]->add($delegate); - } - - function setAnchorDelegate($eventName,&$delegate) - { - if(!isset($this->_mEvents[$eventName])) - $this->_mEvents[$eventName] = new XCube_Event($eventName); - - $this->_mEvents[$eventName]->setAnchorDelegate($delegate); - } - - function replaceEvent($eventName,&$eventHandler) - { - if(isset($this->_mEvents[$eventName])) { - if(strtolower(get_class($this->_mEvents[$eventName]))=="xcube_event") { - // - // TODO : omg! We access private property. - // - foreach($this->_mEvents[$eventName]->_mDelegates as $delegate) { - $eventHandler->_mDelegates[]=$delegate; - unset($delegate); - } - unset($this->_mEvents[$eventName]); - $this->_mEvents[$eventName]=&$eventHandler; - } - } - else { - $this->_mEvents[$eventName]=&$eventHandler; - } - } - - function raiseEvent($eventName,&$sender,&$eventArgs) - { - if(isset($this->_mReserveEventList[$eventName])&&$this->_mRegistedFlags[$eventName]==false) { - $this->_processProxyRegist($eventName); - } - - if(isset($this->_mEvents[$eventName])) { - $this->_mEvents[$eventName]->raiseEvent($sender,$eventArgs); - - return true; - } - return false; - } - - function addProxyRegister(&$register) - { - $i=count($this->_mProxyRegisters)+1; - $this->_mProxyRegisters[$i]=&$register; - - $list=$register->getEventNameList(); - foreach($list as $name) { - if(!isset($this->_mReserveEventList[$name])) { - $this->_mReserveEventList[$name]=array(); - $this->_mRegistedFlags[$name]=false; - } - - $this->_mReserveEventList[$name][]=$i; - } - } - - function _processProxyRegist($eventName) - { - $this->_mRegistedFlags[$eventName]=true; - foreach($this->_mReserveEventList[$eventName] as $i) { - $this->add($eventName,$this->_mProxyRegisters[$i]->createDelegate($eventName)); - } - } -} - -/** - * This class tells a manager about a list of the event that the Delegate which this class can create. - * And this class creates Delegate when the manager needs Delegate. - * Developer does not need to use this by all means. - */ -class XCube_EventProxyRegister -{ - /** - * @return array - */ - function getEventNameList() - { - } - - function &createDelegate($name) - { - $ret =null; - $methodName=str_replace(".","_","create".ucfirst($name)."Delegate"); - if(method_exists($this,$methodName)) { - $ret=&call_user_func(array($this,$methodName)); - } - - return $ret; - } -} - +<?php + +require_once XOOPS_ROOT_PATH."/class/XCube_Event.class.php"; + +/** + * This class manages plural events. + * This class supports substitute registration for speedup. + */ +class XCube_EventManager +{ + var $_mEvents=array(); + + var $_mReserveEventList=array(); + var $_mRegistedFlags=array(); + var $_mProxyRegisters=array(); + + function XCube_EventManager() + { + } + + function prepare() + { + } + + function add($eventName,&$delegate) + { + if(!isset($this->_mEvents[$eventName])) + $this->_mEvents[$eventName] = new XCube_Event($eventName); + + $this->_mEvents[$eventName]->add($delegate); + } + + function setAnchorDelegate($eventName,&$delegate) + { + if(!isset($this->_mEvents[$eventName])) + $this->_mEvents[$eventName] = new XCube_Event($eventName); + + $this->_mEvents[$eventName]->setAnchorDelegate($delegate); + } + + function replaceEvent($eventName,&$eventHandler) + { + if(isset($this->_mEvents[$eventName])) { + if(strtolower(get_class($this->_mEvents[$eventName]))=="xcube_event") { + // + // TODO : omg! We access private property. + // + foreach($this->_mEvents[$eventName]->_mDelegates as $delegate) { + $eventHandler->_mDelegates[]=$delegate; + unset($delegate); + } + unset($this->_mEvents[$eventName]); + $this->_mEvents[$eventName]=&$eventHandler; + } + } + else { + $this->_mEvents[$eventName]=&$eventHandler; + } + } + + function raiseEvent($eventName,&$sender,&$eventArgs) + { + if(isset($this->_mReserveEventList[$eventName])&&$this->_mRegistedFlags[$eventName]==false) { + $this->_processProxyRegist($eventName); + } + + if(isset($this->_mEvents[$eventName])) { + $this->_mEvents[$eventName]->raiseEvent($sender,$eventArgs); + + return true; + } + return false; + } + + function addProxyRegister(&$register) + { + $i=count($this->_mProxyRegisters)+1; + $this->_mProxyRegisters[$i]=&$register; + + $list=$register->getEventNameList(); + foreach($list as $name) { + if(!isset($this->_mReserveEventList[$name])) { + $this->_mReserveEventList[$name]=array(); + $this->_mRegistedFlags[$name]=false; + } + + $this->_mReserveEventList[$name][]=$i; + } + } + + function _processProxyRegist($eventName) + { + $this->_mRegistedFlags[$eventName]=true; + foreach($this->_mReserveEventList[$eventName] as $i) { + $this->add($eventName,$this->_mProxyRegisters[$i]->createDelegate($eventName)); + } + } +} + +/** + * This class tells a manager about a list of the event that the Delegate which this class can create. + * And this class creates Delegate when the manager needs Delegate. + * Developer does not need to use this by all means. + */ +class XCube_EventProxyRegister +{ + /** + * @return array + */ + function getEventNameList() + { + } + + function &createDelegate($name) + { + $ret =null; + $methodName=str_replace(".","_","create".ucfirst($name)."Delegate"); + if(method_exists($this,$methodName)) { + $ret=&call_user_func(array($this,$methodName)); + } + + return $ret; + } +} + +/** + * + * Static Utility methods for XCube_EventManager + * + */ +class XCube_EventUtils +{ + /** + Simple Raise Event method; + */ + function &quickRaiseEvent($event, $eventArgs = array()) + { + $root=&XCube_Root::getSingleton(); + if ($root->mEventManager->raiseEvent($event, $root->mController, $eventArgs)) { + return $eventArgs; + } else { + return false; + } + } + + /** + Simple Text Filterling with Event mechanism + */ + function quickApplyFilter($filter, $string, $optionArgs = array()) + { + $root=&XCube_Root::getSingleton(); + $eventArgs = array_merge(array('string' => $string), $optionArgs); + if ($root->mEventManager->raiseEvent($filter, $root->mController, $eventArgs)) { + return $eventArgs['string']; + } else { + return $string; + } + } +} ?> \ No newline at end of file Index: xoops2jp/html/class/module.textsanitizer.php diff -u xoops2jp/html/class/module.textsanitizer.php:1.2.8.3 xoops2jp/html/class/module.textsanitizer.php:1.2.8.4 --- xoops2jp/html/class/module.textsanitizer.php:1.2.8.3 Mon Jan 2 21:41:35 2006 +++ xoops2jp/html/class/module.textsanitizer.php Fri Jan 27 23:38:08 2006 @@ -1,5 +1,5 @@ <?php -// $Id: module.textsanitizer.php,v 1.2.8.3 2006/01/02 12:41:35 minahito Exp $ +// $Id: module.textsanitizer.php,v 1.2.8.4 2006/01/27 14:38:08 nobunobu Exp $ // ------------------------------------------------------------------------ // // XOOPS - PHP Content Management System // // Copyright (c) 2000 XOOPS.org // @@ -132,7 +132,30 @@ { $patterns = array("/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([^, \r\n\"\(\)'<>]+)/i", "/(^|[^]_a-z0-9-=\"'\/])www\.([a-z0-9\-]+)\.([^, \r\n\"\(\)'<>]+)/i", "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([^, \r\n\"\(\)'<>]+)/i", "/(^|[^]_a-z0-9-=\"'\/:\.])([a-z0-9\-_\.]+?)@([^, \r\n\"\(\)'<>\[\]]+)/i"); $replacements = array("\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", "\\1<a href=\"http://www.\\2.\\3\" target=\"_blank\">www.\\2.\\3</a>", "\\1<a href=\"ftp://ftp.\\2.\\3\" target=\"_blank\">ftp.\\2.\\3</a>", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>"); - return preg_replace($patterns, $replacements, $text); + + // RaiseEvent 'Legacy.TextSanitizer.MakeClicablePre' + // Delegate may replace makeClickable conversion table + // varArgs : + // 'patterns' [I/O] : &Array of pattern RegExp + // 'replacements' [I/O] : &Array of replacing string + // + if ($result =& XCube_EventUtils::quickRaiseEvent('Legacy.TextSanitizer.MakeClickablePre', + array('patterns'=> &$patterns, + 'replacements' => &$replacements))) { + $patterns =& $result['patterns']; + $replacements =& $result['replacements']; + } + + $text = preg_replace($patterns, $replacements, $text); + + // RaiseEvent : 'Legacy.TextSanitizer.MakeClicablePostFilter' + // Delegate may convert output text with quickApplyFilter rule + // varArgs : + // 'string' [I/O] : Text to convert; + // + $text = XCube_EventUtils::quickApplyFilter('Legacy.TextSanitizer.MakeClickablePostFilter', $text); + + return $text; } /** @@ -202,7 +225,34 @@ $replacements[] = "java script:"; $patterns[] = "/about:/si"; $replacements[] = "about :"; - return preg_replace($patterns, $replacements, $text); + + // RaiseEvent 'Legacy.TextSanitizer.XoopsCodePre' + // Delegate may replace conversion table + // varArgs : + // 'patterns' [I/O] : &Array of pattern RegExp + // 'replacements' [I/O] : &Array of replacing string + // 'allowimage' [I] : xoopsCodeDecode $allowimage parameter + // + if ($result =& XCube_EventUtils::quickRaiseEvent('Legacy.TextSanitizer.XoopsCodePre', + array('patterns'=> &$patterns, + 'replacements' => &$replacements, + 'allowimage'=>$allowimage))) { + $patterns =& $result['patterns']; + $replacements =& $result['replacements']; + } + + $text = preg_replace($patterns, $replacements, $text); + + // RaiseEvent : 'Legacy.TextSanitizer.XoopsCodePostFilter' + // Delegate may convert output text with quickApplyFilter rule + // varArgs : + // 'string' [I/O] : Text to convert; + // 'allowimage' [I] : xoopsCodeDecode $allowimage parameter + // + $text = XCube_EventUtils::quickApplyFilter('Legacy.TextSanitizer.XoopsCodePostFilter', $text, + array('allowimage'=>$allowimage)); + + return $text; } /** Index: xoops2jp/html/class/template.php diff -u xoops2jp/html/class/template.php:1.2.8.3 xoops2jp/html/class/template.php:1.2.8.4 --- xoops2jp/html/class/template.php:1.2.8.3 Mon Jan 2 21:41:35 2006 +++ xoops2jp/html/class/template.php Fri Jan 27 23:38:08 2006 @@ -1,5 +1,5 @@ <?php -// $Id: template.php,v 1.2.8.3 2006/01/02 12:41:35 minahito Exp $ +// $Id: template.php,v 1.2.8.4 2006/01/27 14:38:08 nobunobu Exp $ // ------------------------------------------------------------------------ // // XOOPS - PHP Content Management System // // Copyright (c) 2000 XOOPS.org // @@ -76,17 +76,23 @@ $this->cache_dir = XOOPS_CACHE_PATH; $this->compile_dir = XOOPS_COMPILE_PATH; $this->plugins_dir = array(XOOPS_ROOT_PATH.'/class/smarty/plugins'); - $this->default_template_handler_func = 'xoops_template_create'; - - // Added by goghs on 11-26 to deal with safe mode - //if (ini_get('safe_mode') == "1") { - $this->use_sub_dirs = false; - //} else { - // $this->use_sub_dirs = true; - //} - // END +// $this->default_template_handler_func = 'xoops_template_create'; + $this->use_sub_dirs = false; - $this->assign(array('xoops_url' => XOOPS_URL, 'xoops_rootpath' => XOOPS_ROOT_PATH, 'xoops_langcode' => _LANGCODE, 'xoops_charset' => _CHARSET, 'xoops_version' => XOOPS_VERSION, 'xoops_upload_url' => XOOPS_UPLOAD_URL)); + $this->assign(array('xoops_url' => XOOPS_URL, + 'xoops_rootpath' => XOOPS_ROOT_PATH, + 'xoops_langcode' => _LANGCODE, + 'xoops_charset' => _CHARSET, + 'xoops_version' => XOOPS_VERSION, + 'xoops_upload_url' => XOOPS_UPLOAD_URL + )); + + // RaiseEvent 'Legacy.XoopsTpl.New' + // Delegate may define additional initialization code for XoopTpl Instance; + // varArgs : + // 'xoopsTpl' [I/O] : $this + // + XCube_EventUtils::quickRaiseEvent('Legacy.XoopsTpl.New', array('xoopsTpl' => &$this)); } /** @@ -167,6 +173,8 @@ /** * Render output from template data * + * @deprecated + * * @param string $data * @return string Rendered output **/ @@ -223,9 +231,47 @@ } } + +/** + * function to update compiled template file in templates_c folder + * + * @param string $tpl_id + * @param boolean $clear_old + * @return boolean + **/ +function xoops_template_touch($tpl_id, $clear_old = true) +{ + // RaiseEvent 'Legacy.XoopsTpl.TemplateTouch' + // Delegate may define new template touch logic (with XC21, only for clear cache & compiled template) + // varArgs : + // 'xoopsTpl' [I/O] : $this + // + if (! $eventResult =& XCube_EventUtils::quickRaiseEvent('Legacy.XoopsTpl.TemplateTouch', + array('tpl_id' => $tpl_id,'clear_old' => $clear_old,'result'=>false))) { + $tpl = new XoopsTpl(); + $tpl->force_compile = true; + $tplfile_handler =& xoops_gethandler('tplfile'); + $tplfile =& $tplfile_handler->get($tpl_id); + if ( is_object($tplfile) ) { + $file = $tplfile->getVar('tpl_file'); + if ($clear_old) { + $tpl->clear_cache('db:'.$file); + $tpl->clear_compiled_tpl('db:'.$file); + } + // $tpl->fetch('db:'.$file); + return true; + } + return false; + } else { + return $eventResult['result']; + } +} + /** * Smarty default template handler function * + * @deprecated + * * @param $resource_type * @param $resource_name * @param $template_source @@ -249,33 +295,10 @@ } /** - * function to update compiled template file in templates_c folder - * - * @param string $tpl_id - * @param boolean $clear_old - * @return boolean - **/ -function xoops_template_touch($tpl_id, $clear_old = true) -{ - $tpl = new XoopsTpl(); - $tpl->force_compile = true; - $tplfile_handler =& xoops_gethandler('tplfile'); - $tplfile =& $tplfile_handler->get($tpl_id); - if ( is_object($tplfile) ) { - $file = $tplfile->getVar('tpl_file'); - if ($clear_old) { - $tpl->clear_cache('db:'.$file); - $tpl->clear_compiled_tpl('db:'.$file); - } - // $tpl->fetch('db:'.$file); - return true; - } - return false; -} - -/** * Clear the module cache * + * @deprecated + * * @param int $mid Module ID * @return **/ @@ -293,4 +316,4 @@ } } } -?> \ No newline at end of file +?>