* Parse a SKIN\r
* \r
* @param string $type\r
+ * @param string $path path to file if using fileparser\r
* @return void\r
*/\r
- public function parse($type)\r
+ public function parse($type, $path='')\r
{\r
- global $currentSkinName, $manager, $CONF;\r
+ global $currentSkinName, $manager, $CONF, $DIR_NUCLEUS;\r
\r
$manager->notify("Init{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));\r
\r
\r
// set skin name as global var (so plugins can access it)\r
$currentSkinName = $this->getName();\r
- $contents = $this->getContent($type);\r
+ \r
+ $contents = FALSE;\r
+ if ( $type != 'fileparse' )\r
+ {\r
+ $contents = $this->getContent($type);\r
+ }\r
+ else if ( $path !== '' && i18n::strpos(realpath($path), realpath("$DIR_NUCLEUS/../")) == 0 )\r
+ {\r
+ $contents = $this->getFileContent($path);\r
+ }\r
\r
if ( !$contents )\r
{\r
\r
if ( sql_num_rows($res) == 0 )\r
{\r
- return '';\r
+ return FALSE;\r
}\r
return sql_result($res, 0, 0);\r
}\r
-\r
+ \r
+ /**\r
+ * Skin::getFileContent()\r
+ * \r
+ * @param string $fullpath fullpath to the file to parse\r
+ * @return mixed file contents or FALSE\r
+ */\r
+ public function getFileContent($fullpath)\r
+ {\r
+ $fsize = filesize($fullpath);\r
+ if ( $fsize <= 0 )\r
+ {\r
+ return;\r
+ }\r
+ \r
+ $fd = fopen ($fullpath, 'r');\r
+ if ( $fd === FALSE )\r
+ {\r
+ return FALSE;\r
+ }\r
+ \r
+ $contents = fread ($fd, $fsize);\r
+ if ( $contents === FALSE )\r
+ {\r
+ return FALSE;\r
+ }\r
+ \r
+ fclose ($fd);\r
+ return $contents;\r
+ }\r
+ \r
/**\r
* SKIN::update()\r
* Updates the contents for one part of the skin in the database\r
$itemid = intval($id);\r
}\r
\r
-function parseFile($filename, $includeMode = 'normal', $includePrefix = '') {\r
- $handler = new Actions('fileparser');\r
- $parser = new Parser(SKIN::getAllowedActionsForType('fileparser'), $handler);\r
- $handler->parser =& $parser;\r
-\r
- // set IncludeMode properties of parser\r
- Parser::setProperty('IncludeMode', $includeMode);\r
- Parser::setProperty('IncludePrefix', $includePrefix);\r
+function parseFile($filename, $includeMode = 'normal', $includePrefix = '')\r
+{\r
+ global $skinid;\r
\r
- if (!file_exists($filename) ) {\r
- doError('A file is missing');\r
+ if ( !$skinid || !existsID($skinid) )\r
+ {\r
+ $skin = new Skin($CONF['BaseSkin']);\r
+ }\r
+ else\r
+ {\r
+ $skin = new Skin($skinid);\r
}\r
\r
- $fsize = filesize($filename);\r
+ $oldIncludeMode = Parser::getProperty('IncludeMode');\r
+ $oldIncludePrefix = Parser::getProperty('IncludePrefix');\r
\r
- if ($fsize <= 0) {\r
- return;\r
- }\r
+ $skin->parse('fileparse', $filename);\r
\r
- // read file\r
- $fd = fopen ($filename, 'r');\r
- $contents = fread ($fd, $fsize);\r
- fclose ($fd);\r
+ Parser::setProperty('IncludeMode', $oldIncludeMode);\r
+ Parser::setProperty('IncludePrefix', $oldIncludePrefix);\r
\r
- // parse file contents\r
- $parser->parse($contents);\r
+ return;\r
}\r
\r
/**\r