/** * Redirect the request if the requested page closely matches an existing page * If it's just a difference of case, then the similarity will be 100% * */ public function CheckSimilar() { global $config; $requested = trim($this->requested, '/'); $similar = $this->SimilarTitleArray($requested); $first_title = key($similar); $first_percent = current($similar); if ($config['auto_redir'] > 0 && $first_percent >= $config['auto_redir']) { $redirect = \gp\tool::GetUrl($first_title, http_build_query($_GET), false); \gp\tool::Redirect($redirect); } }
public function RunScript() { global $gpLayouts, $config; //layout request $parts = explode('/', $this->page->requested); if (!empty($parts[2])) { if ($this->SetCurrLayout($parts[2])) { $this->EditLayout(); return; } //default layout } elseif ($this->SetCurrLayout($config['gpLayout'])) { $this->EditLayout(); return; } //redirect $url = \gp\tool::GetUrl('Admin_Theme_Content', '', false); \gp\tool::Redirect($url, 302); }
/** * Redirect admin request to the most similar page * */ private function Redirect() { //find similar $scripts = $this->scripts; $scripts['Admin'] = array(); $similar = array(); $lower_req = strtolower($this->requested); foreach ($scripts as $key => $script_info) { $lower_key = strtolower($key); similar_text($lower_req, $lower_key, $percent); $similar[$key] = $percent; } arsort($similar); $redir_key = key($similar); $location = \gp\tool::GetUrl($redir_key, http_build_query($_GET), false); \gp\tool::Redirect($location); }
/** * Check the path of the img, return full path of image if the requested image is found * */ function __construct() { global $dataDir; if (!isset($_GET['w']) || !isset($_GET['h']) || !isset($_GET['img'])) { self::Send404(); //dies } $img = $_GET['img']; $height = $_GET['h']; $width = $_GET['w']; $index = $_GET['i']; if (!is_numeric($height) || !is_numeric($width)) { self::Send404(); //dies } $img = \gp\tool\Files::NoNull($img); //check file path if (strpos($img, './') !== false || strpos($img, '%2f') !== false || strpos($img, '%2F') !== false) { return false; } //make sure the index is set gp_resized::SetIndex(); if (!isset(self::$index[$index])) { self::Send404(); //dies } //if the image has been renamed, redirect to the new name $index_img = self::$index[$index]; if ($index_img != $img) { $path = \gp\tool::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $width . '&h=' . $height . '&img=' . rawurlencode($index_img); \gp\tool::Redirect($path); } $info = self::ImageInfo($img, $width, $height); $folder = $dataDir . '/data/_resized/' . $info['index']; $full_path = $folder . '/' . $info['name']; //if it exists return true if (file_exists($full_path)) { header('Cache-Control: public, max-age=5184000'); //60 days //attempt to send 304 $stats = lstat($full_path); if ($stats) { \gp\tool::Send304(\gp\tool::GenEtag($stats['mtime'], $stats['size'])); } header('Content-Transfer-Encoding: binary'); header('Content-Type: ' . $info['ctype']); readfile($full_path); die; } //redirect to next largest image if available $usage = self::GetUsage($info['index']); foreach ($usage as $size => $data) { if (!$data['uses']) { continue; } list($use_width, $use_height) = explode('x', $size); if ($use_width >= $width && $use_height > $height || $use_width > $width && $use_height >= $height) { $path = \gp\tool::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $use_width . '&h=' . $use_height . '&img=' . rawurlencode($img); \gp\tool::Redirect($path); //dies } } //redirect to full size image $original = \gp\tool::GetDir('/data/_uploaded' . $img, false); \gp\tool::Redirect($original); //dies }
/** * Re-enable components that were disabled because of fatal errors * */ public static function ClearErrors() { \gp\admin\Tools\Errors::ClearAll(); $title = \gp\tool::WhichPage(); \gp\tool::Redirect(\gp\tool::GetUrl($title, '', false)); }
public function ReturnHeader() { if (empty($_POST['return'])) { return; } $return = trim($_POST['return']); if (strpos($return, 'http') !== 0) { $return = \gp\tool::GetUrl($return, '', false); } \gp\tool::Redirect($return, 302); }
/** * 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); } }
/** * Determine how to save the htaccess file to the server (ftp,direct,manual) and give user the appropriate options * * @return boolean true if the .htaccess file is saved */ public function SaveHtaccess() { global $langmessage, $dirPrefix; //hide index ? if (isset($_POST['rewrite_setting']) && $_POST['rewrite_setting'] == 'hide_index') { $this->hide_index = true; $this->undo_if_failed = true; } // www preference $www = null; if (isset($_POST['www_setting'])) { if ($_POST['www_setting'] === 'with') { $www = true; $this->undo_if_failed = true; } elseif ($_POST['www_setting'] === 'without') { $www = false; $this->undo_if_failed = true; } } $this->new_rules = self::Rewrite_Rules($this->hide_index, $dirPrefix, $this->orig_rules, $www); // only proceed with hide if we can test the results if (!$this->CanTestRules()) { $this->ManualMethod(); return false; } if (!$this->SaveRules()) { $this->FileSystem->CompleteForm($_POST, 'Admin/Permalinks'); $this->ManualMethod(); return false; } msg($langmessage['SAVED']); //redirect to new permalink structure $_SERVER['gp_rewrite'] = $this->hide_index; \gp\tool::SetLinkPrefix(); $redir = \gp\tool::GetUrl('Admin/Permalinks'); \gp\tool::Redirect($redir, 302); return false; }
/** * */ public static function GetScriptInfo(&$requested, $redirect = true) { global $dataDir, $gp_index, $gp_titles; $scripts['special_site_map']['class'] = '\\gp\\special\\Map'; $scripts['special_galleries']['class'] = '\\gp\\special\\Galleries'; $scripts['special_contact']['class'] = '\\gp\\special\\Contact'; $scripts['special_missing']['class'] = '\\gp\\special\\Missing'; $scripts['special_gpsearch']['class'] = '\\gp\\special\\Search'; //check for use of a index instead of a page title $translated = \gp\tool::SpecialHref($requested); if ($translated != $requested) { $requested = $translated; if ($redirect) { $title = \gp\tool::GetUrl($requested, http_build_query($_GET), false); \gp\tool::Redirect($title); } } //get the script info $parts = explode('/', $requested); do { $requested = implode('/', $parts); if (isset($gp_index[$requested])) { $index = $gp_index[$requested]; // Merge page data & script data if both exist if (isset($scripts[$index]) && isset($gp_titles[$index])) { return array_merge($scripts[$index], $gp_titles[$index]); } if (isset($scripts[$index])) { return $scripts[$index]; } if (isset($gp_titles[$index])) { return $gp_titles[$index]; } } array_pop($parts); } while (count($parts)); return false; }