function getGoogleCalendarFeeds($start, $end) { GCalendarUtil::ensureSPIsLoaded(); $calendarids = null; $gcids = $this->getState('gcids'); if (!empty($gcids)) { $calendarids = $gcids; } $results = GCalendarDBUtil::getCalendars($calendarids); if (empty($results)) { return array(); } $calendars = array(); foreach ($results as $result) { if (!empty($result->calendar_id)) { $feed = new SimplePie_GCalendar(); $feed->set_show_past_events(FALSE); $feed->set_sort_ascending(TRUE); $feed->set_orderby_by_start_date(TRUE); $feed->set_expand_single_events(TRUE); $feed->enable_order_by_date(FALSE); $feed->enable_cache(FALSE); $feed->set_start_date($start); $feed->set_end_date($end); $feed->set_max_events(100); $feed->put('gcid', $result->id); $feed->put('gccolor', $result->color); $feed->set_cal_language(GCalendarUtil::getFrLanguage()); $feed->set_timezone(GCalendarUtil::getComponentParameter('timezone')); $url = SimplePie_GCalendar::create_feed_url($result->calendar_id, $result->magic_cookie); $feed->set_feed_url($url); $feed->init(); $feed->handle_content_type(); $calendars[] = $feed; } } return $calendars; }
/** * Gets the simplepie event * @return string event */ function getGCalendar() { GCalendarUtil::ensureSPIsLoaded(); $results = GCalendarDBUtil::getCalendars(JRequest::getVar('gcid', null)); if (empty($results) || JRequest::getVar('eventID', null) == null) { return null; } $result = $results[0]; $feed = new SimplePie_GCalendar(); $feed->set_show_past_events(FALSE); $feed->set_sort_ascending(TRUE); $feed->set_orderby_by_start_date(TRUE); $feed->set_expand_single_events(TRUE); $feed->enable_order_by_date(FALSE); $feed->enable_cache(FALSE); $feed->set_start_date(JRequest::getVar('start', 0) - 86400); $feed->set_end_date(JRequest::getVar('end', 0) + 86400); $feed->put('gcid', $result->id); $feed->put('gccolor', $result->color); $feed->put('gcname', $result->name); $feed->set_cal_language(GCalendarUtil::getFrLanguage()); $feed->set_timezone(GCalendarUtil::getComponentParameter('timezone')); $url = SimplePie_GCalendar::create_feed_url($result->calendar_id, $result->magic_cookie); $feed->set_feed_url($url); $feed->init(); if ($feed->error()) { JError::raiseWarning(500, 'Simplepie detected an error for the calendar ' . $result->calendar_id . '. Please run the <a href="administrator/components/com_gcalendar/libraries/sp-gcalendar/sp_compatibility_test.php">compatibility utility</a>.<br>The following Simplepie error occurred:<br>' . $feed->error()); } $feed->handle_content_type(); $items = $feed->get_items(); foreach ($items as $item) { if ($item->get_id() == JRequest::getVar('eventID', null)) { return $item; } } return null; }
function getCalendarItems() { GCalendarUtil::ensureSPIsLoaded(); $params = $this->params; $calendarids = $params->get('calendarids'); $results = GCalendarDBUtil::getCalendars($calendarids); if (empty($results)) { JError::raiseWarning(500, 'The selected calendar(s) were not found in the database.'); return array(); } $values = array(); $sortOrder = $params->get('order', 1) == 1; $maxEvents = $params->get('max_events', 10); foreach ($results as $result) { if (!empty($result->calendar_id)) { $feed = new SimplePie_GCalendar(); $feed->set_show_past_events($params->get('past_events', TRUE)); $startDate = $params->get('start_date', ''); $endDate = $params->get('end_date', ''); if (!empty($startDate) && !empty($endDate)) { $feed->set_start_date(strtotime($startDate)); $feed->set_end_date(strtotime($endDate)); } $feed->set_sort_ascending(TRUE); $feed->set_orderby_by_start_date($sortOrder); $feed->set_expand_single_events($params->get('expand_events', TRUE)); $feed->enable_order_by_date(false); $conf =& JFactory::getConfig(); if ($params != null && ($params->get('gc_cache', 0) == 2 || $params->get('gc_cache', 0) == 1 && $conf->getValue('config.caching'))) { $cacheTime = $params->get('gccache_time', $conf->getValue('config.cachetime') * 60); // check if cache directory exists and is writeable $cacheDir = JPATH_BASE . DS . 'cache' . DS . $params->get('gc_cache_folder', ''); JFolder::create($cacheDir, 0755); if (!is_writable($cacheDir)) { JError::raiseWarning(500, "Created cache at " . $cacheDir . " is not writable, disabling cache."); $cache_exists = false; } else { $cache_exists = true; } //check and set caching $feed->enable_cache($cache_exists); if ($cache_exists) { $feed->set_cache_location($cacheDir); $feed->set_cache_duration($cacheTime); } } else { $feed->enable_cache(false); $feed->set_cache_duration(-1); } $feed->set_max_events($maxEvents); $feed->set_timezone(GCalendarUtil::getComponentParameter('timezone')); $feed->set_cal_language(GCalendarUtil::getFrLanguage()); $feed->set_cal_query($params->get('find', '')); $feed->put('gcid', $result->id); $feed->put('gcname', $result->name); $feed->put('gccolor', $result->color); $url = SimplePie_GCalendar::create_feed_url($result->calendar_id, $result->magic_cookie); $feed->set_feed_url($url); // Initialize the feed so that we can use it. $feed->init(); // echo $feed->feed_url; if ($feed->error()) { JError::raiseWarning(500, 'Simplepie detected an error. Please run the <a href="administrator/components/com_gcalendar/libraries/sp-gcalendar/sp_compatibility_test.php">compatibility utility</a>.', $feed->error()); } // Make sure the content is being served out to the browser properly. $feed->handle_content_type(); $values = array_merge($values, $feed->get_items()); } } // we sort the array based on the event compare function usort($values, array("SimplePie_Item_GCalendar", "compare")); $events = array_filter($values, array($this, "filter")); $offset = $params->get('offset', 0); $numevents = $params->get('count', $maxEvents); $events = array_slice($values, $offset, $numevents); //return the feed data structure for the template return $events; }
/** * Returns a Simplepie feed for the calendar according * to the parameter gcid. * If there is a menu available for this calendar the * cache is used and configured from the menu parameters. */ function getGoogleCalendarFeeds() { GCalendarUtil::ensureSPIsLoaded(); $startDate = JRequest::getVar('start', null); $endDate = JRequest::getVar('end', null); $browserTz = JRequest::getInt('browserTimezone', null); if (!empty($browserTz)) { $browserTz = $browserTz * 60; } else { $browserTz = 0; } $serverOffset = date('Z', $startDate); $startDate = $startDate - $browserTz - $serverOffset - GCalendarModelJSONFeed::getGCalendarTZOffset($startDate); $endDate = $endDate - $browserTz - $serverOffset - GCalendarModelJSONFeed::getGCalendarTZOffset($endDate); $calendarids = ''; if (JRequest::getVar('gcids', null) != null) { if (is_array(JRequest::getVar('gcids', null))) { $calendarids = JRequest::getVar('gcids', null); } else { $calendarids = explode(',', JRequest::getVar('gcids', null)); } } else { $calendarids = JRequest::getVar('gcid', null); } $results = GCalendarDBUtil::getCalendars($calendarids); if (empty($results)) { return null; } $calendars = array(); foreach ($results as $result) { if (empty($result->calendar_id)) { continue; } $feed = new SimplePie_GCalendar(); if (JRequest::getCmd('layout', null) == 'module') { $cacheTime = JRequest::getInt('ctime', -1); if ($cacheTime > -1) { // check if cache directory exists and is writeable $cacheDir = JPATH_BASE . DS . 'cache' . DS . 'mod_gcalendar'; $cache_exists = true; JFolder::create($cacheDir, 0755); if (!is_writable($cacheDir)) { JError::raiseWarning(500, "Created cache at " . $cacheDir . " is not writable, disabling cache."); $cache_exists = false; } else { $cache_exists = true; } $feed->enable_cache($cache_exists); if ($cache_exists) { $feed->set_cache_location($cacheDir); $feed->set_cache_duration($cacheTime); } } else { $feed->enable_cache(false); $feed->set_cache_duration(-1); } } else { $linkID = GCalendarUtil::getItemId($result->id); $menus =& JSite::getMenu(); $params = $menus->getParams($linkID); $conf =& JFactory::getConfig(); if ($params != null && ($params->get('gccache', 0) == 2 || $params->get('gccache', 0) == 1 && $conf->getValue('config.caching'))) { $cacheTime = $params->get('gccache_time', $conf->getValue('config.cachetime') * 60); // check if cache directory exists and is writeable $cacheDir = JPATH_BASE . DS . 'cache' . DS . 'com_gcalendar'; JFolder::create($cacheDir, 0755); if (!is_writable($cacheDir)) { JError::raiseWarning(500, "Created cache at " . $cacheDir . " is not writable, disabling cache."); $cache_exists = false; } else { $cache_exists = true; } //check and set caching $feed->enable_cache($cache_exists); if ($cache_exists) { $feed->set_cache_location($cacheDir); $feed->set_cache_duration($cacheTime); } } else { $feed->enable_cache(false); $feed->set_cache_duration(-1); } } $feed->set_show_past_events(FALSE); $feed->set_sort_ascending(TRUE); $feed->set_orderby_by_start_date(TRUE); $feed->set_expand_single_events(TRUE); $feed->enable_order_by_date(FALSE); $feed->set_start_date($startDate); $feed->set_end_date($endDate); $feed->set_max_events(1000); $feed->put('gcid', $result->id); $feed->put('gccolor', $result->color); $feed->put('gcname', $result->name); $feed->set_cal_language(GCalendarUtil::getFrLanguage()); $feed->set_timezone(GCalendarUtil::getComponentParameter('timezone')); $url = SimplePie_GCalendar::create_feed_url($result->calendar_id, $result->magic_cookie); $feed->set_feed_url($url); $feed->init(); //echo $feed->feed_url; if ($feed->error()) { JError::raiseWarning(500, 'Simplepie detected an error for the calendar ' . $result->calendar_id . '. Please run the <a href="administrator/components/com_gcalendar/libraries/sp-gcalendar/sp_compatibility_test.php">compatibility utility</a>.<br>The following Simplepie error occurred:<br>' . $feed->error()); } $feed->handle_content_type(); $calendars[] = $feed; } return $calendars; }
function getGoogleCalendarFeeds($startDate, $endDate, $projection = null) { GCalendarUtil::ensureSPIsLoaded(); $results = $this->getDBCalendars(); if (empty($results)) { return null; } $params = $this->getState('parameters.menu'); $useCache = false; $calendarids = array(); if ($params != null) { $useCache = $params->get('cache', 'no') == 'yes'; $tmp = $params->get('calendarids'); if (is_array($tmp)) { $calendarids = $tmp; } else { if (!empty($tmp)) { $calendarids[] = $tmp; } } } $calendars = array(); foreach ($results as $result) { if (empty($result->calendar_id)) { continue; } if (!empty($calendarids) && !in_array($result->id, $calendarids)) { continue; } $feed = new SimplePie_GCalendar(); $feed->set_show_past_events(FALSE); $feed->set_sort_ascending(TRUE); $feed->set_orderby_by_start_date(TRUE); $feed->set_expand_single_events(TRUE); $feed->enable_order_by_date(FALSE); $feed->enable_cache($useCache); if ($useCache) { // check if cache directory exists and is writeable $cacheDir = JPATH_BASE . DS . 'cache' . DS . 'com_gcalendar'; JFolder::create($cacheDir, 0755); if (!is_writable($cacheDir)) { JError::raiseWarning(500, "Created cache at " . $cacheDir . " is not writable, disabling cache."); $cache_exists = false; } else { $cache_exists = true; } //check and set caching $feed->enable_cache($cache_exists); if ($cache_exists) { $feed->set_cache_location($cacheDir); $cache_time = intval($params->get('cache_time', 3600)); $feed->set_cache_duration($cache_time); } } $feed->set_projection($projection); $feed->set_start_date($startDate); $feed->set_end_date($endDate); $feed->set_max_events(100); $feed->put('gcid', $result->id); $feed->put('gccolor', $result->color); $feed->put('gcname', $result->name); $feed->set_cal_language(GCalendarUtil::getFrLanguage()); $feed->set_timezone(GCalendarUtil::getComponentParameter('timezone')); $url = SimplePie_GCalendar::create_feed_url($result->calendar_id, $result->magic_cookie); $feed->set_feed_url($url); $feed->init(); $feed->handle_content_type(); $calendars[] = $feed; } return $calendars; }