/** * Get the current classes * */ static function GetClasses() { $classes = gpFiles::Get('_config/classes'); if ($classes) { return $classes; } //defaults return self::Defaults(); }
public function SessionStart() { common::GetConfig(); $username = '******'; $users = gpFiles::Get('_site/users'); $userinfo = $users[$username]; $session_id = gpsession::create($userinfo, $username, $sessions); $logged_in = gpsession::start($session_id, $sessions); self::AssertTrue($logged_in, 'Not Logged In'); }
/** * Get addon history and review data * */ function GetAddonData() { global $dataDir; $this->dataFile = $dataDir . '/data/_site/addonData.php'; $addonData = gpFiles::Get('_site/addonData'); if ($addonData) { $this->addonHistory = $addonData['history']; $this->addonReviews = $addonData['reviews']; } }
/** * 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 true if connected, error message otherwise */ public function connect() { global $config, $dataDir, $langmessage; $save_values = false; $connect_args = \gpFiles::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 ($connected !== true) { return $connected; } //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 $connected; } $connection_file = $dataDir . '/data/_updates/connect.php'; if (!\gpFiles::SaveData($connection_file, 'connect_args', $connect_args)) { return $connected; } /* * 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']); \admin_tools::SaveConfig(); } return $connected; }
/** * Get Gallery Index * * @static */ static function GetData() { $galleries = gpFiles::Get('_site/galleries'); if (!$galleries) { return array(); } if (version_compare(gpFiles::$last_version, '2.2', '<=')) { special_galleries::UpdateData($galleries); } return $galleries; }
/** * Get or cache data about available versions of gpEasy and addons * */ static function VersionData(&$update_data) { global $dataDir; $file = $dataDir . '/data/_updates/updates.php'; //set if (!is_null($update_data)) { return gpFiles::SaveData($file, 'update_data', $update_data); } $update_data = gpFiles::Get('_updates/updates', 'update_data'); $update_data += array('packages' => array()); return gpFiles::$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 = gpFiles::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) { gpFiles::SaveData($datafile, 'error_data', $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 = gpFiles::PageFile($requested); $file_sections = gpFiles::Get($file, 'file_sections'); if (!$file_sections) { return '{{' . htmlspecialchars($requested) . '}}'; } return self::Render($file_sections, self::$title, self::$meta); }
/** * Get usage information about a image * */ static function GetUsage($index) { return gpFiles::Get('_resized/' . $index . '/data', 'usage'); }
/** * Perform regular tasks * Once an hour only when admin is logged in * */ static function Cron() { $cron_info = gpFiles::Get('_site/cron_info'); $file_stats = gpFiles::$last_stats; $file_stats += array('modified' => 0); if (time() - $file_stats['modified'] < 3600) { return; } self::CleanTemp(); gpFiles::SaveData('_site/cron_info', 'cron_info', $cron_info); }
/** * View the contents of a trash file * */ function ViewTrashFile($trash_index) { global $dataDir, $langmessage, $trash_file; $title_info = admin_trash::GetInfo($trash_index); //delete / restore links echo '<div class="pull-right">'; echo common::Link('Admin_Trash', $langmessage['restore'], 'cmd=RestoreDeleted&titles[]=' . rawurlencode($trash_index), array('data-cmd' => 'cnreq', 'class' => 'gpsubmit')); echo ' '; echo common::Link('Admin_Trash', $langmessage['delete'], 'cmd=DeleteFromTrash&titles[]=' . rawurlencode($trash_index), array('data-cmd' => 'cnreq', 'class' => 'gpsubmit')); echo '</div>'; echo '<h2 class="hmargin">'; echo common::Link('Admin_Trash', $langmessage['trash']); echo ' » '; echo htmlspecialchars($title_info['title']); echo '</h2>'; echo '<hr>'; //get file sections $file_sections = gpFiles::Get($title_info['page_file'], 'file_sections'); if ($file_sections) { echo section_content::Render($file_sections, $title_info['title']); } else { echo '<p>This page no longer has any content</p>'; } }
/** * Get and return the extra content specified by $title * */ static function ExtraContent($title, &$file_stats = array()) { $file = '_extra/' . $title; $extra_content = array(); if (gpFiles::Exists($file)) { ob_start(); $extra_content = gpFiles::Get($file, 'extra_content'); $extra_content_string = ob_get_clean(); if (!count($extra_content)) { $extra_content['content'] = $extra_content_string; } } return $extra_content + array('type' => 'text', 'content' => ''); }
/** * Make sure the current user stays logged in after a revert is completed * */ function TransferSession() { global $gpAdmin, $dataDir; $username = $gpAdmin['username']; // get user info include $dataDir . '/data/_site/users.php'; $userinfo =& $users[$username]; $session_id = gpsession::create($userinfo, $username); if (!$session_id) { return; } //set the cookie for the new data $config = gpFiles::Get('_site/config'); $session_cookie = 'gpEasy_' . substr(sha1($config['gpuniq']), 12, 12); gpsession::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 * */ function CreateNew() { global $gp_index, $gp_titles, $langmessage, $gpAdmin; includeFile('tool/editing_page.php'); includeFile('tool/editing.php'); $title = $_POST['title']; $title = admin_tools::CheckPostedNewPage($title, $message); if ($title === false) { message($message); return false; } $type = $_POST['content_type']; $section = gp_edit::DefaultContent($type); if ($section['content'] === false) { return false; } $label = admin_tools::PostedLabel($_POST['title']); if ($type == 'text') { $section['content'] = '<h2>' . strip_tags($_POST['title']) . '</h2>' . $section['content']; } //add to $gp_index first! $index = common::NewFileIndex(); $gp_index[$title] = $index; if (!gpFiles::NewTitle($title, $section, $type)) { message($langmessage['OOPS'] . ' (cn1)'); unset($gp_index[$title]); return false; } //add to gp_titles $new_titles = array(); $new_titles[$index]['label'] = $label; $new_titles[$index]['type'] = $type; $gp_titles += $new_titles; //add to users editing if ($gpAdmin['editing'] != 'all') { $gpAdmin['editing'] = rtrim($gpAdmin['editing'], ',') . ',' . $index . ','; $users = gpFiles::Get('_site/users'); $users[$gpAdmin['username']]['editing'] = $gpAdmin['editing']; gpFiles::SaveData('_site/users', 'users', $users); } return $index; }
function Init() { $this->datafile = '_site/error_data'; $this->error_data = gpFiles::Get($this->datafile, 'error_data'); }
/** * View the current public facing version of the file * */ public function ViewCurrent() { $file_sections = gpFiles::Get($this->file, 'file_sections'); $this->contentBuffer = section_content::Render($file_sections, $this->title, $this->file_stats); }
/** * Set global variables ( $gp_index, $gp_titles, $gp_menu and $gpLayouts ) from _site/pages.php * */ static function GetPagesPHP() { global $gp_index, $gp_titles, $gp_menu, $gpLayouts, $config; $gp_index = array(); $pages = gpFiles::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 = common::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)) { common::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(gpFiles::$last_version, '3.0b1', '<')) { $gp_menu = gpOutput::FixMenu($gp_menu); // fix gp_titles for gpEasy 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'] = common::GetLabelIndex($key, true); } } } //title related configuration settings if (empty($config['homepath_key'])) { $config['homepath_key'] = key($gp_menu); } $config['homepath'] = common::IndexToTitle($config['homepath_key']); }
function SendPassword() { global $langmessage, $gp_mailer, $config; includeFile('tool/email_mailer.php'); $users = gpFiles::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 = gpsession::PassAlgo($userinfo); $users[$username]['newpass'] = common::hash($newpass, $pass_hash); if (!gpFiles::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 = common::AbsoluteLink('Admin', $langmessage['login']); $message = sprintf($langmessage['passwordremindertext'], $server, $link, $username, $newpass); if ($gp_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; }
function SearchPage($title, $index) { global $gp_menu, $gp_titles; //search hidden? if (!$this->search_hidden && !isset($gp_menu[$index])) { return; } //private pages if (!common::LoggedIn()) { if (isset($gp_titles[$index]['vis'])) { return; } } $full_path = gpFiles::PageFile($title); $file_sections = gpFiles::Get($full_path, 'file_sections'); if (!$file_sections) { return; } $content = section_content::Render($file_sections, $title, gpFiles::$last_stats); $label = common::GetLabel($title); $this->FindString($content, $label, $title); }
/** * Create a new page from a user post * */ function CreateNew() { global $gp_index, $gp_titles, $langmessage, $gpAdmin; includeFile('tool/editing_page.php'); includeFile('tool/editing.php'); //check title $title = $_POST['title']; $title = admin_tools::CheckPostedNewPage($title, $message); if ($title === false) { message($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_edit::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_edit::DefaultContent($type); $section['attributes']['class'] .= ' ' . $class; $content[] = $section; } } //single section type } else { $content = gp_edit::DefaultContent($type); if ($content['content'] === false) { return false; } if ($type == 'text') { $content['content'] = '<h2>' . strip_tags($_POST['title']) . '</h2>' . $content['content']; } } //add to $gp_index first! $index = common::NewFileIndex(); $gp_index[$title] = $index; if (!gpFiles::NewTitle($title, $content, $type)) { message($langmessage['OOPS'] . ' (cn1)'); unset($gp_index[$title]); return false; } //add to gp_titles $new_titles = array(); $new_titles[$index]['label'] = 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 = gpFiles::Get('_site/users'); $users[$gpAdmin['username']]['editing'] = $gpAdmin['editing']; gpFiles::SaveData('_site/users', 'users', $users); } return $index; }
/** * Return an array of info about the data file * */ public static function GetFileStats($file) { $file_stats = gpFiles::Get($file, 'file_stats'); if ($file_stats) { return $file_stats; } return array('created' => time()); }
/** * Display the contents of a past revision * */ function ViewRevision() { global $langmessage; $time = $_REQUEST['time']; $full_path = $this->BackupFile($time); if (!$full_path) { return false; } $file_sections = $file_stats = array(); //if it's a compressed file, we need an uncompressed version if (strpos($full_path, '.gze') !== false) { ob_start(); readgzfile($full_path); $contents = ob_get_clean(); $dir = common::DirName($full_path); $full_path = tempnam($dir, 'backup'); gpFiles::Save($full_path, $contents); $file_sections = gpFiles::Get($full_path, 'file_sections'); unlink($full_path); } else { $file_sections = gpFiles::Get($full_path, 'file_sections'); } $this->contentBuffer = section_content::Render($file_sections, $this->title, gpFiles::$last_stats); $date = common::date($langmessage['strftime_datetime'], $time); $message = sprintf($langmessage['viewing_revision'], $date); $message .= ' <br/> ' . common::Link($this->title, $langmessage['Restore this revision'], 'cmd=use_revision&time=' . $time, array('data-cmd' => 'cnreq')); $message .= ' ' . common::Link($this->title, $langmessage['Revision History'], 'cmd=view_history', array('title' => $langmessage['Revision History'], 'data-cmd' => 'gpabox')); message($message); }
/** * Get current configuration settings * */ function Init() { $this->config_file = '_ckeditor/config'; $this->cke_config = gpFiles::Get($this->config_file, 'cke_config'); //$this->cke_config += array('custom_config'=>array()); $this->cke_config += array('plugins' => array()); $this->BuildConfig(); }
static function CKAdminConfig() { static $cke_config; //get ckeditor configuration set by users if (!is_array($cke_config)) { $cke_config = gpFiles::Get('_ckeditor/config', 'cke_config'); if (!$cke_config) { $cke_config = array(); } $cke_config += array('plugins' => array(), 'custom_config' => array()); } return $cke_config; }
function GetUsers() { $this->users = gpFiles::Get('_site/users'); //fix the editing value foreach ($this->users as $username => $userinfo) { $userinfo += array('granted' => ''); admin_tools::EditingValue($userinfo); $this->users[$username] = $userinfo; } }
/** * Get plugin configuration values * @since 3.6 * */ static function GetConfig() { $file = self::$current['data_folder_full'] . '/_config.php'; return gpFiles::Get($file, 'config'); }
/** * Retreive the data file for the current title and update the data if necessary * */ function GetFile() { $this->file_sections = gpFiles::Get($this->file, 'file_sections'); $this->meta_data = gpFiles::$last_meta; $this->fileModTime = gpFiles::$last_modified; $this->file_stats = gpFiles::$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>'); } }
/** * Get the section types so we can set the $gp_titles and $meta_data variables correctly * In future versions, fetching the $meta_data['file_type'] value will suffice * * @static */ static function GetTypes($file) { $types = array(); $file_sections = gpFiles::Get($file, 'file_sections'); foreach ($file_sections as $section) { $types[] = $section['type']; } $types = array_unique($types); return implode(',', $types); }