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