OSDN Git Service

MERGE: リビジョン1778/1779のマージ。Skin::getFriendlyNames()のアクセス方法の変更
[nucleus-jp/nucleus-next.git] / nucleus / libs / PLUGINADMIN.php
1 <?php\r
2 \r
3 /*\r
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
5  * Copyright (C) 2002-2012 The Nucleus Group\r
6  *\r
7  * This program is free software; you can redistribute it and/or\r
8  * modify it under the terms of the GNU General Public License\r
9  * as published by the Free Software Foundation; either version 2\r
10  * of the License, or (at your option) any later version.\r
11  * (see nucleus/documentation/index.html#license for more info)\r
12  */\r
13 /**\r
14  * code to make it easier to create plugin admin areas\r
15  *\r
16  * @license http://nucleuscms.org/license.txt GNU General Public License\r
17  * @copyright Copyright (C) 2002-2012 The Nucleus Group\r
18  * @version $Id: PLUGINADMIN.php 1626 2012-01-09 15:46:54Z sakamocchi $\r
19  */\r
20 \r
21 class PluginAdmin\r
22 {\r
23         public $strFullName;            // NP_SomeThing\r
24         public $plugin;                 // ref. to plugin object\r
25         public $bValid;                 // evaluates to true when object is considered valid\r
26         public $admin;                  // ref to an admin object\r
27         \r
28         public function __construct($pluginName)\r
29         {\r
30                 global $manager, $DIR_LIBS;\r
31                 \r
32                 if ( !class_exists('Admin', FALSE) )\r
33                 {\r
34                         include($DIR_LIBS . 'ADMIN.php');\r
35                 }\r
36                 \r
37                 $this->strFullName = "NP_{$pluginName}";\r
38                 \r
39                 // check if plugin exists and is installed\r
40                 if ( !$manager->pluginInstalled($this->strFullName) )\r
41                 {\r
42                         doError(_ERROR_INVALID_PLUGIN);\r
43                 }\r
44                 \r
45                 $this->plugin =& $manager->getPlugin($this->strFullName);\r
46                 $this->bValid = $this->plugin;\r
47                 \r
48                 if ( !$this->bValid )\r
49                 {\r
50                         doError(_ERROR_INVALID_PLUGIN);\r
51                 }\r
52                 \r
53                 $this->admin = new Admin();\r
54                 $this->admin->action = "plugin_{$pluginName}";\r
55                 return;\r
56         }\r
57         \r
58         /**\r
59          * PluginAdmin::start()\r
60          * \r
61          * @param       string  $extraHead      child elements for header element\r
62          * @return      void\r
63          */\r
64         public function start($extraHead = '')\r
65         {\r
66                 global $CONF;\r
67                 $strBaseHref  = '<base href="' . Entity::hsc($CONF['AdminURL']) . '" />';\r
68                 $extraHead .= $strBaseHref;\r
69                 \r
70                 $this->admin->pagehead($extraHead);\r
71                 return;\r
72         }\r
73         \r
74         /**\r
75          * PluginAdmin::end()\r
76          * \r
77          * @param       void\r
78          * @return      void\r
79          */\r
80         public function end()\r
81         {\r
82                 $this->_AddTicketByJS();\r
83                 $this->admin->pagefoot();\r
84                 return;\r
85         }\r
86         \r
87         /**\r
88          * PluginAdmin::_AddTicketByJS()\r
89          * Add ticket when not used in plugin's admin page\r
90          * to avoid CSRF.\r
91          * \r
92          * @param       void\r
93          * @return      void\r
94          */\r
95         public function _AddTicketByJS()\r
96         {\r
97                 global $CONF,$ticketforplugin;\r
98                 if ( !($ticket=$ticketforplugin['ticket']) ) \r
99                 {\r
100                         return;\r
101                 }\r
102                 $ticket=Entity::hsc($ticket);\r
103 \r
104 ?><script type="text/javascript">\r
105 /*<![CDATA[*/\r
106 /* Add tickets for available links (outside blog excluded) */\r
107 for (i=0;document.links[i];i++){\r
108   if (document.links[i].href.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0\r
109     && !(document.links[i].href.indexOf('//',0)<0)) continue;\r
110   if ((j=document.links[i].href.indexOf('?',0))<0) continue;\r
111   if (document.links[i].href.indexOf('ticket=',j)>=0) continue;\r
112   document.links[i].href=document.links[i].href.substring(0,j+1)+'ticket=<?php echo $ticket; ?>&'+document.links[i].href.substring(j+1);\r
113 }\r
114 /* Add tickets for forms (outside blog excluded) */\r
115 for (i=0;document.forms[i];i++){\r
116   /* check if ticket is already used */\r
117   for (j=0;document.forms[i].elements[j];j++) {\r
118     if (document.forms[i].elements[j].name=='ticket') {\r
119       j=-1;\r
120       break;\r
121     }\r
122   }\r
123   if (j==-1) continue;\r
124  \r
125   /* check if the modification works */\r
126   try{document.forms[i].innerHTML+='';}catch(e){\r
127     /* Modificaion falied: this sometime happens on IE */\r
128     if (!document.forms[i].action.name && document.forms[i].method.toUpperCase()=="POST") {\r
129       /* <input name="action"/> is not used for POST method*/\r
130       if (document.forms[i].action.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0\r
131         && !(document.forms[i].action.indexOf('//',0)<0)) continue;\r
132       if (0<(j=document.forms[i].action.indexOf('?',0))) if (0<document.forms[i].action.indexOf('ticket=',j)) continue;\r
133       if (j<0) document.forms[i].action+='?'+'ticket=<?php echo $ticket; ?>';\r
134       else document.forms[i].action+='&'+'ticket=<?php echo $ticket; ?>';\r
135       continue;\r
136     }\r
137     document.write('<?php echo _PLUGINADMIN_TICKETS_JAVASCRIPT ?>');\r
138     j=document.forms[i].outerHTML;\r
139     while (j!=j.replace('<','&lt;')) j=j.replace('<','&lt;');\r
140     document.write('<p>'+j+'</p>');\r
141     continue;\r
142   }\r
143   /* check the action paramer in form tag */\r
144   /* note that <input name="action"/> may be used here */\r
145   j=document.forms[i].innerHTML;\r
146   document.forms[i].innerHTML='';\r
147   if ((document.forms[i].action+'').indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0\r
148       && !((document.forms[i].action+'').indexOf('//',0)<0)) {\r
149     document.forms[i].innerHTML=j;\r
150     continue;\r
151   }\r
152   /* add ticket */\r
153   document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';\r
154 }\r
155 /*]]>*/\r
156 </script><?php\r
157         return;\r
158         }\r
159 }\r
160 \r