Subversion Repositories ALCASAR

Rev

Rev 2976 | Details | Compare with Previous | Last modification | View Log

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