OSDN Git Service

MERGE: リビジョン1775のマージ。fileparseスキンタイプを使用可能に
authorsakamocchi <o-takashi@sakamocchi.jp>
Sat, 21 Apr 2012 05:29:58 +0000 (14:29 +0900)
committersakamocchi <o-takashi@sakamocchi.jp>
Sat, 21 Apr 2012 05:29:58 +0000 (14:29 +0900)
開発者用ドキュメントのプラグイン
APIを参照すると、InitSkinParse/PreSkinParse/PostSkinParseの各イベントでfileparseスキンタイプをキャッチ可能とあるが、実装はそうなってはいない。
http://japan.nucleuscms.org/nucleus/documentation/devdocs/plugins.html

Skinクラスのインスタンスがファイルの内容をパースできるように修正し、併せてglobalfunctions.phpのparseFile()関数も修正。正しくイベントが発生するようにした。

Revision 1775:
CHANGE: add 'fileparse' skin type to Skin class and modification for
parseFile() in globalfunctions.php
Refering to Plugin API in Nucleus CMS's documentation, fileparse skin
type is generated in events related to parse skin but actually it didn't
happen. This commit enable it.
http://nucleuscms.svn.sourceforge.net/viewvc/nucleuscms?view=revision&revision=1775

nucleus/libs/SKIN.php
nucleus/libs/globalfunctions.php

index b35844d..9bcc04d 100644 (file)
@@ -321,11 +321,12 @@ class Skin
         * 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));
                
@@ -334,7 +335,16 @@ class Skin
                
                // 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 )
                {
@@ -383,11 +393,41 @@ class Skin
                
                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
index fb34ec9..acff99b 100644 (file)
@@ -1407,32 +1407,28 @@ function selectItem($id) {
     $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
-\r
-    if (!file_exists($filename) ) {\r
-        doError('A file is missing');\r
+function parseFile($filename, $includeMode = 'normal', $includePrefix = '')
+{
+       global $skinid;
+\r
+       if ( !$skinid || !existsID($skinid) )
+       {
+               $skin = new Skin($CONF['BaseSkin']);
+       }
+       else
+       {
+               $skin = new Skin($skinid);
     }\r
 \r
-    $fsize = filesize($filename);\r
+       $oldIncludeMode = Parser::getProperty('IncludeMode');
+       $oldIncludePrefix = Parser::getProperty('IncludePrefix');
 \r
-    if ($fsize <= 0) {\r
-        return;\r
-    }\r
+       $skin->parse('fileparse', $filename);
 \r
-    // read file\r
-    $fd = fopen ($filename, 'r');\r
-    $contents = fread ($fd, $fsize);\r
-    fclose ($fd);\r
+       Parser::setProperty('IncludeMode', $oldIncludeMode);
+       Parser::setProperty('IncludePrefix', $oldIncludePrefix);
 \r
-    // parse file contents\r
-    $parser->parse($contents);\r
+       return;
 }\r
 \r
 /**\r