Esempio n. 1
0
 public static function display()
 {
     T3::import('menu/megamenu');
     $input = JFactory::getApplication()->input;
     //params
     $tplparams = T3::getTplParams();
     //menu type
     $menutype = $input->get('t3menu', 'mainmenu');
     //accessLevel
     $t3acl = (int) $input->get('t3acl', 1);
     $accessLevel = array(1, $t3acl);
     if (in_array(3, $accessLevel)) {
         $accessLevel[] = 2;
     }
     $accessLevel = array_unique($accessLevel);
     sort($accessLevel);
     //languages
     $languages = array(trim($input->get('t3lang', '*')));
     if ($languages[0] != '*') {
         $languages[] = '*';
     }
     //check config
     $currentconfig = $tplparams instanceof JRegistry ? json_decode($tplparams->get('mm_config', ''), true) : null;
     $mmkey = $menutype . ($t3acl == 1 ? '' : '-' . $t3acl);
     $mmconfig = array();
     if ($currentconfig) {
         for ($i = $t3acl; $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 T3MenuMegamenu($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 . '"/>';
 }
Esempio n. 2
0
 public static function display()
 {
     T3::import('menu/megamenu');
     $input = JFactory::getApplication()->input;
     $menutype = $input->get('t3menu', '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;
     $menu = new T3MenuMegamenu($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;
 }
Esempio n. 3
0
 function megamenu($menutype)
 {
     T3::import('menu/megamenu');
     //$file = T3_TEMPLATE_PATH.'/etc/megamenu.ini';
     //$currentconfig = json_decode(@file_get_contents ($file), true);
     $currentconfig = json_decode($this->getParam('mm_config', ''), true);
     $mmconfig = $currentconfig && isset($currentconfig[$menutype]) ? $currentconfig[$menutype] : array();
     $menu = new T3MenuMegamenu($menutype, $mmconfig, $this->_tpl->params);
     $menu->render();
     // add core megamenu.css in plugin
     // deprecated - will extend the core style into template megamenu.less & megamenu-responsive.less
     // to use variable overridden in template
     $this->addStyleSheet(T3_URL . '/css/megamenu.css');
     if ($this->getParam('responsive', 1)) {
         $this->addStyleSheet(T3_URL . '/css/megamenu-responsive.css');
     }
     // megamenu.css override in template
     $this->addCss('megamenu');
 }
Esempio n. 4
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)
 {
     T3::import('menu/megamenu');
     $t3app = T3::getApp();
     //we will check from params
     $menutype = empty($params['menutype']) ? empty($params['name']) ? $t3app->getParam('mm_type', 'mainmenu') : $params['name'] : $params['menutype'];
     $currentconfig = json_decode($t3app->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('onT3Megamenu', array(&$menutype, &$mmconfig, &$viewLevels));
     $mmconfig['access'] = $viewLevels;
     $menu = new T3MenuMegamenu($menutype, $mmconfig, $t3app->_tpl->params);
     $t3app->setBuffer($menu->render(true), 'megamenu', empty($params['name']) ? null : $params['name'], null);
     return '';
 }
 public static function afterInit()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $tplparams = $app->getTemplate(true)->params;
     if (!$app->isAdmin()) {
         // check if need update megamenu configuration
         if ($tplparams->get('mm_config_needupdate')) {
             T3::import('menu/megamenu');
             T3::import('admin/megamenu');
             $currentconfig = @json_decode($tplparams->get('mm_config', ''), true);
             if (!is_array($currentconfig)) {
                 $currentconfig = array();
             } else {
                 $menuassoc = T3AdminMegamenu::menus();
                 $menulangs = array();
                 $menutypes = array();
                 foreach ($menuassoc as $key => $massoc) {
                     $menutypes[] = $massoc->value;
                     $menulangs[$massoc->value] = $massoc->language;
                 }
             }
             foreach ($currentconfig as $menukey => $mmconfig) {
                 if (!is_array($mmconfig)) {
                     continue;
                 }
                 $menutype = $menukey;
                 if (!in_array($menutype, $menutypes) && preg_match('@(-(\\d))+$@', $menukey, $match)) {
                     $menutype = preg_replace('@(-(\\d))+$@', '', $menutype);
                     $access = explode('-', $match[0]);
                     $access[] = 1;
                     $access = array_filter($access);
                     $access = array_unique($access);
                     $mmconfig['access'] = $access;
                 }
                 if (!in_array($menutype, $menutypes)) {
                     continue;
                 }
                 $mmconfig['language'] = $menulangs[$menutype];
                 $menu = new T3MenuMegamenu($menutype, $mmconfig);
                 $children = $menu->get('children');
                 //remove additional settings
                 unset($mmconfig['language']);
                 unset($mmconfig['access']);
                 foreach ($mmconfig as $item => $setting) {
                     if (is_array($setting) && isset($setting['sub'])) {
                         $sub =& $setting['sub'];
                         $id = (int) substr($item, 5);
                         // remove item-
                         $modify = false;
                         if (!isset($children[$id]) || !count($children[$id])) {
                             //check and remove any empty row
                             for ($j = 0; $j < count($sub['rows']); $j++) {
                                 $remove = true;
                                 for ($k = 0; $k < count($sub['rows'][$j]); $k++) {
                                     if (isset($sub['rows'][$j][$k]['position'])) {
                                         $remove = false;
                                         break;
                                     }
                                 }
                                 if ($remove) {
                                     $modify = true;
                                     unset($sub['rows'][$j]);
                                 }
                             }
                             if ($modify) {
                                 $sub['rows'] = array_values($sub['rows']);
                                 //re-index
                                 $mmconfig[$item]['sub'] = $sub;
                             }
                             continue;
                         }
                         $items = array();
                         foreach ($sub['rows'] as $row) {
                             foreach ($row as $col) {
                                 if (!isset($col['position'])) {
                                     $items[] = $col['item'];
                                 }
                             }
                         }
                         // update the order of items
                         $_items = array();
                         $_itemsids = array();
                         $firstitem = 0;
                         foreach ($children[$id] as $child) {
                             $_itemsids[] = (int) $child->id;
                             if (!$firstitem) {
                                 $firstitem = (int) $child->id;
                             }
                             if (in_array($child->id, $items)) {
                                 $_items[] = (int) $child->id;
                             }
                         }
                         // $_items[0] = $firstitem;
                         if (empty($_items) || $_items[0] != $firstitem) {
                             if (count($_items) == count($items)) {
                                 $_items[0] = $firstitem;
                             } else {
                                 array_splice($_items, 0, 0, $firstitem);
                             }
                         }
                         // no need update config for this item
                         if ($items == $_items) {
                             continue;
                         }
                         // update back to setting
                         $i = 0;
                         $c = count($_items);
                         for ($j = 0; $j < count($sub['rows']); $j++) {
                             for ($k = 0; $k < count($sub['rows'][$j]); $k++) {
                                 if (!isset($sub['rows'][$j][$k]['position'])) {
                                     $sub['rows'][$j][$k]['item'] = $i < $c ? $_items[$i++] : "";
                                 }
                             }
                         }
                         //update - add new rows for new items - at the first rows
                         if (!empty($_items) && count($items) == 0) {
                             $modify = true;
                             array_unshift($sub['rows'], array(array('item' => $_items[0], 'width' => 12)));
                         }
                         //check and remove any empty row
                         for ($j = 0; $j < count($sub['rows']); $j++) {
                             $remove = true;
                             for ($k = 0; $k < count($sub['rows'][$j]); $k++) {
                                 if (isset($sub['rows'][$j][$k]['position']) || in_array($sub['rows'][$j][$k]['item'], $_itemsids)) {
                                     $remove = false;
                                     break;
                                 }
                             }
                             if ($remove) {
                                 $modify = true;
                                 unset($sub['rows'][$j]);
                             }
                         }
                         if ($modify) {
                             $sub['rows'] = array_values($sub['rows']);
                             //re-index
                         }
                         $mmconfig[$item]['sub'] = $sub;
                     }
                 }
                 $currentconfig[$menukey] = $mmconfig;
             }
             // update  megamenu back to other template styles parameter
             $mm_config = json_encode($currentconfig);
             // update megamenu back to current template style parameter
             $template = $app->getTemplate(true);
             $params = $template->params;
             $params->set('mm_config', $mm_config);
             $template->params = $params;
             //update the cache
             T3::setTemplate(T3_TEMPLATE, $params);
             //get all other styles that have the same template
             $db = JFactory::getDBO();
             $query = $db->getQuery(true);
             $query->select('*')->from('#__template_styles')->where('template=' . $db->quote(T3_TEMPLATE))->where('client_id=0');
             $db->setQuery($query);
             $themes = $db->loadObjectList();
             //update all global parameters
             foreach ($themes as $theme) {
                 $registry = new JRegistry();
                 $registry->loadString($theme->params);
                 $registry->set('mm_config', $mm_config);
                 //overwrite with new value
                 $registry->set('mm_config_needupdate', "");
                 //overwrite with new value
                 $query = $db->getQuery(true);
                 $query->update('#__template_styles')->set('params =' . $db->quote($registry->toString()))->where('id =' . (int) $theme->id);
                 $db->setQuery($query);
                 $db->execute();
             }
             // force reload cache template
             $cache = JFactory::getCache('com_templates', '');
             $cache->clean();
         }
     }
 }
Esempio n. 6
0
 /**
  * Render megamenu block
  *
  * @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)
 {
     T3::import('menu/megamenu');
     $t3app = T3::getApp();
     //we will check from params
     $menutype = empty($params['menutype']) ? $t3app->getParam('mm_type', 'mainmenu') : $params['menutype'];
     $currentconfig = json_decode($t3app->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;
             }
         }
         // check if available configuration for language override
         $langcode = substr(JFactory::getDocument()->language, 0, 2);
         $langtype = $menutype . '-' . $langcode;
         $langkey = $langtype . str_replace($menutype, '', $mmkey);
         if (isset($currentconfig[$langkey])) {
             $mmkey = $langkey;
             $menutype = $langtype;
         } else {
             if (isset($currentconfig[$langtype])) {
                 $mmkey = $menutype = $langtype;
             }
         }
         if (isset($currentconfig[$mmkey])) {
             $mmconfig = $currentconfig[$mmkey];
             if (!is_array($mmconfig)) {
                 $mmconfig = array();
             }
         }
     }
     JDispatcher::getInstance()->trigger('onT3Megamenu', array(&$menutype, &$mmconfig, &$viewLevels));
     $mmconfig['access'] = $viewLevels;
     $menu = new T3MenuMegamenu($menutype, $mmconfig, $t3app->_tpl->params);
     return $menu->render(true);
 }