Пример #1
0
 /**
  * SetVars
  *
  */
 public function SetVars()
 {
     global $dataDir, $config;
     if (!parent::SetVars()) {
         return false;
     }
     $this->permission_edit = \gp\admin\Tools::CanEdit($this->gp_index);
     $this->permission_menu = \gp\admin\Tools::HasPermission('Admin_Menu');
     $this->draft_file = dirname($this->file) . '/draft.php';
     //admin actions
     if ($this->permission_menu) {
         $this->cmds['RenameForm'] = '\\gp\\Page\\Rename::RenameForm';
         $this->cmds['RenameFile'] = '\\gp\\Page\\Rename::RenamePage';
         $this->cmds['ToggleVisibility'] = array('\\gp\\Page\\Visibility::TogglePage', 'DefaultDisplay');
     }
     if ($this->permission_edit) {
         /* gallery/image editing */
         $this->cmds['Gallery_Folder'] = 'GalleryImages';
         $this->cmds['Gallery_Images'] = 'GalleryImages';
         $this->cmds['Image_Editor'] = '\\gp\\tool\\Editing::ImageEditor';
         $this->cmds['New_Dir'] = '\\gp\\tool\\Editing::NewDirForm';
         $this->cmds['ManageSections'] = '';
         $this->cmds['SaveSections'] = '';
         $this->cmds['ViewRevision'] = '';
         $this->cmds['UseRevision'] = 'DefaultDisplay';
         $this->cmds['ViewHistory'] = '';
         $this->cmds['ViewCurrent'] = '';
         $this->cmds['DeleteRevision'] = 'ViewHistory';
         $this->cmds['PublishDraft'] = 'DefaultDisplay';
         /* inline editing */
         $this->cmds['Save'] = 'SectionEdit';
         $this->cmds['Save_Inline'] = 'SectionEdit';
         $this->cmds['Preview'] = 'SectionEdit';
         $this->cmds['Include_Dialog'] = 'SectionEdit';
         $this->cmds['InlineEdit'] = 'SectionEdit';
     }
     if (!\gp\tool\Files::Exists($this->draft_file)) {
         return true;
     }
     $this->draft_exists = true;
     return true;
 }
Пример #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);
             }
         }
     }
 }
Пример #3
0
 /**
  * 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;
     }
     $this->file = $this->ExtraExists($_REQUEST['file']);
     if (is_null($this->file)) {
         message($langmessage['OOPS'] . ' (Invalid File)');
         return;
     }
     $this->title = \gp\tool\Editing::CleanTitle($_REQUEST['file']);
     $this->draft_file = dirname($this->file) . '/draft.php';
     $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;
     }
 }
Пример #4
0
 /**
  * Stop loading
  * Check to see if the cms has already been installed
  *
  */
 public static function stop()
 {
     global $dataDir;
     if (!\gp\tool\Files::Exists($dataDir . '/data/_site/config.php')) {
         if (file_exists($dataDir . '/include/install/install.php')) {
             self::SetLinkPrefix();
             includeFile('install/install.php');
             die;
         }
     }
     die('<p>Notice: The site configuration did not load properly.</p>' . '<p>If you are the site administrator, you can troubleshoot the problem turning debugging "on" or bypass it by enabling ' . CMS_NAME . ' safe mode.</p>' . '<p>More information is available in the <a href="' . CMS_DOMAIN . '/Docs/Main/Troubleshooting">Documentation</a>.</p>' . self::ErrorBuffer(true, false));
 }
