Difference between revisions of "GA Event Notifier"

From Second Life Wiki
Jump to navigation Jump to search
m (language tags to <source>)
 
(3 intermediate revisions by one other user not shown)
Line 10: Line 10:




//GA Event Notifier.lsl 1.0
<source lang="lsl2">
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// GA Event Notifier 1.0 by Jason Dahlen (aka Victor Hua)
// GA Event Notifier 1.0 by Jason Dahlen (aka Victor Hua)
// SpotOn3D
// SpotOn3D
// https://spoton3d.com/
// https://spoton3d.com/
// (c) 2010 - Jason Dahlen
// (c) 2010 - Jason Dahlen
//
//
// Distributed as GPL, donated to wiki.secondlife.com on 13 July 2010
// Distributed as GPL, donated to wiki.secondlife.com on 13 July 2010
//
//
// SCRIPT:  GA Event Notifier.lsl 1.0    :: Use on your web server
// SCRIPT:  GA Event Notifier.lsl 1.0    :: Use on your web server
//          gaenot_1.0.php          :: Use inworld
//          gaenot_1.0.php          :: Use inworld
//
//
// FUNCTION:  
// FUNCTION:  
// Gather seven days event data from a Google calendar and display it through a simple interface.
// Gather seven days event data from a Google calendar and display it through a simple interface.
//The lsl script can access several calendars at once through seperate php files. One file per calendar.
//The lsl script can access several calendars at once through seperate php files. One file per calendar.
//
//
// USAGE:  
// USAGE:  
// 1. Place gaenot_1.0.php in your web directory. Anywhere you can view the php file in a web browser.
// 1. Place gaenot_1.0.php in your web directory. Anywhere you can view the php file in a web browser.
//      You will need a seperate gaenot_1.0.php file for each calendar you want to display. You can rename the files.
//      You will need a seperate gaenot_1.0.php file for each calendar you want to display. You can rename the files.
// 2. At the top of your gaenot_1.0.php file you will find two variables.
// 2. At the top of your gaenot_1.0.php file you will find two variables.
//      $email            Enter your gmail address
//      $email            Enter your gmail address
//      $Calendar_xml_URL    A URL that points to your Live Bookmarks feed for Google Calendars.
//      $Calendar_xml_URL    A URL that points to your Live Bookmarks feed for Google Calendars.
//                              You can find this under My Calendar in the settings toward the bottom.
//                              You can find this under My Calendar in the settings toward the bottom.
//                            Choose the 'xml' button selection from the following:
//                            Choose the 'xml' button selection from the following:
//                              -Calendar Address - This address works if you have a publically viewable calendar  
//                              -Calendar Address - This address works if you have a publically viewable calendar  
//                              (ie viewable publically in a web browser)
//                              (ie viewable publically in a web browser)
//                            -Private Address - Use this address if you want to display information from an
//                            -Private Address - Use this address if you want to display information from an
//                                  otherwise private calendar. This calendar would then only be viewable by
//                                  otherwise private calendar. This calendar would then only be viewable by
//                                      yourself and those using the in world lsl tool.
//                                      yourself and those using the in world lsl tool.
// 3. Drop the GA Event Notifier.lsl in your object.  
// 3. Drop the GA Event Notifier.lsl in your object.  
// 4. Add the locations of the php files in the url list. You can have one or several.
// 4. Add the locations of the php files in the url list. You can have one or several.
// 5. Set the  gmtOffset to your time or the time of the calendar you are accessing.
// 5. Set the  gmtOffset to your time or the time of the calendar you are accessing.
//
//
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
 
 
 
//Add URLs to the list pointing to the location of your gaenot.php script.
//Add URLs to the list pointing to the location of your gaenot.php script.
//list urls = [
//list urls = [
//                "https://yourdomain.com/gaenot_1.0.php",
//                "https://yourdomain.com/gaenot_1.0.php",
//                "https://yourdomain.com/gaenot_1.0-2.php"
//                "https://yourdomain.com/gaenot_1.0-2.php"
//            ];
//            ];
list urls = [
list urls = [
                "https://yourdomain.com/gaenot_1.0.php"
                "https://yourdomain.com/gaenot_1.0.php"
            ];  
            ];
 
 
 
//Set the GMT offset to your timezone or to the timezone of the google calendar.
//Set the GMT offset to your timezone or to the timezone of the google calendar.
integer gmtOffset = -5;  
integer gmtOffset = -5;
 
//######################################### Edit below this line at your own risk ##########################
//######################################### Edit below this line at your own risk ##########################
 
list days; //Day value reference
list days; //Day value reference
list dates; //List of event dates
list dates; //List of event dates
list titles; //Event titles
list titles; //Event titles
list place; //Event locations if given
list place; //Event locations if given
list details; //Event details if given
list details; //Event details if given
integer calendars; //Number of calendars traced by this tool.
integer calendars; //Number of calendars traced by this tool.
integer thisCalendar; //Used when retrieving calendar data.  
integer thisCalendar; //Used when retrieving calendar data.
 
//Used to parse incoming event data
//Used to parse incoming event data
list weekdays = ["Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"];
list weekdays = ["Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"];
 
 
//Used for generating button list.
//Used for generating button list.
list week = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"];
list week = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"];
list buttonList;
list buttonList;
 
//Channels
//Channels
integer CHANNEL;
integer CHANNEL;
integer HANDLE;
integer HANDLE;
 
//Initialize script variables
//Initialize script variables
constructor()
constructor()
{
{
    days = [];
    days = [];
    dates = [];
    dates = [];
    titles = [];
    titles = [];
    place = [];
    place = [];
    details = [];
    details = [];
    calendars = llGetListLength(urls);
    calendars = llGetListLength(urls);
    thisCalendar = 0;
    thisCalendar = 0;
    llSetTimerEvent(3600);
    llSetTimerEvent(3600);
    makeButtonList();
    makeButtonList();
    //llHTTPRequest(url, [], "");
    //llHTTPRequest(url, [], "");
    requestData();
    requestData();
    llOwnerSay("Events List Refreshed");
    llOwnerSay("Events List Refreshed");
    llOwnerSay("");
    llOwnerSay("");
    llListenControl(HANDLE, FALSE);
    llListenControl(HANDLE, FALSE);
}
}
 
requestData()
requestData()
{
{
    if(thisCalendar < calendars)
    if(thisCalendar < calendars)
    {
    {
        llHTTPRequest(llList2String(urls,thisCalendar), [], "");
        llHTTPRequest(llList2String(urls,thisCalendar), [], "");
        thisCalendar += 1;
        thisCalendar += 1;
    }
    }
}  
}
 
// Generate dialog button list
// Generate dialog button list
makeButtonList()
makeButtonList()
{
{
    buttonList = [];
    buttonList = [];
    list tempList = [];
    list tempList = [];
    integer day = getDay(gmtOffset);
    integer day = getDay(gmtOffset);
    integer i;
    integer i;
    for (i=0; i<7; i++)
    for (i=0; i<7; i++)
    {
    {
        tempList += llList2String(week,day);
        tempList += llList2String(week,day);
        day++;
        day++;
        if (day > 6)
        if (day > 6)
        {
        {
            day = 0;
            day = 0;
        }
        }
    }
    }
   
   
    buttonList =    [llList2String(tempList,6),"Today", "Refresh",
    buttonList =    [llList2String(tempList,6),"Today", "Refresh",
                    llList2String(tempList,3), llList2String(tempList,4), llList2String(tempList,5),
                    llList2String(tempList,3), llList2String(tempList,4), llList2String(tempList,5),
                    llList2String(tempList,0), llList2String(tempList,1), llList2String(tempList,2)];
                    llList2String(tempList,0), llList2String(tempList,1), llList2String(tempList,2)];
}
}
 
//Creates dialog channel based on the object UUID. Reduces the chance of cross messaging.
//Creates dialog channel based on the object UUID. Reduces the chance of cross messaging.
integer hex2int(string hex)  
integer hex2int(string hex)  
{
{
    if(llGetSubString(hex,0,1) == "0x")
    if(llGetSubString(hex,0,1) == "0x")
        return (integer)hex;
        return (integer)hex;
    if(llGetSubString(hex,0,0) == "x")  
    if(llGetSubString(hex,0,0) == "x")  
        return (integer)("0"+hex);
        return (integer)("0"+hex);
    return(integer)("0x"+hex);  
    return(integer)("0x"+hex);  
}  
}  
 
