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 $_contenidoLanguageFileLang;
48:
49:
50: protected $_SubNav;
51:
52:
53: protected $_DOMDocument;
54:
55:
56: protected $_ApiNavMainCollection;
57:
58:
59: protected $_ApiNavSubCollection;
60:
61: 62: 63: 64: 65:
66: private function _setDOMDocument() {
67: return $this->_DOMDocument = new DOMDocument();
68: }
69:
70: 71: 72: 73: 74:
75: private function _setApiNavMainCollection() {
76: return $this->_ApiNavMainCollection = new cApiNavMainCollection();
77: }
78:
79: 80: 81: 82: 83:
84: private function _setApiNavSubCollection() {
85: return $this->_ApiNavSubCollection = new cApiNavSubCollection();
86: }
87:
88: 89: 90: 91: 92: 93: 94:
95: private function _setNavigationXmlPath($path) {
96: $this->_contenidoLanguageFileLang = $path;
97: return true;
98: }
99:
100: 101: 102: 103: 104: 105:
106: private function _getNavigationXmlPath() {
107: return $this->_contenidoLanguageFileLang;
108: }
109:
110:
111: 112: 113:
114: public function __construct() {
115:
116:
117: $this->_setDOMDocument();
118:
119:
120: $this->_setApiNavMainCollection();
121: $this->_setApiNavSubCollection();
122: }
123:
124:
125: 126: 127: 128: 129: 130:
131: public function setPluginFoldername($foldername) {
132: return $this->PluginFoldername = cSecurity::escapeString($foldername);
133: }
134:
135:
136: 137: 138: 139: 140:
141: public function getNavSubentries() {
142: global $belang;
143:
144: $cfg = cRegistry::getConfig();
145:
146:
147: $dataPluginXml = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->PluginFoldername . DIRECTORY_SEPARATOR . self::PLUGIN_CONFIG_FILENAME);
148:
149:
150: $xmlPluginXml = simplexml_load_string($dataPluginXml);
151:
152:
153: $this->_NavCount = count($xmlPluginXml->contenido->nav_sub->nav);
154:
155:
156: if ($this->_NavCount == 0) {
157: return i18n('No navigation configuration founded', 'pim');
158: }
159:
160:
161: self::$XmlNavSub = $xmlPluginXml->contenido->nav_sub;
162:
163:
164: $contenidoNav = $this->_getCONTENIDONavigation();
165:
166: if ($contenidoNav != "") {
167: return $this->_getPluginNavigation($contenidoNav);
168: } else {
169:
170:
171: $pluginNav = $this->_checkAndGetPluginNavigation();
172:
173: if ($pluginNav != "") {
174: return $this->_getPluginNavigation($pluginNav);
175: } else {
176: return i18n('No navigation configuration founded', 'pim');
177: }
178: }
179: }
180:
181: 182: 183: 184: 185:
186: private function _getCONTENIDONavigation() {
187: $cfg = cRegistry::getConfig();
188:
189:
190: $this->_setNavigationXmlPath($cfg['path']['contenido'] . 'xml/' . self::CONTENIDO_NAVIGATION_FILENAME);
191:
192: if (cFileHandler::exists($this->_getNavigationXmlPath())) {
193:
194: for ($i = 0; $i < $this->_NavCount; $i++) {
195:
196:
197: preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
198:
199:
200: $navSubEntries = explode("/", $matches[1]);
201:
202: if ($navSubEntries[0] == "navigation") {
203:
204:
205:
206: $this->_SubNav = $this->_getTranslatedNavigationName('//language/navigation/' . $navSubEntries[1] . '/' . $navSubEntries[2] . '/main');
207:
208:
209: return $this->_getTranslatedNavigationName('//language/navigation/' . $navSubEntries[1] . '/main');
210: } else {
211: return false;
212: }
213: }
214: } else {
215: return false;
216: }
217: }
218:
219: 220: 221: 222: 223: 224:
225: private function _getTranslatedNavigationName($query = '') {
226:
227: if ($query == '') {
228: return false;
229: }
230:
231:
232: $this->_DOMDocument->load($this->_getNavigationXmlPath());
233:
234:
235: $xpath = new DOMXPath($this->_DOMDocument);
236:
237:
238: $entriesLang = $xpath->query($query);
239:
240: foreach ($entriesLang as $entry) {
241: return $entry->firstChild->nodeValue;
242: }
243: }
244:
245: 246: 247: 248: 249: 250:
251: private function _checkAndGetPluginNavigation() {
252: $cfg = cRegistry::getConfig();
253:
254:
255: $contenidoLanguageFileLang = $cfg['path']['contenido'] . 'xml/' . self::CONTENIDO_NAVIGATION_FILENAME;
256:
257: if (cFileHandler::exists($contenidoLanguageFileLang)) {
258:
259: for ($i = 0; $i < $this->_NavCount; $i++) {
260:
261: $this->_ApiNavMainCollection->setWhere('idnavm', cSecurity::toInteger(self::$XmlNavSub->nav[$i]->attributes()->navm));
262: $this->_ApiNavMainCollection->query();
263:
264:
265:
266: if ($this->_ApiNavMainCollection->count() == 0) {
267: return false;
268: }
269:
270: $row = $this->_ApiNavMainCollection->next();
271:
272:
273: $query = '//' . $row->get('location');
274:
275:
276: $this->_DOMDocument->load($contenidoLanguageFileLang);
277:
278:
279: $xpath = new DOMXPath($this->_DOMDocument);
280:
281:
282: $entriesLang = $xpath->query($query);
283:
284: foreach ($entriesLang as $entry) {
285: return $entry->firstChild->nodeValue;
286: }
287: }
288: } else {
289: return false;
290: }
291: }
292:
293: 294: 295: 296: 297: 298:
299: private function _getPluginNavigation($contenidoNav = "") {
300: global $belang;
301: $cfg = cRegistry::getConfig();
302:
303:
304:
305: $pluginLanguageFileLang = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->PluginFoldername . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . $cfg['lang'][$belang];
306:
307: if (cFileHandler::exists($pluginLanguageFileLang) && $contenidoNav != "") {
308:
309:
310: $founded = "";
311:
312: for ($i = 0; $i < $this->_NavCount; $i++) {
313:
314:
315: preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
316:
317:
318: $query = '//' . $matches[1];
319:
320:
321: $this->_DOMDocument->load($pluginLanguageFileLang);
322:
323:
324: $xpath = new DOMXPath($this->_DOMDocument);
325:
326:
327: $entriesLang = $xpath->query($query);
328:
329:
330: if ($entriesLang->length == 0) {
331: return false;
332: }
333:
334: foreach ($entriesLang as $entry) {
335:
336:
337:
338: if (self::$XmlNavSub->nav[$i]->attributes()->level == 0 && $this->_NavCount > 1) {
339: $menuName = $entry->nodeValue;
340: continue;
341: } elseif (self::$XmlNavSub->nav[$i]->attributes()->level == 1 && $menuName == '') {
342:
343:
344: $menuName = $this->_SubNav;
345: }
346:
347: $founded[] = i18n('You find this plugin at navigation section', 'pim') . " "{$contenidoNav}" " . i18n('as', 'pim') . (($menuName != "") ? ' "' . $menuName . '" ->' : '') . " "{$entry->nodeValue}"<br />";
348: }
349: }
350:
351:
352: $founded = array_unique($founded);
353:
354:
355: $output = "";
356:
357:
358: foreach ($founded as $entry) {
359: $output .= $entry;
360: }
361:
362: return $output;
363: } else {
364: return false;
365: }
366: }
367:
368: }
369: ?>