Sunday, June 19, 2011

Joomla Anniversary Module

This has got to be the most pointless Joomla Module ever, but I will admit, it cracks me up.

First, some background.

A while back, I created a pointless web tool called The Anniversarator, at http://anniversarator.com, which lets you tell it when your relationship started, and it comes up with some kind of nonsense "anniversary" that you can celebrate today. It also works with birthdays. It will produce results like:

    Today is the first New Moon after your 30 month anniversary!

    Today is your 32 lunar cycle anniversary!

    Today is your 10-bit day (1024 days) anniversary!

    Today is the first Full Moon after your 1000 day anniversary!

    Today is your 1 gross week anniversary (144 weeks)

    Today is your 3 Martian year anniversary!

...and so on. It tells you the normal ones, too.

At any rate, on a whim when I created the site I decided I might as well make it available as an XML REST web service, as well, so that if anyone wanted to they could integrate its output into their own iphone apps or websites or what-not.

Joomla has provided the perfect "what-not" opportunity.

First, you have to install the PHP Module Extension (Fiji Web Design). This functions basically like the built-in HTML module, but allows you to include custom PHP as well as HTML an javascript.

Create a PHP Module in Joomla, and use this code:

<?php

$database =& JFactory::getDBO();
$user =& JFactory::getUser();
$html = '';

if ($html=='') {
  $query = 
"SELECT DATE_FORMAT(`registerDate`,'%Y') as regyear, 
DATE_FORMAT(`registerDate`,'%m') as regmonth, 
DATE_FORMAT(`registerDate`,'%d') as regday 
FROM `jos_users` WHERE `id` = '".$user->get('id')."'";

  $database->setQuery( $query );
  $rows = $database->loadObjectList();

  $regyear = '0000';
  $regmonth = '00';
  $regday = '00';

  foreach($rows as $row){
    $regyear = $row->regyear;
    $regmonth = $row->regmonth;
    $regday = $row->regday;
  }

  $remote_url = 'http://anniversarator.com/?t=anniversary&m='.$regmonth.'&
d='.$regday.'&y='.$regyear.'&format=text';

  $result = file_get_contents($remote_url);

  $result = str_replace('anniversary!','anniversary of joining this site!',$result);

  $html = '<p style="line-height:1.0em; 
padding:10px;">'.$result.'</p><p style="text-align:right; padding-
right:1em; font-size:0.8em;">powered by <a target="_blank" 
href="http://anniversarator.com/">anniversarator</a></p>';

}

print($html);

?>

This will display for the user a module that shows the "anniversary with of joining the website", for example: "This is your 2 fortnight anniversary of joining this site! Congratulations!" will appear in a side-bar box (or where ever you place the module)

Why would you want to display this for your users? I don't know. But there it is, if you want it.

No comments:

Post a Comment