1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24: 25:
26: class PimPluginViewNavSub {
27:
28:
29: const PATTERN = '/;(.+)$/';
30:
31:
32: const PLUGIN_CONFIG_FILENAME = "plugin.xml";
33:
34:
35: const CONTENIDO_NAVIGATION_FILENAME = "navigation.xml";
36:
37:
38: private $PluginFoldername;
39:
40:
41: public static $XmlNavSub;
42:
43:
44: protected $_NavCount = 0;
45:
46:
47: protected $_DOMDocument;
48:
49:
50: protected $_ApiNavMainCollection;
51:
52:
53: protected $_ApiNavSubCollection;
54:
55: 56: 57: 58: 59:
60: private function _setDOMDocument() {
61: return $this->_DOMDocument = new DOMDocument();
62: }
63:
64: 65: 66: 67: 68:
69: private function _setApiNavMainCollection() {
70: return $this->_ApiNavMainCollection = new cApiNavMainCollection();
71: }
72:
73: 74: 75: 76: 77:
78: private function _setApiNavSubCollection() {
79: return $this->_ApiNavSubCollection = new cApiNavSubCollection();
80: }
81:
82: 83: 84:
85: public function __construct() {
86:
87:
88: $this->_setDOMDocument();
89:
90:
91: $this->_setApiNavMainCollection();
92: $this->_setApiNavSubCollection();
93: }
94:
95:
96: 97: 98: 99: 100: 101:
102: public function setPluginFoldername($foldername) {
103: return $this->PluginFoldername = cSecurity::escapeString($foldername);
104: }
105:
106:
107: 108: 109: 110: 111:
112: public function getNavSubentries() {
113: global $belang;
114:
115: $cfg = cRegistry::getConfig();
116:
117:
118: $dataPluginXml = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->PluginFoldername . DIRECTORY_SEPARATOR . self::PLUGIN_CONFIG_FILENAME);
119:
120:
121: $xmlPluginXml = simplexml_load_string($dataPluginXml);
122:
123:
124: $this->_NavCount = count($xmlPluginXml->contenido->nav_sub->nav);
125:
126:
127: if ($this->_NavCount == 0) {
128: return i18n('No navigation configuration founded', 'pim');
129: }
130:
131:
132: self::$XmlNavSub = $xmlPluginXml->contenido->nav_sub;
133:
134:
135: $contenidoNav = $this->_getCONTENIDONavigation();
136:
137: if ($contenidoNav != "") {
138: return $this->_getPluginNavigation($contenidoNav);
139: } else {
140:
141:
142: $pluginNav = $this->_checkAndGetPluginNavigation();
143:
144: if ($pluginNav != "") {
145: return $this->_getPluginNavigation($pluginNav);
146: } else {
147: return i18n('No navigation configuration founded', 'pim');
148: }
149: }
150: }
151:
152: 153: 154: 155: 156:
157: private function _getCONTENIDONavigation() {
158: $cfg = cRegistry::getConfig();
159:
160:
161: $contenidoLanguageFileLang = $cfg['path']['contenido'] . 'xml/' . self::CONTENIDO_NAVIGATION_FILENAME;
162:
163: if (cFileHandler::exists($contenidoLanguageFileLang)) {
164:
165: for ($i = 0; $i < $this->_NavCount; $i++) {
166:
167:
168: preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
169:
170:
171: $navSubEntries = explode("/", $matches[1]);
172:
173: if ($navSubEntries[0] == "navigation") {
174:
175: $query = '//language/navigation/' . $navSubEntries[1] . '/main';
176: } else {
177: return false;
178: }
179:
180:
181: $this->_DOMDocument->load($contenidoLanguageFileLang);
182:
183:
184: $xpath = new DOMXPath($this->_DOMDocument);
185:
186:
187: $entriesLang = $xpath->query($query);
188:
189: foreach ($entriesLang as $entry) {
190: return $entry->firstChild->nodeValue;
191: }
192: }
193: } else {
194: return false;
195: }
196: }
197:
198: 199: 200: 201: 202: 203:
204: private function _checkAndGetPluginNavigation() {
205: $cfg = cRegistry::getConfig();
206:
207:
208: $contenidoLanguageFileLang = $cfg['path']['contenido'] . 'xml/' . self::CONTENIDO_NAVIGATION_FILENAME;
209:
210: if (cFileHandler::exists($contenidoLanguageFileLang)) {
211:
212: for ($i = 0; $i < $this->_NavCount; $i++) {
213:
214: $this->_ApiNavMainCollection->setWhere('idnavm', cSecurity::toInteger(self::$XmlNavSub->nav[$i]->attributes()->navm));
215: $this->_ApiNavMainCollection->query();
216:
217:
218:
219: if ($this->_ApiNavMainCollection->count() == 0) {
220: return false;
221: }
222:
223: $row = $this->_ApiNavMainCollection->next();
224:
225:
226: $query = '//' . $row->get('location');
227:
228:
229: $this->_DOMDocument->load($contenidoLanguageFileLang);
230:
231:
232: $xpath = new DOMXPath($this->_DOMDocument);
233:
234:
235: $entriesLang = $xpath->query($query);
236:
237: foreach ($entriesLang as $entry) {
238: return $entry->firstChild->nodeValue;
239: }
240: }
241: } else {
242: return false;
243: }
244: }
245:
246: 247: 248: 249: 250: 251:
252: private function _getPluginNavigation($contenidoNav = "") {
253: global $belang;
254: $cfg = cRegistry::getConfig();
255:
256:
257:
258: $pluginLanguageFileLang = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->PluginFoldername . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . $cfg['lang'][$belang];
259:
260: if (cFileHandler::exists($pluginLanguageFileLang) && $contenidoNav != "") {
261:
262:
263: $founded = "";
264:
265: for ($i = 0; $i < $this->_NavCount; $i++) {
266:
267:
268: preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
269:
270:
271: $query = '//' . $matches[1];
272:
273:
274: $this->_DOMDocument->load($pluginLanguageFileLang);
275:
276:
277: $xpath = new DOMXPath($this->_DOMDocument);
278:
279:
280: $entriesLang = $xpath->query($query);
281:
282:
283: if ($entriesLang->length == 0) {
284: return false;
285: }
286:
287: foreach ($entriesLang as $entry) {
288:
289:
290:
291: if (self::$XmlNavSub->nav[$i]->attributes()->level == 0 && $this->_NavCount > 1) {
292: $menuName = $entry->nodeValue;
293: continue;
294: }
295:
296: $founded[] = i18n('You find this plugin at navigation section', 'pim') . " "{$contenidoNav}" " . i18n('as', 'pim') . (($menuName != "") ? ' "' . $menuName . '" ->' : '') . " "{$entry->nodeValue}"<br />";
297: }
298: }
299:
300:
301: $founded = array_unique($founded);
302:
303:
304: $output = "";
305:
306:
307: foreach ($founded as $entry) {
308: $output .= $entry;
309: }
310:
311: return $output;
312: } else {
313: return false;
314: }
315: }
316:
317: }
318: ?>