This Week in Web – PHP COM, Pango, Python32, Titanium Mobile

February 25th, 2011 / By logan / No comments

PHP Pango Extension

Michael Maclean has recently published a PHP wrapper for the Pango library. It depends on his Cairo PECL package as well as Pango. Once installed you can draw graphics with Cairo and text with Pango directly from PHP. The following code is taken from his announcement:

header("Content-Type: image/png");
/* Make a 300x300px image surface */
$s = new CairoImageSurface(CairoFormat::ARGB32, 300, 300);
$c = new CairoContext($s);

/* Set the background to white */
$c->setSourceRGB(1, 1, 1);
$c->paint();

/* Let's draw using black 'ink' */
$c->setSourceRGB(0, 0, 0);

/* Make a Pango layout, set the font, then set the layout size */
$l = new PangoLayout($c);
$desc = new PangoFontDescription("Bitstream Charter 28");
$l->setFontDescription($desc);
$l->setWidth(250 * PANGO_SCALE);

/* Here, we use Pango markup to make part of the text bold */
$l->setMarkup("Hello world! Here is a rather long paragraph which should get wrapped");

/* Draw the layout on the surface */
$l->showLayout($c);

/* Output the PNG to the browser */
$s->writeToPng("php://output");

Titanium Mobile 1.6 Released

Appcelerator have just announced the release of version 1.6.0 of their Titanium Mobile SDK. 1.6.0 includes many new features for the Android platform including additional Intents, Samsung Galaxy support and the…

Titanium Mobile Android Development: Installation

February 21st, 2011 / By logan / No comments

In this series of tutorials we use Appcelerator’s Titanium Mobile platform to create Android applications. This tutorial goes over the installation and configuration of the Android SDK and Titanium Mobile on a Windows 7.

This Week In Web – PHP Internals, jQuery Plugins, Kohana Performance

February 18th, 2011 / By logan / No comments

Podcast: Under PHP’s Hood

The folks over at iBuildings recently put up an mp3 version of Johannes Schlüter’s talk “Under PHP’s Hood”. It was recorded at the Dutch PHP Conference 2010. Schlüter describes how common PHP operations are actually executed in the Zend Engine and the performance impact each has. He covers:

  • How your PHP script is run: compilation, opcodes, zend engine
  • How objects and arrays are stored: hashtables, refcount
  • include vs include_once vs require vs require_once
  • Autoloading
  • References (and why you shouldn’t use them in PHP5)
  • Garbage collection in PHP 5.3+

Reuse your Javascript as jQuery Plugins

Christopher Haupt recently wrote a tutorial for the EngineYard blog titled Reuse your Javascript as jQuery Plugins. Haupt walks you through the process of converting an existing piece of Javascript code into a jQuery plugin. He explains how to structure your plugin so it works with jQuery’s method chaining as well as how to create a standalone plugin that would be called like:

$.pluginName('some', 'param');

Optimizing a Kohana Based Website

A question about increasing the speed and scalability of a Kohana powered website was recently asked on Stackoverflow. User Pascal Martin replied with an incredibly

Using Proxies with cURL in PHP

February 13th, 2011 / By logan / 1 comment

If you are new to using PHP and cURL please refer to the PHP cURL tutorial. It covers why you should using cURL (as opposed to file_get_contents) and goes over how to make cURL requests with a custom class.

This tutorial will cover how to use different types of proxies – SOCKS4, SOCKS5 and HTTP with cURL.

Basic cURL Request

We’ll start by creating a simple cURL script that requests the web page checkip.dyndns.org and displays the result on the screen. The website just displays our current IP address, this is useful when working with proxies. Below is our very basic cURL request.

$url = 'http://checkip.dyndns.org/';

$c = curl_init($url);

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($c);

echo '<pre>';
var_dump($result);
echo '</pre>';

curl_close($c);

As we can expect, the output will be your IP address.

202.183.56.21

Using Proxies with cURL

To use proxies with cURL we need to set 2 additional cURL options: CURLOPT_PROXYTYPE and CURLOPT_PROXY. CURLOPT_PROXYTYPE should be set to either CURLPROXY_SOCKS5 or CURLPROXY_SOCKS4, depending on the type of proxy you are using. CURLOPT_PROXY should be set to the IP address and port of the proxy you are using.

If you are using an HTTP proxy then you…

Developing a blog with CakePHP

February 11th, 2011 / By Adit Gupta / No comments
If you want to develop a blog from sctrach without using any CMS like WordPress or Drupal, then you’ve come at the right place! In this series, we will understand how to develop a blog using
the CakePHP framework. So, why CakePHP? CakePHP is a robust PHP Framework having an extensive community and excellent documentation. It’s based on the MVC pattern, which makes it really simple to use.
Moreover, you can add numerous functionalities to your web application or blog using this framework.

We would be covering the following topics in this series

  1. Installing and Configuring CakePHP
  2. Understanding MVC
  3. Creating a simple blog
  4. Adding advanced features to your blog – Understanding Models, Views, Controllers in Depth
  5. Understanding Helpers
  6. Ajaxifying comments, adding content summary and Gravatar to your blog
  7. Securing your blog

In this article, we’ll just take a look at installing and configuring CakePHP.

Download the latest version of CakePHP framework from CakePHP.org. Make sure to download the stable release and not the release candidate.
Unpack the contents of the Cake archive inside the “www” folder of wamp or mamp directory.You now have a folder in your document…

