Thread: MAX cdn
View Single Post
  #57  
Old 01-17-2013, 06:43 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: MAX cdn

Here is my list of MaxCDN edits for my 4.5.4 store.
I have the X-Cart Banner mod, and these images MUST live in the file system for MaxCDN.
This is a collection of edits as contributed by many others here -- but here is what I am using, all in one post...
Hope this helps someone the way other posts here have helped me.

Setting Up MaxCDN -- make a CNAME record in cPanel to simplify the URL and make it looks like: cdn.domain.com (as opposed to companyname.companyname.netdna-cdn.com)

http://cp3support.netdna.com/tutorials/create-cname/

1. file: /smarty.php

FIND:
PHP Code:
$smarty->assign('ImagesDir',        $xcart_web_dir $smarty_skin_dir '/images');
$smarty->assign('SkinDir',          $xcart_web_dir $smarty_skin_dir); 

REPLACE WITH:
PHP Code:
// MaxCDN - next two lines commented out
//$smarty->assign('ImagesDir',        $xcart_web_dir . $smarty_skin_dir . '/images');
//$smarty->assign('SkinDir',          $xcart_web_dir . $smarty_skin_dir);
// MaxCDN add the following
if ($_SERVER['HTTPS'] != 'on'

$smarty->assign('ImagesDir',    "http://cdn.domain.com" $smarty_skin_dir '/images'); 
$smarty->assign('SkinDir',        "http://cdn.domain.com" $smarty_skin_dir); 
$smarty->assign("AltImagesDir",    "http://cdn.domain.com/skin/books_and_magazines/images"); 
$smarty->assign("AltSkinDir",    "http://cdn.domain.com/skin/books_and_magazines"); 

else 

$smarty->assign('ImagesDir',        $xcart_web_dir $smarty_skin_dir '/images'); 
$smarty->assign('SkinDir',          $xcart_web_dir $smarty_skin_dir); 
}  
// END MaxCDN edit 
----------

note:
a) change "cdn.domain.com" to your cdn.domain.com
b) change /skin/books_and_magazines/ to your skin -- if you use "3-columns" - the path would be /skin/3-columns/ etc...

==================================
2. For css and js code

file: /include/templater/plugins/function.load_defer_code.php

FIND:
PHP Code:
$result = ('js' == $type)
            ? 
'<script type="text/javascript" src="' $cacheWebFile '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' $cacheWebFile '" />'

REPLACE WITH:
PHP Code:
// COMMENT OUT next 3 lines for MaxCDN //
/*        
            $result = ('js' == $type)
            ? '<script type="text/javascript" src="' . $cacheWebFile . '"></script>'
            : '<link rel="stylesheet" type="text/css" href="' . $cacheWebFile . '" />';
*/            
// INSERT for MaxCDN
if ($_SERVER['HTTPS'] != 'on') {
$result = ('js' == $type)
            ? 
'<script type="text/javascript" src="' str_replace("www.domain.com","cdn.domain.com",$cacheWebFile) . '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' str_replace("www.domain.com","cdn.domain.com",$cacheWebFile) . '" />';
} else {
        
$result = ('js' == $type)
            ? 
'<script type="text/javascript" src="' $cacheWebFile '"></script>'
            
'<link rel="stylesheet" type="text/css" href="' $cacheWebFile '" />';
}
// END insert for MaxCDN 

==================================
3. FOR CATEGORY IMAGES

file: /include/templater/plugins/function.get_category_image_url.php

FIND:
Code:
return func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path']));
REPLACE WITH:
Code:
return str_replace("www.domain.com","cdn.domain.com",func_convert_amp(func_get_image_url($category['categoryid'], 'C', $category['image_path'])));

==================================
4. FOR IMAGES (W, D, P, T images in file system)

file: /include/func/func.files.php

FIND:
Code:
$current_location = $current_location;

REPLACE WITH:
PHP Code:
/** MaxCDN support */
if ($_SERVER['HTTPS'] != 'on') {
$current_location $current_location
} else {
$current_location 'http://cdn.domain.com';
}
/* END MaxCDN support */ 
==================================
5. FOR X-CART BANNER SYSTEM (A images in file system)

FILE:
/skin/common_files/modules/Banner_System/banner_rotator.tpl

FIND:
Code:
src="{$content.image_path|amp}"

REPLACE WITH:
Code:
src="{$content.image_path|amp|replace:'www.domain.com':'cdn.domain.com'}"

ADDED on Jan 18
6. FOR T images -- I think this is needed too

file:
/common_files/product_thumbnail.tpl

FIND:
Code:
{$tmbn_url|amp}
REPLACE WITH:
Code:
{* MaxCDN edit - comment out next line *} {* {$tmbn_url|amp} *} {if $smarty.server.HTTPS ne "on"} {$tmbn_url|amp|replace:'www.domain.com':'cdn.domain.com'} {else} {$tmbn_url|amp} {/if} {* END MaxCDN edit *}

ADDED on Feb 21
7. FOR IMAGES (W, D, P, T images in file system)

I noticed that some variant images were not getting to the CDN. SO I tried using the code suggested by Phil in post #58 - this seems to work, and is probably a brute force solution. Don't know if I can remove #4?

file: /include/func/func.files.php

FIND:

PHP Code:
// image_path is an locally placed image
            
return $current_location str_replace(XC_DS'/'substr($image_pathstrlen(preg_replace('/' preg_quote(XC_DS'/') . '$/S'''$xcart_dir)))); 

REPLACE WITH:
PHP Code:
// image_path is an locally placed image
            
return 'http://cdn.domain.com' str_replace(XC_DS'/'substr($image_pathstrlen(preg_replace('/' preg_quote(XC_DS'/') . '$/S'''$xcart_dir)))); 

This seems to be doing the trick...
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote