1: <?php
2: /**
3: * This file contains abstract class for view plugin dependencies
4: *
5: * @package Plugin
6: * @subpackage PluginManager
7: * @version SVN Revision $Rev:$
8: *
9: * @author Frederic Schneider
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: /**
19: * View plugin dependencies
20: * TODO: Later implement into new PIM view design
21: *
22: * @package Plugin
23: * @subpackage PluginManager
24: * @author frederic.schneider
25: */
26: class PimPluginViewDependencies {
27:
28: // Filename of Xml configuration file for plugins
29: const PLUGIN_CONFIG_FILENAME = "plugin.xml";
30:
31: // Initializing variables
32: private static $pluginFoldername;
33: private static $tempXml;
34:
35: /**
36: * Construct function
37: */
38: public function __construct() {
39: $this->_setPluginFoldername();
40: }
41:
42: /**
43: * Get method for pluginFoldername
44: *
45: * @return string $pluginFoldername
46: */
47: private function _setPluginFoldername() {
48: $cfg = cRegistry::getConfig();
49: return self::$pluginFoldername = $cfg['path']['contenido'] . $cfg['path']['plugins'];
50: }
51:
52: /**
53: * Get method for pluginFoldername
54: *
55: * @return string $pluginFoldername
56: */
57: private function _getPluginFoldername() {
58: return self::$pluginFoldername;
59: }
60:
61: /**
62: * Get dependencies
63: *
64: * @param string $tempXml
65: * @return boolean|string
66: */
67: private function _getPluginDependencies() {
68:
69: $tempXml = self::$tempXml;
70:
71: // Initializing dependencies string
72: $dependencies = '';
73:
74: $dependenciesCount = count($tempXml->dependencies);
75: for ($i = 0; $i < $dependenciesCount; $i++) {
76: $dependencies .= sprintf(i18n('This plugin has a dependency to plugin "%s"<br />', 'pim'), $tempXml->dependencies->depend[$i]);
77: }
78:
79: if ($dependencies == '') {
80: return i18n('This plugin has no dependencies to other plugins', 'pim');
81: } else {
82: return $dependencies;
83: }
84:
85: }
86:
87: /**
88: * Get dependencies from extracted plugins
89: *
90: * @param array $tempXml
91: * @return string Plugin dependencie
92: */
93: public function getPluginDependenciesExtracted($tempXml) {
94: // Write plugin.xml content into tempXml variable
95: self::$tempXml = $tempXml;
96:
97: // Call plugin dependencies
98: return $this->_getPluginDependencies();
99: }
100:
101: /**
102: * Get dependencies from installed plugins
103: *
104: * @param integer $idplugin Id of defined plugin
105: * @return string Plugin dependencies
106: */
107: public function getPluginDependenciesInstalled($idplugin = '') {
108:
109: // Return false if no idplugin variable is defined
110: if ($idplugin == '') {
111: return false;
112: }
113:
114: // Get foldername from defined plugin
115: $pimPluginColl = new PimPluginCollection();
116: $pimPluginColl->setWhere('idplugin', $idplugin);
117: $pimPluginColl->query();
118: $pimPluginSql = $pimPluginColl->next();
119: $folderBase = $pimPluginSql->get('folder');
120:
121: // Reset query so we can use PimPluginCollection later again...
122: $pimPluginColl->resetQuery();
123:
124: // Skip plugin if it has no plugin.xml file
125: if (!cFileHandler::exists($this->_getPluginFoldername() . $folderBase . DIRECTORY_SEPARATOR . self::PLUGIN_CONFIG_FILENAME)) {
126: return false;
127: }
128:
129: // Read plugin.xml files from existing plugins at contenido/plugins dir
130: $tempXmlContent = cFileHandler::read($this->_getPluginFoldername() . $folderBase . DIRECTORY_SEPARATOR . self::PLUGIN_CONFIG_FILENAME);
131:
132: // Write plugin.xml content into tempXml variable
133: self::$tempXml = simplexml_load_string($tempXmlContent);
134:
135: // Call plugin dependencies
136: return $this->_getPluginDependencies();
137: }
138:
139:
140: }
141: ?>