SMS Notifications + Event Logging in Google Calendar in PHP

    Inspired by: Miracles of automation or how real geeks send SMS .
    If people make such sophistication, then it means much.

    In a couple of hours, a class was developed to add events to Google Calendar. And already Google’s calendar will send us SMS.

    For use, we need to correctly configure our calendar (it is worth creating a separate account for this):
    1. Set the calendar time zone to the same as on the server.
    2. Set up SMS notifications (Settings -> Settings for mobile devices)
    3. Set up a default notification for the calendar. (Calendar settings - Notifications)
    We set the default notification 1 minute before the event via SMS. You can add advanced mail notification.
    All. Calendar prepared.

    For the script to work, we need a part of ZendFramework.
    The gdata classset: framework.zend.com/download/gdata .

    And the script code with the class and usage example:

      require_once 'Zend/Loader.php';
      Zend_Loader::loadClass('Zend_Gdata');
      Zend_Loader::loadClass('Zend_Gdata_AuthSub');
      Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
      Zend_Loader::loadClass('Zend_Gdata_Calendar');

      class GCAlerter
      {
        public $gcCalendar;
        public $gcTimeCorrect;
      
        public function __construct($user, $pass, $tc)
        {
          $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, "cl");
          $this->gcCalendar = new Zend_Gdata_Calendar($client);
          $this->gcTimeCorrect = $tc;
        }
      
        public function Alert($text)
        {
          $quickAddText = "$text ".date("h:i",time() + $this->gcTimeCorrect);
          $event = $this->gcCalendar->newEventEntry();
          $event->content = $this->gcCalendar->newContent($quickAddText);
          $event->quickAdd = $this->gcCalendar->newQuickAdd('true');
          $newEvent = $this->gcCalendar->insertEvent($event);
          return $newEvent->id->text;
        }
      }
      
      $user = "mycal@gmail.com";
      $pass = 'mypass';
      $timecorr = 2*60;// 2*60 = 2 min, 10*60 = 10min

      $gcAlerter = new GCAlerter($user, $pass, $timecorr);
      $gcAlerter->Alert("OMG I`m die!!!");
    ?>

    * This source code was highlighted with Source Code Highlighter
    .


    $ timecorr - time adjustment variable.
    Server time and Google time may vary due to incorrect server time. It is not always possible to fix this.
    In fact, with this parameter we adjust the necessary time so that the notification arrives no later than a minute after the event.

    Also popular now: