3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2011 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
13 * @license http://nucleuscms.org/license.txt GNU General Public License
14 * @copyright Copyright (C) 2002-2011 The Nucleus Group
16 * $NucleusJP: PARSER.php,v 1.7.2.1 2007/09/05 07:35:59 kimitake Exp $
19 if ( !function_exists('requestVar') ) exit;
\r
20 require_once dirname(__FILE__) . '/BaseActions.php';
\r
23 * This is the parser class of Nucleus. It is used for various things (skin parsing,
\r
24 * form generation, ...)
\r
28 // array with the names of all allowed actions
\r
31 // reference to actions handler
\r
34 // delimiters that can be used for skin/templatevars
\r
37 // parameter delimiter (to separate skinvar params)
\r
40 // usually set to 0. When set to 1, all skinvars are allowed regardless of $actions
\r
41 var $norestrictions;
\r
44 * Creates a new parser object with the given allowed actions
\r
45 * and the given handler
\r
47 * @param $allowedActions array
\r
48 * @param $handler class object with functions for each action (reference)
\r
49 * @param $delim optional delimiter
\r
50 * @param $paramdelim optional parameterdelimiter
\r
52 function PARSER($allowedActions, &$handler, $delim = '(<%|%>)', $pdelim = ',') {
\r
53 $this->actions = $allowedActions;
\r
54 $this->handler =& $handler;
\r
55 $this->delim = $delim;
\r
56 $this->pdelim = $pdelim;
\r
57 $this->norestrictions = 0; // set this to 1 to disable checking for allowedActions
\r
61 * Parses the given contents and outputs it
\r
63 function parse(&$contents) {
\r
65 $pieces = preg_split('/'.$this->delim.'/',$contents);
\r
67 $maxidx = sizeof($pieces);
\r
68 for ($idx = 0; $idx < $maxidx; $idx++) {
\r
71 if ($idx < $maxidx) {
\r
72 $this->doAction($pieces[$idx]);
\r
81 function doAction($action) {
\r
82 global $manager, $CONF;
\r
84 if (!$action) return;
\r
86 // split into action name + arguments
\r
87 if (strstr($action,'(')) {
\r
88 $paramStartPos = strpos($action, '(');
\r
89 $params = substr($action, $paramStartPos + 1, strlen($action) - $paramStartPos - 2);
\r
90 $action = substr($action, 0, $paramStartPos);
\r
91 $params = explode ($this->pdelim, $params);
\r
94 // for PHP versions lower than 4.0.6:
\r
95 // - add // before '$params = ...'
\r
96 // - remove // before 'foreach'
\r
97 $params = array_map('trim',$params);
\r
98 // foreach ($params as $key => $value) { $params[$key] = trim($value); }
\r
104 $actionlc = strtolower($action);
\r
106 // skip execution of skinvars while inside an if condition which hides this part of the page
\r
107 if (!$this->handler->if_currentlevel && ($actionlc != 'else') && ($actionlc != 'elseif') && ($actionlc != 'endif') && ($actionlc != 'ifnot') && ($actionlc != 'elseifnot') && (substr($actionlc,0,2) != 'if'))
\r
110 if (in_array($actionlc, $this->actions) || $this->norestrictions ) {
\r
111 // when using PHP versions lower than 4.0.5, uncomment the line before
\r
112 // and comment the call_user_func_array call
\r
113 //$this->call_using_array($action, $this->handler, $params);
\r
114 call_user_func_array(array(&$this->handler,'parse_' . $actionlc), $params);
\r
116 // redirect to plugin action if possible
\r
117 if (in_array('plugin', $this->actions) && $manager->pluginInstalled('NP_' . $action)) {
\r
118 $this->doAction('plugin('.$action.$this->pdelim.implode($this->pdelim,$params).')');
\r
120 if ($CONF['DebugVars']==true) {
\r
121 echo '<%' , $action , '(', implode($this->pdelim, $params), ')%>';
\r
130 * Calls a method using an array of parameters (for use with PHP versions lower than 4.0.5)
\r
131 * ( = call_user_func_array() function )
\r
133 function call_using_array($methodname, &$handler, $paramarray) {
\r
135 $methodname = 'parse_' . $methodname;
\r
137 if (!method_exists($handler, $methodname)) {
\r
141 $command = 'call_user_func(array(&$handler,$methodname)';
\r
142 for ($i = 0; $i<count($paramarray); $i++)
\r
143 $command .= ',$paramarray[' . $i . ']';
\r
145 eval($command); // execute the correct method
\r
148 function setProperty($property, $value) {
\r
150 $manager->setParserProperty($property, $value);
\r
153 function getProperty($name) {
\r
155 return $manager->getParserProperty($name);
\r