コード例 #1
0
 public static function display()
 {
     CANVAS::import('menu/megamenu');
     $input = JFactory::getApplication()->input;
     //params
     $tplparams = CANVAS::getTplParams();
     //menu type
     $menutype = $input->get('canvasmenu', 'mainmenu');
     //accessLevel
     $canvasacl = (int) $input->get('canvasacl', 1);
     $accessLevel = array(1, $canvasacl);
     if (in_array(3, $accessLevel)) {
         $accessLevel[] = 2;
     }
     $accessLevel = array_unique($accessLevel);
     sort($accessLevel);
     //languages
     $languages = array(trim($input->get('canvaslang', '*')));
     if ($languages[0] != '*') {
         $languages[] = '*';
     }
     //check config
     $currentconfig = $tplparams instanceof JRegistry ? json_decode($tplparams->get('mm_config', ''), true) : null;
     $mmkey = $menutype . ($canvasacl == 1 ? '' : '-' . $canvasacl);
     $mmconfig = array();
     if ($currentconfig) {
         for ($i = $canvasacl; $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;
     //build the menu
     $menu = new CANVASMenuMegamenu($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);
     //output the megamenu key to save
     echo $buffer . '<input id="megamenu-key" type="hidden" name="mmkey" value="' . $mmkey . '"/>';
 }
コード例 #2
0
 /**
  * Render megamenu block, then push the output into megamenu renderer to display
  *
  * @param   string  $position  The position of the modules to render
  * @param   array   $params    Associative array of values
  * @param   string  $content   Module content
  *
  * @return  string  The output of the script
  *
  * @since   11.1
  */
 public function render($info = null, $params = array(), $content = null)
 {
     CANVAS::import('menu/megamenu');
     $canvasapp = CANVAS::getApp();
     //we will check from params
     $menutype = empty($params['menutype']) ? empty($params['name']) ? $canvasapp->getParam('mm_type', 'mainmenu') : $params['name'] : $params['menutype'];
     $currentconfig = json_decode($canvasapp->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)) {
             $vlevels = array();
         }
         $vlevels[] = '';
         // extend a blank, default key
         // check if available configuration for language override
         $langcode = JFactory::getDocument()->language;
         $shortlangcode = substr($langcode, 0, 2);
         $types = array($menutype . '-' . $langcode, $menutype . '-' . $shortlangcode, $menutype);
         foreach ($types as $type) {
             foreach ($vlevels as $vlevel) {
                 $key = $type . ($vlevel !== '' ? '-' . $vlevel : '');
                 if (isset($currentconfig[$key])) {
                     $mmkey = $key;
                     $menutype = $type;
                     break 2;
                 } else {
                     if (isset($currentconfig[$type])) {
                         $mmkey = $menutype = $type;
                         break 2;
                     }
                 }
             }
         }
         if (isset($currentconfig[$mmkey])) {
             $mmconfig = $currentconfig[$mmkey];
             if (!is_array($mmconfig)) {
                 $mmconfig = array();
             }
         }
     }
     JDispatcher::getInstance()->trigger('onCANVASMegamenu', array(&$menutype, &$mmconfig, &$viewLevels));
     $mmconfig['access'] = $viewLevels;
     $menu = new CANVASMenuMegamenu($menutype, $mmconfig, $canvasapp->_tpl->params);
     $canvasapp->setBuffer($menu->render(true), 'megamenu', empty($params['name']) ? null : $params['name'], null);
     return '';
 }