public function getGoogleCalendarFeeds() { $startDate = JRequest::getVar('start', null); $endDate = JRequest::getVar('end', null); $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; } $events = GCalendarZendHelper::getEvents($result, $startDate, $endDate, 1000); if ($events == null) { continue; } $calendars[] = $events; } return $calendars; }
public static function getCalendarItems($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(); } $orderBy = $params->get('order', 1) == 1 ? GCalendarZendHelper::ORDER_BY_START_TIME : GCalendarZendHelper::ORDER_BY_LAST_MODIFIED; $maxEvents = $params->get('max_events', 10); $filter = $params->get('find', ''); $startDate = $params->get('start_date', null); $endDate = $params->get('end_date', null); if (!empty($startDate)) { $startDate = strtotime($startDate); } if (!empty($endDate)) { $endDate = strtotime($endDate); } $values = array(); foreach ($results as $result) { $events = GCalendarZendHelper::getEvents($result, $startDate, $endDate, $maxEvents, $filter, $orderBy); if (!empty($events)) { foreach ($events as $event) { if (!$event instanceof GCalendar_Entry) { continue; } $values[] = $event; } } } usort($values, array("GCalendar_Entry", "compare")); return array_slice($values, 0, $maxEvents); }
public function onContentPrepare($context, &$article, &$params, $page = 0) { if (!$article->text) { return; } $calendarids = $this->params->get('calendarids'); $results = GCalendarDBUtil::getCalendars($calendarids); if (empty($results)) { return; } $maxEvents = $this->params->get('max_events', 10); $filter = $this->params->get('find', ''); $values = array(); foreach ($results as $result) { $events = GCalendarZendHelper::getEvents($result, null, null, $maxEvents, $filter); if (!empty($events)) { foreach ($events as $event) { if (!$event instanceof GCalendar_Entry) { continue; } $values[] = $event; } } } usort($values, array("GCalendar_Entry", "compare")); $values = array_slice($values, 0, $maxEvents); $article->text = GCalendarUtil::renderEvents($values, $article->text, JComponentHelper::getParams('com_gcalendar')); }
public static function getCalendarItems($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 null; } $orderBy = $params->get('order', 1) == 1 ? GCalendarZendHelper::ORDER_BY_START_TIME : GCalendarZendHelper::ORDER_BY_LAST_MODIFIED; $maxEvents = $params->get('max_events', 10); $filter = $params->get('find', ''); $titleFilter = $params->get('title_filter', '.*'); $values = array(); foreach ($results as $result) { $events = GCalendarZendHelper::getEvents($result, null, null, $maxEvents, $filter, $orderBy); if (!empty($events)) { foreach ($events as $event) { if (!$event instanceof GCalendar_Entry) { continue; } $event->setParam('moduleFilter', $titleFilter); $values[] = $event; } } } usort($values, array("GCalendar_Entry", "compare")); $events = array_filter($values, array('ModGCalendarNextHelper', "filter")); $offset = $params->get('offset', 0); $numevents = $params->get('count', $maxEvents); return array_shift($values); }
public function getGCalendar() { $results = GCalendarDBUtil::getCalendars(JRequest::getVar('gcid', null)); if (empty($results) || JRequest::getVar('eventID', null) == null) { return null; } return GCalendarZendHelper::getEvent($results[0], JRequest::getVar('eventID', null)); }
public function getDBCalendars() { if ($this->cached_data == null) { $calendarids = $this->getState('calendarids'); if (!empty($calendarids)) { $this->cached_data = GCalendarDBUtil::getCalendars($calendarids); } else { $this->cached_data = GCalendarDBUtil::getAllCalendars(); } } return $this->cached_data; }
public static function getCalendars($params) { $calendarids = null; if ($params != null) { $calendarids = $params->get('calendarids'); if (empty($calendarids)) { return GCalendarDBUtil::getAllCalendars(); } return GCalendarDBUtil::getCalendars($calendarids); } else { return GCalendarDBUtil::getAllCalendars(); } }
/** * Returns all calendars in the database. The returned * rows contain an additional attribute selected which is set * to true when the specific calendar is mentioned in the * parameters property calendarids. * * @return the calendars specified in the database */ function getDBCalendars() { if ($this->cached_data == null) { $params = $this->getState('parameters.menu'); $calendarids = null; if ($params != null) { $calendarids = $params->get('calendarids'); $this->cached_data = GCalendarDBUtil::getCalendars($calendarids); } else { $this->cached_data = GCalendarDBUtil::getAllCalendars(); } } return $this->cached_data; }
/** * Returns all calendars in the database. The returned * rows contain an additional attribute selected which is set * to true when the specific calendar is mentioned in the * parameters property calendarids. * * @return the calendars specified in the database */ function getDBCalendars() { if ($this->cached_data == null) { $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); } $this->cached_data = GCalendarDBUtil::getCalendars($calendarids); } return $this->cached_data; }
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; }
/** * Gets the calendar * @return string The calendar to be displayed to the user */ function getGCalendar() { $gcid = $this->getState('gcid'); $calendars = GCalendarDBUtil::getCalendars($gcid); return $calendars; }
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $user = JFactory::getUser(); $text = trim($text); if ($text == '') { return array(); } if ($phrase == 'exact') { $text = "\"" . $text . "\""; } switch ($ordering) { case 'oldest': $orderasc = GCalendarZendHelper::SORT_ORDER_ASC; break; case 'newest': default: $orderasc = GCalendarZendHelper::SORT_ORDER_DESC; } if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } $pluginParams = $this->params; $limit = $pluginParams->def('search_limit', 50); $calendarids = $pluginParams->get('calendarids', NULL); $pastevents = $pluginParams->get('pastevents', 1) == 1; $results = GCalendarDBUtil::getCalendars($calendarids); if (empty($results)) { return array(); } $events = array(); foreach ($results as $result) { $tmp = GCalendarZendHelper::getEvents($result, null, null, $limit, $text, GCalendarZendHelper::ORDER_BY_START_TIME, $pastevents, $orderasc); foreach ($tmp as $event) { $events[] = $event; } } if ($orderasc == GCalendarZendHelper::SORT_ORDER_ASC) { usort($events, array("GCalendar_Entry", "compare")); } else { usort($events, array("GCalendar_Entry", "compareDesc")); } array_splice($events, $limit); $return = array(); foreach ($events as $event) { $params = clone JComponentHelper::getParams('com_gcalendar'); $title = GCalendarUtil::renderEvents(array($event), '{{#events}}{{date}} {{{title}}}{{/events}}', $params); $text = GCalendarUtil::renderEvents(array($event), '{{#events}}{{{description}}}{{/events}}', $params); $itemID = GCalendarUtil::getItemId($event->getParam('gcid')); if (!empty($itemID)) { $itemID = '&Itemid=' . $itemID; } $row->href = JRoute::_('index.php?option=com_gcalendar&view=event&eventID=' . $event->getGCalId() . '&gcid=' . $event->getParam('gcid') . $itemID); $row->title = $title; $row->text = $text; $row->section = JText::_('PLG_SEARCH_GCALENDAR_OUTPUT_CATEGORY'); $row->category = $event->getParam('gcid'); $row->created = $event->getStartDate()->format('U', true); $row->browsernav = ''; $return[] = $row; $row = null; } return $return; }