blob: b6f145d953bdf56a73773b01bdb53b9dddaa3af6 [file] [log] [blame]
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * CodeIgniter Calendar Class
30 *
31 * This class enables the creation of calendars
32 *
33 * @package CodeIgniter
34 * @subpackage Libraries
35 * @category Libraries
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/libraries/calendar.html
38 */
39class CI_Calendar {
40
Andrey Andreev6dbabb52012-03-26 15:41:48 +030041 protected $CI;
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +020042 public $lang;
43 public $local_time;
44 public $template = '';
45 public $start_day = 'sunday';
46 public $month_type = 'long';
47 public $day_type = 'abr';
48 public $show_next_prev = FALSE;
49 public $next_prev_url = '';
Derek Allard2067d1a2008-11-13 22:59:24 +000050
51 /**
52 * Constructor
53 *
54 * Loads the calendar language file and sets the default time reference
Andrey Andreev6dbabb52012-03-26 15:41:48 +030055 *
56 * @param array
57 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +000058 */
Greg Akera9263282010-11-10 15:26:43 -060059 public function __construct($config = array())
Barry Mienydd671972010-10-04 16:33:58 +020060 {
Derek Allard2067d1a2008-11-13 22:59:24 +000061 $this->CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +020062
Greg Aker3a746652011-04-19 10:59:47 -050063 if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE))
Derek Allard2067d1a2008-11-13 22:59:24 +000064 {
65 $this->CI->lang->load('calendar');
66 }
67
68 $this->local_time = time();
Barry Mienydd671972010-10-04 16:33:58 +020069
Derek Allard2067d1a2008-11-13 22:59:24 +000070 if (count($config) > 0)
71 {
72 $this->initialize($config);
73 }
Barry Mienydd671972010-10-04 16:33:58 +020074
Andrey Andreev6dbabb52012-03-26 15:41:48 +030075 log_message('debug', 'Calendar Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000076 }
Barry Mienydd671972010-10-04 16:33:58 +020077
Derek Allard2067d1a2008-11-13 22:59:24 +000078 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020079
Derek Allard2067d1a2008-11-13 22:59:24 +000080 /**
81 * Initialize the user preferences
82 *
83 * Accepts an associative array as input, containing display preferences
84 *
Derek Allard2067d1a2008-11-13 22:59:24 +000085 * @param array config preferences
86 * @return void
Barry Mienydd671972010-10-04 16:33:58 +020087 */
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +020088 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000089 {
90 foreach ($config as $key => $val)
91 {
92 if (isset($this->$key))
93 {
94 $this->$key = $val;
95 }
96 }
97 }
Barry Mienydd671972010-10-04 16:33:58 +020098
Derek Allard2067d1a2008-11-13 22:59:24 +000099 // --------------------------------------------------------------------
100
101 /**
102 * Generate the calendar
103 *
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300104 * @param int the year
105 * @param int the month
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 * @param array the data to be shown in the calendar cells
107 * @return string
108 */
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200109 public function generate($year = '', $month = '', $data = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 {
111 // Set and validate the supplied month/year
112 if ($year == '')
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200113 {
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200114 $year = date('Y', $this->local_time);
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200115 }
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200116 elseif (strlen($year) === 1)
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200117 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 $year = '200'.$year;
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200119 }
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200120 elseif (strlen($year) === 2)
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200121 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 $year = '20'.$year;
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200123 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000124
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200125 if ($month == '')
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200126 {
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200127 $month = date('m', $this->local_time);
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200128 }
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200129 elseif (strlen($month) === 1)
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200130 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 $month = '0'.$month;
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200132 }
Barry Mienydd671972010-10-04 16:33:58 +0200133
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 $adjusted_date = $this->adjust_date($month, $year);
Barry Mienydd671972010-10-04 16:33:58 +0200135
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 $month = $adjusted_date['month'];
137 $year = $adjusted_date['year'];
Barry Mienydd671972010-10-04 16:33:58 +0200138
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 // Determine the total days in the month
140 $total_days = $this->get_total_days($month, $year);
Barry Mienydd671972010-10-04 16:33:58 +0200141
Derek Allard2067d1a2008-11-13 22:59:24 +0000142 // Set the starting day of the week
143 $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6);
144 $start_day = ( ! isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day];
Barry Mienydd671972010-10-04 16:33:58 +0200145
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 // Set the starting day number
147 $local_date = mktime(12, 0, 0, $month, 1, $year);
148 $date = getdate($local_date);
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300149 $day = $start_day + 1 - $date['wday'];
Barry Mienydd671972010-10-04 16:33:58 +0200150
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 while ($day > 1)
152 {
153 $day -= 7;
154 }
Barry Mienydd671972010-10-04 16:33:58 +0200155
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 // Set the current month/year/day
157 // We use this to determine the "today" date
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200158 $cur_year = date('Y', $this->local_time);
159 $cur_month = date('m', $this->local_time);
160 $cur_day = date('j', $this->local_time);
Barry Mienydd671972010-10-04 16:33:58 +0200161
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300162 $is_current_month = ($cur_year == $year && $cur_month == $month);
Barry Mienydd671972010-10-04 16:33:58 +0200163
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 // Generate the template data array
165 $this->parse_template();
Derek Allard2067d1a2008-11-13 22:59:24 +0000166
Barry Mienydd671972010-10-04 16:33:58 +0200167 // Begin building the calendar output
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200168 $out = $this->temp['table_open']."\n\n".$this->temp['heading_row_start']."\n";
Barry Mienydd671972010-10-04 16:33:58 +0200169
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 // "previous" month link
171 if ($this->show_next_prev == TRUE)
172 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500173 // Add a trailing slash to the URL if needed
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300174 $this->next_prev_url = preg_replace('/(.+?)\/*$/', '\\1/', $this->next_prev_url);
Barry Mienydd671972010-10-04 16:33:58 +0200175
Derek Allard2067d1a2008-11-13 22:59:24 +0000176 $adjusted_date = $this->adjust_date($month - 1, $year);
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200177 $out .= str_replace('{previous_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_previous_cell'])."\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 }
179
180 // Heading containing the month/year
181 $colspan = ($this->show_next_prev == TRUE) ? 5 : 7;
Barry Mienydd671972010-10-04 16:33:58 +0200182
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200183 $this->temp['heading_title_cell'] = str_replace('{colspan}', $colspan,
184 str_replace('{heading}', $this->get_month_name($month).'&nbsp;'.$year, $this->temp['heading_title_cell']));
Barry Mienydd671972010-10-04 16:33:58 +0200185
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200186 $out .= $this->temp['heading_title_cell']."\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000187
188 // "next" month link
189 if ($this->show_next_prev == TRUE)
Barry Mienydd671972010-10-04 16:33:58 +0200190 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 $adjusted_date = $this->adjust_date($month + 1, $year);
192 $out .= str_replace('{next_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_next_cell']);
193 }
194
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200195 $out .= "\n".$this->temp['heading_row_end']."\n\n"
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200196 // Write the cells containing the days of the week
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200197 .$this->temp['week_row_start']."\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000198
199 $day_names = $this->get_day_names();
200
201 for ($i = 0; $i < 7; $i ++)
202 {
203 $out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->temp['week_day_cell']);
204 }
205
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200206 $out .= "\n".$this->temp['week_row_end']."\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000207
208 // Build the main body of the calendar
209 while ($day <= $total_days)
210 {
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200211 $out .= "\n".$this->temp['cal_row_start']."\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000212
213 for ($i = 0; $i < 7; $i++)
214 {
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300215 $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start'];
Barry Mienydd671972010-10-04 16:33:58 +0200216
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300217 if ($day > 0 && $day <= $total_days)
Barry Mienydd671972010-10-04 16:33:58 +0200218 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 if (isset($data[$day]))
Barry Mienydd671972010-10-04 16:33:58 +0200220 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 // Cells with content
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300222 $temp = ($is_current_month === TRUE && $day == $cur_day) ?
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200223 $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200224 $out .= str_replace(array('{content}', '{day}'), array($data[$day], $day), $temp);
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 }
226 else
227 {
228 // Cells with no content
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300229 $temp = ($is_current_month === TRUE && $day == $cur_day) ?
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200230 $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000231 $out .= str_replace('{day}', $day, $temp);
232 }
233 }
234 else
235 {
236 // Blank cells
237 $out .= $this->temp['cal_cell_blank'];
238 }
Barry Mienydd671972010-10-04 16:33:58 +0200239
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300240 $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 $day++;
242 }
Barry Mienydd671972010-10-04 16:33:58 +0200243
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200244 $out .= "\n".$this->temp['cal_row_end']."\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 }
246
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200247 $out .= "\n".$this->temp['table_close'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000248
249 return $out;
250 }
Barry Mienydd671972010-10-04 16:33:58 +0200251
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 // --------------------------------------------------------------------
253
254 /**
255 * Get Month Name
256 *
257 * Generates a textual month name based on the numeric
258 * month provided.
259 *
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300260 * @param int the month
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 * @return string
262 */
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200263 public function get_month_name($month)
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 {
265 if ($this->month_type == 'short')
266 {
267 $month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => 'cal_may', '06' => 'cal_jun', '07' => 'cal_jul', '08' => 'cal_aug', '09' => 'cal_sep', '10' => 'cal_oct', '11' => 'cal_nov', '12' => 'cal_dec');
268 }
269 else
270 {
Derek Allarddefaa172009-08-17 17:24:31 +0000271 $month_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_mayl', '06' => 'cal_june', '07' => 'cal_july', '08' => 'cal_august', '09' => 'cal_september', '10' => 'cal_october', '11' => 'cal_november', '12' => 'cal_december');
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 }
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 $month = $month_names[$month];
Barry Mienydd671972010-10-04 16:33:58 +0200275
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 if ($this->CI->lang->line($month) === FALSE)
277 {
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200278 return ucfirst(substr($month, 4));
Derek Allard2067d1a2008-11-13 22:59:24 +0000279 }
280
281 return $this->CI->lang->line($month);
282 }
Barry Mienydd671972010-10-04 16:33:58 +0200283
Derek Allard2067d1a2008-11-13 22:59:24 +0000284 // --------------------------------------------------------------------
285
286 /**
287 * Get Day Names
288 *
289 * Returns an array of day names (Sunday, Monday, etc.) based
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300290 * on the type. Options: long, short, abrev
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 * @param string
293 * @return array
294 */
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200295 public function get_day_names($day_type = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 {
297 if ($day_type != '')
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200298 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 $this->day_type = $day_type;
Andrey Andreevc7dc07e2011-12-24 16:48:50 +0200300 }
Barry Mienydd671972010-10-04 16:33:58 +0200301
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 if ($this->day_type == 'long')
303 {
304 $day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
305 }
306 elseif ($this->day_type == 'short')
307 {
308 $day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
309 }
310 else
311 {
312 $day_names = array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa');
313 }
Barry Mienydd671972010-10-04 16:33:58 +0200314
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 $days = array();
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200316 for ($i = 0, $c = count($day_names); $i < $c; $i++)
Barry Mienydd671972010-10-04 16:33:58 +0200317 {
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200318 $days[] = ($this->CI->lang->line('cal_'.$day_names[$i]) === FALSE) ? ucfirst($day_names[$i]) : $this->CI->lang->line('cal_'.$day_names[$i]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 }
Barry Mienydd671972010-10-04 16:33:58 +0200320
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 return $days;
322 }
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 // --------------------------------------------------------------------
325
326 /**
327 * Adjust Date
328 *
329 * This function makes sure that we have a valid month/year.
330 * For example, if you submit 13 as the month, the year will
331 * increment and the month will become January.
332 *
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300333 * @param int the month
334 * @param int the year
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 * @return array
336 */
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200337 public function adjust_date($month, $year)
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 {
339 $date = array();
340
341 $date['month'] = $month;
342 $date['year'] = $year;
343
344 while ($date['month'] > 12)
345 {
346 $date['month'] -= 12;
347 $date['year']++;
348 }
349
350 while ($date['month'] <= 0)
351 {
352 $date['month'] += 12;
353 $date['year']--;
354 }
355
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200356 if (strlen($date['month']) === 1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 {
358 $date['month'] = '0'.$date['month'];
359 }
360
361 return $date;
362 }
Barry Mienydd671972010-10-04 16:33:58 +0200363
Derek Allard2067d1a2008-11-13 22:59:24 +0000364 // --------------------------------------------------------------------
365
366 /**
367 * Total days in a given month
368 *
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300369 * @param int the month
370 * @param int the year
371 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 */
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200373 public function get_total_days($month, $year)
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 {
375 $days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
376
377 if ($month < 1 OR $month > 12)
378 {
379 return 0;
380 }
381
382 // Is the year a leap year?
383 if ($month == 2)
384 {
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300385 if ($year % 400 == 0 OR ($year % 4 == 0 && $year % 100 != 0))
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 {
387 return 29;
388 }
389 }
390
391 return $days_in_month[$month - 1];
392 }
Barry Mienydd671972010-10-04 16:33:58 +0200393
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 // --------------------------------------------------------------------
395
396 /**
397 * Set Default Template Data
398 *
399 * This is used in the event that the user has not created their own template
400 *
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300401 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 */
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200403 public function default_template()
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500405 return array (
Barry Mienydd671972010-10-04 16:33:58 +0200406 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
407 'heading_row_start' => '<tr>',
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 'heading_previous_cell' => '<th><a href="{previous_url}">&lt;&lt;</a></th>',
Barry Mienydd671972010-10-04 16:33:58 +0200409 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>',
410 'heading_next_cell' => '<th><a href="{next_url}">&gt;&gt;</a></th>',
411 'heading_row_end' => '</tr>',
412 'week_row_start' => '<tr>',
413 'week_day_cell' => '<td>{week_day}</td>',
414 'week_row_end' => '</tr>',
415 'cal_row_start' => '<tr>',
416 'cal_cell_start' => '<td>',
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 'cal_cell_start_today' => '<td>',
418 'cal_cell_content' => '<a href="{content}">{day}</a>',
419 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>',
420 'cal_cell_no_content' => '{day}',
421 'cal_cell_no_content_today' => '<strong>{day}</strong>',
422 'cal_cell_blank' => '&nbsp;',
423 'cal_cell_end' => '</td>',
424 'cal_cell_end_today' => '</td>',
425 'cal_row_end' => '</tr>',
426 'table_close' => '</table>'
Barry Mienydd671972010-10-04 16:33:58 +0200427 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000428 }
Barry Mienydd671972010-10-04 16:33:58 +0200429
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 // --------------------------------------------------------------------
431
432 /**
433 * Parse Template
434 *
435 * Harvests the data within the template {pseudo-variables}
436 * used to display the calendar
437 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000438 * @return void
439 */
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200440 public function parse_template()
Barry Mienydd671972010-10-04 16:33:58 +0200441 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 $this->temp = $this->default_template();
Barry Mienydd671972010-10-04 16:33:58 +0200443
444 if ($this->template == '')
445 {
446 return;
447 }
448
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today');
Barry Mienydd671972010-10-04 16:33:58 +0200450
Derek Jones37f4b9c2011-07-01 17:56:50 -0500451 foreach (array('table_open', 'table_close', 'heading_row_start', 'heading_previous_cell', 'heading_title_cell', 'heading_next_cell', 'heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start', 'cal_cell_content', 'cal_cell_no_content', 'cal_cell_blank', 'cal_cell_end', 'cal_row_end', 'cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today') as $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 {
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300453 if (preg_match('/\{'.$val.'\}(.*?)\{\/'.$val.'\}/si', $this->template, $match))
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 {
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200455 $this->temp[$val] = $match[1];
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 }
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200457 elseif (in_array($val, $today, TRUE))
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 {
Andrey Andreeve8dfc1b2011-12-24 01:22:19 +0200459 $this->temp[$val] = $this->temp[substr($val, 0, -6)];
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 }
Barry Mienydd671972010-10-04 16:33:58 +0200461 }
462 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000463
464}
465
Derek Allard2067d1a2008-11-13 22:59:24 +0000466/* End of file Calendar.php */
Andrey Andreev6dbabb52012-03-26 15:41:48 +0300467/* Location: ./system/libraries/Calendar.php */