5 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
6 * Copyright (C) 2002-2012 The Nucleus Group
\r
8 * This program is free software; you can redistribute it and/or
\r
9 * modify it under the terms of the GNU General Public License
\r
10 * as published by the Free Software Foundation; either version 2
\r
11 * of the License, or (at your option) any later version.
\r
12 * (see nucleus/documentation/index.html#license for more info)
\r
15 * code to make it easier to create plugin admin areas
\r
17 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
18 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
19 * @version $Id: PLUGINADMIN.php 1626 2012-01-09 15:46:54Z sakamocchi $
\r
24 public $strFullName; // NP_SomeThing
\r
25 public $plugin; // ref. to plugin object
\r
26 public $bValid; // evaluates to true when object is considered valid
\r
27 public $admin; // ref to an admin object
\r
29 public function __construct($pluginName)
\r
31 global $manager, $DIR_LIBS;
\r
33 if ( !class_exists('Admin', FALSE) )
\r
35 include($DIR_LIBS . 'ADMIN.php');
\r
38 $this->strFullName = "NP_{$pluginName}";
\r
40 // check if plugin exists and is installed
\r
41 if ( !$manager->pluginInstalled($this->strFullName) )
\r
43 doError(_ERROR_INVALID_PLUGIN);
\r
46 $this->plugin =& $manager->getPlugin($this->strFullName);
\r
47 $this->bValid = $this->plugin;
\r
49 if ( !$this->bValid )
\r
51 doError(_ERROR_INVALID_PLUGIN);
\r
54 $this->admin = new Admin();
\r
55 $this->admin->action = "plugin_{$pluginName}";
\r
60 * PluginAdmin::start()
\r
62 * @param string $extraHead child elements for header element
\r
65 public function start($extraHead = '')
\r
68 $strBaseHref = '<base href="' . Entity::hsc($CONF['AdminURL']) . '" />';
\r
69 $extraHead .= $strBaseHref;
\r
71 $this->admin->pagehead($extraHead);
\r
76 * PluginAdmin::end()
\r
81 public function end()
\r
83 $this->_AddTicketByJS();
\r
84 $this->admin->pagefoot();
\r
89 * PluginAdmin::_AddTicketByJS()
\r
90 * Add ticket when not used in plugin's admin page
\r
96 public function _AddTicketByJS()
\r
98 global $CONF,$ticketforplugin;
\r
99 if ( !($ticket=$ticketforplugin['ticket']) )
\r
103 $ticket=Entity::hsc($ticket);
\r
105 ?><script type="text/javascript">
\r
107 /* Add tickets for available links (outside blog excluded) */
\r
108 for (i=0;document.links[i];i++){
\r
109 if (document.links[i].href.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
110 && !(document.links[i].href.indexOf('//',0)<0)) continue;
\r
111 if ((j=document.links[i].href.indexOf('?',0))<0) continue;
\r
112 if (document.links[i].href.indexOf('ticket=',j)>=0) continue;
\r
113 document.links[i].href=document.links[i].href.substring(0,j+1)+'ticket=<?php echo $ticket; ?>&'+document.links[i].href.substring(j+1);
\r
115 /* Add tickets for forms (outside blog excluded) */
\r
116 for (i=0;document.forms[i];i++){
\r
117 /* check if ticket is already used */
\r
118 for (j=0;document.forms[i].elements[j];j++) {
\r
119 if (document.forms[i].elements[j].name=='ticket') {
\r
124 if (j==-1) continue;
\r
126 /* check if the modification works */
\r
127 try{document.forms[i].innerHTML+='';}catch(e){
\r
128 /* Modificaion falied: this sometime happens on IE */
\r
129 if (!document.forms[i].action.name && document.forms[i].method.toUpperCase()=="POST") {
\r
130 /* <input name="action"/> is not used for POST method*/
\r
131 if (document.forms[i].action.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
132 && !(document.forms[i].action.indexOf('//',0)<0)) continue;
\r
133 if (0<(j=document.forms[i].action.indexOf('?',0))) if (0<document.forms[i].action.indexOf('ticket=',j)) continue;
\r
134 if (j<0) document.forms[i].action+='?'+'ticket=<?php echo $ticket; ?>';
\r
135 else document.forms[i].action+='&'+'ticket=<?php echo $ticket; ?>';
\r
138 document.write('<?php echo _PLUGINADMIN_TICKETS_JAVASCRIPT ?>');
\r
139 j=document.forms[i].outerHTML;
\r
140 while (j!=j.replace('<','<')) j=j.replace('<','<');
\r
141 document.write('<p>'+j+'</p>');
\r
144 /* check the action paramer in form tag */
\r
145 /* note that <input name="action"/> may be used here */
\r
146 j=document.forms[i].innerHTML;
\r
147 document.forms[i].innerHTML='';
\r
148 if ((document.forms[i].action+'').indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
149 && !((document.forms[i].action+'').indexOf('//',0)<0)) {
\r
150 document.forms[i].innerHTML=j;
\r
154 document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';
\r
166 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
167 * Copyright (C) 2002-2012 The Nucleus Group
169 * This program is free software; you can redistribute it and/or
170 * modify it under the terms of the GNU General Public License
171 * as published by the Free Software Foundation; either version 2
172 * of the License, or (at your option) any later version.
173 * (see nucleus/documentation/index.html#license for more info)
176 * code to make it easier to create plugin admin areas
178 * @license http://nucleuscms.org/license.txt GNU General Public License
179 * @copyright Copyright (C) 2002-2012 The Nucleus Group
180 * @version $Id: PLUGINADMIN.php 1886 2012-06-17 08:27:27Z sakamocchi $
185 public $strFullName; // NP_SomeThing
186 public $plugin; // ref. to plugin object
187 public $bValid; // evaluates to true when object is considered valid
188 public $admin; // ref to an admin object
190 private $skinContents; // PluginAdmin contents
191 private $extrahead; // extrahead
193 public function __construct($pluginName)
195 global $manager, $DIR_LIBS;
197 if ( !class_exists('Admin', FALSE) )
199 include($DIR_LIBS . 'ADMIN.php');
202 $this->strFullName = "NP_{$pluginName}";
204 // check if plugin exists and is installed
205 if ( !$manager->pluginInstalled($this->strFullName) )
207 doError(_ERROR_INVALID_PLUGIN);
211 $this->plugin = &$manager->getPlugin($this->strFullName);
212 $this->bValid = $this->plugin;
214 if ( !$this->bValid )
216 doError(_ERROR_INVALID_PLUGIN);
221 Admin::$action = "plugin_{$pluginName}";
227 * PluginAdmin::start()
229 * @param string $extraHead child elements for header element
232 public function start($extraHead = '')
235 $this->extrahead = $extraHead . '<base href="' . Entity::hsc($CONF['AdminURL']) . '" />' . "\n";
246 public function end()
248 $this->AddTicketByJS();
249 $contents = ob_get_contents();
251 $this->skinContents = '<%pagehead%>' . $contents . '<%pagefoot%>';
252 Admin::action_PluginAdmin($this->skinContents, $this->extrahead);
257 * PluginAdmin::_AddTicketByJS()
258 * Add ticket when not used in plugin's admin page
264 private function AddTicketByJS()
266 global $CONF,$ticketforplugin;
267 if ( !($ticket = $ticketforplugin['ticket']) )
271 $ticket=Entity::hsc($ticket);
273 ?><script type="text/javascript">
275 /* Add tickets for available links (outside blog excluded) */
276 for (i=0;document.links[i];i++){
277 if (document.links[i].href.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
278 && !(document.links[i].href.indexOf('//',0)<0)) continue;
279 if ((j=document.links[i].href.indexOf('?',0))<0) continue;
280 if (document.links[i].href.indexOf('ticket=',j)>=0) continue;
281 document.links[i].href=document.links[i].href.substring(0,j+1)+'ticket=<?php echo $ticket; ?>&'+document.links[i].href.substring(j+1);
283 /* Add tickets for forms (outside blog excluded) */
284 for (i=0;document.forms[i];i++){
285 /* check if ticket is already used */
286 for (j=0;document.forms[i].elements[j];j++) {
287 if (document.forms[i].elements[j].name=='ticket') {
294 /* check if the modification works */
295 try{document.forms[i].innerHTML+='';}catch(e){
296 /* Modificaion falied: this sometime happens on IE */
297 if (!document.forms[i].action.name && document.forms[i].method.toUpperCase()=="POST") {
298 /* <input name="action"/> is not used for POST method*/
299 if (document.forms[i].action.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
300 && !(document.forms[i].action.indexOf('//',0)<0)) continue;
301 if (0<(j=document.forms[i].action.indexOf('?',0))) if (0<document.forms[i].action.indexOf('ticket=',j)) continue;
302 if (j<0) document.forms[i].action+='?'+'ticket=<?php echo $ticket; ?>';
303 else document.forms[i].action+='&'+'ticket=<?php echo $ticket; ?>';
306 document.write('<?php echo _PLUGINADMIN_TICKETS_JAVASCRIPT ?>');
307 j=document.forms[i].outerHTML;
308 while (j!=j.replace('<','<')) j=j.replace('<','<');
309 document.write('<p>'+j+'</p>');
312 /* check the action paramer in form tag */
313 /* note that <input name="action"/> may be used here */
314 j=document.forms[i].innerHTML;
315 document.forms[i].innerHTML='';
316 if ((document.forms[i].action+'').indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
317 && !((document.forms[i].action+'').indexOf('//',0)<0)) {
318 document.forms[i].innerHTML=j;
322 document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';
330 >>>>>>> skinnable-master