16
Mods & Plugins (Releases & Support) / Re: [MOD] Google Friendly Urls For 4images Best Seo Mod
« on: December 04, 2013, 09:04:22 AM »Since we are on optimizing rage today, little more optimized nic_bck's version:Code: [Select]function fixname($text)
{
return strtolower(strtr(
$text,
array(
"é" => "e",
"è" => "e",
"ê" => "e",
"à" => "a",
"ë" => "e",
"â" => "a",
"ú" => "a",
"ó" => "o",
"í" => "i",
"á" => "a",
//russian UTF8 encoded alphabet (lower and upper cases)
"А" => "a",
"а" => "a",
"Б" => "b",
"б" => "b",
"В" => "v",
"в" => "v",
"Г" => "g",
"г" => "g",
"Д" => "d",
"д" => "d",
"Е" => "e",
"е" => "e",
"Ё" => "yo",
"ё" => "yo",
"Ж" => "zh",
"ж" => "zh",
"З" => "z",
"з" => "z",
"И" => "i",
"и" => "i",
"Й" => "j",
"й" => "j",
"К" => "k",
"к" => "k",
"Л" => "l",
"л" => "l",
"М" => "m",
"м" => "m",
"Н" => "n",
"н" => "n",
"О" => "o",
"о" => "o",
"П" => "p",
"п" => "p",
"Р" => "r",
"р" => "r",
"С" => "s",
"с" => "s",
"Т" => "t",
"т" => "t",
"У" => "u",
"у" => "u",
"Ф" => "f",
"ф" => "f",
"Х" => "h",
"х" => "h",
"Ц" => "c",
"ц" => "c",
"Ч" => "ch",
"ч" => "ch",
"Ш" => "sh",
"ш" => "sh",
"Щ" => "sch",
"щ" => "sch",
"Ъ" => "",
"ъ" => "",
"Ы" => "i",
"ы" => "i",
"Ь" => "'",
"ь" => "'",
"Э" => "e",
"э" => "e",
"Ю" => "yu",
"ю" => "yu",
"Я" => "ya",
"я" => "ya",
)));
}
function get_category_url($cat_id,$cat_url = '')
{
global $site_db, $cat_cache;
static $urlname = array(); //cache names in this array
if (isset($urlname[$cat_id]))
return $urlname[$cat_id];
if (!empty($cat_cache))
{
$row['cat_name'] = @$cat_cache[$cat_id]['cat_name'];
$row['cat_parent_id'] = @$cat_cache[$cat_id]['cat_parent_id'];
}
else
{
$sql = "SELECT cat_name,cat_parent_id FROM ".CATEGORIES_TABLE." WHERE cat_id = '".$cat_id."'";
$row = $site_db->query_firstrow($sql);
}
$row['cat_name'] = fixname($row['cat_name']);
$cat_url = '-'.str_replace('+','-',urlencode($row['cat_name'])).'-'.$cat_id.$cat_url;
// if you want full path of category in url, put next line in comment
$row['cat_parent_id'] = 0;
if($row['cat_parent_id'] != 0)
{
$urlname[$cat_id] = get_category_url($row['cat_parent_id'],$cat_url);
}
else
{
$urlname[$cat_id] = $cat_url;
}
return $urlname[$cat_id];
}
//Mod_bmollet
/**
* Get the image url
* @param int $image_id The id of the image
*/
function get_image_url($image_id)
{
global $site_db;
static $urlname = array(); //cache names in this array
if (isset($urlname[$image_id]))
return $urlname[$image_id];
$sql = "SELECT cat_id,image_name FROM ".IMAGES_TABLE." WHERE image_id = '".$image_id."'";
$row = $site_db->query_firstrow($sql);
$row['image_name'] = fixname($row['image_name']);
// if you want comlpete path to image in url, remove comment from following line
//$urlname[$image_id] = get_category_url($row['cat_id']).'-'.str_replace('+','-',urlencode($row['image_name'])).'-'.$image_id;
$urlname[$image_id] = '-'.str_replace('+','-',urlencode($row['image_name'])).'-'.$image_id;
return $urlname[$image_id];
}
Results:
index.php
OriginalCode: [Select]Page generated in 0.109686 seconds with 36 queries, spending 0.059000 seconds doing MySQL queries and 0.050686 doing PHP things. GZIP compression disabled
OptimizedCode: [Select]Page generated in 0.095068 seconds with 11 queries, spending 0.059000 seconds doing MySQL queries and 0.036068 doing PHP things. GZIP compression disabled
categories.php (30 images per page)
Original:Code: [Select]Page generated in 0.227558 seconds with 195 queries, spending 0.051000 seconds doing MySQL queries and 0.176558 doing PHP things. GZIP compression disabled
Optimized:Code: [Select]Page generated in 0.179981 seconds with 37 queries, spending 0.050000 seconds doing MySQL queries and 0.129981 doing PHP things. GZIP compression disabled
details.php
OriginalCode: [Select]Page generated in 0.219341 seconds with 22 queries, spending 0.110000 seconds doing MySQL queries and 0.109341 doing PHP things. GZIP compression disabled
OptimizedCode: [Select]Page generated in 0.060998 seconds with 14 queries, spending 0.028000 seconds doing MySQL queries and 0.032998 doing PHP things. GZIP compression disabled
Many thanks V@no for this great optimization'!!'
