/** * Get the current classes * */ static function GetClasses() { $classes = \gp\tool\Files::Get('_config/classes'); if ($classes) { return $classes; } //defaults return self::Defaults(); }
/** * Get addon history and review data * */ public function GetAddonData() { global $dataDir; $this->dataFile = $dataDir . '/data/_site/addonData.php'; $addonData = \gp\tool\Files::Get('_site/addonData'); if ($addonData) { $this->addonHistory = $addonData['history']; $this->addonReviews = $addonData['reviews']; } }
/** * Get Gallery Index * * @static */ public static function GetData() { $galleries = \gp\tool\Files::Get('_site/galleries'); if (!$galleries) { return array(); } if (version_compare(\gp\tool\Files::$last_version, '2.2', '<=')) { self::UpdateData($galleries); } return $galleries; }
/** * Connect to ftp server using either Post or saved values * Connection values will not be kept in $config in case they're being used for a system revert which will replace the config.php file * Also handle moving ftp connection values from $config to a sep * * @return bool */ public function connect() { global $config, $dataDir, $langmessage; $save_values = false; $connect_args = \gp\tool\Files::Get('_updates/connect', 'connect_args'); if (!$connect_args || !isset($connect_args['ftp_user'])) { if (isset($config['ftp_user'])) { $connect_args['ftp_user'] = $config['ftp_user']; $connect_args['ftp_server'] = $config['ftp_server']; $connect_args['ftp_pass'] = $config['ftp_pass']; $connect_args['ftp_root'] = $config['ftp_root']; $save_values = true; } } if (isset($_POST['ftp_pass'])) { $connect_args = $_POST; $save_values = true; } $connect_args = $this->get_connect_vars($connect_args); $connected = $this->connect_handler($connect_args); if (!is_null($connected)) { return false; } //get the ftp_root if (empty($connect_args['ftp_root']) || $save_values) { $this->ftp_root = $this->get_base_dir(); if (!$this->ftp_root) { return $langmessage['couldnt_connect'] . ' (Couldn\'t find root)'; } $connect_args['ftp_root'] = $this->ftp_root; $save_values = true; } else { $this->ftp_root = $connect_args['ftp_root']; } //save ftp info if (!$save_values) { return true; } $connection_file = $dataDir . '/data/_updates/connect.php'; if (!\gp\tool\Files::SaveData($connection_file, 'connect_args', $connect_args)) { return true; } /* * Remove from $config if it's not a safe mode installation */ if (!isset($config['useftp']) && isset($config['ftp_user'])) { unset($config['ftp_user']); unset($config['ftp_server']); unset($config['ftp_pass']); unset($config['ftp_root']); \gp\admin\Tools::SaveConfig(); } return true; }
/** * Get or cache data about available versions of cms and addons * */ public static function VersionData(&$update_data) { global $dataDir; $file = $dataDir . '/data/_updates/updates.php'; //set if (!is_null($update_data)) { return \gp\tool\Files::SaveData($file, 'update_data', $update_data); } $update_data = \gp\tool\Files::Get('_updates/updates', 'update_data'); $update_data += array('packages' => array()); return \gp\tool\Files::$last_modified; }
/** * Add instructions for a 301 or 302 redirect * */ 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); } }
/** * View the current public facing version of the file * */ public function ViewCurrent() { if (!$this->draft_exists) { $this->DefaultDisplay(); return; } $file_sections = \gp\tool\Files::Get($this->file, 'file_sections'); $this->revision = $this->fileModTime; echo \gp\tool\Output\Sections::Render($file_sections, $this->title, $this->file_stats); }
/** * Get usage information about a image * */ static function GetUsage($index) { return \gp\tool\Files::Get('_resized/' . $index . '/data', 'usage'); }
/** * Get current configuration settings * */ function Init() { $this->config_file = '_ckeditor/config'; $this->cke_config = \gp\tool\Files::Get($this->config_file, 'cke_config'); //$this->cke_config += array('custom_config'=>array()); $this->cke_config += array('plugins' => array()); $this->BuildConfig(); }
public function GetUsers() { $this->users = \gp\tool\Files::Get('_site/users'); //fix the editing value foreach ($this->users as $username => $userinfo) { $userinfo += array('granted' => ''); \gp\admin\Tools::EditingValue($userinfo); $this->users[$username] = $userinfo; } }
public function Init() { $this->datafile = '_site/error_data'; $this->error_data = \gp\tool\Files::Get($this->datafile, 'error_data'); }
/** * 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); }
/** * Perform regular tasks * Once an hour only when admin is logged in * */ public static function Cron() { $cron_info = \gp\tool\Files::Get('_site/cron_info'); $file_stats = \gp\tool\Files::$last_stats; $file_stats += array('modified' => 0); if (time() - $file_stats['modified'] < 3600) { return; } self::CleanTemp(); \gp\tool\Files::SaveData('_site/cron_info', 'cron_info', $cron_info); }
/** * 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); }
/** * Make sure the current user stays logged in after a revert is completed * */ public function TransferSession() { global $gpAdmin; $username = $gpAdmin['username']; // get user info $users = \gp\tool\Files::Get('_site/users'); $userinfo =& $users[$username]; $session_id = \gp\tool\Session::create($userinfo, $username, $sessions); if (!$session_id) { return; } //set the cookie for the new data $config = \gp\tool\Files::Get('_site/config'); $session_cookie = 'gpEasy_' . substr(sha1($config['gpuniq']), 12, 12); \gp\tool\Session::cookie($session_cookie, $session_id); //set the update gpuniq value for the post_nonce $GLOBALS['config']['gpuniq'] = $config['gpuniq']; }
/** * Create a new page from a user post * */ public static function CreateNew() { global $gp_index, $gp_titles, $langmessage, $gpAdmin; //check title $title = $_POST['title']; $title = \gp\admin\Tools::CheckPostedNewPage($title, $message); if ($title === false) { msg($message); return false; } //multiple section types $type = $_POST['content_type']; if (strpos($type, '{') === 0) { $types = json_decode($type, true); if ($types) { $types += array('wrapper_class' => 'gpRow'); $content = array(); //wrapper section $section = \gp\tool\Editing::DefaultContent('wrapper_section'); $section['contains_sections'] = count($types['types']); $section['attributes']['class'] = $types['wrapper_class']; $content[] = $section; //nested sections foreach ($types['types'] as $type) { if (strpos($type, '.')) { list($type, $class) = explode('.', $type, 2); } else { $class = ''; } $section = \gp\tool\Editing::DefaultContent($type); $section['attributes']['class'] .= ' ' . $class; $content[] = $section; } } //single section type } else { $content = \gp\tool\Editing::DefaultContent($type, $_POST['title']); if ($content['content'] === false) { return false; } } //add to $gp_index first! $index = \gp\tool::NewFileIndex(); $gp_index[$title] = $index; if (!\gp\tool\Files::NewTitle($title, $content, $type)) { msg($langmessage['OOPS'] . ' (cn1)'); unset($gp_index[$title]); return false; } //add to gp_titles $new_titles = array(); $new_titles[$index]['label'] = \gp\admin\Tools::PostedLabel($_POST['title']); $new_titles[$index]['type'] = $type; $gp_titles += $new_titles; //add to users editing if ($gpAdmin['editing'] != 'all') { $gpAdmin['editing'] = rtrim($gpAdmin['editing'], ',') . ',' . $index . ','; $users = \gp\tool\Files::Get('_site/users'); $users[$gpAdmin['username']]['editing'] = $gpAdmin['editing']; \gp\tool\Files::SaveData('_site/users', 'users', $users); } return $index; }
/** * 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)); }
/** * Retreive the data file for the current title and update the data if necessary * */ function GetFile() { $this->file_sections = \gp\tool\Files::Get($this->file, 'file_sections'); $this->meta_data = \gp\tool\Files::$last_meta; $this->fileModTime = \gp\tool\Files::$last_modified; $this->file_stats = \gp\tool\Files::$last_stats; if (count($this->file_sections) == 0) { $this->file_sections[0] = array('type' => 'text', 'content' => '<p>Oops, this page no longer has any content.</p>'); } }
/** * View the contents of a trash file * */ public function ViewTrashFile($trash_index) { global $dataDir, $langmessage, $trash_file; $title_info = self::GetInfo($trash_index); //delete / restore links echo '<div class="pull-right">'; echo \gp\tool::Link('Admin/Trash', $langmessage['restore'], 'cmd=RestoreDeleted&titles[]=' . rawurlencode($trash_index), array('data-cmd' => 'cnreq', 'class' => 'gpsubmit')); echo ' '; echo \gp\tool::Link('Admin/Trash', $langmessage['delete'], 'cmd=DeleteFromTrash&titles[]=' . rawurlencode($trash_index), array('data-cmd' => 'cnreq', 'class' => 'gpsubmit')); echo '</div>'; echo '<h2 class="hmargin">'; echo \gp\tool::Link('Admin/Trash', $langmessage['trash']); echo ' » '; echo htmlspecialchars($title_info['title']); echo '</h2>'; echo '<hr>'; //get file sections $file_sections = \gp\tool\Files::Get($title_info['page_file'], 'file_sections'); if ($file_sections) { echo \gp\tool\Output\Sections::Render($file_sections, $title_info['title']); } else { echo '<p>This page no longer has any content</p>'; } }
public function SendPassword() { global $langmessage, $config; $users = \gp\tool\Files::Get('_site/users'); $username = $_POST['username']; if (!isset($users[$username])) { message($langmessage['OOPS']); return false; } $userinfo = $users[$username]; if (empty($userinfo['email'])) { message($langmessage['no_email_provided']); return false; } $passwordChars = str_repeat('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 3); $newpass = str_shuffle($passwordChars); $newpass = substr($newpass, 0, 8); $pass_hash = \gp\tool\Session::PassAlgo($userinfo); $users[$username]['newpass'] = \gp\tool::hash($newpass, $pass_hash); if (!\gp\tool\Files::SaveData('_site/users', 'users', $users)) { message($langmessage['OOPS']); return false; } if (isset($_SERVER['HTTP_HOST'])) { $server = $_SERVER['HTTP_HOST']; } else { $server = $_SERVER['SERVER_NAME']; } $link = \gp\tool::AbsoluteLink('Admin', $langmessage['login']); $message = sprintf($langmessage['passwordremindertext'], $server, $link, $username, $newpass); //send email $mailer = new \gp\tool\Emailer(); if ($mailer->SendEmail($userinfo['email'], $langmessage['new_password'], $message)) { list($namepart, $sitepart) = explode('@', $userinfo['email']); $showemail = substr($namepart, 0, 3) . '...@' . $sitepart; message(sprintf($langmessage['password_sent'], $username, $showemail)); return true; } message($langmessage['OOPS'] . ' (Email not sent)'); return false; }
public static function CKAdminConfig() { static $cke_config; //get ckeditor configuration set by users if (!is_array($cke_config)) { $cke_config = \gp\tool\Files::Get('_ckeditor/config', 'cke_config'); if (!$cke_config) { $cke_config = array(); } $cke_config += array('plugins' => array(), 'custom_config' => array()); } return $cke_config; }
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); }
/** * Set global variables ( $gp_index, $gp_titles, $gp_menu and $gpLayouts ) from _site/pages.php * */ public static function GetPagesPHP() { global $gp_index, $gp_titles, $gp_menu, $gpLayouts, $config; $gp_index = array(); $pages = \gp\tool\Files::Get('_site/pages'); //update for < 2.0a3 if (array_key_exists('gpmenu', $pages) && array_key_exists('gptitles', $pages) && !array_key_exists('gp_titles', $pages) && !array_key_exists('gp_menu', $pages)) { foreach ($pages['gptitles'] as $title => $info) { $index = self::NewFileIndex(); $gp_index[$title] = $index; $gp_titles[$index] = $info; } foreach ($pages['gpmenu'] as $title => $level) { $index = $gp_index[$title]; $gp_menu[$index] = array('level' => $level); } return; } $gpLayouts = $pages['gpLayouts']; $gp_index = $pages['gp_index']; $gp_titles = $pages['gp_titles']; $gp_menu = $pages['gp_menu']; if (!is_array($gp_menu)) { self::stop(); } //update for 3.5, if (!isset($gp_titles['special_gpsearch'])) { $gp_titles['special_gpsearch'] = array(); $gp_titles['special_gpsearch']['label'] = 'Search'; $gp_titles['special_gpsearch']['type'] = 'special'; $gp_index['Search'] = 'special_gpsearch'; //may overwrite special_search settings } //fix the gpmenu if (version_compare(\gp\tool\Files::$last_version, '3.0b1', '<')) { $gp_menu = \gp\tool\Output::FixMenu($gp_menu); // fix gp_titles for 3.0+ // just make sure any ampersands in the label are escaped foreach ($gp_titles as $key => $value) { if (isset($gp_titles[$key]['label'])) { $gp_titles[$key]['label'] = self::GetLabelIndex($key, true); } } } //title related configuration settings if (empty($config['homepath_key'])) { $config['homepath_key'] = key($gp_menu); } $config['homepath'] = self::IndexToTitle($config['homepath_key']); }
/** * Get plugin configuration values * @since 3.6 * */ public static function GetConfig() { $file = self::$current['data_folder_full'] . '/_config.php'; return \gp\tool\Files::Get($file, 'config'); }