Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.0.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * CodeIgniter Calendar Class |
| 42 | * |
| 43 | * This class enables the creation of calendars |
| 44 | * |
| 45 | * @package CodeIgniter |
| 46 | * @subpackage Libraries |
| 47 | * @category Libraries |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 48 | * @author EllisLab Dev Team |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 49 | * @link https://codeigniter.com/user_guide/libraries/calendar.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | */ |
| 51 | class CI_Calendar { |
| 52 | |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 53 | /** |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 54 | * Calendar layout template |
| 55 | * |
Andrew | 021f8ed | 2014-02-09 16:31:22 -0600 | [diff] [blame] | 56 | * @var mixed |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 57 | */ |
| 58 | public $template = ''; |
Andrey Andreev | 9bf3cf2 | 2014-02-18 16:39:46 +0200 | [diff] [blame] | 59 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 60 | /** |
| 61 | * Replacements array for template |
| 62 | * |
Andrew | e0333db | 2014-02-08 01:24:00 -0600 | [diff] [blame] | 63 | * @var array |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 64 | */ |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 65 | public $replacements = array(); |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 66 | |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 67 | /** |
| 68 | * Day of the week to start the calendar on |
| 69 | * |
| 70 | * @var string |
| 71 | */ |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 72 | public $start_day = 'sunday'; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 73 | |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 74 | /** |
| 75 | * How to display months |
| 76 | * |
| 77 | * @var string |
| 78 | */ |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 79 | public $month_type = 'long'; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 80 | |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 81 | /** |
| 82 | * How to display names of days |
| 83 | * |
| 84 | * @var string |
| 85 | */ |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 86 | public $day_type = 'abr'; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 87 | |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 88 | /** |
| 89 | * Whether to show next/prev month links |
| 90 | * |
| 91 | * @var bool |
| 92 | */ |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 93 | public $show_next_prev = FALSE; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 94 | |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 95 | /** |
| 96 | * Url base to use for next/prev month links |
| 97 | * |
| 98 | * @var bool |
| 99 | */ |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 100 | public $next_prev_url = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | |
| 102 | /** |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 103 | * Show days of other months |
| 104 | * |
| 105 | * @var bool |
| 106 | */ |
| 107 | public $show_other_days = FALSE; |
| 108 | |
Andrey Andreev | 6125a27 | 2014-02-21 16:58:13 +0200 | [diff] [blame] | 109 | // -------------------------------------------------------------------- |
| 110 | |
| 111 | /** |
| 112 | * CI Singleton |
| 113 | * |
| 114 | * @var object |
| 115 | */ |
| 116 | protected $CI; |
| 117 | |
| 118 | // -------------------------------------------------------------------- |
| 119 | |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 120 | /** |
Andrey Andreev | 3e9d2b8 | 2012-10-27 14:28:51 +0300 | [diff] [blame] | 121 | * Class constructor |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 122 | * |
Andrey Andreev | 3e9d2b8 | 2012-10-27 14:28:51 +0300 | [diff] [blame] | 123 | * Loads the calendar language file and sets the default time reference. |
Andrey Andreev | 6dbabb5 | 2012-03-26 15:41:48 +0300 | [diff] [blame] | 124 | * |
Andrey Andreev | 3e9d2b8 | 2012-10-27 14:28:51 +0300 | [diff] [blame] | 125 | * @uses CI_Lang::$is_loaded |
| 126 | * |
| 127 | * @param array $config Calendar options |
Andrey Andreev | 6dbabb5 | 2012-03-26 15:41:48 +0300 | [diff] [blame] | 128 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 130 | public function __construct($config = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 131 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | $this->CI =& get_instance(); |
Andrey Andreev | 0340489 | 2015-03-26 20:58:19 +0200 | [diff] [blame] | 133 | $this->CI->lang->load('calendar'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 134 | |
Andrey Andreev | 6125a27 | 2014-02-21 16:58:13 +0200 | [diff] [blame] | 135 | empty($config) OR $this->initialize($config); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 136 | |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 137 | log_message('info', 'Calendar Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 138 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 139 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 140 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 141 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 142 | /** |
| 143 | * Initialize the user preferences |
| 144 | * |
| 145 | * Accepts an associative array as input, containing display preferences |
| 146 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 147 | * @param array config preferences |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 148 | * @return CI_Calendar |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 149 | */ |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 150 | public function initialize($config = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 151 | { |
| 152 | foreach ($config as $key => $val) |
| 153 | { |
| 154 | if (isset($this->$key)) |
| 155 | { |
| 156 | $this->$key = $val; |
| 157 | } |
| 158 | } |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 159 | |
| 160 | // Set the next_prev_url to the controller if required but not defined |
Marcos SF Filho | c4f6616 | 2014-01-08 18:57:09 -0200 | [diff] [blame] | 161 | if ($this->show_next_prev === TRUE && empty($this->next_prev_url)) |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 162 | { |
Marcos SF Filho | 0cd7c92 | 2014-01-08 19:38:00 -0200 | [diff] [blame] | 163 | $this->next_prev_url = $this->CI->config->site_url($this->CI->router->class.'/'.$this->CI->router->method); |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 164 | } |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 165 | |
| 166 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 167 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 168 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 169 | // -------------------------------------------------------------------- |
| 170 | |
| 171 | /** |
| 172 | * Generate the calendar |
| 173 | * |
Andrey Andreev | 6dbabb5 | 2012-03-26 15:41:48 +0300 | [diff] [blame] | 174 | * @param int the year |
| 175 | * @param int the month |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 176 | * @param array the data to be shown in the calendar cells |
| 177 | * @return string |
| 178 | */ |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 179 | public function generate($year = '', $month = '', $data = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 180 | { |
Andrey Andreev | 6125a27 | 2014-02-21 16:58:13 +0200 | [diff] [blame] | 181 | $local_time = time(); |
| 182 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | // Set and validate the supplied month/year |
Andrey Andreev | f51b1fb | 2012-06-16 20:02:23 +0300 | [diff] [blame] | 184 | if (empty($year)) |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 185 | { |
Andrey Andreev | 6125a27 | 2014-02-21 16:58:13 +0200 | [diff] [blame] | 186 | $year = date('Y', $local_time); |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 187 | } |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 188 | elseif (strlen($year) === 1) |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 189 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 190 | $year = '200'.$year; |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 191 | } |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 192 | elseif (strlen($year) === 2) |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 193 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | $year = '20'.$year; |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 195 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | |
Andrey Andreev | f51b1fb | 2012-06-16 20:02:23 +0300 | [diff] [blame] | 197 | if (empty($month)) |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 198 | { |
Andrey Andreev | 6125a27 | 2014-02-21 16:58:13 +0200 | [diff] [blame] | 199 | $month = date('m', $local_time); |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 200 | } |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 201 | elseif (strlen($month) === 1) |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 202 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | $month = '0'.$month; |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 204 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 205 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 206 | $adjusted_date = $this->adjust_date($month, $year); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 207 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 208 | $month = $adjusted_date['month']; |
| 209 | $year = $adjusted_date['year']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 210 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 211 | // Determine the total days in the month |
| 212 | $total_days = $this->get_total_days($month, $year); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 213 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | // Set the starting day of the week |
| 215 | $start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6); |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 216 | $start_day = isset($start_days[$this->start_day]) ? $start_days[$this->start_day] : 0; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 217 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | // Set the starting day number |
| 219 | $local_date = mktime(12, 0, 0, $month, 1, $year); |
| 220 | $date = getdate($local_date); |
Andrey Andreev | 6dbabb5 | 2012-03-26 15:41:48 +0300 | [diff] [blame] | 221 | $day = $start_day + 1 - $date['wday']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 222 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 223 | while ($day > 1) |
| 224 | { |
| 225 | $day -= 7; |
| 226 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 227 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | // Set the current month/year/day |
| 229 | // We use this to determine the "today" date |
Andrey Andreev | 6125a27 | 2014-02-21 16:58:13 +0200 | [diff] [blame] | 230 | $cur_year = date('Y', $local_time); |
| 231 | $cur_month = date('m', $local_time); |
| 232 | $cur_day = date('j', $local_time); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 233 | |
Andrey Andreev | 5036c9c | 2012-06-04 15:34:56 +0300 | [diff] [blame] | 234 | $is_current_month = ($cur_year == $year && $cur_month == $month); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 235 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 236 | // Generate the template data array |
| 237 | $this->parse_template(); |
| 238 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 239 | // Begin building the calendar output |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 240 | $out = $this->replacements['table_open']."\n\n".$this->replacements['heading_row_start']."\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 241 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 242 | // "previous" month link |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 243 | if ($this->show_next_prev === TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | { |
Andrey Andreev | 838a9d6 | 2012-12-03 14:37:47 +0200 | [diff] [blame] | 245 | // Add a trailing slash to the URL if needed |
| 246 | $this->next_prev_url = preg_replace('/(.+?)\/*$/', '\\1/', $this->next_prev_url); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 247 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 248 | $adjusted_date = $this->adjust_date($month - 1, $year); |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 249 | $out .= str_replace('{previous_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->replacements['heading_previous_cell'])."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // Heading containing the month/year |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 253 | $colspan = ($this->show_next_prev === TRUE) ? 5 : 7; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 254 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 255 | $this->replacements['heading_title_cell'] = str_replace('{colspan}', $colspan, |
| 256 | str_replace('{heading}', $this->get_month_name($month).' '.$year, $this->replacements['heading_title_cell'])); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 257 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 258 | $out .= $this->replacements['heading_title_cell']."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 259 | |
| 260 | // "next" month link |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 261 | if ($this->show_next_prev === TRUE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 262 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 263 | $adjusted_date = $this->adjust_date($month + 1, $year); |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 264 | $out .= str_replace('{next_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->replacements['heading_next_cell']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 267 | $out .= "\n".$this->replacements['heading_row_end']."\n\n" |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 268 | // Write the cells containing the days of the week |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 269 | .$this->replacements['week_row_start']."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | |
| 271 | $day_names = $this->get_day_names(); |
| 272 | |
| 273 | for ($i = 0; $i < 7; $i ++) |
| 274 | { |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 275 | $out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->replacements['week_day_cell']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 278 | $out .= "\n".$this->replacements['week_row_end']."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | |
| 280 | // Build the main body of the calendar |
| 281 | while ($day <= $total_days) |
| 282 | { |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 283 | $out .= "\n".$this->replacements['cal_row_start']."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | |
| 285 | for ($i = 0; $i < 7; $i++) |
| 286 | { |
Andrey Andreev | 6dbabb5 | 2012-03-26 15:41:48 +0300 | [diff] [blame] | 287 | if ($day > 0 && $day <= $total_days) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 288 | { |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 289 | $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->replacements['cal_cell_start_today'] : $this->replacements['cal_cell_start']; |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 290 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 291 | if (isset($data[$day])) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 292 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 293 | // Cells with content |
Andrey Andreev | 5036c9c | 2012-06-04 15:34:56 +0300 | [diff] [blame] | 294 | $temp = ($is_current_month === TRUE && $day == $cur_day) ? |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 295 | $this->replacements['cal_cell_content_today'] : $this->replacements['cal_cell_content']; |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 296 | $out .= str_replace(array('{content}', '{day}'), array($data[$day], $day), $temp); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 297 | } |
| 298 | else |
| 299 | { |
| 300 | // Cells with no content |
Andrey Andreev | 5036c9c | 2012-06-04 15:34:56 +0300 | [diff] [blame] | 301 | $temp = ($is_current_month === TRUE && $day == $cur_day) ? |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 302 | $this->replacements['cal_cell_no_content_today'] : $this->replacements['cal_cell_no_content']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 303 | $out .= str_replace('{day}', $day, $temp); |
| 304 | } |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 305 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 306 | $out .= ($is_current_month === TRUE && $day == $cur_day) ? $this->replacements['cal_cell_end_today'] : $this->replacements['cal_cell_end']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | } |
Marcos SF Filho | a593e3e | 2014-01-08 18:22:12 -0200 | [diff] [blame] | 308 | elseif ($this->show_other_days === TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | { |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 310 | $out .= $this->replacements['cal_cell_start_other']; |
Marcos SF Filho | a593e3e | 2014-01-08 18:22:12 -0200 | [diff] [blame] | 311 | |
| 312 | if ($day <= 0) |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 313 | { |
Marcos SF Filho | a593e3e | 2014-01-08 18:22:12 -0200 | [diff] [blame] | 314 | // Day of previous month |
Marcos SF Filho | 2e914b7 | 2014-01-09 09:20:55 -0200 | [diff] [blame] | 315 | $prev_month = $this->adjust_date($month - 1, $year); |
Marcos SF Filho | a593e3e | 2014-01-08 18:22:12 -0200 | [diff] [blame] | 316 | $prev_month_days = $this->get_total_days($prev_month['month'], $prev_month['year']); |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 317 | $out .= str_replace('{day}', $prev_month_days + $day, $this->replacements['cal_cell_other']); |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 318 | } |
| 319 | else |
| 320 | { |
Marcos SF Filho | a593e3e | 2014-01-08 18:22:12 -0200 | [diff] [blame] | 321 | // Day of next month |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 322 | $out .= str_replace('{day}', $day - $total_days, $this->replacements['cal_cell_other']); |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 323 | } |
Marcos SF Filho | a593e3e | 2014-01-08 18:22:12 -0200 | [diff] [blame] | 324 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 325 | $out .= $this->replacements['cal_cell_end_other']; |
Marcos SF Filho | a593e3e | 2014-01-08 18:22:12 -0200 | [diff] [blame] | 326 | } |
| 327 | else |
| 328 | { |
| 329 | // Blank cells |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 330 | $out .= $this->replacements['cal_cell_start'].$this->replacements['cal_cell_blank'].$this->replacements['cal_cell_end']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 331 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 332 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | $day++; |
| 334 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 335 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 336 | $out .= "\n".$this->replacements['cal_row_end']."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 339 | return $out .= "\n".$this->replacements['table_close']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 340 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 341 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 342 | // -------------------------------------------------------------------- |
| 343 | |
| 344 | /** |
| 345 | * Get Month Name |
| 346 | * |
| 347 | * Generates a textual month name based on the numeric |
| 348 | * month provided. |
| 349 | * |
Andrey Andreev | 6dbabb5 | 2012-03-26 15:41:48 +0300 | [diff] [blame] | 350 | * @param int the month |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 351 | * @return string |
| 352 | */ |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 353 | public function get_month_name($month) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 354 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 355 | if ($this->month_type === 'short') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 356 | { |
| 357 | $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'); |
| 358 | } |
| 359 | else |
| 360 | { |
Derek Allard | defaa17 | 2009-08-17 17:24:31 +0000 | [diff] [blame] | 361 | $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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 363 | |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 364 | return ($this->CI->lang->line($month_names[$month]) === FALSE) |
| 365 | ? ucfirst(substr($month_names[$month], 4)) |
| 366 | : $this->CI->lang->line($month_names[$month]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 368 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 369 | // -------------------------------------------------------------------- |
| 370 | |
| 371 | /** |
| 372 | * Get Day Names |
| 373 | * |
| 374 | * Returns an array of day names (Sunday, Monday, etc.) based |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 375 | * on the type. Options: long, short, abr |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 376 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | * @param string |
| 378 | * @return array |
| 379 | */ |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 380 | public function get_day_names($day_type = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 381 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 382 | if ($day_type !== '') |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 383 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 384 | $this->day_type = $day_type; |
Andrey Andreev | c7dc07e | 2011-12-24 16:48:50 +0200 | [diff] [blame] | 385 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 386 | |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 387 | if ($this->day_type === 'long') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 388 | { |
| 389 | $day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'); |
| 390 | } |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 391 | elseif ($this->day_type === 'short') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 392 | { |
| 393 | $day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'); |
| 394 | } |
| 395 | else |
| 396 | { |
| 397 | $day_names = array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'); |
| 398 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 399 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 400 | $days = array(); |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 401 | for ($i = 0, $c = count($day_names); $i < $c; $i++) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 402 | { |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 403 | $days[] = ($this->CI->lang->line('cal_'.$day_names[$i]) === FALSE) ? ucfirst($day_names[$i]) : $this->CI->lang->line('cal_'.$day_names[$i]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 404 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 405 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | return $days; |
| 407 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 408 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 409 | // -------------------------------------------------------------------- |
| 410 | |
| 411 | /** |
| 412 | * Adjust Date |
| 413 | * |
| 414 | * This function makes sure that we have a valid month/year. |
| 415 | * For example, if you submit 13 as the month, the year will |
| 416 | * increment and the month will become January. |
| 417 | * |
Andrey Andreev | 6dbabb5 | 2012-03-26 15:41:48 +0300 | [diff] [blame] | 418 | * @param int the month |
| 419 | * @param int the year |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 420 | * @return array |
| 421 | */ |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 422 | public function adjust_date($month, $year) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 423 | { |
| 424 | $date = array(); |
| 425 | |
| 426 | $date['month'] = $month; |
| 427 | $date['year'] = $year; |
| 428 | |
| 429 | while ($date['month'] > 12) |
| 430 | { |
| 431 | $date['month'] -= 12; |
| 432 | $date['year']++; |
| 433 | } |
| 434 | |
| 435 | while ($date['month'] <= 0) |
| 436 | { |
| 437 | $date['month'] += 12; |
| 438 | $date['year']--; |
| 439 | } |
| 440 | |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 441 | if (strlen($date['month']) === 1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | { |
| 443 | $date['month'] = '0'.$date['month']; |
| 444 | } |
| 445 | |
| 446 | return $date; |
| 447 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 448 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 449 | // -------------------------------------------------------------------- |
| 450 | |
| 451 | /** |
| 452 | * Total days in a given month |
| 453 | * |
Andrey Andreev | 6dbabb5 | 2012-03-26 15:41:48 +0300 | [diff] [blame] | 454 | * @param int the month |
| 455 | * @param int the year |
| 456 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 457 | */ |
Andrey Andreev | e8dfc1b | 2011-12-24 01:22:19 +0200 | [diff] [blame] | 458 | public function get_total_days($month, $year) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 459 | { |
Andrey Andreev | 083a226 | 2014-02-20 16:04:58 +0200 | [diff] [blame] | 460 | $this->CI->load->helper('date'); |
Andrey Andreev | be368a8 | 2014-02-20 15:46:05 +0200 | [diff] [blame] | 461 | return days_in_month($month, $year); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 462 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 463 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 464 | // -------------------------------------------------------------------- |
| 465 | |
| 466 | /** |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 467 | * Set Default Template Data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | * |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 469 | * This is used in the event that the user has not created their own template |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 470 | * |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 471 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 472 | */ |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 473 | public function default_template() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 474 | { |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 475 | return array( |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 476 | 'table_open' => '<table border="0" cellpadding="4" cellspacing="0">', |
| 477 | 'heading_row_start' => '<tr>', |
| 478 | 'heading_previous_cell' => '<th><a href="{previous_url}"><<</a></th>', |
| 479 | 'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>', |
| 480 | 'heading_next_cell' => '<th><a href="{next_url}">>></a></th>', |
| 481 | 'heading_row_end' => '</tr>', |
| 482 | 'week_row_start' => '<tr>', |
| 483 | 'week_day_cell' => '<td>{week_day}</td>', |
| 484 | 'week_row_end' => '</tr>', |
| 485 | 'cal_row_start' => '<tr>', |
| 486 | 'cal_cell_start' => '<td>', |
| 487 | 'cal_cell_start_today' => '<td>', |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 488 | 'cal_cell_start_other' => '<td style="color: #666;">', |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 489 | 'cal_cell_content' => '<a href="{content}">{day}</a>', |
| 490 | 'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>', |
| 491 | 'cal_cell_no_content' => '{day}', |
| 492 | 'cal_cell_no_content_today' => '<strong>{day}</strong>', |
| 493 | 'cal_cell_blank' => ' ', |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 494 | 'cal_cell_other' => '{day}', |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 495 | 'cal_cell_end' => '</td>', |
| 496 | 'cal_cell_end_today' => '</td>', |
Marcos SF Filho | 7977e1d | 2014-01-08 15:34:11 -0200 | [diff] [blame] | 497 | 'cal_cell_end_other' => '</td>', |
Timothy Warren | 68f0981 | 2012-04-27 10:38:32 -0400 | [diff] [blame] | 498 | 'cal_row_end' => '</tr>', |
| 499 | 'table_close' => '</table>' |
| 500 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 501 | } |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 502 | |
| 503 | // -------------------------------------------------------------------- |
| 504 | |
| 505 | /** |
| 506 | * Parse Template |
| 507 | * |
| 508 | * Harvests the data within the template {pseudo-variables} |
| 509 | * used to display the calendar |
| 510 | * |
| 511 | * @return CI_Calendar |
| 512 | */ |
| 513 | public function parse_template() |
| 514 | { |
| 515 | $this->replacements = $this->default_template(); |
| 516 | |
Andrew | 021f8ed | 2014-02-09 16:31:22 -0600 | [diff] [blame] | 517 | if (empty($this->template)) |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 518 | { |
| 519 | return $this; |
| 520 | } |
Andrey Andreev | 9bf3cf2 | 2014-02-18 16:39:46 +0200 | [diff] [blame] | 521 | |
Andrew | 021f8ed | 2014-02-09 16:31:22 -0600 | [diff] [blame] | 522 | if (is_string($this->template)) |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 523 | { |
| 524 | $today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today'); |
Andrey Andreev | 9bf3cf2 | 2014-02-18 16:39:46 +0200 | [diff] [blame] | 525 | |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 526 | 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', 'cal_cell_start_other', 'cal_cell_other', 'cal_cell_end_other') as $val) |
| 527 | { |
| 528 | if (preg_match('/\{'.$val.'\}(.*?)\{\/'.$val.'\}/si', $this->template, $match)) |
| 529 | { |
| 530 | $this->replacements[$val] = $match[1]; |
| 531 | } |
| 532 | elseif (in_array($val, $today, TRUE)) |
| 533 | { |
| 534 | $this->replacements[$val] = $this->replacements[substr($val, 0, -6)]; |
| 535 | } |
| 536 | } |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 537 | } |
Andrew | 021f8ed | 2014-02-09 16:31:22 -0600 | [diff] [blame] | 538 | elseif (is_array($this->template)) |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 539 | { |
| 540 | $this->replacements = array_merge($this->replacements, $this->template); |
| 541 | } |
Andrey Andreev | 9bf3cf2 | 2014-02-18 16:39:46 +0200 | [diff] [blame] | 542 | |
Andrew | 021f8ed | 2014-02-09 16:31:22 -0600 | [diff] [blame] | 543 | return $this; |
Andrew | 227a5d7 | 2014-02-09 15:32:44 -0600 | [diff] [blame] | 544 | } |
| 545 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 546 | } |