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 $langmessage[$lang_key];
echo ' | ';
}
/**
* Display Sync Toggle
*
*/
protected static function ToggleSync($attr){
global $langmessage;
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{}
}
|