Microformats helper for Code Igniter
August 27th, 2006
Designed for humans first and machines second, microformats are a set of simple, open data formats built upon existing and widely adopted standards.
I’ve written and posted a Microformats Helper on the Code Igniter wiki. This helper is meant to ease the creation of various well known microformats. Currently, the most popular hCard format is supported. Edit: license is also now supported.
Download the Microformats helper for Code Igniter.
hCard()
hCard is a simple, open, distributed format for representing people, companies, organizations, and places, using a 1:1 representation of the properties and values of the vCard standard (RFC2426 (http://www.ietf.org/rfc/rfc2426.txt)) in semantic XHTML. hCard is one of several open microformat standards suitable for embedding in (X)HTML, Atom, RSS, and arbitrary XML.
Usage
The hCard helper will accept data either in distinct variable references (for example hCard (”Firstname”, “Middlename”, “Lastname”, “Organizationname”), or more commonly in an array (see below).
$hCard_data = array (
’given_name’ => ‘Firstname’,
’middle_name’ => ‘Middlename’,
’family_name’ => ‘Lastname’,
’organization’ => ‘OrganizationName’,
’street’ => ‘123 Street’,
’city’ => ‘City’,
’province’ => ‘Province/State’,
’postal_code’ => ‘Postal/Zip’,
’country’ => ‘Country’,
’phone’ => ‘phonenumber’,
’email’ => ‘email@yoursite.com’,
’url’ => ‘http://yoursite.com’,
’aim_screenname’ => ‘aimname’,
’yim_screenname’ => ‘yimname’
);
echo hCard($hCard_data);
The output of the above will be:
<div class="vcard">
<a href="http://yoursite.com" class="fn n">
<span class="given-name">Firstname</span>
<span class="additional_name">Middlename</span>
<span class="family_name">Lastname</span>
</a>
<div class="org">OrganizationName</div>
<a class="email" href="mailto:email@yoursite.com">email@yoursite.com</a>
<div class="adr">
<div class="street-address">123 Street</div>
<div class="locality">City</div>
<div class="region">Province/State</div>
<div class="postal-code">Postal/Zip</div>
<div class="country-name">Country</div>
</div>
<div id="tel"></div>
<a class="url" href="aim:goim?screenname=aimname">AIM</a>
<a class="url" href="ymsgr:sendIM?yimname">YIM</a>
</div>
license()
Rel-License is a simple, open, format for indicating content licenses which is embedable in (X)HTML, Atom, RSS, and arbitrary XML. Currently, the following licenses can be automatically generated:
Code Igniter License Agreement (of course), every Creative Commons 2.5 license, GNU General Public License (version 2), GNU Lesser General Public License (version 2.1), Mozilla Public License (Version 1.1), Apache License (version 2.0), and W3C SOFTWARE NOTICE AND LICENSE.
Usage
license (’license type’, ‘optional text’);
echo license('lgpl');
// will output
<a rel="license" href="http://www.gnu.org/licenses/lgpl.html">
GNU Lesser General Public License (version 2.1)
</a>
echo 'We release our code under a ' . license('ci', 'Code Igniter') . ' license.';
// will output
We release our code under a
$lt;a rel="license" href="http://www.codeigniter.com/user_guide/license.html">
Code Igniter
</a> license.
If you end up using this in your project, I'd love to hear about it here!
Enjoy!
This entry was made on August 27th, 2006 @ 16:16 and filed into CodeIgniter, How-To.
