PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/html/AppCode/expressionengine/modules/channel/mod.channel_calendar.php

https://github.com/w3bg/www.hsifin.com
PHP | 796 lines | 483 code | 149 blank | 164 comment | 66 complexity | 867e32651a8066e19045d9533047f3fb MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author ExpressionEngine Dev Team
  7. * @copyright Copyright (c) 2003 - 2010, EllisLab, Inc.
  8. * @license http://expressionengine.com/user_guide/license.html
  9. * @link http://expressionengine.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // --------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Channel Calendar Module
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Modules
  19. * @category Modules
  20. * @author ExpressionEngine Dev Team
  21. * @link http://expressionengine.com
  22. */
  23. class Channel_calendar extends Channel {
  24. var $sql = '';
  25. /** ----------------------------------------
  26. /** Channel Calendar
  27. /** ----------------------------------------*/
  28. function calendar()
  29. {
  30. // Rick is using some funky conditional stuff for the calendar, so
  31. // we have to reassign the var_cond array using the legacy conditional
  32. // parser. Bummer, but whatcha going to do?
  33. $this->EE->TMPL->var_cond = $this->EE->functions->assign_conditional_variables($this->EE->TMPL->tagdata, '/', LD, RD);
  34. /** ----------------------------------------
  35. /** Determine the Month and Year
  36. /** ----------------------------------------*/
  37. $year = '';
  38. $month = '';
  39. // Hard-coded month/year via tag parameters
  40. if ($this->EE->TMPL->fetch_param('month') AND $this->EE->TMPL->fetch_param('year'))
  41. {
  42. $year = $this->EE->TMPL->fetch_param('year');
  43. $month = $this->EE->TMPL->fetch_param('month');
  44. if (strlen($month) == 1)
  45. {
  46. $month = '0'.$month;
  47. }
  48. }
  49. else
  50. {
  51. // Month/year in query string
  52. if (preg_match("#(\d{4}/\d{2})#", $this->EE->uri->query_string, $match))
  53. {
  54. $ex = explode('/', $match['1']);
  55. $time = mktime(0, 0, 0, $ex['1'], 01, $ex['0']);
  56. // $time = $this->EE->localize->set_localized_time(mktime(0, 0, 0, $ex['1'], 01, $ex['0']));
  57. $year = date("Y", $time);
  58. $month = date("m", $time);
  59. }
  60. else
  61. {
  62. // Defaults to current month/year
  63. $year = date("Y", $this->EE->localize->set_localized_time($this->EE->localize->now));
  64. $month = date("m", $this->EE->localize->set_localized_time($this->EE->localize->now));
  65. }
  66. }
  67. /** ----------------------------------------
  68. /** Set Unix timestamp for the given month/year
  69. /** ----------------------------------------*/
  70. $local_date = mktime(12, 0, 0, $month, 1, $year);
  71. // $local_date = $this->EE->localize->set_localized_time($local_date);
  72. /** ----------------------------------------
  73. /** Determine the total days in the month
  74. /** ----------------------------------------*/
  75. $adjusted_date = $this->EE->localize->adjust_date($month, $year);
  76. $month = $adjusted_date['month'];
  77. $year = $adjusted_date['year'];
  78. $total_days = $this->EE->localize->fetch_days_in_month($month, $year);
  79. $previous_date = mktime(12, 0, 0, $month-1, 1, $year);
  80. $next_date = mktime(12, 0, 0, $month+1, 1, $year);
  81. /** ---------------------------------------
  82. /** Determine the total days of the previous month
  83. /** ---------------------------------------*/
  84. $adj_prev_date = $this->EE->localize->adjust_date($month-1, $year);
  85. $prev_month = $adj_prev_date['month'];
  86. $prev_year = $adj_prev_date['year'];
  87. $prev_total_days = $this->EE->localize->fetch_days_in_month($prev_month, $prev_year);
  88. /** ----------------------------------------
  89. /** Set the starting day of the week
  90. /** ----------------------------------------*/
  91. // This can be set using a parameter in the tag: start_day="saturday"
  92. // By default the calendar starts on sunday
  93. $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6);
  94. $start_day = (isset($start_days[$this->EE->TMPL->fetch_param('start_day')])) ? $start_days[$this->EE->TMPL->fetch_param('start_day')]: 0;
  95. $date = getdate($local_date);
  96. $day = $start_day + 1 - $date["wday"];
  97. while ($day > 1)
  98. {
  99. $day -= 7;
  100. }
  101. /** ----------------------------------------
  102. /** {previous_path="channel/index"}
  103. /** ----------------------------------------*/
  104. // This variables points to the previous month
  105. if (preg_match_all("#".LD."previous_path=(.+?)".RD."#", $this->EE->TMPL->tagdata, $matches))
  106. {
  107. $adjusted_date = $this->EE->localize->adjust_date($month - 1, $year, TRUE);
  108. foreach ($matches['1'] as $match)
  109. {
  110. $path = $this->EE->functions->create_url($match).'/'.$adjusted_date['year'].'/'.$adjusted_date['month'];
  111. $this->EE->TMPL->tagdata = preg_replace("#".LD."previous_path=.+?".RD."#", $path, $this->EE->TMPL->tagdata, 1);
  112. }
  113. }
  114. /** ----------------------------------------
  115. /** {next_path="channel/index"}
  116. /** ----------------------------------------*/
  117. // This variables points to the next month
  118. if (preg_match_all("#".LD."next_path=(.+?)".RD."#", $this->EE->TMPL->tagdata, $matches))
  119. {
  120. $adjusted_date = $this->EE->localize->adjust_date($month + 1, $year, TRUE);
  121. foreach ($matches['1'] as $match)
  122. {
  123. $path = $this->EE->functions->create_url($match).'/'.$adjusted_date['year'].'/'.$adjusted_date['month'];
  124. $this->EE->TMPL->tagdata = preg_replace("#".LD."next_path=.+?".RD."#", $path, $this->EE->TMPL->tagdata, 1);
  125. }
  126. }
  127. /** ----------------------------------------
  128. /** {date format="%m %Y"}
  129. /** ----------------------------------------*/
  130. // This variable is used in the heading of the calendar
  131. // to show the month and year
  132. if (preg_match_all("#".LD."date format=[\"|'](.+?)[\"|']".RD."#", $this->EE->TMPL->tagdata, $matches))
  133. {
  134. foreach ($matches['1'] as $match)
  135. {
  136. $this->EE->TMPL->tagdata = preg_replace("#".LD."date format=.+?".RD."#", $this->EE->localize->decode_date($match, $local_date), $this->EE->TMPL->tagdata, 1);
  137. }
  138. }
  139. /** ----------------------------------------
  140. /** {previous_date format="%m %Y"}
  141. /** ----------------------------------------*/
  142. // This variable is used in the heading of the calendar
  143. // to show the month and year
  144. if (preg_match_all("#".LD."previous_date format=[\"|'](.+?)[\"|']".RD."#", $this->EE->TMPL->tagdata, $matches))
  145. {
  146. foreach ($matches['1'] as $match)
  147. {
  148. $this->EE->TMPL->tagdata = preg_replace("#".LD."previous_date format=.+?".RD."#", $this->EE->localize->decode_date($match, $previous_date), $this->EE->TMPL->tagdata, 1);
  149. }
  150. }
  151. /** ----------------------------------------
  152. /** {next_date format="%m %Y"}
  153. /** ----------------------------------------*/
  154. // This variable is used in the heading of the calendar
  155. // to show the month and year
  156. if (preg_match_all("#".LD."next_date format=[\"|'](.+?)[\"|']".RD."#", $this->EE->TMPL->tagdata, $matches))
  157. {
  158. foreach ($matches['1'] as $match)
  159. {
  160. $this->EE->TMPL->tagdata = preg_replace("#".LD."next_date format=.+?".RD."#", $this->EE->localize->decode_date($match, $next_date), $this->EE->TMPL->tagdata, 1);
  161. }
  162. }
  163. /** ----------------------------------------
  164. /** Day Heading
  165. /** ----------------------------------------*/
  166. /*
  167. This code parses out the headings for each day of the week
  168. Contained in the tag will be this variable pair:
  169. {calendar_heading}
  170. <td class="calendarDayHeading">{lang:weekday_abrev}</td>
  171. {/calendar_heading}
  172. There are three display options for the header:
  173. {lang:weekday_abrev} = S M T W T F S
  174. {lang:weekday_short} = Sun Mon Tues, etc.
  175. {lang:weekday_long} = Sunday Monday Tuesday, etc.
  176. */
  177. foreach (array('Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa') as $val)
  178. {
  179. $day_names_a[] = ( ! $this->EE->lang->line($val)) ? $val : $this->EE->lang->line($val);
  180. }
  181. foreach (array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat') as $val)
  182. {
  183. $day_names_s[] = ( ! $this->EE->lang->line($val)) ? $val : $this->EE->lang->line($val);
  184. }
  185. foreach (array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') as $val)
  186. {
  187. $day_names_l[] = ( ! $this->EE->lang->line($val)) ? $val : $this->EE->lang->line($val);
  188. }
  189. if (preg_match("/".LD."calendar_heading".RD."(.*?)".LD.'\/'."calendar_heading".RD."/s", $this->EE->TMPL->tagdata, $match))
  190. {
  191. $temp = '';
  192. for ($i = 0; $i < 7; $i ++)
  193. {
  194. $temp .= str_replace(array( LD.'lang:weekday_abrev'.RD,
  195. LD.'lang:weekday_short'.RD,
  196. LD.'lang:weekday_long'.RD),
  197. array( $day_names_a[($start_day + $i) %7],
  198. $day_names_s[($start_day + $i) %7],
  199. $day_names_l[($start_day + $i) %7]),
  200. trim($match['1'])."\n");
  201. }
  202. $this->EE->TMPL->tagdata = preg_replace ("/".LD."calendar_heading".RD.".*?".LD.'\/'."calendar_heading".RD."/s", trim($temp), $this->EE->TMPL->tagdata);
  203. }
  204. /** ----------------------------------------
  205. /** Separate out cell data
  206. /** ----------------------------------------*/
  207. // We need to strip out the various variable pairs
  208. // that allow us to render each calendar cell.
  209. // We'll do this up-front and assign temporary markers
  210. // in the template which we will replace with the final
  211. // data later
  212. $row_start = '';
  213. $row_end = '';
  214. $row_chunk = '';
  215. $row_chunk_m = '94838dkAJDei8azDKDKe01';
  216. $entries = '';
  217. $entries_m = 'Gm983TGxkedSPoe0912NNk';
  218. $if_today = '';
  219. $if_today_m = 'JJg8e383dkaadPo20qxEid';
  220. $if_entries = '';
  221. $if_entries_m = 'Rgh43K0L0Dff9003cmqQw1';
  222. $if_not_entries = '';
  223. $if_not_entries_m = 'yr83889910BvndkGei8ti3';
  224. $if_blank = '';
  225. $if_blank_m = '43HDueie4q7pa8dAAseit6';
  226. if (preg_match("/".LD."calendar_rows".RD."(.*?)".LD.'\/'."calendar_rows".RD."/s", $this->EE->TMPL->tagdata, $match))
  227. {
  228. $row_chunk = trim($match['1']);
  229. // Fetch all the entry_date variable
  230. if (preg_match_all("/".LD."entry_date\s+format=[\"'](.*?)[\"']".RD."/s", $row_chunk, $matches))
  231. {
  232. for ($j = 0; $j < count($matches['0']); $j++)
  233. {
  234. $matches['0'][$j] = str_replace(array(LD,RD), '', $matches['0'][$j]);
  235. $entry_dates[$matches['0'][$j]] = $this->EE->localize->fetch_date_params($matches['1'][$j]);
  236. }
  237. }
  238. if (preg_match("/".LD."row_start".RD."(.*?)".LD.'\/'."row_start".RD."/s", $row_chunk, $match))
  239. {
  240. $row_start = trim($match['1']);
  241. $row_chunk = trim(str_replace ($match['0'], "", $row_chunk));
  242. }
  243. if (preg_match("/".LD."row_end".RD."(.*?)".LD.'\/'."row_end".RD."/s", $row_chunk, $match))
  244. {
  245. $row_end = trim($match['1']);
  246. $row_chunk = trim(str_replace($match['0'], "", $row_chunk));
  247. }
  248. foreach ($this->EE->TMPL->var_cond as $key => $val)
  249. {
  250. if ($val['3'] == 'today')
  251. {
  252. $if_today = trim($val['2']);
  253. $row_chunk = str_replace ($val['1'], $if_today_m, $row_chunk);
  254. unset($this->EE->TMPL->var_cond[$key]);
  255. }
  256. if ($val['3'] == 'entries')
  257. {
  258. $if_entries = trim($val['2']);
  259. $row_chunk = str_replace ($val['1'], $if_entries_m, $row_chunk);
  260. unset($this->EE->TMPL->var_cond[$key]);
  261. }
  262. if ($val['3'] == 'not_entries')
  263. {
  264. $if_not_entries = trim($val['2']);
  265. $row_chunk = str_replace ($val['1'], $if_not_entries_m, $row_chunk);
  266. unset($this->EE->TMPL->var_cond[$key]);
  267. }
  268. if ($val['3'] == 'blank')
  269. {
  270. $if_blank = trim($val['2']);
  271. $row_chunk = str_replace ($val['1'], $if_blank_m, $row_chunk);
  272. unset($this->EE->TMPL->var_cond[$key]);
  273. }
  274. if (preg_match("/".LD."entries".RD."(.*?)".LD.'\/'."entries".RD."/s", $if_entries, $match))
  275. {
  276. $entries = trim($match['1']);
  277. $if_entries = trim(str_replace($match['0'], $entries_m, $if_entries));
  278. }
  279. }
  280. $this->EE->TMPL->tagdata = preg_replace ("/".LD."calendar_rows".RD.".*?".LD.'\/'."calendar_rows".RD."/s", $row_chunk_m, $this->EE->TMPL->tagdata);
  281. }
  282. /** ----------------------------------------
  283. /** Fetch {switch} variable
  284. /** ----------------------------------------*/
  285. // This variable lets us use a different CSS class
  286. // for the current day
  287. $switch_t = '';
  288. $switch_c = '';
  289. if ($this->EE->TMPL->fetch_param('switch'))
  290. {
  291. $x = explode("|", $this->EE->TMPL->fetch_param('switch'));
  292. if (count($x) == 2)
  293. {
  294. $switch_t = $x['0'];
  295. $switch_c = $x['1'];
  296. }
  297. }
  298. /** ---------------------------------------
  299. /** Set the day number numeric format
  300. /** ---------------------------------------*/
  301. $day_num_fmt = ($this->EE->TMPL->fetch_param('leading_zeroes') == 'yes') ? "%02d" : "%d";
  302. /** ----------------------------------------
  303. /** Build the SQL query
  304. /** ----------------------------------------*/
  305. $this->initialize();
  306. $this->build_sql_query('/'.$year.'/'.$month.'/');
  307. if ($this->sql != '')
  308. {
  309. $query = $this->EE->db->query($this->sql);
  310. $data = array();
  311. if ($query->num_rows() > 0)
  312. {
  313. // We'll need this later
  314. $this->EE->load->library('typography');
  315. $this->EE->typography->initialize();
  316. $this->EE->typography->convert_curly = FALSE;
  317. /** ----------------------------------------
  318. /** Fetch query results and build data array
  319. /** ----------------------------------------*/
  320. foreach ($query->result_array() as $row)
  321. {
  322. /** ----------------------------------------
  323. /** Adjust dates if needed
  324. /** ----------------------------------------*/
  325. // If the "dst_enabled" item is set in any given entry
  326. // we need to offset to the timestamp by an hour
  327. if ($row['entry_date'] != '')
  328. $row['entry_date'] = $this->EE->localize->offset_entry_dst($row['entry_date'], $row['dst_enabled'], FALSE);
  329. /** ----------------------------------------
  330. /** Define empty arrays and strings
  331. /** ----------------------------------------*/
  332. $defaults = array(
  333. 'entry_date' => 'a',
  334. 'permalink' => 'a',
  335. 'title_permalink' => 'a',
  336. 'author' => 's',
  337. 'profile_path' => 'a',
  338. 'id_path' => 'a',
  339. 'base_fields' => 'a',
  340. 'day_path' => 'a',
  341. 'comment_auto_path' => 's',
  342. 'comment_entry_id_auto_path' => 's',
  343. 'comment_url_title_auto_path' => 's'
  344. );
  345. foreach ($defaults as $key => $val)
  346. {
  347. $$key = ($val == 'a') ? array() : '';
  348. }
  349. /** ---------------------------
  350. /** Single Variables
  351. /** ---------------------------*/
  352. foreach ($this->EE->TMPL->var_single as $key => $val)
  353. {
  354. if (isset($entry_dates[$key]))
  355. {
  356. foreach ($entry_dates[$key] as $dvar)
  357. $val = str_replace($dvar, $this->EE->localize->convert_timestamp($dvar, $row['entry_date'], TRUE), $val);
  358. $entry_date[$key] = $val;
  359. }
  360. /** ----------------------------------------
  361. /** parse permalink
  362. /** ----------------------------------------*/
  363. if (strncmp($key, 'permalink', 9) == 0)
  364. {
  365. if ($this->EE->functions->extract_path($key) != '' AND $this->EE->functions->extract_path($key) != 'SITE_INDEX')
  366. {
  367. $path = $this->EE->functions->extract_path($key).'/'.$row['entry_id'];
  368. }
  369. else
  370. {
  371. $path = $row['entry_id'];
  372. }
  373. $permalink[$key] = $this->EE->functions->create_url($path);
  374. }
  375. /** ----------------------------------------
  376. /** parse title permalink
  377. /** ----------------------------------------*/
  378. if (strncmp($key, 'title_permalink', 15) == 0 OR strncmp($key, 'url_title_path', 14) == 0)
  379. {
  380. if ($this->EE->functions->extract_path($key) != '' AND $this->EE->functions->extract_path($key) != 'SITE_INDEX')
  381. {
  382. $path = $this->EE->functions->extract_path($key).'/'.$row['url_title'];
  383. }
  384. else
  385. {
  386. $path = $row['url_title'];
  387. }
  388. $title_permalink[$key] = $this->EE->functions->create_url($path);
  389. }
  390. /** ----------------------------------------
  391. /** {comment_auto_path}
  392. /** ----------------------------------------*/
  393. if ($key == "comment_auto_path")
  394. {
  395. $comment_auto_path = ($row['comment_url'] == '') ? $row['channel_url'] : $row['comment_url'];
  396. }
  397. /** ----------------------------------------
  398. /** {comment_url_title_auto_path}
  399. /** ----------------------------------------*/
  400. if ($key == "comment_url_title_auto_path")
  401. {
  402. $path = ($row['comment_url'] == '') ? $row['channel_url'] : $row['comment_url'];
  403. $comment_url_title_auto_path = $path.$row['url_title'];
  404. }
  405. /** ----------------------------------------
  406. /** {comment_entry_id_auto_path}
  407. /** ----------------------------------------*/
  408. if ($key == "comment_entry_id_auto_path")
  409. {
  410. $path = ($row['comment_url'] == '') ? $row['channel_url'] : $row['comment_url'];
  411. $comment_entry_id_auto_path = $path.$row['entry_id'];
  412. }
  413. /** ----------------------------------------
  414. /** {author}
  415. /** ----------------------------------------*/
  416. if ($key == "author")
  417. {
  418. $author = ($row['screen_name'] != '') ? $row['screen_name'] : $row['username'];
  419. }
  420. /** ----------------------------------------
  421. /** profile path
  422. /** ----------------------------------------*/
  423. if (strncmp($key, 'profile_path', 12) == 0)
  424. {
  425. $profile_path[$key] = $this->EE->functions->create_url($this->EE->functions->extract_path($key).'/'.$row['member_id']);
  426. }
  427. /** ----------------------------------------
  428. /** parse comment_path
  429. /** ----------------------------------------*/
  430. if (strncmp($key, 'comment_path', 12) == 0 OR strncmp($key, 'entry_id_path', 13) == 0)
  431. {
  432. $id_path[$key] = $this->EE->functions->create_url($this->EE->functions->extract_path($key).'/'.$row['entry_id']);
  433. }
  434. /** ----------------------------------------
  435. /** Basic fields (username, screen_name, etc.)
  436. /** ----------------------------------------*/
  437. if (isset($row[$val]))
  438. {
  439. $base_fields[$key] = $row[$val];
  440. }
  441. /** ----------------------------------------
  442. /** {day_path}
  443. /** ----------------------------------------*/
  444. if (strncmp($key, 'day_path', 8) == 0)
  445. {
  446. $d = date('d', $this->EE->localize->set_localized_time($row['entry_date']));
  447. $m = date('m', $this->EE->localize->set_localized_time($row['entry_date']));
  448. $y = date('Y', $this->EE->localize->set_localized_time($row['entry_date']));
  449. if ($this->EE->functions->extract_path($key) != '' AND $this->EE->functions->extract_path($key) != 'SITE_INDEX')
  450. {
  451. $path = $this->EE->functions->extract_path($key).'/'.$y.'/'.$m.'/'.$d;
  452. }
  453. else
  454. {
  455. $path = $y.'/'.$m.'/'.$d;
  456. }
  457. $if_entries = str_replace(LD.$key.RD, LD.'day_path'.$val.RD, $if_entries);
  458. $day_path[$key] = $this->EE->functions->create_url($path);
  459. }
  460. }
  461. // END FOREACH SINGLE VARIABLES
  462. /** ----------------------------------------
  463. /** Build Data Array
  464. /** ----------------------------------------*/
  465. $d = date('d', $this->EE->localize->set_localized_time($row['entry_date']));
  466. if (substr($d, 0, 1) == '0')
  467. {
  468. $d = substr($d, 1);
  469. }
  470. $data[$d][] = array(
  471. $this->EE->typography->parse_type($row['title'], array('text_format' => 'lite', 'html_format' => 'none', 'auto_links' => 'n', 'allow_img_url' => 'no')),
  472. $row['url_title'],
  473. $entry_date,
  474. $permalink,
  475. $title_permalink,
  476. $author,
  477. $profile_path,
  478. $id_path,
  479. $base_fields,
  480. $day_path,
  481. $comment_auto_path,
  482. $comment_url_title_auto_path,
  483. $comment_entry_id_auto_path
  484. );
  485. } // END FOREACH
  486. } // END if ($query->num_rows() > 0)
  487. } // END if ($this->query != '')
  488. /** ----------------------------------------
  489. /** Build Calendar Cells
  490. /** ----------------------------------------*/
  491. $out = '';
  492. $today = getdate($this->EE->localize->set_localized_time($this->EE->localize->now));
  493. while ($day <= $total_days)
  494. {
  495. $out .= $row_start;
  496. for ($i = 0; $i < 7; $i++)
  497. {
  498. if ($day > 0 AND $day <= $total_days)
  499. {
  500. if ($if_entries != '' AND isset($data[$day]))
  501. {
  502. $out .= str_replace($if_entries_m, $this->var_replace($if_entries, $data[$day], $entries), $row_chunk);
  503. foreach($day_path as $k => $v)
  504. {
  505. $out = str_replace(LD.'day_path'.$k.RD, $data[$day]['0']['9'][$k], $out);
  506. }
  507. }
  508. else
  509. {
  510. $out .= str_replace($if_not_entries_m, $if_not_entries, $row_chunk);
  511. }
  512. $out = str_replace(LD.'day_number'.RD, sprintf($day_num_fmt, $day), $out);
  513. if ($day == $today["mday"] AND $month == $today["mon"] AND $year == $today["year"])
  514. {
  515. $out = str_replace(LD.'switch'.RD, $switch_t, $out);
  516. }
  517. else
  518. {
  519. $out = str_replace(LD.'switch'.RD, $switch_c, $out);
  520. }
  521. }
  522. else
  523. {
  524. $out .= str_replace($if_blank_m, $if_blank, $row_chunk);
  525. $out = str_replace(LD.'day_number'.RD, ($day <= 0) ? sprintf($day_num_fmt, $prev_total_days + $day) : sprintf($day_num_fmt, $day - $total_days), $out);
  526. }
  527. $day++;
  528. }
  529. $out .= $row_end;
  530. }
  531. // Garbage collection
  532. $out = str_replace(array($entries_m,
  533. $if_blank_m,
  534. $if_today_m,
  535. $if_entries_m,
  536. $if_not_entries_m),
  537. '',
  538. $out);
  539. return str_replace ($row_chunk_m, $out, $this->EE->TMPL->tagdata);
  540. }
  541. /** ----------------------------------------
  542. /** Replace Calendar Variables
  543. /** ----------------------------------------*/
  544. function var_replace($chunk, $data, $row = '')
  545. {
  546. if ($row != '')
  547. {
  548. $temp = '';
  549. foreach ($data as $val)
  550. {
  551. $str = $row;
  552. $str = str_replace(array(LD.'title'.RD,
  553. LD.'url_title'.RD,
  554. LD.'author'.RD,
  555. LD.'comment_auto_path'.RD,
  556. LD.'comment_url_title_auto_path'.RD,
  557. LD.'comment_entry_id_auto_path'.RD),
  558. array($val['0'],
  559. $val['1'],
  560. $val['5'],
  561. $val['10'],
  562. $val['11'],
  563. $val['12']),
  564. $str);
  565. // Entry Date
  566. foreach ($val['2'] as $k => $v)
  567. {
  568. $str = str_replace(LD.$k.RD, $v, $str);
  569. }
  570. // Permalink
  571. foreach ($val['3'] as $k => $v)
  572. {
  573. $str = str_replace(LD.$k.RD, $v, $str);
  574. }
  575. // Title permalink
  576. foreach ($val['4'] as $k => $v)
  577. {
  578. $str = str_replace(LD.$k.RD, $v, $str);
  579. }
  580. // Profile path
  581. foreach ($val['6'] as $k => $v)
  582. {
  583. $str = str_replace(LD.$k.RD, $v, $str);
  584. }
  585. // ID path
  586. foreach ($val['7'] as $k => $v)
  587. {
  588. $str = str_replace(LD.$k.RD, $v, $str);
  589. }
  590. // Base Fields
  591. foreach ($val['8'] as $k => $v)
  592. {
  593. $str = str_replace(LD.$k.RD, $v, $str);
  594. }
  595. // Day path
  596. foreach ($val['9'] as $k => $v)
  597. {
  598. $str = str_replace(LD.$k.RD, $v, $str);
  599. }
  600. $temp .= $str;
  601. }
  602. $chunk = str_replace('Gm983TGxkedSPoe0912NNk', $temp, $chunk);
  603. }
  604. return $chunk;
  605. }
  606. }
  607. // END CLASS
  608. /* End of file mod.channel_calendar.php */
  609. /* Location: ./system/expressionengine/modules/channel/mod.channel_calendar.php */