285 lines
8.8 KiB
PHP
285 lines
8.8 KiB
PHP
<?php
|
|
/*
|
|
+--------------------------------------------------------------------------
|
|
| CubeCart 4
|
|
| ========================================
|
|
| CubeCart is a registered trade mark of Devellion Limited
|
|
| Copyright Devellion Limited 2006. All rights reserved.
|
|
| Devellion Limited,
|
|
| 5 Bridge Street,
|
|
| Bishops Stortford,
|
|
| HERTFORDSHIRE.
|
|
| CM23 2JU
|
|
| UNITED KINGDOM
|
|
| http://www.devellion.com
|
|
| UK Private Limited Company No. 5323904
|
|
| ========================================
|
|
| Web: http://www.cubecart.com
|
|
| Email: info (at) cubecart (dot) com
|
|
| License Type: CubeCart is NOT Open Source Software and Limitations Apply
|
|
| Licence Info: http://www.cubecart.com/site/faq/license.php
|
|
+--------------------------------------------------------------------------
|
|
| sef_urls.inc.php
|
|
| ========================================
|
|
| Search Engine Friendly URL's
|
|
+--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|
|
LookBack: All self-contained
|
|
LookBack + ForceType: Needs the .htaccess RewriteRule file
|
|
|
|
*/
|
|
|
|
function sef_script_name() {
|
|
# Define the 'script' name for lookback requests
|
|
global $config;
|
|
return (!empty($config['sefscriptname'])) ? $config['sefscriptname'] : 'index';
|
|
}
|
|
|
|
function sef_get_base_url() {
|
|
global $config;
|
|
|
|
switch ($config['sefserverconfig']) {
|
|
case 1:
|
|
case 2:
|
|
## LookBack
|
|
return sef_script_name() . '.php/';
|
|
break;
|
|
default:
|
|
## Mod_Rewrite
|
|
return '';
|
|
}
|
|
}
|
|
|
|
function generateQueryStr($query) {
|
|
## check if there is an ampersand first otherwise just return the same string
|
|
if (!empty($query)) {
|
|
if (preg_match('#^(\&\;|\&)(.*)$#i', $query, $matches)) {
|
|
if (strlen($matches[2]) > 0) return '?'.$matches[2];
|
|
}
|
|
return '?'.$query;
|
|
}
|
|
}
|
|
|
|
function generateSafeUrls($url = '') {
|
|
## normalize accented characters
|
|
$url = strtr($url, "\xA1\xAA\xBA\xBF\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD\xE0\xE1\xE2\xE3\xE5\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF", "_ao_AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy");
|
|
## further character processing
|
|
$url = strtr($url, array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe", "\xDC"=>"Ue", "\xDE"=>"TH", "\xDF"=>"ss", "\xE4"=>"ae", "\xE6"=>"ae", "\xF6"=>"oe", "\xFC"=>"ue", "\xFE"=>"th"));
|
|
## make sure its only english and dashes
|
|
$search = array("/[^a-zA-Z0-9\/]/", "/--+/");
|
|
$replace = array("-", "-");
|
|
$url = preg_replace($search, $replace, $url);
|
|
## return safe url
|
|
return($url);
|
|
}
|
|
|
|
|
|
function generateCategoryUrl($catid) {
|
|
global $glob, $db, $config, $lang_folder;
|
|
|
|
$sefpre = ($config['sefserverconfig'] == 0 || $config['sefserverconfig'] == 3) ? 'cat_' : 'c_';
|
|
$ext = ($config['sefserverconfig'] == 3) ? '.php' : '.html';
|
|
|
|
if (is_numeric($catid)) {
|
|
$query = "SELECT cat_name, cat_id, cat_father_id FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_id='".$catid."'";
|
|
$sef_categories = $db->select($query);
|
|
$prevDirSymbol = $config['dirSymbol'];
|
|
$config['dirSymbol'] = '/';
|
|
$prevLang = $lang_folder;
|
|
$lang_folder = $config['defaultLang'];
|
|
$cat = getCatDir($sef_categories[0]['cat_name'], $sef_categories[0]['cat_father_id'], $sef_categories[0]['cat_id'], FALSE, TRUE);
|
|
$config['dirSymbol'] = $prevDirSymbol;
|
|
$lang_folder = $prevLang;
|
|
$cat = generateSafeUrls($cat);
|
|
$cat = strtolower($cat) . "/". $sefpre . $catid . $ext;
|
|
} else {
|
|
$cat = generateSafeUrls();
|
|
$cat = strtolower($cat) . $sefpre . $catid . $ext;
|
|
}
|
|
return $cat;
|
|
}
|
|
|
|
function generateProductUrl($productid) {
|
|
global $glob, $db, $config, $lang_folder;
|
|
|
|
//"SELECT productId, name, cat_name, ".$glob['dbprefix']."CubeCart_inventory.cat_id, cat_father_id FROM ".$glob['dbprefix']."CubeCart_inventory INNER JOIN ".$glob['dbprefix']."CubeCart_category ON ".$glob['dbprefix']."CubeCart_inventory.cat_id = ".$glob['dbprefix']."CubeCart_category.cat_id WHERE productId='".$productid."'";
|
|
|
|
$query = sprintf("SELECT productId, name, cat_name, %1\$sCubeCart_inventory.cat_id, cat_father_id FROM %1\$sCubeCart_inventory INNER JOIN %1\$sCubeCart_category ON %1\$sCubeCart_inventory.cat_id = %1\$sCubeCart_category.cat_id WHERE productId='%2\$d'", $glob['dbprefix'], $productid);
|
|
$sef_products = $db->select($query);
|
|
|
|
$sefpre = ($config['sefserverconfig'] == 0 || $config['sefserverconfig'] == 3) ? 'prod_' : 'p_';
|
|
$ext = ($config['sefserverconfig'] == 3) ? '.php' : '.html';
|
|
|
|
$prevDirSymbol = $config['dirSymbol'];
|
|
$config['dirSymbol'] = '/';
|
|
|
|
$prevLang = $lang_folder;
|
|
$lang_folder = $config['defaultLang'];
|
|
|
|
#if ($config['seo_custom_urls']) {
|
|
# $prod = generateSafeUrls($sef_products[0]['seo_custom_url']);
|
|
#} else {
|
|
$prod = getCatDir($sef_products[0]['cat_name'], $sef_products[0]['cat_father_id'], $sef_products[0]['cat_id'], false, true) . '/'.$sef_products[0]['name'];
|
|
#}
|
|
|
|
$config['dirSymbol'] = $prevDirSymbol;
|
|
$lang_folder = $prevLang;
|
|
|
|
return strtolower(generateSafeUrls($prod).'/'.$sefpre.$productid.$ext);
|
|
}
|
|
|
|
|
|
function generateDocumentUrl($docid) {
|
|
global $glob, $db, $config;
|
|
|
|
$query = "SELECT doc_name FROM ".$glob['dbprefix']."CubeCart_docs WHERE doc_id='".$docid."'";
|
|
$sef_documents = $db->select($query);
|
|
|
|
$sefpre = ($config['sefserverconfig'] == 0 || $config['sefserverconfig'] == 3) ? 'info_' : 'i_';
|
|
$ext = ($config['sefserverconfig'] == 3) ? '.php' : '.html';
|
|
|
|
$doc = $sef_documents[0]['doc_name'];
|
|
if (strlen($doc) > 0) {
|
|
$doc = generateSafeUrls($doc).'/';
|
|
}
|
|
$doc = $doc . $sefpre . $docid . $ext;
|
|
|
|
return strtolower($doc);
|
|
}
|
|
|
|
function generateTellFriendUrl($docid) {
|
|
global $glob, $db, $config;
|
|
|
|
$sefpre = ($config['sefserverconfig'] == 0 || $config['sefserverconfig'] == 3) ? 'tell_' : 't_';
|
|
$ext = ($config['sefserverconfig'] == 3) ? '.php' : '.html';
|
|
|
|
$doc = generateSafeUrls('tellafriend'). "/" . $sefpre . $docid . $ext;
|
|
|
|
return strtolower($doc);
|
|
}
|
|
|
|
function sef_rewrite_urls($page) {
|
|
global $config, $glob;
|
|
|
|
if ($config['sef'] == true) {
|
|
$indexscript = sef_get_base_url();
|
|
|
|
$store_url = (detectSSL()) ? $config['storeURL_SSL'] : $glob['storeURL'];
|
|
|
|
$search = array(
|
|
'#href=[\"\'][a-z/]*index\.php\?_a=(viewcat|viewprod|tellafriend|viewdoc)\&?(amp;)[a-z]+=([0-9]+)?([^\"\']*)[\"\']#ie',
|
|
|
|
# '#(action|background|href|src|value)\=([\"\'])(index.php|(?![a-z]+:|/|\"|\'|\#|\?))([^\'\"]*)([\"\'])#i',
|
|
'#(\"|\')(index\.php)#i',
|
|
'#(href|src|action|background)\=([\"\'])(?![a-z]+:|/|\"|\'|\#|\?)([^\'\"]*)([\"\'])#i',
|
|
);
|
|
$replace = array(
|
|
'"href=\"".$indexscript.generateXurl(\'$3\', \'$1\').generateQueryStr(\'$4\')."\""',
|
|
|
|
# '$1=$2'.$GLOBALS['rootRel'].'$3$4$5',
|
|
'$1'.$store_url.'/$2',
|
|
'$1=$2'.$store_url.'/$3$4',
|
|
);
|
|
$page = preg_replace($search, $replace, $page);
|
|
## preg_match_all?
|
|
}
|
|
return $page;
|
|
}
|
|
|
|
function generateXurl($id, $type) {
|
|
switch (strtolower($type)) {
|
|
case 'viewcat':
|
|
return generateCategoryUrl($id);
|
|
break;
|
|
case 'viewdoc':
|
|
return generateDocumentUrl($id);
|
|
break;
|
|
case 'viewprod':
|
|
return generateProductUrl($id);
|
|
break;
|
|
case 'tellafriend':
|
|
return generateTellFriendUrl($id);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
function sefHtmlWalk(&$input, $key) {
|
|
$input = htmlspecialchars($input, ENT_COMPAT, 'UTF-8');
|
|
}
|
|
|
|
|
|
function sefMetaTitle($glue = ' - ') {
|
|
global $config, $meta;
|
|
|
|
if ($config['seftags'] == false) {
|
|
$title[] = $meta['siteTitle'];
|
|
|
|
} else {
|
|
|
|
$seftitle = '';
|
|
|
|
if ($config['seftags'] == true) {
|
|
## Combine
|
|
if (!empty($meta['sefSiteTitle'])) $title[] = $meta['sefSiteTitle'];
|
|
if (!empty($meta['siteTitle'])) $title[] = $meta['siteTitle'];
|
|
|
|
} else if ($config['seftags'] == 2) {
|
|
## Override
|
|
if (!empty($meta['sefSiteTitle'])) {
|
|
$title[] = $meta['sefSiteTitle'];
|
|
} else {
|
|
if (!empty($meta['siteTitle'])) {
|
|
$title[] = $meta['siteTitle'];
|
|
}
|
|
}
|
|
}
|
|
if (!empty($config['siteTitle'])) $title[] = $config['siteTitle'];
|
|
//array_walk($title, 'sefHtmlWalk');
|
|
}
|
|
return implode($glue, $title);
|
|
}
|
|
|
|
function sefMetaDesc() {
|
|
global $config, $meta;
|
|
|
|
if ($config['seftags'] == false) {
|
|
$sefdesc = $meta['metaDescription'];
|
|
} else if ($config['seftags'] == true) {
|
|
$sefdesc = $meta['sefSiteDesc'];
|
|
|
|
if (strlen($sefdesc) > 0 && strlen($meta['metaDescription']) > 0) {
|
|
$sefdesc = $sefdesc . " - ";
|
|
}
|
|
$sefdesc = $sefdesc . $meta['metaDescription'];
|
|
|
|
} else {
|
|
$sefdesc = (strlen($sefdesc) == 0) ? $meta['metaDescription'] : $meta['sefSiteDesc'];
|
|
}
|
|
return $sefdesc;
|
|
}
|
|
|
|
|
|
function sefMetaKeywords() {
|
|
global $config, $meta;
|
|
|
|
if ($config['seftags'] == false) {
|
|
$sefkeywords = $config['metaKeyWords'];
|
|
|
|
} else if ($config['seftags'] == true) {
|
|
$sefkeywords = $meta['sefSiteKeywords'];
|
|
|
|
if (strlen($sefkeywords ) > 0 && strlen($config['metaKeyWords']) > 0) {
|
|
$sefkeywords = $sefkeywords.",";
|
|
}
|
|
$sefkeywords = $sefkeywords.$config['metaKeyWords'];
|
|
|
|
} else {
|
|
$sefkeywords = (strlen($sefkeywords) == 0) ? $sefkeywords = $config['metaKeyWords'] : $meta['sefSiteKeywords'];
|
|
}
|
|
return $sefkeywords;
|
|
}
|
|
?>
|