Archive for May, 2008

Gem of the day: haml - abstraction markup language

preamble

If you use RoR [http://en.wikipedia.org/wiki/Ruby_on_Rails] then you already know that
ERuby [http://en.wikipedia.org/wiki/ERuby] is pretty enough and you don’t ever think you need something else.

Haml {markup haiku}

Haml is an alternative way to code your “views”. It can be much easier, look on these examples:

XHTML:
<strong class=”code” id=”message”>Hello, World!</strong>

Haml:
%strong{:class => “code”, :id => “message”} Hello, World!

XHTML:
<div id=’content’>
<div class=’left column’>
<h2>Welcome to our site!>/h2>
<p>
<%= print_information %>
</p>
</div>
<div class=”right column”>
<%= render :partial => “sidebar” %>
</div>
</div>

Haml:
#content
.left.column
%h2 Welcome to our site!
%p= print_information
.right.column= render :partial => “sidebar”

like it .. so give you a try with Haml..

haml site: [http://haml.hamptoncatlin.com/]
haml docs: [http://haml.hamptoncatlin.com/docs/]

World largest database works on modified PostgreSQL

According to InformationWeek [http://www.informationweek.com/news/software/database/showArticle.jhtml?articleID=207801436]

Yahoo! corporation [http://en.wikipedia.org/wiki/Yahoo!] has world busiest and largest database.
System has build for analytical purposes, and contains history of web-users behavior.
It has size: 2-petabyte, and loading about 24 billion events a day.
Engineers of Yahoo expect size increasing up to 5-petabyte by next year.

In order to compare sizes:
USA Revenue Service DB: about 150 terabyte
Ebay: overall size: 6-petabyte, size of biggest system: about 1.4-petabyte

We should understand that we are talking about DBs. Because there are data repository with much greater sizes but data in such repositories practically unaccessible for analyzes and processing.

Surely it is nice to know that it works on modified PostgreSQL [http://en.wikipedia.org/wiki/Postgresql].
PostgreSQL continues active development and prove status as best open-source RDBMS.

As we remember in 2007 year Sun Microsystems [http://en.wikipedia.org/wiki/Sun_microsystems] published
production test [http://www.spec.org/jAppServer2004/results/res2007q3/] which showed that tuned PostgreSQL performance
is very close to Oracle DB [http://en.wikipedia.org/wiki/Oracle_db]: difference only about 15%. Don’t forget about price of Oracle DB.

Setup of Ruby on Rails environment under Debian GNU/Linux

preamble

here you will find just quick-and-dirty hints how to use Ruby on Rails on Debian GNU/Linux platform

ruby and RoR installation

# apt-get install ruby

install ruby gems [http://en.wikipedia.org/wiki/RubyGems]
# apt-get install rubygems

then don’t use ‘rails’ Debian package because it doesn’t work with gem and so gem will not know about it.
you should use gems for that:
# gem install rails –include-dependencies

if you located behind a firewall, export following value before gem using:
HTTP_PROXY=http://[username]:[password]@[proxyserver]:[port]

if you use some IDE like NetBeans [http://en.wikipedia.org/wiki/NetBeans]with Ruby on Rails extension than after installing of ruby and rubygems packages
you can use NetBeans to install ruby extensions

installation of gems that require building of native extensions

some gems are simple set of ruby scripts and then can be just installed
some gems contain source code c/c++ and so before installing of such gems you should have:

**development environment
# apt-get install build-essential

**ruby development header files
# apt-get install ruby-dev

**header files of library that you want to build

for example: you want to have ruby driver for postgresql DB
# apt-get install postgresql-server-dev-8.3
# gem install postgres

enjoy it ..

Typo3, Joomla!, and Drupal CMSs performance testing

preamble

Our company above all uses 3 CMSs [http://en.wikipedia.org/wiki/Content_management_system]
Typo3, Joomla!, and Drupal since we find them the most appropriate for most of our tasks.
Check this our article to find more about it [cms-based-web-applications-fast-way-for-creation-of-web-based-solutions.html]

Sometimes our customers asks what is faster, trying to find fair answer I made a short research
in order to compare them and provide our customer as well as you with pretty graphs.

testing conditions

I have created virtual dedicated server with following configuration within our server
to have a picture of average hosting providers.

configuration:
architecture: x86
CPU: 3.0Ghz
RAM: 512Mb
OS: Debian GNU/Linux lenny/sid (testing)
kernel: 2.6.22-3-686

On all CMS returned page contains:
menu, login form, 2 articles with overall size 40Kb

As Joomla! doesn’t have built-in internationalization functionality I made tests with JoomFish 2.0beta extension
that provide that functionality and without it.

Every testing series contains results for 1, 10, and 20 simultaneous users.
Caching functionally:
turned off for Drupal, Joomla!, and Typo3;

apache configuration:
apache web-server API: apache2.0 handler
processing model: mpm-prefork [http://httpd.apache.org/docs/2.0/mod/prefork.html]

software versions:
apache: 2.2.8
php: 5.2.5-3
mysql: 5.0.51a-3

joomla!: 1.5.2
typo3: 4.1.6
drupal:6.2

comparison results

So it’s time to see some results. Keep your eyes widely opened..

note:
results in the tables are presented in milliseconds per page request
and surely smaller result is better

1 user

joomla+joomfish joomla drupal typo3
average 261 185 130 233
median 260 184 129 232
min 253 180 127 225
max 311 209 144 248

10 users

joomla+joomfish joomla drupal typo3
average 2093 1510 1118 2039
median 1965.5 1416 1040 1247.5
min 253 181 126 226
max 36422 31591 30999 29138

20 users

joomla+joomfish joomla drupal typo3
average 4106 2908 2123 3886
median 3689 2306 1552 2075
min 254 182 128 233
max 119187 112612 83831 105285

fast conclusions:

as you see in the tables and on graphs

**Drupal is noticeably faster then competitors
**joomfish is a break for Joomla but it is very important extension and very likely it is installed on your system
**without JoomFish Joomla! can be even faster then Typo3

Joomla! 1.5 extensions development hints

0. go through basic Joomla! documentation

Joomla! Beginners guide: [http://docs.joomla.org/Beginners]

Joomla developer network: [http://dev.joomla.org/]
which includes very useful:
Joomla framework API: [http://api.joomla.org/]
Joomla! tutorials on Wiki: [http://dev.joomla.org/component/option,com_jd-wiki/Itemid,32/]

Joomla! forum: [http://forum.joomla.org]

1. project structure

It is useful during development to keep the code in only one place. You can easy use this structure with your
IDEs [http://en.wikipedia.org/wiki/Integrated_development_environment] and VCS [http://en.wikipedia.org/wiki/Version_control_system]

It is recommended to use next structure:

project-root
	com_component
		site
			...
			lang
				...
				en-GB.com_component.ini
				de-DE.com_component.ini
			component.php
		admin
			...
			lang
				...
				en-GB.com_component.ini
				de-DE.com_component.ini
			admin.component.php
			install.sql
			uninstall.sql
		component.xml
	mod_module
		...
		lang
			...
			en-GB.mod_module.ini
			de-DE.mod_module.ini
		module.php
		module.xml
	plg_plugin
		...
		lang
			...
			en-GB.plg_group_plugin.ini
			de-DE.plg_group_plugin.ini
		plugin.php
		plugin.xml
	tpl_temlate
		template.xml
	...

After creation of project structure prepare installation packages with help of Joomla! tutorials and install them to Joomla!.
We will work with local installation (or dedicated server in your LAN) because another variants decries performance of developers.

After extensions installation process change files of extensions installed to Joomla! with GNU/Linux symbolic links
[http://en.wikipedia.org/wiki/Symbolic_link] or Windows Vista symbolic links [http://en.wikipedia.org/wiki/NTFS_symbolic_link]
of your project files.
Note: Don’t forget to use option “Options +FollowSymLinks” for Apache web-server for directory where your Joomla!
installed to use symbolic links.

In Joomla! filenames of extensions has special structure. In mentioned structure names of corresponding extensions in
filenames and directories replaced with words component, module, and plug-in.
The word group in files of plugin replaces name of group to which plug-in relate to [content, editors, search, system, user].
Every group defines set of events on which plug-in will be triggered.

Ready to use project has following structure of relations: (<== symbol means symbolic link)

PRJ-ROOT/COM_COMPONENT/SITE <== J_ROOT/COMPONENTS/COM_COMPONET
PRJ-ROOT/COM_COMPONENT/SITE/LANG/en-GB.com_component.ini <== J_ROOT/LANGUAGE/en-GB/en-GB.com_component.ini
PRJ-ROOT/COM_COMPONENT/SITE/LANG/de-DE.com_component.ini <== J_ROOT/LANGUAGE/de-DE/de-DE.com_component.ini

PRJ-ROOT/COM_COMPONENT/ADMIN <== J_ROOT/ADMINISTRATOR/COMPONENTS/COM_COMPONET
PRJ-ROOT/COM_COMPONENT/ADMIN/LANG/en-GB.com_component.ini <== J_ROOT/ADMINISTRATOR/LANGUAGE/en-GB/en-GB.com_component.ini
PRJ-ROOT/COM_COMPONENT/ADMIN/LANG/de-DE.com_component.ini <== J_ROOT/ADMINISTRATOR/LANGUAGE/de-DE/de-DE.com_component.ini

PRJ-ROOT/MOD_MODULE <== J_ROOT/MODULES/MOD_MODULE
PRJ-ROOT/MOD_MODULE/LANG/en-GB.mod_module.ini <== J_ROOT/LANGUAGE/en-GB/en-GB.mod_module.ini
PRJ-ROOT/MOD_MODULE/LANG/de-DE.mod_module.ini <== J_ROOT/LANGUAGE/de-DE/de-DE.mod_module.ini

PRJ-ROOT/PLG_PLUGIN/plugin.php <== J_ROOT/PLUGINS/GROUP/plugin.php
PRJ-ROOT/PLG_PLUGIN/LANG/en-GB.plg_group_plugin.ini <== J_ROOT/ADMINISTRATOR/LANGUAGE/en-GB/en-GB.plg_group_plugin.ini
PRJ-ROOT/PLG_PLUGIN/LANG/de-DE.plg_group_plugin.ini <== J_ROOT/ADMINISTRATOR/LANGUAGE/de-DE/de-DE.plg_group_plugin.ini

As you see languages files of plug-ins installed to administration part of Joomla!. Why so we should ask Joomla! developers.

2. internationalization (i18n)

Most of extensions require internationalization. This mechanism is simple to use in Joomla!, but it has some ambiguous decisions.

To use internationalization support of text messages in the code of extensions instead of output of simple strings we should
use next construction: JText::_(’text message’);
This call check current locale and using appropriate localization file returns required string.

For instance if current locale is ‘en-GB’ then it seek for appropriate file:
for “site part” of Joomla!: joomla-root/language/en-GB/en-GB.com_component.ini
and in that file I look for sting with id ‘TEXT MESSAGE’

If it can’t find appropriate file then it returns passed string.

Structure of localization file:
identifier=value

identifier – is a string, it should be written in UPPER CASE.
Value – is a localized value.

Example:
We need to output 2 internationalized strings
echo JText::_(’This is test message.’);
echo JText::_(’Hello world.’);

Then we create localization file for appropriate locale
en-EN.com_component.ini:
THIS IS TEST MESSAGE=This is test message.
HELLO WORLD.=Hello all.

de-DE.com_component.ini:
THIS IS TEST MESSAGE=Das ist testen Meldung.
HELLO WORLD.=Halo eine Welt.

I want to note that in order to use that mechanism for plug-ins you should invoke method loadLanguage of class Jplugin:

loadLanguage(
[name of localization file],
[path to root directory of site part of admin part of Joomla!]

name of localization file, by default plg_group_plugin.ini
path to root directory, can be: “j_root/administrator” or “j_root” (by default)

3. layouts

Layouts is a handy mechanism which let us to avoid using of “if construction” in “view” of the MVC model
[http://en.wikipedia.org/wiki/Model-view-controller] which Joomla! 1.5 began to use actively for extensions development.

By default structure of extensions presentation in Joomla (for modules, and components) has next structure:

EXTENSION-ROOT
	VIEWS
	   VIEW
               TMPL
		 default.php
	     view.html.php

Here “view.html.php” file is a common part of presentation which can commonly contains invocations of “model” (MVC)
or in other words where we extract data that necessary for data output, and some simple logic.
There is a rule to place mature logic to model or controller(MVC).
In the “TMPL” directory we keep different presentations. They contain markup or in other words exact presentation of data.
An file “default.php “ is a default layout, so it will be used if we wasn’t selected another one.
You can easily create additional layouts adding them to ‘TMPL’ directory files with name “layoutname.php”.
In order to select specific layout you should in the controller(MVC) before invocation of display() function
select its name with command: JRequest::setVar(’layout’, ‘layoutname’);

4. using of AJAX

It is hardy to imagine an application that can be developed nowadays without AJAX. [http://en.wikipedia.org/wiki/Ajax_%28programming%29]

It is much easier to use some javascript library like jquery, mootols, dojo, etc.. to invoke Ajax-based methods.
I like jquery [http://jquery.com]. However Joomla! Developers have selected another Javascript library – mootols [http://mootools.net] and so I earnestly recommend to you to use for ajax methods invocations Mootools library.
If you anyway want to use your favorite JavaScript library you must switch your library to the compatibility mode.
For instance for Jquery it can be do it with:
var jq = jQuery.noConflict();
then instead of ‘$’ you should use ‘jq’ but anyway keep in mind that most of extensions for JavaScript libraries don’t use that mode and so you will have Javascript error because of name collisions.

Example of MVC flow using Ajax invocation:
- Create task in the controller, ex.: getAjaxData

	“controller.php”:
	function getAjaxData() {
		JRequest::setVar('view', 'viewname');
		JRequest::setVar('layout', 'ajaxlayout');

		parent::display();
	}

- Create layout, ex: ajaxlayout

	“viewname/tmpl/ajaxlayout.php”:
	<?php defined('_JEXEC') or die('Restricted access');

	global $mainframe;
	echo <ajax data>;

	$mainframe->close();
	?>

Important note:
You should add invocation: $mainframe->close();
in order to create output flow or it will add Joomla! standard page after result of you Ajax method.
Thus creating concrete layout you can pass any data, don’t forget to setup appropriate header.
For XML [http://en.wikipedia.org/wiki/Xml] it can be: header(”Content-type: text/xml;charset=utf-8″);

On client-side yous should make invoke defined method using Ajax call, using URL like:
JURI::root().’index.php?option=com_component&task=getajaxdata’;

5. mapping of tables to the Database

Joomla! using simple ORM system [http://en.wikipedia.org/wiki/Object-relational_mapping].
In order to use this mechanism you should describe your DB structure with sets of objects that inherit JTable.

For example:
foo.php:

<?php
defined('_JEXEC') or die('Restricted access');

class TableFoo extends JTable {
	var $id = null;
	var $bar = null;

	function TableFoo(& $db) {
		parent::__construct('#__foo', 'id', $db);
	}

	function bind( $from, $ignore=array() ) {
		$from['bar'] = strtoupper($from['bar']);
		return parent::bind($from, $ignore);
	}

	function check() {
		if (empty($this->bar)) {
			$this->setError( 'Error message');
			return false;
        		}
		return true;
	}

	function delete( $oid=null ) {
		$res = parent::delete($oid);

		// here if you need you can define mechanism
		// to delete linked tables
		return $res;
    	}
}
?>

First of all it is necessary to define public variables that corresponding to fields names of table.
Then you should pass name of the table and name of primary key to the constructor.

key methods:

Bind() method using in order to transfer data from external sources (ex.: requst) into object.
Overriding that method you can execute specific data transformations of data before adding to the fields of the object.

Check() method make checking of data in the fields, for example it can check that fields not empty or filled with required range of values, etc.

Delete() method can add specific behavior during deletion of records. For example deleting of linked records.

Also JTable class contains set of other handy methods overriding which you can add appropriate specific behavior.
See Joomla! documentation for details.

possible use:

You can get object in the model (MVC) with following: $row =& $this->getTable(’foo’);

to delete record you invoke: $row->delete($id)

to store record to db:
$row->bind($data);
$row->check();
$row->store();

If then you need get value of primary key you can simply take the value from the object: $row->id;

Surely it is better to add to described calls check of result of methods executions.

Fast ways for creation of web-based solutions

preamble

Nowadays business require full-featured cost-effective solutions with short time to market.
I see only 3 approaches to achieve it:

**development platform which allows rapid visual component-based web-applications development
Unfortunately only .Net platform has it at this moment but we try to avoid proprietary [http://en.wikipedia.org/wiki/Proprietary] solutions.

**using of real productive framework Ruby on Rails (RoR) [http://en.wikipedia.org/wiki/Ruby_on_Rails]

**lightweight platform which provide already developed full-featured system that can be easily customized with modules
- CMS (Content Management System) [http://en.wikipedia.org/wiki/Content_management_system]

I want to make a note here: not every CMS can be used as such base platform.
Appropriate platform should contain well-designed API and documentation for extension development as well as
good set of already developed extensions.

Ruby on Rails

RoR gives you an extremely quick way to develop flexible Web applications.
It contains set of useful classes and methods for carrying out the actions most used in Web-based applications, and
provide base structure of project that everyone should follow.

Rails based on 2 principles: Convention over Configuration (CoC) [http://en.wikipedia.org/wiki/Convention_over_Configuration]
and Don’t repeat yourself (DRY) [http://en.wikipedia.org/wiki/Don%27t_repeat_yourself];
uses the Model-View-Controller (MVC) [http://en.wikipedia.org/wiki/Model-view-controller] architecture,
and ActiveRecord [http://en.wikipedia.org/wiki/Active_record_pattern] which maps relational tables to Ruby objects.
I just like it..

Selected CMSs

There are set of different CMSs, and even commercial ones but we should not use them because we have enough cool open source software.

I have reviewed numerous Open-source CMSs for our company to find some noteworthy systems.
Look to this list to understand that we have to select from:
[http://en.wikipedia.org/wiki/Category:Open_source_content_management_systems]

I will not provide you with any comparison due to you can easily find them on the Internet.
There are several platform as base for CMSs: Java, Ruby, Python, PHP

Personally I like Java for strict object-oriented programming methodology, type safety [http://en.wikipedia.org/wiki/Strongly-typed_programming_language],
automatic garbage collection, good design of API, and amount of libraries that almost all are open-source.
But: Java based CMSs are heavy, ugly, and still lack functionality.

Most of wonderful (lightweight, pretty, and full-featured) CMSs are written in PHP, and 2 most cool are:

Joomla! [http://en.wikipedia.org/wiki/Joomla%21]
features list: [http://www.joomla.org/content/view/4483/118/]
documentation: [http://docs.joomla.org/]
api: [http://api.joomla.org/]
list of extensions: [http://extensions.joomla.org/]

Typo3 [http://en.wikipedia.org/wiki/TYPO3]
features list: [http://typo3.com/Feature_list.1243.0.html]
documentation: [http://typo3.org/documentation/]
api: [http://typo3.org/fileadmin/typo3api-4.0.0/]
list of extensions: [http://typo3.org/extensions/]

and at the end of the article I will provide to you one of our last solution based on Joomla!:

project name: car auctions site
rough description: site that provide functionality to purchase cars from auctions, forum to discus details, multi language support,
vote functionality, customized searches.

platform: Joomla! 1.5
template: free template from [http://joomlashack.com]
Joomla extensions:
forum: simplest forum 1.1.4 [http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,3131/Itemid,35/]
Polls: built-in Joomla! 1.5 vote component
localization support: JoomFish 2.0 [http://www.joomfish.net]

men-hours: 110
site URL: http://www.svidcars.com