//Parse incoming data from the php file into seperate lists.
//Parse incoming data from the php file into seperate lists.
parceString(string body)
parceString(string body)
{
{
    list tempList = llParseString2List(body, ["||"], []);
    list tempList = llParseString2List(body, ["||"], []);
       
       
    integer listLength = llGetListLength(tempList);
    integer listLength = llGetListLength(tempList);
    integer i;
    integer i;
       
       
    for (i = 0; i < listLength; i++)
    for (i = 0; i < listLength; i++)
    {
    {
        list data = llParseString2List(llList2String(tempList, i), [":"], []);
        list data = llParseString2List(llList2String(tempList, i), [":"], []);
        string flag = llStringTrim(llList2String(data,0), STRING_TRIM);
        string flag = llStringTrim(llList2String(data,0), STRING_TRIM);
        string val = llStringTrim(llList2String(data,1), STRING_TRIM);
        string val = llStringTrim(llList2String(data,1), STRING_TRIM);
           
           
        if (flag == "Date")
        if (flag == "Date")
        {
        {
            string day = llList2String(llParseString2List(val, [" "], []), 0);
            string day = llList2String(llParseString2List(val, [" "], []), 0);
            integer dayNum = llListFindList(weekdays, [day]);
            integer dayNum = llListFindList(weekdays, [day]);
            days += dayNum;
            days += dayNum;
            dates+=val;
            dates+=val;
        }
        }
        else
        else
        if (flag == "Title")
        if (flag == "Title")
        {
        {
            titles+=val;
            titles+=val;
        }
        }
        else
        else
        if (flag == "Event Description")
        if (flag == "Event Description")
        {
        {
            //Google uses a colon for its data tags.  
            //Google uses a colon for its data tags.  
            //Unfortionatly this means that if you used a colon in your description such as a URL, it would be cut off prematurly.  
            //Unfortionatly this means that if you used a colon in your description such as a URL, it would be cut off prematurly.  
            //I put a check here so at least two URLs or SLURLS such as secondlife://lambda/175/30/26 could be included.
            //I put a check here so at least two URLs or SLURLS such as secondlife://lambda/175/30/26 could be included.
            if (llStringTrim(llList2String(data,3), STRING_TRIM) != "")
            if (llStringTrim(llList2String(data,3), STRING_TRIM) != "")
            {
            {
                place += (val + ":" + llStringTrim(llList2String(data,2), STRING_TRIM)+ ":" + llStringTrim(llList2String(data,3), STRING_TRIM));
                place += (val + ":" + llStringTrim(llList2String(data,2), STRING_TRIM)+ ":" + llStringTrim(llList2String(data,3), STRING_TRIM));
            }
            }
            else
            else
            if (llStringTrim(llList2String(data,2), STRING_TRIM) != "")
            if (llStringTrim(llList2String(data,2), STRING_TRIM) != "")
            {
            {
                place += (val + ":" + llStringTrim(llList2String(data,2), STRING_TRIM));
                place += (val + ":" + llStringTrim(llList2String(data,2), STRING_TRIM));
            }
            }
            else
            else
            {
            {
                place+=val;
                place+=val;
            }
            }
        }
        }
        else
        else
        if (flag == "Where" || flag == "Event Status")
        if (flag == "Where" || flag == "Event Status")
        {
        {
            details+=val;
            details+=val;
        }
        }
    }
    }
}
}
 
//Display day event.
//Display day event.
displayEvent(integer day)
displayEvent(integer day)
{
{
    llListenControl(HANDLE, FALSE);
    llListenControl(HANDLE, FALSE);
    integer i;
    integer i;
    if(llListFindList(days, [day]) != -1)
    if(llListFindList(days, [day]) != -1)
    {
    {
        for (i=0; i<llGetListLength(days); i++)
        for (i=0; i<llGetListLength(days); i++)
        {
        {
            if (llList2Integer(days,i) == day)
            if (llList2Integer(days,i) == day)
            {
            {
                llOwnerSay("Event Date: " + llList2String(dates, i));
                llOwnerSay("Event Date: " + llList2String(dates, i));
                llOwnerSay("Event Name: " + llList2String(titles, i));
                llOwnerSay("Event Name: " + llList2String(titles, i));
                llOwnerSay(llList2String(place, i));
                llOwnerSay(llList2String(place, i));
                llOwnerSay(llList2String(details, i));
                llOwnerSay(llList2String(details, i));
                llOwnerSay("");
                llOwnerSay("");
            }
            }
        }
        }
    }
    }
    else
    else
    {
    {
        llOwnerSay("No events found for the day selected.");
        llOwnerSay("No events found for the day selected.");
        llOwnerSay("");
        llOwnerSay("");
    }
    }
}
}
 
