/** * Determine a user's language preference and redirect them to the appropriate homepage if necessary * How do we differentiate between a user requesting the home page (to get the default language content) and a request that should be redirected? * ... don't create any empty links (set $config['homepath'] to false) * ... redirect all empty paths? * */ function WhichPage($path) { global $config; $home_title = $config['homepath']; $config['homepath_key'] = false; $config['homepath'] = false; //only if homepage if (!empty($path)) { return $path; } //only if the homepage is translated $list = $this->GetList($config['homepath_key']); if (!$list) { common::Redirect(common::GetUrl($home_title)); //dies } //only if user has language settings if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { common::Redirect(common::GetUrl($home_title)); //dies } //check for appropriate translation $langs = $this->RequestLangs(); foreach ($langs as $lang => $importance) { if (isset($list[$lang])) { $title = common::IndexToTitle($list[$lang]); common::Redirect(common::GetUrl($title)); //dies } } common::Redirect(common::GetUrl($home_title)); }
/** * 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% */ function CheckSimilar() { global $config; $similar = $this->SimilarTitleArray($this->requested); reset($similar); $first_title = key($similar); $first_percent = current($similar); if ($config['auto_redir'] > 0 && $first_percent >= $config['auto_redir']) { common::Redirect($first_title); } }
/** * 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% * */ 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 = common::GetUrl($first_title, http_build_query($_GET), false); common::Redirect($redirect); } }
public function WhichPage($path) { global $config; $home_title = $config['homepath']; $home_key = $config['homepath_key']; $config['homepath_key'] = false; $config['homepath'] = false; //only if homepage if (!empty($path) && $path !== $home_title) { return $path; } $translated_key = $this->WhichTranslation($home_key); if (!is_null($translated_key)) { $home_title = common::IndexToTitle($translated_key); } //redirect if needed if ($home_title != $path) { common::Redirect(common::GetUrl($home_title)); } }
/** * Run commands * */ public function PostCommands() { global $page; $cmd = common::GetCommand(); if (empty($cmd)) { //redirect to correct url if needed SimpleBlogCommon::UrlQuery($this->post_id, $expected_url, $query); $expected_url = str_replace('&', '&', $expected_url); //because of htmlspecialchars($cattitle) if ($page->requested != $expected_url) { $expected_url = common::GetUrl($expected_url, $query, false); common::Redirect($expected_url); } return; } switch ($cmd) { case 'Add Comment': $this->AddComment(); break; } }
/** * Find the requested admin script and execute it if the user has permissions to view it * */ function RunAdminScript() { global $dataDir, $langmessage; //resolve request for /Admin_Theme_Content if the request is for /Admin_Theme_Conent/1234 $parts = explode('/', $this->requested); do { $request_string = implode('/', $parts); $scriptinfo = false; $scripts = admin_tools::AdminScripts(); if (isset($scripts[$request_string])) { $scriptinfo = $scripts[$request_string]; if (admin_tools::HasPermission($request_string)) { admin_display::OrganizeFrequentScripts($request_string); gpOutput::ExecInfo($scriptinfo); return; } else { message($langmessage['not_permitted']); $parts = array(); } } elseif (count($scripts) > 0) { //check case $case_check = array_keys($scripts); $case_check = array_combine($case_check, $case_check); $case_check = array_change_key_case($case_check, CASE_LOWER); $lower = strtolower($request_string); if (isset($case_check[$lower])) { $location = common::GetUrl($case_check[$lower], http_build_query($_GET), false); common::Redirect($location); } } //these are here because they should be available to everyone switch ($request_string) { case 'Admin_Browser': includeFile('admin/admin_browser.php'); new admin_browser(); return; case 'Admin_Preferences': $this->label = $langmessage['Preferences']; includeFile('admin/admin_preferences.php'); new admin_preferences(); return; case 'Admin_About': $this->label = 'About gpEasy'; includeFile('admin/admin_about.php'); new admin_about(); return; case 'Admin_Finder': if (admin_tools::HasPermission('Admin_Uploaded')) { includeFile('thirdparty/finder/connector.php'); return; } break; } array_pop($parts); } while (count($parts)); $this->AdminPanel(); }
/** * Display a blog page with multiple blog posts * */ public function ShowPage() { global $page; $per_page = SimpleBlogCommon::$data['per_page']; $page_num = 0; $expected_q = ''; if (isset($_GET['page']) && is_numeric($_GET['page'])) { $page_num = (int) $_GET['page']; $expected_q = 'page=' . $page_num; } //redirect if the request isn't correct if ($page->requested != SimpleBlogCommon::$root_url) { $expected_url = common::GetUrl(SimpleBlogCommon::$root_url, $expected_q, false); common::Redirect($expected_url); } $start = $page_num * $per_page; $include_drafts = common::LoggedIn(); $show_posts = SimpleBlogCommon::WhichPosts($start, $per_page, $include_drafts); $this->ShowPosts($show_posts); //pagination links echo '<p class="blog_nav_links">'; if ($page_num > 0) { $html = common::Link('Special_Blog', '%s'); echo gpOutput::GetAddonText('Blog Home', $html); echo ' '; $html = common::Link('Special_Blog', '%s', 'page=' . ($page_num - 1), 'class="blog_newer"'); echo gpOutput::GetAddonText('Newer Entries', $html); echo ' '; } if (($page_num + 1) * $per_page < SimpleBlogCommon::$data['post_count']) { $html = common::Link('Special_Blog', '%s', 'page=' . ($page_num + 1), 'class="blog_older"'); echo gpOutput::GetAddonText('Older Entries', $html); } echo '</p>'; }
/** * 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 = gpFiles::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 = common::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $width . '&h=' . $height . '&img=' . rawurlencode($index_img); common::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) { common::Send304(common::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 = common::GetDir('/include/image.php', false) . '?i=' . $index . '&w=' . $use_width . '&h=' . $use_height . '&img=' . rawurlencode($img); common::Redirect($path); //dies } } //redirect to full size image $original = common::GetDir('/data/_uploaded' . $img, false); common::Redirect($original); //dies }
/** * Re-enable components that were disabled because of fatal errors * */ static function EnableComponent() { includeFile('admin/admin_errors.php'); admin_errors::ClearError($_REQUEST['hash']); $title = common::WhichPage(); common::Redirect(common::GetUrl($title, '', false)); }
/** * * @static */ static function GetScriptInfo(&$requested, $redirect = true) { global $dataDir, $gp_index, $gp_titles; $scripts['special_site_map']['script'] = '/include/special/special_map.php'; $scripts['special_site_map']['class'] = 'special_map'; $scripts['special_galleries']['script'] = '/include/special/special_galleries.php'; $scripts['special_galleries']['class'] = 'special_galleries'; $scripts['special_contact']['script'] = '/include/special/special_contact.php'; $scripts['special_contact']['class'] = 'special_contact'; $scripts['special_missing']['script'] = '/include/special/special_missing.php'; $scripts['special_missing']['class'] = 'special_missing'; $scripts['special_gpsearch']['script'] = '/include/special/special_search.php'; $scripts['special_gpsearch']['class'] = 'special_gpsearch'; //check for use of a index instead of a page title $translated = common::SpecialHref($requested); if ($translated != $requested) { $requested = $translated; if ($redirect) { $title = common::GetUrl($requested, http_build_query($_GET), false); common::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; }
/** * Output the html for a single blog post * Handle comment actions */ function ShowPost($cmd) { global $langmessage, $page; $post = $this->GetPostContent($this->post_id); if ($post === false) { message($langmessage['OOPS']); return; } $commentSaved = false; switch ($cmd) { //redirect to correct url if needed case 'post': SimpleBlogCommon::UrlQuery($this->post_id, $expected_url, $query); $expected_url = str_replace('&', '&', $expected_url); //because of htmlspecialchars($cattitle) if ($page->requested != $expected_url) { $expected_url = common::GetUrl($expected_url, $query, false); common::Redirect($expected_url, 301); } break; //close comments //close comments case 'closecomments': $this->CloseComments($this->post_id); break; case 'opencomments': $this->OpenComments($this->post_id); break; //commments //commments case 'Add Comment': if ($this->AddComment($this->post_id)) { $commentSaved = true; } else { echo '<div class="comment_container">'; $this->CommentForm($this->post_id, true); echo '</div>'; return; } break; case 'delete_comment': $this->DeleteComment($this->post_id); break; } $post = $this->GetPostContent($this->post_id); if (!common::LoggedIn() && SimpleBlogCommon::AStrValue('drafts', $this->post_id)) { //How to make 404 page? message($langmessage['OOPS']); return; } $this->ShowPostContent($post, $this->post_id); $page->label = SimpleBlogCommon::Underscores($post['title']); //blog categories if (isset($post['categories']) && count($post['categories'])) { $temp = array(); foreach ($post['categories'] as $catindex) { $title = SimpleBlogCommon::AStrValue('categories', $catindex); if (!$title) { continue; } if (SimpleBlogCommon::AStrValue('categories_hidden', $catindex)) { continue; } $temp[] = SimpleBlogCommon::CategoryLink($catindex, $title, $title); } if (count($temp)) { echo '<div class="category_container">'; echo '<b>'; echo gpOutput::GetAddonText('Categories'); echo ':</b> '; echo implode(', ', $temp); echo '</div>'; } } SimpleBlog::PostLinks($this->post_id); //comments if (SimpleBlogCommon::$data['allow_comments']) { echo '<div class="comment_container">'; $this->ShowComments($this->post_id); if (!$commentSaved) { $this->CommentForm($this->post_id); } echo '</div>'; } }
/** * Return the name of the page being requested based on $_SERVER['REQUEST_URI'] * May also redirect the request * * @return string The title to display based on the request uri * */ function WhichPage() { global $config, $gp_internal_redir, $gp_menu; if (isset($gp_internal_redir)) { return $gp_internal_redir; } $path = common::CleanRequest($_SERVER['REQUEST_URI']); $pos = strpos($path, '?'); if ($pos !== false) { $path = substr($path, 0, $pos); } $path = gpPlugin::Filter('WhichPage', array($path)); //redirect if an "external link" is the first entry of the main menu if (empty($path) && isset($gp_menu[$config['homepath_key']])) { $homepath_info = $gp_menu[$config['homepath_key']]; if (isset($homepath_info['url'])) { common::Redirect($homepath_info['url'], 302); } } if (empty($path)) { return $config['homepath']; } if (isset($config['homepath']) && $path == $config['homepath']) { common::Redirect(common::GetUrl('')); } return $path; }
/** * Save a new blog post * @return bool * */ function SaveNew() { global $langmessage, $gpAdmin; //use current data file or create new one SimpleBlogCommon::$data['post_index']++; $new_id = SimpleBlogCommon::$data['post_index']; //add new_id to list of indeces $str_index = SimpleBlogCommon::AStrToArray('str_index'); array_unshift($str_index, $new_id); SimpleBlogCommon::$data['str_index'] = SimpleBlogCommon::AStrFromArray($str_index); //save to data file $post = array(); if (!self::SavePost($new_id, $post)) { return false; } //redirect to new post $url = common::GetUrl('Admin_Blog', '', false); common::Redirect($url); }
/** * Find the requested admin script and execute it if the user has permissions to view it * */ function RunAdminScript() { global $dataDir, $langmessage; //resolve request for /Admin_Theme_Content if the request is for /Admin_Theme_Conent/1234 $parts = explode('/', $this->requested); do { $request_string = implode('/', $parts); $scriptinfo = false; $scripts = admin_tools::AdminScripts(); if (isset($scripts[$request_string])) { $scriptinfo = $scripts[$request_string]; if (admin_tools::HasPermission($request_string)) { if (isset($scriptinfo['addon'])) { gpPlugin::SetDataFolder($scriptinfo['addon']); } admin_display::OrganizeFrequentScripts($request_string); if (isset($scriptinfo['script'])) { require $dataDir . $scriptinfo['script']; } if (isset($scriptinfo['class'])) { new $scriptinfo['class'](); } gpPlugin::ClearDataFolder(); return; } else { message($langmessage['not_permitted']); $parts = array(); } } elseif (count($scripts) > 0) { //check case $case_check = array_keys($scripts); $case_check = array_combine($case_check, $case_check); $case_check = array_change_key_case($case_check, CASE_LOWER); $lower = strtolower($request_string); if (isset($case_check[$lower])) { $location = common::GetUrl($case_check[$lower], '', false); common::Redirect($location); } } //these are here because they should be available to everyone switch ($request_string) { case 'Admin_Browser': includeFile('admin/admin_browser.php'); new admin_browser(); return; case 'Admin_Preferences': includeFile('admin/admin_preferences.php'); new admin_preferences(); return; case 'Admin_About': includeFile('admin/admin_about.php'); new admin_about(); return; case 'Admin_Finder': includeFile('thirdparty/elfinder/connector.php'); return; } } while (array_pop($parts)); $this->AdminPanel(); }
/** * * @static */ function GetScriptInfo(&$requested) { global $dataDir, $gp_index, $gp_titles; $scripts['special_site_map']['script'] = '/include/special/special_map.php'; $scripts['special_site_map']['class'] = 'special_map'; $scripts['special_galleries']['script'] = '/include/special/special_galleries.php'; $scripts['special_galleries']['class'] = 'special_galleries'; $scripts['special_contact']['script'] = '/include/special/special_contact.php'; $scripts['special_contact']['class'] = 'special_contact'; $scripts['special_missing']['script'] = '/include/special/special_missing.php'; $scripts['special_missing']['class'] = 'special_missing'; if (isset($gp_index[$requested])) { $index = $gp_index[$requested]; if (isset($scripts[$index])) { return $scripts[$index]; } if (isset($gp_titles[$index])) { return $gp_titles[$index]; } } //resolve if the requested path matches a data index $title = common::IndexToTitle(strtolower($requested)); if ($title) { $title = common::GetUrl($title, '', false); common::Redirect($title); } return false; }
/** * Return the name of the page being requested based on $_SERVER['REQUEST_URI'] * May also redirect the request * * @return string The title to display based on the request uri * */ static function WhichPage() { global $config, $gp_menu; $path = common::CleanRequest($_SERVER['REQUEST_URI']); $path = preg_replace('#[[:cntrl:]]#u', '', $path); // remove control characters $pos = mb_strpos($path, '?'); if ($pos !== false) { $path = mb_substr($path, 0, $pos); } $path = gpPlugin::Filter('WhichPage', array($path)); //redirect if an "external link" is the first entry of the main menu if (empty($path) && isset($gp_menu[$config['homepath_key']])) { $homepath_info = $gp_menu[$config['homepath_key']]; if (isset($homepath_info['url'])) { common::Redirect($homepath_info['url'], 302); } } if (empty($path)) { return $config['homepath']; } if (isset($config['homepath']) && $path == $config['homepath']) { $args = $_GET; common::Redirect(common::GetUrl('', http_build_query($_GET), false)); } return $path; }
/** * 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 */ function SaveHtaccess() { global $gp_filesystem, $langmessage, $dirPrefix; if (isset($_POST['rewrite_setting']) && $_POST['rewrite_setting'] == 'hide_index') { $this->changed_to_hide = true; } // only proceed with hide if we can test the results if (!gpRemoteGet::Test()) { $this->ManualMethod(); return false; } if (!$gp_filesystem->ConnectOrPrompt('Admin_Permalinks')) { $this->ManualMethod(); return false; } if (!$this->SaveRules()) { $gp_filesystem->CompleteForm($_POST, 'Admin_Permalinks'); $this->ManualMethod(); return false; } message($langmessage['SAVED']); //redirect to new permalink structure $_SERVER['gp_rewrite'] = $this->changed_to_hide; common::SetLinkPrefix(); $redir = common::GetUrl('Admin_Permalinks'); common::Redirect($redir, 302); return false; }
function ReturnHeader() { if (empty($_POST['return'])) { return; } $return = trim($_POST['return']); if (strpos($return, 'http') !== 0) { $return = common::GetUrl($return, '', false); } common::Redirect($return, 302); }
/** * 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 = admin_permalinks::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; common::SetLinkPrefix(); $redir = common::GetUrl('Admin_Permalinks'); common::Redirect($redir, 302); return false; }