X-Cart 4.5 and a CDN / Cookieless Static Domain


Written by

So today I was working on a site based on xcart 4.5 with an aim to speed up page load times. I had previously migrated all the background images into CSS base64 encoded data to save on the number of requests and file sizes etc.

Part of x-carts SEO tools and optimisation is that it will combine all CSS files into one but while it does that, it craftily rewrites specific parts mainly so URLs are correct which plays havoc with base64 encoded CSS images as it attempts to rewrite it all, so this file needs to be separate and defined manually in the template via the <link /> tag and not with the load_defer() function.

Anyway in regards to using a cookie-less Static domain or a Content Delivery Network for CSS, Javascripts, Images etc then you need to do some minor rewriting of x-cart.

Firstly, you need to setup your domain and relevant services to have the correct resources and the domain to work. I was using apache and included the following lines in the vhosts.

RequestHeader unset Cookie    
Header unset Set-Cookie

Which removes any cookies on that domain.

Once the domain is all setup and ready then we have to edit x-cart a little, I’ll try and write this as simply as possible.

Edit /smarty.php

approx. line 92
from:

$smarty->assign('AltImagesDir', $alt_skin_info['web_path'].'/images');
$smarty->assign('AltSkinDir', $alt_skin_info['web_path']);

to:

if ($_SERVER['HTTPS'] != 'on') {
    $smarty->assign('AltImagesDir', "http://cdn.domain.tld".$alt_skin_info['web_path'].'/images');
    $smarty->assign('AltSkinDir', "http://cdn.domain.tld".$alt_skin_info['web_path']);
} else {
    $smarty->assign('AltImagesDir', $alt_skin_info['web_path'].'/images');
    $smarty->assign('AltSkinDir', $alt_skin_info['web_path']);
}

and approx. line 107
from:

$smarty->assign('ImagesDir', $xcart_web_dir.$smarty_skin_dir.'/images');
$smarty->assign('SkinDir', $xcart_web_dir.$smarty_skin_dir);

to:

if ($_SERVER['HTTPS'] != 'on') {
    $smarty->assign('ImagesDir', "http://cdn.domain.tld".$smarty_skin_dir.'/images');
    $smarty->assign('SkinDir', "http://cdn.domain.tld".$smarty_skin_dir);
} else {
    $smarty->assign('ImagesDir', $xcart_web_dir.$smarty_skin_dir.'/images');
    $smarty->assign('SkinDir', $xcart_web_dir.$smarty_skin_dir);
}

then edit: /include/template/plugins/function.load_defer_code.php

at approx. line 111
from:

$cacheWebFile = $var_dirs_web['cache'].'/'.$label.'.'.$md5Suffix.'.'.$type;

to:

if ($_SERVER['HTTPS'] != 'on') {
    $cacheWebFile = "http://cdn.domain.tld/var/cache".'/' .$label.'.'.$md5Suffix.'.'.$type;
} else {
    $cacheWebFile = $var_dirs_web['cache'].'/'.$label.'.'.$md5Suffix.'.'.$type;
}

We have to check for SSL so we don’t get certificate errors and alerts about unencrypted content. There isn’t much information in regards to x-cart 4.5 and CDN’s but there’s a snippet on the wiki about it in older versions.

 

Responsive Websites and Static Headers


Written by

So one of the websites I am developing has a static header, there are a few examples of this being used such as Next; the issue comes, when you require lots of information in this header but use a responsive layout, the header is then taking up real estate for your main content (even more so in landscape mode).

So this is where hiding the less vital information such as the company logo and search could come in useful; so I developed a small hacky jquery base script to do this. It isn’t perfect and it’s my first serious javascript on this site so please be kind!

The script hides a div on scroll and displays another to allow you to have a small “show div” button available at all times. if then shows and hides when the display is resizes to a desktop resolution.

Have a go of the demo and feel free to steal the code; if you find any better ways of doing it then don’t hesitate to contact me.

Small yet Functional Conky


Written by

Here’s my small but functional conky config (conkyrc).

It displays:

  • Battery
  • CPU Utilisation
  • RAM Utilisation
  • SWAP Utilisation
  • Hard Drive Usage
  • eth0 and wlan0 stats
  • Public IP
  • Wireless Info
  • Clock

