add description of function

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10764 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
chschy 2012-06-05 05:33:14 +00:00
parent 5a510567d1
commit ebfe89ca32
10 changed files with 243 additions and 120 deletions

View file

@ -2,7 +2,7 @@
/** /**
* @class DisplayHandler * @class DisplayHandler
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
* @brief DisplayHandler is responsible for displaying the execution result. \n * DisplayHandler is responsible for displaying the execution result. \n
* Depending on the request type, it can display either HTML or XML content.\n * Depending on the request type, it can display either HTML or XML content.\n
* Xml content is simple xml presentation of variables in oModule while html content * Xml content is simple xml presentation of variables in oModule while html content
* is the combination of the variables of oModue and template files/. * is the combination of the variables of oModue and template files/.
@ -16,11 +16,11 @@
var $handler = null; var $handler = null;
/** /**
* @brief print either html or xml content given oModule object * print either html or xml content given oModule object
* @remark addon execution and the trigger execution are included within this method, which * @remark addon execution and the trigger execution are included within this method, which might create inflexibility for the fine grained caching
* might create inflexibility for the fine grained caching * @param ModuleObject $oModule the module object
* @param[in] $oModule the module object * @return void
**/ **/
function printContent(&$oModule) { function printContent(&$oModule) {
// Check if the gzip encoding supported // Check if the gzip encoding supported
if( if(
@ -82,9 +82,10 @@
/** /**
* @brief Print debugging message to designated output source depending on the value set to __DEBUG_OUTPUT_. \n * Print debugging message to designated output source depending on the value set to __DEBUG_OUTPUT_. \n
* This method only functions when __DEBUG__ variable is set to 1. * This method only functions when __DEBUG__ variable is set to 1.
* __DEBUG_OUTPUT__ == 0, messages are written in ./files/_debug_message.php * __DEBUG_OUTPUT__ == 0, messages are written in ./files/_debug_message.php
* @return void
**/ **/
function _debugOutput() { function _debugOutput() {
if(!__DEBUG__) return; if(!__DEBUG__) return;
@ -221,7 +222,8 @@
} }
/** /**
* @brief print a HTTP HEADER for XML, which is encoded in UTF-8 * print a HTTP HEADER for XML, which is encoded in UTF-8
* @return void
**/ **/
function _printXMLHeader() { function _printXMLHeader() {
header("Content-Type: text/xml; charset=UTF-8"); header("Content-Type: text/xml; charset=UTF-8");
@ -234,7 +236,8 @@
/** /**
* @brief print a HTTP HEADER for HTML, which is encoded in UTF-8 * print a HTTP HEADER for HTML, which is encoded in UTF-8
* @return void
**/ **/
function _printHTMLHeader() { function _printHTMLHeader() {
header("Content-Type: text/html; charset=UTF-8"); header("Content-Type: text/html; charset=UTF-8");
@ -247,7 +250,8 @@
/** /**
* @brief print a HTTP HEADER for JSON, which is encoded in UTF-8 * print a HTTP HEADER for JSON, which is encoded in UTF-8
* @return void
**/ **/
function _printJSONHeader() { function _printJSONHeader() {
header("Content-Type: text/html; charset=UTF-8"); header("Content-Type: text/html; charset=UTF-8");
@ -260,7 +264,8 @@
/** /**
* @brief print a HTTP HEADER for HTML, which is encoded in UTF-8 * print a HTTP HEADER for HTML, which is encoded in UTF-8
* @return void
**/ **/
function _printHttpStatusCode($code) { function _printHttpStatusCode($code) {
$statusMessage = Context::get('http_status_message'); $statusMessage = Context::get('http_status_message');

View file

@ -2,8 +2,9 @@
class HTMLDisplayHandler { class HTMLDisplayHandler {
/** /**
* @brief Produce HTML compliant content given a module object.\n * Produce HTML compliant content given a module object.\n
* @param[in] $oModule the module object * @param ModuleObject $oModule the module object
* @return string compiled template string
**/ **/
function toDoc(&$oModule) function toDoc(&$oModule)
{ {
@ -79,6 +80,11 @@ class HTMLDisplayHandler {
return $output; return $output;
} }
/**
* when display mode is HTML, prepare code before print.
* @param string $output compiled template string
* @return void
**/
function prepareToPrint(&$output) { function prepareToPrint(&$output) {
if(Context::getResponseMethod() != 'HTML') return; if(Context::getResponseMethod() != 'HTML') return;
@ -151,6 +157,11 @@ class HTMLDisplayHandler {
$oModuleController->replaceDefinedLangCode($output); $oModuleController->replaceDefinedLangCode($output);
} }
/**
* when display mode is HTML, prepare code before print about <input> tag value.
* @param array $match input value.
* @return string input value.
**/
function _preserveValue($match) function _preserveValue($match)
{ {
$INPUT_ERROR = Context::get('INPUT_ERROR'); $INPUT_ERROR = Context::get('INPUT_ERROR');
@ -181,6 +192,11 @@ class HTMLDisplayHandler {
return $str.' />'; return $str.' />';
} }
/**
* when display mode is HTML, prepare code before print about <select> tag value.
* @param array $matches select tag.
* @return string select tag.
**/
function _preserveSelectValue($matches) function _preserveSelectValue($matches)
{ {
$INPUT_ERROR = Context::get('INPUT_ERROR'); $INPUT_ERROR = Context::get('INPUT_ERROR');
@ -200,6 +216,11 @@ class HTMLDisplayHandler {
return $mm[0].implode('', $m[0]).'</select>'; return $mm[0].implode('', $m[0]).'</select>';
} }
/**
* when display mode is HTML, prepare code before print about <textarea> tag value.
* @param array $matches textarea tag information.
* @return string textarea tag
**/
function _preserveTextAreaValue($matches) function _preserveTextAreaValue($matches)
{ {
$INPUT_ERROR = Context::get('INPUT_ERROR'); $INPUT_ERROR = Context::get('INPUT_ERROR');
@ -208,23 +229,29 @@ class HTMLDisplayHandler {
} }
/** /**
* @brief add html style code extracted from html body to Context, which will be * add html style code extracted from html body to Context, which will be
* printed inside <header></header> later. * printed inside <header></header> later.
* @param[in] $oModule the module object * @param array $matches
* @return void
**/ **/
function _moveStyleToHeader($matches) { function _moveStyleToHeader($matches) {
Context::addHtmlHeader($matches[0]); Context::addHtmlHeader($matches[0]);
} }
/** /**
* @brief add given .css or .js file names in widget code to Context * add given .css or .js file names in widget code to Context
* @param[in] $oModule the module object * @param array $matches
* @return void
**/ **/
function _transMeta($matches) { function _transMeta($matches) {
if($matches[1]) return ''; if($matches[1]) return '';
Context::loadFile($matches[2]); Context::loadFile($matches[2]);
} }
/**
* import basic .js files.
* @return void
**/
function _loadJSCSS() function _loadJSCSS()
{ {
$oContext =& Context::getInstance(); $oContext =& Context::getInstance();
@ -260,6 +287,10 @@ class HTMLDisplayHandler {
} }
} }
/**
* add meta tag.
* @return void
**/
function _addMetaTag() function _addMetaTag()
{ {
$oContext =& Context::getInstance(); $oContext =& Context::getInstance();

View file

@ -1,6 +1,11 @@
<?php <?php
class JSONDisplayHandler { class JSONDisplayHandler {
/**
* Produce JSON compliant content given a module object.\n
* @param ModuleObject $oModule the module object
* @return string
**/
function toDoc(&$oModule) function toDoc(&$oModule)
{ {
$variables = $oModule->getVariables(); $variables = $oModule->getVariables();

View file

@ -2,8 +2,9 @@
class VirtualXMLDisplayHandler { class VirtualXMLDisplayHandler {
/** /**
* @brief Produce virtualXML compliant content given a module object.\n * Produce virtualXML compliant content given a module object.\n
* @param[in] $oModule the module object * @param ModuleObject $oModule the module object
* @return string
**/ **/
function toDoc(&$oModule) function toDoc(&$oModule)

View file

@ -2,8 +2,9 @@
class XMLDisplayHandler { class XMLDisplayHandler {
/** /**
* @brief Produce XML compliant content given a module object.\n * Produce XML compliant content given a module object.\n
* @param[in] $oModule the module object * @param ModuleObject $oModule the module object
* @return string
**/ **/
function toDoc(&$oModule) function toDoc(&$oModule)
{ {
@ -21,8 +22,9 @@ class XMLDisplayHandler {
} }
/** /**
* @brief produce XML code given variable object\n * produce XML code given variable object\n
* @param[in] $oModule the module object * @param object $obj
* @return string
**/ **/
function _makeXmlDoc($obj) { function _makeXmlDoc($obj) {
if(!count($obj)) return; if(!count($obj)) return;

View file

@ -10,7 +10,9 @@
class EditorHandler extends Object { class EditorHandler extends Object {
/** /**
* @brief set the xml and other information of the component * set the xml and other information of the component
* @param object $info editor information
* @return void
**/ **/
function setInfo($info) { function setInfo($info) {
Context::set('component_info', $info); Context::set('component_info', $info);

View file

@ -2,7 +2,7 @@
/** /**
* @class ModuleHandler * @class ModuleHandler
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
* @brief Handling modules * Handling modules
* *
* @remarks This class is to excute actions of modules. * @remarks This class is to excute actions of modules.
* Constructing an instance without any parameterconstructor, it finds the target module based on Context. * Constructing an instance without any parameterconstructor, it finds the target module based on Context.
@ -23,8 +23,13 @@
var $httpStatusCode = NULL; ///< http status code. var $httpStatusCode = NULL; ///< http status code.
/** /**
* @brief constructor * prepares variables to use in moduleHandler
* @remarks it prepares variables to use in moduleHandler * @param string $module name of module
* @param string $act name of action
* @param int $mid
* @param int $document_srl
* @param int $module_srl
* @return void
**/ **/
function ModuleHandler($module = '', $act = '', $mid = '', $document_srl = '', $module_srl = '') { function ModuleHandler($module = '', $act = '', $mid = '', $document_srl = '', $module_srl = '') {
// If XE has not installed yet, set module as install // If XE has not installed yet, set module as install
@ -63,8 +68,8 @@
} }
/** /**
* @brief Initialization. It finds the target module based on module, mid, document_srl, and prepares to execute an action * Initialization. It finds the target module based on module, mid, document_srl, and prepares to execute an action
* @return true: OK, false: redirected * @return boolean true: OK, false: redirected
**/ **/
function init() { function init() {
$oModuleModel = &getModel('module'); $oModuleModel = &getModel('module');
@ -172,8 +177,8 @@
} }
/** /**
* @brief get a module instance and execute an action * get a module instance and execute an action
* @return executed module instance * @return ModuleObject executed module instance
**/ **/
function procModule() { function procModule() {
$oModuleModel = &getModel('module'); $oModuleModel = &getModel('module');
@ -458,6 +463,10 @@
return $oModule; return $oModule;
} }
/**
* set error message to Session.
* @return void
**/
function _setInputErrorToContext() function _setInputErrorToContext()
{ {
if($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR')) Context::set('XE_VALIDATOR_ERROR', $_SESSION['XE_VALIDATOR_ERROR']); if($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR')) Context::set('XE_VALIDATOR_ERROR', $_SESSION['XE_VALIDATOR_ERROR']);
@ -468,6 +477,10 @@
$this->_clearErrorSession(); $this->_clearErrorSession();
} }
/**
* clear error message to Session.
* @return void
**/
function _clearErrorSession() function _clearErrorSession()
{ {
$_SESSION['XE_VALIDATOR_ERROR'] = ''; $_SESSION['XE_VALIDATOR_ERROR'] = '';
@ -476,6 +489,10 @@
$_SESSION['XE_VALIDATOR_RETURN_URL'] = ''; $_SESSION['XE_VALIDATOR_RETURN_URL'] = '';
} }
/**
* occured error when, set input values to session.
* @return void
**/
function _setInputValueToSession() function _setInputValueToSession()
{ {
$requestVars = Context::getRequestVars(); $requestVars = Context::getRequestVars();
@ -484,9 +501,9 @@
} }
/** /**
* @brief display contents from executed module * display contents from executed module
* @param[in] $oModule module instance * @param ModuleObject $oModule module instance
* @return none * @return void
**/ **/
function displayContent($oModule = NULL) { function displayContent($oModule = NULL) {
// If the module is not set or not an object, set error // If the module is not set or not an object, set error
@ -594,20 +611,20 @@
} }
/** /**
* @brief returns module's path * returns module's path
* @param[in] $module module name * @param string $module module name
* @return path of the module * @return string path of the module
**/ **/
function getModulePath($module) { function getModulePath($module) {
return sprintf('./modules/%s/', $module); return sprintf('./modules/%s/', $module);
} }
/** /**
* @brief It creates a module instance * It creates a module instance
* @param[in] $module module name * @param string $module module name
* @param[in] $type instance type, (e.g., view, controller, model) * @param string $type instance type, (e.g., view, controller, model)
* @param[in] $kind admin or svc * @param string $kind admin or svc
* @return module instance (if failed it returns null) * @return ModuleObject module instance (if failed it returns null)
* @remarks if there exists a module instance created before, returns it. * @remarks if there exists a module instance created before, returns it.
**/ **/
function &getModuleInstance($module, $type = 'view', $kind = '') { function &getModuleInstance($module, $type = 'view', $kind = '') {
@ -696,10 +713,10 @@
} }
/** /**
* @brief call a trigger * call a trigger
* @param[in] $trigger_name trigger's name to call * @param string $trigger_name trigger's name to call
* @param[in] $called_position called position * @param string $called_position called position
* @param[in] $obj an object as a parameter to trigger * @param object $obj an object as a parameter to trigger
* @return Object * @return Object
**/ **/
function triggerCall($trigger_name, $called_position, &$obj) { function triggerCall($trigger_name, $called_position, &$obj) {
@ -728,7 +745,9 @@
} }
/** /**
* @brief get http status message by http status code * get http status message by http status code
* @param string $code
* @return string
**/ **/
function _setHttpStatusMessage($code) { function _setHttpStatusMessage($code) {
$statusMessageList = array( $statusMessageList = array(

View file

@ -2,7 +2,7 @@
/** /**
* @class ModuleObject * @class ModuleObject
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
* @brief base class of ModuleHandler * base class of ModuleHandler
**/ **/
class ModuleObject extends Object { class ModuleObject extends Object {
@ -30,16 +30,18 @@
var $module_config = NULL; var $module_config = NULL;
/** /**
* @brief setter to set the name of module * setter to set the name of module
* @param name of module * @param string $module name of module
* @return void
**/ **/
function setModule($module) { function setModule($module) {
$this->module = $module; $this->module = $module;
} }
/** /**
* @brief setter to set the name of module path * setter to set the name of module path
* @param the directory path to a module directory * @param string $path the directory path to a module directory
* @return void
**/ **/
function setModulePath($path) { function setModulePath($path) {
if(substr($path,-1)!='/') $path.='/'; if(substr($path,-1)!='/') $path.='/';
@ -47,25 +49,28 @@
} }
/** /**
* @brief setter to set an url for redirection * setter to set an url for redirection
* @param $url url for redirection * @param string $url url for redirection
* @remark redirect_url is used only for ajax requests * @remark redirect_url is used only for ajax requests
* @return void
**/ **/
function setRedirectUrl($url='./') { function setRedirectUrl($url='./') {
$this->add('redirect_url', $url); $this->add('redirect_url', $url);
} }
/** /**
* @brief get url for redirection * get url for redirection
* @return string redirect_url
**/ **/
function getRedirectUrl(){ function getRedirectUrl(){
return $this->get('redirect_url'); return $this->get('redirect_url');
} }
/** /**
* @brief set message * set message
* @param $message a message string * @param string $message a message string
* @param $type type of message (error, info, update) * @param string $type type of message (error, info, update)
* @return void
**/ **/
function setMessage($message, $type = null){ function setMessage($message, $type = null){
parent::setMessage($message); parent::setMessage($message);
@ -73,15 +78,17 @@
} }
/** /**
* @brief set type of message * set type of message
* @param $type type of message (error, info, update) * @param string $type type of message (error, info, update)
* @return void
**/ **/
function setMessageType($type){ function setMessageType($type){
$this->add('message_type', $type); $this->add('message_type', $type);
} }
/** /**
* @brief get type of message * get type of message
* @return string $type
**/ **/
function getMessageType(){ function getMessageType(){
$type = $this->get('message_type'); $type = $this->get('message_type');
@ -92,9 +99,10 @@
} }
/** /**
* @brief sett to set the template path for refresh.html * sett to set the template path for refresh.html
* @remark refresh.html is executed as a result of method execution * refresh.html is executed as a result of method execution
* Tpl as the common run of the refresh.html .. * Tpl as the common run of the refresh.html ..
* @return void
**/ **/
function setRefreshPage() { function setRefreshPage() {
$this->setTemplatePath('./common/tpl'); $this->setTemplatePath('./common/tpl');
@ -103,16 +111,19 @@
/** /**
* @brief sett to set the action name * sett to set the action name
* @param string $act
* @return void
**/ **/
function setAct($act) { function setAct($act) {
$this->act = $act; $this->act = $act;
} }
/** /**
* @brief sett to set module information * sett to set module information
* @param[in] $module_info object containing module information * @param object $module_info object containing module information
* @param[in] $xml_info object containing module description * @param object $xml_info object containing module description
* @return void
**/ **/
function setModuleInfo($module_info, $xml_info) { function setModuleInfo($module_info, $xml_info) {
// The default variable settings // The default variable settings
@ -172,8 +183,9 @@
} }
/** /**
* @brief set the stop_proc and approprate message for msg_code * set the stop_proc and approprate message for msg_code
* @param $msg_code an error code * @param string $msg_code an error code
* @return ModuleObject $this
**/ **/
function stop($msg_code) { function stop($msg_code) {
// flag setting to stop the proc processing // flag setting to stop the proc processing
@ -195,7 +207,9 @@
} }
/** /**
* @brief set the file name of the template file * set the file name of the template file
* @param string name of file
* @return void
**/ **/
function setTemplateFile($filename) { function setTemplateFile($filename) {
if(substr($filename,-5)!='.html') $filename .= '.html'; if(substr($filename,-5)!='.html') $filename .= '.html';
@ -203,14 +217,17 @@
} }
/** /**
* @brief retrieve the directory path of the template directory * retrieve the directory path of the template directory
* @return string
**/ **/
function getTemplateFile() { function getTemplateFile() {
return $this->template_file; return $this->template_file;
} }
/** /**
* @brief set the directory path of the template directory * set the directory path of the template directory
* @param string path of template directory.
* @return void
**/ **/
function setTemplatePath($path) { function setTemplatePath($path) {
if(substr($path,0,1)!='/' && substr($path,0,2)!='./') $path = './'.$path; if(substr($path,0,1)!='/' && substr($path,0,2)!='./') $path = './'.$path;
@ -219,15 +236,17 @@
} }
/** /**
* retrieve the directory path of the template directory
* @brief retrieve the directory path of the template directory * @return string
**/ **/
function getTemplatePath() { function getTemplatePath() {
return $this->template_path; return $this->template_path;
} }
/** /**
* @brief set the file name of the temporarily modified by admin * set the file name of the temporarily modified by admin
* @param string name of file
* @return void
**/ **/
function setEditedLayoutFile($filename) { function setEditedLayoutFile($filename) {
if(substr($filename,-5)!='.html') $filename .= '.html'; if(substr($filename,-5)!='.html') $filename .= '.html';
@ -235,14 +254,17 @@
} }
/** /**
* @brief retreived the file name of edited_layout_file * retreived the file name of edited_layout_file
* @return string
**/ **/
function getEditedLayoutFile() { function getEditedLayoutFile() {
return $this->edited_layout_file; return $this->edited_layout_file;
} }
/** /**
* @brief set the file name of the layout file * set the file name of the layout file
* @param string name of file
* @return void
**/ **/
function setLayoutFile($filename) { function setLayoutFile($filename) {
if(substr($filename,-5)!='.html') $filename .= '.html'; if(substr($filename,-5)!='.html') $filename .= '.html';
@ -250,14 +272,16 @@
} }
/** /**
* @brief get the file name of the layout file * get the file name of the layout file
* @return string
**/ **/
function getLayoutFile() { function getLayoutFile() {
return $this->layout_file; return $this->layout_file;
} }
/** /**
* @brief set the directory path of the layout directory * set the directory path of the layout directory
* @param string path of layout directory.
**/ **/
function setLayoutPath($path) { function setLayoutPath($path) {
if(substr($path,0,1)!='/' && substr($path,0,2)!='./') $path = './'.$path; if(substr($path,0,1)!='/' && substr($path,0,2)!='./') $path = './'.$path;
@ -266,15 +290,16 @@
} }
/** /**
* @brief set the directory path of the layout directory * set the directory path of the layout directory
* @return string
**/ **/
function getLayoutPath() { function getLayoutPath() {
return $this->layout_path; return $this->layout_path;
} }
/** /**
* @brief excute the member method specified by $act variable * excute the member method specified by $act variable
* * @return boolean true : success false : fail
**/ **/
function proc() { function proc() {
// pass if stop_proc is true // pass if stop_proc is true

View file

@ -2,7 +2,7 @@
/** /**
* @class PageHandler * @class PageHandler
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
* @brief handles page navigation * handles page navigation
* @version 0.1 * @version 0.1
* *
* @remarks Getting total counts, number of pages, current page number, number of items per page, * @remarks Getting total counts, number of pages, current page number, number of items per page,
@ -20,11 +20,12 @@
var $point = 0; ///< increments per getNextPage() var $point = 0; ///< increments per getNextPage()
/** /**
* @brief constructor * constructor
* @param[in] $total_count number of total items * @param int $total_count number of total items
* @param[in] $total_page number of total pages * @param int $total_page number of total pages
* @param[in] $cur_page current page number * @param int $cur_page current page number
* @param[in] $page_count number of page links displayed at one time * @param int $page_count number of page links displayed at one time
* @return void
**/ **/
function PageHandler($total_count, $total_page, $cur_page, $page_count = 10) { function PageHandler($total_count, $total_page, $cur_page, $page_count = 10) {
$this->total_count = $total_count; $this->total_count = $total_count;
@ -45,8 +46,8 @@
} }
/** /**
* @brief request next page * request next page
* @return next page number * @return int next page number
**/ **/
function getNextPage() { function getNextPage() {
$page = $this->first_page+$this->point++; $page = $this->first_page+$this->point++;
@ -54,6 +55,11 @@
return $page; return $page;
} }
/**
* return number of page that added offset.
* @param int $offset
* @return int
**/
function getPage($offset) function getPage($offset)
{ {
return max(min($this->cur_page + $offset, $this->total_page), ''); return max(min($this->cur_page + $offset, $this->total_page), '');

View file

@ -2,7 +2,7 @@
/** /**
* @class TemplateHandler * @class TemplateHandler
* @author NHN (developers@xpressengine.com) * @author NHN (developers@xpressengine.com)
* @brief template compiler * template compiler
* @version 0.1 * @version 0.1
* @remarks It compiles template file by using regular expression into php * @remarks It compiles template file by using regular expression into php
* code, and XE caches compiled code for further uses * code, and XE caches compiled code for further uses
@ -22,6 +22,10 @@ class TemplateHandler {
var $handler_mtime = 0; var $handler_mtime = 0;
/**
* constructor
* @return void
**/
function TemplateHandler() function TemplateHandler()
{ {
// TODO: replace this with static variable in PHP5 // TODO: replace this with static variable in PHP5
@ -33,7 +37,7 @@ class TemplateHandler {
} }
/** /**
* @brief returns TemplateHandler's singleton object * returns TemplateHandler's singleton object
* @return TemplateHandler instance * @return TemplateHandler instance
**/ **/
function &getInstance() function &getInstance()
@ -51,7 +55,11 @@ class TemplateHandler {
} }
/** /**
* @brief set variables for template compile * set variables for template compile
* @param string $tpl_path
* @param string $tpl_filename
* @param string $tpl_file
* @return void
**/ **/
function init($tpl_path, $tpl_filename, $tpl_file='') function init($tpl_path, $tpl_filename, $tpl_file='')
{ {
@ -80,11 +88,11 @@ class TemplateHandler {
} }
/** /**
* @brief compiles specified tpl file and execution result in Context into resultant content * compiles specified tpl file and execution result in Context into resultant content
* @param[in] $tpl_path path of the directory containing target template file * @param string $tpl_path path of the directory containing target template file
* @param[in] $tpl_filename target template file's name * @param string $tpl_filename target template file's name
* @param[in] $tpl_file if specified use it as template file's full path * @param string $tpl_file if specified use it as template file's full path
* @return Returns compiled result in case of success, NULL otherwise * @return string Returns compiled result in case of success, NULL otherwise
*/ */
function compile($tpl_path, $tpl_filename, $tpl_file='') { function compile($tpl_path, $tpl_filename, $tpl_file='') {
global $__templatehandler_root_tpl; global $__templatehandler_root_tpl;
@ -140,10 +148,10 @@ class TemplateHandler {
} }
/** /**
* @brief compile specified file and immediately return * compile specified file and immediately return
* @param[in] $tpl_path path of the directory containing target template file * @param string $tpl_path path of the directory containing target template file
* @param[in] $tpl_filename target template file's name * @param string $tpl_filename target template file's name
* @return Returns compiled content in case of success or NULL in case of failure * @return string Returns compiled content in case of success or NULL in case of failure
**/ **/
function compileDirect($tpl_path, $tpl_filename) { function compileDirect($tpl_path, $tpl_filename) {
$this->init($tpl_path, $tpl_filename, null); $this->init($tpl_path, $tpl_filename, null);
@ -158,11 +166,9 @@ class TemplateHandler {
} }
/** /**
* @brief compile a template file specified in $tpl_file and * parse syntax.
* @pre files specified by $tpl_file exists. * @param string $buff template file
* @param[in] $tpl_file path of tpl file * @return string compiled result in case of success or NULL in case of error
* @param[in] $compiled_tpl_file if specified, write compiled result into the file
* @return compiled result in case of success or NULL in case of error
**/ **/
function parse($buff=null) { function parse($buff=null) {
if(is_null($buff)) { if(is_null($buff)) {
@ -202,10 +208,13 @@ class TemplateHandler {
} }
/** /**
* @brief 1. remove ruleset from form tag * preg_replace_callback handler
* 1. remove ruleset from form tag
* 2. add hidden tag with ruleset value * 2. add hidden tag with ruleset value
* 3. if empty default hidden tag, generate hidden tag (ex:mid, vid, act...) * 3. if empty default hidden tag, generate hidden tag (ex:mid, vid, act...)
* 4. generate return url, return url use in server side validator * 4. generate return url, return url use in server side validator
* @param array $matches
* @return string
**/ **/
function _compileFormAuthGeneration($matches) function _compileFormAuthGeneration($matches)
{ {
@ -272,11 +281,9 @@ class TemplateHandler {
} }
/** /**
* @brief fetch using ob_* function * fetch using ob_* function
* @param[in] $compiled_tpl_file path of compiled template file * @param string $buff if buff is not null, eval it instead of including compiled template file
* @param[in] $buff if buff is not null, eval it instead of including compiled template file * @return string
* @param[in] $tpl_path set context's tpl path
* @return result string
**/ **/
function _fetch($buff) { function _fetch($buff) {
if(!$buff) return; if(!$buff) return;
@ -300,10 +307,12 @@ class TemplateHandler {
} }
/** /**
* @brief change image path * preg_replace_callback hanlder
* @pre $matches is an array containg three elements *
* @param[in] $matches match * replace image path
* @return changed result * @param array $match
*
* @return string changed result
**/ **/
function _replacePath($match) function _replacePath($match)
{ {
@ -320,6 +329,11 @@ class TemplateHandler {
return substr($match[0],0,-strlen($match[1])-6)."src=\"{$src}\""; return substr($match[0],0,-strlen($match[1])-6)."src=\"{$src}\"";
} }
/**
* replace loop and cond template syntax
* @param string $buff
* @return string changed result
**/
function _parseInline($buff) function _parseInline($buff)
{ {
if(preg_match_all('/<([a-zA-Z]+\d?)(?>(?!<[a-z]+\d?[\s>]).)*?(?:[ \|]cond| loop)="/s', $buff, $match) === false) return $buff; if(preg_match_all('/<([a-zA-Z]+\d?)(?>(?!<[a-z]+\d?[\s>]).)*?(?:[ \|]cond| loop)="/s', $buff, $match) === false) return $buff;
@ -408,6 +422,12 @@ class TemplateHandler {
return $buff; return $buff;
} }
/**
* preg_replace_callback hanlder
* replace php code.
* @param array $m
* @return string changed result
**/
function _parseResource($m) function _parseResource($m)
{ {
// {@ ... } or {$var} or {func(...)} // {@ ... } or {$var} or {func(...)}
@ -545,6 +565,11 @@ class TemplateHandler {
return $m[0]; return $m[0];
} }
/**
* change relative path
* @param string $path
* @return string
**/
function _getRelativeDir($path) function _getRelativeDir($path)
{ {
$_path = $path; $_path = $path;
@ -573,7 +598,9 @@ class TemplateHandler {
} }
/** /**
* @brief replace PHP variables of $ character * replace PHP variables of $ character
* @param string $php
* @return string $__Context->varname
**/ **/
function _replaceVar($php) { function _replaceVar($php) {
if(!strlen($php)) return ''; if(!strlen($php)) return '';