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