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
    • 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: 
141:         $cfg = cRegistry::getConfig();
142: 
143:         // Get contents of plugin.xml file
144:         $dataPluginXml = file_get_contents($cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->PluginFoldername . DIRECTORY_SEPARATOR . self::PLUGIN_CONFIG_FILENAME);
145: 
146:         // Load xml strings
147:         $xmlPluginXml = simplexml_load_string($dataPluginXml);
148: 
149:         // Count nav_sub entries for this plugin
150:         $entries = $xmlPluginXml->contenido->nav_sub->nav;
151:         $this->_NavCount = is_object($entries) ? count($entries) : 0;
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:                 if (cSecurity::toInteger(self::$XmlNavSub->nav[$i]->attributes()->navm) > 0)  {
260:                     $this->_ApiNavMainCollection->setWhere('idnavm', cSecurity::toInteger(self::$XmlNavSub->nav[$i]->attributes()->navm));
261:                 } else {
262:                     $this->_ApiNavMainCollection->setWhere('name', cSecurity::escapeString(self::$XmlNavSub->nav[$i]->attributes()->navm));
263:                 }
264: 
265:                 $this->_ApiNavMainCollection->query();
266: 
267:                 // If no entry at nav_sub database table founded,
268:                 // return false
269:                 if ($this->_ApiNavMainCollection->count() == 0) {
270:                     return false;
271:                 }
272: 
273:                 $row = $this->_ApiNavMainCollection->next();
274: 
275:                 // Define query
276:                 $query = '//' . $row->get('location');
277: 
278:                 // Load plugin navigation xml file
279:                 $this->_DOMDocument->load($contenidoLanguageFileLang);
280: 
281:                 // Create new DOMXPath
282:                 $xpath = new DOMXPath($this->_DOMDocument);
283: 
284:                 // Run defined query
285:                 $entriesLang = $xpath->query($query);
286: 
287:                 foreach ($entriesLang as $entry) {
288:                     return $entry->firstChild->nodeValue;
289:                 }
290:             }
291:         } else {
292:             return false;
293:         }
294:     }
295: 
296:     /**
297:      * Get founded plugin navigation entries
298:      *
299:      * @param string $contenidoNav
300:      * @return string boolean
301:      */
302:     private function _getPluginNavigation($contenidoNav = "") {
303:         global $belang;
304:         $cfg = cRegistry::getConfig();
305: 
306:         // Path to plugin specific navigation xml file with selected backend
307:         // language
308:         $pluginLanguageFileLang = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->PluginFoldername . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . $cfg['lang'][$belang];
309: 
310:         if (cFileHandler::exists($pluginLanguageFileLang) && $contenidoNav != "") {
311: 
312:             // Initializing founded array
313:             $founded = array();
314: 
315:             for ($i = 0; $i < $this->_NavCount; $i++) {
316: 
317:                 // Get only navigation value (pattern)
318:                 preg_match(self::PATTERN, self::$XmlNavSub->nav[$i], $matches);
319: 
320:                 // Define query
321:                 $query = '//' . $matches[1];
322: 
323:                 // Load plugin navigation xml file
324:                 $this->_DOMDocument->load($pluginLanguageFileLang);
325: 
326:                 // Create new DOMXPath
327:                 $xpath = new DOMXPath($this->_DOMDocument);
328: 
329:                 // Run defined query
330:                 $entriesLang = $xpath->query($query);
331: 
332:                 // Prevent misarrangement
333:                 if ($entriesLang->length == 0) {
334:                     return false;
335:                 }
336: 
337:                 foreach ($entriesLang as $entry) {
338: 
339:                     // If we have more then one navigation entry, define
340:                     // menuname for other entries
341:                     if (self::$XmlNavSub->nav[$i]->attributes()->level == 0 && $this->_NavCount > 1) {
342:                         $menuName = $entry->nodeValue;
343:                         continue;
344:                     } elseif (self::$XmlNavSub->nav[$i]->attributes()->level == 1 && $menuName == '') {
345:                         // If we have an plugin with level one and no defined menuName, use subnavigation name
346:                         // as menuName
347:                         $menuName = $this->_SubNav;
348:                     }
349: 
350:                     $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 />";
351:                 }
352:             }
353: 
354:             // Prevent double entries
355:             $founded = array_unique($founded);
356: 
357:             // Initializing output variable
358:             $output = "";
359: 
360:             // Convert founded array to an string
361:             foreach ($founded as $entry) {
362:                 $output .= $entry;
363:             }
364: 
365:             return $output;
366:         } else {
367:             return false;
368:         }
369:     }
370: 
371: }
372: ?>
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0