Archive for the 'php' Category

Been busy working on a software licensing lately. Finally had the time to play with Zend’s standalone GData client library. I learnt about it through Dot Jay’s excellent article on sending SMS with Google Calendar on Twitter direct messages using PHP.

I gave it a go with his codes and realized quickEvent will not trigger a SMS alert. GCal SMS alerts are sent (latest) 5 mins before the event, creating an event now will “miss” that alert.

In other words, if you want an alert now, create an event that will occur 6 mins from now.

Translate that to code (largely from Dot Jay’s with my modifications), it looks something like this:

<?php

// Define credentials for the Google Calendar account
define(’GCAL_USER’, ‘yourid@gmail.com’);
define(’GCAL_PASS’, ‘yourpwd’);

// Include Zend GData client library
require_once ‘Zend/Loader.php’;
Zend_Loader::loadClass(’Zend_Gdata’);
Zend_Loader::loadClass(’Zend_Gdata_ClientLogin’);
Zend_Loader::loadClass(’Zend_Gdata_Calendar’);

// Get Google Calendar service name (predefined service name for calendar)
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;

// Authenticate with Google Calendar
$client = Zend_Gdata_ClientLogin::getHttpClient(GCAL_USER, GCAL_PASS, $service);

// Create a new Google Calendar object
$calendar = new Zend_Gdata_Calendar($client);

// Create a new event
$event = $calendar->newEventEntry();

//setup reminder setting
$reminder = $calendar->newReminder();
$reminder->method = “sms”;
$reminder->minutes = “5″; //google even soonest sms reminder is 5 mins

$startDate     = date(”Y-m-d”);
$startTime     = date(”H:i”, time() + 6*60);//6 mins ahead of now
$endDate     = date(”Y-m-d”);
$endTime     = date(”H:i”, time() + 7*60);//7 mins ahead of now
$tzOffset     = “+08″; //this is Singapore’s offset

$when = $calendar->newWhen();
$when->startTime = “{$startDate}T{$startTime}:00.000{$tzOffset}:00″;
$when->endTime = “{$endDate}T{$endTime}:00.000{$tzOffset}:00″;
$when->reminders = array($reminder);
$event->when = array($when);

// Add our message as the event content
$event->title = $calendar->newTitle(”My title”);
$event->content = $calendar->newContent(”TwitterSG alert”);

// Send the new event to be added to Google Calendar
if (defined(’GCAL_ID’)) {
$newEvent = $calendar->insertEvent($event, ‘http://www.google.com/calendar/feeds/’.GCAL_ID.’/private/full’);
} else {
$newEvent = $calendar->insertEvent($event);
}

?>

With this piece of code, it’s not hard to imagine the uses for it.

Related posts:



    Well as you might know that Twitter is gradually dropping SMS alerts from system to users due to high cost. GCal on the other hand still supports SMS reminders of your nearing events. I guess Google is quite rich and Twitter is not.

    I have been using Google Calendar (or GCal) static recurring events to do *ahem* some polling. Recently I was fiddling with Twitter by coding a SMS update service http://twitter.sg. It got me to wonder if we can mash the two up.

    Seems like a few people have beaten me to it. http://twittercal.com/ &
    http://dotjay.co.uk/2008/feb/php-twitter-google-calendar-sms

    As a person who is concerned with security, it bothers me since users would have to save not one but two sets of username:password into the system. This is a prevailing problem in the cyber world where users have “identities” crisis with growing adoption of online services. I digressed…

    Maybe I am still rather new to Twitter. It all seems kinda convoluted to run so many lines of code just to get a text message to a person. You might as well pick up the phone and text directly. O well… I guess I will just do that for now.

    Related posts:

      Recently I have been coding alot. Reading other people’s code that is badly design is a pain. And worst still, working with people who stick to outdated development techniques.

      Its a waste of time trying to convince people that they should look at Object-Oriented design, use code versioning, bugging tracking system etc. Let’s not even speak of design patterns when they don’t even apply basic stuff like generalization/specialization.

      No point ranting any further here. So I decided to experiment with other more interesting stuff in other areas apart from applied cryptography which is pretty much revolving around messing up and “unmessing” information..*yawnz*. I must always remind myself that I don’t need a company to explore fun and interesting technologies.

      Now to the actual topic. Graphing is an important form of visualization of data. Basically it turns data into information by making meaningful representations. What options do we have in PHP to generate graphs?

      It seems like most libraries out there for PHP requires GD library. So make sure you have it! Btw, this is not another how-to or tutorial entries since there are plenty out there. This is just my entry to store links that I refer to and help me make an assessment of what to use for different applications.

      Graphing libraries that I found useful are (not exhaustive list of course!):
      JGraph http://www.aditus.nu/jpgraph/proversion.php
      PHP/SWF Charts http://www.maani.us/charts/index.php?menu=Introduction

      I will not discuss how to code with each library but rather compare the two in terms of:
      - features
      - ease of use
      - licensing

      Features
      The key difference between the two is that SWF charts uses of flash for rendering of graphs and charts. In PHP/SWF charts introduction page, you will find people whining about Jgraph doesn’t work on PHP5 or it looks amatuerish etc. Most of the time, I dismiss such “testimonials” as it is no different from saying “O i think PC sux and Mac is cool or vice versa”. With the same pen, an artist can draw wonders and an idiot can scribble crap.

      From this key difference one can infer that certain situation will rule out the use of SWF charts. For example if one is in intranet that has paranoid policies and denies applets and what not, including running of flash swf. JGraph will shine in such situations since the output is basically image file.

      But if interactiveness and aesthetics are crucial, then SWF will be useful since its flash representations allow clickable charts and drill downs without page refresh. Something that JGraph is incapable of. Also the flash charts generally looks more “flashy” and prettier.

      Documentation is important, JGraph is extensive in this respect while SWF chart’s is rather sparse. Usually the number features are proportional to the amount of documentation for most products. It is safe to conclude that JGraph has alot more than the flashy counterpart.

      Ease of use
      I haven’t gotten my hands dirty to test the libraries during the time of writing this entry. So all the comments/opinions are based on what I have read from tutorial sites pointed by JGraph main site and from SWF chart’s site tutorials.

      SWF
      From the surface, it seems inserting SWF charts is much easier and a little more MVC. The view and controller role is performed by “chart.swf” while data for the chart is fed in the third parameter of InsertChart(...). The configuration of chart is done mostly via assignment of variables. After more reading of the samples from the Gallery, I find it a little messy… Anyway most people like messy codes. Well heck!

      JGraph
      OO way of creating graphs and charts, very neat assignments of various attributes relevant to the graph/chart. With a little separation, one partition configuration of graph, data assignment and rendering neatly. With cool IDE such as PHPEdit, the coding is alot easier with code hinting rather than assignment of arrays in SWF.

      I would prefer JGraph when it comes to good design of software. Then again most people wouldn’t care less so long the graph looks pretty…

      Licensing
      Both have some form of dual licensing scheme. “Free” and Commercial license. JGraph is stricter in a sense that you CANNOT use it for commercial if you don’t pay. SWF doesn’t have that restriction, but you have to registry. However, clicking on a SWF chart using the free version will lead the browser to PHP/SWF’s site.

      The cost details can be found at both sites so I shall not repeat them here. In short, one can easily try out the two without forking a single cent.

      Tutorials:
      Jgraph: http://www.maani.us/charts/index.php?menu=Introduction

      PHP/SWF charts: http://www.maani.us/charts/index.php?menu=Tutorial

      Related posts:
        Clicky Web Analytics