OSDN Git Service

Modify JavaScript parse error in item edit page when the login user turn it off to...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / PAGEFACTORY.php
index 60d9fc6..3a2a7eb 100755 (executable)
@@ -1,19 +1,23 @@
 <?php\r
+/*\r
+ * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
+ * Copyright (C) 2002-2010 The Nucleus Group\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * (see nucleus/documentation/index.html#license for more info)\r
+ */\r
 /**\r
-  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) \r
-  * Copyright (C) 2002-2005 The Nucleus Group\r
-  *\r
-  * This program is free software; you can redistribute it and/or\r
-  * modify it under the terms of the GNU General Public License\r
-  * as published by the Free Software Foundation; either version 2\r
-  * of the License, or (at your option) any later version.\r
-  * (see nucleus/documentation/index.html#license for more info)\r
-  *\r
-  * $Id: PAGEFACTORY.php,v 1.3 2005-03-12 06:19:05 kimitake Exp $\r
-  */\r
+ * @license http://nucleuscms.org/license.txt GNU General Public License\r
+ * @copyright Copyright (C) 2002-2010 The Nucleus Group\r
+ * @version $Id$\r
+ * $NucleusJP: PAGEFACTORY.php,v 1.8.2.2 2007/10/30 16:12:27 shizuki Exp $\r
+ */\r
 \r
 /**\r
- * The formfactory class can be used to insert add/edit item forms into \r
+ * The formfactory class can be used to insert add/edit item forms into\r
  * admin area, bookmarklet, skins or any other places where such a form\r
  * might be needed\r
  */\r
@@ -21,17 +25,17 @@ class PAGEFACTORY extends BaseActions {
 \r
        // ref to the blog object for which an add:edit form is created\r
        var $blog;\r
-       \r
+\r
        // allowed actions (for parser)\r
        var $actions;\r
-       \r
+\r
        // allowed types of forms (bookmarklet/admin)\r
        var $allowedTypes;\r
        var $type;              // one of the types in $allowedTypes\r
-       \r
+\r
        // 'add' or 'edit'\r
        var $method;\r
-       \r
+\r
        // info to fill out in the form (e.g. catid, itemid, ...)\r
        var $variables;\r
 \r
@@ -40,15 +44,15 @@ class PAGEFACTORY extends BaseActions {
         */\r
        function PAGEFACTORY($blogid) {\r
                // call constructor of superclass first\r
-               $this->BaseActions();                   \r
-               \r
+               $this->BaseActions();\r
+\r
                global $manager;\r
                $this->blog =& $manager->getBlog($blogid);\r
-               \r
-               // TODO: move the definition of actions to the createXForm \r
+\r
+               // TODO: move the definition of actions to the createXForm\r
                // methods\r
                $this->actions = Array(\r
-                       'actionurl', \r
+                       'actionurl',\r
                        'title',\r
                        'body',\r
                        'more',\r
@@ -73,41 +77,44 @@ class PAGEFACTORY extends BaseActions {
                        'pluginextras',\r
                        'itemoptions',\r
                        'extrahead',\r
-                       'ticket'\r
+                       'ticket',\r
+                       'autosave',\r
+                       'autosaveinfo',\r
+                       'ifautosave'\r
                );\r
-               \r
+\r
                // TODO: maybe add 'skin' later on?\r
                // TODO: maybe add other pages from admin area\r
-               $this->allowedTypes = Array('bookmarklet','admin');     \r
+               $this->allowedTypes = Array('bookmarklet','admin');\r
        }\r
 \r
        /**\r
         * creates a "add item" form for a given type of page\r
         *\r
         * @param type\r
-        *              'admin' or 'bookmarklet' \r
+        *              'admin' or 'bookmarklet'\r
         */\r
        function createAddForm($type, $contents = array()) {\r
                if (!in_array($type, $this->allowedTypes))\r
                        return;\r
                $this->type = $type;\r
                $this->method = 'add';\r
-               \r
+\r
                global $manager;\r
                $manager->notify('PreAddItemForm', array('contents' => &$contents, 'blog' => &$this->blog));\r
-               \r
+\r
                $this->createForm($contents);\r
        }\r
-       \r
+\r
        /**\r
         * creates a "add item" form for a given type of page\r
         *\r
         * @param type\r
-        *              'admin' or 'bookmarklet' \r
+        *              'admin' or 'bookmarklet'\r
         * @param contents\r
         *              An associative array\r
         *                      'author' => author\r
-        *                      '' => \r
+        *                      '' =>\r
         */\r
        function createEditForm($type, $contents) {\r
                if (!in_array($type, $this->allowedTypes))\r
@@ -116,68 +123,68 @@ class PAGEFACTORY extends BaseActions {
                $this->method = 'edit';\r
                $this->createForm($contents);\r
        }\r
-       \r
+\r
        /**\r
         * (private) creates a form for a given type of page\r
         */\r
        function createForm($contents) {\r
                // save contents\r
                $this->variables = $contents;\r
-               \r
+\r
                // get template to use\r
                $template = $this->getTemplateFor($this->type);\r
-               \r
+\r
                // use the PARSER engine to parse that template\r
                $parser =& new PARSER($this->actions, $this);\r
                $parser->parse($template);\r
        }\r
-       \r
+\r
        /**\r
         * returns an appropriate template\r
         */\r
        function getTemplateFor($type) {\r
                global $DIR_LIBS;\r
-               \r
+\r
                $filename = $DIR_LIBS . 'include/' . $this->type . '-' . $this->method . '.template';\r
-               \r
-               if (!file_exists($filename)) \r
+\r
+               if (!file_exists($filename))\r
                        return '';\r
 \r
                $fsize = filesize($filename);\r
                if ($fsize <= 0)\r
                        return '';\r
-                       \r
+\r
                // read file and return it\r
                $fd = fopen ($filename, 'r');\r
                $contents = fread ($fd, $fsize);\r
                fclose ($fd);\r
-               \r
+\r
                return $contents;\r
-               \r
+\r
        }\r
-       \r
+\r
        // create category dropdown box\r
        function parse_categories($startidx = 0) {\r
-                       if ($this->variables['catid']) \r
+                       if ($this->variables['catid'])\r
                                $catid = $this->variables['catid'];                             // on edit item\r
                        else\r
                                $catid = $this->blog->getDefaultCategory();             // on add item\r
-                       \r
+\r
                        ADMIN::selectBlogCategory('catid',$catid,$startidx,1,$this->blog->getID());\r
        }\r
-       \r
+\r
        function parse_blogid() {\r
                echo $this->blog->getID();\r
        }\r
-       \r
+\r
        function parse_blogname() {\r
                echo $this->blog->getName();\r
        }\r
-       \r
+\r
        function parse_bloglink() {\r
-               echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.$this->blog->getName().'</a>';\r
+               echo '<a href="'.htmlspecialchars($this->blog->getURL()).'">'.htmlspecialchars($this->blog->getName()).'</a>';\r
        }\r
-       \r
+\r
        function parse_authorname() {\r
                // don't use on add item?\r
                global $member;\r
@@ -190,7 +197,7 @@ class PAGEFACTORY extends BaseActions {
 \r
        /**\r
         * Indicates the start of a conditional block of data. It will be added to\r
-        * the output only if the blogsetting with the given name equals the \r
+        * the output only if the blogsetting with the given name equals the\r
         * given value (default for value = 1 = true)\r
         *\r
         * the name of the blogsetting is the column name in the nucleus_blog table\r
@@ -200,97 +207,109 @@ class PAGEFACTORY extends BaseActions {
        function parse_ifblogsetting($name,$value=1) {\r
                $this->_addIfCondition(($this->blog->getSetting($name) == $value));\r
        }\r
-       \r
+\r
        function parse_ifitemproperty($name,$value=1) {\r
                $this->_addIfCondition(($this->variables[$name] == $value));\r
        }\r
-       \r
+\r
+       function parse_ifautosave($name,$value=1) {\r
+               global $member;\r
+               $this->_addIfCondition($member->getAutosave() == $value);\r
+       }\r
+\r
        function parse_helplink($topic) {\r
                help($topic);\r
        }\r
-       \r
+\r
        // for future items\r
        function parse_currenttime($what) {\r
                $nu = getdate($this->blog->getCorrectTime());\r
                echo $nu[$what];\r
        }\r
-       \r
+\r
        // date change on edit item\r
        function parse_itemtime($what) {\r
                $itemtime = getdate($this->variables['timestamp']);\r
                echo $itemtime[$what];\r
        }\r
-       \r
+\r
        // some init stuff for all forms\r
        function parse_init() {\r
                $authorid = ($this->method == 'edit') ? $this->variables['authorid'] : '';\r
-               $this->blog->insertJavaScriptInfo($authorid);           \r
+               $this->blog->insertJavaScriptInfo($authorid);\r
        }\r
-       \r
+\r
        // on bookmarklets only: insert extra html header information (by plugins)\r
        function parse_extrahead() {\r
                global $manager;\r
-               \r
+\r
                $extrahead = '';\r
-               \r
+\r
                $manager->notify(\r
                        'BookmarkletExtraHead',\r
                        array(\r
                                'extrahead' => &$extrahead\r
                        )\r
                );\r
-               \r
+\r
                echo $extrahead;\r
        }\r
-       \r
+\r
        // inserts some localized text\r
        function parse_text($which) {\r
                // constant($which) only available from 4.0.4 :(\r
-               if (defined($which)) {  \r
+               if (defined($which)) {\r
                        eval("echo $which;");\r
                } else {\r
                        echo $which;    // this way we see where definitions are missing\r
                }\r
-               \r
+\r
        }\r
-       \r
+\r
        function parse_contents($which) {\r
-               echo htmlspecialchars($this->variables[$which]);\r
+               if (!isset($this->variables[$which])) $this->variables[$which] = '';\r
+               echo htmlspecialchars($this->variables[$which],ENT_QUOTES);\r
        }\r
-       \r
+\r
        function parse_checkedonval($value, $name) {\r
+               if (!isset($this->variables[$name])) $this->variables[$name] = '';\r
                if ($this->variables[$name] == $value)\r
-                       echo "checked='checked'";\r
+                       echo 'checked="checked"';\r
        }\r
-       \r
+\r
        // extra javascript for input and textarea fields\r
        function parse_jsinput($which) {\r
-               global $CONF;\r
-       ?>\r
-                       name="<?php echo $which?>" \r
-                       id="input<?php echo $which?>" \r
-       <?php\r
-               if ($CONF['DisableJsTools'] != 1) {\r
-       ?>\r
-                       onkeyup="storeCaret(this); updPreview('<?php echo $which?>');"\r
-                       onclick="storeCaret(this);"\r
-                       onselect="storeCaret(this);" \r
-\r
-       <?php           \r
-               } \r
+               global $CONF, $member;\r
                \r
-               if ($CONF['DisableJsTools'] == 0) {\r
-       ?>\r
-                   onkeypress="shortCuts();"                   \r
-       <?php           }\r
+               $attributes  = " name=\"{$which}\"";\r
+               $attributes .= " id=\"input{$which}\"";\r
+               \r
+               if ($CONF['DisableJsTools'] != 1) {\r
+                       $attributes .= ' onclick="storeCaret(this);"';\r
+                       $attributes .= ' onselect="storeCaret(this);"';\r
+                       if ($member->getAutosave()) {\r
+                               $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}'); doMonitor();\"";\r
+                       } else {\r
+                               $attributes .= " onkeyup=\"storeCaret(this); updPreview('{$which}');\"";\r
+                       }\r
+               }\r
+               else {\r
+                       if ($CONF['DisableJsTools'] == 0) {\r
+                               $attributes .= ' onkeypress="shortCuts();"';\r
+                       }\r
+                       if ($member->getAutosave()) {\r
+                               $attributes .= ' onkeyup="doMonitor();"';\r
+                       }\r
+               }\r
+               echo $attributes;\r
        }\r
-       \r
+\r
        // shows the javascript button bar\r
        function parse_jsbuttonbar($extrabuttons = "") {\r
                global $CONF;\r
                switch($CONF['DisableJsTools']) {\r
 \r
-                       case "0":       \r
+                       case "0":\r
                                echo '<div class="jsbuttonbar">';\r
 \r
                                        $this->_jsbutton('cut','cutThis()',_ADD_CUT_TT . " (Ctrl + X)");\r
@@ -300,47 +319,47 @@ class PAGEFACTORY extends BaseActions {
                                        $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT ." (Ctrl + Shift + B)");\r
                                        $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT ." (Ctrl + Shift + I)");\r
                                        $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT ." (Ctrl + Shift + A)");\r
-                                       $this->_jsbuttonspacer();                                       \r
+                                       $this->_jsbuttonspacer();\r
                                        $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);\r
                                        $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);\r
                                        $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);\r
-                                       $this->_jsbuttonspacer();                                       \r
+                                       $this->_jsbuttonspacer();\r
                                        $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);\r
                                        $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);\r
 \r
-                               \r
+\r
                                        if ($extrabuttons) {\r
                                                $btns = explode('+',$extrabuttons);\r
                                                $this->_jsbuttonspacer();\r
                                                foreach ($btns as $button) {\r
                                                        switch($button) {\r
                                                                case "media":\r
-                                                                       $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT .   " (Ctrl + Shift + M)");                                                 \r
+                                                                       $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT .   " (Ctrl + Shift + M)");\r
                                                                        break;\r
                                                                case "preview":\r
                                                                        $this->_jsbutton('preview',"showedit()",_ADD_PREVIEW_TT);\r
                                                                        break;\r
                                                        }\r
                                                }\r
-                                       } \r
-                                       \r
+                                       }\r
+\r
                                echo '</div>';\r
-                               \r
+\r
                                break;\r
                        case "2":\r
                                echo '<div class="jsbuttonbar">';\r
 \r
-                                       $this->_jsbutton('bold',"boldThis()",'');\r
-                                       $this->_jsbutton('italic',"italicThis()",'');\r
-                                       $this->_jsbutton('link',"ahrefThis()",'');\r
-                                       $this->_jsbuttonspacer();                                                                               \r
+                                       $this->_jsbutton('bold',"boldThis()",_ADD_BOLD_TT);\r
+                                       $this->_jsbutton('italic',"italicThis()",_ADD_ITALIC_TT);\r
+                                       $this->_jsbutton('link',"ahrefThis()",_ADD_HREF_TT);\r
+                                       $this->_jsbuttonspacer();\r
                                        $this->_jsbutton('alignleft',"alignleftThis()",_ADD_ALIGNLEFT_TT);\r
                                        $this->_jsbutton('alignright',"alignrightThis()",_ADD_ALIGNRIGHT_TT);\r
                                        $this->_jsbutton('aligncenter',"aligncenterThis()",_ADD_ALIGNCENTER_TT);\r
-                                       $this->_jsbuttonspacer();                                       \r
+                                       $this->_jsbuttonspacer();\r
                                        $this->_jsbutton('left',"leftThis()",_ADD_LEFT_TT);\r
                                        $this->_jsbutton('right',"rightThis()",_ADD_RIGHT_TT);\r
-                                       \r
+\r
 \r
                                        if ($extrabuttons) {\r
                                                $btns = explode('+',$extrabuttons);\r
@@ -348,34 +367,34 @@ class PAGEFACTORY extends BaseActions {
                                                foreach ($btns as $button) {\r
                                                        switch($button) {\r
                                                                case "media":\r
-                                                                       $this->_jsbutton('media',"addMedia()",'');                                                      \r
+                                                                       $this->_jsbutton('media',"addMedia()",_ADD_MEDIA_TT);\r
                                                                        break;\r
                                                        }\r
                                                }\r
-                                       } \r
-                                       \r
+                                       }\r
+\r
                                echo '</div>';\r
-                               \r
-                               break;                  \r
+\r
+                               break;\r
                }\r
        }\r
-       \r
+\r
        /**\r
         * Allows plugins to add their own custom fields\r
         */\r
        function parse_pluginextras() {\r
                global $manager;\r
-                       \r
+\r
                switch ($this->method) {\r
                        case 'add':\r
-                               $manager->notify('AddItemFormExtras', \r
+                               $manager->notify('AddItemFormExtras',\r
                                                array(\r
                                                        'blog' => &$this->blog\r
                                                )\r
                                );\r
                                break;\r
                        case 'edit':\r
-                               $manager->notify('EditItemFormExtras', \r
+                               $manager->notify('EditItemFormExtras',\r
                                                array(\r
                                                        'variables' => $this->variables,\r
                                                        'blog' => &$this->blog,\r
@@ -385,38 +404,38 @@ class PAGEFACTORY extends BaseActions {
                                break;\r
                }\r
        }\r
-       \r
+\r
        /**\r
         * Adds the itemOptions of a plugin to a page\r
         * @author TeRanEX\r
         */\r
-    function parse_itemoptions() {\r
+       function parse_itemoptions() {\r
                global $itemid;\r
                ADMIN::_insertPluginOptions('item', $itemid);\r
-    }\r
-    \r
-    function parse_ticket() {\r
-       global $manager;\r
-       $manager->addTicketHidden();\r
-    }\r
-       \r
+       }\r
+\r
+       function parse_ticket() {\r
+               global $manager;\r
+               $manager->addTicketHidden();\r
+       }\r
+\r
        /**\r
         * convenience method\r
         */\r
        function _jsbutton($type, $code ,$tooltip) {\r
        ?>\r
                        <span class="jsbutton"\r
-                               onmouseover="BtnHighlight(this);" \r
-                               onmouseout="BtnNormal(this);" \r
-                               onclick="<?php echo $code?>" >                  \r
-                               <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" width="16" height="16"/>\r
-                       </span>                         \r
+                               onmouseover="BtnHighlight(this);"\r
+                               onmouseout="BtnNormal(this);"\r
+                               onclick="<?php echo $code?>" >\r
+                               <img src="images/button-<?php echo $type?>.gif" alt="<?php echo $tooltip?>" title="<?php echo $tooltip?>" width="16" height="16"/>\r
+                       </span>\r
        <?php   }\r
        \r
        function _jsbuttonspacer() {\r
-               echo '<span class="jsbuttonspacer"></span>';\r
+               echo '<span class="jsbuttonspacer">&nbsp;</span>';\r
        }\r
-       \r
+\r
 }\r
\r
- ?>
\ No newline at end of file
+\r
+?>
\ No newline at end of file