📄 seo.url.php
字号:
break; default: $container[$p2[0]] = $p2[1]; break; } # end switch break; case 'manufacturers_id': switch(true){ case ($page == FILENAME_DEFAULT && !$this->is_cPath_string($params) && !$this->is_product_string($params)): $url = $this->make_url($page, $this->get_manufacturer_name($p2[1]), $p2[0], $p2[1], '.html', $separator); break; case ($page == FILENAME_PRODUCT_INFO): break; default: $container[$p2[0]] = $p2[1]; break; } # end switch break; case 'pID': switch(true){ case ($page == FILENAME_POPUP_IMAGE): $url = $this->make_url($page, $this->get_product_name($p2[1]), $p2[0], $p2[1], '.html', $separator); break; default: $container[$p2[0]] = $p2[1]; break; } # end switch break; default: $container[$p2[0]] = $p2[1]; break; } # end switch } # end foreach $p $url = isset($url) ? $url : $page; if ( sizeof($container) > 0 ){ if ( $imploded_params = $this->implode_assoc($container) ){ $url .= $separator . $this->output_string( $imploded_params ); $separator = '&'; } } return $url; } # end function/** * Function to return the generated SEO URL * @author Bobby Easland * @version 1.0 * @param string $page * @param string $string Stripped, formed anchor * @param string $anchor_type Parameter type (products_id, cPath, etc.) * @param integer $id * @param string $extension Default = .html * @param string $separator NOTE: passed by reference * @return string */ function make_url($page, $string, $anchor_type, $id, $extension = '.html', &$separator){ // Right now there is but one rewrite method since cName was dropped // In the future there will be additional methods here in the switch switch ( $this->attributes['SEO_REWRITE_TYPE'] ){ case 'Rewrite': return $string . $this->reg_anchors[$anchor_type] . $id . $extension; break; default: break; } # end switch } # end function function get_info_manager_page_name($pages_id) { switch(true){ case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('INFO_MANAGER_PAGE_NAME_' . $pages_id)): $return = constant('INFO_MANAGER_PAGE_NAME_' . $pages_id); $this->cache['INFO_MANAGER_PAGES'][$pages_id] = $return; break; case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['INFO_MANAGER_PAGES'][$pages_id])): $return = $this->cache['INFO_MANAGER_PAGES'][$pages_id]; break; default: $sql = "SELECT pages_title FROM " . TABLE_INFO_MANAGER . " WHERE pages_id = " . (int)$pages_id . " LIMIT 1"; $result = $this->db->Execute($sql); $pages_title = $this->strip($result->fields['pages_title']); $this->cache['INFO_MANAGER_PAGES'][$pages_id] = $pages_title; $return = $pages_title; break; } return $return; } function get_news_article_name($article_id) { switch(true){ case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('NEWS_ARTICLE_NAME_' . $article_id)): $return = constant('NEWS_ARTICLE_NAME_' . $article_id); $this->cache['NEWS_ARTICLES'][$article_id] = $return; break; case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['NEWS_ARTICLES'][$article_id])): $return = $this->cache['NEWS_ARTICLES'][$article_id]; break; default: $sql = "SELECT news_article_name FROM " . TABLE_NEWS_ARTICLES_TEXT . " WHERE article_id = " . (int)$article_id . " AND language_id = " . (int)$this->languages_id . " LIMIT 1"; $result = $this->db->Execute($sql); $news_article_name = $this->strip($result->fields['news_article_name']); $this->cache['NEWS_ARTICLES'][$article_id] = $news_article_name; $return = $news_article_name; break; } return $return; }/** * Function to get the product name. Use evaluated cache, per page cache, or database query in that order of precedent * @author Bobby Easland * @version 1.1 * @param integer $pID * @return string Stripped anchor text */ function get_product_name($pID){ switch(true){ case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('PRODUCT_NAME_' . $pID)): $return = constant('PRODUCT_NAME_' . $pID); $this->cache['PRODUCTS'][$pID] = $return; break; case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['PRODUCTS'][$pID])): $return = $this->cache['PRODUCTS'][$pID]; break; default: $sql = "SELECT products_name as pName FROM " . TABLE_PRODUCTS_DESCRIPTION . " WHERE products_id = " . (int)$pID . " AND language_id = " . (int)$this->languages_id . " LIMIT 1"; $result = $this->db->Execute($sql); $pName = $this->strip($result->fields['pName']); $this->cache['PRODUCTS'][$pID] = $pName; $return = $pName; break; } # end switch return $return; } # end function /** * Function to get the category name. Use evaluated cache, per page cache, or database query in that order of precedent * @author Bobby Easland * @version 1.1 * @param integer $cID NOTE: passed by reference * @return string Stripped anchor text */ function get_category_name(&$cID){ $full_cPath = $this->get_full_cPath($cID, $single_cID); // full cPath needed for uniformity switch(true){ case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('CATEGORY_NAME_' . $full_cPath)): $return = constant('CATEGORY_NAME_' . $full_cPath); $this->cache['CATEGORIES'][$full_cPath] = $return; break; case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['CATEGORIES'][$full_cPath])): $return = $this->cache['CATEGORIES'][$full_cPath]; break; default: switch(true){ case ($this->attributes['SEO_ADD_CAT_PARENT'] == 'true'): $sql = "SELECT c.categories_id, c.parent_id, cd.categories_name as cName, cd2.categories_name as pName FROM ".TABLE_CATEGORIES_DESCRIPTION." cd, ".TABLE_CATEGORIES." c LEFT JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd2 ON c.parent_id=cd2.categories_id AND cd2.language_id='".(int)$this->languages_id."' WHERE c.categories_id='".(int)$single_cID."' AND cd.categories_id='".(int)$single_cID."' AND cd.language_id='".(int)$this->languages_id."' LIMIT 1"; $result = $this->db->Execute($sql); $cName = $this->not_null($result->fields['pName']) ? $result->fields['pName'] . ' ' . $result->fields['cName'] : $result->fields['cName']; break; default: $sql = "SELECT categories_name as cName FROM ".TABLE_CATEGORIES_DESCRIPTION." WHERE categories_id='".(int)$single_cID."' AND language_id='".(int)$this->languages_id."' LIMIT 1"; $result = $this->db->Execute($sql); $cName = $result->fields['cName']; break; } $cName = $this->strip($cName); $this->cache['CATEGORIES'][$full_cPath] = $cName; $return = $cName; break; } # end switch $cID = $full_cPath; return $return; } # end function/** * Function to get the manufacturer name. Use evaluated cache, per page cache, or database query in that order of precedent. * @author Bobby Easland * @version 1.1 * @param integer $mID * @return string */ function get_manufacturer_name($mID){ switch(true){ case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('MANUFACTURER_NAME_' . $mID)): $return = constant('MANUFACTURER_NAME_' . $mID); $this->cache['MANUFACTURERS'][$mID] = $return; break; case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['MANUFACTURERS'][$mID])): $return = $this->cache['MANUFACTURERS'][$mID]; break; default: $sql = "SELECT manufacturers_name as mName FROM ".TABLE_MANUFACTURERS." WHERE manufacturers_id='".(int)$mID."' LIMIT 1"; $result = $this->db->Execute($sql); $mName = $this->strip($result->fields['mName']); $this->cache['MANUFACTURERS'][$mID] = $mName; $return = $mName; break; } # end switch return $return; } # end function/** * Function to retrieve full cPath from category ID * @author Bobby Easland * @version 1.1 * @param mixed $cID Could contain cPath or single category_id * @param integer $original Single category_id passed back by reference * @return string Full cPath string */ function get_full_cPath($cID, &$original){ if ( is_numeric(strpos($cID, '_')) ){ $temp = @explode('_', $cID); $original = $temp[sizeof($temp)-1]; return $cID; } else { $c = array(); $this->GetParentCategories($c, $cID); $c = array_reverse($c); $c[] = $cID; $original = $cID; $cID = sizeof($c) > 1 ? implode('_', $c) : $cID; return $cID; } } # end function/** * Recursion function to retrieve parent categories from category ID * @author Bobby Easland * @version 1.0 * @param mixed $categories Passed by reference * @param integer $categories_id */ function GetParentCategories(&$categories, $categories_id) { $sql = "SELECT parent_id FROM " . TABLE_CATEGORIES . " WHERE categories_id = " . (int)$categories_id; $parent_categories = $this->db->Execute($sql); while (!$parent_categories->EOF) { if ($parent_categories->fields['parent_id'] == 0) return true; $categories[sizeof($categories)] = $parent_categories->fields['parent_id']; if ($parent_categories->fields['parent_id'] != $categories_id) { $this->GetParentCategories($categories, $parent_categories->fields['parent_id']); } $parent_categories->MoveNext(); } } function not_null($value) { return zen_not_null($value); } function is_attribute_string($params){ if (preg_match('/products_id=([0-9]+):([a-zA-z0-9]{32})/', $params)) { return true; } return false; } function is_product_string($params) { if (preg_match('/products_id=/i', $params)) { return true; } return false; } function is_cPath_string($params) { if (preg_match('/cPath=/i', $params)) { return true; } return false; } /** * Function to strip the string of punctuation and white space * @author Bobby Easland * @version 1.1 * @param string $string * @return string Stripped text. Removes all non-alphanumeric characters. */ function strip($string){ if ( is_array($this->attributes['SEO_CHAR_CONVERT_SET']) ) $string = strtr($string, $this->attributes['SEO_CHAR_CONVERT_SET']); $pattern = $this->attributes['SEO_REMOVE_ALL_SPEC_CHARS'] == 'true' ? "([^[:alnum:]])+" : "([[:punct:]])+"; $anchor = ereg_replace($pattern, '', GBcase($string,"lower")); // modified by zen-cart.cn $pattern = "([[:space:]]|[[:blank:]])+"; $anchor = ereg_replace($pattern, '-', $anchor); return $this->short_name($anchor); // return the short filtered name } # end function/** * Function to expand the SEO_CONVERT_SET group * @author Bobby Easland * @version 1.0 * @param string $set * @return mixed */ function expand($set){ if ( $this->not_null($set) ){ if ( $data = @explode(',', $set) ){ foreach ( $data as $index => $valuepair){ $p = @explode('=>', $valuepair); $container[trim($p[0])] = trim($p[1]); } return $container; } else { return 'false'; } } else { return 'false'; } } # end function/** * Function to return the short word filtered string * @author Bobby Easland * @version 1.0 * @param string $str * @param integer $limit * @return string Short word filtered */ function short_name($str, $limit=3){ if ( $this->attributes['SEO_URLS_FILTER_SHORT_WORDS'] != 'false' ) $limit = (int)$this->attributes['SEO_URLS_FILTER_SHORT_WORDS']; $foo = @explode('-', $str); foreach($foo as $index => $value){ switch (true){ case ( strlen($value) <= $limit ): continue; default: $container[] = $value; break; } } # end foreach $container = ( sizeof($container) > 1 ? implode('-', $container) : $str ); return $container; } /** * Function to implode an associative array * @author Bobby Easland * @version 1.0 * @param array $array Associative data array * @param string $inner_glue * @param string $outer_glue * @return string */ function implode_assoc($array, $inner_glue='=', $outer_glue='&') { $output = array(); foreach( $array as $key => $item ){ if ( $this->not_null($key) && $this->not_null($item) ){ $output[] = $key . $inner_glue . $item; } } # end foreach return @implode($outer_glue, $output); }/** * Function to translate a string * @author Bobby Easland * @version 1.0 * @param string $data String to be translated * @param array $parse Array of tarnslation variables * @return string */ function parse_input_field_data($data, $parse) { return strtr(trim($data), $parse); } /** * Function to output a translated or sanitized string * @author Bobby Easland * @version 1.0 * @param string $sting String to be output * @param mixed $translate Array of translation characters * @param boolean $protected Switch for htemlspecialchars processing * @return string */ function output_string($string, $translate = false, $protected = false) { if ($protected == true) { return htmlspecialchars($string); } else { if ($translate == false) { return $this->parse_input_field_data($string, array('"' => '"')); } else { return $this->parse_input_field_data($string, $translate); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -