Exemplo n.º 1
0
 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'));
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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));
 }
Exemplo n.º 6
0
 public function getDBCalendars()
 {
     if ($this->cached_data == null) {
         $calendars = GCalendarDBUtil::getAllCalendars();
         $this->cached_data = $calendars;
     }
     return $this->cached_data;
 }
Exemplo n.º 7
0
 protected function getOptions()
 {
     $accounts = GCalendarDBUtil::getAllCalendars();
     $options = array();
     foreach ($accounts as $account) {
         $options[] = JHtml::_('select.option', $account->id, $account->name);
     }
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 9
0
 /**
  * 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::getAllCalendars();
     }
     return $this->cached_data;
 }
Exemplo n.º 10
0
 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();
     }
 }
Exemplo n.º 11
0
 /**
  * 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;
 }
Exemplo n.º 12
0
 /**
  * Returns the database entries as objects with the column fields as
  * variable (according to the joomla table framework).
  *
  * @param $calendarIDs the calendar ID's to find
  */
 function getCalendars($calendarIDs)
 {
     $condition = '';
     if (!empty($calendarIDs)) {
         if (is_array($calendarIDs)) {
             $condition = 'id IN ( ' . rtrim(implode(',', $calendarIDs), ',') . ')';
         } else {
             $condition = 'id = ' . (int) rtrim($calendarIDs, ',');
         }
     } else {
         return GCalendarDBUtil::getAllCalendars();
     }
     $db =& JFactory::getDBO();
     $query = "SELECT id, calendar_id, name, color, magic_cookie  FROM #__gcalendar where " . $condition;
     $db->setQuery($query);
     $results = $db->loadObjectList();
     return $results;
 }
Exemplo n.º 13
0
function checkDB()
{
    $tmp = array();
    $results = GCalendarDBUtil::getAllCalendars();
    if (empty($results)) {
        $tmp[] = array('name' => 'DB Entries Check', 'description' => 'No DB data found.', 'status' => 'ok', 'solution' => '');
    } else {
        foreach ($results as $result) {
            $events = GCalendarZendHelper::getEvents($result, null, null, 5);
            if ($events == null) {
                $message = array_shift(JFactory::getApplication()->getMessageQueue());
                if (key_exists('message', $message)) {
                    $message = $message['message'];
                } else {
                    $message = print_r($message, true);
                }
                $desc = "An error occurred when reading calendar " . $result->name . ":<br>" . $message;
                $solution = "<ul><li>If the error is the same as in the connection test use the solution described there.</li>";
                $solution .= "<li>Please check your shared settings of the calendar and the events, ";
                $solution .= "if you do not share your calendar with the public the <a href=\"http://code.google.com/apis/calendar/docs/2.0/developers_guide_protocol.html#AuthMagicCookie\">magic cookie</a> field must be set.</li>";
                $solution .= "<li><b>If the problem still exists check the forum at <a href=\"http://g4j.digital-peak.com\">g4j.digital-peak.com</a>.</b></li></ul>";
                $status = 'failure';
            } else {
                if (empty($events)) {
                    $solution = 'Create events in the calendar.';
                    $status = 'warning';
                    $desc = 'GCalendar could check the events without any problems from calendar ' . $result->name . '. But the result was empty.';
                } else {
                    $solution = '';
                    $status = 'ok';
                    $desc = 'GCalendar could read the events without any problems from calendar ' . $result->name . '.';
                }
            }
            // 				$desc .= $desc.'<br><a href="'.$feed->feed_url.'" target="_blank">Here</a> is the url of the generated google calendar feed.';
            $tmp[] = array('name' => $result->name . ' Check', 'description' => $desc, 'status' => $status, 'solution' => $solution);
        }
    }
    return $tmp;
}
Exemplo n.º 14
0
 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;
 }
Exemplo n.º 15
0
 public static function getItemId($calendarId, $strict = false)
 {
     $component = JComponentHelper::getComponent('com_gcalendar');
     $menu = JFactory::getApplication()->getMenu();
     $items = $menu->getItems('component_id', $component->id);
     $default = null;
     if (is_array($items)) {
         foreach ($items as $item) {
             $default = $item;
             $paramsItem = $menu->getParams($item->id);
             $calendarids = $paramsItem->get('calendarids');
             if (empty($calendarids)) {
                 $results = GCalendarDBUtil::getAllCalendars();
                 if ($results) {
                     $calendarids = array();
                     foreach ($results as $result) {
                         $calendarids[] = $result->id;
                     }
                 }
             }
             $contains_gc_id = FALSE;
             if ($calendarids) {
                 if (is_array($calendarids)) {
                     $contains_gc_id = in_array($calendarId, $calendarids);
                 } else {
                     $contains_gc_id = $calendarId == $calendarids;
                 }
             }
             if ($contains_gc_id) {
                 return $item->id;
             }
         }
     }
     if ($strict = true) {
         return null;
     }
     return $default;
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 17
0
 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;
 }
Exemplo n.º 18
0
 /**
  * Returns a valid Item ID for the given calendar id. If none is found
  * NULL is returned.
  *
  * @param $cal_id
  * @return the item id
  */
 function getItemId($cal_id)
 {
     $component =& JComponentHelper::getComponent('com_gcalendar');
     $menu =& JSite::getMenu();
     $items = $menu->getItems('componentid', $component->id);
     if (is_array($items)) {
         foreach ($items as $item) {
             $paramsItem =& $menu->getParams($item->id);
             $calendarids = $paramsItem->get('calendarids');
             if (empty($calendarids)) {
                 $results = GCalendarDBUtil::getAllCalendars();
                 if ($results) {
                     $calendarids = array();
                     foreach ($results as $result) {
                         $calendarids[] = $result->id;
                     }
                 }
             }
             $contains_gc_id = FALSE;
             if ($calendarids) {
                 if (is_array($calendarids)) {
                     $contains_gc_id = in_array($cal_id, $calendarids);
                 } else {
                     $contains_gc_id = $cal_id == $calendarids;
                 }
             }
             if ($contains_gc_id) {
                 return $item->id;
             }
         }
     }
     return null;
 }
Exemplo n.º 19
0
$document->addStyleSheet(JURI::base() . 'components/com_gcalendar/libraries/jquery/fancybox/jquery.fancybox-1.3.4.css');
$document->addStyleSheet(JURI::base() . 'components/com_gcalendar/libraries/jquery/ext/tipTip.css');
$document->addStyleDeclaration("#ui-datepicker-div { z-index: 15 !important; }");
$document->addStyleSheet(JURI::base() . 'components/com_gcalendar/views/gcalendar/tmpl/gcalendar.css');
$params = $this->params;
$theme = $params->get('theme', '');
if (JRequest::getVar('theme', null) != null) {
    $theme = JRequest::getWord('theme', null);
}
if (!empty($theme)) {
    $document->addStyleSheet(JURI::base() . 'components/com_gcalendar/libraries/jquery/themes/' . $theme . '/jquery-ui.custom.css');
} else {
    $document->addStyleSheet(JURI::base() . 'components/com_gcalendar/libraries/jquery/themes/aristo/jquery-ui.custom.css');
}
$calendarids = $this->calendarids;
$allCalendars = GCalendarDBUtil::getAllCalendars();
$calsSources = "\t\teventSources: [\n";
foreach ($allCalendars as $calendar) {
    $cssClass = "gcal-event_gccal_" . $calendar->id;
    $color = GCalendarUtil::getFadedColor($calendar->color);
    $document->addStyleDeclaration("." . $cssClass . ",.fc-agenda " . $cssClass . " .fc-event-time, ." . $cssClass . " a, ." . $cssClass . " div{background-color: " . $color . " !important; border-color: #" . $calendar->color . "; color: white;}");
    if (empty($calendarids) || in_array($calendar->id, $calendarids)) {
        $value = html_entity_decode(JRoute::_('index.php?option=com_gcalendar&view=jsonfeed&format=raw&gcid=' . $calendar->id . '&Itemid=' . JRequest::getInt('Itemid')));
        $calsSources .= "\t\t\t\t'" . $value . "',\n";
    }
}
$calsSources = trim($calsSources, ",\n");
$calsSources .= "\t],\n";
$defaultView = $params->get('defaultView', 'month');
if ($params->get('defaultView', 'month') == 'week') {
    $defaultView = 'agendaWeek';
Exemplo n.º 20
0
 /**
  * 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;
 }
Exemplo n.º 21
0
 /**
  * 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;
 }
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
 public function getOriginalGCEvent()
 {
     if ($this->originalGCEvent != null) {
         return $this->originalGCEvent;
     }
     if (!$this->isRepeating()) {
         return null;
     }
     if ($this->getRecurrence() != null) {
         return $this;
     }
     $this->originalGCEvent = GCalendarZendHelper::getEvent(GCalendarDBUtil::getCalendar($this->getParam('gcid')), substr($this->getGCalId(), 0, strpos($this->getGCalId(), '_')));
     return $this->originalGCEvent;
 }