true, 'all' => true, 'hidden' => true, 'nomenus' => true ); public $section_types; protected $cmd; public function __construct($args){ global $langmessage, $config; parent::__construct($args); $this->section_types = \gp\tool\Output\Sections::GetTypes(); $this->page->ajaxReplace = array(); $this->page->css_admin[] = '/include/css/admin_menu_new.css'; $this->page->head_js[] = '/include/thirdparty/js/nestedSortable.js'; $this->page->head_js[] = '/include/thirdparty/js/jquery_cookie.js'; $this->page->head_js[] = '/include/js/admin_menu_new.js'; $this->max_level_index = max(3, gp_max_menu_level-1); $this->page->head_script .= 'var max_level_index = ' . $this->max_level_index . ';'; $this->avail_menus['gpmenu'] = $langmessage['Main Menu'] . ' / ' . $langmessage['site_map']; $this->avail_menus['all'] = $langmessage['All Pages']; $this->avail_menus['hidden'] = $langmessage['Not In Main Menu']; $this->avail_menus['nomenus'] = $langmessage['Not In Any Menus']; $this->avail_menus['search'] = $langmessage['search pages']; if( isset($config['menus']) ){ foreach($config['menus'] as $id => $menu_label){ $this->avail_menus[$id] = $menu_label; } } //read cookie settings if( isset($_COOKIE['gp_menu_prefs']) ){ parse_str($_COOKIE['gp_menu_prefs'], $this->cookie_settings); } $this->SetMenuID(); $this->SetMenuArray(); $this->SetCollapseSettings(); $this->SetQueryInfo(); $cmd = \gp\tool::GetCommand(); $this->cmd = \gp\tool\Plugins::Filter('MenuCommand', array($cmd)); } public function RunScript(){ if( $this->cmd === 'return' ){ return; } switch($this->cmd){ case 'drag': $this->SaveDrag(); break; //layout case 'layout': case 'uselayout': case 'restorelayout': $page_layout = new \gp\Page\Layout($this->cmd, 'Admin/Menu', $this->query_string); if( $page_layout->result() ){ return; } break; } $this->ShowForm(); } /** * @param string $href * @param string $label * @param string $query * @param string|array $attr * @param mixed $nonce_action * */ public function Link($href, $label, $query='', $attr='', $nonce_action=false){ $query = $this->MenuQuery($query); return \gp\tool::Link($href, $label, $query, $attr, $nonce_action); } public function GetUrl($href, $query='', $ampersands=true){ $query = $this->MenuQuery($query); return \gp\tool::GetUrl($href,$query,$ampersands); } public function MenuQuery($query=''){ if( !empty($query) ){ $query .= '&'; } $query .= 'menu=' . $this->curr_menu_id; if( strpos($query, 'page=') !== false ){ //do nothing }elseif( $this->search_page > 0 ){ $query .= '&page=' . $this->search_page; } //for searches if( !empty($_REQUEST['q']) ){ $query .= '&q='.urlencode($_REQUEST['q']); } return $query; } public function SetQueryInfo(){ //search page if( isset($_REQUEST['page']) && is_numeric($_REQUEST['page']) ){ $this->search_page = (int)$_REQUEST['page']; } //browse query string $this->query_string = $this->MenuQuery(); } public function SetCollapseSettings(){ $gp_menu_collapse =& $_COOKIE['gp_menu_hide']; $search = '#' . $this->curr_menu_id . '=['; $gp_menu_collapse .= ""; $pos = strpos($gp_menu_collapse, $search); if( $pos === false ){ return; } $gp_menu_collapse = substr($gp_menu_collapse, intval($pos) + intval(strlen($search))); $pos = strpos($gp_menu_collapse, ']'); if( $pos === false ){ return; } $gp_menu_collapse = substr($gp_menu_collapse, 0, $pos); $gp_menu_collapse = trim($gp_menu_collapse, ','); $this->hidden_levels = explode(',', $gp_menu_collapse); $this->hidden_levels = array_flip($this->hidden_levels); } /** * Get the id for the current menu * Not the same order as used for $_REQUEST * */ public function SetMenuID(){ if( isset($this->curr_menu_id) ){ return; } if( isset($_POST['menu']) ){ $this->curr_menu_id = $_POST['menu']; }elseif( isset($_GET['menu']) ){ $this->curr_menu_id = $_GET['menu']; }elseif( isset($this->cookie_settings['gp_menu_select']) ){ $this->curr_menu_id = $this->cookie_settings['gp_menu_select']; } if( !isset($this->curr_menu_id) || !isset($this->avail_menus[$this->curr_menu_id]) ){ $this->curr_menu_id = 'gpmenu'; } } public function SetMenuArray(){ global $gp_menu; if( isset($this->list_displays[$this->curr_menu_id]) ){ return; } //set curr_menu_array if( $this->curr_menu_id == 'gpmenu' ){ $this->curr_menu_array =& $gp_menu; $this->is_main_menu = true; return; } $this->curr_menu_array = \gp\tool\Output\Menu::GetMenuArray($this->curr_menu_id); $this->is_alt_menu = true; } public function SaveMenu($menu_and_pages=false){ global $dataDir; if( $this->is_main_menu ){ return \gp\admin\Tools::SavePagesPHP(); } if( is_null($this->curr_menu_array) ){ return false; } if( $menu_and_pages && !\gp\admin\Tools::SavePagesPHP() ){ return false; } $menu_file = $dataDir . '/data/_menus/' . $this->curr_menu_id . '.php'; return \gp\tool\Files::SaveData($menu_file, 'menu', $this->curr_menu_array); } /** * Primary Display * * */ public function ShowForm(){ global $langmessage, $config; $menu_output = false; ob_start(); if( isset($this->list_displays[$this->curr_menu_id]) ){ $this->SearchDisplay(); $replace_id = '#gp_menu_available'; }else{ $menu_output = true; $this->OutputMenu(); $replace_id = '#admin_menu'; } $content = ob_get_clean(); // json response if( isset($_REQUEST['gpreq']) && ($_REQUEST['gpreq'] == 'json') ){ $this->MenuJsonResponse($replace_id, $content); return; } // search form echo ''; $menus = $this->GetAvailMenus('menu'); $lists = $this->GetAvailMenus('display'); //heading echo '
'; echo ''; echo '

'; echo $langmessage['file_manager'] . ' » '; echo ''; echo '

'; echo '
'; //homepage echo '
'; $this->HomepageDisplay(); echo '
'; \gp\tool\Editing::PrepAutoComplete(); echo '
'; if( $menu_output ){ echo '
'; echo ''; echo ''; echo ''; }else{ echo '
'; echo $content; echo '
'; } echo '
'; echo '
'; echo '
'; echo ''.$langmessage['Menus'].''; $this->MenuList($menus); echo ''; echo \gp\tool::Link( 'Admin/Menu/Menus', '+ ' . $langmessage['Add New Menu'], 'cmd=NewMenuPrompt', 'data-cmd="gpabox"' ); echo ''; echo '
'; echo '
'; echo ''.$langmessage['Lists'].''; $this->MenuList($lists); echo '
'; //options for alternate menu if( $this->is_alt_menu ){ echo '
'; $label = $menus[$this->curr_menu_id]; echo ''.$label.''; echo ''; echo \gp\tool::Link( 'Admin/Menu/Menus', $langmessage['rename'], 'cmd=MenuRenamePrompt&id=' . $this->curr_menu_id, 'data-cmd="gpabox"' ); echo ''; $title_attr = sprintf($langmessage['generic_delete_confirm'], '"' . $label . '"'); echo ''; echo \gp\tool::Link( 'Admin/Menu/Menus', $langmessage['delete'], 'cmd=MenuRemove&id=' . $this->curr_menu_id, array( 'data-cmd' => 'cnreq', 'class' => 'gpconfirm', 'title' => $title_attr ) ); echo ''; echo '
'; } echo '
'; echo '
'; } /** * Generate link list for available menus * */ public function MenuList($menus){ foreach($menus as $menu_id => $menu_label){ if( $menu_id == $this->curr_menu_id ){ echo '' . $menu_label . ''; }else{ echo ''; echo \gp\tool::Link( 'Admin/Menu', $menu_label, 'menu=' . $menu_id, array('data-cmd' => 'cnreq') ); echo ''; } } } public function GetAvailMenus($get_type='menu'){ $result = array(); foreach($this->avail_menus as $menu_id => $menu_label){ $menu_type = 'menu'; if( isset($this->list_displays[$menu_id]) ){ $menu_type = 'display'; } if( $menu_type == $get_type ){ $result[$menu_id] = $menu_label; } } return $result; } /** * Send updated page manager content via ajax * we're replacing more than just the content * */ public function MenuJsonResponse($replace_id, $content){ $this->page->ajaxReplace[] = array('gp_menu_prep', '', ''); $this->page->ajaxReplace[] = array('inner', $replace_id, $content); $this->page->ajaxReplace[] = array('gp_menu_refresh', '', ''); ob_start(); $this->HomepageDisplay(); $content = ob_get_clean(); $this->page->ajaxReplace[] = array('inner', '.homepage_setting', $content); ob_start(); \gp\tool\Output::GetTopTwoMenu(); $content = ob_get_clean(); $this->page->ajaxReplace[] = array('inner', '#admin_menu_wrap', $content); } public function OutputMenu(){ global $langmessage, $gp_titles, $gpLayouts; if( is_null($this->curr_menu_array) ){ msg($langmessage['OOPS'] . ' (Current menu not set)'); return; } $array = $this->CurrMenuArray(); $menu_keys = array_keys($array); $menu_values = array_values($array); $curr_level = $menu_values[0]['level']; //for sites that don't start with level 0 $prev_level = 0; if( $curr_level > 0 ){ $piece = '
  •