Esempio n. 1
0
 function setupModuleCatids($modparams)
 {
     $this->myItemid = findAppropriateMenuID($this->catidsOut, $this->catids, $this->catidList, $modparams->toObject(), $this->moduleAllCats);
     // set menu/module constraint values for later use
     $this->mmcatids = array();
     // New system
     $newcats = $modparams->get("catidnew", false);
     if ($newcats && is_array($newcats)) {
         foreach ($newcats as $newcat) {
             if (!in_array($newcat, $this->mmcatids)) {
                 $this->mmcatids[] = $newcat;
             }
         }
     } else {
         for ($c = 0; $c < 999; $c++) {
             $nextCID = "catid{$c}";
             //  stop looking for more catids when you reach the last one!
             if (!($nextCatId = $modparams->get($nextCID, null))) {
                 break;
             }
             if (!in_array($nextCatId, $this->mmcatids)) {
                 $this->mmcatids[] = $nextCatId;
             }
         }
     }
     $this->mmcatidList = implode(",", $this->mmcatids);
     return $this->myItemid;
 }
 /**
  * Search method
  *
  * The sql must return the following fields that are used in a common display
  * routine: href, title, section, created, text, browsernav
  * @param string Target search string
  * @param string matching option, exact|any|all
  * @param string ordering option, newest|oldest|popular|alpha|category
  */
 function onSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $groups = version_compare(JVERSION, '1.6.0', '>=') ? implode(',', $user->getAuthorisedViewLevels()) : false;
     $limit = version_compare(JVERSION, '1.6.0', '>=') ? $this->params->get('search_limit', 50) : $this->_params->def('search_limit', 50);
     $dateformat = version_compare(JVERSION, '1.6.0', ">=") ? $this->params->get('date_format', "%d %B %Y") : $this->_params->def('date_format', "%d %B %Y");
     $allLanguages = $this->params->get('all_language_search', true);
     $limit = "\n LIMIT {$limit}";
     $text = trim($text);
     if ($text == '') {
         return array();
     }
     if (is_array($areas)) {
         $test = array_keys(plgSearchEventsSearchAreas());
         if (!array_intersect($areas, array_keys(plgSearchEventsSearchAreas()))) {
             return array();
         }
     }
     $params = JComponentHelper::getParams("com_jevents");
     // See http://www.php.net/manual/en/timezones.php
     $tz = $params->get("icaltimezonelive", "");
     if ($tz != "" && is_callable("date_default_timezone_set")) {
         $timezone = date_default_timezone_get();
         date_default_timezone_set($tz);
         $this->jeventstimezone = $timezone;
     }
     $search_ical_attributes = array('det.summary', 'det.description', 'det.location', 'det.contact', 'det.extra_info');
     // process the new plugins
     // get extra data and conditionality from plugins
     $extrawhere = array();
     $extrajoin = array();
     $needsgroup = false;
     $filterarray = array("published");
     $dataModel = new JEventsDataModel();
     $compparams = JComponentHelper::getParams("com_jevents");
     if ($compparams->get("multicategory", 0)) {
         $catwhere = "\n AND catmap.catid IN(" . $dataModel->accessibleCategoryList(null, null, null, $allLanguages) . ")";
         $catjoin = "\n LEFT JOIN #__jevents_catmap as catmap ON catmap.evid = rpt.eventid";
         $catjoin .= "\n LEFT JOIN #__categories AS b ON catmap.catid = b.id";
     } else {
         $catwhere = "\n AND ev.catid IN(" . $dataModel->accessibleCategoryList(null, null, null, $allLanguages) . ")";
         $catjoin = "\n INNER JOIN #__categories AS b ON b.id = ev.catid";
     }
     // If there are extra filters from the module then apply them now
     $reg = JFactory::getConfig();
     $modparams = $reg->get("jev.modparams", false);
     if ($modparams && $modparams->get("extrafilters", false)) {
         $filterarray = array_merge($filterarray, explode(",", $modparams->get("extrafilters", false)));
     }
     $filters = jevFilterProcessing::getInstance($filterarray);
     $filters->setWhereJoin($extrawhere, $extrajoin);
     $needsgroup = $filters->needsGroupBy();
     JPluginHelper::importPlugin('jevents');
     $dispatcher = JDispatcher::getInstance();
     $dispatcher->trigger('onListIcalEvents', array(&$extrafields, &$extratables, &$extrawhere, &$extrajoin, &$needsgroup));
     $extrajoin = count($extrajoin) ? " \n LEFT JOIN " . implode(" \n LEFT JOIN ", $extrajoin) : '';
     $extrawhere = count($extrawhere) ? ' AND ' . implode(' AND ', $extrawhere) : '';
     $extrasearchfields = array();
     $dispatcher->trigger('onSearchEvents', array(&$extrasearchfields, &$extrajoin, &$needsgroup));
     $wheres = array();
     $wheres_ical = array();
     switch ($phrase) {
         case 'exact':
             $text = $db->Quote('%' . $db->escape($text, true) . '%', false);
             // ical
             $wheres2 = array();
             foreach ($search_ical_attributes as $search_item) {
                 $wheres2[] = "LOWER({$search_item}) LIKE " . $text;
             }
             $where_ical = '(' . implode(') OR (', $wheres2) . ')';
             break;
         case 'all':
         case 'any':
         default:
             $words = explode(' ', $text);
             $text = $db->Quote('%' . $db->escape($text, true) . '%', false);
             // ical
             $wheres = array();
             foreach ($words as $word) {
                 $word = $db->Quote('%' . $db->escape($word) . '%', false);
                 $wheres2 = array();
                 foreach ($search_ical_attributes as $search_item) {
                     $wheres2[] = "LOWER({$search_item}) LIKE " . $word;
                 }
                 $wheres[] = implode(' OR ', $wheres2);
             }
             $where_ical = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
             break;
     }
     if (count($extrasearchfields) > 0) {
         $extraor = implode(" OR ", $extrasearchfields);
         $extraor = " OR " . $extraor;
         // replace the ### placeholder with the keyword
         // $text is already exscaped above
         $extraor = str_replace("###", $text, $extraor);
         $where_ical .= $extraor;
     }
     // some of the where statements may already be escaped
     $where_ical = str_replace("%'%'", "%'", $where_ical);
     $where_ical = str_replace("''", "'", $where_ical);
     $where_ical = str_replace("'%'%", "'%", $where_ical);
     $morder = '';
     $morder_ical = '';
     switch ($ordering) {
         case 'oldest':
             $order = 'a.created ASC';
             $order_ical = 'det.created ASC';
             break;
         case 'popular':
             $order = 'a.hits DESC';
             $order_ical = 'det.created ASC';
             // no hit field available
             break;
         case 'alpha':
             $order = 'a.title ASC';
             $order_ical = 'det.summary ASC';
             break;
         case 'category':
             $order = 'b.title ASC, a.title ASC';
             $morder = 'a.title ASC';
             $order_ical = 'b.title ASC, det.summary ASC';
             $morder_ical = 'det.summary ASC';
             break;
         case 'newest':
         default:
             $order = 'a.created DESC';
             $order_ical = 'det.created DESC';
             break;
     }
     $eventstitle = JText::_("Events Calendar");
     // Now Search Icals
     $display2 = array();
     foreach ($search_ical_attributes as $search_ical_attribute) {
         $display2[] = "{$search_ical_attribute}";
     }
     $display = 'CONCAT(' . implode(", ' ', ", $display2) . ')';
     $query = "SELECT det.evdet_id, det.summary as title," . "\n ev.created as created," . "\n {$display} as text," . "\n CONCAT('{$eventstitle}','/',det.summary) AS section," . "\n CONCAT('index.php?option=com_jevents&task=icalrepeat.detail&evid=',min(rpt.rp_id)) AS href," . "\n '2' AS browsernav ," . "\n rpt.startrepeat, rpt.rp_id " . "\n FROM (#__jevents_vevent as ev)" . "\n LEFT  JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id" . $catjoin . "\n LEFT  JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id" . "\n LEFT  JOIN #__jevents_icsfile as icsf ON icsf.ics_id = ev.icsid" . $extrajoin . "\n WHERE ({$where_ical})" . "\n AND icsf.state = 1" . "\n AND icsf.access " . (version_compare(JVERSION, '1.6.0', '>=') ? ' IN (' . $groups . ')' : ' <=  ' . $user->gid) . "\n AND ev.state = 1" . "\n AND ev.access " . (version_compare(JVERSION, '1.6.0', '>=') ? ' IN (' . $groups . ')' : ' <=  ' . $user->gid) . "\n AND b.access " . (version_compare(JVERSION, '1.6.0', '>=') ? ' IN (' . $groups . ')' : ' <=  ' . $user->gid) . "\n AND b.published = '1'" . $extrawhere . $catwhere . "\n GROUP BY det.evdet_id" . "\n ORDER BY " . ($morder_ical ? $morder_ical : $order_ical) . $limit;
     $db->setQuery($query);
     $list_ical = $db->loadObjectList('evdet_id');
     jimport('joomla.utilities.date');
     if ($list_ical) {
         foreach ($list_ical as $id => $item) {
             $user = JFactory::getUser();
             $query = "SELECT ev.*, ev.state as published, rpt.*, rr.*, det.*, ev.created as created, ex_id, exception_type " . "\n , YEAR(rpt.startrepeat) as yup, MONTH(rpt.startrepeat ) as mup, DAYOFMONTH(rpt.startrepeat ) as dup" . "\n , YEAR(rpt.endrepeat  ) as ydn, MONTH(rpt.endrepeat   ) as mdn, DAYOFMONTH(rpt.endrepeat   ) as ddn" . "\n , HOUR(rpt.startrepeat) as hup, MINUTE(rpt.startrepeat ) as minup, SECOND(rpt.startrepeat ) as sup" . "\n , HOUR(rpt.endrepeat  ) as hdn, MINUTE(rpt.endrepeat   ) as mindn, SECOND(rpt.endrepeat   ) as sdn" . "\n FROM #__jevents_vevent as ev" . "\n LEFT JOIN #__jevents_repetition as rpt ON rpt.eventid = ev.ev_id" . "\n LEFT JOIN #__jevents_vevdetail as det ON det.evdet_id = rpt.eventdetail_id" . "\n LEFT JOIN #__jevents_rrule as rr ON rr.eventid = ev.ev_id" . "\n LEFT JOIN #__jevents_exception as ex ON det.evdet_id = ex.eventdetail_id" . "\n WHERE ev.access " . (version_compare(JVERSION, '1.6.0', '>=') ? ' IN (' . $groups . ')' : ' <=  ' . $user->gid) . "\n AND det.evdet_id = {$id}" . "\n ORDER BY rpt.startrepeat ASC limit 1";
             $db->setQuery($query);
             $row = $db->loadObject();
             if (!$row) {
                 continue;
             }
             $event = new jIcalEventRepeat($row);
             // only get the next repeat IF its not an exception
             if (is_null($row->ex_id)) {
                 $event = $event->getNextRepeat();
             }
             $startdate = new JevDate(strtotime($event->_startrepeat));
             $item->title = $item->title . " (" . $startdate->toFormat($dateformat) . ")";
             $item->startrepeat = $event->_startrepeat;
             $myitemid = $this->params->get("target_itemid", 0);
             if ($myitemid == 0) {
                 // I must find the itemid that allows this event to be shown
                 $catidsOut = $modcatids = $catidList = $modparams = $showall = "";
                 // Use the plugin params to ensure menu item is picked up
                 //$modparams = new JRegistry($this->_plugin->params);
                 $modparams = new JRegistry(null);
                 // pretend to have category restriction
                 $modparams->set("catid0", $row->catid);
                 $modparams->set("ignorecatfilter", 1);
                 $myitemid = findAppropriateMenuID($catidsOut, $modcatids, $catidList, $modparams->toObject(), $showall);
             }
             $item->href = $event->viewDetailLink($event->yup(), $event->mup(), $event->dup(), false, $myitemid);
             $link = $item->href;
             $list_ical[$id] = $item;
         }
     }
     // Must reset the timezone back!!
     if ($tz && is_callable("date_default_timezone_set")) {
         date_default_timezone_set($timezone);
     }
     return $list_ical;
 }
 function setupModuleCatids($modparams)
 {
     $this->myItemid = findAppropriateMenuID($this->catidsOut, $this->catids, $this->catidList, $modparams->toObject(), $this->moduleAllCats);
     return $this->myItemid;
 }
 function displayLatestEvents($asHTML = true)
 {
     global $mainframe;
     global $database;
     global $_MAMBOTS;
     static $isloaded_css = false;
     $now = time() + $mainframe->getCfg('offset') * 60 * 60;
     $now_Y_m_d = date('Y-m-d', $now);
     $now_d = date('d', $now);
     $now_m = date('m', $now);
     $now_Y = date('Y', $now);
     $now_w = date("w", $now);
     $content = null;
     if ($this->inccss && !$isloaded_css && $asHTML) {
         $content .= '<link href="' . $mainframe->getCfg('live_site') . '/modules/mod_events_latest.css" rel="stylesheet" type="text/css" />' . "\n";
         $isloaded_css = true;
     }
     $catidsOut = null;
     $modcatids = null;
     $catidList = null;
     $myItemid = findAppropriateMenuID($catidsOut, $modcatids, $catidList, $this->modparams->toObject());
     $cat = "";
     if ($catidsOut != 0) {
         $cat = '&amp;catids=' . $catidsOut;
     }
     // derive the event date range we want based on current date and
     // form the db query.
     $todayBegin = $now_Y_m_d . " 00:00:00";
     $yesterdayEnd = date('Y-m-d', mktime(0, 0, 0, $now_m, $now_d - 1, $now_Y)) . " 23:59:59";
     switch ($this->dispMode) {
         case 0:
         case 1:
             // week start (ie. Sun or Mon) is according to what has been selected in the events
             // component configuration thru the events admin interface.
             $numDay = ($now_w - $this->com_starday + 7) % 7;
             // begin of this week
             $beginDate = date('Y-m-d', mktime(0, 0, 0, $now_m, $now_d - $numDay, $now_Y)) . " 00:00:00";
             //$thisWeekEnd = date('Y-m-d', mktime(0,0,0,date('m'),date('d') - date('w')+6, date('Y'))." 23:59:59";
             // end of next week
             $endDate = date('Y-m-d', mktime(0, 0, 0, $now_m, $now_d - $numDay + 13, $now_Y)) . " 23:59:59";
             break;
         case 2:
         case 3:
             // begin of today - $days
             $beginDate = date('Y-m-d', mktime(0, 0, 0, $now_m, $now_d - $this->rangeDays, $now_Y)) . " 00:00:00";
             // end of today + $days
             $endDate = date('Y-m-d', mktime(0, 0, 0, $now_m, $now_d + $this->rangeDays, $now_Y)) . " 23:59:59";
             break;
         case 4:
         default:
             // beginning of this month
             $beginDate = date('Y-m-d', mktime(0, 0, 0, $now_m, 1, $now_Y)) . " 00:00:00";
             // end of this month
             $endDate = date('Y-m-d', mktime(0, 0, 0, $now_m + 1, 0, $now_Y)) . " 23:59:59";
             break;
     }
     $query = "SELECT #__events.* " . "\n , YEAR(publish_up  ) as yup, MONTH(publish_up  ) as mup, DAYOFMONTH(publish_up  ) as dup" . "\n , YEAR(publish_down) as ydn, MONTH(publish_down) as mdn, DAYOFMONTH(publish_down) as ddn" . "\n , HOUR(publish_up  ) as hup, MINUTE(publish_up  ) as minup, SECOND(publish_up  ) as sup" . "\n , HOUR(publish_down) as hdn, MINUTE(publish_down) as mindn, SECOND(publish_down) as sdn" . "\n FROM (#__events)" . "\n WHERE #__events.catid IN(" . accessibleCategoryList($this->gid, $modcatids, $catidList) . ")" . "\n AND #__events.access <= {$this->gid}" . "\n AND (#__events.state='1' AND #__events.checked_out='0')" . "\n AND ((publish_up <= '{$todayBegin}%' AND publish_down >= '{$todayBegin}%')" . "\n OR (publish_up <= '{$endDate}%' AND publish_down >= '{$endDate}%')" . "\n OR (publish_up <= '{$endDate}%' AND publish_up >= '{$todayBegin}%')" . "\n OR (publish_down <= '{$endDate}%' AND publish_down >= '{$todayBegin}%'))" . "\n ORDER BY publish_up ASC";
     // initialise the query in the $database connector
     // this translates the '#__' prefix into the real database prefix
     $database->setQuery($query);
     // retrieve the list of returned records as an array of objects
     $rows = $database->loadObjectList();
     // determine the events that occur each day within our range
     $events = 0;
     $date = $now;
     $lastDate = mktime(0, 0, 0, intval(substr($endDate, 5, 2)), intval(substr($endDate, 8, 2)), intval(substr($endDate, 0, 4)));
     $i = 0;
     if ($asHTML) {
         $content .= '<table class="mod_events_latest_table" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
     }
     $seenThisEvent = array();
     if (count($rows)) {
         while ($date <= $lastDate) {
             // get the events for this $date
             $eventsThisDay = $this->getEventsByDate($rows, $date, $seenThisEvent, $this->norepeat);
             if (count($eventsThisDay)) {
                 // dmcd May 7/04  bug fix to not exceed maxEvents
                 $eventsToAdd = min($this->maxEvents - $events, count($eventsThisDay));
                 $eventsThisDay = array_slice($eventsThisDay, 0, $eventsToAdd);
                 $eventsByRelDay[$i] = $eventsThisDay;
                 $events += count($eventsByRelDay[$i]);
             }
             if ($events >= $this->maxEvents) {
                 break;
             }
             $date = mktime(0, 0, 0, date('m', $date), date('d', $date) + 1, date('Y', $date));
             $i++;
         }
     }
     if ($events < $this->maxEvents && ($this->dispMode == 1 || $this->dispMode == 3)) {
         // display some recent previous events too up to a total of $maxEvents
         $query = "SELECT #__events.* " . "\n , YEAR(publish_up  ) as yup, MONTH(publish_up  ) as mup, DAYOFMONTH(publish_up  ) as dup" . "\n , YEAR(publish_down) as ydn, MONTH(publish_down) as mdn, DAYOFMONTH(publish_down) as ddn" . "\n , HOUR(publish_up  ) as hup, MINUTE(publish_up  ) as minup, SECOND(publish_up  ) as sup" . "\n , HOUR(publish_down) as hdn, MINUTE(publish_down) as mindn, SECOND(publish_down) as sdn" . "\n FROM (#__events)" . "\n WHERE #__events.catid IN(" . accessibleCategoryList($this->gid, $modcatids, $catidList) . ")" . "\n AND #__events.access <= {$this->gid}" . "\n AND (#__events.state='1' AND #__events.checked_out='0')" . "\n AND ((publish_up <= '{$beginDate}%' AND publish_down >= '{$beginDate}%')" . "\n OR (publish_up <= '{$yesterdayEnd}%' AND publish_down >= '{$yesterdayEnd}%')" . "\n OR (publish_up <= '{$yesterdayEnd}%' AND publish_up >= '{$beginDate}%')" . "\n OR (publish_down <= '{$yesterdayEnd}%' AND publish_down >= '{$beginDate}%'))" . "\n ORDER BY publish_up DESC";
         // initialise the query in the $database connector
         // this translates the '#__' prefix into the real database prefix
         $database->setQuery($query);
         // retrieve the list of returned records as an array of objects
         $prows = $database->loadObjectList();
         if (count($prows)) {
             // start from yesterday
             $date = mktime(23, 59, 59, $now_m, $now_d - 1, $now_Y);
             $lastDate = mktime(0, 0, 0, intval(substr($beginDate, 5, 2)), intval(substr($beginDate, 8, 2)), intval(substr($beginDate, 0, 4)));
             $i = -1;
             while ($date >= $lastDate) {
                 // get the events for this $date
                 $eventsThisDay = $this->getEventsByDate($prows, $date, $seenThisEvent, $this->norepeat);
                 if (count($eventsThisDay)) {
                     $eventsByRelDay[$i] = $eventsThisDay;
                     $events += count($eventsByRelDay[$i]);
                 }
                 if ($events >= $this->maxEvents) {
                     break;
                 }
                 $date = mktime(0, 0, 0, date('m', $date), date('d', $date) - 1, date('Y', $date));
                 $i--;
             }
         }
     }
     //asdbg_break();
     if (isset($eventsByRelDay) && count($eventsByRelDay)) {
         // Now to display these events, we just start at the smallest index of the $eventsByRelDay array
         // and work our way up.
         ksort($eventsByRelDay, SORT_NUMERIC);
         reset($eventsByRelDay);
         $firstTime = true;
         // initialize name of com_events module and task defined to view
         // event detail.  Note that these could change in future com_event
         // component revisions!!  Note that the '$itemId' can be left out in
         // the link parameters for event details below since the event.php
         // component handler will fetch its own id from the db menu table
         // anyways as far as I understand it.
         $option = 'com_events';
         $task_events = 'view_detail';
         // Note we MUST get the $Itemid value for the events component
         // here, or some mambo things can break.
         /* replace by findAppropriateMenuID [tstahl]
         			$query = "SELECT id"
         			. "\n FROM #__menu WHERE"
         			. "\n link = 'index.php?option=$option'"
         			. "\n AND published = 1"
         			. "\n AND access <= $this->gid"
         			. "\n ORDER BY access ASC";
         			$database->setQuery($query);
         			$Itemid = intval($database->loadResult());
         			*/
         /*	tstahl, 30.05.2006, fetch $category and $users attributes by class function on demand
         
         				// get the com_events category names from the categories mos table
         				
         				$database->setQuery("SELECT id, name FROM #__categories WHERE section= 'com_events' AND published='1'");
         				$category = $database->loadObjectList('id');
         				
         				// get the usernames and email addresses from the users mos table
         				
         				$database->setQuery("SELECT id, username, sendEmail, email FROM #__users WHERE block ='0'");
         				$users = $database->loadObjectList('id');
         				*/
         // see if $customFormatStr has been specified.  If not, set it to the default format
         // of date followed by event title.
         if ($this->customFormatStr == NULL) {
             $this->customFormatStr = $this->defaultfFormatStr;
         } else {
             $this->customFormatStr = preg_replace('/^"(.*)"$/', "\$1", $this->customFormatStr);
             $this->customFormatStr = preg_replace("/^'(.*)'\$/", "\$1", $this->customFormatStr);
             // escape all " within the string
             // $customFormatStr = preg_replace('/"/','\"', $customFormatStr);
         }
         // strip out event variables and run the string thru an html checker to make sure
         // it is legal html.  If not, we will not use the custom format and print an error
         // message in the module output.  This functionality is not here for now.
         // parse the event variables and reformat them into php syntax with special handling
         // for the startDate and endDate fields.
         //asdbg_break();
         $customFormat = $this->customFormatStr;
         $keywords = array('content', 'eventDetailLink', 'createdByAlias', 'color', 'createdByUserName', 'createdByUserEmail', 'createdByUserEmailLink', 'eventDate', 'endDate', 'startDate', 'title', 'category', 'contact', 'addressInfo', 'extraInfo');
         $keywords_or = implode('|', $keywords);
         $whsp = '[\\t ]*';
         // white space
         $datefm = '\\([^\\)]*\\)';
         // date formats
         //$modifiers	= '(?::[[:alnum:]]*)';
         $pattern = '/(\\$\\{' . $whsp . '(?:' . $keywords_or . ')(?:' . $datefm . ')?' . $whsp . '\\})/';
         // keyword pattern
         $cond_pattern = '/(\\[!?[[:alnum:]]+:[^\\]]*])/';
         // conditional string pattern e.g. [!a: blabla ${endDate(%a)}]
         // tokenize conditional strings
         $splitTerm = preg_split($cond_pattern, $customFormat, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
         $splitCustomFormat = array();
         foreach ($splitTerm as $key => $value) {
             if (preg_match('/^\\[(.*)\\]$/', $value, $matches)) {
                 // remove outer []
                 $splitCustomFormat[$key]['data'] = $matches[1];
                 // split condition
                 preg_match('/^([^:]*):(.*)$/', $splitCustomFormat[$key]['data'], $matches);
                 $splitCustomFormat[$key]['cond'] = $matches[1];
                 $splitCustomFormat[$key]['data'] = $matches[2];
             } else {
                 $splitCustomFormat[$key]['data'] = $value;
             }
             // tokenize into array
             $splitCustomFormat[$key]['data'] = preg_split($pattern, $splitCustomFormat[$key]['data'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
         }
         // cleanup, remove white spaces from key words, seperate date parm string and modifier into array;
         // e.g.  ${ keyword ( 'aaaa' ) } => array('keyword', 'aaa',)
         foreach ($splitCustomFormat as $ix => $yy) {
             foreach ($splitCustomFormat[$ix]['data'] as $keyToken => $customToken) {
                 if (preg_match('/\\$\\{' . $whsp . '(' . $keywords_or . ')(' . $datefm . ')?' . $whsp . '}/', $customToken, $matches)) {
                     $splitCustomFormat[$ix]['data'][$keyToken] = array();
                     $splitCustomFormat[$ix]['data'][$keyToken]['keyword'] = stripslashes($matches[1]);
                     if (isset($matches[2])) {
                         // ('aaa') => aaa
                         $splitCustomFormat[$ix]['data'][$keyToken]['dateParm'] = preg_replace('/^\\(["\']?(.*)["\']?\\)$/', "\$1", stripslashes($matches[2]));
                     }
                 } else {
                     $splitCustomFormat[$ix]['data'][$keyToken] = stripslashes($customToken);
                 }
             }
         }
         $_MAMBOTS->loadBotGroup('content');
         foreach ($eventsByRelDay as $relDay => $daysEvents) {
             reset($daysEvents);
             // get all of the events for this day
             foreach ($daysEvents as $dayEvent) {
                 // get the title and start time
                 $startDate = $dayEvent->publish_up;
                 $eventDate = mktime(substr($startDate, 11, 2), substr($startDate, 14, 2), substr($startDate, 17, 2), $now_m, $now_d + $relDay, $now_Y);
                 $startDate = mktime(substr($startDate, 11, 2), substr($startDate, 14, 2), substr($startDate, 17, 2), substr($startDate, 5, 2), substr($startDate, 8, 2), substr($startDate, 0, 4));
                 $endDate = $dayEvent->publish_down;
                 $endDate = mktime(substr($endDate, 11, 2), substr($endDate, 14, 2), substr($endDate, 17, 2), substr($endDate, 5, 2), substr($endDate, 8, 2), substr($endDate, 0, 4));
                 $year = date('Y', $startDate);
                 $month = date('m', $startDate);
                 $day = date('d', $startDate);
                 if ($asHTML) {
                     if ($firstTime) {
                         $content .= '<tr><td class="mod_events_latest_first">';
                     } else {
                         $content .= '<tr><td class="mod_events_latest">';
                     }
                 }
                 // generate output according custom string
                 foreach ($splitCustomFormat as $condtoken) {
                     // evaluate all_day_event
                     $all_day_event = false;
                     //if ($dayEvent->publish_up == $dayEvent->publish_down) {
                     if ($dayEvent->hup == $dayEvent->hdn && $dayEvent->minup == $dayEvent->mindn && $dayEvent->sup == $dayEvent->sdn) {
                         $all_day_event = true;
                     }
                     if (isset($condtoken['cond'])) {
                         if ($condtoken['cond'] == 'a' && !$all_day_event) {
                             continue;
                         }
                         if ($condtoken['cond'] == '!a' && $all_day_event) {
                             continue;
                         }
                     }
                     foreach ($condtoken['data'] as $token) {
                         unset($match);
                         unset($dateParm);
                         $match = '';
                         if (is_array($token)) {
                             $match = $token['keyword'];
                             $dateParm = isset($token['dateParm']) ? trim($token['dateParm']) : "";
                         } else {
                             $content .= $token;
                             continue;
                         }
                         switch ($match) {
                             case 'endDate':
                             case 'startDate':
                             case 'eventDate':
                                 // Note we need to examine the date specifiers used to determine if language translation will be
                                 // necessary.  Do this later when script is debugged.
                                 if (!$this->disableDateStyle && $asHTML) {
                                     $content .= '<span class="mod_events_latest_date">';
                                 }
                                 if (!isset($dateParm) || $dateParm == '') {
                                     // no actual format specified, use default, eg. Fri Oct 12th, @7:30pm\
                                     // use the strftime function for international support
                                     if ($this->lang == 'english') {
                                         //if($lang == 'english'){
                                         $time_fmt = $all_day_event ? '' : ', @g:ia';
                                         $dateFormat = $this->displayYear ? 'D, M jS, Y' . $time_fmt : 'D, M jS' . $time_fmt;
                                         $content .= date($dateFormat, ${$match});
                                     } else {
                                         $time_fmt = $all_day_event ? '' : ' @%I:%M%p';
                                         $dateFormat = $this->displayYear ? '%a %b %d, %Y' . $time_fmt : '%a %b %d' . $time_fmt;
                                         $content .= strftime($dateFormat, ${$match});
                                     }
                                 } else {
                                     // if a '%' sign detected in date format string, we assume strftime() is to be used,
                                     if (preg_match("/\\%/", $dateParm)) {
                                         $content .= strftime($dateParm, ${$match});
                                     } else {
                                         $content .= date($dateParm, ${$match});
                                     }
                                 }
                                 if (!$this->disableDateStyle && $asHTML) {
                                     $content .= "</span>";
                                 }
                                 break;
                             case 'title':
                                 if (!$this->disableTitleStyle && $asHTML) {
                                     $content .= '<span class="mod_events_latest_content">';
                                 }
                                 if ($this->displayLinks) {
                                     $content .= $this->_htmlLinkCloaking("index.php?option=" . $option . "&amp;task=" . $task_events . "&amp;agid=" . $dayEvent->id . "&amp;year=" . date("Y", $eventDate) . "&amp;month=" . date("m", $eventDate) . "&amp;day=" . date("d", $eventDate) . "&amp;Itemid=" . $myItemid . $cat, $dayEvent->title);
                                 } else {
                                     $content .= $dayEvent->title;
                                 }
                                 if (!$this->disableTitleStyle && $asHTML) {
                                     $content .= '</span>';
                                 }
                                 break;
                             case 'category':
                                 $catobj = $this->_getCategory($dayEvent->catid);
                                 $content .= $catobj->name;
                                 break;
                             case 'contact':
                                 // Also want to cloak contact details so
                                 $this->modparams->set("image", 1);
                                 $dayEvent->text = $dayEvent->contact_info;
                                 $_MAMBOTS->trigger('onPrepareContent', array(&$dayEvent, &$this->modparams, 0), true);
                                 $dayEvent->contact_info = $dayEvent->text;
                                 $content .= $dayEvent->contact_info;
                                 break;
                             case 'content':
                                 // Added by Kaz McCoy 1-10-2004
                                 $this->modparams->set("image", 1);
                                 $dayEvent->text = $dayEvent->content;
                                 $results = $_MAMBOTS->trigger('onPrepareContent', array(&$dayEvent, &$this->modparams, 0), true);
                                 $dayEvent->content = $dayEvent->text;
                                 //$content .= substr($dayEvent->content, 0, 150);
                                 $content .= $dayEvent->content;
                                 break;
                             case 'addressInfo':
                                 $content .= $dayEvent->adresse_info;
                                 break;
                             case 'extraInfo':
                                 $content .= $dayEvent->extra_info;
                                 break;
                             case 'createdByAlias':
                                 $content .= $dayEvent->created_by_alias;
                                 break;
                             case 'createdByUserName':
                                 $catobj = $this->_getUser($dayEvent->created_by);
                                 $content .= $catobj->username;
                                 break;
                             case 'createdByUserEmail':
                                 // Note that users email address will NOT be available if they don't want to receive email
                                 $catobj = $this->_getUser($dayEvent->created_by);
                                 $content .= $catobj->sendEmail ? $catobj->email : '';
                                 break;
                             case 'createdByUserEmailLink':
                                 // Note that users email address will NOT be available if they don't want to receive email
                                 $content .= sefRelToAbs("index.php?option=" . $option . "&amp;task=" . $task_events . "&amp;agid=" . $dayEvent->id . "&amp;year=" . $year . "&amp;month=" . $month . "&amp;day=" . $day . "&amp;Itemid=" . $myItemid . $cat);
                                 break;
                             case 'color':
                                 $content .= $dayEvent->color_bar;
                                 break;
                             case 'eventDetailLink':
                                 $content .= sefRelToAbs("index.php?option=" . $option . "&amp;task=" . $task_events . "&amp;agid=" . $dayEvent->id . "&amp;year=" . $year . "&amp;month=" . $month . "&amp;day=" . $day . "&amp;Itemid=" . $myItemid . $cat);
                                 break;
                             default:
                                 if ($match) {
                                     $content .= $match;
                                 }
                                 break;
                         }
                         // end of switch
                     }
                     // end of foreach
                 }
                 // end of foreach
                 if ($asHTML) {
                     $content .= "</td></tr>\n";
                 } else {
                     $content .= "\n";
                 }
                 $firstTime = false;
             }
             // end of foreach
         }
         // end of foreach
     } else {
         if ($asHTML) {
             $content .= '<tr><td class="mod_events_latest_noevents">' . _CAL_LANG_NO_EVENTS . '</td></tr>' . "\n";
         } else {
             $content .= _CAL_LANG_NO_EVENTS . "\n";
         }
     }
     if ($asHTML) {
         $content .= "</table>\n";
     }
     return $content;
 }
Esempio n. 5
0
 function displayCalendarMod($time, $linkString, &$day_name, $monthMustHaveEvent = false)
 {
     global $startday, $database, $timeWithOffset, $my, $modparams;
     $myItemid = findAppropriateMenuID($catidsOut, $modcatids, $catidList, $modparams);
     $gid = $my->gid;
     if (strlen($catidsOut) > 0) {
         $cat = "&amp;catids={$catidsOut}";
     } else {
         $cat = "";
     }
     $cal_year = date("Y", $time);
     $cal_month = date("m", $time);
     $calmonth = date("n", $time);
     $month_name = EventsHelper::getMonthName($cal_month);
     $to_day = date("Y-m-d", $timeWithOffset);
     $cal_prev_month = $cal_month - 1;
     $cal_prev_month_yy = $cal_year;
     $cal_next_month = $cal_month + 1;
     $cal_next_month_yy = $cal_year;
     $cal_mod_next_year = $cal_year + 1;
     $cal_mod_prev_year = $cal_year - 1;
     $content = '';
     // additional EBS
     if ($cal_prev_month == 0) {
         $cal_prev_month = 12;
         $cal_prev_month_yy = $cal_prev_month_yy - 1;
     }
     if ($cal_next_month == 13) {
         $cal_next_month = 1;
         $cal_next_month_yy = $cal_next_month_yy + 1;
     }
     if ($modparams->minical_showlink) {
         $content = '<table cellpadding="0" cellspacing="0" width="140" align="center" class="mod_events_monthyear">' . "\n" . '<tr >' . "\n";
         if ($modparams->minical_showlink == 1) {
             $link = 'index.php?option=com_events&amp;Itemid=' . $myItemid . $cat . '&amp;task=';
             if ($modparams->minical_prevyear) {
                 $seflinkPrevYear = sefRelToAbs($link . 'view_year' . '&amp;day=1&amp;month=' . $cal_month . '&amp;year=' . $cal_mod_prev_year . '&amp;mod_cal_year=' . $cal_mod_prev_year . '&amp;mod_cal_month=' . $cal_month);
                 $content .= '<td>';
                 $content .= '<a class="mod_events_link" href="' . $seflinkPrevYear . '" title="' . _CAL_LANG_CLICK_TOSWITCH_PY . '">&laquo;</a>' . "\n";
                 $content .= '</td>';
             }
             if ($modparams->minical_prevmonth) {
                 $seflinkPrevMon = sefRelToAbs($link . 'view_month' . '&amp;day=1&amp;month=' . $cal_prev_month . '&amp;year=' . $cal_prev_month_yy . '&amp;mod_cal_year=' . $cal_prev_month_yy . '&amp;mod_cal_month=' . $cal_prev_month);
                 $content .= '<td>';
                 $content .= '<a class="mod_events_link" href="' . $seflinkPrevMon . '" title="' . _CAL_LANG_CLICK_TOSWITCH_PM . '">&lt;</a>' . "\n";
                 $content .= '</td>';
             }
             if ($modparams->minical_actmonth == 1) {
                 // combination of actual month and year: view month
                 $seflinkActMonth = sefRelToAbs($link . 'view_month' . '&amp;month=' . $cal_month . '&amp;year=' . $cal_year);
                 $content .= '<td align="center">';
                 $content .= '<a class="mod_events_link" href="' . $seflinkActMonth . '" title="' . _CAL_LANG_CLICK_TOSWITCH_MON . '">' . $month_name . '</a>' . "\n";
                 if ($modparams->minical_actyear < 1) {
                     $content .= '</td>';
                 }
             } elseif ($modparams->minical_actmonth == 2) {
                 $content .= '<td align="center">';
                 $content .= $month_name . "\n";
                 if ($modparams->minical_actyear < 1) {
                     $content .= '</td>';
                 }
             }
             if ($modparams->minical_actyear == 1) {
                 // combination of actual month and year: view year
                 $seflinkActYear = sefRelToAbs($link . 'view_year' . '&amp;month=' . $cal_month . '&amp;year=' . $cal_year);
                 if ($modparams->minical_actmonth < 1) {
                     $content .= '<td align="center">';
                 }
                 $content .= '<a class="mod_events_link" href="' . $seflinkActYear . '" title="' . _CAL_LANG_CLICK_TOSWITCH_YEAR . '">' . $cal_year . '</a>' . "\n";
                 $content .= '</td>';
             } elseif ($modparams->minical_actyear == 2) {
                 if ($modparams->minical_actmonth < 1) {
                     $content .= '<td align="center">';
                 }
                 $content .= $cal_year . "\n";
                 $content .= '</td>';
             }
             if ($modparams->minical_nextmonth) {
                 $seflinkNextMon = sefRelToAbs($link . 'view_month' . '&amp;day=1&amp;month=' . $cal_next_month . '&amp;year=' . $cal_next_month_yy . '&amp;mod_cal_year=' . $cal_next_month_yy . '&amp;mod_cal_month=' . $cal_next_month);
                 $content .= '<td>';
                 $content .= '<a class="mod_events_link" href="' . $seflinkNextMon . '" title="' . _CAL_LANG_CLICK_TOSWITCH_NM . '">&gt;</a>' . "\n";
                 $content .= '</td>';
             }
             if ($modparams->minical_nextyear) {
                 $seflinkNextYear = sefRelToAbs($link . 'view_year' . '&amp;day=1&amp;month=' . $cal_month . '&amp;year=' . $cal_mod_next_year . '&amp;mod_cal_year=' . $cal_mod_next_year . '&amp;mod_cal_month=' . $cal_month);
                 $content .= '<td>';
                 $content .= '<a class="mod_events_link" href="' . $seflinkNextYear . '" title="' . _CAL_LANG_CLICK_TOSWITCH_NY . '">&raquo;</a>' . "\n";
                 $content .= '</td>';
             }
             // combination of actual month and year: view year & month [ mic: not used here ]
             // $seflinkActYM   = sefRelToAbs( $link . 'view_month' . '&amp;month=' . $cal_month
             // . '&amp;year=' . $cal_year );
         } else {
             // show only text
             $content .= '<td>';
             $content .= $month_name . ' ' . $cal_year;
             $content .= '</td>';
         }
         $content .= "</tr>\n" . "</table>\n";
     }
     $content .= '<table align="center" class="mod_events_table" cellspacing="0" cellpadding="2">' . "\n" . '<tr class="mod_events_dayname">' . "\n";
     // Days name rows
     for ($i = 0; $i < 7; $i++) {
         $content .= "<td class='mod_events_td_dayname'>" . $day_name[($i + $startday) % 7] . "</td>\n";
     }
     $content .= "</tr>\n";
     // dmcd May 7/04 fix to fill in end days out of month correctly
     $dayOfWeek = $startday;
     $start = (date("w", mktime(0, 0, 0, $cal_month, 1, $cal_year)) - $startday + 7) % 7;
     $d = date("t", mktime(0, 0, 0, $cal_month, 0, $cal_year)) - $start + 1;
     if ($start > 0) {
         $content .= "<tr>\n";
     }
     for ($a = $start; $a > 0; $a--) {
         $content .= "<td class='mod_events_td_dayoutofmonth'>" . $d++ . "</td>\n";
         $dayOfWeek++;
     }
     $monthHasEvent = false;
     $lastDayOfMonth = date("t", mktime(0, 0, 0, $cal_month, 1, $cal_year));
     /********** COPIED FROM EVENTS.PHP **********/
     $select_date = $cal_year . '-' . $cal_month . '-01 00:00:00';
     $select_date_fin = $cal_year . '-' . $cal_month . '-' . $lastDayOfMonth . ' 23:59:59';
     $query = "SELECT #__events.*" . "\n , YEAR(publish_up  ) as yup, MONTH(publish_up  ) as mup, DAYOFMONTH(publish_up  ) as dup" . "\n , YEAR(publish_down) as ydn, MONTH(publish_down) as mdn, DAYOFMONTH(publish_down) as ddn" . "\n , HOUR(publish_up  ) as hup, MINUTE(publish_up  ) as minup, SECOND(publish_up  ) as sup" . "\n , HOUR(publish_down) as hdn, MINUTE(publish_down) as mindn, SECOND(publish_down) as sdn" . "\n FROM #__events" . "\n WHERE #__events.catid IN(" . accessibleCategoryList($gid, $modcatids, $catidList) . ")" . "\n AND #__events.access <= {$gid}" . "\n AND (((publish_up >= '{$select_date}%' AND publish_up <= '{$select_date_fin}%')" . "\n OR (publish_down >= '{$select_date}%' AND publish_down <= '{$select_date_fin}%')" . "\n OR (publish_up >= '{$select_date}%' AND publish_down <= '{$select_date_fin}%')" . "\n OR (publish_up <= '{$select_date}%' AND publish_down >= '{$select_date_fin}%')" . "\n )" . "\n AND #__events.state = '1')" . "\n ORDER BY publish_up ASC";
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     /********** END COPIED FROM EVENTS.PHP **********/
     $rowcount = count($rows);
     $repeatArray = array();
     for ($i = 0; $i < $rowcount; $i++) {
         // build array of dates for each event
         $repeatArray[$i] = mosEventRepeatArrayMonth($rows[$i], $cal_year, $cal_month);
     }
     for ($d = 1; $d <= $lastDayOfMonth; $d++) {
         // Note that if we are on the last day of the month and last day of week then we won't have
         // any out of month days so don't start a new row!
         if ((date('w', mktime(0, 0, 0, $cal_month, $d, $cal_year)) - $startday) % 7 == 0) {
             // && $d!=date( 't', mktime( 0, 0, 0, $cal_month, $d, $cal_year ))){
             $content .= "<tr>";
         }
         $do = $d < 10 ? "0{$d}" : "{$d}";
         $selected_date = "{$cal_year}-{$cal_month}-{$do}";
         $cellDate = mktime(0, 0, 0, $cal_month, $d, $cal_year);
         $mark_bold = '';
         $mark_close_bold = '';
         $class = $selected_date == $to_day ? 'mod_events_td_todaynoevents' : 'mod_events_td_daynoevents';
         $dayHasEvent = false;
         for ($r = 0; $r < $rowcount && !$dayHasEvent; $r++) {
             if (array_key_exists($cellDate, $repeatArray[$r])) {
                 $monthHasEvent = true;
                 $dayHasEvent = true;
                 $mark_bold = "<b>";
                 $mark_close_bold = "</b>";
                 $class = $selected_date == $to_day ? "mod_events_td_todaywithevents" : "mod_events_td_daywithevents";
                 break;
             }
         }
         $sefdaylink = sefRelToAbs("index.php?option=com_events&amp;task=view_day&amp;year=" . $cal_year . "&amp;month=" . $cal_month . "&amp;day=" . $do . "&amp;Itemid=" . $myItemid . $cat);
         $content .= "<td class='" . $class . "'><a class='mod_events_daylink' href='" . $sefdaylink . "' title='" . _CAL_LANG_CLICK_TOSWITCH_DAY . "'>" . $mark_bold . $d . $mark_close_bold . "</a></td>\n";
         // Check if Next week row
         // dmcd May 7/04 fix to fill in end days out of month correctly
         //if(((date("w",mktime(0,0,0,$cal_month,$d,$cal_year))-$startday+1)%7)==0) {
         if ((1 + $dayOfWeek++) % 7 == $startday && intval($d) != date('t', mktime(0, 0, 0, $cal_month, $d, $cal_year))) {
             $content .= "</tr>\n";
         }
     }
     // Days out of the month
     // dmcd May 7/04 fix to fill in end days out of month correctly
     //if(((date("w",mktime(0,0,0,$cal_month+1,1,$cal_year))-$startday)%7)<>1) {
     $d = 1;
     //    while(((date("w",mktime(0,0,0,($cal_month+1),$d,$cal_year))-$startday+1)%7)<>1) {
     while ($dayOfWeek++ % 7 != $startday) {
         $content .= '<td class="mod_events_td_dayoutofmonth">' . $d . "</td>\n";
         $d++;
     }
     $content .= '</tr></table>' . "\n";
     // Many people found this confusing! (geraint)
     /* just a textlink [mic] - if wanted just delete the remarks at cont[]
      * if remarks are deleted at content, the links will be displayed right after each months
      * otherwise with cont[] as 1 block after the last month
      */
     //$seflink = sefRelToAbs( 'index.php?option=com_events&amp;task=view_month&amp;Itemid=' . $myItemid
     //. '&amp;month=' . $cal_month . '&amp;year=' . $cal_year );
     //$content .= '<table width="140" align="center"><tr><td class="mod_events_thismonth" >' . "\n";
     //$content .= '<div align="center"><a class="mod_events_link" href="' . $seflink . '">'
     //. $linkString . '</a></div>' . "\n";
     //$cont[] .= '<div align="center"><a class="mod_events_link" href="' . $seflink . '">' . $linkString.'</a></div>'."\n";
     //$content .= '</td></tr>' . "\n";
     //$content .= '</table>' . "\n";
     /* end textlink */
     // Now check to see if this month needs to have at least 1 event in order to display
     if (!$monthMustHaveEvent || $monthHasEvent) {
         return $content;
     } else {
         return '';
     }
 }