PLUGINADMIN.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
00005  * Copyright (C) 2002-2007 The Nucleus Group
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * (see nucleus/documentation/index.html#license for more info)
00012  */
00022 global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES, $HTTP_SESSION_VARS;
00023 $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');
00024 
00025 foreach ($aVarsToCheck as $varName)
00026 {
00027         if (phpversion() >= '4.1.0')
00028         {
00029                 if (   isset($_GET[$varName])
00030                         || isset($_POST[$varName])
00031                         || isset($_COOKIE[$varName])
00032                         || isset($_ENV[$varName])
00033                         || isset($_SESSION[$varName])
00034                         || isset($_FILES[$varName])
00035                 ){
00036                         die('Sorry. An error occurred.');
00037                 }
00038         } else {
00039                 if (   isset($HTTP_GET_VARS[$varName])
00040                         || isset($HTTP_POST_VARS[$varName])
00041                         || isset($HTTP_COOKIE_VARS[$varName])
00042                         || isset($HTTP_ENV_VARS[$varName])
00043                         || isset($HTTP_SESSION_VARS[$varName])
00044                         || isset($HTTP_POST_FILES[$varName])
00045                 ){
00046                         die('Sorry. An error occurred.');
00047                 }
00048         }
00049 }
00050 
00051 if (!isset($DIR_LIBS)) {
00052         die('Sorry.');
00053 }
00054 
00055 include($DIR_LIBS . 'ADMIN.php');
00056 
00057 class PluginAdmin {
00058 
00059         var $strFullName;               // NP_SomeThing
00060         var $plugin;                    // ref. to plugin object
00061         var $bValid;                    // evaluates to true when object is considered valid
00062         var $admin;                             // ref to an admin object
00063 
00064         function PluginAdmin($pluginName)
00065         {
00066                 global $manager;
00067 
00068                 $this->strFullName = 'NP_' . $pluginName;
00069 
00070                 // check if plugin exists and is installed
00071                 if (!$manager->pluginInstalled($this->strFullName))
00072                         doError('Invalid plugin');
00073 
00074                 $this->plugin =& $manager->getPlugin($this->strFullName);
00075                 $this->bValid = $this->plugin;
00076 
00077                 if (!$this->bValid)
00078                         doError('Invalid plugin');
00079 
00080                 $this->admin = new ADMIN();
00081                 $this->admin->action = 'plugin_' . $pluginName;
00082         }
00083 
00084         function start($extraHead = '')
00085         {
00086                 global $CONF;
00087                 $strBaseHref  = '<base href="' . htmlspecialchars($CONF['AdminURL']) . '" />';
00088                 $extraHead .= $strBaseHref;
00089 
00090                 $this->admin->pagehead($extraHead);
00091         }
00092 
00093         function end()
00094         {
00095                 $this->_AddTicketByJS();
00096                 $this->admin->pagefoot();
00097         }
00098 
00103         function _AddTicketByJS(){
00104                 global $CONF,$ticketforplugin;
00105                 if (!($ticket=$ticketforplugin['ticket'])) {
00106                         //echo "\n<!--TicketForPlugin skipped-->\n";
00107                         return;
00108                 }
00109                 $ticket=htmlspecialchars($ticket,ENT_QUOTES);
00110  
00111 ?><script type="text/javascript">
00112 /*<![CDATA[*/
00113 /* Add tickets for available links (outside blog excluded) */
00114 for (i=0;document.links[i];i++){
00115   if (document.links[i].href.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
00116     && !(document.links[i].href.indexOf('//',0)<0)) continue;
00117   if ((j=document.links[i].href.indexOf('?',0))<0) continue;
00118   if (document.links[i].href.indexOf('ticket=',j)>=0) continue;
00119   document.links[i].href=document.links[i].href.substring(0,j+1)+'ticket=<?php echo $ticket; ?>&'+document.links[i].href.substring(j+1);
00120 }
00121 /* Add tickets for forms (outside blog excluded) */
00122 for (i=0;document.forms[i];i++){
00123   /* check if ticket is already used */
00124   for (j=0;document.forms[i].elements[j];j++) {
00125     if (document.forms[i].elements[j].name=='ticket') {
00126       j=-1;
00127       break;
00128     }
00129   }
00130   if (j==-1) continue;
00131  
00132   /* check if the modification works */
00133   try{document.forms[i].innerHTML+='';}catch(e){
00134     /* Modificaion falied: this sometime happens on IE */
00135     if (!document.forms[i].action.name && document.forms[i].method.toUpperCase()=="POST") {
00136       /* <input name="action"/> is not used for POST method*/
00137       if (document.forms[i].action.indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
00138         && !(document.forms[i].action.indexOf('//',0)<0)) continue;
00139       if (0<(j=document.forms[i].action.indexOf('?',0))) if (0<document.forms[i].action.indexOf('ticket=',j)) continue;
00140       if (j<0) document.forms[i].action+='?'+'ticket=<?php echo $ticket; ?>';
00141       else document.forms[i].action+='&'+'ticket=<?php echo $ticket; ?>';
00142       continue;
00143     }
00144     document.write('<p><b>Error occured during automatic addition of tickets.</b></p>');
00145     j=document.forms[i].outerHTML;
00146     while (j!=j.replace('<','&lt;')) j=j.replace('<','&lt;');
00147     document.write('<p>'+j+'</p>');
00148     continue;
00149   }
00150   /* check the action paramer in form tag */
00151   /* note that <input name="action"/> may be used here */
00152   j=document.forms[i].innerHTML;
00153   document.forms[i].innerHTML='';
00154   if ((document.forms[i].action+'').indexOf('<?php echo $CONF['PluginURL']; ?>',0)<0
00155       && !((document.forms[i].action+'').indexOf('//',0)<0)) {
00156     document.forms[i].innerHTML=j;
00157     continue;
00158   }
00159   /* add ticket */
00160   document.forms[i].innerHTML=j+'<input type="hidden" name="ticket" value="<?php echo $ticket; ?>"/>';
00161 }
00162 /*]]>*/
00163 </script><?php
00164  
00165         }
00166 }
00167 
00168 
00169 
00170 ?>



Generated on Wed Jun 25 17:25:59 2008 by  doxygen 1.5.5