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 public function __construct($pluginName)
\r
30 global $manager, $DIR_LIBS;
\r
32 if ( !class_exists('Admin', FALSE) )
\r
34 include($DIR_LIBS . 'ADMIN.php');
\r
37 $this->strFullName = "NP_{$pluginName}";
\r
39 // check if plugin exists and is installed
\r
40 if ( !$manager->pluginInstalled($this->strFullName) )
\r
42 doError(_ERROR_INVALID_PLUGIN);
\r
45 $this->plugin =& $manager->getPlugin($this->strFullName);
\r
46 $this->bValid = $this->plugin;
\r
48 if ( !$this->bValid )
\r
50 doError(_ERROR_INVALID_PLUGIN);
\r
53 /*$this->admin = new Admin();
\r
54 $this->admin->action = "plugin_{$pluginName}";*/
\r
55 Admin::initialize();
\r
56 Admin::setAdminAction("plugin_{$pluginName}");
\r
61 * PluginAdmin::start()
\r
63 * @param string $extraHead child elements for header element
\r
66 public function start($extraHead = '')
\r
69 $strBaseHref = '<base href="' . Entity::hsc($CONF['AdminURL']) . '" />';
\r
70 $extraHead .= $strBaseHref;
\r
72 //$this->admin->pagehead($extraHead);
\r
73 Admin::PluninAdminPagehead($extraHead);
\r
78 * PluginAdmin::end()
\r
83 public function end()
\r
85 $this->_AddTicketByJS();
\r
86 //$this->admin->pagefoot();
\r
87 Admin::PluninAdminPagefoot();
\r
92 * PluginAdmin::_AddTicketByJS()
\r
93 * Add ticket when not used in plugin's admin page
\r
99 public function _AddTicketByJS()
\r
101 global $CONF,$ticketforplugin;
\r
102 if ( !($ticket=$ticketforplugin['ticket']) )
\r
106 $ticket=Entity::hsc($ticket);
\r
108 ?><script type="text/javascript">
\r
110 /* Add tickets for available links (outside blog excluded) */
\r
111 for (i=0;document.links[i];i++){
\r
112 if (document.links[i].href.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
113 && !(document.links[i].href.indexOf('//',0)<0)) continue;
\r
114 if ((j=document.links[i].href.indexOf('?',0))<0) continue;
\r
115 if (document.links[i].href.indexOf('ticket=',j)>=0) continue;
\r
116 document.links[i].href=document.links[i].href.substring(0,j+1)+'ticket=<?php echo $ticket; ?>&'+document.links[i].href.substring(j+1);
\r
118 /* Add tickets for forms (outside blog excluded) */
\r
119 for (i=0;document.forms[i];i++){
\r
120 /* check if ticket is already used */
\r
121 for (j=0;document.forms[i].elements[j];j++) {
\r
122 if (document.forms[i].elements[j].name=='ticket') {
\r
127 if (j==-1) continue;
\r
129 /* check if the modification works */
\r
130 try{document.forms[i].innerHTML+='';}catch(e){
\r
131 /* Modificaion falied: this sometime happens on IE */
\r
132 if (!document.forms[i].action.name && document.forms[i].method.toUpperCase()=="POST") {
\r
133 /* <input name="action"/> is not used for POST method*/
\r
134 if (document.forms[i].action.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
135 && !(document.forms[i].action.indexOf('//',0)<0)) continue;
\r
136 if (0<(j=document.forms[i].action.indexOf('?',0))) if (0<document.forms[i].action.indexOf('ticket=',j)) continue;
\r
137 if (j<0) document.forms[i].action+='?'+'ticket=<?php echo $ticket; ?>';
\r
138 else document.forms[i].action+='&'+'ticket=<?php echo $ticket; ?>';
\r
141 document.write('<?php echo _PLUGINADMIN_TICKETS_JAVASCRIPT ?>');
\r
142 j=document.forms[i].outerHTML;
\r
143 while (j!=j.replace('<','<')) j=j.replace('<','<');
\r
144 document.write('<p>'+j+'</p>');
\r
147 /* check the action paramer in form tag */
\r
148 /* note that <input name="action"/> may be used here */
\r
149 j=document.forms[i].innerHTML;
\r
150 document.forms[i].innerHTML='';
\r
151 if ((document.forms[i].action+'').indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
\r
152 && !((document.forms[i].action+'').indexOf('//',0)<0)) {
\r
153 document.forms[i].innerHTML=j;
\r
157 document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';
\r