PageRenderTime 29ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/com_joomleague/components/com_joomleague/modules/mod_joomleague_calendar/helper.php

https://gitlab.com/julienv/joomleague
PHP | 406 lines | 330 code | 57 blank | 19 comment | 51 complexity | 91616aad0a1a63aeda629fe97a8702c0 MD5 | raw file
  1. <?php
  2. /**
  3. * @version 1.2.2.1
  4. * @package Blog Calendar
  5. * @author Justo Gonzalez de Rivera
  6. * @license GNU/GPL
  7. * modified by johncage for use with joomleague
  8. * @version 1.5.0.1
  9. */
  10. // no direct access
  11. defined('_JEXEC') or die('Restricted access');
  12. //require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
  13. require_once (dirname(__FILE__).DS.'calendarClass.php');
  14. class modJLCalendarHelper
  15. {
  16. function showCal(&$params,$year,$month,$ajax=0,$modid) //this function returns the html of the calendar for a given month
  17. {
  18. global $mainframe;
  19. $offset = 0; //$mainframe->getCfg('offset');
  20. $language= JFactory::getLanguage(); //get the current language
  21. $language->load( 'mod_joomleague_calendar' ); //load the language ini file of the module
  22. $article= $language->_('MOD_JOOMLEAGUE_CALENDAR_VALUEMATCH');
  23. $articles= $language->_('MOD_JOOMLEAGUE_CALENDAR_VALUEMATCHES'); //this strings are used for the titles of the links
  24. $article2= $language->_('MOD_JOOMLEAGUE_CALENDAR_MATCHTHISDAY');
  25. $cal = new JLCalendar; //this object creates the html for the calendar
  26. $dayNamLen= $params->get('cal_length_days');
  27. $cal->dayNames = array(
  28. substr(JText::_( 'SUN' ),0,$dayNamLen),
  29. substr(JText::_( 'MON' ),0,$dayNamLen),
  30. substr(JText::_( 'TUE' ),0,$dayNamLen),
  31. substr(JText::_( 'WED' ),0,$dayNamLen),
  32. substr(JText::_( 'THU' ),0,$dayNamLen),
  33. substr(JText::_( 'FRI' ),0,$dayNamLen),
  34. substr(JText::_( 'SAT' ),0,$dayNamLen)
  35. );
  36. $cal->monthNames = array(
  37. JText::_( 'JANUARY' ),
  38. JText::_( 'FEBRUARY' ),
  39. JText::_( 'MARCH' ),
  40. JText::_( 'APRIL' ),
  41. JText::_( 'MAY' ),
  42. JText::_( 'JUNE' ),
  43. JText::_( 'JULY' ),
  44. JText::_( 'AUGUST' ),
  45. JText::_( 'SEPTEMBER' ),
  46. JText::_( 'OCTOBER' ),
  47. JText::_( 'NOVEMBER' ),
  48. JText::_( 'DECEMBER' )
  49. );
  50. $cal->startDay = $params->get('cal_start_day'); //set the startday (this is the day that appears in the first column). Sunday = 0
  51. //it is loaded from the language ini because it may vary from one country to another, in Spain
  52. //for example, the startday is Monday (1)
  53. $cal->lightbox = $params->get('lightbox');
  54. $cal->lightbox_on_pageload = $params->get('lightbox_on_pageload');
  55. $cal->prefix = $params->get('custom_prefix');
  56. $cal->usedteams = $params->get('usedteams');
  57. $cal->usedclubs = $params->get('usedclubs');
  58. $cal->params = $params;
  59. //set the link for the month, this will be the link for the calendar header (ex. December 2007)
  60. $cal->monthLink=JRoute::_('index.php?option=com_joomleague_calendar' . '&year=' . $year .
  61. '&month=' . $month . '&modid=' . $modid);
  62. $cal->modid= $modid;
  63. $cal->ajax = $ajax;
  64. $cal->getMatches($month,$year);
  65. $counter= Array();
  66. jimport('joomla.utilities.date');
  67. foreach ( $cal->matches as $row )
  68. {
  69. $created= new JDate($row['date'], -$offset);
  70. $createdYear=$created->toFormat('%Y');
  71. $createdMonth=$created->toFormat('%m');
  72. $createdDay=$created->toFormat('%d'); //have to use %d because %e doesn't works on windows
  73. $createdDate=$createdYear . $createdMonth . $createdDay; //this makes an unique variable for every day
  74. $counter[$createdDate]['createdYear'] = $createdYear;
  75. $counter[$createdDate]['createdMonth'] = $createdMonth;
  76. $counter[$createdDate]['createdDay'] = $createdDay;
  77. $counter[$createdDate]['tiptitle'] = $created->toFormat('%A, %d.%m.%Y');
  78. if (!isset($counter[$createdDate]['count'])) $counter[$createdDate]['count'] = 1;
  79. else $counter[$createdDate]['count'] += 1; //$counter[$date] counts the number of articles in each day, to display it as a title in the link of the day
  80. }
  81. foreach ($counter AS $createdDate => $val) {
  82. $title = $counter[$createdDate]['tiptitle'].' :: ' .$counter[$createdDate]['count'] . ' ';
  83. $title .= ($counter[$createdDate]['count'] > 1)? $articles : $article;
  84. $title .= ' ' . $article2;
  85. $inject = $params->get('inject', 0);
  86. $update_module = $params->get('update_module', 0);
  87. $cal->linklist[$createdDate]['click']= 'jlCalmod_showhide(\'jlCalList-'.$modid.'\', \'jlcal_'
  88. .$counter[$createdDate]['createdYear'].'-'.$counter[$createdDate]['createdMonth'].'-'.$counter[$createdDate]['createdDay'].'-'.$modid
  89. .'\', \''.str_replace(' :: ', ': ',$title).'\', '.$inject.', '.$modid.');';
  90. //$cal->linklist[$createdDate]['click']= 'jlcnewDate('.$counter[$createdDate]['createdMonth'].",". $counter[$createdDate]['createdYear'].",".$modid."," .$day.');';
  91. $cal->linklist[$createdDate]['link']= 'javascript:void(0)';
  92. $cal->linklist[$createdDate]['link'].="\" title=\""; //the calendar class sets the links this way: <a href=" . THE LINK STRING . ">
  93. //so, the easiest way to add a title to that link is by setting THE LINK STRING = the link" title="the title
  94. //the result link would be <a href="the link" title="the title">
  95. $cal->linklist[$createdDate]['link'].= $title;
  96. //the above 3 lines output something like: 3 articles on this day. Or: 1 article on this day
  97. }
  98. return $cal->getMonthView($month,$year);
  99. }
  100. function getDate_byId($id)
  101. {
  102. global $mainframe;
  103. $offset = 0; // $mainframe->getCfg('offset');
  104. $prefix = $params->get('custom_prefix');
  105. $query= ' SELECT match_date' .
  106. ' FROM #__joomleague_matches'.
  107. ' WHERE match_id=\'' . $id . '\'';
  108. $query = ($prefix != '') ? str_replace('#__', $prefix, $query) : $query;
  109. $db = JFactory::getDbo();
  110. $db->setQuery($query);
  111. $row=& $db->loadObjectList();
  112. jimport('joomla.utilities.date');
  113. $created=new JDate($row[0]->match_date, -$offset);
  114. $createdYear=$created->toFormat('%Y');
  115. $createdMonth=$created->toFormat('%m');
  116. $createdDay=$created->toFormat('%d');
  117. $createdDate=Array($createdYear,$createdMonth,$createdDay);
  118. return $createdDate;
  119. }
  120. function showDropDown($params,$year,$month,$day,$ajax=0){
  121. $results= $this->setTheQuery($params,$year,$month,$day,$ajax,1);
  122. foreach($results as $key => $result){
  123. $created=new JDate($results[$key]->match_date);
  124. $createdYear= $created->toFormat('%Y');
  125. $createdMonth= $created->toFormat('%m');
  126. $results[$key]->year = $createdYear;
  127. $results[$key]->month = $createdMonth;
  128. $createdYear == $year ? $articleCounter[$createdYear]['now']= true : '';
  129. $createdMonth== $month ? $articleCounter[$createdYear][$createdMonth]['now']= true : '';
  130. if (!isset($articleCounter[$createdYear][$createdMonth]['total'])) $articleCounter[$createdYear][$createdMonth]['total'] = 0;
  131. if (!isset($articleCounter[$createdYear]['total'])) $articleCounter[$createdYear]['total'] = 0;
  132. $articleCounter[$createdYear][$createdMonth]['total']++;
  133. $articleCounter[$createdYear]['total']++;
  134. }
  135. return array($results,$articleCounter);
  136. }
  137. }
  138. class JLCalendar extends PHPCalendar
  139. {
  140. var $linklist; //this variable will be an array that contains all the links of the month
  141. var $prefix;
  142. var $params;
  143. var $matches = array();
  144. var $teams = array();
  145. var $teamslist = array();
  146. function addTeam($id, $name='', $pic='')
  147. {
  148. if (! array_key_exists($id, $this->teams)&& $id > 0){
  149. $this->teams[$id] = new stdclass;
  150. $this->teams[$id]->value = $id;
  151. $this->teams[$id]->name = $name;
  152. $this->teams[$id]->picture = $pic;
  153. $this->teamslist[] = $this->teams[$id];
  154. }
  155. }
  156. function getDateLink($day, $month, $year) //this function is called from getMonthView(month,year) to get the link of the given day
  157. { //if this function returns nothing (""), then getMonthView wont put a link on that day
  158. $link = "";
  159. if(strlen($month)<2)
  160. $month = '0'.$month;
  161. if(strlen($day)<2)
  162. $day = '0'.$day;
  163. $date= $year . $month . $day;
  164. if(isset($this->linklist[$date]['link'])){
  165. $link=$this->linklist[$date]['link']; //$this->linklist[$date] was set for every date in the foreach bucle at lines 50-83
  166. }
  167. return $link;
  168. }
  169. function getDateClick($day, $month, $year) //this function is called from getMonthView(month,year) to get the link of the given day
  170. { //if this function returns nothing (""), then getMonthView wont put a link on that day
  171. $link = "";
  172. if(strlen($month)<2)
  173. $month = '0'.$month;
  174. if(strlen($day)<2)
  175. $day = '0'.$day;
  176. $date= $year . $month . $day;
  177. if(isset($this->linklist[$date]['click'])){
  178. $link=$this->linklist[$date]['click']; //$this->linklist[$date] was set for every date in the foreach bucle at lines 50-83
  179. }
  180. return $link;
  181. }
  182. //Return the URL to link to in order to display a calendar for a given month/year.
  183. //this function is called to get the links of the two arrows in the header.
  184. function getCalendarLink($month, $year)
  185. {
  186. $getquery = JRequest::get('GET'); //get the GET query
  187. $calendarLink= JUri::current().'?'; //get the current url, without the GET query; and add "?", to set the GET vars
  188. foreach($getquery as $key => $value){ /*this bucle goes through every GET variable that was in the url*/
  189. if($key!='month' AND $key!='year' AND $key!='day' AND $value){ /*the month,year, and day Variables must be diferent of the current ones, because this is a link for a diferent month */
  190. $calendarLink.= $key . '=' . $value . '&amp;';
  191. }
  192. }
  193. $calendarLink.='month='.$month.'&amp;year='.$year; //add the month and the year that was passed to the function to the GET string
  194. return $calendarLink;
  195. }
  196. function jl_utf8_convert ($text, $fromenc='iso-8859-1', $toenc='UTF-8' )
  197. {
  198. if (strtolower($fromenc)==strtolower($toenc) || $this->params->get('convert', 0)==0) return $text;
  199. elseif (function_exists('iconv')) {
  200. return iconv($fromenc, $toenc, $text);
  201. }
  202. elseif (strtolower($fromenc) == 'iso-8859-1' && strtolower($toenc) == 'utf-8') {
  203. return utf8_encode($text);
  204. }
  205. elseif (strtolower($fromenc) == 'utf-8' && strtolower($toenc) == 'iso-8859-1') {
  206. return utf8_decode($text);
  207. }
  208. else return $text;
  209. }
  210. function sortObject($array, $comparefunction, $property = '')
  211. {
  212. $zcount=count($array);
  213. for($i=1;$i<$zcount;$i++){
  214. for ($a=$zcount-1;$a>=$i;$a--) {
  215. if($this->$comparefunction($array[$a-1]->$property,$array[$a]->$property)>0){
  216. $tempzal=$array[$a-1];
  217. $array[$a-1]=$array[$a];
  218. $array[$a]=$tempzal;
  219. }
  220. }
  221. }
  222. return $array;
  223. }
  224. function sortArray($array, $comparefunction, $property = ''){
  225. $zcount=count($array);
  226. for($i=1;$i<$zcount;$i++){
  227. for ($a=$zcount-1;$a>=$i;$a--) {
  228. if($this->$comparefunction($array[$a-1][$property],$array[$a][$property])>0){
  229. $tempzal=$array[$a-1];
  230. $array[$a-1]=$array[$a];
  231. $array[$a]=$tempzal;
  232. }
  233. }
  234. }
  235. return $array;
  236. }
  237. function asc($a,$b){
  238. if($a<$b)return -1;
  239. if($a==$b)return 0;
  240. return 1;
  241. }
  242. function desc($a,$b){
  243. if($a>$b)return -1;
  244. if($a==$b)return 0;
  245. return 1;
  246. }
  247. function getMatches($month, $year) {
  248. $livescore = $this->params->get('livescore', '');
  249. $joomleague = $this->params->get('joomleague', '');
  250. $caldates = array();
  251. $caldates['start'] = date("$year-$month-01 00:00:00");
  252. $caldates['end'] = date("$year-$month-31 23:59:59");
  253. $jlrows = array();
  254. $lsrows = array();
  255. $usejevents = $this->params->get('jevents', 0);
  256. if ( $usejevents == 1 ) {
  257. $day = 0;
  258. require_once (dirname(__FILE__).DS.'connectors'.DS.'jevents.php');
  259. JEventsConnector::getEntries($caldates, $this->params, $this->matches);
  260. }
  261. require_once (dirname(__FILE__).DS.'connectors'.DS.$joomleague.'.php');
  262. $this->params->prefix = $this->prefix;
  263. JoomleagueConnector::getEntries ( $caldates, $this->params, $this->matches );
  264. if ($livescore != ''){
  265. require_once (dirname(__FILE__).DS.'connectors'.DS.'livescore.php');
  266. $this->params->prefix = $this->params->get('prefix_livescore', '');
  267. LivescoreConnector::getMatches ( $caldates, $this->params, $this->matches );
  268. }
  269. $matches = $this->sortArray($this->matches, 'asc', 'date');
  270. $this->matches = $matches;
  271. return $matches;
  272. }
  273. function matches_output($month, $year) {
  274. global $mainframe;
  275. $language= JFactory::getLanguage(); //get the current language
  276. $language->load( 'mod_joomleague_calendar' ); //load the language ini file of the module
  277. $article= $language->_('MOD_JOOMLEAGUE_CALENDAR_VALUEMATCH');
  278. $articles= $language->_('MOD_JOOMLEAGUE_CALENDAR_VALUEMATCHES'); //this strings are used for the titles of the links
  279. $article2= $language->_('MOD_JOOMLEAGUE_CALENDAR_MATCHTHISDAY');
  280. $noarticle= $language->_('MOD_JOOMLEAGUE_CALENDAR_NOMATCHES');
  281. $outstring = '';
  282. $todaystring = '';
  283. $matches = $this->matches;
  284. $div = '';
  285. $now = new JDate();
  286. $today = $now->toFormat('%Y-%m-%d');
  287. $todaytitle = '';
  288. $pm='';
  289. $offset = 0; // $mainframe->getCfg('offset');
  290. $update_module = $this->params->get('update_module', 0);
  291. $totalgamesstring = (count($matches)>0) ? count($matches) : $noarticle;
  292. $totalgamesstring .= ' ';
  293. $totalgamesstring .= (count($matches) > 1) ? $articles : $article;
  294. $totalgamesstring .= ' ';
  295. $totalgamesstring .= $language->_('MOD_JOOMLEAGUE_CALENDAR_VALUEMATCHESMONTH') . ' ' .$this->monthNames[$month - 1] . ' ' . $year;
  296. $thistitle = ($todaytitle != '') ? $todaytitle : $totalgamesstring;
  297. $thistitle = $totalgamesstring;
  298. $format = array();
  299. $format[] = array('tag' => 'span', 'divid' => 'oldjlCalListTitle-'.$this->modid, 'class' => 'jlcal_hiddenmatches', 'text' => $totalgamesstring);
  300. $format[] = array('tag' => 'span', 'divid' => 'jlCalListTitle-'.$this->modid, 'class' => 'jlCalListTitle', 'text' => $thistitle);
  301. $format[] = array('tag' => 'span', 'divid' => 'jlCalListDayTitle-'.$this->modid, 'class' => 'jlCalListTitle', 'text' => '');
  302. for ($x=0;$x<count($matches);$x++) {
  303. $sclass = ($x%2) ? 'sectiontableentry1' : 'sectiontableentry2';
  304. $row = $matches[$x];
  305. $thispm = $row['project_id'].'_'.$row['matchcode'].'_'.$row['type'];
  306. $da= new JDate($row['date'], -$offset);
  307. if ($div !=$da->toFormat('%Y-%m-%d')) {
  308. $counter = 0;
  309. $div = $da->toFormat('%Y-%m-%d');
  310. $format[] = array('tag' => 'div', 'divid' => 'jlcal_'.$div."-".$this->modid, 'class' => 'jlcal_hiddenmatches');
  311. $format[] = array('tag' => 'table', 'divid' => 'jlcal_'.$div."-".$this->modid, 'class' => 'jlcal_result_table');
  312. }
  313. if($pm != $thispm) {
  314. $format[] = array('tag' => 'headingrow', 'text' => $row['headingtitle']);
  315. $roundname = $row['headingtitle'];
  316. }
  317. $pm = $thispm;
  318. $format[] = $row;
  319. $counter++;
  320. if (isset($matches[$x+1])) $nd= new JDate($matches[$x+1]['date'], -$offset);
  321. else $nd = false;
  322. if (!$nd || $nd->toFormat('%Y-%m-%d') != $da->toFormat('%Y-%m-%d')) {
  323. $pm = '';
  324. $format[] = array('tag' => 'tableend');
  325. $format[] = array('tag' => 'divend');
  326. $titletext = $counter;
  327. $titletext .= ' ';
  328. $titletext .= ($counter > 1)? $articles : $article;
  329. $titletext .= ' ';
  330. $titletext .= ($today == $da->toFormat('%Y-%m-%d')) ? $language->_('MOD_JOOMLEAGUE_CALENDAR_TODAY'): $language->_('MOD_JOOMLEAGUE_CALENDAR_AT');
  331. $titletext .= ' ' .$da->toFormat('%d').'. '.$this->monthNames[$month - 1] . ' ' . $year;
  332. $format[] = array('tag' => 'span', 'divid' => 'jlcaltitte_'.$div."-".$this->modid, 'class' => 'jlcal_hiddenmatches', 'text' => $titletext);
  333. }
  334. }
  335. return $format;
  336. }
  337. function output_teamlist() {
  338. $teamslist = array();
  339. if(count($this->teams) > 0 && $this->params->get('show_teamslist', 0) == 1) {
  340. $teams = $this->sortObject($this->teamslist, 'asc', 'name');
  341. $teamslist[] = JHtml::_('select.option', 0, JText::_($this->params->get('teamslist_option')));
  342. foreach ($teams AS $id => $obj) {
  343. $teamslist[] = JHtml::_('select.option', $obj->value, JText::_($obj->name));
  344. }
  345. }
  346. return $teamslist;
  347. }
  348. }
  349. ?>