//Get what day it is today based on ineger value
//Get what day it is today based on ineger value
integer getDay(integer offset) {
integer getDay(integer offset) {
    integer hours = llGetUnixTime()/3600;
    integer hours = llGetUnixTime()/3600;
    integer days = (hours + offset)/24;
    integer days = (hours + offset)/24;
    integer day_of_week = days%7;
    integer day_of_week = days%7;
    return day_of_week;
    return day_of_week;
}  
}
 
 
default
default
{
{
    state_entry()
    state_entry()
    {
    {
        CHANNEL = hex2int(llGetKey());
        CHANNEL = hex2int(llGetKey());
        HANDLE = llListen(CHANNEL, "", "", "");
        HANDLE = llListen(CHANNEL, "", "", "");
        llListenControl(HANDLE, FALSE);
        llListenControl(HANDLE, FALSE);
        constructor();
        constructor();
    }
    }
    touch_start(integer start)
    touch_start(integer start)
    {
    {
        llListenControl(HANDLE, TRUE);
        llListenControl(HANDLE, TRUE);
        llDialog(llDetectedKey(0), "Google Access Event Calendar \n \n" + llList2String(week,getDay(0)) + " "+ llGetDate(), buttonList, CHANNEL);
        llDialog(llDetectedKey(0), "Google Access Event Calendar \n \n" + llList2String(week,getDay(0)) + " "+ llGetDate(), buttonList, CHANNEL);
    }
    }
      http_response(key request_id, integer status, list metadata, string body)
    http_response(key request_id, integer status, list metadata, string body)
    {
    {
        parceString(body);
        parceString(body);
        requestData();
        requestData();
    }
    }
    listen(integer channel, string name, key id, string message)
    listen(integer channel, string name, key id, string message)
    {
    {
        //0 => "Thu", 1 =>"Fri", 2=>"Sat", 3=>"Sun", 4=>"Mon", 5=>"Tue", 6=>"Wed"];
        //0 => "Thu", 1 =>"Fri", 2=>"Sat", 3=>"Sun", 4=>"Mon", 5=>"Tue", 6=>"Wed"];
        if(message == "Today")
        if(message == "Today")
        {
        {
            displayEvent(getDay(gmtOffset));
            displayEvent(getDay(gmtOffset));
        }
        }
        else
        else
        if(message == "Sunday")
        if(message == "Sunday")
        {
        {
            displayEvent(3);
            displayEvent(3);
        }
        }
        else
        else
        if(message == "Monday")
        if(message == "Monday")
        {
        {
            displayEvent(4);
            displayEvent(4);
        }
        }
        else
        else
        if(message == "Tuesday")
        if(message == "Tuesday")
        {
        {
            displayEvent(5);
            displayEvent(5);
        }
        }
        else
        else
        if(message == "Wednesday")
        if(message == "Wednesday")
        {
        {
            displayEvent(6);
            displayEvent(6);
        }
        }
        else
        else
        if(message == "Thursday")
        if(message == "Thursday")
        {
        {
            displayEvent(0);
            displayEvent(0);
        }
        }
        else
        else
        if(message == "Friday")
        if(message == "Friday")
        {
        {
            displayEvent(1);
            displayEvent(1);
        }
        }
        else
        else
        if(message == "Saturday")
        if(message == "Saturday")
        {
        {
            displayEvent(2);
            displayEvent(2);
        }
        }
        else
        else
        if(message == "Refresh")
        if(message == "Refresh")
        {
        {
            constructor();
            constructor();
        }
        }
    }
    }
    timer()
    timer()
    {
    {
        llSetTimerEvent(3600);
        llSetTimerEvent(3600);
        constructor();
        constructor();
    }
    }
}
}
 
</source>
 




Line 310: Line 313:




