Tuesday, March 22, 2011

Mootools 1.3 DatePicker class

I think that DatePicker mootools class by monkeyphysics is fantastic. It is fast, well written, it has a nice layout and some awesome options like the inputOutputFormat one. Recently I upgrade to mootools 1.3 without compatibility in a project of a php framework which uses this class.
So I need to make DatePicker class working with the new release of my favourite js framework.
During the upgrade work I found and fixed a bug in the date selection when selecting a day of the previous/next year in january/december months view.
Moreover I added the z-index management so that the calendar is always shown above all document elements.
Maybe more improvemets will come in the next future.
My project is a fork of the original one and hosted on my github repository.
From command line you may simply clone my project
git clone git://github.com/abidibo/mootools-datepicker.git

Monday, March 21, 2011

XDebugButton. Php XDebug with Vim.

Vim is fucking awesome. Vim is fucking extensible.
You may find a lot of plugins transforming it in a perfect IDE for you programming language.
One of the best plugin for php programmers is xdebug, which runs a debug session right into vim.
On the web you may find many articles, explaining how-to install it and make it working (it involves some configurations in vim, php.ini), here is the one I read.
Once you have installed it and made it working, you'll know that to activate the connection between vim and the server you have to recharge the web page passing a get variable: XDEBUG_SESSION_START=1
Now here comes my work, very easy indeed, but was my first firefox addon developement.
I wrote a firefox extension that appends automatically the paramether at  the url, checking for the right symbol to insert (& or ?).
You may find my addon source, with the instructions on how-to install it on my github account here.
From command line you may simply clone my project (install git first)
git clone git://github.com/abidibo/XDebug-Button---Firefox-Add-on.git
If you find errors or bugs please write to abidibo@gmail.com.

Friday, March 4, 2011

Add total time logged in infos to SMF message posters

some hours ago I had the need to show the total time logged in info in the poster message area below the number of posts published by the member.
The forum platform is SMF, I 've just started working with it so I can't give a professional opinion about it.
Now what we have to do to achieve our goal is what follows.
  1. Edit the /Sources/Load.php file.
    goto line 838 (inside the loadMemberData method) and add to the fields selected by the query the one we want: mem.totalTimeLoggedIn
  2. Well, now the information we want is selected from db.
  3. Goto line 1006 (inside loadMemberContext method). Here the member context variable to be passed to the template is prepared. We have to add our informations to the array returned by this method, so add the following key=>value pair to the $memberContext[$user]  array:
    'total_time_logged_in' => array(
    'days' => floor($profile['totalTimeLoggedIn'] / 86400),
    'hours' => floor(($profile['totalTimeLoggedIn'] % 86400) / 3600),
    'minutes' => floor(($profile['totalTimeLoggedIn'] % 3600) / 60)
  4. Well done, now our information is present in the context member variable passed to the template we have to edit. Notice that we have divided the amount of time in days, hours and minutes.
  5. Now we have to show this information in the right place, that is the right template, which is /Themes/default/Display.template.php, or the one corresponding to your used theme if present in the theme folder. Open the file and goto line 316. At this line are printed the informations about the number of posts written by the message poster, so below that we insert our code:
    // Show how many posts they have made.
    echo '
    ', $txt[26], ': ', $message['member']['posts'], '

    // Show total time online.
    if (!empty($message['member']['total_time_logged_in'])) {
    echo '
    ', $txt['totalTimeLogged1'];

    // If days is just zero, don't bother to show it.
    if ($message['member']['total_time_logged_in']['days'] > 0)
    echo $message['member']['total_time_logged_in']['days'], $txt['totalTimeLogged5'];

    // Same with hours - only show it if it's above zero.
    if ($message['member']['total_time_logged_in']['hours'] > 0)
    echo $message['member']['total_time_logged_in']['hours'], $txt['totalTimeLogged6'];

    // But, let's always show minutes - Time wasted here: 0 minutes ;).
    echo $message['member']['total_time_logged_in']['minutes'], $txt['totalTimeLogged7'], '<br /><br />';
    else echo '<br />';
Ok, only some considerations:
I displayed the count of time in this form;
xd xh xm
you can show it as
x days x hours and x minutes
or in the form you want, you only have to edit the language locate files of the languages you're interedsted in and set the text you prefer, you may define new strings and so on. Brutally you may also print the string you want directly into the template without using the locate system.
Hasta la proxima siempre.