4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2012 The Nucleus Group
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)
14 * code to make it easier to create plugin admin areas
16 * @license http://nucleuscms.org/license.txt GNU General Public License
17 * @copyright Copyright (C) 2002-2012 The Nucleus Group
18 * @version $Id: PLUGINADMIN.php 1886 2012-06-17 08:27:27Z sakamocchi $
23 public $strFullName; // NP_SomeThing
24 public $plugin; // ref. to plugin object
25 public $bValid; // evaluates to true when object is considered valid
26 public $admin; // ref to an admin object
28 private $skinContents; // PluginAdmin contents
29 private $extrahead; // extrahead
31 public function __construct($pluginName)
33 global $manager, $DIR_LIBS;
35 if ( !class_exists('Admin', FALSE) )
37 include($DIR_LIBS . 'ADMIN.php');
40 $this->strFullName = "NP_{$pluginName}";
42 // check if plugin exists and is installed
43 if ( !$manager->pluginInstalled($this->strFullName) )
45 doError(_ERROR_INVALID_PLUGIN);
49 $this->plugin = &$manager->getPlugin($this->strFullName);
50 $this->bValid = $this->plugin;
54 doError(_ERROR_INVALID_PLUGIN);
59 Admin::$action = "plugin_{$pluginName}";
65 * PluginAdmin::start()
67 * @param string $extraHead child elements for header element
70 public function start($extraHead = '')
73 $this->extrahead = $extraHead . '<base href="' . Entity::hsc($CONF['AdminURL']) . '" />' . "\n";
86 $this->AddTicketByJS();
87 $contents = ob_get_contents();
89 $this->skinContents = '<%pagehead%>' . $contents . '<%pagefoot%>';
90 Admin::action_PluginAdmin($this->skinContents, $this->extrahead);
95 * PluginAdmin::_AddTicketByJS()
96 * Add ticket when not used in plugin's admin page
102 private function AddTicketByJS()
104 global $CONF,$ticketforplugin;
105 if ( !($ticket = $ticketforplugin['ticket']) )
109 $ticket=Entity::hsc($ticket);
111 ?><script type="text/javascript">
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);
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') {
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; ?>';
144 document.write('<?php echo _PLUGINADMIN_TICKETS_JAVASCRIPT ?>');
145 j=document.forms[i].outerHTML;
146 while (j!=j.replace('<','<')) j=j.replace('<','<');
147 document.write('<p>'+j+'</p>');
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;
160 document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';