page = $args['page']; $this->codes = array('301'=>$langmessage['301 Moved Permanently'],'302'=>$langmessage['302 Moved Temporarily']); \gp\tool\Editing::PrepAutoComplete(); $this->cmds['Save404'] = 'Edit404'; $this->cmds['Edit404'] = ''; $this->cmds['EditRedir'] = ''; $this->cmds['UpdateRedir'] = 'DefaultDisplay'; $this->cmds['SaveRedir'] = 'DefaultDisplay'; $this->cmds['RmRedir'] = 'DefaultDisplay'; } /** * Add instructions for a 301 or 302 redirect * */ public static function AddRedirect($source,$target){ global $dataDir; $datafile = $dataDir.'/data/_site/error_data.php'; $error_data = \gp\tool\Files::Get('_site/error_data'); if( !$error_data ){ $error_data = array(); } $changed = false; //remove redirects from the $target if( isset($error_data['redirects'][$target]) ){ unset($error_data['redirects'][$target]); $changed = true; } //redirect already exists for $source if( !isset($error_data['redirects'][$source]) ){ $error_data['redirects'][$source]['target'] = $target; $error_data['redirects'][$source]['code'] = '301'; $changed = true; } if( $changed ){ \gp\tool\Files::SaveData($datafile,'error_data',$error_data); } } protected function SaveMissingData(){ global $langmessage; if( !\gp\tool\Files::SaveData($this->datafile,'error_data',$this->error_data) ){ message($langmessage['OOPS']); return false; } message($langmessage['SAVED']); return true; } protected function GetCodeLanguage($code){ global $langmessage; switch($code){ case '301': return $langmessage['301 Moved Permanently']; case '302': return $langmessage['302 Moved Temporarily']; } return ''; } /** * Show 404 info and Redirection list * */ public function DefaultDisplay(){ global $langmessage; echo '
'.$langmessage['404_Usage'].'
'; //404 Page echo ''.$langmessage['About_404_Page'].'
'; echo ''; echo \gp\tool::Link('Special_Missing',$langmessage['preview'],'','class="gpsubmit"'); echo ' '; echo \gp\tool::Link('Admin/Missing',$langmessage['edit'],'cmd=Edit404','class="gpsubmit"'); echo '
'; echo ''; echo $langmessage['Useful Variables']; echo ' | |
---|---|
'; echo '{{Similar_Titles}}'; echo ' | '; echo $langmessage['Similar_Titles']; echo ' | '; echo '
'; echo $langmessage['About_Redirection']; echo '
'; echo ''; echo ''; echo ' '; echo $langmessage['Target URL Invalid']; echo ''; echo '
'; } } /** * Return true if the target is a valid url * * @return bool */ public function ValidTarget($target){ global $gp_index; if( empty($target) ){ return true; } if( !$this->isGPLink($target) ){ return true; } if( isset($gp_index[$target]) ){ return true; } $type = \gp\tool::SpecialOrAdmin($target); if( $type == 'admin' ){ return true; } return false; } /** * Add Redirection form for * */ protected function AddMissingRow(){ global $langmessage; $_REQUEST += array('source'=>'','target'=>'','code'=>'','orig_source'=>''); //source echo ''; echo '