Пример #5
0
 /**
  * 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;
 }
Пример #6
0
 /**
  * Return the data for the requested menu, return the main menu if the requested menu doesn't exist
  * @param string $id String identifying the requested menu
  * @return array menu data
  */
 public function GetMenuArray($id)
 {
     global $dataDir, $gp_menu;
     $menu_file = $dataDir . '/data/_menus/' . $id . '.php';
     if (empty($id) || !\gp\tool\Files::Exists($menu_file)) {
         return \gp\tool\Plugins::Filter('GetMenuArray', array($gp_menu));
     }
     $menu = \gp\tool\Files::Get('_menus/' . $id, 'menu');
     if (\gp\tool\Files::$last_version && version_compare(\gp\tool\Files::$last_version, '3.0b1', '<')) {
         $menu = $this->FixMenu($menu);
     }
     return \gp\tool\Plugins::Filter('GetMenuArray', array($menu));
 }
Пример #7
0
 /**
  * Determine if $session_id represents a valid session and if so start the session
  *
  */
 public static function start($session_id, $sessions = false)
 {
     global $langmessage, $dataDir, $wbMessageBuffer;
     static $locked_message = false;
     //get the session file
     if (!$sessions) {
         $sessions = self::GetSessionIds();
         if (!isset($sessions[$session_id])) {
             self::cookie(gp_session_cookie);
             //make sure the cookie is deleted
             msg($langmessage['Session Expired'] . ' (timeout)');
             return false;
         }
     }
     $sess_info = $sessions[$session_id];
     //check ~ip, ~user agent ...
     if (gp_browser_auth && !empty($sess_info['uid'])) {
         $auth_uid = self::auth_browseruid();
         $auth_uid_legacy = self::auth_browseruid(true);
         //legacy option added to prevent logging users out, added 2.0b2
         if ($sess_info['uid'] != $auth_uid && $sess_info['uid'] != $auth_uid_legacy) {
             self::cookie(gp_session_cookie);
             //make sure the cookie is deleted
             msg($langmessage['Session Expired'] . ' (browser auth)');
             return false;
         }
     }
     $session_file = $dataDir . '/data/_sessions/' . $sess_info['file_name'];
     if ($session_file === false || !\gp\tool\Files::Exists($session_file)) {
         self::cookie(gp_session_cookie);
         //make sure the cookie is deleted
         msg($langmessage['Session Expired'] . ' (invalid)');
         return false;
     }
     //prevent browser caching when editing
     Header('Last-Modified: ' . gmdate('D, j M Y H:i:s') . ' GMT');
     Header('Expires: ' . gmdate('D, j M Y H:i:s', time()) . ' GMT');
     Header('Cache-Control: no-store, no-cache, must-revalidate');
     // HTTP/1.1
     Header('Cache-Control: post-check=0, pre-check=0', false);
     Header('Pragma: no-cache');
     // HTTP/1.0
     $GLOBALS['gpAdmin'] = self::SessionData($session_file, $checksum);
     //lock to prevent conflicting edits
     if (gp_lock_time > 0 && (!empty($GLOBALS['gpAdmin']['editing']) || !empty($GLOBALS['gpAdmin']['granted']))) {
         $expires = gp_lock_time;
         if (!\gp\tool\Files::Lock('admin', sha1(sha1($session_id)), $expires)) {
             msg($langmessage['site_locked'] . ' ' . sprintf($langmessage['lock_expires_in'], ceil($expires / 60)));
             $locked_message = true;
             $GLOBALS['gpAdmin']['locked'] = true;
         } else {
             unset($GLOBALS['gpAdmin']['locked']);
         }
     }
     //extend cookie?
     if (isset($GLOBALS['gpAdmin']['remember'])) {
         $elapsed = time() - $GLOBALS['gpAdmin']['remember'];
         if ($elapsed > 604800) {
             //7 days
             $GLOBALS['gpAdmin']['remember'] = time();
             self::cookie(gp_session_cookie, $session_id);
         }
     }
     register_shutdown_function(array('\\gp\\tool\\Session', 'close'), $session_file, $checksum);
     self::SaveSetting();
     //make sure forms have admin nonce
     ob_start(array('\\gp\\tool\\Session', 'AdminBuffer'));
     \gp\tool\Output::$lang_values += array('cancel' => 'ca', 'update' => 'up', 'caption' => 'cp', 'Width' => 'Width', 'Height' => 'Height', 'save' => 'Save', 'Saved' => 'Saved', 'Saving' => 'Saving', 'Close' => 'Close', 'Page' => 'Page', 'theme_content' => 'Extra', 'Publish Draft' => 'Draft', 'Publish' => 'Publish');
     \gp\tool::LoadComponents('sortable,autocomplete,gp-admin,gp-admin-css');
     \gp\admin\Tools::VersionsAndCheckTime();
     \gp\tool\Output::$inline_vars += array('gpRem' => \gp\admin\Tools::CanRemoteInstall());
     //prepend messages from message buffer
     if (isset($GLOBALS['gpAdmin']['message_buffer']) && count($GLOBALS['gpAdmin']['message_buffer'])) {
         $wbMessageBuffer = array_merge($GLOBALS['gpAdmin']['message_buffer'], $wbMessageBuffer);
         unset($GLOBALS['gpAdmin']['message_buffer']);
     }
     //alias
     if (isset($_COOKIE['gp_alias'])) {
         $GLOBALS['gpAdmin']['useralias'] = $_COOKIE['gp_alias'];
     } else {
         $GLOBALS['gpAdmin']['useralias'] = $GLOBALS['gpAdmin']['username'];
     }
     return true;
 }
