📄 seo.url.php
字号:
<?php/* +----------------------------------------------------------------------+ | Ultimate SEO URLs For Zen Cart, version 2.101 | +----------------------------------------------------------------------+ | | | Derrived from Ultimate SEO URLs v2.1 for osCommerce by Chemo | | | | Portions Copyright 2005, Joshua Dechant | | | | Portions Copyright 2005, Bobby Easland | | | | Portions Copyright 2003 The zen-cart developers | | | +----------------------------------------------------------------------+ | This source file is subject to version 2.0 of the GPL license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.zen-cart.com/license/2_0.txt. | | If you did not receive a copy of the zen-cart license and are unable | | to obtain it through the world-wide-web, please send a note to | | license@zen-cart.com so we can mail you a copy immediately. | +----------------------------------------------------------------------+*/ require_once(dirname(__FILE__) . '/seo.install.php'); class SEO_URL{ var $cache; var $languages_id; var $attributes; var $base_url; var $base_url_ssl; var $reg_anchors; var $cache_query; var $cache_file; var $data; var $need_redirect; var $is_seopage; var $uri; var $real_uri; var $uri_parsed; var $db; var $installer; function SEO_URL($languages_id=''){ global $session_started; $this->installer = &new SEO_URL_INSTALLER(); $this->db = &$GLOBALS['db']; if ($languages_id == '') $languages_id = $_SESSION['languages_id']; $this->languages_id = (int)$languages_id; $this->data = array(); $seo_pages = array( FILENAME_DEFAULT, FILENAME_PRODUCT_INFO, FILENAME_POPUP_IMAGE, FILENAME_PRODUCT_REVIEWS, FILENAME_PRODUCT_REVIEWS_INFO, ); // News & Article Manager SEO support if (defined('FILENAME_NEWS_INDEX')) $seo_pages[] = FILENAME_NEWS_INDEX; if (defined('FILENAME_NEWS_ARTICLE')) $seo_pages[] = FILENAME_NEWS_ARTICLE; if (defined('FILENAME_NEWS_COMMENTS')) $seo_pages[] = FILENAME_NEWS_COMMENTS; if (defined('FILENAME_NEWS_ARCHIVE')) $seo_pages[] = FILENAME_NEWS_ARCHIVE; if (defined('FILENAME_NEWS_RSS')) $seo_pages[] = FILENAME_NEWS_RSS; // Info Manager (Open Operations) if (defined('FILENAME_INFO_MANAGER')) $seo_pages[] = FILENAME_INFO_MANAGER; $this->attributes = array( 'PHP_VERSION' => PHP_VERSION, 'SESSION_STARTED' => $session_started, 'SID' => (defined('SID') && $this->not_null(SID) ? SID : ''), 'SEO_ENABLED' => defined('SEO_ENABLED') ? SEO_ENABLED : 'false', 'SEO_ADD_CPATH_TO_PRODUCT_URLS' => defined('SEO_ADD_CPATH_TO_PRODUCT_URLS') ? SEO_ADD_CPATH_TO_PRODUCT_URLS : 'false', 'SEO_ADD_CAT_PARENT' => defined('SEO_ADD_CAT_PARENT') ? SEO_ADD_CAT_PARENT : 'true', 'SEO_URLS_USE_W3C_VALID' => defined('SEO_URLS_USE_W3C_VALID') ? SEO_URLS_USE_W3C_VALID : 'true', 'USE_SEO_CACHE_GLOBAL' => defined('USE_SEO_CACHE_GLOBAL') ? USE_SEO_CACHE_GLOBAL : 'false', 'USE_SEO_CACHE_PRODUCTS' => defined('USE_SEO_CACHE_PRODUCTS') ? USE_SEO_CACHE_PRODUCTS : 'false', 'USE_SEO_CACHE_CATEGORIES' => defined('USE_SEO_CACHE_CATEGORIES') ? USE_SEO_CACHE_CATEGORIES : 'false', 'USE_SEO_CACHE_MANUFACTURERS' => defined('USE_SEO_CACHE_MANUFACTURERS') ? USE_SEO_CACHE_MANUFACTURERS : 'false', 'USE_SEO_CACHE_ARTICLES' => defined('USE_SEO_CACHE_ARTICLES') ? USE_SEO_CACHE_ARTICLES : 'false', 'USE_SEO_CACHE_INFO_PAGES' => defined('USE_SEO_CACHE_INFO_PAGES') ? USE_SEO_CACHE_INFO_PAGES : 'false', 'USE_SEO_REDIRECT' => defined('USE_SEO_REDIRECT') ? USE_SEO_REDIRECT : 'false', 'SEO_REWRITE_TYPE' => defined('SEO_REWRITE_TYPE') ? SEO_REWRITE_TYPE : 'false', 'SEO_URLS_FILTER_SHORT_WORDS' => defined('SEO_URLS_FILTER_SHORT_WORDS') ? SEO_URLS_FILTER_SHORT_WORDS : 'false', 'SEO_CHAR_CONVERT_SET' => defined('SEO_CHAR_CONVERT_SET') ? $this->expand(SEO_CHAR_CONVERT_SET) : 'false', 'SEO_REMOVE_ALL_SPEC_CHARS' => defined('SEO_REMOVE_ALL_SPEC_CHARS') ? SEO_REMOVE_ALL_SPEC_CHARS : 'false', 'SEO_PAGES' => $seo_pages, 'SEO_INSTALLER' => $this->installer->attributes ); $this->base_url = HTTP_SERVER; $this->base_url_ssl = HTTPS_SERVER; $this->cache = array(); $this->reg_anchors = array( 'products_id' => '-p-', 'cPath' => '-c-', 'manufacturers_id' => '-m-', 'pID' => '-pi-', 'products_id_review' => '-pr-', 'products_id_review_info' => '-pri-', // News & Article Manager SEO support 'news_article_id' => '-a-', 'news_comments_article_id' => '-a-', 'news_dates' => '/', 'news_archive_dates' => '/archive/', 'news_rss_feed' => '/rss', // Info Manager (Open Operations) 'info_manager_page_id' => '-i-', ); if ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true'){ $this->cache_file = 'seo_urls_v2_'; $this->cache_gc(); if ( $this->attributes['USE_SEO_CACHE_PRODUCTS'] == 'true' ) $this->generate_products_cache(); if ( $this->attributes['USE_SEO_CACHE_CATEGORIES'] == 'true' ) $this->generate_categories_cache(); if ( $this->attributes['USE_SEO_CACHE_MANUFACTURERS'] == 'true' ) $this->generate_manufacturers_cache(); if ( $this->attributes['USE_SEO_CACHE_ARTICLES'] == 'true' && defined('TABLE_NEWS_ARTICLES_TEXT')) $this->generate_news_articles_cache(); if ( $this->attributes['USE_SEO_CACHE_INFO_PAGES'] == 'true' && defined('TABLE_INFO_MANAGER')) $this->generate_info_manager_cache(); } if ($this->attributes['USE_SEO_REDIRECT'] == 'true'){ $this->check_redirect(); } # end if } # end constructor function href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $static = false, $use_dir_ws_catalog = true) { // don't rewrite when disabled // don't rewrite images, css, js, xml, real html files, etc if ( ($this->attributes['SEO_ENABLED'] == 'false') || (preg_match('/(.+)\.(html?|xml|css|js|png|jpe?g|gif|bmp|tiff?|ico|gz|zip|rar)$/i', $page)) ) { return $this->stock_href_link($page, $parameters, $connection, $add_session_id, true, $static, $use_dir_ws_catalog); } // don't rewrite the paypal IPN notify url if ($page == 'ipn_main_handler.php') { return $this->stock_href_link($page, $parameters, $connection, $add_session_id, true, $static, $use_dir_ws_catalog); } // don't rewrite the zhifubao ATN notify url if ($page == 'atn_main_handler.php') { return $this->stock_href_link($page, $parameters, $connection, $add_session_id, true, $static, $use_dir_ws_catalog); } /* * Fix up $page */ $page = preg_replace('/(index\.php)?\??main_page=/', '', $page); if ((!in_array($page, $this->attributes['SEO_PAGES'])) || (($page == FILENAME_DEFAULT) && (!preg_match('/(cpath|manufacturers_id)/i', $parameters)))) { if ($page == FILENAME_DEFAULT) { $page = ''; } else { $page = $page . '.html'; } } if ($connection == 'NONSSL') { $link = $this->base_url; } elseif ($connection == 'SSL') { if (ENABLE_SSL == 'true') { $link = $this->base_url_ssl ; } else { $link = $this->base_url; } } if ($use_dir_ws_catalog) { if ($connection == 'SSL' && ENABLE_SSL == 'true') { $link .= DIR_WS_HTTPS_CATALOG; } else { $link .= DIR_WS_CATALOG; } } if (strstr($page, '?')) { $separator = '&'; } else { $separator = '?'; } if ($this->not_null($parameters)) { $link .= $this->parse_parameters($page, $parameters, $separator); } else { // support SEO pages with no parameters switch ($page) { case FILENAME_NEWS_RSS: $link .= $this->make_url($page, FILENAME_NEWS_INDEX, 'news_rss_feed', '', '.xml', $separator); break; case FILENAME_NEWS_ARCHIVE: $link .= $this->make_url($page, FILENAME_NEWS_INDEX, 'news_archive_dates', '', '', $separator); break; case FILENAME_NEWS_INDEX: $link .= $this->make_url($page, FILENAME_NEWS_INDEX, 'news_dates', '', '', $separator); break; default: $link .= $page; break; } } $link = $this->add_sid($link, $add_session_id, $connection, $separator); switch($this->attributes['SEO_URLS_USE_W3C_VALID']){ case 'true': if (!isset($_SESSION['customer_id']) && defined('ENABLE_PAGE_CACHE') && ENABLE_PAGE_CACHE == 'true' && class_exists('page_cache')){ return $link; } else { return htmlspecialchars(utf8_encode($link)); } break; case 'false': default: return $link; break; } } # end function function stock_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true, $static = false, $use_dir_ws_catalog = true) { global $request_type, $session_started, $http_domain, $https_domain; if (!$this->not_null($page)) { die('</td></tr></table></td></tr></table><br /><br /><strong class="note">Error!<br /><br />Unable to determine the page link!</strong><br /><br />'); } if ($connection == 'NONSSL') { $link = HTTP_SERVER; } elseif ($connection == 'SSL') { if (ENABLE_SSL == 'true') { $link = HTTPS_SERVER ; } else { $link = HTTP_SERVER; } } else { die('</td></tr></table></td></tr></table><br /><br /><strong class="note">Error!<br /><br />Unable to determine connection method on a link!<br /><br />Known methods: NONSSL SSL</strong><br /><br />'); } if ($use_dir_ws_catalog) { if ($connection == 'SSL') { $link .= DIR_WS_HTTPS_CATALOG; } else { $link .= DIR_WS_CATALOG; } } if (!$static) { if ($this->not_null($parameters)) { $link .= 'index.php?main_page='. $page . "&" . $this->output_string($parameters); } else { $link .= 'index.php?main_page=' . $page; } } else { if ($this->not_null($parameters)) { $link .= $page . "?" . $this->output_string($parameters); } else { $link .= $page; } } $separator = '&'; while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1); if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) { if ($this->not_null($this->attributes['SID'])) { $_sid = $this->attributes['SID']; } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == 'true') ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) { if ($http_domain != $https_domain) { $_sid = session_name() . '=' . session_id(); } } } // clean up the link before processing while (strstr($link, '&&')) $link = str_replace('&&', '&', $link); while (strstr($link, '&&')) $link = str_replace('&&', '&', $link); switch(true){ case (!isset($_SESSION['customer_id']) && defined('ENABLE_PAGE_CACHE') && ENABLE_PAGE_CACHE == 'true' && class_exists('page_cache')): $page_cache = true; $return = $link . $separator . '<zensid>'; break; case (isset($_sid)): $page_cache = false; $return = $link . $separator . $_sid; break; default: $page_cache = false; $return = $link; break; } $this->cache['STANDARD_URLS'][] = $link; switch(true){ case ($this->attributes['SEO_URLS_USE_W3C_VALID'] == 'true' && !$page_cache): return htmlspecialchars(utf8_encode($return)); break; default: return $return; break; }# end swtich } # end default tep_href function function add_sid($link, $add_session_id, $connection, $separator) { global $request_type, $http_domain, $https_domain; if ( ($add_session_id == true) && ($this->attributes['SESSION_STARTED']) && (SESSION_FORCE_COOKIE_USE == 'False') ) { if ($this->not_null($this->attributes['SID'])) { $_sid = $this->attributes['SID']; } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == 'true') ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) { if ($http_domain != $https_domain) { $_sid = session_name() . '=' . session_id(); } } } switch(true){ case (!isset($_SESSION['customer_id']) && defined('ENABLE_PAGE_CACHE') && ENABLE_PAGE_CACHE == 'true' && class_exists('page_cache')): $return = $link . $separator . '<zensid>'; break; case ($this->not_null($_sid)): $return = $link . $separator . $_sid; break; default: $return = $link; break; } # end switch return $return; } # end function /** * Function to parse the parameters into an SEO URL * @author Bobby Easland * @version 1.2 * @param string $page * @param string $params * @param string $separator NOTE: passed by reference * @return string */ function parse_parameters($page, $params, &$separator) { $p = @explode('&', $params); krsort($p); $container = array(); foreach ($p as $index => $valuepair){ $p2 = @explode('=', $valuepair); switch ($p2[0]){ case 'article_id': switch(true) { case ($page == FILENAME_NEWS_ARTICLE): $url = $this->make_url($page, 'news/' . $this->get_news_article_name($p2[1]), 'news_article_id', $p2[1], '.html', $separator); break; case ($page == FILENAME_NEWS_COMMENTS): $url = $this->make_url($page, 'news/' . $this->get_news_article_name($p2[1]), 'news_comments_article_id', $p2[1], '-comments.html', $separator); break; default: $container[$p2[0]] = $p2[1]; break; } break; case 'date': switch(true) { case ($page == FILENAME_NEWS_ARCHIVE): $url = $this->make_url($page, FILENAME_NEWS_INDEX, 'news_archive_dates', $p2[1], '.html', $separator); break; case ($page == FILENAME_NEWS_INDEX): $url = $this->make_url($page, FILENAME_NEWS_INDEX, 'news_dates', $p2[1], '.html', $separator); break; default: $container[$p2[0]] = $p2[1]; break; } break; case 'pages_id': switch(true) { case ($page == FILENAME_INFO_MANAGER): $url = $this->make_url($page, $this->get_info_manager_page_name($p2[1]), 'info_manager_page_id', $p2[1], '.html', $separator); break; default: $container[$p2[0]] = $p2[1]; break; } break; case 'products_id': switch(true) {// case ($page == FILENAME_PRODUCT_INFO && !$this->is_attribute_string($params)): case ($page == FILENAME_PRODUCT_INFO): $url = $this->make_url($page, $this->get_product_name($p2[1]), $p2[0], $p2[1], '.html', $separator); break; case ($page == FILENAME_PRODUCT_REVIEWS): $url = $this->make_url($page, $this->get_product_name($p2[1]), 'products_id_review', $p2[1], '.html', $separator); break; case ($page == FILENAME_PRODUCT_REVIEWS_INFO): $url = $this->make_url($page, $this->get_product_name($p2[1]), 'products_id_review_info', $p2[1], '.html', $separator); break; default: $container[$p2[0]] = $p2[1]; break; } # end switch break; case 'cPath': switch(true){ case ($page == FILENAME_DEFAULT): $url = $this->make_url($page, $this->get_category_name($p2[1]), $p2[0], $p2[1], '.html', $separator); break; case ($this->is_product_string($params)): if ($this->attributes['SEO_ADD_CPATH_TO_PRODUCT_URLS'] == 'true') { $container[$p2[0]] = $p2[1]; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -