1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
<?php
/**
* Basic Plugin Functions
*
* PHP version 5
*
* @category PHP
* @package PSI_Plugin
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version SVN: $Id: class.PSI_Plugin.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* basic functions to get a plugin working in phpSysinfo
* every plugin must implement this abstract class to be a valid plugin, main tasks
* of this class are reading the configuration file and check for the required files
* (*.js, lang/en.xml) to get everything working, if we have errors here we log them
* to our global error object
*
* @category PHP
* @package PSI_Plugin
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class PSI_Plugin implements PSI_Interface_Plugin
{
/**
* name of the plugin (classname)
*
* @var string
*/
private $_plugin_name = "";
/**
* full directory path of the plugin
*
* @var string
*/
private $_plugin_base = "";
/**
* global object for error handling
*
* @var Error
*/
protected $global_error = "";
/**
* xml tamplate with header
*
* @var SimpleXMLExtended
*/
protected $xml;
/**
* build the global Error object, read the configuration and check if all files are available
* for a minimalistic function of the plugin
*
* @param string $plugin_name name of the plugin
* @param string $enc target encoding
* @return void
*/
public function __construct($plugin_name, $enc)
{
$this->global_error = PSI_Error::Singleton();
if (trim($plugin_name) != "") {
$this->_plugin_name = $plugin_name;
$this->_plugin_base = PSI_APP_ROOT."/plugins/".strtolower($this->_plugin_name)."/";
$this->_checkfiles();
$this->_getconfig();
} else {
$this->global_error->addError("__construct()", "Parent constructor called without Plugin-Name!");
}
$this->_createXml($enc);
}
/**
* read the plugin configuration file, if we have one in the plugin directory
*
* @return void
*/
private function _getconfig()
{
if ((strtoupper($this->_plugin_name) !== 'DISKLOAD') &&
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_ACCESS')) &&
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_FILE')) &&
(!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SHOW_SERIAL'))) {
$this->global_error->addError("phpsysinfo.ini", "Config for plugin ".$this->_plugin_name." not exist!");
}
}
/**
* check if there is a default translation file availabe and also the required js file for
* appending the content of the plugin to the main webpage
*
* @return void
*/
private function _checkfiles()
{
if (!file_exists($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
$this->global_error->addError("file_exists(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is missing!");
} else {
if (!is_readable($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
$this->global_error->addError("is_readable(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is not readable but present!");
}
}
if (!file_exists($this->_plugin_base."lang/en.xml")) {
$this->global_error->addError("file_exists(".$this->_plugin_base."lang/en.xml)", "At least an english translation must exist for the plugin!");
} else {
if (!is_readable($this->_plugin_base."lang/en.xml")) {
$this->global_error->addError("is_readable(".$this->_plugin_base."js/".$this->_plugin_name.".js)", "The english translation can't be read but is present!");
}
}
}
/**
* create the xml template where plugin information are added to
*
* @param string $enc target encoding
*
* @return void
*/
private function _createXml($enc)
{
$dom = new DOMDocument('1.0', 'UTF-8');
$root = $dom->createElement("Plugin_".$this->_plugin_name);
$dom->appendChild($root);
$this->xml = new SimpleXMLExtended(simplexml_import_dom($dom), $enc);
$plugname = strtoupper($this->_plugin_name);
if ((PSI_OS == 'Linux') && defined('PSI_PLUGIN_'.$plugname.'_SSH_HOSTNAME') &&
(!defined('PSI_SSH_HOSTNAME') || (PSI_SSH_HOSTNAME != constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SSH_HOSTNAME')))) {
$this->xml->addAttribute('Hostname', constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SSH_HOSTNAME'));
} elseif (((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) && defined('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME') &&
(!defined('PSI_WMI_HOSTNAME') || (PSI_WMI_HOSTNAME != constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME')))) {
$this->xml->addAttribute('Hostname', constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME'));
}
}
}
|