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