function SaveAddonData() { if (!isset($this->dataFile)) { trigger_error('dataFile not set'); return; } $addonData = array(); while (count($this->addonHistory) > 30) { array_shift($this->addonHistory); } $addonData['history'] = $this->addonHistory; $addonData['reviews'] = $this->addonReviews; return gpFiles::SaveData($this->dataFile, 'addonData', $addonData); }
/** * 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; includeFile('tool/gpOutput.php'); $special_indexes = array(); $new_index = array(); $new_titles = array(); foreach ($gp_index as $title => $index) { $info = $gp_titles[$index]; $type = common::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 (!admin_tools::SavePagesPHP()) { return; } $config['gpversion'] = '2.3.4'; 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 (gpFiles::Exists($menu_file)) { $menu = gpOutput::GetMenuArray($key); $menu = $this->FixMenu($menu, $special_indexes); gpFiles::SaveData($menu_file, 'menu', $menu); } } } }
/** * 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); } }
/** * Generate a file with all of the combined content * */ static function GenerateFile($files, $type) { global $dataDir; //get etag $modified = $content_length = 0; $full_paths = array(); foreach ($files as $file) { $full_path = gp_combine::CheckFile($file); if ($full_path === false) { continue; } gp_combine::FileStat_Static($full_path, $modified, $content_length); $full_paths[$file] = $full_path; } //check css imports if ($type == 'css') { $had_imported = false; $import_data = array(); $imported_file = $dataDir . '/data/_cache/import_info.php'; if (file_exists($imported_file)) { include_once $imported_file; } foreach ($full_paths as $file => $full_path) { if (!isset($import_data[$full_path])) { continue; } $had_imported = true; foreach ($import_data[$full_path] as $imported_full) { gp_combine::FileStat_Static($imported_full, $modified, $content_length); } unset($import_data[$full_path]); } } //check to see if file exists $etag = common::GenEtag(json_encode($files), $modified, $content_length); $cache_relative = '/data/_cache/combined_' . $etag . '.' . $type; $cache_file = $dataDir . $cache_relative; if (file_exists($cache_file)) { // change modified time to extend cache if (time() - filemtime($cache_file) > 604800) { touch($cache_file); } return $cache_relative; } //create file if ($type == 'js') { ob_start(); common::jsStart(); foreach ($full_paths as $full_path) { readfile($full_path); echo ";\n"; } $combined_content = ob_get_clean(); } else { $imports = $combined_content = ''; $new_imported = array(); foreach ($full_paths as $file => $full_path) { $temp = new gp_combine_css($file); $combined_content .= "\n/* " . $file . " */\n"; $combined_content .= $temp->content; $imports .= $temp->imports; if (count($temp->imported)) { $new_imported[$full_path] = $temp->imported; } } $combined_content = $imports . $combined_content; //save imported data if (count($new_imported) || $had_imported) { if (count($new_imported)) { $import_data = $new_imported + $import_data; } gpFiles::SaveData($imported_file, 'import_data', $import_data); } } if (!gpFiles::Save($cache_file, $combined_content)) { return false; } includeFile('admin/admin_tools.php'); admin_tools::CleanCache(); return $cache_relative; }
/** * 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 */ 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']) && 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; }
/** * Copy the php file in _pages to _trash for $title * */ static function MoveToTrash_File($title, $index, &$trash_data) { global $dataDir, $gp_titles, $config; //get the file data $source_file = gpFiles::PageFile($title); $source_dir = dirname($source_file); $trash_file = $source_dir . '/deleted.php'; $file_sections = gpFiles::Get($source_file, 'file_sections'); //create trash info file $trash_info = $gp_titles[$index]; $trash_info['title'] = $title; $trash_info['time'] = time(); if (!gpFiles::SaveData($trash_file, 'deleted', $trash_info)) { return false; } //update image information if (count($file_sections)) { includeFile('image.php'); gp_resized::SetIndex(); foreach ($file_sections as $section_data) { if (isset($section_data['resized_imgs'])) { gp_edit::ResizedImageUse($section_data['resized_imgs'], array()); } } } return true; }
/** * Save the gpEasy configuration * @return bool * */ static function SaveConfig() { global $config, $dataDir; if (!is_array($config)) { return false; } if (!isset($config['gpuniq'])) { $config['gpuniq'] = common::RandomString(20); } return gpFiles::SaveData($dataDir . '/data/_site/config.php', 'config', $config); }
/** * Save the configuration file * */ function SaveConfig() { return gpFiles::SaveData($this->config_file, 'cke_config', $this->cke_config); }
/** * Save the content for a new page in /data/_pages/<title> * @since 1.8a1 * */ public static function NewTitle($title, $section_content = false, $type = 'text') { // get the file for the title if (empty($title)) { return false; } $file = gpFiles::PageFile($title); if (!$file) { return false; } // organize section data $file_sections = array(); if (is_array($section_content) && isset($section_content['type'])) { $file_sections[0] = $section_content; } elseif (is_array($section_content)) { $file_sections = $section_content; } else { $file_sections[0] = array('type' => $type, 'content' => $section_content); } // add meta data $meta_data = array('file_number' => gpFiles::NewFileNumber(), 'file_type' => $type); return gpFiles::SaveData($file, 'file_sections', $file_sections, $meta_data); }
function SaveConfig() { global $langmessage; if (isset($_POST['search_hidden'])) { $search_config['search_hidden'] = true; } else { $search_config['search_hidden'] = false; } if (gpFiles::SaveData($this->config_file, 'search_config', $search_config)) { msg($langmessage['SAVED']); $this->search_config = $search_config; return true; } msg($langmessage['OOPS']); $this->Config($_POST); return false; }
function SaveData() { return gpFiles::SaveData($this->datafile, 'error_data', $this->error_data); }
/** * Make the working draft the live file * */ public function PublishDraft() { global $langmessage; if (!$this->draft_exists) { msg($langmessage['OOPS'] . ' (Not a draft)'); return false; } if (!gpFiles::SaveData($this->file, 'file_sections', $this->file_sections, $this->draft_meta)) { msg($langmessage['OOPS'] . ' (Draft not published)'); return false; } unlink($this->draft_file); $this->ResetFileTypes(); $this->draft_exists = false; msg($langmessage['SAVED']); }
/** * Save the posted data * */ function SaveClasses() { global $langmessage; $classes = array(); foreach ($_POST['class_names'] as $i => $class_names) { $class_names = trim($class_names); if (empty($class_names)) { continue; } $classes[] = array('names' => $class_names, 'desc' => $_POST['class_desc'][$i]); } if (gpFiles::SaveData('_config/classes', 'classes', $classes)) { msg($langmessage['SAVED']); } else { msg($langmessage['OOPS'] . ' (Not Saved)'); } }
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; }
/** * Save the content for a new page in /data/_pages/<title> * @since 1.8a1 * */ static function NewTitle($title, $section_content = false, $type = 'text') { if (empty($title)) { return false; } $file = gpFiles::PageFile($title); if (!$file) { return false; } $file_sections = array(); if (is_array($section_content)) { $file_sections[0] = $section_content; } else { $file_sections[0] = array('type' => $type, 'content' => $section_content); } $meta_data = array('file_number' => gpFiles::NewFileNumber(), 'file_type' => $type); return gpFiles::SaveData($file, 'file_sections', $file_sections, $meta_data); }
function SaveThis($backup = true) { if (!is_array($this->meta_data) || !is_array($this->file_sections)) { return false; } //file count if (!isset($this->meta_data['file_number'])) { $this->meta_data['file_number'] = gpFiles::NewFileNumber(); } if ($backup) { $this->SaveBackup(); //make a backup of the page file } return gpFiles::SaveData($this->file, 'file_sections', $this->file_sections, $this->meta_data); }
/** * Perform various section editing commands * */ function SectionEdit($cmd) { global $page, $langmessage; if (empty($_REQUEST['file'])) { message($langmessage['OOPS']); return false; } $page->ajaxReplace = array(); $file = gp_edit::CleanTitle($_REQUEST['file']); $data = gpOutput::ExtraContent($file, $file_stats); $page->file_sections = array($data); //hack so the SaveSection filter works $page->file_stats = $file_stats; if (!gp_edit::SectionEdit($cmd, $data, 0, '', $file_stats)) { return; } //save the new content $file_full = $this->folder . '/' . $file . '.php'; if (!gpFiles::SaveData($file_full, 'extra_content', $data)) { message($langmessage['OOPS']); $this->EditExtra(); return false; } $page->ajaxReplace[] = array('ck_saved', '', ''); message($langmessage['SAVED']); $this->areas[$file] = $file; $this->EditExtra(); return true; }
static function SaveIndex($galleries) { global $dataDir; includeFile('admin/admin_tools.php'); $file = $dataDir . '/data/_site/galleries.php'; return gpFiles::SaveData($file, 'galleries', $galleries); }
function AltMenu_Create() { global $config, $langmessage, $dataDir; $menu_name = $this->AltMenu_NewName(); if (!$menu_name) { return; } $new_menu = $this->AltMenu_New(); //get next index $index = 0; if (isset($config['menus']) && is_array($config['menus'])) { foreach ($config['menus'] as $id => $label) { $id = substr($id, 1); $index = max($index, $id); } } $index++; $id = 'm' . $index; $menu_file = $dataDir . '/data/_menus/' . $id . '.php'; if (!gpFiles::SaveData($menu_file, 'menu', $new_menu)) { message($langmessage['OOPS'] . ' (Menu Not Saved)'); return false; } $config['menus'][$id] = $menu_name; if (!admin_tools::SaveConfig()) { message($langmessage['OOPS'] . ' (Config Not Saved)'); } else { $this->avail_menus[$id] = $menu_name; $this->curr_menu_id = $id; } }
/** * Get plugin configuration values * @since 3.6 * */ function SaveConfig($config) { $file = self::$current['data_folder_full'] . '/_config.php'; if (gpFiles::SaveData($file, 'config', $config)) { return true; } return false; }
static function NewExtra($file, $content) { $extra_content = array('type' => 'text', 'content' => $content); return gpFiles::SaveData($file, 'extra_content', $extra_content); }
/** * 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); }
function SaveUserFile($refresh = true) { global $langmessage; if (!gpFiles::SaveData('_site/users', 'users', $this->users)) { message($langmessage['OOPS']); return false; } if ($refresh && isset($_GET['gpreq']) && $_GET['gpreq'] == 'json') { message($langmessage['SAVED'] . ' ' . $langmessage['REFRESH']); } else { message($langmessage['SAVED']); } return true; }
/** * Get usage information about a image * */ static function SaveUsage($index, $data) { global $dataDir; $data_file = $dataDir . '/data/_resized/' . $index . '/data.php'; return gpFiles::SaveData($data_file, 'usage', $data); }
/** * Return the name of the cleansed extra area name, create file if it doesn't already exist * */ function NewExtraArea() { global $langmessage, $dataDir; $title = gp_edit::CleanTitle($_REQUEST['extra_area']); if (empty($title)) { message($langmessage['OOPS']); return false; } $data = gp_edit::DefaultContent($_POST['type']); $file = $dataDir . '/data/_extra/' . $title . '.php'; if (gpFiles::Exists($file)) { return $title; } if (!gpFiles::SaveData($file, 'extra_content', $data)) { message($langmessage['OOPS']); return false; } return $title; }
static function SaveTrashTitles($trash_titles) { global $dataDir; $index_file = $dataDir . '/data/_site/trash.php'; uksort($trash_titles, 'strnatcasecmp'); return gpFiles::SaveData($index_file, 'trash_titles', $trash_titles); }