function SetVars() { global $gp_index, $gp_titles, $gp_menu; if (!isset($gp_index[$this->title])) { $this->Error_404($this->title); return false; } $this->gp_index = $gp_index[$this->title]; $this->TitleInfo =& $gp_titles[$this->gp_index]; //so changes made by rename are seen $this->label = \gp\tool::GetLabel($this->title); $this->file = \gp\tool\Files::PageFile($this->title); if (!$this->CheckVisibility()) { return false; } \gp\tool\Plugins::Action('PageSetVars'); return true; }
/** * Check page files for orphaned data files * */ protected function CheckPageFiles() { global $dataDir, $gp_index; $pages_dir = $dataDir . '/data/_pages'; $all_files = \gp\tool\Files::ReadDir($pages_dir, 'php'); foreach ($all_files as $key => $file) { $all_files[$key] = $pages_dir . '/' . $file . '.php'; } $page_files = array(); foreach ($gp_index as $slug => $index) { $page_files[] = \gp\tool\Files::PageFile($slug); } $diff = array_diff($all_files, $page_files); if (!count($diff)) { return; } echo '<h2>Orphaned Data Files</h2>'; echo '<p>The following data files appear to be orphaned and are most likely no longer needed. Before completely removing these files, we recommend backing them up first.</p>'; echo '<table class="bordered"><tr><th>File</th></tr>'; foreach ($diff as $file) { echo '<tr><td>' . $file . '</td></tr>'; } echo '</table>'; }
/** * Include the content of a normal page * @param string $requested The name of the page to include * */ static function IncludePage($requested) { global $gp_index; $requested = str_replace(' ', '_', $requested); if (!isset($gp_index[$requested])) { return '{{' . htmlspecialchars($requested) . '}}'; } $file = \gp\tool\Files::PageFile($requested); $file_sections = \gp\tool\Files::Get($file, 'file_sections'); if (!$file_sections) { return '{{' . htmlspecialchars($requested) . '}}'; } return self::Render($file_sections, self::$title, self::$meta); }
/** * Restore $titles and return array with menu information * @param array $titles An array of titles to be restored. After completion, it will contain only the titles that were prepared successfully * @return array A list of restored titles that can be used for menu insertion * */ public static function RestoreTitles(&$titles) { global $dataDir, $gp_index, $gp_titles, $config; $new_menu = array(); $restored = array(); foreach ($titles as $trash_index) { //get trash info about file $title_info = self::GetInfo($trash_index); if ($title_info === false) { continue; } $new_title = \gp\admin\Tools::CheckPostedNewPage($title_info['title'], $message); if (!$new_title) { continue; } //make sure the page_file exists if (!\gp\tool\Files::Exists($title_info['page_file'])) { continue; } //add to $gp_index before PageFile() if (isset($title_info['index'])) { $index = $title_info['index']; $gp_index[$new_title] = $index; } else { $index = \gp\tool::NewFileIndex(); $gp_index[$new_title] = $index; } // move the trash file to the /_pages directory if needed $new_file = \gp\tool\Files::PageFile($new_title); if (!\gp\tool\Files::Exists($new_file)) { if (!\gp\tool\Files::Rename($title_info['page_file'], $new_file)) { unset($gp_index[$new_title]); continue; } } //add to $gp_titles $gp_titles[$index] = array(); $gp_titles[$index]['label'] = $title_info['label']; $gp_titles[$index]['type'] = $title_info['type']; $new_menu[$index] = array(); $restored[$trash_index] = $title_info; self::RestoreFile($new_title, $new_file, $title_info); } $titles = $restored; return $new_menu; }
/** * Perform a page copy * */ public function CopyPage() { global $gp_index, $gp_titles, $langmessage; $this->CacheSettings(); if (!isset($_POST['from_title'])) { msg($langmessage['OOPS'] . ' (Copy from not selected)'); if (isset($_POST['insert_how'])) { $this->InsertDialog($_POST['insert_how']); } else { $this->AddHidden(); } return false; } //existing page info $from_title = $_POST['from_title']; if (!isset($gp_index[$from_title])) { msg($langmessage['OOPS_TITLE']); return false; } $from_index = $gp_index[$from_title]; $info = $gp_titles[$from_index]; //check the new title $title = $_POST['title']; $title = \gp\admin\Tools::CheckPostedNewPage($title, $message); if ($title === false) { msg($message); return false; } //get the existing content $from_file = \gp\tool\Files::PageFile($from_title); $contents = file_get_contents($from_file); //add to $gp_index first! $index = \gp\tool::NewFileIndex(); $gp_index[$title] = $index; $file = \gp\tool\Files::PageFile($title); if (!\gp\tool\Files::Save($file, $contents)) { msg($langmessage['OOPS'] . ' (File not saved)'); return false; } //add to gp_titles $new_titles = array(); $new_titles[$index]['label'] = \gp\admin\Tools::PostedLabel($_POST['title']); $new_titles[$index]['type'] = $info['type']; $gp_titles += $new_titles; //add to menu $insert = array(); $insert[$index] = array(); if (!$this->SaveNew($insert)) { $this->RestoreSettings(); return false; } $this->HiddenSaved($index); return true; }
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; }
/** * Get the output formatting data for * */ public function GetReplaceData($title, $layout_info, $menu_key, $menu_value = array()) { global $langmessage, $gp_titles; $isSpecialLink = \gp\tool::SpecialOrAdmin($title); //get the data for this title $data = array('key' => $menu_key, 'url' => \gp\tool::GetUrl($title), 'title' => $title, 'special' => $isSpecialLink, 'has_layout' => !empty($gp_titles[$menu_key]['gpLayout']), 'layout_color' => $layout_info['color'], 'layout_label' => $layout_info['label'], 'types' => $gp_titles[$menu_key]['type'], 'opts' => '', 'size' => '', 'mtime' => ''); if (isset($menu_value['level'])) { $data['level'] = $menu_value['level']; } if ($isSpecialLink === false) { $file = \gp\tool\Files::PageFile($title); $stats = @stat($file); if ($stats) { $data['size'] = \gp\admin\Tools::FormatBytes($stats['size']); $data['time'] = \gp\tool::date($langmessage['strftime_datetime'], $stats['mtime']); } } ob_start(); \gp\tool\Plugins::Action('MenuPageOptions', array($title, $menu_key, $menu_value, $layout_info)); $menu_options = ob_get_clean(); if ($menu_options) { $data['opts'] = $menu_options; } return $data; }
public function SearchPage($title, $index) { global $gp_menu, $gp_titles; //search hidden? if (!$this->search_hidden && !isset($gp_menu[$index])) { return; } //private pages if (!\gp\tool::LoggedIn()) { if (isset($gp_titles[$index]['vis'])) { return; } } $full_path = \gp\tool\Files::PageFile($title); $file_sections = \gp\tool\Files::Get($full_path, 'file_sections'); if (!$file_sections) { return; } $content = \gp\tool\Output\Sections::Render($file_sections, $title, \gp\tool\Files::$last_stats); $label = \gp\tool::GetLabel($title); $this->FindString($content, $label, $title); }