<?php
<source lang="php">
/*
 
/////////////////////////////////////////////////////////////////////
<?php
// GA Event Notifier 1.0 by Jason Dahlen (aka Victor Hua)
/*
// SpotOn3D
/////////////////////////////////////////////////////////////////////
// https://spoton3d.com/
// GA Event Notifier 1.0 by Jason Dahlen (aka Victor Hua)
// (c) 2010 - Jason Dahlen
// SpotOn3D
//
// https://spoton3d.com/
// Distributed as GPL, donated to wiki.secondlife.com on 13 July 2010
// (c) 2010 - Jason Dahlen
//
//
// SCRIPT:  GA Event Notifier.lsl 1.0    :: Use on your web server
// Distributed as GPL, donated to wiki.secondlife.com on 13 July 2010
//          gaenot_1.0.php          :: Use inworld
//
//
// SCRIPT:  GA Event Notifier.lsl 1.0    :: Use on your web server
// FUNCTION:  
//          gaenot_1.0.php          :: Use inworld
// Gather seven days event data from a Google calendar and display it through a simple interface.
//
//The lsl script can access several calendars at once through seperate php files. One file per calendar.
// FUNCTION:  
//
// Gather seven days event data from a Google calendar and display it through a simple interface.
// USAGE:  
//The lsl script can access several calendars at once through seperate php files. One file per calendar.
// 1. Place gaenot_1.0.php in your web directory. Anywhere you can view the php file in a web browser.
//
//      You will need a seperate gaenot_1.0.php file for each calendar you want to display. You can rename the files.
// USAGE:  
// 2. At the top of your gaenot_1.0.php file you will find two variables.
// 1. Place gaenot_1.0.php in your web directory. Anywhere you can view the php file in a web browser.
//      $email            Enter your gmail address
//      You will need a seperate gaenot_1.0.php file for each calendar you want to display. You can rename the files.
//      $Calendar_xml_URL    A URL that points to your Live Bookmarks feed for Google Calendars.
// 2. At the top of your gaenot_1.0.php file you will find two variables.
//                              You can find this under My Calendar in the settings toward the bottom.
//      $email            Enter your gmail address
//                            Choose the 'xml' button selection from the following:
//      $Calendar_xml_URL    A URL that points to your Live Bookmarks feed for Google Calendars.
//                              -Calendar Address - This address works if you have a publically viewable calendar  
//                              You can find this under My Calendar in the settings toward the bottom.
//                              (ie viewable publically in a web browser)
//                            Choose the 'xml' button selection from the following:
//                            -Private Address - Use this address if you want to display information from an
//                              -Calendar Address - This address works if you have a publically viewable calendar  
//                                  otherwise private calendar. This calendar would then only be viewable by
//                              (ie viewable publically in a web browser)
//                                      yourself and those using the in world lsl tool.
//                            -Private Address - Use this address if you want to display information from an
// 3. Drop the GA Event Notifier.lsl in your object.  
//                                  otherwise private calendar. This calendar would then only be viewable by
// 4. Add the locations of the php files in the url list. You can have one or several.
//                                      yourself and those using the in world lsl tool.
// 5. Set the  gmtOffset to your time or the time of the calendar you are accessing.
// 3. Drop the GA Event Notifier.lsl in your object.  
//
// 4. Add the locations of the php files in the url list. You can have one or several.
/////////////////////////////////////////////////////////////////////
// 5. Set the  gmtOffset to your time or the time of the calendar you are accessing.
*/
//
$email = 'hakumei70ster@gmail.com';
/////////////////////////////////////////////////////////////////////
$Calendar_xml_URL = "http://www.google.com/calendar/feeds/hakumei70ster%40gmail.com/public/basic";
*/
$email = 'myname@gmail.com';
$Calendar_xml_URL = "http://www.google.com/calendar/feeds/myfeed";
 
//######################################### Edit below this line at your own risk ##########################
 
 
//######################################### Edit below this line at your own risk ##########################
 
 
 
/*Debug
 
ini_set('display_errors',1);
 
error_reporting(E_ALL|E_STRICT);
/*Debug
*/
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
*/
 
     $userid = $email;
     $userid = $email;
     $magicCookie = 'cookie';
     $magicCookie = 'cookie';
Line 368: Line 373:
     // build feed URL
     // build feed URL
     $feedURL = $Calendar_xml_URL;
     $feedURL = $Calendar_xml_URL;
 
     //Return string date as a timestamp.
     //Return string date as a timestamp.
     function _dateConv($str)
     function _dateConv($str)
     {
     {
        $dateStr = substr_replace($str[3], '', -1, 1).' '.$str[2];
        $dateStr = substr_replace($str[3], '', -1, 1).' '.$str[2];
          
          
         if (isset($str['4']))
         if (isset($str['4']))
Line 378: Line 383:
             $dateStr = $dateStr.' '.$str[4];
             $dateStr = $dateStr.' '.$str[4];
         }
         }
 
         if (isset($str['5']))
         if (isset($str['5']))
         {
         {
Line 390: Line 395:
         return $dateStr;
         return $dateStr;
     }
     }
 
     //Print Array
     //Print Array
     function printArrayElements($array)
     function printArrayElements($array)
Line 399: Line 404:
         }
         }
     }
     }
 
     // read feed into SimpleXML object
     // read feed into SimpleXML object
     $sxml = simplexml_load_file($feedURL);
     $sxml = simplexml_load_file($feedURL);
