requested); $label = \gp\tool::GetLabelIndex($index); $title = \gp\tool::IndexToTitle($index); $title_info = $gp_titles[$index]; $title_info += array( 'browser_title' => '', 'keywords' => '', 'description' => '', 'rel' => '', ); if( empty($_REQUEST['new_title']) ){ $new_title = \gp\tool::LabelSpecialChars($label); }else{ $new_title = htmlspecialchars($_REQUEST['new_title']); } $new_title = str_replace('_',' ',$new_title); ob_start(); echo '
'; echo '
'; echo ''; echo ''; echo '

'.$langmessage['rename/details'].'

'; echo ''; echo ''; echo ''; echo ''; echo ''; //label self::FormLabel('label'); echo ''; echo ''; //slug (title) $attr = ''; $class = 'new_title'; if( $title == \gp\admin\Tools::LabelToSlug($label) ){ //$attr = 'disabled="disabled" '; $attr = 'readonly="readonly"" '; $class .= ' sync_label'; } self::FormLabel('Slug/URL'); echo ''; self::ToggleSync($attr); echo ''; //browser title defaults to label $attr = ''; $class = 'browser_title'; $browser_title = $title_info['browser_title']; self::FormLabel('browser_title',$title_info['browser_title']); if( empty($title_info['browser_title']) ){ $browser_title = htmlspecialchars($label); $attr = 'readonly="readonly" '; $class .= ' sync_label'; } echo ''; self::ToggleSync($attr); echo ''; //meta keywords self::FormLabel('keywords',$title_info['keywords']); echo ''; echo ''; //meta description self::FormLabel('description',$title_info['description']); $count_label = sprintf($langmessage['_characters'],''.strlen($title_info['description']).''); echo ''; echo ''; echo ''.$count_label.''; echo ''; echo ''; //robots self::FormLabel('robots',$title_info['rel']); echo ''; echo ''; echo ''; echo ''; echo '
'; echo $langmessage['options']; echo '
'; //redirection echo '

'; echo ''; echo '

'; echo '

'; if( self::$hidden_rows ) echo '   + '.$langmessage['more_options'].''; echo '

'; echo '

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

'; echo '
'; echo '
'; $content = ob_get_clean(); $page->ajaxReplace = array(); $array = array(); $array[0] = 'gpabox'; $array[1] = ''; $array[2] = $content; $page->ajaxReplace[] = $array; //call renameprep function after admin_box $array = array(); $array[0] = 'renameprep'; $array[1] = ''; $array[2] = ''; $page->ajaxReplace[] = $array; } protected static function FormLabel($lang_key, $hidden_if_empty = 'not-empty' ){ global $langmessage; if( empty($hidden_if_empty) ){ echo ''; self::$hidden_rows = true; }else{ echo ''; } echo ''; echo $langmessage[$lang_key]; echo ''; } /** * Display Sync Toggle * */ protected static function ToggleSync($attr){ global $langmessage; echo '
'; if( empty( $attr ) ){ echo ''.$langmessage['sync_with_label'].''; echo ''.$langmessage['edit'].''; }else{ echo ''.$langmessage['sync_with_label'].''; echo ''.$langmessage['edit'].''; } echo '
'; } /** * Handle renaming a page based on POSTed data * */ public static function RenameFile($title){ global $langmessage, $page, $gp_index, $gp_titles; $page->ajaxReplace = array(); //change the title $title = self::RenameFileWorker($title); if( $title === false ){ return false; } if( !isset($gp_index[$title]) ){ msg($langmessage['OOPS']); return false; } $id = $gp_index[$title]; $title_info = &$gp_titles[$id]; //change the label $title_info['label'] = \gp\admin\Tools::PostedLabel($_POST['new_label']); if( isset($title_info['lang_index']) ){ unset($title_info['lang_index']); } //browser_title, keywords, description self::SetInfo($title_info, 'browser_title'); self::SetInfo($title_info, 'keywords'); self::SetInfo($title_info, 'description'); self::SetRobots($title_info); //same as auto-generated? $auto_browser_title = strip_tags($title_info['label']); if( isset($title_info['browser_title']) && $title_info['browser_title'] == $auto_browser_title ){ unset($title_info['browser_title']); } if( !\gp\admin\Tools::SavePagesPHP(true,true) ){ return false; } return $title; } /** * Set the title_info value if not emptpy * Otherwise, unset the key * */ private static function SetInfo( &$title_info, $key){ if( isset($_POST[$key]) ){ $title_info[$key] = htmlspecialchars($_POST[$key]); if( empty($title_info[$key]) ){ unset($title_info[$key]); } } } /** * Set the robot visibility * */ private static function SetRobots(&$title_info){ $title_info['rel'] = ''; if( isset($_POST['nofollow']) ){ $title_info['rel'] = 'nofollow'; } if( isset($_POST['noindex']) ){ $title_info['rel'] .= ',noindex'; } $title_info['rel'] = trim($title_info['rel'],','); if( empty($title_info['rel']) ){ unset($title_info['rel']); } } private static function RenameFileWorker($title){ global $langmessage,$dataDir,$gp_index; //use new_label or new_title if( isset($_POST['new_title']) ){ $new_title = \gp\admin\Tools::PostedSlug($_POST['new_title']); }else{ $new_title = \gp\admin\Tools::LabelToSlug($_POST['new_label']); } //title unchanged if( $new_title == $title ){ return $title; } $special_file = false; if( \gp\tool::SpecialOrAdmin($title) !== false ){ $special_file = true; } if( !\gp\admin\Tools::CheckTitle($new_title,$message) ){ msg($message); return false; } $old_gp_index = $gp_index; //re-index: make the new title point to the same data index $old_file = \gp\tool\Files::PageFile($title); $file_index = $gp_index[$title]; unset($gp_index[$title]); $gp_index[$new_title] = $file_index; //rename the php file if( !$special_file ){ $new_file = \gp\tool\Files::PageFile($new_title); //if the file being renamed doesn't use the index naming convention, then we'll still need to rename it if( $new_file != $old_file ){ $new_dir = dirname($new_file); $old_dir = dirname($old_file); if( !\gp\tool\Files::Rename($old_dir,$new_dir) ){ msg($langmessage['OOPS'].' (N3)'); $gp_index = $old_gp_index; return false; } } //gallery rename \gp\special\Galleries::RenamedGallery($title,$new_title); } //create a 301 redirect if( isset($_POST['add_redirect']) && $_POST['add_redirect'] == 'add' ){ \gp\admin\Settings\Missing::AddRedirect($title,$new_title); } \gp\tool\Plugins::Action('RenameFileDone',array($file_index, $title, $new_title)); return $new_title; } /** * Rename a page * */ public static function RenamePage(){ global $langmessage, $gp_index, $page; $new_title = self::RenameFile($page->title); if( ($new_title !== false) && $new_title != $page->title ){ msg(sprintf($langmessage['will_redirect'],\gp\tool::Link_Page($new_title))); $page->head .= ''; $page->ajaxReplace[] = array('location',\gp\tool::GetUrl($new_title,'',false,''),15000); return true; } return false; } } } namespace{ class gp_rename extends \gp\Page\Rename{} }