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