public 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 \gp\tool\Files::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; $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); } } } }
/** * 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); } }
public function SaveMenu($menu_and_pages = false) { global $dataDir; if ($this->is_main_menu) { return \gp\admin\Tools::SavePagesPHP(); } if (is_null($this->curr_menu_array)) { return false; } if ($menu_and_pages && !\gp\admin\Tools::SavePagesPHP()) { return false; } $menu_file = $dataDir . '/data/_menus/' . $this->curr_menu_id . '.php'; return \gp\tool\Files::SaveData($menu_file, 'menu', $this->curr_menu_array); }
public function SaveUserFile($refresh = true) { global $langmessage; if (!\gp\tool\Files::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; }
/** * Create a new extra content section * */ public function NewSection() { global $langmessage, $gpAdmin; $title = \gp\tool\Editing::CleanTitle($_REQUEST['new_title']); if (empty($title)) { message($langmessage['OOPS'] . ' (Invalid Title)'); return false; } $file = $this->folder . '/' . $title . '/page.php'; $section = \gp\tool\Editing::DefaultContent($_POST['type']); $section['created'] = time(); $section['created_by'] = $gpAdmin['username']; $sections = array($section); if (!\gp\tool\Files::SaveData($file, 'file_sections', $sections)) { message($langmessage['OOPS'] . ' (Not Saved)'); return false; } message($langmessage['SAVED']); $this->areas[$title] = $title; }
/** * Get plugin configuration values * @since 3.6 * */ function SaveConfig($config) { $file = self::$current['data_folder_full'] . '/_config.php'; if (\gp\tool\Files::SaveData($file, 'config', $config)) { return true; } return false; }
/** * 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 (\gp\tool\Files::SaveData('_config/classes', 'classes', $classes)) { msg($langmessage['SAVED']); } else { msg($langmessage['OOPS'] . ' (Not Saved)'); } }
/** * Make the working draft the live file * */ public function PublishDraft() { global $langmessage, $page; if (!$this->draft_exists) { msg($langmessage['OOPS'] . ' (Not a draft)'); return false; } if (!\gp\tool\Files::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; $page->ajaxReplace = array(); $page->ajaxReplace[] = array('DraftPublished'); return true; }
/** * Generate a file with all of the combined content * */ public static function GenerateFile($files, $type) { global $dataDir; //get etag $modified = $content_length = 0; $full_paths = array(); foreach ($files as $file) { $full_path = self::CheckFile($file); if ($full_path === false) { continue; } self::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) { self::FileStat_Static($imported_full, $modified, $content_length); } unset($import_data[$full_path]); } } //check to see if file exists $etag = \gp\tool::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(); \gp\tool::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\tool\Output\CombineCss($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; } \gp\tool\Files::SaveData($imported_file, 'import_data', $import_data); } } if (!\gp\tool\Files::Save($cache_file, $combined_content)) { return false; } \gp\admin\Tools::CleanCache(); return $cache_relative; }
public function SaveData() { return \gp\tool\Files::SaveData($this->datafile, 'error_data', $this->error_data); }
public function SaveConfig() { global $langmessage; if (isset($_POST['search_hidden'])) { $search_config['search_hidden'] = true; } else { $search_config['search_hidden'] = false; } if (\gp\tool\Files::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; }
/** * Create an alternate menu * */ public function NewMenuCreate() { global $config, $langmessage, $dataDir; $menu_name = $this->AltMenu_NewName(); if (!$menu_name) { return; } $new_menu = \gp\admin\Menu\Tools::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 (!\gp\tool\Files::SaveData($menu_file, 'menu', $new_menu)) { msg($langmessage['OOPS'] . ' (Menu Not Saved)'); return false; } $config['menus'][$id] = $menu_name; if (\gp\admin\Tools::SaveConfig(true)) { $url = \gp\tool::GetUrl('Admin/Menu', 'menu=' . $id, false); \gp\tool::Redirect($url); } }
/** * Save the CMS configuration * @return bool * */ public static function SaveConfig($notify_fail = false, $notify_save = false) { global $config, $langmessage; $saved = is_array($config) && \gp\tool\Files::SaveData('_site/config', 'config', $config); return self::SaveNotify($saved, $notify_fail, $notify_save, ' (Config not saved)'); }
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; }
/** * Save the configuration file * */ function SaveConfig() { return \gp\tool\Files::SaveData($this->config_file, 'cke_config', $this->cke_config); }
/** * Get usage information about a image * */ static function SaveUsage($index, $data) { global $dataDir; $data_file = $dataDir . '/data/_resized/' . $index . '/data.php'; return \gp\tool\Files::SaveData($data_file, 'usage', $data); }
/** * 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; }
/** * 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; }
/** * 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); }
/** * Copy the php file in _pages to _trash for $title * */ public static function MoveToTrash_File($title, $index, &$trash_data) { global $dataDir, $gp_titles, $config; //get the file data $source_file = \gp\tool\Files::PageFile($title); $source_dir = dirname($source_file); $trash_file = $source_dir . '/deleted.php'; $file_sections = \gp\tool\Files::Get($source_file, 'file_sections'); //create trash info file $trash_info = $gp_titles[$index]; $trash_info['title'] = $title; $trash_info['time'] = time(); if (!\gp\tool\Files::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\tool\Editing::ResizedImageUse($section_data['resized_imgs'], array()); } } } return true; }
public static function SaveIndex($galleries) { global $dataDir; $file = $dataDir . '/data/_site/galleries.php'; return \gp\tool\Files::SaveData($file, 'galleries', $galleries); }
static function NewExtra($file, $content) { $extra_content = array('type' => 'text', 'content' => $content); return \gp\tool\Files::SaveData($file, 'extra_content', $extra_content); }
/** * 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; }