Пример #8
0
 /**
  * Get and return the extra content specified by $title
  *
  */
 public static function ExtraContent($title, &$file_stats = array(), &$is_draft = false)
 {
     //draft?
     $draft_file = '_extra/' . $title . '/draft';
     if (\gp\tool::LoggedIn() && \gp\tool\Files::Exists($draft_file)) {
         $is_draft = true;
         return \gp\tool\Files::Get($draft_file, 'file_sections');
     }
     //new location
     $file = '_extra/' . $title . '/page';
     if (\gp\tool\Files::Exists($file)) {
         return \gp\tool\Files::Get($file, 'file_sections');
     }
     $file = '_extra/' . $title;
     $extra_section = array();
     if (\gp\tool\Files::Exists($file)) {
         ob_start();
         $extra_section = \gp\tool\Files::Get($file, 'extra_content');
         $extra_section_string = ob_get_clean();
         if (!count($extra_section)) {
             $extra_section['content'] = $extra_section_string;
         }
     }
     $extra_section += array('type' => 'text', 'content' => '');
     return array($extra_section);
 }
Пример #9
0
 /**
  * Remove an alternate menu from the configuration and delete the data file
  *
  */
 public function MenuRemove()
 {
     global $langmessage, $config, $dataDir;
     $menu_id =& $_POST['id'];
     if (!\gp\admin\Menu\Tools::IsAltMenu($menu_id)) {
         msg($langmessage['OOPS']);
         return;
     }
     $menu_file = $dataDir . '/data/_menus/' . $menu_id . '.php';
     unset($config['menus'][$menu_id]);
     unset($this->avail_menus[$menu_id]);
     \gp\admin\Tools::SaveConfig(true, true);
     //delete menu file
     $menu_file = $dataDir . '/data/_menus/' . $menu_id . '.php';
     if (\gp\tool\Files::Exists($menu_file)) {
         unlink($menu_file);
     }
 }
Пример #10
0
 /**
  * Return the name of the cleansed extra area name, create file if it doesn't already exist
  *
  */
 public function NewExtraArea()
 {
     global $langmessage, $dataDir;
     $title = \gp\tool\Editing::CleanTitle($_REQUEST['extra_area']);
     if (empty($title)) {
         message($langmessage['OOPS']);
         return false;
     }
     $data = \gp\tool\Editing::DefaultContent($_POST['type']);
     $file = $dataDir . '/data/_extra/' . $title . '.php';
     if (\gp\tool\Files::Exists($file)) {
         return $title;
     }
     if (!\gp\tool\Files::SaveData($file, 'extra_content', $data)) {
         message($langmessage['OOPS']);
         return false;
     }
     return $title;
 }