OSDN Git Service

Fix bug, getOption() values are not reflected after changing them by using admin...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / PLUGINADMIN.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2007 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 /**
14  * code to make it easier to create plugin admin areas
15  *
16  * @license http://nucleuscms.org/license.txt GNU General Public License
17  * @copyright Copyright (C) 2002-2007 The Nucleus Group
18  * @version $Id: PLUGINADMIN.php,v 1.8 2007-03-22 03:30:14 kmorimatsu Exp $
19  * $NucleusJP: PLUGINADMIN.php,v 1.7 2007/02/06 09:00:24 kimitake Exp $
20  */
21
22 global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS;
23 $aVarsToCheck = array('HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_ENV_VARS', 'HTTP_SESSION_VARS', 'HTTP_POST_FILES', 'HTTP_SERVER_VARS', 'GLOBALS', 'argv', 'argc', '_GET', '_POST', '_COOKIE', '_ENV', '_SESSION', '_SERVER', '_FILES', 'DIR_LIBS');
24
25 foreach ($aVarsToCheck as $varName)
26 {
27         if (phpversion() >= '4.1.0')
28         {
29                 if (   isset($_GET[$varName])
30                         || isset($_POST[$varName])
31                         || isset($_COOKIE[$varName])
32                         || isset($_ENV[$varName])
33                         || isset($_SESSION[$varName])
34                         || isset($_FILES[$varName])
35                 ){
36                         die('Sorry. An error occurred.');
37                 }
38         } else {
39                 if (   isset($HTTP_GET_VARS[$varName])
40                         || isset($HTTP_POST_VARS[$varName])
41                         || isset($HTTP_COOKIE_VARS[$varName])
42                         || isset($HTTP_ENV_VARS[$varName])
43                         || isset($HTTP_SESSION_VARS[$varName])
44                         || isset($HTTP_POST_FILES[$varName])
45                 ){
46                         die('Sorry. An error occurred.');
47                 }
48         }
49 }
50
51 if (!isset($DIR_LIBS)) {
52         die('Sorry.');
53 }
54
55 include($DIR_LIBS . 'ADMIN.php');
56
57 class PluginAdmin {
58
59         var $strFullName;               // NP_SomeThing
60         var $plugin;                    // ref. to plugin object
61         var $bValid;                    // evaluates to true when object is considered valid
62         var $admin;                             // ref to an admin object
63
64         function PluginAdmin($pluginName)
65         {
66                 global $manager;
67
68                 $this->strFullName = 'NP_' . $pluginName;
69
70                 // check if plugin exists and is installed
71                 if (!$manager->pluginInstalled($this->strFullName))
72                         doError('Invalid plugin');
73
74                 $this->plugin =& $manager->getPlugin($this->strFullName);
75                 $this->bValid = $this->plugin;
76
77                 if (!$this->bValid)
78                         doError('Invalid plugin');
79
80                 $this->admin = new ADMIN();
81                 $this->admin->action = 'plugin_' . $pluginName;
82         }
83
84         function start($extraHead = '')
85         {
86                 global $CONF;
87                 $strBaseHref  = '<base href="' . htmlspecialchars($CONF['AdminURL']) . '" />';
88                 $extraHead .= $strBaseHref;
89
90                 $this->admin->pagehead($extraHead);
91         }
92
93         function end()
94         {
95                 $this->_AddTicketByJS();
96                 $this->admin->pagefoot();
97         }
98
99 /** 
100  * Add ticket when not used in plugin's admin page
101  * to avoid CSRF.
102  */
103         function _AddTicketByJS(){
104                 global $CONF,$ticketforplugin;
105                 if (!($ticket=$ticketforplugin['ticket'])) {
106                         //echo "\n<!--TicketForPlugin skipped-->\n";
107                         return;
108                 }
109                 $ticket=htmlspecialchars($ticket,ENT_QUOTES);
110  
111 ?><script type="text/javascript">
112 /*<![CDATA[*/
113 /* Add tickets for available links (outside blog excluded) */
114 for (i=0;document.links[i];i++){
115   if (document.links[i].href.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
116     && !(document.links[i].href.indexOf('//',0)<0)) continue;
117   if ((j=document.links[i].href.indexOf('?',0))<0) continue;
118   if (document.links[i].href.indexOf('ticket=',j)>=0) continue;
119   document.links[i].href=document.links[i].href.substring(0,j+1)+'ticket=<?php echo $ticket; ?>&'+document.links[i].href.substring(j+1);
120 }
121 /* Add tickets for forms (outside blog excluded) */
122 for (i=0;document.forms[i];i++){
123   /* check if ticket is already used */
124   for (j=0;document.forms[i].elements[j];j++) {
125     if (document.forms[i].elements[j].name=='ticket') {
126       j=-1;
127       break;
128     }
129   }
130   if (j==-1) continue;
131  
132   /* check if the modification works */
133   try{document.forms[i].innerHTML+='';}catch(e){
134     /* Modificaion falied: this sometime happens on IE */
135     if (!document.forms[i].action.name && document.forms[i].method.toUpperCase()=="POST") {
136       /* <input name="action"/> is not used for POST method*/
137       if (document.forms[i].action.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
138         && !(document.forms[i].action.indexOf('//',0)<0)) continue;
139       if (0<(j=document.forms[i].action.indexOf('?',0))) if (0<document.forms[i].action.indexOf('ticket=',j)) continue;
140       if (j<0) document.forms[i].action+='?'+'ticket=<?php echo $ticket; ?>';
141       else document.forms[i].action+='&'+'ticket=<?php echo $ticket; ?>';
142       continue;
143     }
144     document.write('<p><b>Error occured druing automatic addition of tickets.</b></p>');
145     j=document.forms[i].outerHTML;
146     while (j!=j.replace('<','&lt;')) j=j.replace('<','&lt;');
147     document.write('<p>'+j+'</p>');
148     continue;
149   }
150   /* check the action paramer in form tag */
151   /* note that <input name="action"/> may be used here */
152   j=document.forms[i].innerHTML;
153   document.forms[i].innerHTML='';
154   if ((document.forms[i].action+'').indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
155       && !((document.forms[i].action+'').indexOf('//',0)<0)) {
156     document.forms[i].innerHTML=j;
157     continue;
158   }
159   /* add ticket */
160   document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';
161 }
162 /*]]>*/
163 </script><?php
164  
165         }
166 }
167
168
169
170 ?>