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 $handler class object with functions for each action (reference)
\r
51 * @param $delim optional delimiter
\r
52 * @param $paramdelim optional parameterdelimiter
\r
54 public function __construct( &$handler, $delim = '(<%|%>)', $pdelim = ',')
\r
56 $this->handler = &$handler;
\r
57 $this->actions = $handler->getAvailableActions();
\r
58 $this->delim = $delim;
\r
59 $this->pdelim = $pdelim;
\r
60 $this->norestrictions = 0; // set this to 1 to disable checking for allowedActions
\r
62 $handler->setParser($this);
\r
68 * Parses the given contents and outputs it
\r
70 public function parse(&$contents)
\r
72 /* escaping only pcre delimiter */
\r
73 $pcre = preg_replace('#\##', '#', $this->delim);
\r
75 $pieces = preg_split("#{$pcre}#", $contents);
\r
77 $maxidx = sizeof($pieces);
\r
78 for ( $idx = 0; $idx < $maxidx; $idx++ )
\r
82 if ( $idx < $maxidx )
\r
84 $this->doAction($pieces[$idx]);
\r
92 * Parset::doAction()
\r
93 * Called from the parser to handle an action
\r
95 * @param string $action name of the action (e.g. blog, image ...)
\r
98 public function doAction($action)
\r
100 global $manager, $CONF;
\r
107 // split into action name + arguments
\r
108 if ( i18n::strpos($action, '(') != FALSE )
\r
110 $paramStartPos = i18n::strpos($action, '(');
\r
111 $params = i18n::substr($action, $paramStartPos + 1, i18n::strlen($action) - $paramStartPos - 2);
\r
112 $action = i18n::substr($action, 0, $paramStartPos);
\r
113 $params = preg_split ('#' . preg_quote($this->pdelim, '#') . '#', $params);
\r
114 $params = array_map('trim', $params);
\r
122 $actionlc = strtolower($action);
\r
123 // skip execution of skinvars while inside an if condition which hides this part of the page
\r
124 $if_tags = array('else', 'elseif', 'endif', 'ifnot', 'elseifnot');
\r
125 if ( !$this->handler->getTopIfCondition()
\r
126 && !in_array($actionlc, $if_tags)
\r
127 && (i18n::substr($actionlc, 0, 2) != 'if') )
\r
132 if ( in_array($actionlc, $this->actions) || $this->norestrictions )
\r
134 call_user_func_array(array(&$this->handler, "parse_{$actionlc}"), $params);
\r
138 // redirect to plugin action if possible
\r
139 if ( in_array('plugin', $this->actions) && $manager->pluginInstalled("NP_{$action}") )
\r
141 $this->doAction('plugin(' . $action . $this->pdelim . implode($this->pdelim,$params) . ')');
\r
145 if ( $CONF['DebugVars']==true )
\r
147 echo '<%' , $action , '(', implode($this->pdelim, $params), ')%>';
\r
155 * Parser::setProperty()
\r
156 * Set a property of the parser in the manager
\r
159 * @param string $property additional parser property (e.g. include prefix of the skin)
\r
160 * @param string $value new value
\r
163 static public function setProperty($property, $value)
\r
166 $manager->setParserProperty($property, $value);
\r
171 * Parser::getProperty()
\r
172 * Get a property of the parser from the manager
\r
175 * @param string $name name of the property
\r
176 * @return string value of the property
\r
178 static public function getProperty($name)
\r
181 return $manager->getParserProperty($name);
\r