Facebook Web/Mobile Promotion

SHARE YOUR FEIT 2012

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:

SHARE YOUR FEIT 2012

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;
}	

Authenticate Github on MediaTemple Grid (Shared) Server

Firstly ssh to your remote server:

$ ssh username@host

Then create ssh keys:

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/your_account/users/.home/.ssh/id_rsa): [provide a filename] <- create a short descriptive filename [ie - github_myproject]<br>Enter passphrase (empty for no passphrase): [password] <- always use a password 
Enter same passphrase again: [password confirmation]
Your identification has been saved in /home/your_account/users/.home/.ssh/github_myproject.
Your public key has been saved in /home/your_account/users/.home/.ssh/github_myproject.pub.<br>The key fingerprint is:
46:1b:99:56:77:0b:38:1e:35:92:de:94:58:b4:f3:d4 user@machine

Next, create or edit your config file as follows (create one if you don’t already have one):

$ pico .ssh/config

Add the following line to it:

IdentityFile /home/your_account/users/.home/.ssh/github_myproject

(Feel free to add as many keys here as you like, one on each line)

Now get your public key and copy to your clipboard, and login to Github, and create a new deploy key:

$ cat /home/your_account/users/.home/.ssh/github_myproject.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwIuZA6ca9I1E2c6j1lbqvzDpZD2XQ5dRGVjeby1SGX+6
tyjA1zcN9mim9DXOWiX1wyUwnQdNR3qmzJwjlX1riLpXoEutZxRHsvWyeQFsrWM8B5rJk0U0HDEEH+/9
u0SjGZZq0ERZE+L999ZzAYp7voxD7L7zFqp+odqNMpLln4A98JTBI50q5tVBQBbkh8wXHKPI0xLB1N9u7
VCLB8zrR7/SC73/t3XicnhmaaPL8R+9GKyfRtjxAWyRGZiG+A9ZDXgQ9m6kNP2xS3AFi2jRvHfH2tnmy
+KD80sn9hwqTIMANVr2FjVloBHmi+FIHeL9qFbdI/4DCJMHt/hEdAw== user@machine

Test that it is working by doing this from your remote server.

$ ssh -vT git@github.com

(It should prompt you to save the ssh key as a known host, and for your password)

If you get permission denied, check your config file.

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->CI->load->config('url2png');
		
        $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/";
		
	unset($this->CI);
    }

	/*
	* 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);
			$rawdata=curl_exec($ch);
			curl_close ($ch);
			if(file_exists($fullpath)){
				unlink($fullpath);
			}
			$fp = fopen($fullpath,'w+');
			fwrite($fp, $rawdata);
			fclose($fp);
			
			if(file_exists($fullpath)){
				return $fullpath;
			}
		}
		return false;
	}

}

?>

Then add this code to your controller construct:

$this->load->library('Url2png');

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

$this->url2png->display_image($url,$size);
Where:
$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):

$this->url2png->geturl($url,$size);

Use this method to save it to your server drive:

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

Dreamweaver editor filetypes for web application development

Dreamweaver > Preferences > Filetypes / Editors

.js .asa .css .cs .config .inc .txt .as .asc .asr .vb .htaccess .htpasswd .ini .liquid .json .sample .phtml .gitignore .md