Beispiel #1
0
 /**
  * Return a sorted array of files in the trash
  *
  */
 public static function TrashFiles()
 {
     global $dataDir, $gp_index, $config;
     $trash_titles = array();
     // pre 4.6, deleted page info was stored
     $trash_file = $dataDir . '/data/_site/trash.php';
     if (\gp\tool\Files::Exists($trash_file)) {
         $trash_titles = \gp\tool\Files::Get($trash_file, 'trash_titles');
     }
     // get files associated existing titles
     $pages_dir = $dataDir . '/data/_pages/';
     $pages_dir_len = strlen($pages_dir);
     $existing = array();
     foreach ($gp_index as $title => $index) {
         if (\gp\tool::SpecialOrAdmin($title) !== false) {
             continue;
         }
         $file = \gp\tool\Files::PageFile($title);
         $file = substr($file, $pages_dir_len);
         if (strpos($file, '/')) {
             $existing[] = dirname($file);
         } else {
             $existing[] = $file;
         }
     }
     // post 4.6, deleted pages are left in the data/_pages folder
     $files = scandir($pages_dir);
     $files = array_diff($files, array('.', '..', 'index.html'));
     // add the new files to the list of $trash_titles
     $new_trash_files = array_diff($files, $existing);
     $page_prefix = substr($config['gpuniq'], 0, 7) . '_';
     foreach ($new_trash_files as $file) {
         $info = array();
         $info_file = $dataDir . '/data/_pages/' . $file . '/deleted.php';
         if (\gp\tool\Files::Exists($info_file)) {
             $info = \gp\tool\Files::Get($info_file, 'deleted');
             $info['page_file'] = $dataDir . '/data/_pages/' . $file . '/page.php';
         } else {
             $info['page_file'] = $dataDir . '/data/_pages/' . $file;
             $info['time'] = filemtime($info['page_file']);
             $info['orphaned'] = true;
         }
         //get index
         if (strpos($file, $page_prefix) === 0) {
             $info['index'] = substr($file, 8);
             // remove page_prefix
         }
         $info['rm_path'] = $dataDir . '/data/_pages/' . $file;
         $trash_titles[$file] = $info;
     }
     //make sure we have a title
     foreach ($trash_titles as $trash_index => &$info) {
         if (!isset($info['title'])) {
             $info['title'] = str_replace('_', ' ', $trash_index);
         }
     }
     uasort($trash_titles, array('self', 'TitleSort'));
     return $trash_titles;
 }
