Esempio n. 1
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;
 }
Esempio n. 2
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'));
 }
Esempio 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);
 }
Esempio n. 5
0
 public function getOnlineData()
 {
     try {
         $user = JRequest::getVar('user', null);
         $pass = JRequest::getVar('pass', null);
         $calendars = GCalendarZendHelper::getCalendars($user, $pass);
         if ($calendars == null) {
             return null;
         }
         $this->_data = array();
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_gcalendar/tables');
         foreach ($calendars as $calendar) {
             $table =& $this->getTable('Import', 'GCalendarTable');
             $table->id = 0;
             $cal_id = substr($calendar->getId(), strripos($calendar->getId(), '/') + 1);
             $table->calendar_id = $cal_id;
             $table->username = $user;
             $table->password = $pass;
             $table->name = (string) $calendar->getTitle();
             if (strpos($calendar->getColor(), '#') === 0) {
                 $color = str_replace("#", "", (string) $calendar->getColor());
                 $table->color = $color;
             }
             $this->_data[] = $table;
         }
     } catch (Exception $e) {
         JError::raiseWarning(200, $e->getMessage());
         $this->_data = null;
     }
     return $this->_data;
 }
Esempio n. 6
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));
 }
Esempio n. 7
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;
}
Esempio n. 8
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;
 }
            $query->setParam('hl', GCalendarUtil::getFrLanguage());
            $event = $service->getEntry($query, 'GCalendar_Entry');
            $event->setParam('gcid', $calendar->id);
            $event->setParam('gccolor', $calendar->color);
            $event->setParam('gcname', $calendar->name);
            return $event;
        } catch (Zend_Gdata_App_Exception $e) {
            JError::raiseWarning(200, $e->getMessage());
            return null;
        }
    }
    public static function loadZendClasses()
    {
        static $zendLoaded;
        if ($zendLoaded == null) {
            ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_gcalendar' . DIRECTORY_SEPARATOR . 'libraries');
            if (!class_exists('Zend_Loader')) {
                require_once 'Zend/Loader.php';
            }
            Zend_Loader::loadClass('Zend_Gdata_AuthSub');
            Zend_Loader::loadClass('Zend_Gdata_HttpClient');
            Zend_Loader::loadClass('Zend_Gdata_Calendar');
            Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
            Zend_Loader::loadClass('GCalendar_Feed');
            Zend_Loader::loadClass('GCalendar_Entry');
            $zendLoaded = true;
        }
    }
}
GCalendarZendHelper::loadZendClasses();
Esempio n. 10
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;
 }