Facebook Web/Mobile Promotion


Share your fight with your friends and receive a gift voucher. Users can send via email or Facebook. Facebook users experience open graph actions such as “Shared a feit” or “Claimed a gift”. Responsive design means this works on several different platforms. Here is a sneak preview of the Desktop, Mobile and Email version of the promotion:


Codeigniter Bootstrap .htaccess for github, apple-touch-icons, humans.txt, robots.txt and more…

# max filesize and post size overrides
php_value upload_max_filesize 100M
php_value post_max_size 100M

# MediaTemple force php5
AddHandler php5-script .php

# Rewrites for codeigniter
RewriteEngine on
RewriteCond $1 !^(github\.php|index\.php|CI210|uploads|images|javascripts|email|stylesheets|humans\.txt|robots\.txt|README|apple-touch-icon-114x114\.png|apple-touch-icon-57x57\.png|apple-touch-icon-72×72\.png|apple-touch-icon-precomposed\.png|apple-touch-icon\.png|favicon\.png|thumbnail_image\.png)
RewriteRule ^(.*)$ index.php/$1 [L]

Codeigniter Unserialize Error

Here is safe way of unserializing a string into PHP object when you encounter the dreaded error .

* mixed safe_unserialize(string $serialized)
* Safely unserialize, that is only unserialize string, numbers and arrays, not objects
* @license Public Domain
* @author dcz (at) phpbb-seo (dot) com
function safe_unserialize($serialized) {
    // unserialize will return false for object declared with small cap o
    // as well as if there is any ws between O and :
    if (is_string($serialized) && strpos($serialized, "\0") === false) {
        if (strpos($serialized, 'O:') === false) {
            // the easy case, nothing to worry about
            // let unserialize do the job
            return @unserialize($serialized);
        } else if (!preg_match('/(^|;|{|})O:[0-9]+:"/', $serialized)) {
            // in case we did have a string with O: in it,
            // but it was not a true serialized object
            return @unserialize($serialized);
    return false;

URL2PNG Library for Codeigniter

Creating screenshots on the fly is fly. Here is an example in action.

Here is a simple plugin for using the URL2PNG service in Codeigniter.

First create a config file at config/url2png.php:

$config['url2png_apikey'] = 'put your api key here'; 
$config['url2png_secret'] = 'put your secret key here';
$config['url2png_size'] = '300x300'; // w x h in pixels 

Then create a library file at libraries/Url2png.php:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 * Url2png API integration.
 * @package    CodeigniterUrl2png
 * @author     Ronny EW
class Url2png {

    var $url2pngurl; // the api url
    var $apikey; // from url2png
    var $secretkey; // from url2png
    var $size; // something like 300x300
     * Connect to Url2PNG and display or save an image.
    public function Url2png() {
	// Get CI Instance
	$this->CI = &get_instance();
        $this->apikey = $this->CI->config->item('url2png_apikey');
        $this->secretkey = $this->CI->config->item('url2png_secret');
        $this->size = $this->CI->config->item('url2png_size');
        $this->url2pngurl = "http://api.url2png.com/v3/";

	* Get the actual url to call from url2png
	* @param url
	* @param size (e.g. 300x300)
	function geturl($url = "",$size = "")
		if (trim($size) == "") { $size = $this->size; }
		if (trim($url) == "") { return false; }
		$url = str_replace('%','%25',$url);
		$url = str_replace(' ','%20',$url);
		$url = str_replace('&','%26',$url);
		$url = str_replace('#','%23',$url);
		$url = str_replace('?','%3F',$url);
		$token = md5($this->secretkey."+$url");
		return $this->url2pngurl.$this->apikey."/".$token."/".$size."/".$url;
	* Display an image with image tags
	* @param url
	* @param size (e.g. 300x300)
	function display_image($url = "",$size = "")
		$src = $this->geturl($url,$size);
		$img_tag = ($src) ? sprintf('<img src="%s" title="%s">', $src, $url) : false;
		return $img_tag;
	* Generate an image and save it to disk
	* @param url
	* @param fullpath (e.g. /join/images/12345.png)
	* @param size (e.g. 300x300)
	function save_image($url = "", $size = "", $fullpath = ""){
		// get the image path
		$img = $this->geturl($url,$size);
		if ($img)
			$ch = curl_init ($img);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
			curl_close ($ch);
			$fp = fopen($fullpath,'w+');
			fwrite($fp, $rawdata);
				return $fullpath;
		return false;



Then add this code to your controller construct:


Then use this method in the controller to generate the HTML required to display a thumbnail:

$url is a valid URL
$size is the image dimensions (e.g. 300x300)

E.G. $this->url2png->display_image("http://www.google.com","300x300");

Use this method to return the URL (without HTML):


Use this method to save it to your server drive:

$this->url2png->save_image($url, $size, $fullpath);
$fullpath is the path and name of file you want to save it as (e.g. /images/1234.png)

Service Oriented Open Source E-commerce

What you need:

  1. Services
    1. DynDNS
      1. Domain name registration
      2. Custom DNS
      3. SSL
    2. Google Apps
    3. Dropbox
    4. Google Analytics
    5. Google Webmaster Tools
    6. Github
    7. Browsercam
    8. Mailchimp
    9. Australian bank account with Merchant Facility
    10. Payment Methods
      1. eway (Australian payment gateway for on site, credit cards, debit cards, bank transfers)
      2. Paypal merchant account
      3. Google Checkout merchant account
  2. Hosting Platform
    1. 1 x Amazon LAMP server
    2. 2 x Amazon S3 buckets (One for remote backup and the other as a CDN serving static files)
  3. Frameworks
    1. Paypal’s Magento Go Hosted shopping cart platform
    2. PHP MVC Framework Codeigniter
    3. AWSPHPSDK (Amazon Web Services PHP SDK)
    4. HTML5, CSS3, JQuery
  4. Development Platform
    1. VirtualBox VM running OpenSolaris Linux, MySQL, PHP, OpenSSL (same as Joyent SmartMachine)
    2. PHPUnit
    3. Phing build automation
    4. Seige load testing
    5. Git version control
    6. Cross-browser testing available via remote-access to various OS/Browser/Mobile combinations using Browsercam or Mailchimp’s Mailbox Inspector program

What you can do:

  1. Google Apps Single Sign-on for administrators of Mailchimp, Google Analytics, DynDNS, Dropbox
  2. Social affiliate application with Codeigniter, Google Apps, Facebook, Twitter, Magento and Google Analytics
  3. User submitted content microsite with HTML5 audio/video, Codeigniter, Mailchimp and Google Analytics, AWS S3
  4. HTML5 Location-based SMS Promotion with Magento, Mailchimp, Google Maps and Google Analytics
  5. A/B Testing for Email and Landing Page Campaigns with Google Analytics, Webmaster Tools, Magento and Mailchimp
  6. 360 E-commerce Campaign Reporting with Mailchimp, Magento and Google Analytics
  7. Production Forecasting and Product-Level ROI Reporting Tool with Codeigniter, Magento, Google Apps Spreadsheet and Google Analytics
  8. Share source graphics and other files with 3rd-parties using Dropbox
  9. Daily remote database and file back-up on Amazon S3
  10. Automated user testing on daily or weekly builds using PHPUnit
  11. Salvage unsubscribes by creating web-hooks in Mailchimp using Codeigniter/Magento.
  12. Everytime a person forwards an email to a friend, add credit to the Magento customer account using the API.
  13. Then create another web hook that sends an email to that person if they remove themselves from the mailing list saying that you’re sorry to see them go because they will loose the credit they earned previously. Then allow them to click a link to reinstate their subscription and recover their credit with a special offer. Situation averted.

Codeigniter and the Mailchimp Export API v1.0

The Mailchimp Export API is a useful tool when you want to sync data sources. You use it to download dump of all your subscriber data.

First set up your Mailchimp API for Codeginiter.

Now, add a new config variable to your /config/mcapi.php file.

$config['mcapi_exporturl'] = 'http://us2.api.mailchimp.com/export/1.0/list'; 

To find out what your Mailchimp server center is. Get this by looking at the URL you see when you login:

Mailchimp address

Create a database table to store our data locally. We’ll only use the email address and serialised data for now, but you could do something more fancy using field headers.

CREATE TABLE `mailchimpcache` (
  `id` int(11) NOT NULL auto_increment,
  `email` varchar(255) NOT NULL,
  `extra` text NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `email` (`email`)

Create a model called “mailexport” as follows:

class Mailexport extends Model {
	function __construct()

	* Get a dump of Mailchimp subscribers
	* @param array $params
	*                - $status 	
	*                	        optional – the status to get members for - one of (subscribed, unsubscribed, cleaned), 
	*                           defaults to subscribed
	*                - $segment 	
	*                	        optional – pull only a certain Segment of your list. For help with what this array 
	*                	        should contain: see $campaignSegmentTest(). It's also suggested 
	*                	        that you test your options against campaignSegmentTest().
	*                - $since 	
	*                	        optional – only return member whose data has changed since a GMT timestamp – in YYYY-MM-
	*                	        DD HH:mm:ss format 
	*               Example:
	*               $params = array(
	*              					'status' => "",	
	*               				'segment' => "",	
	*               				'since' => "",
	*               				);
	* @returns array 
	*                - error
	*                	        "failed to access url" indicates an error with url
	*                	        "yes" indicates a Mailchimp error like "Invalid API Key", see the $obj var for details
	*                	        "no" indicates all is good
	*                - url
	*                	        "failed to access url" indicates an error with url
	*                - headers
	*                	        if error = no, an array of field titles
	*                - data
	*                	        if error = no, an array of subscriber email addresses
	*                - obj
	*                	        if error = yes, contains the last error returned by mailchimp
	function getexport($params = array())
		$apikey = $this->config->item('mcapi_apikey');
		$list_id = $this->config->item('mcapi_list_customers');
		$value_pairs = $this->get_value_pairs_from_param($params);
		$chunk_size = 4096; //in bytes
		$url = 'http://us2.api.mailchimp.com/export/1.0/list?apikey='.$apikey.'&id='.$list_id.$value_pairs;
		//echo $url;

		// output vars
		$headers = array();
		$data = array();
		$obj = array();
		// process
		$handle = @fopen($url,'r');
		if (!$handle) {
		  return array("error"=>"failed to access url", 'url'=>$url);
		} else {
		  $i = 0;
		  $c = 0;
		  while (!feof($handle)) {
			$buffer = fgets($handle, $chunk_size);
			if (trim($buffer)!=''){
			  $obj = json_decode($buffer);
			  if (is_array($obj))
				  if ($i==0)
					// get header
					foreach ($obj as $key=>$val)
						$headers[$key] = $val;
					// get data
					$data[] = array('email'=>strtolower($obj[0]), 'extra'=>serialize($obj));
				  // error with mailchimp
				  return array("error"=>"yes", 'url'=>$url, 'obj'=>$obj);
		  return array("error"=>"no", 'url'=>$url, 'headers'=>$headers, 'data'=>$data);
	private function get_value_pairs_from_param($params = array())
		$par = array();
		if (!empty($params))
			foreach ($params as $key => $val) 
				if ($val <> "")
					$par[] = "$key=$val";
		return (!empty($par)) ? "&".implode("&",$par) : "";	


Then create a controller to get the data into a database… or anything else.

class Getmailchimp extends Controller {

	function Getmailchimp()

	function index()
		$mailchimplist = $this->mailintegration->getexport();
		if ($mailchimplist['error'] == "no")
			// do something more sexy with the $data here like save it in a db
                       // i.e. insert each row into the database table we created 
			// handle your errors!
			echo $mailchimplist['error'];
			if (isset($mailchimplist['obj'])) var_dump($mailchimplist['obj']); 


Codeigniter Mailchimp Integration

Getting Started

  1. Install Codeigniter
  2. Download the Mailchimp PHP API Wrapper. I’m using version 1.3.
  3. Get a Mailchimp account
  4. Create a Mailchimp API Key
  5. Create a list in Mailchimp, and get the List ID.

Create a config file for Mailchimp
Create a new file called “mcapi.php” in Codeigniter’s /application/config/ folder.

Add the following code:

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['mcapi_apikey'] = 'mailchimp_api_key_here';
$config['mcapi_secure'] = true;
$config['mcapi_list_customers'] = 'mailchimp_list_id_here';

Create the library file
Rename the file MCAPI.class.php from the Mailchimp PHP API Wrapper to Mcapi.php and save it in Codeigniter’s /application/libraries/ folder.

Add the following code to the top of the file:

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Rename the class to Mcapi. IE:

class Mcapi { ...

Change the constructor to:

public function Mcapi() { 	// Get CI Instance 	$this--->CI = &get_instance();
$this->secure = $this->CI->config->item('mcapi_secure');
$this->apiUrl = parse_url("http://api.mailchimp.com/" . $this->version . "/?output=php");
$this->api_key = $this->CI->config->item('mcapi_apikey');

Basic Usage
From now on, you can load this library by simply doing this;

$return = $this->mcapi->any_method_here();