3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2009 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-2009 The Nucleus Group
16 * @version $Id: PARSER.php 1757 2012-04-15 09:02:32Z sakamocchi $
18 * @version $Id: PARSER.php 1879 2012-06-17 07:45:09Z sakamocchi $
19 >>>>>>> skinnable-master
22 if ( !function_exists('requestVar') )
26 require_once dirname(__FILE__) . '/BaseActions.php';
29 * This is the parser class of Nucleus. It is used for various things
30 * (skin parsing, form generation, ...)
34 // array with the names of all allowed actions
37 // reference to actions handler
40 // reference to an instance of Skin class
43 // delimiters that can be used for skin/templatevars
46 // parameter delimiter (to separate skinvar params)
49 // usually set to 0. When set to 1, all skinvars are allowed regardless of $actions
50 public $norestrictions;
53 * Parset::__construct()
54 * Creates a new parser object with the given allowed actions
55 * and the given handler
57 * @param $handler class object with functions for each action (reference)
58 * @param $delim optional delimiter
59 * @param $paramdelim optional parameterdelimiter
61 public function __construct( &$handler, $delim = '(<%|%>)', $pdelim = ',')
63 $this->handler = &$handler;
64 $this->actions = $handler->getAvailableActions();
65 $this->delim = $delim;
66 $this->pdelim = $pdelim;
67 $this->norestrictions = 0; // set this to 1 to disable checking for allowedActions
73 >>>>>>> skinnable-master
74 $handler->setParser($this);
80 * Parses the given contents and outputs it
82 public function parse(&$contents)
84 /* escaping only pcre delimiter */
85 $pcre = preg_replace('#\##', '#', $this->delim);
87 $pieces = preg_split("#{$pcre}#", $contents);
89 $maxidx = sizeof($pieces);
90 for ( $idx = 0; $idx < $maxidx; $idx++ )
96 $this->doAction($pieces[$idx]);
105 * Called from the parser to handle an action
107 * @param string $action name of the action (e.g. blog, image ...)
110 public function doAction($action)
112 global $manager, $CONF;
119 // split into action name + arguments
120 if ( i18n::strpos($action, '(') != FALSE )
122 $paramStartPos = i18n::strpos($action, '(');
123 $params = i18n::substr($action, $paramStartPos + 1, i18n::strlen($action) - $paramStartPos - 2);
124 $action = i18n::substr($action, 0, $paramStartPos);
125 $params = preg_split ('#' . preg_quote($this->pdelim, '#') . '#', $params);
126 $params = array_map('trim', $params);
134 $actionlc = strtolower($action);
136 // skip execution of skinvars while inside an if condition which hides this part of the page
137 $if_tags = array('else', 'elseif', 'endif', 'ifnot', 'elseifnot');
138 if ( !$this->handler->getTopIfCondition()
139 && !in_array($actionlc, $if_tags)
140 && (i18n::substr($actionlc, 0, 2) != 'if') )
145 if ( in_array($actionlc, $this->actions) || $this->norestrictions )
148 call_user_func_array(array(&$this->handler, "parse_{$actionlc}"), $params);
150 call_user_func_array(array($this->handler, "parse_{$actionlc}"), $params);
151 >>>>>>> skinnable-master
155 // redirect to plugin action if possible
156 if ( in_array('plugin', $this->actions) && $manager->pluginInstalled("NP_{$action}") )
158 $this->doAction('plugin(' . $action . $this->pdelim . implode($this->pdelim,$params) . ')');
162 if ( $CONF['DebugVars']==true )
164 echo '<%' , $action , '(', implode($this->pdelim, $params), ')%>';
174 * @param object $skin an instance of Skin class
177 public function setSkin(&$skin)
179 $this->skin = &$skin;
184 * Parser::setProperty()
185 * Set a property of the parser in the manager
188 * @param string $property additional parser property (e.g. include prefix of the skin)
189 * @param string $value new value
192 static public function setProperty($property, $value)
195 $manager->setParserProperty($property, $value);
200 * Parser::getProperty()
201 * Get a property of the parser from the manager
204 * @param string $name name of the property
205 * @return string value of the property
207 static public function getProperty($name)
210 return $manager->getParserProperty($name);