* Parse a SKIN
*
* @param string $type
+ * @param string $path path to file if using fileparser
* @return void
*/
- public function parse($type)
+ public function parse($type, $path='')
{
- global $currentSkinName, $manager, $CONF;
+ global $currentSkinName, $manager, $CONF, $DIR_NUCLEUS;
$manager->notify("Init{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type));
// set skin name as global var (so plugins can access it)
$currentSkinName = $this->getName();
- $contents = $this->getContent($type);
+
+ $contents = FALSE;
+ if ( $type != 'fileparse' )
+ {
+ $contents = $this->getContent($type);
+ }
+ else if ( $path !== '' && i18n::strpos(realpath($path), realpath("$DIR_NUCLEUS/../")) == 0 )
+ {
+ $contents = $this->getFileContent($path);
+ }
if ( !$contents )
{
}
}
- $actions = $this->getAllowedActionsForType($type);
-
$manager->notify("Pre{$this->event_identifier}Parse", array('skin' => &$this, 'type' => $type, 'contents' => &$contents));
// set IncludeMode properties of parser
$action_class = $this->action_class;
$handler = new $action_class($type);
+ $actions = $handler->getDefinedActions($type);
$parser = new Parser($actions, $handler);
+
$handler->setParser($parser);
$handler->setSkin($this);
$parser->parse($contents);
if ( sql_num_rows($res) == 0 )
{
- return '';
+ return FALSE;
}
return sql_result($res, 0, 0);
}
-
+
+ /**
+ * Skin::getFileContent()
+ *
+ * @param string $fullpath fullpath to the file to parse
+ * @return mixed file contents or FALSE
+ */
+ public function getFileContent($fullpath)
+ {
+ $fsize = filesize($fullpath);
+ if ( $fsize <= 0 )
+ {
+ return;
+ }
+
+ $fd = fopen ($fullpath, 'r');
+ if ( $fd === FALSE )
+ {
+ return FALSE;
+ }
+
+ $contents = fread ($fd, $fsize);
+ if ( $contents === FALSE )
+ {
+ return FALSE;
+ }
+
+ fclose ($fd);
+ return $contents;
+ }
+
/**
* SKIN::update()
* Updates the contents for one part of the skin in the database
$includeMode = sql_real_escape_string($includeMode);
$includePrefix = sql_real_escape_string($includePrefix);
- $query ="UPDATE %s SET sdname='', sddesc='%s', sdtype='%s', sdincmode='%s', sdincpref='%s' WHERE sdnumber=%d:";
- $query = sprintf($query, $name, $desc, $type, $includeMode, $includePrefix, (integer) $this->id);
+ $query ="UPDATE %s SET sdname='%s', sddesc='%s', sdtype='%s', sdincmode='%s', sdincpref='%s' WHERE sdnumber=%d";
+ $query = sprintf($query, sql_table('skin_desc'), $name, $desc, $type, $includeMode, $includePrefix, (integer) $this->id);
sql_query($query);
return;