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
122 // skip execution of skinvars while inside an if condition which hides this part of the page
\r
123 $if_tags = array('else', 'elseif', 'endif', 'ifnot', 'elseifnot');
\r
124 if ( !$this->handler->getTopIfCondition()
\r
125 && !in_array($actionlc, $if_tags)
\r
126 && (i18n::substr($actionlc, 0, 2) != 'if') )
\r
131 if ( in_array($actionlc, $this->actions) || $this->norestrictions )
\r
133 call_user_func_array(array(&$this->handler, "parse_{$actionlc}"), $params);
\r
137 // redirect to plugin action if possible
\r
138 if ( in_array('plugin', $this->actions) && $manager->pluginInstalled("NP_{$action}") )
\r
140 $this->doAction('plugin(' . $action . $this->pdelim . implode($this->pdelim,$params) . ')');
\r
144 if ( $CONF['DebugVars']==true )
\r
146 echo '<%' , $action , '(', implode($this->pdelim, $params), ')%>';
\r
154 * Parser::setProperty()
\r
155 * Set a property of the parser in the manager
\r
158 * @param string $property additional parser property (e.g. include prefix of the skin)
\r
159 * @param string $value new value
\r
162 static public function setProperty($property, $value)
\r
165 $manager->setParserProperty($property, $value);
\r
170 * Parser::getProperty()
\r
171 * Get a property of the parser from the manager
\r
174 * @param string $name name of the property
\r
175 * @return string value of the property
\r
177 static public function getProperty($name)
\r
180 return $manager->getParserProperty($name);
\r