Line 405: Line 410:
     // get number of events
     // get number of events
     $total = count($sxml);
     $total = count($sxml);
 
     //Populate data arrays
     //Populate data arrays
     foreach ($sxml->entry as $entry)  
     foreach ($sxml->entry as $entry)  
     {
     {
         $content = stripslashes($entry->content);
         $content = stripslashes($entry->content);
 
<nowiki>        $data = explode('<br />', $content);</nowiki>
        $data = explode('<br />', $content);
 
         $dateArr = explode(" ",$data[0]);
         $dateArr = explode(" ",$data[0]);
 
         $dateString =  _dateConv($dateArr);
         $dateString =  _dateConv($dateArr);
         $date = strtotime(_dateConv($dateArr));
         $date = strtotime(_dateConv($dateArr));
 
         $pastDue = strtotime("12:00 am -11 hours");
         $pastDue = strtotime("12:00 am -11 hours");
         $endDate = strtotime("+6 day");
         $endDate = strtotime("+6 day");
 
         if ($date > $pastDue && $date < $endDate)
         if ($date > $pastDue && $date < $endDate)
         {
         {
Line 427: Line 432:
             $titleList[] = 'Title: '.trim(stripslashes($entry->title));
             $titleList[] = 'Title: '.trim(stripslashes($entry->title));
             $placeList[] = trim($data[2]);
             $placeList[] = trim($data[2]);
 
 
             if (isset($data[4]))
             if (isset($data[4]))
             {
             {
Line 439: Line 444:
         }
         }
     }
     }
 
     //print arrays
     //print arrays
      
      
     printArrayElements($timeList);
     printArrayElements($timeList);
 
     printArrayElements($titleList);
     printArrayElements($titleList);
 
     printArrayElements($placeList);
     printArrayElements($placeList);
 
     printArrayElements($descList);
     printArrayElements($descList);
 
 
     ?>
     ?>
</php>

Latest revision as of 19:59, 24 January 2015

This calendar consists of an lsl script and a php script.

The lsl script is listed first, and the php script is listed below it.

Please be careful not to overlap when copying the scripts.

FUNCTION: 
Gather seven days event data from a Google calendar and display it through a simple interface.
The lsl script can access several calendars at once through seperate php files. One file per calendar.


/////////////////////////////////////////////////////////////////////
// GA Event Notifier 1.0 by Jason Dahlen (aka Victor Hua)
// SpotOn3D
// https://spoton3d.com/
// (c) 2010 - Jason Dahlen
//
// Distributed as GPL, donated to wiki.secondlife.com on 13 July 2010
//
// SCRIPT:  GA Event Notifier.lsl 1.0    :: Use on your web server
//          gaenot_1.0.php           :: Use inworld
//
// FUNCTION: 
// Gather seven days event data from a Google calendar and display it through a simple interface.
//The lsl script can access several calendars at once through seperate php files. One file per calendar.
//
// USAGE: 
// 1. Place gaenot_1.0.php in your web directory. Anywhere you can view the php file in a web browser.
//      You will need a seperate gaenot_1.0.php file for each calendar you want to display. You can rename the files.
// 2. At the top of your gaenot_1.0.php file you will find two variables.
//      $email            Enter your gmail address
//      $Calendar_xml_URL     A URL that points to your Live Bookmarks feed for Google Calendars.
//                               You can find this under My Calendar in the settings toward the bottom.
//                             Choose the 'xml' button selection from the following:
//                              -Calendar Address - This address works if you have a publically viewable calendar 
//                              (ie viewable publically in a web browser)
//                            -Private Address - Use this address if you want to display information from an
//                                   otherwise private calendar. This calendar would then only be viewable by
//                                      yourself and those using the in world lsl tool.
// 3. Drop the GA Event Notifier.lsl in your object. 
// 4. Add the locations of the php files in the url list. You can have one or several.
// 5. Set the  gmtOffset to your time or the time of the calendar you are accessing.
//
/////////////////////////////////////////////////////////////////////



//Add URLs to the list pointing to the location of your gaenot.php script.
//list urls = [
//                "https://yourdomain.com/gaenot_1.0.php",
//                "https://yourdomain.com/gaenot_1.0-2.php"
//            ];
list urls = [
                "https://yourdomain.com/gaenot_1.0.php"
            ];


//Set the GMT offset to your timezone or to the timezone of the google calendar.
integer gmtOffset = -5;

//######################################### Edit below this line at your own risk ##########################

list days; //Day value reference
list dates; //List of event dates
list titles; //Event titles
list place; //Event locations if given
list details; //Event details if given
integer calendars; //Number of calendars traced by this tool.
integer thisCalendar; //Used when retrieving calendar data.

//Used to parse incoming event data
list weekdays = ["Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed"];


//Used for generating button list.
list week = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"];
list buttonList;

//Channels
integer CHANNEL;
integer HANDLE;

//Initialize script variables
constructor()
{
    days = [];
    dates = [];
    titles = [];
    place = [];
    details = [];
    calendars = llGetListLength(urls);
    thisCalendar = 0;
    llSetTimerEvent(3600);
    makeButtonList();
    //llHTTPRequest(url, [], "");
    requestData();
    llOwnerSay("Events List Refreshed");
    llOwnerSay("");
    llListenControl(HANDLE, FALSE);
}

requestData()
{
    if(thisCalendar < calendars)
    {
        llHTTPRequest(llList2String(urls,thisCalendar), [], "");
        thisCalendar += 1;
    }
}

// Generate dialog button list
makeButtonList()
{
    buttonList = [];
    list tempList = [];
    integer day = getDay(gmtOffset);
    integer i;
    for (i=0; i<7; i++)
    {
        tempList += llList2String(week,day);
        day++;
        if (day > 6)
        {
            day = 0;
        }
    }
    
    buttonList =    [llList2String(tempList,6),"Today", "Refresh",
                    llList2String(tempList,3), llList2String(tempList,4), llList2String(tempList,5),
                    llList2String(tempList,0), llList2String(tempList,1), llList2String(tempList,2)];
}

//Creates dialog channel based on the object UUID. Reduces the chance of cross messaging.
integer hex2int(string hex) 
{
    if(llGetSubString(hex,0,1) == "0x")
        return (integer)hex;
    if(llGetSubString(hex,0,0) == "x") 
        return (integer)("0"+hex);
    return(integer)("0x"+hex); 
} 

//Parse incoming data from the php file into seperate lists.
parceString(string body)
{
    list tempList = llParseString2List(body, ["||"], []);
        
    integer listLength = llGetListLength(tempList);
    integer i;
        
    for (i = 0; i < listLength; i++)
    {
        list data = llParseString2List(llList2String(tempList, i), [":"], []);
        string flag = llStringTrim(llList2String(data,0), STRING_TRIM);
        string val = llStringTrim(llList2String(data,1), STRING_TRIM);
            
        if (flag == "Date")
        {
            string day = llList2String(llParseString2List(val, [" "], []), 0);
            integer dayNum = llListFindList(weekdays, [day]);
            days += dayNum;
            dates+=val;
        }
        else
        if (flag == "Title")
        {
            titles+=val;
        }
        else
        if (flag == "Event Description")
        {
            //Google uses a colon for its data tags. 
            //Unfortionatly this means that if you used a colon in your description such as a URL, it would be cut off prematurly. 
            //I put a check here so at least two URLs or SLURLS such as secondlife://lambda/175/30/26 could be included.
            if (llStringTrim(llList2String(data,3), STRING_TRIM) != "")
            {
                place += (val + ":" + llStringTrim(llList2String(data,2), STRING_TRIM)+ ":" + llStringTrim(llList2String(data,3), STRING_TRIM));
            }
            else
            if (llStringTrim(llList2String(data,2), STRING_TRIM) != "")
            {
                place += (val + ":" + llStringTrim(llList2String(data,2), STRING_TRIM));
            }
            else
            {
                place+=val;
            }
        }
        else
        if (flag == "Where" || flag == "Event Status")
        {
            details+=val;
        }
    }
}

//Display day event.
displayEvent(integer day)
{
    llListenControl(HANDLE, FALSE);
    integer i;
    if(llListFindList(days, [day]) != -1)
    {
        for (i=0; i<llGetListLength(days); i++)
        {
            if (llList2Integer(days,i) == day)
            {
                llOwnerSay("Event Date: " + llList2String(dates, i));
                llOwnerSay("Event Name: " + llList2String(titles, i));
                llOwnerSay(llList2String(place, i));
                llOwnerSay(llList2String(details, i));
                llOwnerSay("");
            }
        }
    }
    else
    {
        llOwnerSay("No events found for the day selected.");
        llOwnerSay("");
    }
}

//Get what day it is today based on ineger value
integer getDay(integer offset) {
    integer hours = llGetUnixTime()/3600;
    integer days = (hours + offset)/24;
    integer day_of_week = days%7;
    return day_of_week;
}


default
{
    state_entry()
    {
        CHANNEL = hex2int(llGetKey());
        HANDLE = llListen(CHANNEL, "", "", "");
        llListenControl(HANDLE, FALSE);
        constructor();
    }
    touch_start(integer start)
    {
        llListenControl(HANDLE, TRUE);
        llDialog(llDetectedKey(0), "Google Access Event Calendar \n \n" + llList2String(week,getDay(0)) + " "+ llGetDate(), buttonList, CHANNEL);
    }
     http_response(key request_id, integer status, list metadata, string body)
    {
        parceString(body);
        requestData();
    }
    listen(integer channel, string name, key id, string message)
    {
        //0 => "Thu", 1 =>"Fri", 2=>"Sat", 3=>"Sun", 4=>"Mon", 5=>"Tue", 6=>"Wed"];
        if(message == "Today")
        {
            displayEvent(getDay(gmtOffset));
        }
        else
        if(message == "Sunday")
        {
            displayEvent(3);
        }
        else
        if(message == "Monday")
        {
            displayEvent(4);
        }
        else
        if(message == "Tuesday")
        {
            displayEvent(5);
        }
        else
        if(message == "Wednesday")
        {
            displayEvent(6);
        }
        else
        if(message == "Thursday")
        {
            displayEvent(0);
        }
        else
        if(message == "Friday")
        {
            displayEvent(1);
        }
        else
        if(message == "Saturday")
        {
            displayEvent(2);
        }
        else
        if(message == "Refresh")
        {
            constructor();
        }
    }
    timer()
    {
        llSetTimerEvent(3600);
        constructor();
    }
}



Start of the gaenot_1.0.php script.


<source lang="php">

<?php /* ///////////////////////////////////////////////////////////////////// // GA Event Notifier 1.0 by Jason Dahlen (aka Victor Hua) // SpotOn3D // https://spoton3d.com/ // (c) 2010 - Jason Dahlen // // Distributed as GPL, donated to wiki.secondlife.com on 13 July 2010 // // SCRIPT: GA Event Notifier.lsl 1.0  :: Use on your web server // gaenot_1.0.php  :: Use inworld // // FUNCTION: // Gather seven days event data from a Google calendar and display it through a simple interface. //The lsl script can access several calendars at once through seperate php files. One file per calendar. // // USAGE: // 1. Place gaenot_1.0.php in your web directory. Anywhere you can view the php file in a web browser. // You will need a seperate gaenot_1.0.php file for each calendar you want to display. You can rename the files. // 2. At the top of your gaenot_1.0.php file you will find two variables. // $email Enter your gmail address // $Calendar_xml_URL A URL that points to your Live Bookmarks feed for Google Calendars. // You can find this under My Calendar in the settings toward the bottom. // Choose the 'xml' button selection from the following: // -Calendar Address - This address works if you have a publically viewable calendar // (ie viewable publically in a web browser) // -Private Address - Use this address if you want to display information from an // otherwise private calendar. This calendar would then only be viewable by // yourself and those using the in world lsl tool. // 3. Drop the GA Event Notifier.lsl in your object. // 4. Add the locations of the php files in the url list. You can have one or several. // 5. Set the gmtOffset to your time or the time of the calendar you are accessing. // /////////////////////////////////////////////////////////////////////

  • /

$email = 'myname@gmail.com'; $Calendar_xml_URL = "http://www.google.com/calendar/feeds/myfeed";


//######################################### Edit below this line at your own risk ##########################



/*Debug ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT);

  • /
   $userid = $email;
   $magicCookie = 'cookie';
   date_default_timezone_set('America/Chicago');
   
   // build feed URL
   $feedURL = $Calendar_xml_URL;
   //Return string date as a timestamp.
   function _dateConv($str)
   {
       $dateStr = substr_replace($str[3], , -1, 1).' '.$str[2];
       
       if (isset($str['4']))
       {
           $dateStr = $dateStr.' '.$str[4];
       }
       if (isset($str['5']))
       {
           $dateStr = $dateStr.' '.$str[5];
       }
       
       if (isset($str[7]))
       {
           $dateStr = $dateStr.' '.substr($str[7], -3, 3);
       }
       return $dateStr;
   }
   //Print Array
   function printArrayElements($array)
   {
       foreach($array as $key => $value)
       {
           echo "$value"."||";
       }
   }
   // read feed into SimpleXML object
   $sxml = simplexml_load_file($feedURL);
   
   // get number of events
   $total = count($sxml);
   //Populate data arrays
   foreach ($sxml->entry as $entry) 
   {
       $content = stripslashes($entry->content);
       $data = explode('
', $content);
       $dateArr = explode(" ",$data[0]);
       $dateString =  _dateConv($dateArr);
       $date = strtotime(_dateConv($dateArr));
       $pastDue = strtotime("12:00 am -11 hours");
       $endDate = strtotime("+6 day");
       if ($date > $pastDue && $date < $endDate)
       {
           $t = "test string"; 
           $timeList[] = 'Date: '.$dateArr[1].' '.trim($dateString);
           $titleList[] = 'Title: '.trim(stripslashes($entry->title));
           $placeList[] = trim($data[2]);


           if (isset($data[4]))
           {
               $descList[] = trim($data[4]);
           }
           else
           {
               $descList[] = "Event Description:";
           }
       }
   }
   //print arrays
   
   printArrayElements($timeList);
   printArrayElements($titleList);
   printArrayElements($placeList);
   printArrayElements($descList);


   ?>


</php>