page->requested); if( !empty($parts[2]) ){ if( $this->SetCurrLayout($parts[2]) ){ $this->EditLayout(); return; } //default layout }elseif( $this->SetCurrLayout($config['gpLayout']) ){ $this->EditLayout(); return; } //redirect $url = \gp\tool::GetUrl('Admin_Theme_Content','',false); \gp\tool::Redirect($url,302); } /** * Set the current layout * */ protected function SetCurrLayout($layout){ global $langmessage, $gpLayouts; if( !isset($gpLayouts[$layout]) ){ return false; } $this->curr_layout = $layout; $this->SetLayoutArray(); $this->page->SetTheme($layout); if( !$this->page->gpLayout ){ message($langmessage['OOPS'].' (Theme Not Found)'); parent::RunScript(); return false; } \gp\tool\Output::TemplateSettings(); return true; } /** * Edit layout properties * Layout Identification * Content Arrangement * Gadget Visibility * */ public function EditLayout(){ $GLOBALS['GP_ARRANGE_CONTENT'] = true; $this->layout_slug = 'Admin_Theme_Content/Edit/'.rawurlencode($this->curr_layout); $this->cmds['ShowThemeImages'] = ''; $this->cmds['SelectContent'] = ''; $this->cmds['LayoutMenu'] = ''; $this->cmds['LayoutMenuSave'] = 'ReturnHeader'; //show the layout (displayed within an iframe) $this->cmds['SaveCSS'] = 'ShowInIframe'; $this->cmds['PreviewCSS'] = 'ShowInIframe'; $this->cmds['addcontent'] = 'ShowInIframe'; $this->cmds['RemoveArea'] = 'ShowInIframe'; $this->cmds['DragArea'] = 'ShowInIframe'; $this->cmds['in_iframe'] = 'ShowInIframe'; \gp\tool\Plugins::Action('edit_layout_cmd',array($this->curr_layout)); $cmd = \gp\tool::GetCommand(); $this->LayoutCommands(); $this->RunCommands($cmd); } public function DefaultDisplay(){ global $langmessage; $layout_info = \gp\tool::LayoutInfo($this->curr_layout,false); $this->page->label = $langmessage['layouts'] . ' ยป '.$layout_info['label']; $this->LayoutEditor($this->curr_layout, $layout_info ); } /** * Prepare the page for css editing * */ public function ShowInIframe(){ $this->LoremIpsum(); $cmd = \gp\tool::GetCommand(); $this->page->show_admin_content = false; \gp\admin\Tools::$show_toolbar = false; // $this->page->head .= ''; if( $cmd != 'PreviewCSS' ){ $this->page->head .= ''; } } /** * Display the toolbar for layout editing * */ public function LayoutEditor($layout, $layout_info ){ global $langmessage, $gpAdmin; $_REQUEST += array('gpreq' => 'body'); //force showing only the body as a complete html document $this->page->get_theme_css = false; $this->page->css_user[] = '/include/thirdparty/codemirror/lib/codemirror.css'; $this->page->head_js[] = '/include/thirdparty/codemirror/lib/codemirror.js'; $this->page->head_js[] = '/include/thirdparty/codemirror/mode/css/css.js'; $this->page->css_admin[] = '/include/css/theme_content_outer.scss'; $this->page->head_js[] = '/include/js/theme_content_outer.js'; //custom css $css = $this->layoutCSS($this->curr_layout); $dir = $layout_info['dir'].'/'.$layout_info['theme_color']; $style_type = \gp\tool\Output::StyleType($dir); $style_type_info = array(); switch ($style_type) { case 'scss': $style_type_info['name'] = 'Scss'; $style_type_info['link'] = 'http://sass-lang.com/'; break; case 'less': $style_type_info['name'] = 'Less'; $style_type_info['link'] = 'http://lesscss.org/'; break; default: $style_type_info['name'] = 'CSS'; $style_type_info['link'] = 'https://developer.mozilla.org/docs/Web/CSS'; } //Iframe echo '
'; $url = \gp\tool::GetUrl('Admin_Theme_Content/Edit/'.rawurlencode($layout),'cmd=in_iframe'); echo ''; echo '
'; //CSS Editing ob_start(); echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '
'; $this->LayoutSelect($layout,$layout_info); echo '
'; //options echo '
'; echo ''.$langmessage['Layout Options'].''; echo '
'; echo '
    '; $this->LayoutOptions($layout,$layout_info); echo '
'; echo '
'; echo '
'; //css textarea echo '
'; echo '
'; //sytax links echo '
'; echo 'Syntax: '; echo '' . $style_type_info['name'] . ''; echo '
'; echo '
'; echo '
'; if( empty($css) ){ $var_file = $dir.'/variables.'.$style_type; if( file_exists($var_file) ){ $css = file_get_contents($var_file); } } //editor mode echo ''; echo '
'; echo '
'; // preview echo ''; // save echo ''; // reset echo ''; //cancel $cancel_url = !empty($_REQUEST['redir']) ? $_REQUEST['redir'] : 'Admin_Theme_Content'; echo \gp\tool::Link($cancel_url, $langmessage['Close'], '', 'class="gpcancel"'); echo '
'; // /.css_buttons echo '
'; echo '
'; //show site in iframe echo '
'; //#theme_editor $this->page->admin_html = ob_get_clean(); } /** * Display all the layouts available in a '; echo ''; echo ''; echo ''; $types = \gp\tool\Output\Sections::GetTypes(); echo ' '; echo ' '; echo ''; echo ''; echo ''; echo '

'; echo '

'; echo ' '; echo '
'; echo '

'; echo ''; //gadgets if( $count_gadgets > 0){ echo '
'; echo ''; echo ''; foreach($config['gadgets'] as $gadget => $info){ echo ''; echo ''; echo ''; echo ''; } echo ''; echo '
 
'; echo str_replace('_',' ',$gadget); echo ''; echo \gp\tool::Link($this->layout_slug,$langmessage['add'],$addQuery.'&insert='.$gadget,array('data-cmd'=>'creq')); echo '
'; echo ' '; echo '
'; echo '
'; } //menus echo '
'; echo '
'; echo ''; echo ''; echo ''; echo ''; $this->PresetMenuForm(); echo ''; echo '
'; echo ''; echo ' '; echo '
'; echo '
'; echo '
'; echo '
'; //custom area echo '
'; echo ''; echo ''; echo ''; $this->CustomMenuForm(); echo ''; echo ''; echo ' '; echo ''; echo ''; echo '
'; echo '
'; echo ''; } /** * Insert new content into a layout * */ public function AddContent(){ global $langmessage; //for ajax responses $this->page->ajaxReplace = array(); if( !isset($_REQUEST['where']) ){ message($langmessage['OOPS']); return false; } //prep destination if( !$this->GetValues($_REQUEST['where'],$to_container,$to_gpOutCmd) ){ return false; } $handlers = $this->GetAllHandlers(); $this->PrepContainerHandlers($handlers,$to_container,$to_gpOutCmd); //figure out what we're inserting $addtype =& $_REQUEST['addtype']; switch($_REQUEST['addtype']){ case 'new_extra': $extra_name = $this->NewExtraArea(); if( $extra_name === false ){ message($langmessage['OOPS'].' (2)'); return false; } $insert = 'Extra:'.$extra_name; break; case 'custom_menu': $insert = $this->NewCustomMenu(); break; case 'preset_menu': $insert = $this->NewPresetMenu(); break; default: $insert = $_REQUEST['insert']; break; } if( !$insert ){ message($langmessage['OOPS'].' (Nothing to insert)'); return false; } //new info $new_gpOutInfo = \gp\tool\Output::GetgpOutInfo($insert); if( !$new_gpOutInfo ){ message($langmessage['OOPS'].' (Nothing to insert)'); return false; } $new_gpOutCmd = rtrim($new_gpOutInfo['key'].':'.$new_gpOutInfo['arg'],':'); if( !$this->AddToContainer($handlers[$to_container],$to_gpOutCmd,$new_gpOutCmd,false) ){ return false; } $this->SaveHandlersNew($handlers); return true; } /** * Return the name of the cleansed extra area name, create file if it doesn't already exist * */ public function NewExtraArea(){ global $langmessage, $dataDir; $title = \gp\tool\Editing::CleanTitle($_REQUEST['extra_area']); if( empty($title) ){ message($langmessage['OOPS']); return false; } $data = \gp\tool\Editing::DefaultContent($_POST['type']); $file = $dataDir.'/data/_extra/'.$title.'/page.php'; if( \gp\admin\Content\Extra::AreaExists($title) !== false ){ return $title; } if( !\gp\tool\Files::SaveData($file,'file_sections',array($data) ) ){ message($langmessage['OOPS']); return false; } return $title; } public function RemoveArea(){ global $langmessage; //for ajax responses $this->page->ajaxReplace = array(); if( !$this->ParseHandlerInfo($_GET['param'],$curr_info) ){ message($langmessage['OOPS'].' (0)'); return; } $gpOutCmd = $curr_info['gpOutCmd']; $container = $curr_info['container']; //prep work $handlers = $this->GetAllHandlers(); $this->PrepContainerHandlers($handlers,$container,$gpOutCmd); //remove from $handlers[$container] $where = $this->ContainerWhere($gpOutCmd, $handlers[$container]); if( $where === false ){ return; } array_splice($handlers[$container],$where,1); $this->SaveHandlersNew($handlers); } /** * Get the position of $gpOutCmd in $container_info * */ public function ContainerWhere( $gpOutCmd, &$container_info, $warn = true){ global $langmessage; $where = array_search($gpOutCmd,$container_info); if( ($where === null) || ($where === false) ){ if( $warn ){ message($langmessage['OOPS'].' (Not found in container)'); } return false; } return $where; } /** * Display popup dialog for editing layout menus * */ public function LayoutMenu(){ global $langmessage, $gpLayouts; if( !$this->ParseHandlerInfo($_GET['handle'],$curr_info) ){ message($langmessage['00PS']); return; } $showCustom = false; $menu_args = $this->MenuArgs($curr_info); if( $curr_info['key'] == 'CustomMenu' ){ $showCustom = true; } echo '
'; echo ''; echo '
'; echo '
'; //preset menus $style = ''; if( $showCustom ){ $style = ' class="nodisplay"'; } echo '
'; echo '
'; echo ''; echo ''; $this->PresetMenuForm($menu_args); echo ''; echo '
'; echo ''; echo ' '; echo '
'; echo '
'; echo '
'; //custom menus $style = ' class="nodisplay"'; if( $showCustom ){ $style = ''; } echo '
'; echo '
'; echo ''; $this->CustomMenuForm($menu_args); echo ''; echo ''; echo ' '; echo ''; echo ''; echo '
'; echo '
'; echo '

'; echo $langmessage['see_also']; echo ' '; echo \gp\tool::Link('Admin/Menu',$langmessage['file_manager']); echo ', '; echo \gp\tool::Link('Admin_Theme_Content',$langmessage['content_arrangement']); echo '

'; echo '
'; echo '
'; } /** * Save the posted layout menu settings * */ public function LayoutMenuSave(){ global $langmessage, $gpLayouts; if( !$this->ParseHandlerInfo($_POST['handle'],$curr_info) ){ message($langmessage['OOPS'].' (0)'); return; } if( isset($_POST['new_handle']) ){ $new_gpOutCmd = $this->NewPresetMenu(); }else{ $new_gpOutCmd = $this->NewCustomMenu(); } if( $new_gpOutCmd === false ){ message($langmessage['OOPS'].' (1)'); return; } //prep $handlers = $this->GetAllHandlers($this->curr_layout); $container =& $curr_info['container']; $this->PrepContainerHandlers($handlers,$container,$curr_info['gpOutCmd']); //unchanged? if( $curr_info['gpOutCmd'] == $new_gpOutCmd ){ return; } if( !$this->AddToContainer($handlers[$container],$curr_info['gpOutCmd'],$new_gpOutCmd,true) ){ return; } $this->SaveHandlersNew($handlers,$this->curr_layout); } public function ParseHandlerInfo($str,&$info){ global $config,$gpOutConf; if( substr_count($str,'|') !== 1 ){ return false; } list($container,$fullKey) = explode('|',$str); $arg = ''; $pos = strpos($fullKey,':'); $key = $fullKey; if( $pos > 0 ){ $arg = substr($fullKey,$pos+1); $key = substr($fullKey,0,$pos); } if( !isset($gpOutConf[$key]) && !isset($config['gadgets'][$key]) ){ return false; } $info = array(); $info['gpOutCmd'] = trim($fullKey,':'); $info['container'] = $container; $info['key'] = $key; $info['arg'] = $arg; return true; } /** * Get the container and gpOutCmd from the $arg * */ public function GetValues($arg,&$container,&$gpOutCmd){ global $langmessage; if( substr_count($arg,'|') !== 1 ){ message($langmessage['OOPS'].' (Invalid argument)'); return false; } list($container,$gpOutCmd) = explode('|',$arg); return true; } public function AddToContainer(&$container_info,$to_gpOutCmd,$new_gpOutCmd,$replace=true,$offset=0){ global $langmessage; //add to to_container in front of $to_gpOutCmd if( !is_array($container_info) ){ message($langmessage['OOPS'].' (a1)'); return false; } //can't have two identical outputs in the same container $check = $this->ContainerWhere($new_gpOutCmd, $container_info, false); if( $check !== false ){ message($langmessage['OOPS']. ' (Area already in container)'); return false; } //if empty, just add if( count($container_info) === 0 ){ $container_info[] = $new_gpOutCmd; return true; } //insert $where = $this->ContainerWhere($to_gpOutCmd, $container_info); if( $where === false ){ return false; } $length = 1; if( $replace === false ){ $length = 0; $where += $offset; } array_splice($container_info,$where,$length,$new_gpOutCmd); return true; } public function NewCustomMenu(){ $upper_bound =& $_POST['upper_bound']; $lower_bound =& $_POST['lower_bound']; $expand_bound =& $_POST['expand_bound']; $expand_all =& $_POST['expand_all']; $source_menu =& $_POST['source_menu']; $this->CleanBounds($upper_bound,$lower_bound,$expand_bound,$expand_all,$source_menu); $arg = $upper_bound.','.$lower_bound.','.$expand_bound.','.$expand_all.','.$source_menu; return 'CustomMenu:'.$arg; } public function NewPresetMenu(){ global $gpOutConf; $new_gpOutCmd =& $_POST['new_handle']; if( !isset($gpOutConf[$new_gpOutCmd]) || !isset($gpOutConf[$new_gpOutCmd]['link']) ){ return false; } return rtrim($new_gpOutCmd.':'.$this->CleanMenu($_POST['source_menu']),':'); } public function PresetMenuForm($args = array()){ global $gpOutConf,$langmessage; $current_function =& $args['current_function']; $current_menu =& $args['source_menu']; $this->MenuSelect($current_menu); echo ''; echo $langmessage['Menu Output']; echo ''; $i = 0; foreach($gpOutConf as $outKey => $info){ if( !isset($info['link']) ){ continue; } echo ''; echo ''; echo ''; echo ''; echo ''; if( $current_function == $outKey ){ echo ''; }else{ echo ''; } echo ''; echo ''; $i++; } } public function MenuArgs($curr_info){ $menu_args = array(); if( $curr_info['key'] == 'CustomMenu' ){ $args = explode(',',$curr_info['arg']); $args += array( 0=>0, 1=>-1, 2=>-1, 3=>0, 4=>'' ); //defaults list($upper_bound,$lower_bound,$expand_bound,$expand_all,$source_menu) = $args; $this->CleanBounds($upper_bound,$lower_bound,$expand_bound,$expand_all,$source_menu); $menu_args['upper_bound'] = $upper_bound; $menu_args['lower_bound'] = $lower_bound; $menu_args['expand_bound'] = $expand_bound; $menu_args['expand_all'] = $expand_all; $menu_args['source_menu'] = $source_menu; }else{ $menu_args['current_function'] = $curr_info['key']; $menu_args['source_menu'] = $this->CleanMenu($curr_info['arg']); } return $menu_args; } /** * Output form elements for setting custom menu settings * * @param array $menu_args */ public function CustomMenuForm($menu_args = array()){ global $langmessage; $upper_bound =& $menu_args['upper_bound']; $lower_bound =& $menu_args['lower_bound']; $expand_bound =& $menu_args['expand_bound']; $expand_all =& $menu_args['expand_all']; $source_menu =& $menu_args['source_menu']; echo ''; $this->MenuSelect($source_menu); echo ''; $this->CustomMenuSection($langmessage['... Below Level'], 'upper_bound', $upper_bound); $this->CustomMenuSection($langmessage['... At And Above Level'], 'lower_bound', $lower_bound); echo ''; $this->CustomMenuSection($langmessage['... Below Level'], 'expand_bound', $expand_bound); echo ''; } public function CleanBounds(&$upper_bound,&$lower_bound,&$expand_bound,&$expand_all,&$source_menu){ $upper_bound = (int)$upper_bound; $upper_bound = max(0,$upper_bound); $upper_bound = min(4,$upper_bound); $lower_bound = (int)$lower_bound; $lower_bound = max(-1,$lower_bound); $lower_bound = min(4,$lower_bound); $expand_bound = (int)$expand_bound; $expand_bound = max(-1,$expand_bound); $expand_bound = min(4,$expand_bound); if( $expand_all ){ $expand_all = 1; }else{ $expand_all = 0; } $source_menu = $this->CleanMenu($source_menu); } public function CleanMenu($menu){ global $config; if( empty($menu) ){ return ''; } if( !isset($config['menus'][$menu]) ){ return ''; } return $menu; } /** * Output section for custom menu form * * @param string $label * @param string $name * @param int $value */ public function CustomMenuSection($label, $name, $value){ echo ''; } public function MenuSelect($source_menu){ global $config, $langmessage; echo ''; echo ''; echo ''; } }
'; echo $langmessage['Show Titles...']; echo '
'; echo $langmessage['Expand Menu...']; echo '
'; echo $langmessage['... Expand All']; echo ''; $attr = $expand_all ? 'checked' : ''; echo ''; echo '
'; echo $label; echo ''; echo ''; echo '
'; echo $langmessage['Source Menu']; echo '
'; echo $langmessage['Menu']; echo ''; echo ''; echo '