Getting subcategory totals [shopp(‘subcategory’,’total’)] to work in Shopp Plugin 1.1.*

Problem: Pulling the total number of products from a subcat in Shopp doesn’t seem to work out the box. For example, this code WON’T return the total even though the correct tag shopp(‘subcategory’,’total’) is used: Continue reading “Getting subcategory totals [shopp(‘subcategory’,’total’)] to work in Shopp Plugin 1.1.*”

Capture last viewed category in product view in Shopp Plugin for WordPress

Problem: I’m using the Shopp 1.1.9 ecommerce plugin for WordPress, and my client wanted to display specific background images while showing certain products. Shopp is very complete, but one thing that is missing in the current version ‘out of the box’ is the ability to pull the ‘last viewed’ category name when viewing a product. Obviously a product can belong to more than one cat, so it can’t know which one to display… Continue reading “Capture last viewed category in product view in Shopp Plugin for WordPress”

What is Notice: unserialize() [function.unserialize]: Error at offset then?

Problem: While doing some Shopp Plugin support work earlier, one customer was getting this error…

Notice: unserialize() [function.unserialize]: Error at offset 111 of 118 bytes in /home/maxwell4/public_html/main/wp-content/plugins/shopp/core/model/Settings.php on line 228

Continue reading “What is Notice: unserialize() [function.unserialize]: Error at offset then?”

.htaccess hidden on Rackspace Cloud Sites (in FTP, with Filezilla)

Problem: When connecting to a Rackspace Cloud site via FTP, hidden files are.. uh.. hidden. Usually Filezilla shows everything.

Fix: There is a setting in Filezilla called ‘Force showing hidden files’ that does exactly that. To activate that, go to the ‘Server’ menu item and select it. Like this: Continue reading “.htaccess hidden on Rackspace Cloud Sites (in FTP, with Filezilla)”

Set date.timezone in PHP without using php.ini

Problem: I needed to set default timezone for a site to get Zen Cart installed. The usual way would be to call date_default_timezone_set from a globally included script, or to use the date.timezone option in a php.ini file. The problem is that I don’t have access to the php.ini file and there is no script that will be called across the board. Continue reading “Set date.timezone in PHP without using php.ini”

Add ‘Related Products’ to the Product Template in the Shopp WordPress Plugin

Problem: Today I needed to add some code to a Shopp (ver 1.1.9) product.php template so that related products (that have same ‘Tag’) would show up at the bottom. The ‘Related Products‘ template tag was not behaving as I expected it to.. i.e. it was stopping the product page rendering anything at all. Continue reading “Add ‘Related Products’ to the Product Template in the Shopp WordPress Plugin”

Launch Google Chrome Incognito from the terminal or a shortcut in OSX

Problem: Ok not really a problem, but I want to be able to launch Google Chrome straight to Incognito mode from a shortcut. This is useful when logging into multiple bank accounts, Google Apps accounts, or testing session based websites. etc etc etc.

Fix: Thankfully the Google can be launched with the –incognito switch to do just that. The terminal command to do this, assuming the browser is sitting in /Applications/ is this:

open -a /Applications/Google --args --incognito

Note: –args has to be passed to satisfy the ‘open’ command’s arguments first.

Launching it from a shortcut: If you want to create a shortcut to do this, open AppleScript Editor and enter the following:

tell application "Terminal"
	do script "open -a /Applications/Google\ --args --incognito;"
	delay 1
end tell

Note: The space in the Google name must be double-escaped with two backslashes like that to work. Also, without the delay I found that the script exits too quickly or something like that, and it doesn’t work.

Save the above script as an Application, and call it something like ‘Incognito’. Running this app will launch Terminal, Chrome Incognito, then exit Terminal. Bingo!

Giving your Incognito app an Icon: I’ve added the app to my Dock, and given it a special icon (see below for a downloadable PNG icon). To do this:

  • Open the image you want to use as the icon – it should be a 512×512 24bit PNG if possible – and copy the image to the clipboard. If you are using Preview to view the image, do cmd+a to select all, then cmd+c to copy it… this works for most other graphics packages also.
  • Locate the app you created above in Finder, then press cmd+i to bring up the info window (alternatively right-click the app then select ‘get info’).
  • In the resulting pop-up, click on the icon at the top to highlight it like so (notice the blue halo around it):
    Original Script Icon
  • Then use cmd+v to paste the new icon from the clopboard into the icon area and it should look like this:
    New Incognito icon
  • Close the info window, and it’s done. You should now have a nice looking shortcut that opens Chrome Incognito with one or two clicks!

Feel free to use this icon. It’s just the standard one with some ‘colour replace’ work to make it blue. You could paste some tacky sun glasses over it if you wished 🙂

Convert eregi_replace to preg_replace in old class.phpmailer.php scripts

Problem: I have lots of legacy php code on old sites that uses eregi_replace to format up an HTML email body. As eregi_replace is now depreciated it can be replaced with preg_replace. This is tricky sometimes because the formatting is quite different.

Fix: Here’s a common line from class.phpmailer.php scripts:

$emailBody = eregi_replace("[]",'',$emailBody);

To convert that you’ll need to do this:

$emailBody = preg_replace("/\\/", '', $emailBody);

Wondering why there are so MANY escaping backslashes there? I asked that question and got this answer:

“..the backslash needs to be escaped once for the php string’s benefit, then again for the interpretation of the regular expression engine, as escaped characters like d indicate a digit in regular expressions. So a pattern of \d would match a digit, but \\d would match a backslash then a d character. PHP strings are lenient on backslashing when it isn’t necessary, so:
– setting a string to “d” will give it a value of d (the same as setting it to “\d”).
– but setting it to “”” will give a value of “.
– and setting it to “” will return a syntax error.

– PHP double quoted strings will consume the (first) backslash for \ n t r and “.
– PHP single quoted strings will only consume the first backslash for \ and ‘ “

There.. clear as mud!