Subversion Repositories ALCASAR

Rev

Rev 2775 | 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
    {
89
        if ((!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_ACCESS')) &&
90
             (!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_FILE')) &&
91
             (!defined('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_SHOW_SERIAL'))) {
92
                $this->global_error->addError("phpsysinfo.ini", "Config for plugin ".$this->_plugin_name." not exist!");
93
        }
94
    }
95
 
96
    /**
97
     * check if there is a default translation file availabe and also the required js file for
98
     * appending the content of the plugin to the main webpage
99
     *
100
     * @return void
101
     */
102
    private function _checkfiles()
103
    {
104
        if (!file_exists($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
105
            $this->global_error->addError("file_exists(".$this->_plugin_base."js/".strtolower($this->_plugin_name).".js)", "JS-File for Plugin '".$this->_plugin_name."' is missing!");
106
        } else {
107
            if (!is_readable($this->_plugin_base."js/".strtolower($this->_plugin_name).".js")) {
108
                $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!");
109
            }
110
        }
111
        if (!file_exists($this->_plugin_base."lang/en.xml")) {
112
            $this->global_error->addError("file_exists(".$this->_plugin_base."lang/en.xml)", "At least an english translation must exist for the plugin!");
113
        } else {
114
            if (!is_readable($this->_plugin_base."lang/en.xml")) {
115
                $this->global_error->addError("is_readable(".$this->_plugin_base."js/".$this->_plugin_name.".js)", "The english translation can't be read but is present!");
116
            }
117
        }
118
    }
119
 
120
    /**
121
     * create the xml template where plugin information are added to
122
     *
123
     * @param string $enc target encoding
124
     *
125
     * @return void
126
     */
127
    private function _createXml($enc)
128
    {
129
        $dom = new DOMDocument('1.0', 'UTF-8');
130
        $root = $dom->createElement("Plugin_".$this->_plugin_name);
131
        $dom->appendChild($root);
132
        $this->xml = new SimpleXMLExtended(simplexml_import_dom($dom), $enc);
2976 rexy 133
        $plugname = strtoupper($this->_plugin_name);
134
        if (((PSI_OS == 'WINNT') || (PSI_OS == 'Linux')) &&
135
           defined('PSI_PLUGIN_'.$plugname.'_WMI_HOSTNAME') &&
136
           (!defined('PSI_WMI_HOSTNAME') || (PSI_WMI_HOSTNAME != constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME')))) {
137
            $this->xml->addAttribute('Hostname', constant('PSI_PLUGIN_'.strtoupper($this->_plugin_name).'_WMI_HOSTNAME'));
138
        }
2775 rexy 139
    }
140
}