Beispiel #2
0
 /**
  * Update the gp_index, gp_titles and menus so that special pages can be renamed
  *
  */
 function Upgrade_234()
 {
     global $gp_index, $gp_titles, $gp_menu, $config, $dataDir;
     $special_indexes = array();
     $new_index = array();
     $new_titles = array();
     foreach ($gp_index as $title => $index) {
         $info = $gp_titles[$index];
         $type = \gp\tool::SpecialOrAdmin($title);
         if ($type === 'special') {
             $special_indexes[$index] = strtolower($title);
             $index = strtolower($title);
             $info['type'] = 'special';
             //some older versions didn't maintain this value well
         }
         $new_index[$title] = $index;
         $new_titles[$index] = $info;
     }
     $gp_titles = $new_titles;
     $gp_index = $new_index;
     //update gp_menu
     $gp_menu = $this->FixMenu($gp_menu, $special_indexes);
     //save pages
     if (!\gp\admin\Tools::SavePagesPHP()) {
         return;
     }
     $config['gpversion'] = '2.3.4';
     \gp\admin\Tools::SaveConfig();
     //update alt menus
     if (isset($config['menus']) && is_array($config['menus'])) {
         foreach ($config['menus'] as $key => $value) {
             $menu_file = $dataDir . '/data/_menus/' . $key . '.php';
             if (\gp\tool\Files::Exists($menu_file)) {
                 $menu = \gp\tool\Output::GetMenuArray($key);
                 $menu = $this->FixMenu($menu, $special_indexes);
                 \gp\tool\Files::SaveData($menu_file, 'menu', $menu);
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Include the content of a page or gadget as specified in $data
  * @param array $data
  * @param string The included content
  */
 static function IncludeContent($data)
 {
     global $langmessage, $gp_index;
     if (isset($data['index'])) {
         $requested = \gp\tool::IndexToTitle($data['index']);
     } else {
         $requested = $data['content'];
     }
     if (empty($requested)) {
         return '<p>' . $langmessage['File Include'] . '</p>';
     }
     if (self::$title == $requested) {
         if (\gp\tool::LoggedIn()) {
             msg('Infinite loop detected: ' . htmlspecialchars($requested));
         }
         return;
     }
     if (isset($data['include_type'])) {
         $type = $data['include_type'];
     } else {
         $type = \gp\tool::SpecialOrAdmin($requested);
     }
     switch ($type) {
         case 'gadget':
             return self::IncludeGadget($requested);
         case 'special':
             return self::IncludeSpecial($requested);
         default:
             return self::IncludePage($requested);
     }
 }
Beispiel #4
0
<?php

define('gp_start_time', microtime(true));
defined('is_running') or define('is_running', true);
require_once 'common.php';
\gp\tool::EntryPoint(0);
/*
 *	Flow Control
 */
if (!empty($GLOBALS['config']['updating_message'])) {
    die($GLOBALS['config']['updating_message']);
}
$title = \gp\tool::WhichPage();
$type = \gp\tool::SpecialOrAdmin($title);
switch ($type) {
    case 'special':
        $page = new \gp\special\Page($title, $type);
        break;
    case 'admin':
        if (\gp\tool::LoggedIn()) {
            $page = new \gp\admin\Page($title, $type);
        } else {
            $page = new \gp\admin\Login($title, $type);
        }
        break;
    default:
        if (\gp\tool::LoggedIn()) {
            $page = new \gp\Page\Edit($title, $type);
        } else {
            $page = new \gp\Page($title, $type);
        }
Beispiel #5
0
 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;
 }
Beispiel #6
0
 /**
  * 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;
 }
Beispiel #7
0
 /**
  * Save an include section
  *
  */
 public static function SectionFromPost_Include(&$existing_section, $section_num, $title, $file_stats)
 {
     global $page, $langmessage, $gp_index, $config;
     unset($existing_section['index']);
     //gadget include
     if (strpos($_POST['include'], 'gadget:') === 0) {
         $gadget = substr($_POST['include'], 7);
         if (!isset($config['gadgets'][$gadget])) {
             msg($langmessage['OOPS_TITLE']);
             return false;
         }
         $existing_section['include_type'] = 'gadget';
         $existing_section['content'] = $gadget;
         //file include
     } elseif (strpos($_POST['include'], 'file:') === 0) {
         $include_title = substr($_POST['include'], 5);
         if (!isset($gp_index[$include_title])) {
             msg($langmessage['OOPS_TITLE']);
             return false;
         }
         $existing_section['include_type'] = \gp\tool::SpecialOrAdmin($include_title);
         $existing_section['index'] = $gp_index[$include_title];
         $existing_section['content'] = $include_title;
     }
     //send replacement content
     $content = \gp\tool\Output\Sections::RenderSection($existing_section, $section_num, $title, $file_stats);
     $page->ajaxReplace[] = array('gp_include_content', '', $content);
     return true;
 }
Beispiel #8
0
 public function Get404()
 {
     global $langmessage, $page;
     \gp\tool\Output::AddHeader('Not Found', true, 404);
     $page->head .= '<meta name="robots" content="noindex,nofollow" />';
     //this isn't getting to the template because $page isn't available yet
     //message for admins
     if (\gp\tool::LoggedIn()) {
         if ($this->requested && \gp\tool::SpecialOrAdmin($this->requested) === false) {
             $with_spaces = htmlspecialchars($this->requested);
             $link = \gp\tool::GetUrl('Admin/Menu/Ajax', 'cmd=AddHidden&redir=redir&title=' . rawurlencode($this->requested)) . '" title="' . $langmessage['create_new_file'] . '" data-cmd="gpabox';
             $message = sprintf($langmessage['DOESNT_EXIST'], $with_spaces, $link);
             msg($message);
         }
     }
     //Contents of 404 page
     $wrap = \gp\tool\Output::ShowEditLink('Admin/Missing');
     if ($wrap) {
         echo \gp\tool\Output::EditAreaLink($edit_index, 'Admin/Missing', $langmessage['edit'], 'cmd=edit404', ' title="' . $langmessage['404_Page'] . '" ');
         echo '<div class="editable_area" id="ExtraEditArea' . $edit_index . '">';
         // class="edit_area" added by javascript
     }
     echo self::Get404Output();
     if ($wrap) {
         echo '</div>';
     }
 }
Beispiel #9
0
 public function SearchPages()
 {
     global $gp_index;
     ob_start();
     foreach ($gp_index as $title => $index) {
         if (\gp\tool::SpecialOrAdmin($title) === false) {
             $this->SearchPage($title, $index);
         }
     }
     ob_get_clean();
 }
Beispiel #10
0
 /**
  * Check a title against existing titles, special pages and reserved unique string
  *
  * @param string $title The title to be checked
  * @return mixed false if the title doesn't exist, string if a conflict is found
  * @since 2.4b5
  */
 public static function CheckTitle($title, &$message)
 {
     global $gp_index, $config, $langmessage;
     if (empty($title)) {
         $message = $langmessage['TITLE_REQUIRED'];
         return false;
     }
     if (isset($gp_index[$title])) {
         $message = $langmessage['TITLE_EXISTS'];
         return false;
     }
     $type = \gp\tool::SpecialOrAdmin($title);
     if ($type !== false) {
         $message = $langmessage['TITLE_RESERVED'];
         return false;
     }
     $prefix = substr($config['gpuniq'], 0, 7) . '_';
     if (strpos($title, $prefix) !== false) {
         $message = $langmessage['TITLE_RESERVED'] . ' (2)';
         return false;
     }
     if (strlen($title) > 100) {
         $message = $langmessage['LONG_TITLE'];
         return false;
     }
     return true;
 }