Exemple #1
0
 public static function display()
 {
     Plazart::import('menu/megamenu');
     $input = JFactory::getApplication()->input;
     $menutype = $input->get('plazartmenu', 'mainmenu');
     $tplparams = $input->get('tplparams', '', 'raw');
     //		$currentconfig = $tplparams instanceof JRegistry ? json_decode($tplparams->get('mm_config', ''), true) : null;
     //		$mmconfig = ($currentconfig && isset($currentconfig[$menutype])) ? $currentconfig[$menutype] : array();
     //		$mmconfig['editmode'] = true;
     //accessLevel
     $accessLevel = array();
     $plazartacl = (int) $input->get('plazartacl', 6);
     for ($i = 1; $i <= $plazartacl; $i++) {
         $accessLevel[] = $i;
     }
     $accessLevel = array_unique($accessLevel);
     //languages
     $languages = array(trim($input->get('plazartlang', '*')));
     if ($languages[0] != '*') {
         $languages[] = '*';
     }
     //check config
     $currentconfig = $tplparams instanceof JRegistry ? json_decode($tplparams->get('mm_config', ''), true) : null;
     $mmkey = $menutype . ($plazartacl == 1 ? '' : '-' . $plazartacl);
     $mmconfig = array();
     if ($currentconfig) {
         for ($i = $plazartacl; $i >= 1; $i--) {
             $tmmkey = $menutype . ($i == 1 ? '' : '-' . $i);
             if (isset($currentconfig[$tmmkey])) {
                 $mmconfig = $currentconfig[$tmmkey];
                 break;
             }
         }
     }
     if (!is_array($mmconfig)) {
         $mmconfig = array();
     }
     $mmconfig['editmode'] = true;
     $mmconfig['access'] = $accessLevel;
     $mmconfig['language'] = $languages;
     $menu = new PlazartMenuMegamenu($menutype, $mmconfig);
     $buffer = $menu->render(true);
     // replace image path
     $base = JURI::base(true) . '/';
     $protocols = '[a-zA-Z0-9]+:';
     //To check for all unknown protocals (a protocol must contain at least one alpahnumeric fillowed by :
     $regex = '#(src)="(?!/|' . $protocols . '|\\#|\')([^"]*)"#m';
     $buffer = preg_replace($regex, "\$1=\"{$base}\$2\"", $buffer);
     //remove invisibile content
     $buffer = preg_replace(array('@<style[^>]*?>.*?</style>@siu', '@<script[^>]*?.*?</script>@siu'), array('', ''), $buffer);
     echo $buffer;
 }
Exemple #2
0
 function megamenu($menutype)
 {
     Plazart::import('menu/megamenu');
     $currentconfig = json_decode($this->getParam('mm_config', ''), true);
     //force to array
     if (!is_array($currentconfig)) {
         $currentconfig = (array) $currentconfig;
     }
     //get user access levels
     $viewLevels = JFactory::getUser()->getAuthorisedViewLevels();
     $mmkey = $menutype;
     $mmconfig = array();
     if (!empty($currentconfig)) {
         //find best fit configuration based on view level
         $vlevels = array_merge($viewLevels);
         if (is_array($vlevels) && in_array(3, $vlevels)) {
             //we assume, if a user is special, they should be registered also
             $vlevels[] = 2;
         }
         $vlevels = array_unique($vlevels);
         rsort($vlevels);
         if (is_array($vlevels) && count($vlevels)) {
             //should check for special view level first
             if (in_array(3, $vlevels)) {
                 array_unshift($vlevels, 3);
             }
             $found = false;
             foreach ($vlevels as $vlevel) {
                 $mmkey = $menutype . '-' . $vlevel;
                 if (isset($currentconfig[$mmkey])) {
                     $found = true;
                     break;
                 }
             }
             //fallback
             if (!$found) {
                 $mmkey = $menutype;
             }
         }
         //we try to switch the language if we are in public
         if ($mmkey == $menutype) {
             // check if available configuration for language override
             $langcode = substr(JFactory::getDocument()->language, 0, 2);
             if (isset($currentconfig[$menutype . '-' . $langcode])) {
                 $mmkey = $menutype = $menutype . '-' . $langcode;
             }
         }
         if (isset($currentconfig[$mmkey])) {
             $mmconfig = $currentconfig[$mmkey];
         }
     }
     $mmconfig['access'] = $viewLevels;
     $menu = new PlazartMenuMegamenu($menutype, $mmconfig, $this->getParam(true));
     $menu->render();
 }