Some bits you might want to change according to your distro.

######################
# - Conky settings - #
######################
update_interval 2
total_run_times 0
net_avg_samples 1
cpu_avg_samples 2

imlib_cache_size 0
double_buffer yes
no_buffers yes

format_human_readable

#####################
# - Text settings - #
#####################
use_xft yes
xftfont Droid Sans:size=8
override_utf8_locale yes
text_buffer_size 2048

#############################
# - Window specifications - #
#############################
own_window_class Conky
own_window yes
own_window_type normal
own_window_transparent yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

alignment top_right
gap_y 40
gap_x 20
border_inner_margin 8

minimum_size 180 300
maximum_width 180
maximum_height 460

default_bar_size 92 6

#########################
# - Graphics settings - #
#########################
draw_shades no
default_shade_color 000000
default_color FFFFFF

TEXT
${font Droid Sans:style=Bold:size=8}DEBIAN LINUX $hr${font}
##############
# -   OS       - #
##############
${voffset 5}${font OpenLogos:size=35}J${font}${goto 45}${voffset -30}Name:  ${alignr}${nodename}
${goto 45}OS: ${alignr}Debian Wheezy
${goto 45}Kernel: ${alignr}${kernel}
${goto 45}Uptime: ${alignr}${uptime}
${voffset 8}${font Droid Sans:style=Bold:size=8}SYSTEM $hr${font}
##############
# - SYSTEM - #
##############
# |--SWAP
${voffset 5}${font Droid Sans:style=Bold:size=8}BATT${font}${goto 45}Rem: ${font Droid Sans:style=Bold:size=8}${battery_percent BAT0}%${font} ${alignr}${battery_bar 7,70 BAT0}
${goto 45}Status: ${font Droid Sans:style=Bold:size=8}${battery BAT0}${font}
# |--CPU
${voffset 6}${font Droid Sans:style=Bold:size=8}CPU${font}${offset -20}${goto 45}Core 1: ${font Droid Sans:style=Bold:size=8}${cpu cpu1}%${font} ${alignr}${cpubar cpu2 7,70 EEEEEE}
${goto 45}Core 2: ${font Droid Sans:style=Bold:size=8}${cpu cpu2}%${font} ${alignr}${cpubar cpu2 7,70 EEEEEE}
# |--MEM
${voffset 6}${font Droid Sans:style=Bold:size=8}RAM${font}${goto 45}RAM: ${font Droid Sans:style=Bold:size=8}$memperc%${font} ${alignr}${membar 7,70}
${goto 45}Free: ${font Droid Sans:style=Bold:size=8}${memeasyfree}${font} ${goto 115}Used: ${font Droid Sans:style=Bold:size=8}${mem}${font}
# |--HDD
${voffset 6}${font Droid Sans:style=Bold:size=8}HDD${font}${goto 45}/: ${font Droid Sans:style=Bold:size=8}${fs_used_perc /}%${font} ${alignr}${fs_bar 7,70 /}
${goto 45}Free: ${font Droid Sans:style=Bold:size=8}${fs_free /}${font} ${goto 115}Used: ${font Droid Sans:style=Bold:size=8}${fs_used /}${font}
# |--SWAP
${voffset 5}${font Droid Sans:style=Bold:size=8}SWAP${font}${goto 45}Swap: ${font Droid Sans:style=Bold:size=8}${swapperc}%${font} ${alignr}${swapbar 7,70}
${goto 45}Free: ${font Droid Sans:style=Bold:size=8}$swapmax${font} ${goto 115}Used: ${font Droid Sans:style=Bold:size=8}$swap${font}
###############
# - NETWORK - #
###############
${voffset 8}${font Droid Sans:style=Bold:size=8}NETWORK $hr${font}
${voffset 5}${font Droid Sans:style=Bold:size=8}Public${font}${goto 45}Addr:${goto 85}${font Droid Sans:style=Bold:size=8}${execi 240 curl http://automation.whatismyip.com/n09230945.asp}${font}
${if_existing /proc/net/route wlan0}${voffset 5}${font Droid Sans:style=Bold:size=8}waln0${font}${goto 45}Addr:${goto 85}${font Droid Sans:style=Bold:size=8}${addr wlan0}${font}
${goto 45}Down:${goto 85}${font Droid Sans:style=Bold:size=8}${downspeed wlan0}${font}${alignr}${downspeedgraph wlan0 8,50 EEEEEE}
${goto 45}Up:${goto 85}${font Droid Sans:style=Bold:size=8}${upspeed wlan0}${font}${alignr}${upspeedgraph wlan0 8,50 EEEEEE}
${goto 45}Total:${goto 85}${font Droid Sans:style=Bold:size=8}${totaldown wlan0}${font} / ${font Droid Sans:style=Bold:size=8}${totalup wlan0}${font}${else}${font Droid Sans:style=Bold:size=8}wlan0${font}${goto 45}Not Conencted${endif}
${if_existing /proc/net/route eth0}${voffset 5}${font Droid Sans:style=Bold:size=8}eth0${font}${goto 45}Addr:${goto 85}${font Droid Sans:style=Bold:size=8}${addr eth0}${font}
${goto 45}Down:${goto 85}${font Droid Sans:style=Bold:size=8}${downspeed eth0}${font}${alignr}${downspeedgraph eth0 8,50 EEEEEE}
${goto 45}Up:${goto 85}${font Droid Sans:style=Bold:size=8}${upspeed eth0}${font}${alignr}${upspeedgraph eth0 8,50 EEEEEE}
${goto 45}Total:${goto 85}${font Droid Sans:style=Bold:size=8}${totaldown eth0}${font} / ${font Droid Sans:style=Bold:size=8}${totalup eth0}${font}${else}${font Droid Sans:style=Bold:size=8}eth0${font}${goto 45}Not Connected${endif}
${if_existing /proc/net/route wlan0}${voffset 8}${font Droid Sans:style=Bold:size=8}WIRELESS $hr${font}
${voffset 5}${goto 45}Int:${goto 85}${font Droid Sans:style=Bold:size=8}wlan0${font}
${goto 45}SSID:${goto 85}${font Droid Sans:style=Bold:size=8}${wireless_essid wlan0}${font}
${goto 45}Speed:${goto 85}${font Droid Sans:style=Bold:size=8}${wireless_bitrate wlan0}${font}
${goto 45}Signal:${goto 85}${font Droid Sans:style=Bold:size=8}${wireless_link_qual_perc wlan0}%${font}${alignr}${wireless_link_bar 7,70 wlan0}${endif}
#############
# - CLOCK - #
#############
${voffset 8}${font Droid Sans:style=Bold:size=8}CLOCK $hr${font}
${font Droid Sans:size=20}${alignc}${time %l:%M %p}${font}
${alignc}${time %d %B %Y}

It requires openlogos font too for the debian/distro logo and curl for the public ip. The initial script isn’t mine; it’s just oen I found and them modified.

Updates and Newness…


Written by

So this afternoon, I decided to upload and release my latest function mailattch. This function takes php’s mail to a whole new level, allowing files to be attached!

There are currently limitations to it and it isn’t highly tested but everyone is welcome to use it and is release under GPL v3.

I have also pushed a little update to ldir. It’s nothing big, just a shameless link back to here; if you really don’t like it then you’re free to remove it from the function source or you can hide is with CSS via display: none; on the class .ldir_link.

That’s all for now.

ldir 1.7.10 Released


Written by

After reading through ldir’s latest release I found a few bugs which have now been fixed in ldir 1.7.10.

I’ve also rewritten the icon file type check, so we assume some common file types are available and then add any new ones to the array on that call, so if that type is found again in that folder, the icon is already known. All in all resulting in a considerably faster speed for listing the same file types or common files.

There are more extensions supported than listed but I chose not to include them all but you can if you wish.

I will also be looking at overhauling the icons and providing them as a pack allowing you to self host which at the moment isn’t possible due to licesning issue.

Version 1.7.10

  • Speed optimisations
  • Rewrote icon checking
  • Added supported common icons list
  • Suppressed header() / ob_flush() calls
  • Fixed ‘parent folder’ link not working