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')); }
/** * GCalendars view display method * @return void **/ function display($tpl = null) { GCalendarUtil::ensureSPIsLoaded(); JToolBarHelper::title(JText::_('GCALENDAR_MANAGER'), 'calendar'); JToolBarHelper::preferences('com_gcalendar', 550); parent::display($tpl); }
/** * @param array * @return array */ function GCalendarParseRoute($segments) { // Get the active menu item $menu = JFactory::getApplication()->getMenu(); $item = $menu->getActive(); $vars = array(); $view = $segments[0]; //if the view is calendars it is a menu link if ($view == 'calendars') { $view = $item->query['view']; } $vars['view'] = $view; switch ($view) { case 'event': $vars['gcid'] = $segments[1]; $vars['eventID'] = $segments[2]; $vars['Itemid'] = GCalendarUtil::getItemId($segments[2]); break; case 'google': case 'gcalendar': // do nothing break; } return $vars; }
public function display($tpl = null) { JToolBarHelper::title(JText::_('COM_GCALENDAR_MANAGER_GCALENDAR'), 'calendar'); $canDo = GCalendarUtil::getActions(); if ($canDo->get('core.create')) { JToolBarHelper::addNew('gcalendar.add', 'JTOOLBAR_NEW'); JToolBarHelper::custom('import', 'upload.png', 'upload.png', 'COM_GCALENDAR_VIEW_GCALENDARS_BUTTON_IMPORT', false); } if ($canDo->get('core.edit')) { JToolBarHelper::editList('gcalendar.edit', 'JTOOLBAR_EDIT'); } if ($canDo->get('core.delete')) { JToolBarHelper::deleteList('', 'gcalendars.delete', 'JTOOLBAR_DELETE'); } if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_gcalendar', 550); JToolBarHelper::divider(); } $items = $this->get('Items'); $pagination = $this->get('Pagination'); if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode('<br />', $errors)); return false; } $this->items = $items; $this->pagination = $pagination; parent::display($tpl); }
public function display($tpl = null) { JToolBarHelper::title(JText::_('COM_GCALENDAR'), 'calendar'); $canDo = GCalendarUtil::getActions(); if ($canDo->get('core.admin')) { JToolBarHelper::preferences('com_gcalendar', 550); JToolBarHelper::divider(); } parent::display($tpl); }
public function display($tpl = null) { JToolBarHelper::title(JText::_('COM_GCALENDAR_MANAGER_GCALENDAR'), 'calendar'); if (JRequest::getWord('layout') != 'login') { $canDo = GCalendarUtil::getActions(); if ($canDo->get('core.create')) { JToolBarHelper::custom('import.save', 'new.png', 'new.png', 'COM_GCALENDAR_VIEW_IMPORT_BUTTON_ADD', false); } JToolBarHelper::cancel('gcalendar.cancel', 'JTOOLBAR_CANCEL'); $this->onlineItems = $this->get('OnlineData'); $this->dbItems = $this->get('DBData'); } JRequest::setVar('hidemainmenu', 0); parent::display($tpl); }
/** * @param array * @return array */ function GCalendarParseRoute($segments) { // Get the active menu item $menu =& JSite::getMenu(); $item =& $menu->getActive(); $vars = array(); $view = $segments[0]; //if the view is calendars it is a menu link if ($view == 'calendars') { $view = $item->query['view']; } $vars['view'] = $view; switch ($view) { case 'event': $vars['eventID'] = $segments[1]; $vars['gcid'] = $segments[2]; $vars['Itemid'] = GCalendarUtil::getItemId($segments[2]); break; case 'day': $vars['gcids'] = explode("-", $segments[2]); $calids = $vars['gcids']; if (count($calids) > 0) { $itemid = GCalendarUtil::getItemId($calids[0]); foreach ($calids as $cal) { $id = GCalendarUtil::getItemId($cal); if ($id != $itemid) { $itemid = null; break; } } if ($itemid != null) { $vars['Itemid'] = $itemid; } } break; case 'google': case 'gcalendar': // do nothing break; } return $vars; }
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(); 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://gcalendar.laoneo.net\">gcalendar.laoneo.net</a>.</b></li>"; $status = 'failure'; } else { $solution = ''; $status = 'ok'; $desc = 'Simplepie could read the events without any problems from calendar ' . $result->name . '.'; } $tmp[] = array('name' => $result->name . ' Check', 'description' => $desc, 'status' => $status, 'solution' => $solution); } } return $tmp; }
public function getInput() { $document =& JFactory::getDocument(); $document->addScript(JURI::base() . 'components/com_gcalendar/libraries/jscolor/jscolor.js'); $buffer = "<input type=\"text\" name=\"" . $this->name . "\" id=\"" . $this->id . "\" readonly=\"readonly\" class=\"inputbox\" \n"; $buffer .= "size=\"100%\" value=\"" . $this->value . "\" style=\"background-color: " . GCalendarUtil::getFadedColor($this->value) . "\" />\n"; $buffer .= "<br CLEAR=\"both\"/><label id=\"jform_colors-lbl\" title=\"\" for=\"jform_color\"></label><table><tbody>\n"; for ($i = 0; $i < count($this->googleColors); $i++) { if ($i % 7 == 0) { $buffer .= "<tr>\n"; } $c = $this->googleColors[$i]; $cFaded = GCalendarUtil::getFadedColor($c); $buffer .= "<td onmouseover=\"this.style.cursor='pointer'\" onclick=\"document.getElementById('" . $this->id . "').style.backgroundColor = '" . $cFaded . "';document.getElementById('" . $this->id . "').value = '" . $c . "';\" style=\"background-color: " . $cFaded . ";width: 20px;\"></td><td>" . $c . "</td>\n"; if ($i % 7 == 6) { $buffer .= "</tr>\n"; } } $buffer .= "</tbody></table>\n"; return $buffer; }
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; }
public function display($tpl = null) { $this->form = $this->get('Form'); $this->gcalendar = $this->get('Item'); if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode('<br />', $errors)); return false; } //get the calendar $isNew = $this->gcalendar->id < 1; JToolBarHelper::title(JText::_('COM_GCALENDAR_MANAGER_GCALENDAR'), 'calendar'); JRequest::setVar('hidemainmenu', true); $canDo = GCalendarUtil::getActions($this->gcalendar->id); if ($isNew) { if ($canDo->get('core.create')) { JToolBarHelper::apply('gcalendar.apply', 'JTOOLBAR_APPLY'); JToolBarHelper::save('gcalendar.save', 'JTOOLBAR_SAVE'); JToolBarHelper::custom('gcalendar.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false); } JToolBarHelper::cancel('gcalendar.cancel', 'JTOOLBAR_CANCEL'); } else { if ($canDo->get('core.edit')) { // We can save the new record JToolBarHelper::apply('gcalendar.apply', 'JTOOLBAR_APPLY'); JToolBarHelper::save('gcalendar.save', 'JTOOLBAR_SAVE'); // We can save this record, but check the create permission to see if we can return to make a new one. if ($canDo->get('core.create')) { JToolBarHelper::custom('gcalendar.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false); } } if ($canDo->get('core.create')) { JToolBarHelper::custom('gcalendar.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false); } JToolBarHelper::cancel('gcalendar.cancel', 'JTOOLBAR_CLOSE'); } parent::display($tpl); }
$daysMin = "["; $monthsLong = "["; $monthsShort = "["; for ($i = 0; $i < 7; $i++) { $daysLong .= "'" . GCalendarUtil::dayToString($i, false) . "'"; $daysShort .= "'" . GCalendarUtil::dayToString($i, true) . "'"; $daysMin .= "'" . substr(GCalendarUtil::dayToString($i, true), 0, 2) . "'"; if ($i < 6) { $daysLong .= ","; $daysShort .= ","; $daysMin .= ","; } } for ($i = 1; $i <= 12; $i++) { $monthsLong .= "'" . GCalendarUtil::monthToString($i, false) . "'"; $monthsShort .= "'" . GCalendarUtil::monthToString($i, true) . "'"; if ($i < 12) { $monthsLong .= ","; $monthsShort .= ","; } } $daysLong .= "]"; $daysShort .= "]"; $daysMin .= "]"; $monthsLong .= "]"; $monthsShort .= "]"; $calCode = "// <![CDATA[ \n"; $calCode .= "jQuery(document).ready(function(){\n"; $calCode .= "\tvar today = new Date();\n"; $calCode .= "\tvar tmpYear = today.getFullYear();\n"; $calCode .= "\tvar tmpMonth = today.getMonth();\n";
/** * Checks if the DST applyes to the timezone of GCalendar for the given date. * * @param $date unix timestamp * @param $tz the timezone * @return if is DST */ function isDST($date, $tz = null) { if (empty($tz)) { $tz = GCalendarUtil::getComponentParameter('timezone'); } if (class_exists('DateTimeZone') && !empty($tz)) { $gtz = new DateTimeZone($tz); return $gtz->getOffset(new DateTime('2007-01-01 01:00')) != $gtz->getOffset(new DateTime(strftime('%Y-%m-%d %H:%M', $date))) ? true : false; } return false; }
function checkTimezones() { $defaultTZ = ini_get('date.timezone'); if (function_exists('date_default_timezone_get')) { $defaultTZ = date_default_timezone_get(); } if (empty($defaultTZ)) { $defaultTZ = 'empty'; } $gcalendarTZ = GCalendarUtil::getComponentParameter('timezone'); if (empty($gcalendarTZ)) { $gcalendarTZ = 'empty'; } $desc = "Your default timezone is " . $defaultTZ . " and the GCalendar timezone is " . $gcalendarTZ . ". They are the same which means you should have no problems with date issues."; $status = 'ok'; $solution = ''; if ($defaultTZ != $gcalendarTZ) { $desc = "Your default timezone is " . $defaultTZ . " and the GCalendar timezone is " . $gcalendarTZ . ". They are not the same which means you can run into some date issues."; $status = 'warning'; $solution = 'Set the timezone propriate timezone in the GCalendar preferences or the <a href="http://php.net/manual/en/function.date-default-timezone-get.php" target="_blank">default timezone</a>.'; } return array('name' => 'Timezone Check', 'description' => $desc, 'status' => $status, 'solution' => $solution); }
if (!empty($gcalendar_data)) { if ($params->get('images', 'no') != 'no') { echo '<p style="clear: both;"/>'; } foreach ($gcalendar_data as $item) { // APRIL 2010 MOD - CALENDAR IMAGES by Tyson Moore if ($params->get('images', 'no') != 'no') { $tmp = JFactory::getDate($item->get_start_date()); $month_text = strtoupper(GCalendarUtil::monthToString($tmp->toFormat('%m'), true)); $day = $tmp->toFormat('%d'); $feed = $item->get_feed(); $colorImageBackground = $params->get('images', 'yes') == 'custom' ? '#' . $params->get('calimage_background') : GCalendarUtil::getFadedColor($feed->get('gccolor'), 80); $colorMonth = $params->get('images', 'yes') == 'custom' ? $params->get('calimage_month') : 'FFFFFF'; $colorDay = $params->get('images', 'yes') == 'custom' ? $params->get('calimage_day') : $feed->get('gccolor'); echo '<div class="gc_up_mod_img">'; echo '<div class="gc_up_mod_month_background" style="background-color: ' . $colorImageBackground . ';"></div>'; echo '<div class="gc_up_mod_month_text" style="color: #' . $colorMonth . ';">' . $month_text . '</div>'; echo '<div class="gc_up_mod_day" style="color: #' . $colorDay . ';">' . $day . '</div>'; echo '</div>'; } //END MOD echo GCalendarUtil::renderEvent($item, $event_display, $dateformat, $timeformat); if ($params->get('images', 'no') != 'no') { echo '<p style="clear: both;"/>'; } } } echo $params->get('text_after'); ?>
/** * Returns the faded color for the given color. * * @param $color * @param $percentage * @return the faded color */ function getFadedColor($color, $percentage = 85) { $percentage = 100 - $percentage; $rgbValues = array_map('hexDec', GCalendarUtil::str_split(ltrim($color, '#'), 2)); for ($i = 0, $len = count($rgbValues); $i < $len; $i++) { $rgbValues[$i] = decHex(floor($rgbValues[$i] + (255 - $rgbValues[$i]) * ($percentage / 100))); } return '#' . implode('', $rgbValues); }
* You should have received a copy of the GNU General Public License * along with GCalendar. If not, see <http://www.gnu.org/licenses/>. * * @author Allon Moritz * @copyright 2007-2009 Allon Moritz * @version $Revision: 2.1.2 $ */ defined('_JEXEC') or die('Restricted access'); require_once 'daycalendar.php'; $model =& $this->getModel(); $gcids = $model->getState('gcids'); $itemID = null; if (!empty($gcids)) { $itemID = GCalendarUtil::getItemId($gcids[0]); foreach ($gcids as $cal) { $id = GCalendarUtil::getItemId($cal); if ($id != $itemID) { $itemID = null; break; } } if ($itemID != null) { $component =& JComponentHelper::getComponent('com_gcalendar'); $menu =& JSite::getMenu(); $item = $menu->getItem($itemID); $backLinkView = $item->query['view']; echo "<table><tr><td valign=\"middle\">\n"; echo '<a href="' . JRoute::_('index.php?option=com_gcalendar&view=' . $backLinkView . '&Itemid=' . $itemID) . "\">\n"; echo "<img id=\"prevBtn_img\" height=\"16\" border=\"0\" width=\"16\" alt=\"backlink\" src=\"components/com_gcalendar/hiddenviews/day/tmpl/back.png\"/>\n"; echo "</a></td><td valign=\"middle\">\n"; echo '<a href="' . JRoute::_('index.php?option=com_gcalendar&view=' . $backLinkView . '&Itemid=' . $itemID) . '">' . JText::_('CALENDAR_BACK_LINK') . "</a>\n";
</td> <td class="nowrap has-context"> <a href="<?php echo JRoute::_('index.php?option=com_gcalendar&task=gcalendar.edit&id=' . $item->id); ?> " title="<?php echo JText::_('JACTION_EDIT'); ?> "> <?php echo $this->escape($item->name); ?> </a> </td> <td class="nowrap has-context"><div style="background-color: <?php echo GCalendarUtil::getFadedColor($item->color); ?> ;width:40px;height:20px"></div></td> <td class="nowrap has-context"> <?php echo urldecode($item->calendar_id); ?> </td> <td class="nowrap has-context"> <?php if (!empty($item->magic_cookie)) { echo JText::_('COM_GCALENDAR_FIELD_MAGIC_COOKIE_LABEL'); } else { if (!empty($item->username)) { echo JText::_('COM_GCALENDAR_VIEW_GCALENDARS_COLUMN_AUTHENTICATION_USERNAME'); } else {
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; }
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GCalendar. If not, see <http://www.gnu.org/licenses/>. * * @author Allon Moritz * @copyright 2007-2011 Allon Moritz * @since 2.2.0 */ defined('_JEXEC') or die('Restricted access'); $tmp = clone JComponentHelper::getParams('com_gcalendar'); $tmp->set('event_date_format', $params->get('date_format', $tmp->get('event_date_format'))); $tmp->set('event_time_format', $params->get('time_format', $tmp->get('event_time_format'))); $tmp->set('grouping', $params->get('output_grouping', '')); $output = $params->get('output', '{{#events}} {{#header}}<p style="clear: both;"><strong>{{header}}</strong></p>{{/header}} <p style="clear: both;"/> <div style="float:left;margin-right:6px;width:42px;height:42px;background-image:url(\'modules/mod_gcalendar_upcoming/tmpl/images/calendar-icon.gif\')"> <div style="background-color: #{{calendarcolor}};width:32px;height:10px;margin-top:6px;margin-left:5px;"></div> <div style="color: #FFFFFF;padding:2px;font-weight:bold;font-size:10px;text-align:center;position:relative;margin-top:-16px;margin-bottom:-4px;">{{month}}</div> <div style="color: #{{calendarcolor}};font-weight:bold;font-size:1.3em;width:42px;text-align:center;">{{day}}</div> </div> <p>{{date}}<br/><a href="{{{backlink}}}">{{title}}</a></p> <p style="clear: both;"/> {{/events}} {{^events}} {{emptyText}} {{/events}}'); echo GCalendarUtil::renderEvents($events, $output, $tmp);
} foreach ($calendar as $event) { $dateformat = $params->get('description_date_format', 'm.d.Y'); $timeformat = $params->get('description_time_format', 'g:i a'); $params->set('event_date_format', $dateformat); $params->set('event_time_format', $timeformat); if (!empty($itemID)) { $itemID = '&Itemid=' . $itemID; } else { $menu = JFactory::getApplication()->getMenu(); $activemenu = $menu->getActive(); if ($activemenu != null) { $itemID = '&Itemid=' . $activemenu->id; } } $description = GCalendarUtil::renderEvents(array($event), $params->get('description_format', '{{#events}}<p>{{date}}<br/>{{{description}}}</p>{{/events}}'), $params); if (strlen($description) > 200) { $description = mb_substr($description, 0, 196) . ' ...'; } $allDayEvent = $event->getDayType() == GCalendar_Entry::SINGLE_WHOLE_DAY || $event->getDayType() == GCalendar_Entry::MULTIPLE_WHOLE_DAY; $end = $event->getEndDate(); if ($allDayEvent) { $end = clone $event->getEndDate(); $end->modify('-1 day'); } $eventData = array('id' => $event->getGCalId(), 'gcid' => $event->getParam('gcid'), 'title' => htmlspecialchars_decode($event->getTitle()), 'start' => $event->getStartDate()->format('Y-m-d\\TH:i:s', true), 'end' => $end->format('Y-m-d\\TH:i:s', true), 'url' => JRoute::_('index.php?option=com_gcalendar&view=event&eventID=' . $event->getGCalId() . '&gcid=' . $event->getParam('gcid') . (empty($itemID) ? '' : $itemID)), 'className' => "gcal-event_gccal_" . $event->getParam('gcid'), 'allDay' => $allDayEvent, 'description' => $description); $dispatcher->trigger('onGCEventBeforeLoad', array($event, &$eventData)); $data[] = $eventData; } } }
$calCode .= "var eventResizeCustom = function(event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, view){};\n"; $calCode .= "// ]]>\n"; $document->addScriptDeclaration($calCode); echo JHTML::_('content.prepare', $params->get('textbefore')); if ($params->get('show_selection', 1) == 1 || $params->get('show_selection', 1) == 3) { $document->addScript(JURI::base() . 'components/com_gcalendar/views/gcalendar/tmpl/gcalendar.js'); $calendar_list = '<div id="gc_gcalendar_view_list"><table class="gcalendar-table">'; foreach ($allCalendars as $calendar) { $value = html_entity_decode(JRoute::_('index.php?option=com_gcalendar&view=jsonfeed&format=raw&gcid=' . $calendar->id)); $checked = ''; if (empty($calendarids) || in_array($calendar->id, $calendarids)) { $checked = 'checked="checked"'; } $calendar_list .= "<tr>\n"; $calendar_list .= "<td><input type=\"checkbox\" name=\"" . $calendar->calendar_id . "\" value=\"" . $value . "\" " . $checked . " onclick=\"updateGCalendarFrame(this)\"/></td>\n"; $calendar_list .= "<td><font color=\"" . GCalendarUtil::getFadedColor($calendar->color) . "\">" . $calendar->name . "</font></td></tr>\n"; } $calendar_list .= "</table></div>\n"; echo $calendar_list; echo "<div align=\"center\" style=\"text-align:center\">\n"; $image = JURI::base() . 'media/com_gcalendar/images/down.png'; if ($params->get('show_selection', 1) == 3) { $image = JURI::base() . 'media/com_gcalendar/images/up.png'; } echo "<img id=\"gc_gcalendar_view_toggle_status\" name=\"gc_gcalendar_view_toggle_status\" src=\"" . $image . "\" alt=\"" . JText::_('COM_GCALENDAR_GCALENDAR_VIEW_CALENDAR_LIST') . "\" title=\"" . JText::_('COM_GCALENDAR_GCALENDAR_VIEW_CALENDAR_LIST') . "\"/>\n"; echo "</div>\n"; } echo "<div id='gcalendar_component_loading' style=\"text-align: center;\"><img src=\"" . JURI::base() . "media/com_gcalendar/images/ajax-loader.gif\" alt=\"loader\" /></div>"; echo "<div id='gcalendar_component'></div><div id='gcalendar_component_popup' style=\"visibility:hidden\" ></div>"; echo JHTML::_('content.prepare', $params->get('textafter')); $dispatcher = JDispatcher::getInstance();
public static function renderEvents(array $events = null, $output, $params = null, $eventParams = array()) { if ($events === null) { $events = array(); } JFactory::getLanguage()->load('com_gcalendar', JPATH_ADMINISTRATOR . '/components/com_gcalendar'); $lastHeading = ''; $configuration = $eventParams; $configuration['events'] = array(); foreach ($events as $event) { if (!is_object($event)) { continue; } $variables = array(); $itemID = GCalendarUtil::getItemId($event->getParam('gcid', null)); if (!empty($itemID) && JRequest::getVar('tmpl', null) != 'component' && $event != null) { $component = JComponentHelper::getComponent('com_gcalendar'); $menu = JFactory::getApplication()->getMenu(); $item = $menu->getItem($itemID); if ($item != null) { $backLinkView = $item->query['view']; $dateHash = ''; if ($backLinkView == 'gcalendar') { $day = $event->getStartDate()->format('d', true); $month = $event->getStartDate()->format('m', true); $year = $event->getStartDate()->format('Y', true); $dateHash = '#year=' . $year . '&month=' . $month . '&day=' . $day; } } $variables['calendarLink'] = JRoute::_('index.php?option=com_gcalendar&Itemid=' . $itemID . $dateHash); } $itemID = GCalendarUtil::getItemId($event->getParam('gcid')); if (!empty($itemID)) { $itemID = '&Itemid=' . $itemID; } else { $menu = JFactory::getApplication()->getMenu(); $activemenu = $menu->getActive(); if ($activemenu != null) { $itemID = '&Itemid=' . $activemenu->id; } } $variables['backlink'] = JRoute::_('index.php?option=com_gcalendar&view=event&eventID=' . $event->getGCalId() . '&gcid=' . $event->getParam('gcid') . $itemID); $variables['link'] = $event->getLink('alternate')->getHref(); $variables['calendarcolor'] = $event->getParam('gccolor'); // the date formats from http://php.net/date $dateformat = $params->get('event_date_format', 'm.d.Y'); $timeformat = $params->get('event_time_format', 'g:i a'); // These are the dates we'll display $startDate = $event->getStartDate()->format($dateformat, true); $startTime = $event->getStartDate()->format($timeformat, true); $endDate = $event->getEndDate()->format($dateformat, true); $endTime = $event->getEndDate()->format($timeformat, true); $dateSeparator = '-'; $timeString = $startTime . ' ' . $startDate . ' ' . $dateSeparator . ' ' . $endTime . ' ' . $endDate; $copyDateTimeFormat = 'Ymd'; switch ($event->getDayType()) { case GCalendar_Entry::SINGLE_WHOLE_DAY: $timeString = $startDate; $copyDateTimeFormat = 'Ymd'; $startTime = ''; $endTime = ''; $dateSeparator = ''; break; case GCalendar_Entry::SINGLE_PART_DAY: $timeString = $startDate . ' ' . $startTime . ' ' . $dateSeparator . ' ' . $endTime; $copyDateTimeFormat = 'Ymd\\THis'; break; case GCalendar_Entry::MULTIPLE_WHOLE_DAY: $tmp = clone $event->getEndDate(); $tmp->modify('-1 day'); $endDate = $tmp->format($dateformat, true); $timeString = $startDate . ' ' . $dateSeparator . ' ' . $endDate; $copyDateTimeFormat = 'Ymd'; $startTime = ''; $endTime = ''; break; case GCalendar_Entry::MULTIPLE_PART_DAY: $timeString = $startTime . ' ' . $startDate . ' ' . $dateSeparator . ' ' . $endTime . ' ' . $endDate; $copyDateTimeFormat = 'Ymd\\THis'; break; } $variables['calendarName'] = $event->getParam('gcname'); $variables['title'] = (string) $event->getTitle(); if ($params->get('show_event_date', 1) == 1) { $variables['date'] = $timeString; $variables['startDate'] = $startDate; $variables['startTime'] = $startTime; $variables['endDate'] = $endDate; $variables['endTime'] = $endTime; $variables['dateseparator'] = $dateSeparator; $variables['month'] = strtoupper($event->getStartDate()->format('M', true)); $variables['day'] = $event->getStartDate()->format('j', true); } $variables['modifieddate'] = $event->getModifiedDate()->format($timeformat, true) . ' ' . $event->getModifiedDate()->format($dateformat, true); if (count($event->getWho()) > 0) { $variables['hasAttendees'] = true; $variables['attendees'] = array(); foreach ($event->getWho() as $a) { $variables['attendees'][] = array('name' => (string) $a->getValueString(), 'email' => base64_encode(str_replace('@', '#', $a->getEmail()))); } } $location = $event->getLocation(); $variables['location'] = $location; if (!empty($location)) { $variables['maplink'] = (JBrowser::getInstance()->isSSLConnection() ? 'https' : 'http') . "://maps.google.com/?q=" . urlencode($location) . '&hl=' . substr(GCalendarUtil::getFrLanguage(), 0, 2) . '&output=embed'; } $variables['description'] = (string) $event->getContent(); if ($params->get('event_description_format', 1) == 1) { $variables['description'] = preg_replace("@(src|href)=\"https?://@i", '\\1="', $event->getContent()); $variables['description'] = nl2br(preg_replace("@(((f|ht)tp:\\/\\/)[^\"\\'\\>\\s]+)@", '<a href="\\1" target="_blank">\\1</a>', $variables['description'])); } $variables['hasAuthor'] = count($event->getAuthor()) > 0; $variables['author'] = array(); foreach ($event->getAuthor() as $author) { $variables['author'][] = array('name' => (string) $author->getName(), 'email' => base64_encode(str_replace('@', '#', $author->getEmail()))); } $variables['copyGoogleUrl'] = 'http://www.google.com/calendar/render?action=TEMPLATE&text=' . urlencode($event->getTitle()); $variables['copyGoogleUrl'] .= '&dates=' . $event->getStartDate()->format($copyDateTimeFormat) . '%2F' . $event->getEndDate()->format($copyDateTimeFormat); $variables['copyGoogleUrl'] .= '&location=' . urlencode($event->getLocation()); $variables['copyGoogleUrl'] .= '&details=' . urlencode($event->getContent()); $variables['copyGoogleUrl'] .= '&hl=' . GCalendarUtil::getFrLanguage() . '&ctz=Etc/GMT'; $variables['copyGoogleUrl'] .= '&sf=true&output=xml'; $ical_timeString_start = $startTime . ' ' . $startDate; $ical_timeString_start = strtotime($ical_timeString_start); $ical_timeString_end = $endTime . ' ' . $endDate; $ical_timeString_end = strtotime($ical_timeString_end); $loc = $event->getLocation(); $variables['copyOutlookUrl'] = JRoute::_("index.php?option=com_gcalendar&view=ical&format=raw&eventID=" . $event->getGCalId() . '&gcid=' . $event->getParam('gcid')); $groupHeading = $event->getStartDate()->format($params->get('grouping', ''), true); if ($groupHeading != $lastHeading) { $lastHeading = $groupHeading; $variables['header'] = $groupHeading; } $configuration['events'][] = $variables; } $configuration['eventLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL'); $configuration['calendarLinkLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_CALENDAR_BACK_LINK'); $configuration['calendarNameLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_CALENDAR_NAME'); $configuration['titleLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_EVENT_TITLE'); $configuration['dateLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_WHEN'); $configuration['attendeesLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_ATTENDEES'); $configuration['locationLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_LOCATION'); $configuration['descriptionLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_DESCRIPTION'); $configuration['authorLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_AUTHOR'); $configuration['copyLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_COPY'); $configuration['copyGoogleLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_COPY_TO_MY_CALENDAR'); $configuration['copyOutlookLabel'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_COPY_TO_MY_CALENDAR_ICS'); $configuration['language'] = substr(GCalendarUtil::getFrLanguage(), 0, 2); $configuration['emptyText'] = JText::_('COM_GCALENDAR_FIELD_CONFIG_EVENT_LABEL_NO_EVENT_TEXT'); try { $m = new Mustache(); return $m->render($output, $configuration); } catch (Exception $e) { echo $e->getMessage(); } }
<div class="contentpane<?php echo $params->get('pageclass_sfx'); ?> "><?php $variables = ''; $variables .= '?showTitle=' . $params->get('title'); $variables .= '&showNav=' . $params->get('navigation'); $variables .= '&showDate=' . $params->get('date'); $variables .= '&showPrint=' . $params->get('print'); $variables .= '&showTabs=' . $params->get('tabs'); $variables .= '&showCalendars=0'; $variables .= '&showTz=' . $params->get('tz'); $variables .= '&mode=' . $params->get('view', 'MONTH'); $variables .= '&wkst=' . $params->get('weekstart', 2); $variables .= '&bgcolor=%23' . $params->get('bgcolor', 'FFFFFF'); $variables .= '&hl=' . GCalendarUtil::getFrLanguage(); $tz = $params->get('timezone'); if (!empty($tz)) { $tz = '&ctz=' . $tz; } $variables .= $tz; $variables .= '&height=' . $params->get('height', 500); $domain = 'http://www.google.com/calendar/embed'; $google_apps_domain = $params->get('google_apps_domain'); if (!empty($google_apps_domain)) { $domain = 'http://www.google.com/calendar/hosted/' . $google_apps_domain . '/embed'; } $calendar_list = '<div id="gc_google_view_list"><table>'; $calendarids = array(); $tmp = $params->get('calendarids'); if (is_array($tmp)) {
size="100%" value="<?php echo $calendar->color; ?> " style="background-color: <?php echo GCalendarUtil::getFadedColor($calendar->color); ?> ;" /> <table> <tbody> <?php for ($i = 0; $i < count($googleColors); $i++) { if ($i % 7 == 0) { echo "<tr>\n"; } $c = $googleColors[$i]; $cFaded = GCalendarUtil::getFadedColor($c); echo "<td onmouseover=\"this.style.cursor='pointer'\" onclick=\"document.getElementById('color').style.backgroundColor = '" . $cFaded . "';document.getElementById('color').value = '" . $c . "';\" style=\"background-color: " . $cFaded . ";width: 20px;\"/><td>" . $c . "</td>\n"; if ($i % 7 == 6) { echo "</tr>\n"; } } ?> </tbody> </table> </td> </tr> </table> </fieldset> </div> <div class="clr"></div>
function printToolBar() { global $Itemid; $year = (int) $this->year; $month = (int) $this->month; $day = (int) $this->day; $view = $this->view; $document =& JFactory::getDocument(); $document->setTitle('GCalendar: ' . $this->getViewTitle($year, $month, $day, $this->getWeekStart(), $view)); $mainFilename = "index.php?option=com_gcalendar&view=gcalendar&Itemid=" . $Itemid; switch ($view) { case "month": $nextMonth = $month == 12 ? 1 : $month + 1; $prevMonth = $month == 1 ? 12 : $month - 1; $nextYear = $month == 12 ? $year + 1 : $year; $prevYear = $month == 1 ? $year - 1 : $year; $prevURL = $mainFilename . "&gcalendarview=month&year=" . $prevYear . "&month=" . $prevMonth; $nextURL = $mainFilename . "&gcalendarview=month&year=" . $nextYear . "&month=" . $nextMonth; break; case "week": list($nextYear, $nextMonth, $nextDay) = explode(",", date("Y,n,j", strtotime("+7 days", strtotime("" . $year . "-" . $month . "-" . $day)))); list($prevYear, $prevMonth, $prevDay) = explode(",", date("Y,n,j", strtotime("-7 days", strtotime("" . $year . "-" . $month . "-" . $day)))); $prevURL = $mainFilename . "&gcalendarview=week&year=" . $prevYear . "&month=" . $prevMonth . "&day=" . $prevDay; $nextURL = $mainFilename . "&gcalendarview=week&year=" . $nextYear . "&month=" . $nextMonth . "&day=" . $nextDay; break; case "day": list($nextYear, $nextMonth, $nextDay) = explode(",", date("Y,n,j", strtotime("+1 day", strtotime("" . $year . "-" . $month . "-" . $day)))); list($prevYear, $prevMonth, $prevDay) = explode(",", date("Y,n,j", strtotime("-1 day", strtotime("" . $year . "-" . $month . "-" . $day)))); $prevURL = $mainFilename . "&gcalendarview=day&year=" . $prevYear . "&month=" . $prevMonth . "&day=" . $prevDay; $nextURL = $mainFilename . "&gcalendarview=day&year=" . $nextYear . "&month=" . $nextMonth . "&day=" . $nextDay; break; } $calCode = "function jumpToDate(d){\n"; $calCode .= "if(d == null) d = new Date();\n"; $calCode .= "window.location = '" . html_entity_decode(JRoute::_($mainFilename . "&gcalendarview=" . $view)) . "&day='+d.getDate()+'&month='+(d.getMonth()+1)+'&year='+d.getFullYear();\n"; $calCode .= "};\n"; $document->addScriptDeclaration($calCode); GCalendarUtil::loadJQuery(); $document->addScript('administrator/components/com_gcalendar/libraries/jquery/ui/ui.core.js'); $document->addScript('administrator/components/com_gcalendar/libraries/jquery/ui/ui.datepicker.js'); $document->addStyleSheet('administrator/components/com_gcalendar/libraries/jquery/themes/redmond/ui.all.css'); $daysLong = "["; $daysShort = "["; $daysMin = "["; $monthsLong = "["; $monthsShort = "["; $dateObject = JFactory::getDate(); for ($i = 0; $i < 7; $i++) { $daysLong .= "'" . $dateObject->_dayToString($i, false) . "'"; $daysShort .= "'" . $dateObject->_dayToString($i, true) . "'"; $daysMin .= "'" . substr($dateObject->_dayToString($i, true), 0, 2) . "'"; if ($i < 6) { $daysLong .= ","; $daysShort .= ","; $daysMin .= ","; } } for ($i = 1; $i <= 12; $i++) { $monthsLong .= "'" . $dateObject->_monthToString($i, false) . "'"; $monthsShort .= "'" . $dateObject->_monthToString($i, true) . "'"; if ($i < 12) { $monthsLong .= ","; $monthsShort .= ","; } } $daysLong .= "]"; $daysShort .= "]"; $daysMin .= "]"; $monthsLong .= "]"; $monthsShort .= "]"; $calCode .= "jQuery(document).ready(function(){\n"; $calCode .= "document.getElementById('gcdate').value = jQuery.datepicker.formatDate('" . $this->dateFormat . "', new Date(" . $year . ", " . $month . " - 1, " . $day . "));\n"; // $calCode .= "jQuery(\"#gcdate\").datepicker({changeYear: true});\n"; $calCode .= "jQuery(\"#gcdate\").datepicker({dateFormat: '" . $this->dateFormat . "'});\n"; $calCode .= "jQuery(\"#gcdate\").datepicker('option', 'dayNames', " . $daysLong . ");\n"; $calCode .= "jQuery(\"#gcdate\").datepicker('option', 'dayNamesShort', " . $daysShort . ");\n"; $calCode .= "jQuery(\"#gcdate\").datepicker('option', 'dayNamesMin', " . $daysMin . ");\n"; $calCode .= "jQuery(\"#gcdate\").datepicker('option', 'monthNames', " . $monthsLong . ");\n"; $calCode .= "jQuery(\"#gcdate\").datepicker('option', 'monthNamesShort', " . $monthsShort . ");\n"; $calCode .= "});\n"; $document->addScriptDeclaration($calCode); echo "<div id=\"calToolbar\">\n"; echo "<table style=\"margin: 0pt auto;\"><tr>\n"; echo " <td valign=\"middle\"><a class=\"Item\" href=\"" . JRoute::_($prevURL) . "\" title=\"" . JText::_('TOOLBAR_PREVIOUS') . $this->getTranslatedViewName() . "\">\n"; $this->image("btn-prev.gif", JText::_('TOOLBAR_PREVIOUS') . $this->getTranslatedViewName(), "prevBtn_img"); echo "</a></td>\n"; echo " <td valign=\"middle\"><span class=\"ViewTitle\">\n"; echo $this->getViewTitle($year, $month, $day, $this->getWeekStart(), $view); echo "</span></td>\n"; echo " <td valign=\"middle\"><a class=\"Item\" href=\"" . JRoute::_($nextURL) . "\" title=\"" . JText::_('TOOLBAR_NEXT') . $this->getTranslatedViewName() . "\">\n"; $this->image("btn-next.gif", JText::_('TOOLBAR_NEXT') . $this->getTranslatedViewName(), "nextBtn_img"); echo "</a></td>\n"; echo "<td width=\"20px\"/>\n"; $today = getdate(); echo " <td valign=\"middle\">\n"; echo "<button onClick=\"jumpToDate(null)\" title=\"" . JText::_('TOOLBAR_JUMP') . JText::_('TOOLBAR_TODAY') . "\">" . JText::_('TOOLBAR_TODAY') . "</button>\n"; echo "</td>\n"; echo " <td valign=\"middle\"><input class=\"Item\"\ttype=\"text\" name=\"gcdate\" id=\"gcdate\" \n"; echo "size=\"10\" maxlength=\"10\" title=\"" . JText::_('TOOLBAR_SELECT_DATE') . "\" /></td>"; echo " <td valign=\"middle\">\n"; echo "<button onClick=\"jumpToDate(jQuery.datepicker.parseDate('" . $this->dateFormat . "', document.getElementById('gcdate').value))\" title=\"" . JText::_('TOOLBAR_JUMP') . "\">" . JText::_('TOOLBAR_GO') . "</button>\n"; echo "</td>\n"; echo "<td width=\"20px\"/>\n"; echo " <td valign=\"middle\"><a href=\"" . JRoute::_($mainFilename . "&gcalendarview=day&year=" . $year . "&month=" . $month . "&day=" . $day) . "\">\n"; $this->image("cal-day.gif", JText::_('TOOLBAR_JUMP') . $this->getTranslatedViewName('day'), "calday_img"); echo "</a></td>\n"; echo " <td valign=\"middle\"><a href=\"" . JRoute::_($mainFilename . "&gcalendarview=week&year=" . $year . "&month=" . $month . "&day=" . $day) . "\">\n"; $this->image("cal-week.gif", JText::_('TOOLBAR_JUMP') . $this->getTranslatedViewName('week'), "calweek_img"); echo "</a></td>\n"; echo " <td valign=\"middle\"><a href=\"" . JRoute::_($mainFilename . "&gcalendarview=month&year=" . $year . "&month=" . $month . "&day=" . $day) . "\">\n"; $this->image("cal-month.gif", JText::_('TOOLBAR_JUMP') . $this->getTranslatedViewName('month'), "calmonth_img"); echo "</a></td></tr></table></div>\n"; }
echo $row->id; ?> </td> <td><?php echo $checked; ?> </td> <td><a href="<?php echo $link; ?> "><?php echo $row->name; ?> </a></td> <td width="40px"><div style="background-color: <?php echo GCalendarUtil::getFadedColor($row->color); ?> ;width: 100%;height: 100%;"/></td> <td> <table> <tr> <td><b><?php echo JText::_('Calendar ID'); ?> :</b></td> <td><?php echo $row->calendar_id; ?> </td> </tr> <tr>
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; }
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; }