4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2012 The Nucleus Group
\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
14 * code to make it easier to create plugin admin areas
\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
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
28 private $skinContents; // PluginAdmin contents
\r
29 private $extrahead; // extrahead
\r
31 public function __construct($pluginName)
\r
33 global $manager, $DIR_LIBS;
\r
35 if ( !class_exists('Admin', FALSE) )
\r
37 include($DIR_LIBS . 'ADMIN.php');
\r
40 $this->strFullName = "NP_{$pluginName}";
\r
42 // check if plugin exists and is installed
\r
43 if ( !$manager->pluginInstalled($this->strFullName) )
\r
45 doError(_ERROR_INVALID_PLUGIN);
\r
48 $this->plugin = &$manager->getPlugin($this->strFullName);
\r
49 $this->bValid = $this->plugin;
\r
51 if ( !$this->bValid )
\r
53 doError(_ERROR_INVALID_PLUGIN);
\r
56 Admin::initialize();
\r
57 Admin::setAdminAction("plugin_{$pluginName}");
\r
63 * PluginAdmin::start()
\r
65 * @param string $extraHead child elements for header element
\r
68 public function start($extraHead = '')
\r
71 $this->extrahead = $extraHead . '<base href="' . Entity::hsc($CONF['AdminURL']) . '" />' . "\n";
\r
77 * PluginAdmin::end()
\r
82 public function end()
\r
84 $this->AddTicketByJS();
\r
85 $contents = ob_get_contents();
\r
87 $this->skinContents = '<%pagehead%>' . $contents . '<%pagefoot%>';
\r
88 Admin::action_PluginAdmin($this->skinContents, $this->extrahead);
\r
93 * PluginAdmin::_AddTicketByJS()
\r
94 * Add ticket when not used in plugin's admin page
\r
100 private function AddTicketByJS()
\r
102 global $CONF,$ticketforplugin;
\r
103 if ( !($ticket = $ticketforplugin['ticket']) )
\r
107 $ticket=Entity::hsc($ticket);
\r
109 ?><script type="text/javascript">
\r
111 /* Add tickets for available links (outside blog excluded) */
\r
112 for (i=0;document.links[i];i++){
\r
113 if (document.links[i].href.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
114 && !(document.links[i].href.indexOf('//',0)<0)) continue;
\r
115 if ((j=document.links[i].href.indexOf('?',0))<0) continue;
\r
116 if (document.links[i].href.indexOf('ticket=',j)>=0) continue;
\r
117 document.links[i].href=document.links[i].href.substring(0,j+1)+'ticket=<?php echo $ticket; ?>&'+document.links[i].href.substring(j+1);
\r
119 /* Add tickets for forms (outside blog excluded) */
\r
120 for (i=0;document.forms[i];i++){
\r
121 /* check if ticket is already used */
\r
122 for (j=0;document.forms[i].elements[j];j++) {
\r
123 if (document.forms[i].elements[j].name=='ticket') {
\r
128 if (j==-1) continue;
\r
130 /* check if the modification works */
\r
131 try{document.forms[i].innerHTML+='';}catch(e){
\r
132 /* Modificaion falied: this sometime happens on IE */
\r
133 if (!document.forms[i].action.name && document.forms[i].method.toUpperCase()=="POST") {
\r
134 /* <input name="action"/> is not used for POST method*/
\r
135 if (document.forms[i].action.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
136 && !(document.forms[i].action.indexOf('//',0)<0)) continue;
\r
137 if (0<(j=document.forms[i].action.indexOf('?',0))) if (0<document.forms[i].action.indexOf('ticket=',j)) continue;
\r
138 if (j<0) document.forms[i].action+='?'+'ticket=<?php echo $ticket; ?>';
\r
139 else document.forms[i].action+='&'+'ticket=<?php echo $ticket; ?>';
\r
142 document.write('<?php echo _PLUGINADMIN_TICKETS_JAVASCRIPT ?>');
\r
143 j=document.forms[i].outerHTML;
\r
144 while (j!=j.replace('<','<')) j=j.replace('<','<');
\r
145 document.write('<p>'+j+'</p>');
\r
148 /* check the action paramer in form tag */
\r
149 /* note that <input name="action"/> may be used here */
\r
150 j=document.forms[i].innerHTML;
\r
151 document.forms[i].innerHTML='';
\r
152 if ((document.forms[i].action+'').indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
153 && !((document.forms[i].action+'').indexOf('//',0)<0)) {
\r
154 document.forms[i].innerHTML=j;
\r
158 document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';
\r