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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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:     const PATTERN = '/;(.+)$/';
 28: 
 29:     // Filename of Xml configuration file for plugins
 30:     const PLUGIN_CONFIG_FILENAME = "plugin.xml";
 31: 
 32:     // Filename of Xml configuration file for CONTENIDO navigation
 33:     const CONTENIDO_NAVIGATION_FILENAME = "navigation.xml";
 34: 
 35:     // Initializing variables
 36:     private $PluginFoldername;
 37: 
 38:     // CONTENIDO sub navigations: *_nav_sub
 39:     public static $XmlNavSub;
 40: 
 41:     // Varianle for counted nav entries
 42:     protected $_NavCount = 0;
 43: 
 44:     // Variable for filepath to CONTENIDO base navigation.xml
 45:     protected $_contenidoLanguageFileLang;
 46: 
 47:     // Variable for subnavigation name
 48:     protected $_SubNav;
 49: 
 50:     // Class variable for DOMDocument
 51:     protected $_DOMDocument;
 52: 
 53:     // Class variable for cApiNavMainCollection
 54:     protected $_ApiNavMainCollection;
 55: 
 56:     // Class variable for cApiNavSubCollection
 57:     protected $_ApiNavSubCollection;
 58: 
 59:     /**
 60:      * Initializing and set variable for DOMDocument
 61:      *
 62:      * @return DOMDocument
 63:      */
 64:     private function _setDOMDocument() {
 65:         return $this->_DOMDocument = new DOMDocument();
 66:     }
 67: 
 68:     /**
 69:      * Initializing and set variable for cApiNavMainCollection
 70:      *
 71:      * @return cApiNavMainCollection
 72:      */
 73:     private function _setApiNavMainCollection() {
 74:         return $this->_ApiNavMainCollection = new cApiNavMainCollection();
 75:     }
 76: 
 77:     /**
 78:      * Initializing and set variable for cApiNavSubCollection
 79:      *
 80:      * @return cApiNavSubCollection
 81:      */
 82:     private function _setApiNavSubCollection() {
 83:         return $this->_ApiNavSubCollection = new cApiNavSubCollection();
 84:     }
 85: 
 86:     /**
 87:      * Set contenidoLanguageFileLang variable
 88:      * (Filepath to CONTENIDO base navigation.xml)
 89:      *
 90:      * @param string $path
 91:      * @return boolean
 92:      */
 93:     private function _setNavigationXmlPath($path) {
 94:         $this->_contenidoLanguageFileLang = $path;
 95:         return true;
 96:     }
 97: 
 98:     /**
 99:      * Get contenidoLanguageFileLang variable
100:      * (Filepath to CONTENIDO base navigation.xml)
101:      *
102:      * @return string contenigoLanguageFileLang
103:      */
104:     private function _getNavigationXmlPath() {
105:         return $this->_contenidoLanguageFileLang;
106:     }
107: 
108: 
109:     /**
110:      * Construct function
111:      */
112:     public function __construct() {
113: 
114:         // Initializing and set classes
115:         $this->_setDOMDocument();
116: 
117:         // cApiClasses
118:         $this->_setApiNavMainCollection();
119:         $this->_setApiNavSubCollection();
120:     }
121: 
122:     // GET and SET methods for installation routine
123:     /**
124:      * Set variable for plugin foldername
125:      *
126:      * @param string $foldername
127:      * @return string
128:      */
129:     public function setPluginFoldername($foldername) {
130:         return $this->PluginFoldername = cSecurity::escapeString($foldername);
131:     }
132: 
133:     // View methods
134:     /**
135:      * Get nav_sub entries
136:      *
137:      * @return Ambigous <string, string>|Ambigous <string, boolean>
138:      */
139:     public function getNavSubentries() {
140:         global $belang;
141: 
142:         $cfg = cRegistry::getConfig();
143: 
144:         // Get contents of plugin.xml file
145:         $dataPluginXml = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->PluginFoldername . DIRECTORY_SEPARATOR . self::PLUGIN_CONFIG_FILENAME);
146: 
147:         // Load xml strings
148:         $xmlPluginXml = simplexml_load_string($dataPluginXml);
149: 
150:         // Count nav_sub entries for this plugin
151:         $this->_NavCount = count($xmlPluginXml->contenido->nav_sub->nav);
152: 
153:         // No navigation configured, so we can stop this process
154:         if ($this->_NavCount == 0) {
155:             return i18n('No navigation configuration founded', 'pim');
156:         }
157: 
158:         // Added nav_sub entries to variable XmlNavSub
159:         self::$XmlNavSub = $xmlPluginXml->contenido->nav_sub;
160: 
161:         // Check for CONTENIDO navigation entries
162:         $contenidoNav = $this->_getCONTENIDONavigation();
163: 
164:         if ($contenidoNav != "") { // CONTENIDO navigation entry founded
165:             return $this->_getPluginNavigation($contenidoNav);
166:         } else { // No CONTENIDO navigation entry founded
167: 
168:             // Check for plugin navigation entry
169:             $pluginNav = $this->_checkAndGetPluginNavigation();
170: 
171:             if ($pluginNav != "") { // Plugin navigation entry founded
172:                 return $this->_getPluginNavigation($pluginNav);
173:             } else { // No navigation entries founded
174:                 return i18n('No navigation configuration founded', 'pim');
175:             }
176:         }
177:     }
178: 
179:     /**
180:      * Get founded CONTENIDO navigation entries
181:      *
182:      * @return bool
183:      */
184:     private function _getCONTENIDONavigation() {
185:         $cfg = cRegistry::getConfig();
186: 
187:         // Path to CONTENIDO navigation xml file
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:                 // Get only navigation value (pattern)
195:                 preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
196: 
197:                 // Get single navigation values
198:                 $navSubEntries = explode("/", $matches[1]);
199: 
200:                 if ($navSubEntries[0] == "navigation") { // CONTENIDO navigation
201:                                                          // case
202: 
203:                     // Define subnavigation name (example: navigation/content/linkchecker)
204:                     $this->_SubNav = $this->_getTranslatedNavigationName('//language/navigation/' . $navSubEntries[1] . '/' . $navSubEntries[2] . '/main');
205: 
206:                     // Define navigation name (example: navigation/content)
207:                     return $this->_getTranslatedNavigationName('//language/navigation/' . $navSubEntries[1] . '/main');
208:                 } else { // No CONTENIDO navigation case
209:                     return false;
210:                 }
211:             }
212:         } else {
213:             return false;
214:         }
215:     }
216: 
217:     /**
218:      * Get translated navigation name
219:      *
220:      * @param string $query
221:      * @return xml String of translated navigation nane
222:      */
223:     private function _getTranslatedNavigationName($query = '') {
224: 
225:         if ($query == '') {
226:             return false;
227:         }
228: 
229:         // Load CONTENIDO navigation xml file
230:         $this->_DOMDocument->load($this->_getNavigationXmlPath());
231: 
232:         // Create new DOMXPath
233:         $xpath = new DOMXPath($this->_DOMDocument);
234: 
235:         // Run defined query
236:         $entriesLang = $xpath->query($query);
237: 
238:         foreach ($entriesLang as $entry) {
239:             return $entry->firstChild->nodeValue;
240:         }
241:     }
242: 
243:     /**
244:      * Checks for plugin navigation entry and get navigation entries from
245:      * CONTENIDO navigation xml file
246:      *
247:      * @return bool
248:      */
249:     private function _checkAndGetPluginNavigation() {
250:         $cfg = cRegistry::getConfig();
251: 
252:         // Path to CONTENIDO navigation xml file
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:                 // If no entry at nav_sub database table founded,
263:                 // return false
264:                 if ($this->_ApiNavMainCollection->count() == 0) {
265:                     return false;
266:                 }
267: 
268:                 $row = $this->_ApiNavMainCollection->next();
269: 
270:                 // Define query
271:                 $query = '//' . $row->get('location');
272: 
273:                 // Load plugin navigation xml file
274:                 $this->_DOMDocument->load($contenidoLanguageFileLang);
275: 
276:                 // Create new DOMXPath
277:                 $xpath = new DOMXPath($this->_DOMDocument);
278: 
279:                 // Run defined query
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:      * Get founded plugin navigation entries
293:      *
294:      * @param string $contenidoNav
295:      * @return string boolean
296:      */
297:     private function _getPluginNavigation($contenidoNav = "") {
298:         global $belang;
299:         $cfg = cRegistry::getConfig();
300: 
301:         // Path to plugin specific navigation xml file with selected backend
302:         // language
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:             // Initializing founded variable
308:             $founded = "";
309: 
310:             for ($i = 0; $i < $this->_NavCount; $i++) {
311: 
312:                 // Get only navigation value (pattern)
313:                 preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
314: 
315:                 // Define query
316:                 $query = '//' . $matches[1];
317: 
318:                 // Load plugin navigation xml file
319:                 $this->_DOMDocument->load($pluginLanguageFileLang);
320: 
321:                 // Create new DOMXPath
322:                 $xpath = new DOMXPath($this->_DOMDocument);
323: 
324:                 // Run defined query
325:                 $entriesLang = $xpath->query($query);
326: 
327:                 // Prevent misarrangement
328:                 if ($entriesLang->length == 0) {
329:                     return false;
330:                 }
331: 
332:                 foreach ($entriesLang as $entry) {
333: 
334:                     // If we have more then one navigation entry, define
335:                     // menuname for other entries
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:                         // If we have an plugin with level one and no defined menuName, use subnavigation name
341:                         // as menuName
342:                         $menuName = $this->_SubNav;
343:                     }
344: 
345:                     $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 />";
346:                 }
347:             }
348: 
349:             // Prevent double entries
350:             $founded = array_unique($founded);
351: 
352:             // Initializing output variable
353:             $output = "";
354: 
355:             // Convert founded array to an string
356:             foreach ($founded as $entry) {
357:                 $output .= $entry;
358:             }
359: 
360:             return $output;
361:         } else {
362:             return false;
363:         }
364:     }
365: 
366: }
367: ?>
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0