This module needs the Events component");
}
// load language constants
EventsHelper::loadLanguage('modlatest');
if (!defined( 'EVENTS_LATEST_MODULE' )) {
define( 'EVENTS_LATEST_MODULE', 1 );
function JEventsLatestcmpByStartTime (&$a, &$b) {
// this custom sort compare function compares the start times of events that are referenced by the a & b vars
if ($a->publish_up == $b->publish_up) return 0;
if (!isset($a->_startTime)){
$a->_startTime = mktime($a->hup,$a->minup,$a->sup);
}
if (!isset($b->_startTime)){
$b->_startTime = mktime($b->hup,$b->minup,$b->sup);
}
return ($a->_startTime < $b->_startTime) ? -1 : 1;
}
class JEventsLatest {
// Note that we encapsulate all this in a class to create
// an isolated name space from everythng else (I hope).
var $gid = null;
var $lang = null;
var $catid = null;
var $inccss = null;
var $maxEvents = null;
var $dispMode = null;
var $rangeDays = null;
var $norepeat = null;
var $displayLinks = null;
var $displayYear = null;
var $disableDateStyle = null;
var $disableTitleStyle = null;
var $linkCloaking = null;
var $customFormatStr = null;
var $defaultfFormatStr = '${eventDate}[!a: - ${endDate(%I:%M%p)}]
${title}';
var $com_starday = null;
var $modparams = null;
function JEventsLatest(&$params) {
global $my, $mainframe;
// get global configuration object
$jevents_config = &EventsConfig::getInstance();
$this->gid = $my->gid;
// Can't use getCfg since this cannot be changed by Joomfish etc.
$this->lang = $mainframe->getCfg('lang');
//$this->lang = $mainframe->getLanguage();
$this->modparams = & $params;
// get params exclusive to module
$this->inccss = $params->get('modlatest_inccss', 0);
// get params exclusive to component
$this->com_starday = intval($jevents_config->get('com_starday',0));
// get params depending on switch
if (intval($params->get('modlatest_useLocalParam', 0)) == 1) {
$myparam = &$params;
} else {
$myparam = &$jevents_config;
}
$this->maxEvents = intval($myparam->get('modlatest_MaxEvents', 15));
$this->dispMode = intval($myparam->get('modlatest_Mode', 0));
$this->rangeDays = intval($myparam->get('modlatest_Days', 30));
$this->norepeat = intval($myparam->get('modlatest_NoRepeat', 0));
$this->displayLinks = intval($myparam->get('modlatest_DispLinks', 1));
$this->displayYear = intval($myparam->get('modlatest_DispYear', 0));
$this->disableDateStyle = intval($myparam->get('modlatest_DisDateStyle', 0));
$this->disableTitleStyle = intval($myparam->get('modlatest_DisTitleStyle', 0));
$this->linkCloaking = intval($myparam->get('modlatest_LinkCloaking', 0));
$this->customFormatStr = $myparam->get('modlatest_CustFmtStr', '');
if($this->dispMode > 4) $this->dispMode = 0;
// $maxEvents hardcoded to 150 for now to avoid bad mistakes in params
if($this->maxEvents > 150) $this->maxEvents = 150;
}
/**
* Creates a JEvents_Latest object
*
* @param object The module parameter
* @return object A JEvents_Latest object
*/
function &getInstance(&$params) {
$object = & new JEventsLatest($params);
return $object;
}
/**
* Serves requested category
*
* @param int category id
* @return object database row
*/
function &_getCategory($id) {
global $mainframe;
global $database;
static $rows;
if ($id <= 0) {
return null;
}
if (!isset($rows)) {
$rows = array();
}
if (!isset($rows[$id])) {
$rows[$id] = null;
$query = "SELECT id, name FROM #__categories WHERE section= 'com_events'"
. "\n AND published='1'"
. "\n AND id = " . $id;
$database->setQuery($query);
$database->loadObject($rows[$id]);
}
return $rows[$id];
}
/**
* Serves requested user
*
* @param int user id
* @return object database row
*/
function &_getUser($id) {
global $mainframe;
global $database;
static $rows;
if ($id <= 0) {
return null;
}
if (!isset($rows)) {
$rows = array();
}
if (!isset($rows[$id])) {
$rows[$id] = null;
$query = "SELECT id, username, sendEmail, email FROM #__users"
. "\n WHERE block ='0'"
. "\n AND id = " . $id;
$database->setQuery($query);
$database->loadObject($rows[$id]);
}
return $rows[$id];
}
/**
* Cloaks html link whith javascript
*
* @param string The cloaking URL
* @param string The link text
* @return string HTML
*/
function _htmlLinkCloaking($url='', $text='') {
$link = sefReltoAbs($url);
if ($this->linkCloaking) {
//return mosHTML::Link("", $text, array('onclick'=>'"window.location.href=\''.josURL($url).'\';return false;"'));
return '' . $text . '';
} else {
//return mosHTML::Link(josURL($url), "$text");
return '' . $text . '';
}
}
// The function below is essentially the 'ShowEventsByDate' function in the com_events module,
// except no actual output is performed. Rather this function returns an array of references to
// $rows within the $rows (ie events) input array which occur on the input '$date'. This
// is determined by the complicated com_event algorithm according to the event's repeatting type.
function getEventsByDate(&$rows, $date, &$seenThisEvent, $noRepeats) {
$year = date('Y', $date);
$month = date('m', $date);
$day = date('d', $date);
$cellDate = mktime(0,0,0,$month,$day,$year);
$num_events = count($rows);
$chhours = "";
$select_date = $year."-".$month."-".$day;
$dayOfTheWeek = date("w",$date);
$printcount = 0;
$new_rows_events = array();
if ($num_events==0) {
return $new_rows_events;
}
for( $i = 0; $i < $num_events; $i++ ){
// build array of dates for each event
if (!isset($this->repeatArray[$month][$i])) {
$this->repeatArray[$month][$i] = mosEventRepeatArrayMonth( $rows[$i], $year, $month );
// merge it to an array by day
foreach ($this->repeatArray[$month][$i] as $key => $value) {
$this->eventsByDay[$key][] = $i;
}
}
}
if (isset($this->eventsByDay) && array_key_exists($cellDate, $this->eventsByDay)) {
// get all items of the day
foreach ($this->eventsByDay[$cellDate] as $i) {
$id = $rows[$i]->id;
if(isset($seenThisEvent[$id]) && $noRepeats) continue;
$seenThisEvent[$id] = 1;
$new_rows_events[] = &$rows[$i];
}
usort($new_rows_events, "JEventsLatestcmpByStartTime");
}
return $new_rows_events;
} // end function
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 .= '' . "\n";
$isloaded_css = true;
}
$catidsOut = null;
$modcatids = null;
$catidList = null;
$myItemid = findAppropriateMenuID($catidsOut, $modcatids, $catidList, $this->modparams->toObject());
$cat = "";
if ($catidsOut != 0){
$cat = '&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 .= '
| '; else $content .= ' |
| '; } // 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 .= ''; 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'; /* Rodax Software -> poner mejor formato de fechas */ $dateFormat = $this->displayYear ? '%A, %e de %B de %Y'.$time_fmt : '%A, %e de %B'.$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); // otherwise the date() function is assumed. else $content .= date($dateParm, $$match); } if(!$this->disableDateStyle && $asHTML) $content .= ""; break; case 'title': if (!$this->disableTitleStyle && $asHTML) $content .= ''; if ($this->displayLinks) { $content .= $this->_htmlLinkCloaking("index.php?option=".$option . "&task=" . $task_events . "&agid=" . $dayEvent->id . "&year=" . date("Y", $eventDate) . "&month=" . date("m", $eventDate) . "&day=" . date("d", $eventDate) . "&Itemid=". $myItemid . $cat, $dayEvent->title); } else { $content .= $dayEvent->title; } if (!$this->disableTitleStyle && $asHTML) $content .= ''; 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 . "&task=".$task_events . "&agid=".$dayEvent->id . "&year=".$year . "&month=".$month . "&day=".$day . "&Itemid=".$myItemid . $cat); break; case 'color': $content .= $dayEvent->color_bar; break; case 'eventDetailLink': $content .= sefRelToAbs("index.php?option=" . $option . "&task=".$task_events . "&agid=".$dayEvent->id . "&year=".$year . "&month=".$month . "&day=".$day . "&Itemid=".$myItemid . $cat); break; default: if ($match) $content .= $match; break; } // end of switch } // end of foreach } // end of foreach if ($asHTML){ $content .= " |
| '. _CAL_LANG_NO_EVENTS . ' |