page = $args['page']; $this->folder = $dataDir.'/data/_extra'; $this->SetVars(); } public function RunScript(){ // area specific commands if( !is_null($this->file) ){ $this->cmds['DeleteArea'] = 'DefaultDisplay'; $this->cmds['EditExtra'] = ''; $this->cmds['PublishDraft'] = 'DefaultDisplay'; $this->cmds['PublishAjax'] = ''; $this->cmds['PreviewText'] = ''; $this->cmds['SaveText'] = 'EditExtra'; /* inline editing */ $this->cmds['save'] = 'SectionEdit'; $this->cmds['save_inline'] = 'SectionEdit'; $this->cmds['preview'] = 'SectionEdit'; $this->cmds['include_dialog'] = 'SectionEdit'; $this->cmds['InlineEdit'] = 'SectionEdit'; } $this->cmds['gallery_folder'] = 'GalleryImages'; $this->cmds['gallery_images'] = 'GalleryImages'; $this->cmds['new_dir'] = '\\gp\\tool\\Editing::NewDirForm'; $this->cmds['NewSection'] = 'DefaultDisplay'; $cmd = \gp\tool::GetCommand(); $this->RunCommands($cmd); } /** * Get a list of all extra edit areas * */ public function SetVars(){ global $langmessage; $this->GetAreas(); // is there a specific file being requested if( !isset($_REQUEST['file']) ){ return; } $area_info = $this->ExtraExists($_REQUEST['file']); if( is_null($area_info) ){ message($langmessage['OOPS'].' (Invalid File)'); return; } $this->area_info = $area_info; $this->file = $area_info['file_path']; $this->title = \gp\tool\Editing::CleanTitle($area_info['title']); $this->draft_file = $area_info['draft_path']; $this->file_sections = \gp\tool\Output::ExtraContent($this->title); $this->meta_data = \gp\tool\Files::$last_meta; $this->fileModTime = \gp\tool\Files::$last_modified; $this->file_stats = \gp\tool\Files::$last_stats; if( \gp\tool\Files::Exists($this->draft_file) ){ $this->draft_exists = true; } } /** * Get a list of all extra edit areas * */ public function GetAreas(){ $this->areas = array(); $files = scandir($this->folder); foreach($files as $file){ $this->AddArea($file); } uksort($this->areas,'strnatcasecmp'); } /** * Add $file to the list of areas * */ private function AddArea($title){ $title = self::AreaExists($title); if( $title == false ){ return; } $this->areas[$title] = array(); $this->areas[$title]['title'] = $title; $this->areas[$title]['file_path'] = $this->folder.'/'.$title.'/page.php'; $this->areas[$title]['draft_path'] = $this->folder.'/'.$title.'/draft.php'; $this->areas[$title]['legacy_path'] = $this->folder.'/'.$title.'.php'; } /** * Return the area name if valid * */ public static function AreaExists($title){ global $dataDir; if( $title == '.' || $title == '..' ){ return false; } $legacy = $dataDir.'/data/_extra/'.$title; $new = $dataDir.'/data/_extra/'.$title.'/page.php'; $php = (substr($title,-4) === '.php'); if( !$php && is_dir($legacy) && \gp\tool\Files::Exists($new) ){ //is_dir() used to prevent open_basedir notice http://www.typesettercms.com/Forum?show=t2110 return $title; } if( $php && \gp\tool\Files::Exists($legacy) ){ return substr($title,0,-4); } return false; } /** * Delete an extra content area * */ public function DeleteArea(){ global $langmessage; if( $this->_DeleteArea() ){ unset($this->areas[$this->title]); }else{ message($langmessage['OOPS']); } } private function _DeleteArea(){ //legacy path if( \gp\tool\Files::Exists($this->area_info['legacy_path']) && !unlink($this->area_info['legacy_path']) ){ return false; } //remove directory $dir = dirname($this->area_info['draft_path']); if( file_exists($dir) && !\gp\tool\Files::RmAll($dir) ){ return false; } return true; } /** * Check to see if the extra area exists * */ public function ExtraExists($file){ global $dataDir; if( !isset($this->areas[$file]) ){ return; } return $this->areas[$file]; } /** * Show all available extra content areas * */ public function DefaultDisplay(){ global $langmessage; $types = \gp\tool\Output\Sections::GetTypes(); echo '
'; echo $langmessage['file_name']; echo ' | '; echo $langmessage['Content Type']; echo ' | '; echo $langmessage['options']; echo ' |
---|
'; echo '
'; echo ''; } public function EditExtra(){ global $langmessage, $page; echo '