Пример #1
0
function checkDB()
{
    $tmp = array();
    $db =& JFactory::getDBO();
    $query = "SELECT id, calendar_id, name, color, magic_cookie  FROM #__gcalendar";
    $db->setQuery($query);
    $results = $db->loadObjectList();
    if (empty($results)) {
        $tmp[] = array('name' => 'DB Entries Check', 'description' => 'No DB data found.', 'status' => 'ok', 'solution' => '');
    } else {
        foreach ($results as $result) {
            $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_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();
            $data = $feed->get_items();
            if ($feed->error()) {
                $desc = "The following Simplepie error occurred when reading calendar " . $result->name . ":<br>" . $feed->error();
                $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>Run the <a href=\"components/com_gcalendar/libraries/sp-gcalendar/sp_compatibility_test.php\">simplepie compatibility test</a> and check if your system does meet the minimum requirements of simplepie.</li>";
                $solution .= "<li><b>If the problem still exists check the forum at <a href=\"http://g4j.laoneo.net\">g4j.laoneo.net</a>.</b></li>";
                $status = 'failure';
            } else {
                if (empty($data)) {
                    $solution = 'Create events in the calendar.';
                    $status = 'warning';
                    $desc = 'Simplepie could check the events without any problems from calendar ' . $result->name . '. But the result was empty.';
                } else {
                    $solution = '';
                    $status = 'ok';
                    $desc = 'Simplepie 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;
}
Пример #2
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;
 }
Пример #3
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;
 }
Пример #4
0
$feed->set_expand_single_events(1);
$feed->set_start_min_date($startMin);
$feed->set_start_max_date($startMax);
$feed->set_max_results();
$feed->set_cal_query();
/* SimplePie Parameters */
if ($useCache) {
    $feed->set_cache_location($basePath . 'cache');
} else {
    $feed->enable_cache(false);
}
$feed->set_feed_url($urls);
$feed->enable_order_by_date(FALSE);
$feed->init();
$feed->handle_content_type();
$gcalendar_data = $feed->get_items();
$cal_dates = array();
for ($i = 0; $i < sizeof($gcalendar_data); $i++) {
    $item = $gcalendar_data[$i];
    /*
            if ($i == 1):
            	echo '<pre>';
            	print_r($gcalendar_data[$i]);
            	echo '</pre>';
            endif;
    */
    $startDate = $item->get_start_time();
    $endDate = $item->get_end_time();
    $calName = $item->get_name();
    $cal_dates[] = array('sortDate' => $item->get_start_time(), 'startDate' => date("M j, y g:i", $startDate - $offset), 'endDate' => date("M j, y g:i", $endDate - $offset), 'pubDate' => date("M j, y g:i", $item->get_publish_date()), 'title' => $item->get_title(), 'where' => $item->get_location(), 'link' => $item->get_link(), 'status' => $item->get_status(), 'description' => $item->get_description(), 'startDay' => date('j', $startDate - $offset), 'startMonth' => date('n', $startDate - $offset), 'startYear' => date('Y', $startDate - $offset), 'startHour' => date('g', $startDate - $offset), 'startMinute' => date('i', $startDate - $offset), 'startMeridiem' => date('A', $startDate - $offset), 'endDay' => date('j', $endDate - $offset), 'endMonth' => date('n', $endDate - $offset), 'endYear' => date('Y', $endDate - $offset), 'endHour' => date('g', $endDate - $offset), 'endMinute' => date('i', $endDate - $offset), 'endMeridiem' => date('A', $endDate - $offset), 'calName' => $calName, 'calNameClean' => str_replace(' ', '-', strtolower($calName)), 'calEmail' => $item->get_email());
}