[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path Zen Cart 源代码 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 2011, Andrew Ballanger |
| |
| 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. |
+----------------------------------------------------------------------+
*/
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;
// START SEO_URLS_FILTER_PCRE PATCH
protected static $unicodeEnabled;
// END SEO_URLS_FILTER_PCRE PATCH
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'];
// 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;
// clean up the link before processing
while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);
while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);
case 'products_id':
switch(true) {
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;
// case ($page == FILENAME_PRODUCT_INFO && !$this->is_attribute_string($params)):
case ($page == FILENAME_PRODUCT_INFO):
case ($page == 'product_free_shipping_info'):
case ($page == 'product_music_info'):
case ($page == 'document_product_info'):
case ($page == 'document_general_info'): default:
$url = $this->make_url($page, $this->get_product_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
break;
} # end switch
break;
case 'cPath':
switch(true){
case ($page == FILENAME_DEFAULT):
/* START SEO-ADD-PRODUCT-CAT PATCH
*
* Patched to use SEO_ADD_PRODUCT_CAT
* This allows the use of a directory structure for urls.
* @author Andrew Ballanger
*/
if($this->attributes['SEO_ADD_PRODUCT_CAT'] == 'true')
{
// Retrieve the actual category id
$tmp = strrpos($p2[1], '_');
if($tmp !== false)
{
$p2[1] = substr($p2[1], $tmp+1);
}
$path = array();
$this->get_parent_categories_path($path, $p2[1]);
$url = $this->make_url($page, implode('/', $path), $p2[0], $p2[1], '/', $separator);
}
else
{
// END SEO-ADD-PRODUCT-CAT PATCH
$url = $this->make_url($page, $this->get_category_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
// START SEO-ADD-PRODUCT-CAT PATCH
}
// END SEO-ADD-PRODUCT-CAT PATCH
break;
case ($this->is_product_string($params)):
if ($this->attributes['SEO_ADD_CPATH_TO_PRODUCT_URLS'] == 'true') {
$container[$p2[0]] = $p2[1];
}
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;
case 'id': // EZ-Pages
switch(true){
case ($page == FILENAME_EZPAGES):
$url = $this->make_url($page, $this->get_ezpages_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':
// START SEO-ADD-PRODUCT-CAT PATCH
if($anchor_type == 'cPath' && $this->attributes['SEO_ADD_PRODUCT_CAT'] == 'true')
{
return $string . $extension;
}
// END SEO-ADD-PRODUCT-CAT PATCH
return $string . $this->reg_anchors[$anchor_type] . $id . $extension;
break;
default:
break;
} # end switch
} # end function
/**
* 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:
/* START SEO-ADD-PRODUCT-CAT PATCH
*
* Patched to use SEO_ADD_PRODUCT_CAT
* This allows the use of a directory structure for urls.
* @author Andrew Ballanger
*/
if($this->attributes['SEO_ADD_PRODUCT_CAT'] == 'true')
{
$sql = 'SELECT pd.products_name AS pName, ptc.categories_id AS c_id ' .
'FROM ' . TABLE_PRODUCTS_DESCRIPTION . ' AS pd ' .
'LEFT JOIN ' . TABLE_PRODUCTS . ' AS p ' .
'ON pd.products_id=p.products_id ' .
'LEFT JOIN ' . TABLE_PRODUCTS_TO_CATEGORIES . ' AS ptc ' .
'ON pd.products_id=ptc.products_id ' .
'WHERE pd.products_id=\'' . (int)$pID . '\' ' .
'AND language_id=\'' . (int)$this->languages_id . '\' LIMIT 1';
}
else
{
// END SEO-ADD-PRODUCT-CAT PATCH
$sql = 'SELECT pd.products_name as pName ' .
'FROM ' . TABLE_PRODUCTS_DESCRIPTION . ' pd ' .
'WHERE products_id=\'' . (int)$pID . '\' ' .
'AND language_id=\'' . (int)$this->languages_id . '\' LIMIT 1';
// START SEO-ADD-PRODUCT-CAT PATCH
}
// END SEO-ADD-PRODUCT-CAT PATCH
$result = $this->db->Execute($sql, false, true, 43200);
$pName = $this->strip($result->fields['pName']);
// START SEO-ADD-PRODUCT-CAT PATCH
if($this->attributes['SEO_ADD_PRODUCT_CAT'] == 'true')
{
$path = array();
$this->get_parent_categories_path($path, $result->fields['c_id']);
$pName = implode('/', $path) . '/' . $pName;
}
// END SEO-ADD-PRODUCT-CAT PATCH
$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, false, true, 43200);
$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, false, true, 43200);
$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, false, true, 43200);
$mName = $this->strip($result->fields['mName']);
$this->cache['MANUFACTURERS'][$mID] = $mName;
$return = $mName;
break;
} # end switch
return $return;
} # end function
/**
* Function to get the EZ-Pages name. Use evaluated cache, per page cache, or database query in that order of precedent.
* @author Bobby Easland, Ronald Crawford
* @version 1.0
* @param integer $mID
* @return string
*/
function get_ezpages_name($ezpID){
switch(true){
case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('EZPAGES_NAME_' . $ezpID)):
$return = constant('EZPAGES_NAME_' . $ezpID);
$this->cache['EZPAGES'][$ezpID] = $return;
break;
case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['EZPAGES'][$ezpID])):
$return = $this->cache['EZPAGES'][$ezpID];
break;
default:
// modified by zen-cart.cn
// $sql = "SELECT pages_title as ezpName
// FROM ".TABLE_EZPAGES."
// WHERE pages_id='".(int)$ezpID."'
// LIMIT 1";
$sql = "SELECT et.pages_title as ezpName
from " . TABLE_EZPAGES . " e, " . TABLE_EZPAGES_TEXT . " et
where e.pages_id='" . (int)$ezpID . "'
and e.pages_id = et.pages_id
and et.languages_id = '" . (int)$_SESSION['languages_id'] . "'
and status_sidebox = 1
and sidebox_sort_order > 0
LIMIT 1";
$result = $this->db->Execute($sql, false, true, 43200);
$ezpName = $this->strip($result->fields['ezpName']);
$this->cache['EZPAGES'][$ezpID] = $ezpName;
$return = $ezpName;
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->get_parent_categories_id($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 get_parent_categories_id(&$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;
// Recurse if the parent id is not empty or equal the passed categories id
if ($parent->fields['p_id'] != 0 && $parent->fields['p_id'] != $categories_id) {
$this->get_parent_categories_path($path, $parent->fields['p_id'], $cPath);
}
// Add category id to cPath and name to path
$cPath[sizeof($cPath)] = $categories_id;
$path[sizeof($path)] = $this->strip($parent->fields['name']) . '-c-' .
(sizeof($cPath) > 1 ? implode('_', $cPath) : $categories_id);
$parent->MoveNext();
}
}
// END SEO-ADD-PRODUCT-CAT PATCH
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 (original), Andrew Ballanger (PHP 5.x update)
* @version 1.2
* @param string $string
* @return string Stripped text. Removes all non-alphanumeric characters.
*/
function strip($string){
// START SEO_URLS_FILTER_PCRE PATCH
$retval = $string;
// First run PCRE filters over the string
if (is_array($this->attributes['SEO_URLS_FILTER_PCRE']))
{
$retval = preg_replace(
array_keys($this->attributes['SEO_URLS_FILTER_PCRE']),
array_values($this->attributes['SEO_URLS_FILTER_PCRE']),
$retval
);
}
// END SEO_URLS_FILTER_PCRE PATCH
// Next run Character Conversion Sets over the string
if (is_array($this->attributes['SEO_CHAR_CONVERT_SET'])) $retval = strtr($retval, $this->attributes['SEO_CHAR_CONVERT_SET']);
$pattern = '';
// Remove Special Characters from the strings
if($this->attributes['SEO_REMOVE_ALL_SPEC_CHARS'])
{
// Remove all non alphanumeric characters
if(!self::$unicodeEnabled) {
// POSIX named classes are not supported by preg_replace
$pattern = '/[^a-zA-Z0-9\s]/';
} else {
// Each language's alphabet.
$pattern = '/[^\p{L}\p{N}\s]/u';
}
}
else
{
// Remove all punctuation
if(!self::$unicodeEnabled) {
// POSIX named classes are not supported by preg_replace
$pattern = '/[!"#$%&\'()*+,\-.\/:;<=>?@[\\\]^_`{|}~\s]/';
} else {
// Each language's punctuation.
$pattern = '/[\p{P}\p{S}\s]/u';
}
}
return $this->short_name($retval); // 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
*/
// START SEO_URLS_FILTER_PCRE PATCH
function expand($set, $pcre = false){
// END SEO_URLS_FILTER_PCRE PATCH
if ( $this->not_null($set) ){
if ( $data = @explode(',', $set) ){
foreach ( $data as $index => $valuepair){
$p = @explode('=>', $valuepair);
// START SEO_URLS_FILTER_PCRE PATCH
if($pcre) $p[0] = '/' . $p[0] . '/';
// END SEO_URLS_FILTER_PCRE PATCH
$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);
}
}
}
/**
* Function to generate EZ-Pages cache entries
* @author Bobby Easland, Ronald Crawford
* @version 1.0
*/
function generate_ezpages_cache(){
$this->is_cached($this->cache_file . 'ezpages', $is_cached, $is_expired);
if ( !$is_cached || $is_expired ) {
// modified by zen-cart.cn
$sql = "SELECT e.pages_id as id, et.pages_title as name
FROM " . TABLE_EZPAGES . " e, " . TABLE_EZPAGES_TEXT . " et
WHERE e.pages_id = et.pages_id
and et.languages_id = '" . (int)$this->languages_id . "'
and status_sidebox = 1 and sidebox_sort_order > 0";
/**
* 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 ) {
/* START SEO-ADD-PRODUCT-CAT PATCH
*
* Patched to use SEO_ADD_PRODUCT_CAT
* This allows the use of a directory structure for urls.
* @author Andrew Ballanger
*/
$sql = 'SELECT p.products_id as id, ptc.categories_id as c_id, pd.products_name as name ' .
'FROM ' . TABLE_PRODUCTS . ' AS p ' .
'LEFT JOIN ' . TABLE_PRODUCTS_DESCRIPTION . ' AS pd ' .
'ON p.products_id=pd.products_id ' .
'LEFT JOIN ' . TABLE_PRODUCTS_TO_CATEGORIES . ' AS ptc ' .
'ON p.products_id=ptc.products_id ' .
'WHERE p.products_status=\'1\' ' .
'AND pd.language_id=\'' . (int)$this->languages_id . '\'';
// END SEO-ADD-PRODUCT-CAT PATCH
$product = $this->db->Execute($sql, false, true, 43200);
$prod_cache = '';
while (!$product->EOF) {
// START SEO-ADD-PRODUCT-CAT PATCH
$define = 'define(\'PRODUCT_NAME_' . $product->fields['id'] . '\', \'';
if($this->attributes['SEO_ADD_PRODUCT_CAT'] == 'true')
{
$path = array();
$this->get_parent_categories_path($path, $product->fields['c_id']);
$define .= implode('/', $path) . '/';
}
$define .= $this->strip($product->fields['name']) . '\');';
// END SEO-ADD-PRODUCT-CAT PATCH
$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, false, true, 43200);
$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){
/* START SEO-ADD-PRODUCT-CAT PATCH
*
* Patched to use SEO_ADD_PRODUCT_CAT
* This allows the use of a directory structure for urls.
* @author Andrew Ballanger
*/
// Disable SEO_ADD_CAT_PARENT if using the SEO-ADD-PRODUCT-CAT patch
case ($this->attributes['SEO-ADD-PRODUCT-CAT'] != 'true' && $this->attributes['SEO_ADD_CAT_PARENT'] == 'true'):
// END SEO-ADD-PRODUCT-CAT PATCH
$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, false, true, 43200);
$cat_cache = '';
while (!$category->EOF) {
// START SEO-ADD-PRODUCT-CAT PATCH
if($this->attributes['SEO_ADD_PRODUCT_CAT'] == 'true')
{
$path = array();
$this->get_parent_categories_path($path, $category->fields['id']);
$name = implode('/', $path) . '/' . $cName;
}
else
{
// END SEO-ADD-PRODUCT-CAT PATCH
$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'];
// START SEO-ADD-PRODUCT-CAT PATCH
}
// END SEO-ADD-PRODUCT-CAT PATCH
$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, false, true, 43200);
$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, false, true, 43200);
$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'){
global $queryCache;
// Fix for query_cache
$query = "SELECT cache_expires FROM " . TABLE_SEO_CACHE . " WHERE cache_id='".md5($name)."' AND cache_language_id='".(int)$this->languages_id."' LIMIT 1";
if(isset($queryCache) && $queryCache->inCache($query))
$queryCache->removeFromCache($query);
# unset the variables...clean as we go
unset($value, $expires, $sql_data_array, $query);
}# 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'], '/' );
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(",", preg_replace('/ +/', '', SEO_URLS_ONLY_IN ));
if ((SEO_URLS_ONLY_IN!="") && !in_array($_GET['main_page'],$sefu) ) $this->need_redirect = false;
// IMAGINADW.COM
/**
* 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';
}
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