PageRenderTime 82ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/mod_jevents_latest/tmpl/default/latest.php

https://bitbucket.org/kraymitchell/saiu
PHP | 1158 lines | 892 code | 135 blank | 131 comment | 229 complexity | b45622ae3e09a2c89f2ad9bab1ba186a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * copyright (C) 2008 GWE Systems Ltd - All rights reserved
  4. */
  5. // Check to ensure this file is included in Joomla!
  6. defined('_JEXEC') or die();
  7. /**
  8. * HTML View class for the module frontend
  9. *
  10. * @static
  11. */
  12. class DefaultModLatestView
  13. {
  14. var $_modid = null;
  15. var $modparams = null;
  16. // Note that we encapsulate all this in a class to create
  17. // an isolated name space from everythng else (I hope).
  18. var $aid = null;
  19. var $lang = null;
  20. var $catid = null;
  21. var $inccss = null;
  22. var $maxEvents = null;
  23. var $dispMode = null;
  24. var $rangeDays = null;
  25. var $norepeat = null;
  26. var $displayLinks = null;
  27. var $displayYear = null;
  28. var $disableDateStyle = null;
  29. var $disableTitleStyle = null;
  30. var $linkCloaking = null;
  31. var $customFormatStr = null;
  32. var $_defaultfFormatStr12 = '${eventDate}[!a: - ${endDate(%l:%M%p)}]<br />${title}';
  33. var $_defaultfFormatStr24 = '${eventDate}[!a: - ${endDate(%H:%M)}]<br />${title}';
  34. var $defaultfFormatStr = null;
  35. var $linkToCal = null; // 0=no, 1=top, 2=bottom
  36. var $sortReverse = null;
  37. var $displayRSS = null;
  38. var $rsslink = null;
  39. var $com_starday = null;
  40. var $com_calUseStdTime = null;
  41. var $datamodel = null;
  42. var $catout = null;
  43. function DefaultModLatestView($params, $modid)
  44. {
  45. $this->_modid = $modid;
  46. $this->modparams = & $params;
  47. $jevents_config = & JEVConfig::getInstance();
  48. $this->datamodel = new JEventsDataModel();
  49. // find appropriate Itemid and setup catids for datamodel
  50. $this->myItemid = $this->datamodel->setupModuleCatids($this->modparams);
  51. $this->catout = $this->datamodel->getCatidsOutLink(true);
  52. $user = & JFactory::getUser();
  53. $this->aid = $user->aid;
  54. // Can't use getCfg since this cannot be changed by Joomfish etc.
  55. $tmplang = & JFactory::getLanguage();
  56. $this->langtag = $tmplang->getTag();
  57. // get params exclusive to module
  58. $this->inccss = $params->get('modlatest_inccss', 0);
  59. if ($this->inccss)
  60. {
  61. JEVHelper::componentStylesheet($this, "modstyle.css");
  62. }
  63. // get params exclusive to component
  64. $this->com_starday = intval($jevents_config->get('com_starday', 0));
  65. $this->com_calUseStdTime = intval($jevents_config->get('com_calUseStdTime', 1));
  66. if ($this->com_calUseStdTime)
  67. {
  68. $this->defaultfFormatStr = $this->_defaultfFormatStr12;
  69. }
  70. else
  71. {
  72. $this->defaultfFormatStr = $this->_defaultfFormatStr24;
  73. }
  74. // get params depending on switch
  75. if (intval($params->get('modlatest_useLocalParam', 0)) == 1)
  76. {
  77. $myparam = &$params;
  78. }
  79. else
  80. {
  81. $myparam = &$jevents_config;
  82. }
  83. $this->maxEvents = intval($myparam->get('modlatest_MaxEvents', 15));
  84. $this->dispMode = intval($myparam->get('modlatest_Mode', 0));
  85. $this->startNow = intval($myparam->get('startnow', 0));
  86. $this->pastOnly = intval($myparam->get('pastonly', 0));
  87. $this->rangeDays = intval($myparam->get('modlatest_Days', 30));
  88. $this->norepeat = intval($myparam->get('modlatest_NoRepeat', 0));
  89. $this->multiday = intval($myparam->get('modlatest_multiday', 0));
  90. $this->displayLinks = intval($myparam->get('modlatest_DispLinks', 1));
  91. $this->displayYear = intval($myparam->get('modlatest_DispYear', 0));
  92. $this->disableDateStyle = intval($myparam->get('modlatest_DisDateStyle', 0));
  93. $this->disableTitleStyle = intval($myparam->get('modlatest_DisTitleStyle', 0));
  94. $this->linkCloaking = intval($myparam->get('modlatest_LinkCloaking', 0));
  95. $this->linkToCal = intval($myparam->get('modlatest_LinkToCal', 0));
  96. $this->customFormatStr = $myparam->get('modlatest_CustFmtStr', '');
  97. $this->displayRSS = intval($myparam->get('modlatest_RSS', 0));
  98. $this->sortReverse = intval($myparam->get('modlatest_SortReverse', 0));
  99. if ($this->dispMode > 6)
  100. $this->dispMode = 0;
  101. // $maxEvents hardcoded to 105 for now to avoid bad mistakes in params
  102. if ($this->maxEvents > 150)
  103. $this->maxEvents = 150;
  104. if ($this->displayRSS)
  105. {
  106. if ($modid > 0)
  107. {
  108. // do not use JRoute since this creates .rss link which normal sef can't deal with
  109. $this->rsslink = JURI::root() . 'index.php?option=' . JEV_COM_COMPONENT . '&amp;task=modlatest.rss&amp;format=feed&amp;type=rss&amp;modid=' . $modid;
  110. }
  111. else
  112. {
  113. $this->displayRSS = false;
  114. }
  115. }
  116. }
  117. function getTheme()
  118. {
  119. $theme = JEV_CommonFunctions::getJEventsViewName();
  120. return $theme;
  121. }
  122. /**
  123. * Cloaks html link whith javascript
  124. *
  125. * @param string The cloaking URL
  126. * @param string The link text
  127. * @return string HTML
  128. */
  129. function _htmlLinkCloaking($url='', $text='', $class='')
  130. {
  131. //$link = JRoute::_($url);
  132. // sef already should be already called below
  133. $link = $url;
  134. if ($this->linkCloaking)
  135. {
  136. //return mosHTML::Link("", $text, array('onclick'=>'"window.location.href=\''.josURL($url).'\';return false;"'));
  137. return '<a href="#" onclick="window.location.href=\'' . $link . '\'; return false;" ' . $class . ' >' . $text . '</a>';
  138. }
  139. else
  140. {
  141. //return mosHTML::Link(josURL($url), "$text");
  142. return '<a href="' . $link . '" ' . $class . '>' . $text . '</a>';
  143. }
  144. }
  145. // this could go to a data model class
  146. // for the time being put it here so the different views can inherit from this 'base' class
  147. function getLatestEventsData($limit="")
  148. {
  149. // RSS situation overrides maxecents
  150. $limit = intval($limit);
  151. if ($limit > 0)
  152. {
  153. $this->maxEvents = $limit;
  154. }
  155. $db = & JFactory::getDBO();
  156. $t_datenow = JEVHelper::getNow();
  157. $this->now = $t_datenow->toUnix(true);
  158. $this->now_Y_m_d = date('Y-m-d', $this->now);
  159. $this->now_d = date('d', $this->now);
  160. $this->now_m = date('m', $this->now);
  161. $this->now_Y = date('Y', $this->now);
  162. $this->now_w = date('w', $this->now);
  163. $t_datenowSQL = $t_datenow->toMysql();
  164. // derive the event date range we want based on current date and
  165. // form the db query.
  166. $todayBegin = $this->now_Y_m_d . " 00:00:00";
  167. $yesterdayEnd = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d - 1, $this->now_Y)) . " 23:59:59";
  168. switch ($this->dispMode) {
  169. case 0:
  170. case 1:
  171. // week start (ie. Sun or Mon) is according to what has been selected in the events
  172. // component configuration thru the events admin interface.
  173. $numDay = ($this->now_w - $this->com_starday + 7) % 7;
  174. // begin of this week
  175. $beginDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d - $numDay, $this->now_Y)) . " 00:00:00";
  176. //$thisWeekEnd = date('Y-m-d', JevDate::mktime(0,0,0,$this->now_m,$this->now_d - $this->now_w+6, $this->now_Y)." 23:59:59";
  177. // end of next week
  178. $endDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d - $numDay + 13, $this->now_Y)) . " 23:59:59";
  179. break;
  180. case 2:
  181. if ($this->startNow)
  182. {
  183. $beginDate = $t_datenowSQL;
  184. // end of today + $days
  185. $endDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d + $this->rangeDays, $this->now_Y)) . " 23:59:59";
  186. }
  187. else
  188. {
  189. // begin of today - $days
  190. $beginDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d, $this->now_Y)) . " 00:00:00";
  191. // end of today + $days
  192. $endDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d + $this->rangeDays, $this->now_Y)) . " 23:59:59";
  193. }
  194. break;
  195. case 3:
  196. case 5:
  197. case 6:
  198. // begin of today - $days
  199. $beginDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d - $this->rangeDays, $this->now_Y)) . " 00:00:00";
  200. // end of today + $days
  201. $endDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d + $this->rangeDays, $this->now_Y)) . " 23:59:59";
  202. break;
  203. case 4:
  204. default:
  205. // beginning of this month
  206. $beginDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, 1, $this->now_Y)) . " 00:00:00";
  207. // end of this month
  208. $endDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m + 1, 0, $this->now_Y)) . " 23:59:59";
  209. break;
  210. }
  211. // only past events
  212. if ($this->pastOnly == 1)
  213. {
  214. if ($this->startNow)
  215. {
  216. $endDate = $t_datenowSQL;
  217. }
  218. else
  219. {
  220. $endDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d, $this->now_Y)) . " 00:00:00";
  221. }
  222. }
  223. // only future events
  224. else if ($this->pastOnly == 2)
  225. {
  226. if ($this->startNow)
  227. {
  228. $startDate = $t_datenowSQL;
  229. }
  230. else
  231. {
  232. $startDate = date('Y-m-d', JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d, $this->now_Y)) . " 00:00:00";
  233. }
  234. }
  235. $periodStart = $beginDate; //substr($beginDate,0,10);
  236. $periodEnd = $endDate; //substr($endDate,0,10);
  237. $reg = & JFactory::getConfig();
  238. $reg->setValue("jev.modparams", $this->modparams);
  239. if ($this->dispMode == 5)
  240. {
  241. $this->sortReverse = true;
  242. $rows = $this->datamodel->queryModel->recentIcalEvents($periodStart, $periodEnd, $this->maxEvents, $this->norepeat);
  243. }
  244. else if ($this->dispMode == 6)
  245. {
  246. $rows = $this->datamodel->queryModel->popularIcalEvents($periodStart, $periodEnd, $this->maxEvents, $this->norepeat);
  247. }
  248. else
  249. {
  250. $rows = $this->datamodel->queryModel->listLatestIcalEvents($periodStart, $periodEnd, $this->maxEvents, $this->norepeat, $this->multiday);
  251. }
  252. $reg->setValue("jev.modparams", false);
  253. // determine the events that occur each day within our range
  254. $events = 0;
  255. // I need the date not the time of day !!
  256. //$date = $this->now;
  257. $date = JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d, $this->now_Y);
  258. $lastDate = JevDate::mktime(0, 0, 0, intval(substr($endDate, 5, 2)), intval(substr($endDate, 8, 2)), intval(substr($endDate, 0, 4)));
  259. $i = 0;
  260. $seenThisEvent = array();
  261. $this->eventsByRelDay = array();
  262. if (count($rows))
  263. {
  264. // sort combined array by date
  265. if ($this->dispMode == 5)
  266. usort($rows, array(get_class($this), "_sortEventsByCreationDate"));
  267. else if ($this->dispMode == 6)
  268. usort($rows, array(get_class($this), "_sortEventsByHits"));
  269. else
  270. usort($rows, array(get_class($this), "_sortEventsByDate"));
  271. }
  272. if ($this->dispMode == 6)
  273. {
  274. if (count($rows))
  275. {
  276. $eventsThisDay = array();
  277. foreach ($rows as $row)
  278. {
  279. $eventsThisDay[] = clone $row;
  280. }
  281. if (count($eventsThisDay))
  282. {
  283. $this->eventsByRelDay[$i] = $eventsThisDay;
  284. }
  285. }
  286. }
  287. else
  288. {
  289. if (count($rows))
  290. {
  291. while ($date <= $lastDate)
  292. {
  293. // get the events for this $date
  294. $eventsThisDay = array();
  295. foreach ($rows as $row)
  296. {
  297. if ($this->dispMode == 2 && $this->startNow)
  298. {
  299. if ($row->_endrepeat < $t_datenowSQL)
  300. continue;
  301. }
  302. if (($this->dispMode == 5 && $this->checkCreateDay($date, $row)) || ($this->dispMode != 5 && $row->checkRepeatDay($date, $this->multiday)))
  303. {
  304. if (($this->norepeat && $row->hasrepetition())
  305. // use settings from the event - multi day event only show once
  306. || ($this->multiday == 0 && $row->ddn() != $row->dup() && $row->multiday() == 0)
  307. // override settings from the event - multi day event only show once/on first day
  308. || (($this->multiday == 2 || $this->multiday == 3) && $row->ddn() != $row->dup() )
  309. )
  310. {
  311. // make sure this event has not already been used!
  312. $eventAlreadyAdded = false;
  313. foreach ($this->eventsByRelDay as $ebrd)
  314. {
  315. foreach ($ebrd as $evt)
  316. {
  317. // could test on devent detail but would need another config option
  318. if ($row->ev_id() == $evt->ev_id())
  319. {
  320. $eventAlreadyAdded = true;
  321. break;
  322. }
  323. }
  324. if ($eventAlreadyAdded)
  325. {
  326. break;
  327. }
  328. }
  329. if (!$eventAlreadyAdded)
  330. {
  331. $row->moddate = $date;
  332. $eventsThisDay[] = clone $row;
  333. }
  334. }
  335. else
  336. {
  337. $row->moddate = $date;
  338. $eventsThisDay[] = clone $row;
  339. }
  340. }
  341. if ($events + count($eventsThisDay) >= $this->maxEvents)
  342. {
  343. break;
  344. }
  345. }
  346. if (count($eventsThisDay))
  347. {
  348. // dmcd May 7/04 bug fix to not exceed maxEvents
  349. $eventsToAdd = min($this->maxEvents - $events, count($eventsThisDay));
  350. $eventsThisDay = array_slice($eventsThisDay, 0, $eventsToAdd);
  351. //sort by time on this day
  352. usort($eventsThisDay, array(get_class($this), "_sortEventsByTime"));
  353. $this->eventsByRelDay[$i] = $eventsThisDay;
  354. $events += count($this->eventsByRelDay[$i]);
  355. }
  356. if ($events >= $this->maxEvents)
  357. {
  358. break;
  359. }
  360. $date = JevDate::strtotime("+1 day", $date);
  361. $i++;
  362. }
  363. }
  364. if ($events < $this->maxEvents && ($this->dispMode == 1 || $this->dispMode == 3 || $this->dispMode == 5 || $this->dispMode == 6))
  365. {
  366. if (count($rows))
  367. {
  368. // start from yesterday
  369. // I need the date not the time of day !!
  370. $date = JevDate::mktime(0, 0, 0, $this->now_m, $this->now_d - 1, $this->now_Y);
  371. $lastDate = JevDate::mktime(0, 0, 0, intval(substr($beginDate, 5, 2)), intval(substr($beginDate, 8, 2)), intval(substr($beginDate, 0, 4)));
  372. $i = -1;
  373. while ($date >= $lastDate)
  374. {
  375. // get the events for this $date
  376. $eventsThisDay = array();
  377. foreach ($rows as $row)
  378. {
  379. if (($this->dispMode == 5 && $this->checkCreateDay($date, $row)) || ($this->dispMode != 5 && $row->checkRepeatDay($date, $this->multiday)))
  380. {
  381. if (($this->norepeat && $row->hasrepetition())
  382. // use settings from the event - multi day event only show once
  383. || ($this->multiday == 0 && $row->ddn() != $row->dup() && $row->multiday() == 0)
  384. // override settings from the event - multi day event only show once/on first day
  385. || (($this->multiday == 2 || $this->multiday == 3) && $row->ddn() != $row->dup() )
  386. )
  387. {
  388. // make sure this event has not already been used!
  389. $eventAlreadyAdded = false;
  390. foreach ($this->eventsByRelDay as $ebrd)
  391. {
  392. foreach ($ebrd as $evt)
  393. {
  394. // could test on devent detail but would need another config option
  395. if ($row->ev_id() == $evt->ev_id())
  396. {
  397. $eventAlreadyAdded = true;
  398. break;
  399. }
  400. }
  401. if ($eventAlreadyAdded)
  402. {
  403. break;
  404. }
  405. }
  406. if ($this->dispMode == 5 && !$eventAlreadyAdded)
  407. {
  408. foreach ($eventsThisDay as $evt)
  409. {
  410. // could test on devent detail but would need another config option
  411. if ($row->ev_id() == $evt->ev_id())
  412. {
  413. $eventAlreadyAdded = true;
  414. break;
  415. }
  416. }
  417. if ($eventAlreadyAdded)
  418. {
  419. break;
  420. }
  421. }
  422. if (!$eventAlreadyAdded)
  423. {
  424. $row->moddate = $date;
  425. $eventsThisDay[] = clone $row;
  426. }
  427. }
  428. else
  429. {
  430. $row->moddate = $date;
  431. $eventsThisDay[] = clone $row;
  432. }
  433. }
  434. if ($events + count($eventsThisDay) >= $this->maxEvents)
  435. {
  436. break;
  437. }
  438. }
  439. if (count($eventsThisDay))
  440. {
  441. //sort by time on this day
  442. usort($eventsThisDay, array(get_class($this), "_sortEventsByTime"));
  443. $this->eventsByRelDay[$i] = $eventsThisDay;
  444. $events += count($this->eventsByRelDay[$i]);
  445. }
  446. if ($events >= $this->maxEvents)
  447. {
  448. break;
  449. }
  450. $date = JevDate::strtotime("-1 day", $date);
  451. $i--;
  452. }
  453. }
  454. }
  455. }
  456. if (isset($this->eventsByRelDay) && count($this->eventsByRelDay))
  457. {
  458. // When we display these events, we just start at the smallest index of the $this->eventsByRelDay array
  459. // and work our way up so sort the data first
  460. ksort($this->eventsByRelDay, SORT_NUMERIC);
  461. reset($this->eventsByRelDay);
  462. }
  463. if ($this->sortReverse)
  464. {
  465. $this->eventsByRelDay = array_reverse($this->eventsByRelDay, true);
  466. foreach ($this->eventsByRelDay as $relDay => $daysEvents)
  467. {
  468. $this->eventsByRelDay[$relDay] = array_reverse($daysEvents, true);
  469. }
  470. }
  471. }
  472. function checkCreateDay($date, $row)
  473. {
  474. return (JevDate::strftime("%Y-%m-%d", $date) == substr($row->created(), 0, 10));
  475. }
  476. function _sortEventsByDate(&$a, &$b)
  477. {
  478. $adate = $a->_startrepeat;
  479. $bdate = $b->_startrepeat;
  480. return strcmp($adate, $bdate);
  481. }
  482. function _sortEventsByCreationDate(&$a, &$b)
  483. {
  484. $adate = $a->created();
  485. $bdate = $b->created();
  486. // reverse created date
  487. return -strcmp($adate, $bdate);
  488. }
  489. function _sortEventsByHits(&$a, &$b)
  490. {
  491. $ah = $a->hits();
  492. $bh = $b->hits();
  493. if ($ah == $bh)
  494. {
  495. return 0;
  496. }
  497. return ($ah > $bh) ? -1 : 1;
  498. }
  499. function _sortEventsByTime(&$a, &$b)
  500. {
  501. // this custom sort compare function compares the start times of events that are referenced by the a & b vars
  502. //if ($a->publish_up() == $b->publish_up()) return 0;
  503. list( $adate, $atime ) = explode(' ', $a->publish_up());
  504. list( $bdate, $btime ) = explode(' ', $b->publish_up());
  505. // if allday event, sort by title first on day
  506. if ($a->alldayevent())
  507. $atime = '00:00' . $a->title();
  508. if ($b->alldayevent())
  509. $btime = '00:00' . $b->title();
  510. return strcmp($atime, $btime);
  511. }
  512. function processFormatString()
  513. {
  514. // see if $customFormatStr has been specified. If not, set it to the default format
  515. // of date followed by event title.
  516. if ($this->customFormatStr == NULL)
  517. $this->customFormatStr = $this->defaultfFormatStr;
  518. else
  519. {
  520. $this->customFormatStr = preg_replace('/^"(.*)"$/', "\$1", $this->customFormatStr);
  521. $this->customFormatStr = preg_replace("/^'(.*)'$/", "\$1", $this->customFormatStr);
  522. // escape all " within the string
  523. // $customFormatStr = preg_replace('/"/','\"', $customFormatStr);
  524. }
  525. // strip out event variables and run the string thru an html checker to make sure
  526. // it is legal html. If not, we will not use the custom format and print an error
  527. // message in the module output. This functionality is not here for now.
  528. // parse the event variables and reformat them into php syntax with special handling
  529. // for the startDate and endDate fields.
  530. //asdbg_break();
  531. // interpret linefeed as <br />
  532. $customFormat = nl2br($this->customFormatStr);
  533. $keywords = array(
  534. 'content', 'eventDetailLink', 'createdByAlias', 'color',
  535. 'createdByUserName', 'createdByUserEmail', 'createdByUserEmailLink',
  536. 'eventDate', 'endDate', 'startDate', 'title', 'category', 'calendar',
  537. 'contact', 'addressInfo', 'location', 'extraInfo',
  538. 'countdown'
  539. );
  540. $keywords_or = implode('|', $keywords);
  541. $whsp = '[\t ]*'; // white space
  542. $datefm = '\([^\)]*\)'; // date formats
  543. //$modifiers = '(?::[[:alnum:]]*)';
  544. $pattern = '/(\$\{' . $whsp . '(?:' . $keywords_or . ')(?:' . $datefm . ')?' . $whsp . '\})/'; // keyword pattern
  545. $cond_pattern = '/(\[!?[[:alnum:]]+:[^\]]*])/'; // conditional string pattern e.g. [!a: blabla ${endDate(%a)}]
  546. // tokenize conditional strings
  547. $splitTerm = preg_split($cond_pattern, $customFormat, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  548. $this->splitCustomFormat = array();
  549. foreach ($splitTerm as $key => $value)
  550. {
  551. if (preg_match('/^\[(.*)\]$/', $value, $matches))
  552. {
  553. // remove outer []
  554. $this->splitCustomFormat[$key]['data'] = $matches[1];
  555. // split condition
  556. preg_match('/^([^:]*):(.*)$/', $this->splitCustomFormat[$key]['data'], $matches);
  557. $this->splitCustomFormat[$key]['cond'] = $matches[1];
  558. $this->splitCustomFormat[$key]['data'] = $matches[2];
  559. }
  560. else
  561. {
  562. $this->splitCustomFormat[$key]['data'] = $value;
  563. }
  564. // tokenize into array
  565. $this->splitCustomFormat[$key]['data'] = preg_split($pattern, $this->splitCustomFormat[$key]['data'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  566. }
  567. // cleanup, remove white spaces from key words, seperate date parm string and modifier into array;
  568. // e.g. ${ keyword ( 'aaaa' ) } => array('keyword', 'aaa',)
  569. foreach ($this->splitCustomFormat as $ix => $yy)
  570. {
  571. foreach ($this->splitCustomFormat[$ix]['data'] as $keyToken => $customToken)
  572. {
  573. if (preg_match('/\$\{' . $whsp . '(' . $keywords_or . ')(' . $datefm . ')?' . $whsp . '}/', $customToken, $matches))
  574. {
  575. $this->splitCustomFormat[$ix]['data'][$keyToken] = array();
  576. $this->splitCustomFormat[$ix]['data'][$keyToken]['keyword'] = stripslashes($matches[1]);
  577. if (isset($matches[2]))
  578. {
  579. // ('aaa') => aaa
  580. $this->splitCustomFormat[$ix]['data'][$keyToken]['dateParm'] = preg_replace('/^\(["\']?(.*)["\']?\)$/', "\$1", stripslashes($matches[2]));
  581. }
  582. }
  583. else
  584. {
  585. $this->splitCustomFormat[$ix]['data'][$keyToken] = stripslashes($customToken);
  586. }
  587. }
  588. }
  589. }
  590. function displayLatestEvents()
  591. {
  592. // this will get the viewname based on which classes have been implemented
  593. $viewname = $this->getTheme();
  594. $cfg = & JEVConfig::getInstance();
  595. $compname = JEV_COM_COMPONENT;
  596. $this->getLatestEventsData();
  597. $content = "";
  598. $k = 0;
  599. if (isset($this->eventsByRelDay) && count($this->eventsByRelDay))
  600. {
  601. $content .= '<table class="mod_events_latest_table" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
  602. // Now to display these events, we just start at the smallest index of the $this->eventsByRelDay array
  603. // and work our way up.
  604. $firstTime = true;
  605. // initialize name of com_jevents module and task defined to view
  606. // event detail. Note that these could change in future com_event
  607. // component revisions!! Note that the '$this->itemId' can be left out in
  608. // the link parameters for event details below since the event.php
  609. // component handler will fetch its own id from the db menu table
  610. // anyways as far as I understand it.
  611. $this->processFormatString();
  612. foreach ($this->eventsByRelDay as $relDay => $daysEvents)
  613. {
  614. reset($daysEvents);
  615. // get all of the events for this day
  616. foreach ($daysEvents as $dayEvent)
  617. {
  618. if ($firstTime)
  619. $content .= '<tr class="jevrow'.$k.'"><td class="mod_events_latest_first">';
  620. else
  621. $content .= '<tr class="jevrow'.$k.'"><td class="mod_events_latest">';
  622. // generate output according custom string
  623. foreach ($this->splitCustomFormat as $condtoken)
  624. {
  625. if (isset($condtoken['cond']))
  626. {
  627. if ($condtoken['cond'] == 'a' && !$dayEvent->alldayevent())
  628. continue;
  629. else if ($condtoken['cond'] == '!a' && $dayEvent->alldayevent())
  630. continue;
  631. else if ($condtoken['cond'] == 'e' && !($dayEvent->noendtime() || $dayEvent->alldayevent()))
  632. continue;
  633. else if ($condtoken['cond'] == '!e' && ($dayEvent->noendtime() || $dayEvent->alldayevent()))
  634. continue;
  635. else if ($condtoken['cond'] == '!m' && $dayEvent->getUnixStartDate() != $dayEvent->getUnixEndDate())
  636. continue;
  637. else if ($condtoken['cond'] == 'm' && $dayEvent->getUnixStartDate() == $dayEvent->getUnixEndDate())
  638. continue;
  639. }
  640. foreach ($condtoken['data'] as $token)
  641. {
  642. unset($match);
  643. unset($dateParm);
  644. $dateParm = "";
  645. $match = '';
  646. if (is_array($token))
  647. {
  648. $match = $token['keyword'];
  649. $dateParm = isset($token['dateParm']) ? trim($token['dateParm']) : "";
  650. }
  651. else if (strpos($token, '${') !== false)
  652. {
  653. $match = $token;
  654. }
  655. else
  656. {
  657. $content .= $token;
  658. continue;
  659. }
  660. $this->processMatch($content, $match, $dayEvent, $dateParm, $relDay);
  661. } // end of foreach
  662. } // end of foreach
  663. $content .= "</td></tr>\n";
  664. $firstTime = false;
  665. } // end of foreach
  666. $k ++;
  667. $k %=2;
  668. } // end of foreach
  669. $content .="</table>\n";
  670. }
  671. else
  672. {
  673. $content .= '<table class="mod_events_latest_table" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
  674. $content .= '<tr class="jevrow'.$k.'"><td class="mod_events_latest_noevents">' . JText::_('JEV_NO_EVENTS') . '</td></tr>' . "\n";
  675. $content .="</table>\n";
  676. }
  677. $callink_HTML = '<div class="mod_events_latest_callink">'
  678. . $this->getCalendarLink()
  679. . '</div>';
  680. if ($this->linkToCal == 1)
  681. $content = $callink_HTML . $content;
  682. if ($this->linkToCal == 2)
  683. $content .= $callink_HTML;
  684. if ($this->displayRSS)
  685. {
  686. if (JVersion::isCompatible("1.6.0")) {
  687. $rssimg = JURI::root() . "media/system/images/livemarks.png";
  688. }
  689. else {
  690. $rssimg = JURI::root() . "images/M_images/livemarks.png";
  691. }
  692. $callink_HTML = '<div class="mod_events_latest_rsslink">'
  693. . '<a href="' . $this->rsslink . '" title="' . JText::_("RSS_FEED") . '" target="_blank">'
  694. . '<img src="' . $rssimg . '" alt="' . JText::_("RSS_FEED") . '" />'
  695. . JText::_("SUBSCRIBE_TO_RSS_FEED")
  696. . '</a>'
  697. . '</div>';
  698. $content .= $callink_HTML;
  699. }
  700. return $content;
  701. }
  702. // end of function
  703. protected function processMatch(&$content, $match, $dayEvent, $dateParm, $relDay)
  704. {
  705. $datenow = JEVHelper::getNow();
  706. $dispatcher = & JDispatcher::getInstance();
  707. // get the title and start time
  708. $startDate = JevDate::strtotime($dayEvent->publish_up());
  709. if ($relDay > 0)
  710. {
  711. $eventDate = JevDate::strtotime($datenow->toFormat('%Y-%m-%d ') . JevDate::strftime('%H:%M', $startDate) . " +$relDay days");
  712. }
  713. else
  714. {
  715. $eventDate = JevDate::strtotime($datenow->toFormat('%Y-%m-%d ') . JevDate::strftime('%H:%M', $startDate) . " $relDay days");
  716. }
  717. $endDate = JevDate::strtotime($dayEvent->publish_down());
  718. list($st_year, $st_month, $st_day) = explode('-', JevDate::strftime('%Y-%m-%d', $startDate));
  719. list($ev_year, $ev_month, $ev_day) = explode('-', JevDate::strftime('%Y-%m-%d', $startDate));
  720. $task_events = 'icalrepeat.detail';
  721. switch ($match) {
  722. case 'endDate':
  723. case 'startDate':
  724. case 'eventDate':
  725. // Note we need to examine the date specifiers used to determine if language translation will be
  726. // necessary. Do this later when script is debugged.
  727. if (!$this->disableDateStyle)
  728. $content .= '<span class="mod_events_latest_date">';
  729. if (!$dayEvent->alldayevent() && $match == "endDate" && ($dayEvent->noendtime() || $dayEvent->getUnixStartTime() == $dayEvent->getUnixEndTime()))
  730. {
  731. $time_fmt = "";
  732. }
  733. else if (!isset($dateParm) || $dateParm == '')
  734. {
  735. if ($this->com_calUseStdTime)
  736. {
  737. $time_fmt = $dayEvent->alldayevent() ? '' : ' @%l:%M%p';
  738. }
  739. else
  740. {
  741. $time_fmt = $dayEvent->alldayevent() ? '' : ' @%H:%M';
  742. }
  743. $dateFormat = $this->displayYear ? '%a %b %d, %Y' . $time_fmt : '%a %b %d' . $time_fmt;
  744. $jmatch = new JevDate($$match);
  745. $content .= $jmatch->toFormat($dateFormat);
  746. //$content .= JEV_CommonFunctions::jev_strftime($dateFormat, $$match);
  747. }
  748. else
  749. {
  750. // format endDate when midnight to show midnight!
  751. if ($match == "endDate" && $dayEvent->sdn()==59){
  752. $tempEndDate = $endDate + 1;
  753. if ($dayEvent->alldayevent()){
  754. // if an all day event then we don't want to roll to the next day
  755. $tempEndDate -= 86400;
  756. }
  757. $match = "tempEndDate";
  758. }
  759. // if a '%' sign detected in date format string, we assume JevDate::strftime() is to be used,
  760. if (preg_match("/\%/", $dateParm))
  761. {
  762. $jmatch = new JevDate($$match);
  763. $content .= $jmatch->toFormat($dateParm);
  764. }
  765. // otherwise the date() function is assumed.
  766. else {
  767. $content .= date($dateParm, $$match);
  768. }
  769. if ($match == "tempDndDate" ){
  770. $match = "endDate";
  771. }
  772. }
  773. if (!$this->disableDateStyle)
  774. $content .= "</span>";
  775. break;
  776. case 'title':
  777. $title = $dayEvent->title();
  778. if (!empty ($dateParm)){
  779. $parts = explode("|",$dateParm);
  780. if (count($parts)>0 && strlen($title)> intval($parts[0])){
  781. $title = substr($title, 0, intval($parts[0]));
  782. if (count($parts)>1) {
  783. $title .= $parts[1];
  784. }
  785. }
  786. }
  787. if (!$this->disableTitleStyle)
  788. $content .= '<span class="mod_events_latest_content">';
  789. if ($this->displayLinks)
  790. {
  791. $link = $dayEvent->viewDetailLink($ev_year, $ev_month, $ev_day, false, $this->myItemid);
  792. $link = JRoute::_($link . $this->datamodel->getCatidsOutLink());
  793. $content .= $this->_htmlLinkCloaking($link, JEventsHTML::special($title));
  794. }
  795. else
  796. {
  797. $content .= JEventsHTML::special($title);
  798. }
  799. if (!$this->disableTitleStyle)
  800. $content .= '</span>';
  801. break;
  802. case 'category':
  803. $catobj = $dayEvent->getCategoryName();
  804. $content .= JEventsHTML::special($catobj);
  805. break;
  806. case 'categoryimage':
  807. $catobj = $dayEvent->getCategoryImage();
  808. $content .= $catobj;
  809. break;
  810. case 'calendar':
  811. $catobj = $dayEvent->getCalendarName();
  812. $content .= JEventsHTML::special($catobj);
  813. break;
  814. case 'contact':
  815. // Also want to cloak contact details so
  816. $this->modparams->set("image", 1);
  817. $dayEvent->text = $dayEvent->contact_info();
  818. if (JVersion::isCompatible("1.6.0")) {
  819. $dispatcher->trigger( 'onContentPrepare', array('com_jevents', &$dayEvent, &$this->modparams, 0));
  820. }
  821. else {
  822. $dispatcher->trigger('onPrepareContent', array(&$dayEvent, &$this->modparams, 0), true);
  823. }
  824. $dayEvent->contact_info($dayEvent->text);
  825. $content .= $dayEvent->contact_info();
  826. break;
  827. case 'content': // Added by Kaz McCoy 1-10-2004
  828. $this->modparams->set("image", 1);
  829. $dayEvent->data->text = $dayEvent->content();
  830. if (JVersion::isCompatible("1.6.0")) {
  831. $dispatcher->trigger( 'onContentPrepare', array('com_jevents', &$dayEvent->data, &$this->modparams, 0));
  832. }
  833. else {
  834. $results = $dispatcher->trigger('onPrepareContent', array(&$dayEvent->data, &$this->modparams, 0), true);
  835. }
  836. if (!empty ($dateParm)){
  837. $parts = explode("|",$dateParm);
  838. if (count($parts)>0 && strlen(strip_tags($dayEvent->data->text)) > intval($parts[0])){
  839. $dayEvent->data->text = substr(strip_tags($dayEvent->data->text), 0, intval($parts[0]));
  840. if (count($parts)>1) {
  841. $dayEvent->data->text .= $parts[1];
  842. }
  843. }
  844. }
  845. $dayEvent->content($dayEvent->data->text);
  846. //$content .= substr($dayEvent->content, 0, 150);
  847. $content .= $dayEvent->content();
  848. break;
  849. case 'addressInfo':
  850. case 'location':
  851. $this->modparams->set("image", 0);
  852. $dayEvent->data->text = $dayEvent->location();
  853. if (JVersion::isCompatible("1.6.0")) {
  854. $dispatcher->trigger( 'onContentPrepare', array('com_jevents', &$dayEvent->data, &$this->modparams, 0));
  855. }
  856. else {
  857. $results = $dispatcher->trigger('onPrepareContent', array(&$dayEvent->data, &$this->modparams, 0), true);
  858. }
  859. $dayEvent->location($dayEvent->data->text);
  860. $content .= $dayEvent->location();
  861. break;
  862. case 'extraInfo':
  863. $this->modparams->set("image", 0);
  864. $dayEvent->data->text = $dayEvent->extra_info();
  865. if (JVersion::isCompatible("1.6.0")) {
  866. $dispatcher->trigger( 'onContentPrepare', array('com_jevents', &$dayEvent->data, &$this->modparams, 0));
  867. }
  868. else {
  869. $results = $dispatcher->trigger('onPrepareContent', array(&$dayEvent->data, &$this->modparams, 0), true);
  870. }
  871. $dayEvent->extra_info($dayEvent->data->text);
  872. $content .= $dayEvent->extra_info();
  873. break;
  874. case 'countdown':
  875. $timedelta = $dayEvent->getUnixStartTime() - JevDate::mktime();
  876. $fieldval = $dateParm;
  877. $shownsign = false;
  878. if (stripos($fieldval, "%d") !== false)
  879. {
  880. $days = intval($timedelta / (60 * 60 * 24));
  881. $timedelta -= $days * 60 * 60 * 24;
  882. $fieldval = str_ireplace("%d", $days, $fieldval);
  883. $shownsign = true;
  884. }
  885. if (stripos($fieldval, "%h") !== false)
  886. {
  887. $hours = intval($timedelta / (60 * 60));
  888. $timedelta -= $hours * 60 * 60;
  889. if ($shownsign)
  890. $hours = abs($hours);
  891. $hours = sprintf("%02d", $hours);
  892. $fieldval = str_ireplace("%h", $hours, $fieldval);
  893. $shownsign = true;
  894. }
  895. if (stripos($fieldval, "%m") !== false)
  896. {
  897. $mins = intval($timedelta / 60);
  898. $timedelta -= $hours * 60;
  899. if ($mins)
  900. $mins = abs($mins);
  901. $mins = sprintf("%02d", $mins);
  902. $fieldval = str_ireplace("%m", $mins, $fieldval);
  903. }
  904. $content .= $fieldval;
  905. break;
  906. case 'createdByAlias':
  907. $content .= $dayEvent->created_by_alias();
  908. break;
  909. case 'createdByUserName':
  910. $catobj = JFactory::getUser($dayEvent->created_by());
  911. $content .= isset($catobj->username) ? $catobj->username : "";
  912. break;
  913. case 'createdByUserEmail':
  914. // Note that users email address will NOT be available if they don't want to receive email
  915. $catobj = JFactory::getUser($dayEvent->created_by());
  916. $content .= $catobj->sendEmail ? $catobj->email : '';
  917. break;
  918. case 'createdByUserEmailLink':
  919. // Note that users email address will NOT be available if they don't want to receive email
  920. $content .= JRoute::_("index.php?option="
  921. . $compname
  922. . "&task=" . $task_events
  923. . "&agid=" . $dayEvent->id()
  924. . "&year=" . $st_year
  925. . "&month=" . $st_month
  926. . "&day=" . $st_day
  927. . "&Itemid=" . $this->myItemid . $this->catout);
  928. break;
  929. case 'color':
  930. $content .= $dayEvent->bgcolor();
  931. break;
  932. case 'eventDetailLink':
  933. $link = $dayEvent->viewDetailLink($st_year, $st_month, $st_day, false, $this->myItemid);
  934. $link = JRoute::_($link . $this->datamodel->getCatidsOutLink());
  935. $content .= $link;
  936. /*
  937. $content .= JRoute::_("index.php?option="
  938. . $compname
  939. . "&task=".$task_events
  940. . "&agid=".$dayEvent->id()
  941. . "&year=".$st_year
  942. . "&month=".$st_month
  943. . "&day=".$st_day
  944. . "&Itemid=".$this->myItemid . $this->catout);
  945. */
  946. break;
  947. default:
  948. try {
  949. if (strpos($match, '${') !== false)
  950. {
  951. $parts = explode('${', $match);
  952. $tempstr = "";
  953. foreach ($parts as $part)
  954. {
  955. if (strpos($part, "}") !== false)
  956. {
  957. $subparts = explode("}", $part);
  958. //$part = str_replace("}","",$part);
  959. $subpart = "_" . $subparts[0];
  960. if (isset($dayEvent->$subpart))
  961. {
  962. $temp = $dayEvent->$subpart;
  963. $tempstr .= $temp;
  964. }
  965. else if (isset($dayEvent->customfields[$subparts[0]]['value']))
  966. {
  967. $temp = $dayEvent->customfields[$subparts[0]]['value'];
  968. $tempstr .= $temp;
  969. }
  970. else {
  971. $layout = "list";
  972. $jevplugins = JPluginHelper::getPlugin("jevents");
  973. foreach ($jevplugins as $jevplugin){
  974. $classname = "plgJevents".ucfirst($jevplugin->name);
  975. if (is_callable(array($classname,"substitutefield"))){
  976. $fieldNameArray = call_user_func(array($classname,"fieldNameArray"),$layout);
  977. if (isset($fieldNameArray["values"])) {
  978. if (in_array($subparts[0],$fieldNameArray["values"] )){
  979. // is the event detail hidden - if so then hide any custom fields too!
  980. if (!isset($event->_privateevent) || $event->_privateevent!=3){
  981. $tempstr .= call_user_func(array($classname,"substitutefield"),$dayEvent,$subparts[0]);
  982. }
  983. }
  984. }
  985. }
  986. }
  987. //$dispatcher->trigger( 'onLatestEventsField', array( &$dayEvent, $subparts[0], &$tempstr));
  988. }
  989. $tempstr .= $subparts[1];
  990. }
  991. else
  992. {
  993. $tempstr .= $part;
  994. }
  995. }
  996. $content .= $tempstr;
  997. }
  998. else if ($match)
  999. $content .= $match;
  1000. }
  1001. catch (Exception $e) {
  1002. if ($match)
  1003. $content .= $match;
  1004. }
  1005. break;
  1006. } // end of switch
  1007. }
  1008. protected function getCalendarLink()
  1009. {
  1010. $menu = & JApplication::getMenu('site');
  1011. $menuItem = $menu->getItem($this->myItemid);
  1012. if ($menuItem && $menuItem->component == JEV_COM_COMPONENT)
  1013. {
  1014. $task = isset($menuItem->query["task"]) ? $menuItem->query["task"] : ($menuItem->query["view"] . "." . $menuItem->query["layout"]);
  1015. }
  1016. else
  1017. {
  1018. $task = "month.calendar";
  1019. }
  1020. return $this->_htmlLinkCloaking(JRoute::_("index.php?option=" . JEV_COM_COMPONENT . "&Itemid=" . $this->myItemid . "&task=" . $task . $this->catout, true), JText::_('JEV_CLICK_TOCOMPONENT'));
  1021. }
  1022. }
  1023. // end of class