OSDN Git Service

Subversion由来のタグを削除
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / libs / PLUGINADMIN.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2012 The Nucleus Group
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * (see nucleus/documentation/index.html#license for more info)
12  *
13  * code to make it easier to create plugin admin areas
14  */
15
16 class PluginAdmin {\r
17 \r
18         var $strFullName;               // NP_SomeThing\r
19         var $plugin;                    // ref. to plugin object\r
20         var $bValid;                    // evaluates to true when object is considered valid\r
21         var $admin;                             // ref to an admin object\r
22 \r
23         function PluginAdmin($pluginName)\r
24         {\r
25                 global $manager, $DIR_LIBS;\r
26                 include_once($DIR_LIBS . 'ADMIN.php');
27                 \r
28                 $this->strFullName = 'NP_' . $pluginName;\r
29 \r
30                 // check if plugin exists and is installed\r
31                 if (!$manager->pluginInstalled($this->strFullName))\r
32                         doError(_ERROR_INVALID_PLUGIN);\r
33 \r
34                 $this->plugin =& $manager->getPlugin($this->strFullName);\r
35                 $this->bValid = $this->plugin;\r
36 \r
37                 if (!$this->bValid)\r
38                         doError(_ERROR_INVALID_PLUGIN);\r
39 \r
40                 $this->admin = new ADMIN();\r
41                 $this->admin->action = 'plugin_' . $pluginName;\r
42         }\r
43 \r
44         function start($extraHead = '')\r
45         {\r
46                 global $CONF;\r
47                 $strBaseHref  = '<base href="' . htmlspecialchars($CONF['AdminURL']) . '" />';\r
48                 $extraHead .= $strBaseHref;\r
49 \r
50                 $this->admin->pagehead($extraHead);\r
51         }\r
52 \r
53         function end()\r
54         {\r
55                 $this->_AddTicketByJS();\r
56                 $this->admin->pagefoot();\r
57         }\r
58 \r
59 /** \r
60  * Add ticket when not used in plugin's admin page\r
61  * to avoid CSRF.\r
62  */\r
63         function _AddTicketByJS(){\r
64                 global $CONF,$ticketforplugin;\r
65                 if (!($ticket=$ticketforplugin['ticket'])) {\r
66                         //echo "\n<!--TicketForPlugin skipped-->\n";\r
67                         return;\r
68                 }\r
69                 $ticket=htmlspecialchars($ticket,ENT_QUOTES);\r
70  \r
71 ?><script type="text/javascript">\r
72 /*<![CDATA[*/\r
73 /* Add tickets for available links (outside blog excluded) */\r
74 for (i=0;document.links[i];i++){\r
75   if (document.links[i].href.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0\r
76     && !(document.links[i].href.indexOf('//',0)<0)) continue;\r
77   if ((j=document.links[i].href.indexOf('?',0))<0) continue;\r
78   if (document.links[i].href.indexOf('ticket=',j)>=0) continue;\r
79   document.links[i].href=document.links[i].href.substring(0,j+1)+'ticket=<?php echo $ticket; ?>&'+document.links[i].href.substring(j+1);\r
80 }\r
81 /* Add tickets for forms (outside blog excluded) */\r
82 for (i=0;document.forms[i];i++){\r
83   /* check if ticket is already used */\r
84   for (j=0;document.forms[i].elements[j];j++) {\r
85     if (document.forms[i].elements[j].name=='ticket') {\r
86       j=-1;\r
87       break;\r
88     }\r
89   }\r
90   if (j==-1) continue;\r
91  \r
92   /* check if the modification works */\r
93   try{document.forms[i].innerHTML+='';}catch(e){\r
94     /* Modificaion falied: this sometime happens on IE */\r
95     if (!document.forms[i].action.name && document.forms[i].method.toUpperCase()=="POST") {\r
96       /* <input name="action"/> is not used for POST method*/\r
97       if (document.forms[i].action.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0\r
98         && !(document.forms[i].action.indexOf('//',0)<0)) continue;\r
99       if (0<(j=document.forms[i].action.indexOf('?',0))) if (0<document.forms[i].action.indexOf('ticket=',j)) continue;\r
100       if (j<0) document.forms[i].action+='?'+'ticket=<?php echo $ticket; ?>';\r
101       else document.forms[i].action+='&'+'ticket=<?php echo $ticket; ?>';\r
102       continue;\r
103     }\r
104     document.write('<?php echo _PLUGINADMIN_TICKETS_JAVASCRIPT ?>');\r
105     j=document.forms[i].outerHTML;\r
106     while (j!=j.replace('<','&lt;')) j=j.replace('<','&lt;');\r
107     document.write('<p>'+j+'</p>');\r
108     continue;\r
109   }\r
110   /* check the action paramer in form tag */\r
111   /* note that <input name="action"/> may be used here */\r
112   j=document.forms[i].innerHTML;\r
113   document.forms[i].innerHTML='';\r
114   if ((document.forms[i].action+'').indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0\r
115       && !((document.forms[i].action+'').indexOf('//',0)<0)) {\r
116     document.forms[i].innerHTML=j;\r
117     continue;\r
118   }\r
119   /* add ticket */\r
120   document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';\r
121 }\r
122 /*]]>*/\r
123 </script><?php\r
124  \r
125         }\r
126 }\r
127 \r
128 \r
129 \r
130 ?>