Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • PimPlugin
  • PimPluginArchiveExtractor
  • PimPluginCollection
  • PimPluginRelations
  • PimPluginRelationsCollection
  • PimPluginSetup
  • PimPluginSetupInstall
  • PimPluginSetupStatus
  • PimPluginSetupUninstall
  • PimPluginSetupUpdate
  • PimPluginViewDependencies
  • PimPluginViewNavSub
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains abstract class for view navsub entries
  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 navigation entries
 18:  * TODO: Later implement into new PIM view design
 19:  *
 20:  * @package Plugin
 21:  * @subpackage PluginManager
 22:  * @author frederic.schneider
 23:  */
 24: class PimPluginViewNavSub {
 25:     /**
 26:      * Pattern for navigation (nav_sub) xml entries
 27:      */
 28:     const PATTERN = '/;(.+)$/';
 29:     /**
 30:      * Filename of Xml configuration file for plugins
 31:      */
 32:     const PLUGIN_CONFIG_FILENAME = "plugin.xml";
 33:     /**
 34:      * Filename of Xml configuration file for CONTENIDO navigation
 35:      */
 36:     const CONTENIDO_NAVIGATION_FILENAME = "navigation.xml";
 37: 
 38:     /**
 39:      * @var string
 40:      */
 41:     private $PluginFoldername;
 42: 
 43:     /**
 44:      * CONTENIDO sub navigations: *_nav_sub
 45:      *
 46:      * @var SimpleXMLElement
 47:      */
 48:     public static $XmlNavSub;
 49: 
 50:     /**
 51:      * Variable for counted nav entries
 52:      *
 53:      * @var int
 54:      */
 55:     protected $_NavCount = 0;
 56: 
 57:     /**
 58:      * Variable for filepath to CONTENIDO base navigation.xml
 59:      *
 60:      * @todo check variable name
 61:      * @var string
 62:      */
 63:     protected $_contenidoLanguageFileLang;
 64: 
 65:     /**
 66:      * Variable for subnavigation name
 67:      *
 68:      * @var string
 69:      */
 70:     protected $_SubNav;
 71: 
 72:     /**
 73:      * Class variable for DOMDocument
 74:      *
 75:      * @var DOMDocument
 76:      */
 77:     protected $_DOMDocument;
 78: 
 79:     /**
 80:      * Class variable for cApiNavMainCollection
 81:      *
 82:      * @var cApiNavMainCollection
 83:      */
 84:     protected $_ApiNavMainCollection;
 85: 
 86:     /**
 87:      * Class variable for cApiNavSubCollection
 88:      *
 89:      * @var cApiNavSubCollection
 90:      */
 91:     protected $_ApiNavSubCollection;
 92: 
 93:     /**
 94:      * Initializing and set variable for DOMDocument
 95:      *
 96:      * @return DOMDocument
 97:      */
 98:     private function _setDOMDocument() {
 99:         return $this->_DOMDocument = new DOMDocument();
100:     }
101: 
102:     /**
103:      * Initializing and set variable for cApiNavMainCollection
104:      *
105:      * @return cApiNavMainCollection
106:      */
107:     private function _setApiNavMainCollection() {
108:         return $this->_ApiNavMainCollection = new cApiNavMainCollection();
109:     }
110: 
111:     /**
112:      * Initializing and set variable for cApiNavSubCollection
113:      *
114:      * @return cApiNavSubCollection
115:      */
116:     private function _setApiNavSubCollection() {
117:         return $this->_ApiNavSubCollection = new cApiNavSubCollection();
118:     }
119: 
120:     /**
121:      * Set contenidoLanguageFileLang variable
122:      * (Filepath to CONTENIDO base navigation.xml)
123:      *
124:      * @param string $path
125:      * @return bool
126:      */
127:     private function _setNavigationXmlPath($path) {
128:         $this->_contenidoLanguageFileLang = $path;
129:         return true;
130:     }
131: 
132:     /**
133:      * Get contenidoLanguageFileLang variable
134:      * (Filepath to CONTENIDO base navigation.xml)
135:      *
136:      * @return string contenigoLanguageFileLang
137:      */
138:     private function _getNavigationXmlPath() {
139:         return $this->_contenidoLanguageFileLang;
140:     }
141: 
142:     /**
143:      * Construct function
144:      */
145:     public function __construct() {
146: 
147:         // Initializing and set classes
148:         $this->_setDOMDocument();
149: 
150:         // cApiClasses
151:         $this->_setApiNavMainCollection();
152:         $this->_setApiNavSubCollection();
153:     }
154: 
155:     // GET and SET methods for installation routine
156:     /**
157:      * Set variable for plugin foldername
158:      *
159:      * @param string $foldername
160:      * @return string
161:      */
162:     public function setPluginFoldername($foldername) {
163:         return $this->PluginFoldername = cSecurity::escapeString($foldername);
164:     }
165: 
166:     // View methods
167: 
168:     /**
169:      * Get nav_sub entries
170:      *
171:      * @return string
172:      *
173:      * @throws cException
174:      */
175:     public function getNavSubentries() {
176: 
177:         $cfg = cRegistry::getConfig();
178: 
179:         // Get contents of plugin.xml file
180:         $dataPluginXml = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->PluginFoldername . DIRECTORY_SEPARATOR . self::PLUGIN_CONFIG_FILENAME);
181: 
182:         // Load xml strings
183:         $xmlPluginXml = simplexml_load_string($dataPluginXml);
184: 
185:         // Count nav_sub entries for this plugin
186:         $entries = $xmlPluginXml->contenido->nav_sub->nav;
187:         $this->_NavCount = is_object($entries) ? count($entries) : 0;
188: 
189:         // No navigation configured, so we can stop this process
190:         if ($this->_NavCount == 0) {
191:             return i18n('No navigation configuration founded', 'pim');
192:         }
193: 
194:         // Added nav_sub entries to variable XmlNavSub
195:         self::$XmlNavSub = $xmlPluginXml->contenido->nav_sub;
196: 
197:         // Check for CONTENIDO navigation entries
198:         $contenidoNav = $this->_getCONTENIDONavigation();
199: 
200:         if ($contenidoNav != "") { // CONTENIDO navigation entry founded
201:             return $this->_getPluginNavigation($contenidoNav);
202:         } else { // No CONTENIDO navigation entry founded
203: 
204:             // Check for plugin navigation entry
205:             $pluginNav = $this->_checkAndGetPluginNavigation();
206: 
207:             if ($pluginNav != "") { // Plugin navigation entry founded
208:                 return $this->_getPluginNavigation($pluginNav);
209:             } else { // No navigation entries founded
210:                 return i18n('No navigation configuration founded', 'pim');
211:             }
212:         }
213:     }
214: 
215:     /**
216:      * Get founded CONTENIDO navigation entries
217:      *
218:      * @return bool
219:      */
220:     private function _getCONTENIDONavigation() {
221:         $cfg = cRegistry::getConfig();
222: 
223:         // Path to CONTENIDO navigation xml file
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:                 // Get only navigation value (pattern)
231:                 preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
232: 
233:                 // Get single navigation values
234:                 $navSubEntries = explode("/", $matches[1]);
235: 
236:                 if ($navSubEntries[0] == "navigation") {
237:                     // CONTENIDO navigation case
238: 
239:                     // Define subnavigation name (example: navigation/content/linkchecker)
240:                     $this->_SubNav = $this->_getTranslatedNavigationName('//language/navigation/' . $navSubEntries[1] . '/' . $navSubEntries[2] . '/main');
241: 
242:                     // Define navigation name (example: navigation/content)
243:                     return $this->_getTranslatedNavigationName('//language/navigation/' . $navSubEntries[1] . '/main');
244:                 } else { // No CONTENIDO navigation case
245:                     return false;
246:                 }
247:             }
248:         } else {
249:             return false;
250:         }
251:     }
252: 
253:     /**
254:      * Get translated navigation name
255:      *
256:      * @param string $query
257:      * @return string XML of translated navigation nane
258:      */
259:     private function _getTranslatedNavigationName($query = '') {
260: 
261:         if ($query == '') {
262:             return false;
263:         }
264: 
265:         // Load CONTENIDO navigation xml file
266:         $this->_DOMDocument->load($this->_getNavigationXmlPath());
267: 
268:         // Create new DOMXPath
269:         $xpath = new DOMXPath($this->_DOMDocument);
270: 
271:         // Run defined query
272:         $entriesLang = $xpath->query($query);
273: 
274:         foreach ($entriesLang as $entry) {
275:             return $entry->firstChild->nodeValue;
276:         }
277:     }
278: 
279:     /**
280:      * Checks for plugin navigation entry and get navigation entries from
281:      * CONTENIDO navigation xml file
282:      *
283:      * @return bool
284:      *
285:      * @throws cDbException
286:      * @throws cException
287:      */
288:     private function _checkAndGetPluginNavigation() {
289:         $cfg = cRegistry::getConfig();
290: 
291:         // Path to CONTENIDO navigation xml file
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:                 // If no entry at nav_sub database table founded,
307:                 // return false
308:                 if ($this->_ApiNavMainCollection->count() == 0) {
309:                     return false;
310:                 }
311: 
312:                 $row = $this->_ApiNavMainCollection->next();
313: 
314:                 // Define query
315:                 $query = '//' . $row->get('location');
316: 
317:                 // Load plugin navigation xml file
318:                 $this->_DOMDocument->load($contenidoLanguageFileLang);
319: 
320:                 // Create new DOMXPath
321:                 $xpath = new DOMXPath($this->_DOMDocument);
322: 
323:                 // Run defined query
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:      * Get founded plugin navigation entries
337:      *
338:      * @param string $contenidoNav
339:      *
340:      * @return string|bool
341:      */
342:     private function _getPluginNavigation($contenidoNav = "") {
343:         global $belang;
344:         $cfg = cRegistry::getConfig();
345: 
346:         // Path to plugin specific navigation xml file with selected backend
347:         // language
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:             // Initializing founded array
353:             $founded = array();
354: 
355:             for ($i = 0; $i < $this->_NavCount; $i++) {
356: 
357:                 // Get only navigation value (pattern)
358:                 preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
359: 
360:                 // Define query
361:                 $query = '//' . $matches[1];
362: 
363:                 // Load plugin navigation xml file
364:                 $this->_DOMDocument->load($pluginLanguageFileLang);
365: 
366:                 // Create new DOMXPath
367:                 $xpath = new DOMXPath($this->_DOMDocument);
368: 
369:                 // Run defined query
370:                 $entriesLang = $xpath->query($query);
371: 
372:                 // Prevent misarrangement
373:                 if ($entriesLang->length == 0) {
374:                     return false;
375:                 }
376: 
377:                 foreach ($entriesLang as $entry) {
378: 
379:                     // If we have more then one navigation entry, define
380:                     // menuname for other entries
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:                         // If we have an plugin with level one and no defined menuName, use subnavigation name
386:                         // as menuName
387:                         $menuName = $this->_SubNav;
388:                     }
389: 
390:                     $founded[] = i18n('You find this plugin at navigation section', 'pim') . " &quot;{$contenidoNav}&quot; " . i18n('as', 'pim') . (($menuName != "") ? ' &quot;' . $menuName . '&quot; ->' : '') . " &quot;{$entry->nodeValue}&quot;<br />";
391:                 }
392:             }
393: 
394:             // Prevent double entries
395:             $founded = array_unique($founded);
396: 
397:             // Initializing output variable
398:             $output = "";
399: 
400:             // Convert founded array to an string
401:             foreach ($founded as $entry) {
402:                 $output .= $entry;
403:             }
404: 
405:             return $output;
406:         } else {
407:             return false;
408:         }
409:     }
410: 
411: }
412: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0