This Week in Web – PHP Namespaces, NodeTuts, Kohana

February 11th, 2011 / By logan / No comments

Interview with Matthew Weier O’Phinney

Kevin Schroeder, tech evangelist at Zend, recently interviewed Zend Framework lead Matthew Weier O’Phinney. The two talk about Weier O’Phinney’s history with Zend and experiences with maintaining and developing the Zend Framework. They then go on to talk about Zend Framework 2 and cover the design decisions made in ZF2 and the things learned from ZF1 that will be altered. I found the sections on namespaces and autoloading in ZF2 particularly interesting.

Javascript Libraries Deconstructed

JS Libs Deconstructed is a website which clearly sets out and explains and explains the differences between jQuery, Prototype and Mootools. The index page gives a summary of the advantages and disadvantages of each of the 3 frameworks. Clicking on the name of a framework sends you to a page where you can easily browser through the source code (organised by class and method) of the framework.

Why PHP Namespaces Matter

Zend Framework lead Matthew Weier O’Phinney has written an article discussing the use and implementation of namespaces in PHP. One of the key points that he emphasises is that namespaces are alot more readable than the old Zend_Style_Classes. An example of this would be the hypothetical…

This Week in Web – Django, Cloud9, Orion, AOP

January 12th, 2011 / By logan / No comments

CSS Overlay in Webkit

Guillermo Rauch has written a tutorial on how to implement a lightbox using pure CSS3. He gives reasons as to why using the CSS3 method is less buggier than the old javascript or “pure css” implementations and then demonstrates how to code a lightbox with animations.

Deploying Django Applications with nginx and uwsgi

Martin Rusev has written a tutorial describing how to deploy a Django web application using nginx and uwsgi. It covers compiling nginx, setting up upstart, creating the wsgi.py file for Django, installing uwsgi and configuring nginx to use uwsgi with Django. This is definitely worth reading and bookmarking if your new to Django deployments.

Hosted Cloud9

The Cloud9 team have started the private beta for the hosted version of the Cloud9 IDE. If you want to participate in the beta, create an account, and wait until your account is activated (it could be days/weeks). You can still download and host your own version of the software, but the hosted version allows you to:

  • Run and debug NodeJS applications on their cloud infrastructure
  • One click forking of GitHub projects
  • Push and pull from and to GitHub
  • Access your code

Open Source Web Projects in Python

January 11th, 2011 / By Adit Gupta / No comments
The Python user base has grown exponentially over the years, thanks to the sheer brilliance of the language and regular updates from the brilliant python community.
You can find Python everywhere – Rapid Application Development, Game Development, System Administration, Visualization, Web Development, Scientific Programming, Embedded Systems and what not!
In this article, we’re going to take a look at some of the open source python projects for the web.

1. HTML5Lib
HTML5Lib is a Python implementation of a HTML parser based on the WHATWG HTML5 specification. It includes HTML and CSS sanitizer, DOM to SAX convertor, character encoding detection and filtering and serializing of tress.

2. Django-CMS
This is perhaps the best CMS based on Django. The installation is little tricky and you need to be familiar with Python and Django to successfully install Django-CMS. Once done, it’s easy to use and configure. Some of the major features include Flexible Plugin Architecture, SEO Optimization, Editorial Workflow, Versioning and support for custom extensions.
Get more information about Django-CMS at – http://www.django-cms.org

3. Tornado
From their website – “Tornado is an open source version of the scalable, non-blocking web server and tools that power

Tutorial: Django Template Tags

January 10th, 2011 / By logan / No comments

Introduction

In the Python Web Framework Django, template tags can be used to modify data that is about to be output in a Django template file. In this tutorial we will learn how to create and use our own template tags in a Django application.

Setting Up

Template tag definitions are stored in Django apps. The template tags in each app should be relevant to the models and views in that app. You shouldn’t have one app that stores every single template tag you use throughout your website. Each app can contain a directory called templatetags and assuming the app is added to settings.INSTALLED_APPS, Django will automatically search that appname/templatetags/ directory for template tag definitions. Remember to put an __init__.py file in each templatetags directory because the template tags inside them are imported.

Example

In an application I worked on recently I needed to display some data about a World Of Warcraft character such as their race, class and gender. The information about the character was stored in a database table and was referenced like so:

This means that if the character was a Male Orc Shaman, then the…

This Week in Web – jQuery, NodeJS, FuelPHP, How I Work

January 7th, 2011 / By logan / No comments

5 Things You Might Not Know About jQuery

David Flanagan has written a post a post at O’Reilly titled ’5 Things You Might Not Know about jQuery’. As the name suggests, the post discusses 5 tips, tricks and shortcuts about jQuery. If you taught yourself jQuery by referencing the API, then these tips are probably useful. However if you read a book to learn jQuery, chances are these tips would have been covered in that.

Serverside JS Tools

Addy Osmani has written an article about different libraries that can be used when developing NodeJS applications. If you are new to the NodeJS community I recommend you read this article. Osmani covers:

FuelPHP

FuelPHP is a new PHP framework which aims to be light, fast and full featured. It is primarily based on the Kohana Framework but draws inspiration from Code Igniter. Fuel comes with it’s own ActiveRecord implementation as well as support for database migrations. The core library is fully namespaced (for some reason the application you create doesn’t…