📄 seo.url.php
字号:
}/** * Function to generate products cache entries * @author Bobby Easland * @version 1.0 */ function generate_products_cache(){ $this->is_cached($this->cache_file . 'products', $is_cached, $is_expired); if ( !$is_cached || $is_expired ) { $sql = "SELECT p.products_id as id, pd.products_name as name FROM ".TABLE_PRODUCTS." p LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd ON p.products_id=pd.products_id AND pd.language_id='".(int)$this->languages_id."' WHERE p.products_status='1'"; $product = $this->db->Execute($sql); $prod_cache = ''; while (!$product->EOF) { $define = 'define(\'PRODUCT_NAME_' . $product->fields['id'] . '\', \'' . $this->strip($product->fields['name']) . '\');'; $prod_cache .= $define . "\n"; eval("$define"); $product->MoveNext(); } $this->save_cache($this->cache_file . 'products', $prod_cache, 'EVAL', 1 , 1); unset($prod_cache); } else { $this->get_cache($this->cache_file . 'products'); } } # end function /** * Function to generate manufacturers cache entries * @author Bobby Easland * @version 1.0 */ function generate_manufacturers_cache(){ $this->is_cached($this->cache_file . 'manufacturers', $is_cached, $is_expired); if ( !$is_cached || $is_expired ) { // it's not cached so create it $sql = "SELECT m.manufacturers_id as id, m.manufacturers_name as name FROM ".TABLE_MANUFACTURERS." m LEFT JOIN ".TABLE_MANUFACTURERS_INFO." md ON m.manufacturers_id=md.manufacturers_id AND md.languages_id='".(int)$this->languages_id."'"; $manufacturers = $this->db->Execute($sql); $man_cache = ''; while (!$manufacturers->EOF) { $define = 'define(\'MANUFACTURER_NAME_' . $manufacturer->fields['id'] . '\', \'' . $this->strip($manufacturer->fields['name']) . '\');'; $man_cache .= $define . "\n"; eval("$define"); $manufacturers->MoveNext(); } $this->save_cache($this->cache_file . 'manufacturers', $man_cache, 'EVAL', 1 , 1); unset($man_cache); } else { $this->get_cache($this->cache_file . 'manufacturers'); } } # end function/** * Function to generate categories cache entries * @author Bobby Easland * @version 1.1 */ function generate_categories_cache(){ $this->is_cached($this->cache_file . 'categories', $is_cached, $is_expired); if ( !$is_cached || $is_expired ) { // it's not cached so create it switch(true){ case ($this->attributes['SEO_ADD_CAT_PARENT'] == 'true'): $sql = "SELECT c.categories_id as id, c.parent_id, cd.categories_name as cName, cd2.categories_name as pName FROM ".TABLE_CATEGORIES." c LEFT JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd2 ON c.parent_id=cd2.categories_id AND cd2.language_id='".(int)$this->languages_id."', ".TABLE_CATEGORIES_DESCRIPTION." cd WHERE c.categories_id=cd.categories_id AND cd.language_id='".(int)$this->languages_id."'"; //IMAGINADW.COM; break; default: $sql = "SELECT categories_id as id, categories_name as cName FROM ".TABLE_CATEGORIES_DESCRIPTION." WHERE language_id='".(int)$this->languages_id."'"; break; } # end switch $category = $this->db->Execute($sql); $cat_cache = ''; while (!$category->EOF) { $id = $this->get_full_cPath($category->fields['id'], $single_cID); $name = $this->not_null($category->fields['pName']) ? $category->fields['pName'] . ' ' . $category->fields['cName'] : $category->fields['cName']; $define = 'define(\'CATEGORY_NAME_' . $id . '\', \'' . $this->strip($name) . '\');'; $cat_cache .= $define . "\n"; eval("$define"); $category->MoveNext(); } $this->save_cache($this->cache_file . 'categories', $cat_cache, 'EVAL', 1 , 1); unset($cat_cache); } else { $this->get_cache($this->cache_file . 'categories'); } } # end function/** * Function to generate articles cache entries * @author Bobby Easland * @version 1.0 */ function generate_news_articles_cache(){ $this->is_cached($this->cache_file . 'news_articles', $is_cached, $is_expired); if ( !$is_cached || $is_expired ) { // it's not cached so create it $sql = "SELECT article_id as id, news_article_name as name FROM ".TABLE_NEWS_ARTICLES_TEXT." WHERE language_id = '".(int)$this->languages_id."'"; $article = $this->db->Execute($sql); $article_cache = ''; while (!$article->EOF) { $define = 'define(\'NEWS_ARTICLE_NAME_' . $article->fields['id'] . '\', \'' . $this->strip($article->fields['name']) . '\');'; $article_cache .= $define . "\n"; eval("$define"); $article->MoveNext(); } $this->save_cache($this->cache_file . 'news_articles', $article_cache, 'EVAL', 1 , 1); unset($article_cache); } else { $this->get_cache($this->cache_file . 'news_articles'); } } # end function/** * Function to generate information cache entries * @author Bobby Easland * @version 1.0 */ function generate_info_manager_cache(){ $this->is_cached($this->cache_file . 'info_manager', $is_cached, $is_expired); if ( !$is_cached || $is_expired ) { // it's not cached so create it $sql = "SELECT pages_id as id, pages_title as name FROM ".TABLE_INFO_MANAGER; $information = $this->db->Execute($sql); $information_cache = ''; while (!$information->EOF) { $define = 'define(\'INFO_MANAGER_PAGE_NAME_' . $information->fields['id'] . '\', \'' . $this->strip($information->fields['name']) . '\');'; $information_cache .= $define . "\n"; eval("$define"); $information->MoveNext(); } $this->save_cache($this->cache_file . 'info_manager', $information_cache, 'EVAL', 1 , 1); unset($information_cache); } else { $this->get_cache($this->cache_file . 'info_manager'); } } # end function/** * Function to save the cache to database * @author Bobby Easland * @version 1.0 * @param string $name Cache name * @param mixed $value Can be array, string, PHP code, or just about anything * @param string $method RETURN, ARRAY, EVAL * @param integer $gzip Enables compression * @param integer $global Sets whether cache record is global is scope * @param string $expires Sets the expiration */ function save_cache($name, $value, $method='RETURN', $gzip=1, $global=0, $expires = '30 days'){ $expires = date('Y-m-d H:i:s', strtotime('+' . $expires)); if ($method == 'ARRAY') $value = serialize($value); $value = ( $gzip === 1 ? base64_encode(gzdeflate($value, 1)) : addslashes($value) ); $sql_data_array = array( 'cache_id' => md5($name), 'cache_language_id' => (int)$this->languages_id, 'cache_name' => $name, 'cache_data' => $value, 'cache_global' => (int)$global, 'cache_gzip' => (int)$gzip, 'cache_method' => $method, 'cache_date' => date("Y-m-d H:i:s"), 'cache_expires' => $expires ); $this->is_cached($name, $is_cached, $is_expired); $cache_check = ( $is_cached ? 'true' : 'false' ); switch ( $cache_check ) { case 'true': zen_db_perform(TABLE_SEO_CACHE, $sql_data_array, 'update', "cache_id='".md5($name)."'"); break; case 'false': zen_db_perform(TABLE_SEO_CACHE, $sql_data_array, 'insert'); break; default: break; } # end switch ($cache check) # unset the variables...clean as we go unset($value, $expires, $sql_data_array); }# end function save_cache() /** * Function to get cache entry * @author Bobby Easland * @version 1.0 * @param string $name * @param boolean $local_memory * @return mixed */ function get_cache($name = 'GLOBAL', $local_memory = false){ $select_list = 'cache_id, cache_language_id, cache_name, cache_data, cache_global, cache_gzip, cache_method, cache_date, cache_expires'; $global = ( $name == 'GLOBAL' ? true : false ); // was GLOBAL passed or is using the default? switch($name){ case 'GLOBAL': $cache = $this->db->Execute("SELECT ".$select_list." FROM " . TABLE_SEO_CACHE . " WHERE cache_language_id='".(int)$this->languages_id."' AND cache_global='1'"); break; default: $cache = $this->db->Execute("SELECT ".$select_list." FROM " . TABLE_SEO_CACHE . " WHERE cache_id='".md5($name)."' AND cache_language_id='".(int)$this->languages_id."'"); break; } $num_rows = $cache->RecordCount(); if ($num_rows){ $container = array(); while(!$cache->EOF){ $cache_name = $cache->fields['cache_name']; if ( $cache->fields['cache_expires'] > date("Y-m-d H:i:s") ) { $cache_data = ( $cache->fields['cache_gzip'] == 1 ? gzinflate(base64_decode($cache->fields['cache_data'])) : stripslashes($cache->fields['cache_data']) ); switch($cache->fields['cache_method']){ case 'EVAL': // must be PHP code eval("$cache_data"); break; case 'ARRAY': $cache_data = unserialize($cache_data); case 'RETURN': default: break; } # end switch ($cache['cache_method']) if ($global) $container['GLOBAL'][$cache_name] = $cache_data; else $container[$cache_name] = $cache_data; // not global } else { // cache is expired if ($global) $container['GLOBAL'][$cache_name] = false; else $container[$cache_name] = false; }# end if ( $cache['cache_expires'] > date("Y-m-d H:i:s") ) if ( $this->keep_in_memory || $local_memory ) { if ($global) $this->data['GLOBAL'][$cache_name] = $container['GLOBAL'][$cache_name]; else $this->data[$cache_name] = $container[$cache_name]; } $cache->MoveNext(); } # end while ($cache = $this->DB->FetchArray($this->cache_query)) unset($cache_data); switch (true) { case ($num_rows == 1): if ($global){ if ($container['GLOBAL'][$cache_name] == false || !isset($container['GLOBAL'][$cache_name])) return false; else return $container['GLOBAL'][$cache_name]; } else { // not global if ($container[$cache_name] == false || !isset($container[$cache_name])) return false; else return $container[$cache_name]; } # end if ($global) case ($num_rows > 1): default: return $container; break; }# end switch (true) } else { return false; }# end if ( $num_rows ) } # end function get_cache()/** * Function to get cache from memory * @author Bobby Easland * @version 1.0 * @param string $name * @param string $method * @return mixed */ function get_cache_memory($name, $method = 'RETURN'){ $data = ( isset($this->data['GLOBAL'][$name]) ? $this->data['GLOBAL'][$name] : $this->data[$name] ); if ( isset($data) && !empty($data) && $data != false ){ switch($method){ case 'EVAL': // data must be PHP eval("$data"); return true; break; case 'ARRAY': case 'RETURN': default: return $data; break; } # end switch ($method) } else { return false; } # end if (isset($data) && !empty($data) && $data != false) } # end function get_cache_memory()/** * Function to perform basic garbage collection for database cache system * @author Bobby Easland * @version 1.0 */ function cache_gc(){ $this->db->Execute("DELETE FROM " . TABLE_SEO_CACHE . " WHERE cache_expires <= '" . date("Y-m-d H:i:s") . "'"); }/** * Function to check if the cache is in the database and expired * @author Bobby Easland * @version 1.0 * @param string $name * @param boolean $is_cached NOTE: passed by reference * @param boolean $is_expired NOTE: passed by reference */ function is_cached($name, &$is_cached, &$is_expired){ // NOTE: $is_cached and $is_expired is passed by reference !! $this->cache_query = $this->db->Execute("SELECT cache_expires FROM " . TABLE_SEO_CACHE . " WHERE cache_id='".md5($name)."' AND cache_language_id='".(int)$this->languages_id."' LIMIT 1"); $is_cached = ( $this->cache_query->RecordCount() > 0 ? true : false ); if ($is_cached){ $is_expired = ( $this->cache_query->fields['cache_expires'] <= date("Y-m-d H:i:s") ? true : false ); unset($check); } }# end function is_cached()/** * Function to initialize the redirect logic * @author Bobby Easland * @version 1.1 */ function check_redirect(){ $this->need_redirect = false; $this->uri = ltrim( basename($_SERVER['REQUEST_URI']), '/' ); $this->real_uri = ltrim( basename($_SERVER['SCRIPT_NAME']) . '?' . $_SERVER['QUERY_STRING'], '/' ); // damn zen cart attributes use illegal url characters if ($this->is_attribute_string($this->uri)) { $parsed_url = parse_url($this->uri); $this->uri_parsed = parse_url($parsed_url['scheme']); $this->uri_parsed['query'] = preg_replace('/products_id=([0-9]+)/', 'products_id=$1:' . $parsed_url['path'], $this->uri_parsed['query']); } else { $this->uri_parsed = parse_url($this->uri); } $this->attributes['SEO_REDIRECT']['URI'] = $this->uri; $this->attributes['SEO_REDIRECT']['REAL_URI'] = $this->real_uri; $this->attributes['SEO_REDIRECT']['URI_PARSED'] = $this->uri_parsed; $this->need_redirect(); $this->check_seo_page(); if ($this->need_redirect && $this->is_seopage && $this->attributes['USE_SEO_REDIRECT'] == 'true') { $this->do_redirect(); } } # end function /** * Function to check if the URL needs to be redirected * @author Bobby Easland * @version 1.2 */ function need_redirect() { $this->need_redirect = ((preg_match('/main_page=/i', $this->uri)) ? true : false); // QUICK AND DIRTY WAY TO DISABLE REDIRECTS ON PAGES WHEN SEO_URLS_ONLY_IN is enabled IMAGINADW.COM $sefu = explode(",", ereg_replace( ' +', '', SEO_URLS_ONLY_IN )); if ((SEO_URLS_ONLY_IN!="") && !in_array($_GET['main_page'],$sefu) ) $this->need_redirect = false; // IMAGINADW.COM $this->attributes['SEO_REDIRECT']['NEED_REDIRECT'] = $this->need_redirect ? 'true' : 'false'; } /** * Function to check if it's a valid redirect page * @author Bobby Easland * @version 1.1 */ function check_seo_page() { if (!isset($_GET['main_page']) || (!$this->not_null($_GET['main_page']))) { $_GET['main_page'] = 'index'; } $this->is_seopage = (($this->attributes['SEO_ENABLED'] == 'true') ? true : false); $this->attributes['SEO_REDIRECT']['IS_SEOPAGE'] = $this->is_seopage ? 'true' : 'false'; } /** * Function to perform redirect * @author Bobby Easland * @version 1.0 */ function do_redirect() { $p = @explode('&', $this->uri_parsed['query']); foreach( $p as $index => $value ) { $tmp = @explode('=', $value); if ($tmp[0] == 'main_page') continue; switch($tmp[0]){ case 'products_id': if ($this->is_attribute_string('products_id=' . $tmp[1])) { $pieces = explode(':', $tmp[1]); $params[] = $tmp[0] . '=' . $pieces[0]; } else { $params[] = $tmp[0] . '=' . $tmp[1]; } break; default: $params[] = $tmp[0].'='.$tmp[1]; break; } } # end foreach( $params as $var => $value ) $params = ( sizeof($params) > 1 ? implode('&', $params) : $params[0] ); $url = $this->href_link($_GET['main_page'], $params, 'NONSSL', false); // cleanup url for redirection $url = str_replace('&', '&', $url); switch($this->attributes['USE_SEO_REDIRECT']){ case 'true': header("HTTP/1.1 301 Moved Permanently"); header("Location: $url"); break; default: $this->attributes['SEO_REDIRECT']['REDIRECT_URL'] = $url; break; } # end switch } # end function do_redirect} # end class?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -