3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2009 The Nucleus Group
\r
6 * This program is free software; you can redistribute it and/or
\r
7 * modify it under the terms of the GNU General Public License
\r
8 * as published by the Free Software Foundation; either version 2
\r
9 * of the License, or (at your option) any later version.
\r
10 * (see nucleus/documentation/index.html#license for more info)
\r
13 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
14 * @copyright Copyright (C) 2002-2009 The Nucleus Group
\r
15 * @version $Id: PARSER.php 1757 2012-04-15 09:02:32Z sakamocchi $
\r
18 if ( !function_exists('requestVar') )
\r
22 require_once dirname(__FILE__) . '/BaseActions.php';
\r
25 * This is the parser class of Nucleus. It is used for various things
\r
26 * (skin parsing, form generation, ...)
\r
30 // array with the names of all allowed actions
\r
33 // reference to actions handler
\r
36 // delimiters that can be used for skin/templatevars
\r
39 // parameter delimiter (to separate skinvar params)
\r
42 // usually set to 0. When set to 1, all skinvars are allowed regardless of $actions
\r
43 public $norestrictions;
\r
46 * Parset::__construct()
\r
47 * Creates a new parser object with the given allowed actions
\r
48 * and the given handler
\r
50 * @param $allowedActions array
\r
51 * @param $handler class object with functions for each action (reference)
\r
52 * @param $delim optional delimiter
\r
53 * @param $paramdelim optional parameterdelimiter
\r
55 public function __construct($allowedActions, &$handler, $delim = '(<%|%>)', $pdelim = ',')
\r
57 $this->actions = $allowedActions;
\r
58 $this->handler =& $handler;
\r
59 $this->delim = $delim;
\r
60 $this->pdelim = $pdelim;
\r
61 $this->norestrictions = 0; // set this to 1 to disable checking for allowedActions
\r
66 * Parses the given contents and outputs it
\r
68 public function parse(&$contents)
\r
70 /* escaping only pcre delimiter */
\r
71 $pcre = preg_replace('#\##', '#', $this->delim);
\r
73 $pieces = preg_split("#{$pcre}#", $contents);
\r
75 $maxidx = sizeof($pieces);
\r
76 for ( $idx = 0; $idx < $maxidx; $idx++ )
\r
80 if ( $idx < $maxidx )
\r
82 $this->doAction($pieces[$idx]);
\r
90 * Parset::doAction()
\r
91 * Called from the parser to handle an action
\r
93 * @param string $action name of the action (e.g. blog, image ...)
\r
96 public function doAction($action)
\r
98 global $manager, $CONF;
\r
105 // split into action name + arguments
\r
106 if ( i18n::strpos($action, '(') != FALSE )
\r
108 $paramStartPos = i18n::strpos($action, '(');
\r
109 $params = i18n::substr($action, $paramStartPos + 1, i18n::strlen($action) - $paramStartPos - 2);
\r
110 $action = i18n::substr($action, 0, $paramStartPos);
\r
111 $params = preg_split ('#' . preg_quote($this->pdelim, '#') . '#', $params);
\r
112 $params = array_map('trim', $params);
\r
120 $actionlc = strtolower($action);
\r
121 // skip execution of skinvars while inside an if condition which hides this part of the page
\r
122 $if_tags = array('else', 'elseif', 'endif', 'ifnot', 'elseifnot');
\r
123 if ( !$this->handler->getTopIfCondition()
\r
124 && !in_array($actionlc, $if_tags)
\r
125 && (i18n::substr($actionlc, 0, 2) != 'if') )
\r
130 if ( in_array($actionlc, $this->actions) || $this->norestrictions )
\r
132 call_user_func_array(array(&$this->handler, "parse_{$actionlc}"), $params);
\r
136 // redirect to plugin action if possible
\r
137 if ( in_array('plugin', $this->actions) && $manager->pluginInstalled("NP_{$action}") )
\r
139 $this->doAction('plugin(' . $action . $this->pdelim . implode($this->pdelim,$params) . ')');
\r
143 if ( $CONF['DebugVars']==true )
\r
145 echo '<%' , $action , '(', implode($this->pdelim, $params), ')%>';
\r
153 * Parser::setProperty()
\r
154 * Set a property of the parser in the manager
\r
157 * @param string $property additional parser property (e.g. include prefix of the skin)
\r
158 * @param string $value new value
\r
161 static public function setProperty($property, $value)
\r
164 $manager->setParserProperty($property, $value);
\r
169 * Parser::getProperty()
\r
170 * Get a property of the parser from the manager
\r
173 * @param string $name name of the property
\r
174 * @return string value of the property
\r
176 static public function getProperty($name)
\r
179 return $manager->getParserProperty($name);
\r