1
- <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
1
+ <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
2
2
/**
3
3
* CodeIgniter
4
4
*
5
5
* An open source application development framework for PHP 5.1.6 or newer
6
6
*
7
7
* NOTICE OF LICENSE
8
- *
8
+ *
9
9
* Licensed under the Open Software License version 3.0
10
- *
10
+ *
11
11
* This source file is subject to the Open Software License (OSL 3.0) that is
12
12
* bundled with this package in the files license.txt / license.rst. It is
13
13
* also available through the world wide web at this URL:
40
40
*/
41
41
class CI_Calendar {
42
42
43
- var $ CI ;
44
- var $ lang ;
45
- var $ local_time ;
46
- var $ template = '' ;
47
- var $ start_day = 'sunday ' ;
48
- var $ month_type = 'long ' ;
49
- var $ day_type = 'abr ' ;
50
- var $ show_next_prev = FALSE ;
51
- var $ next_prev_url = '' ;
43
+ private $ CI ;
44
+ public $ lang ;
45
+ public $ local_time ;
46
+ public $ template = '' ;
47
+ public $ start_day = 'sunday ' ;
48
+ public $ month_type = 'long ' ;
49
+ public $ day_type = 'abr ' ;
50
+ public $ show_next_prev = FALSE ;
51
+ public $ next_prev_url = '' ;
52
52
53
53
/**
54
54
* Constructor
@@ -85,7 +85,7 @@ public function __construct($config = array())
85
85
* @param array config preferences
86
86
* @return void
87
87
*/
88
- function initialize ($ config = array ())
88
+ public function initialize ($ config = array ())
89
89
{
90
90
foreach ($ config as $ key => $ val )
91
91
{
@@ -107,22 +107,19 @@ function initialize($config = array())
107
107
* @param array the data to be shown in the calendar cells
108
108
* @return string
109
109
*/
110
- function generate ($ year = '' , $ month = '' , $ data = array ())
110
+ public function generate ($ year = '' , $ month = '' , $ data = array ())
111
111
{
112
112
// Set and validate the supplied month/year
113
113
if ($ year == '' )
114
- $ year = date ("Y " , $ this ->local_time );
115
-
116
- if ($ month == '' )
117
- $ month = date ("m " , $ this ->local_time );
118
-
119
- if (strlen ($ year ) == 1 )
114
+ $ year = date ('Y ' , $ this ->local_time );
115
+ elseif (strlen ($ year ) === 1 )
120
116
$ year = '200 ' .$ year ;
121
-
122
- if (strlen ($ year ) == 2 )
117
+ elseif (strlen ($ year ) === 2 )
123
118
$ year = '20 ' .$ year ;
124
119
125
- if (strlen ($ month ) == 1 )
120
+ if ($ month == '' )
121
+ $ month = date ('m ' , $ this ->local_time );
122
+ elseif (strlen ($ month ) === 1 )
126
123
$ month = '0 ' .$ month ;
127
124
128
125
$ adjusted_date = $ this ->adjust_date ($ month , $ year );
@@ -149,22 +146,17 @@ function generate($year = '', $month = '', $data = array())
149
146
150
147
// Set the current month/year/day
151
148
// We use this to determine the "today" date
152
- $ cur_year = date (" Y " , $ this ->local_time );
153
- $ cur_month = date (" m " , $ this ->local_time );
154
- $ cur_day = date (" j " , $ this ->local_time );
149
+ $ cur_year = date (' Y ' , $ this ->local_time );
150
+ $ cur_month = date (' m ' , $ this ->local_time );
151
+ $ cur_day = date (' j ' , $ this ->local_time );
155
152
156
153
$ is_current_month = ($ cur_year == $ year AND $ cur_month == $ month ) ? TRUE : FALSE ;
157
154
158
155
// Generate the template data array
159
156
$ this ->parse_template ();
160
157
161
158
// Begin building the calendar output
162
- $ out = $ this ->temp ['table_open ' ];
163
- $ out .= "\n" ;
164
-
165
- $ out .= "\n" ;
166
- $ out .= $ this ->temp ['heading_row_start ' ];
167
- $ out .= "\n" ;
159
+ $ out = $ this ->temp ['table_open ' ] . "\n\n" . $ this ->temp ['heading_row_start ' ] . "\n" ;
168
160
169
161
// "previous" month link
170
162
if ($ this ->show_next_prev == TRUE )
@@ -173,18 +165,16 @@ function generate($year = '', $month = '', $data = array())
173
165
$ this ->next_prev_url = preg_replace ("/(.+?)\/*$/ " , "\\1/ " , $ this ->next_prev_url );
174
166
175
167
$ adjusted_date = $ this ->adjust_date ($ month - 1 , $ year );
176
- $ out .= str_replace ('{previous_url} ' , $ this ->next_prev_url .$ adjusted_date ['year ' ].'/ ' .$ adjusted_date ['month ' ], $ this ->temp ['heading_previous_cell ' ]);
177
- $ out .= "\n" ;
168
+ $ out .= str_replace ('{previous_url} ' , $ this ->next_prev_url .$ adjusted_date ['year ' ].'/ ' .$ adjusted_date ['month ' ], $ this ->temp ['heading_previous_cell ' ])."\n" ;
178
169
}
179
170
180
171
// Heading containing the month/year
181
172
$ colspan = ($ this ->show_next_prev == TRUE ) ? 5 : 7 ;
182
173
183
- $ this ->temp ['heading_title_cell ' ] = str_replace ('{colspan} ' , $ colspan , $ this -> temp [ ' heading_title_cell ' ]);
184
- $ this -> temp [ ' heading_title_cell ' ] = str_replace ('{heading} ' , $ this ->get_month_name ($ month )." " .$ year , $ this ->temp ['heading_title_cell ' ]);
174
+ $ this ->temp ['heading_title_cell ' ] = str_replace ('{colspan} ' , $ colspan ,
175
+ str_replace ('{heading} ' , $ this ->get_month_name ($ month ).' ' .$ year , $ this ->temp ['heading_title_cell ' ]) );
185
176
186
- $ out .= $ this ->temp ['heading_title_cell ' ];
187
- $ out .= "\n" ;
177
+ $ out .= $ this ->temp ['heading_title_cell ' ] . "\n" ;
188
178
189
179
// "next" month link
190
180
if ($ this ->show_next_prev == TRUE )
@@ -193,14 +183,9 @@ function generate($year = '', $month = '', $data = array())
193
183
$ out .= str_replace ('{next_url} ' , $ this ->next_prev_url .$ adjusted_date ['year ' ].'/ ' .$ adjusted_date ['month ' ], $ this ->temp ['heading_next_cell ' ]);
194
184
}
195
185
196
- $ out .= "\n" ;
197
- $ out .= $ this ->temp ['heading_row_end ' ];
198
- $ out .= "\n" ;
199
-
200
- // Write the cells containing the days of the week
201
- $ out .= "\n" ;
202
- $ out .= $ this ->temp ['week_row_start ' ];
203
- $ out .= "\n" ;
186
+ $ out .= "\n" . $ this ->temp ['heading_row_end ' ] . "\n\n"
187
+ // Write the cells containing the days of the week
188
+ . $ this ->temp ['week_row_start ' ] . "\n" ;
204
189
205
190
$ day_names = $ this ->get_day_names ();
206
191
@@ -209,33 +194,29 @@ function generate($year = '', $month = '', $data = array())
209
194
$ out .= str_replace ('{week_day} ' , $ day_names [($ start_day + $ i ) %7 ], $ this ->temp ['week_day_cell ' ]);
210
195
}
211
196
212
- $ out .= "\n" ;
213
- $ out .= $ this ->temp ['week_row_end ' ];
214
- $ out .= "\n" ;
197
+ $ out .= "\n" . $ this ->temp ['week_row_end ' ] . "\n" ;
215
198
216
199
// Build the main body of the calendar
217
200
while ($ day <= $ total_days )
218
201
{
219
- $ out .= "\n" ;
220
- $ out .= $ this ->temp ['cal_row_start ' ];
221
- $ out .= "\n" ;
202
+ $ out .= "\n" . $ this ->temp ['cal_row_start ' ] . "\n" ;
222
203
223
204
for ($ i = 0 ; $ i < 7 ; $ i ++)
224
205
{
225
- $ out .= ($ is_current_month == TRUE AND $ day == $ cur_day ) ? $ this ->temp ['cal_cell_start_today ' ] : $ this ->temp ['cal_cell_start ' ];
206
+ $ out .= ($ is_current_month === TRUE AND $ day == $ cur_day ) ? $ this ->temp ['cal_cell_start_today ' ] : $ this ->temp ['cal_cell_start ' ];
226
207
227
208
if ($ day > 0 AND $ day <= $ total_days )
228
209
{
229
210
if (isset ($ data [$ day ]))
230
211
{
231
212
// Cells with content
232
- $ temp = ($ is_current_month == TRUE AND $ day == $ cur_day ) ? $ this ->temp ['cal_cell_content_today ' ] : $ this ->temp ['cal_cell_content ' ];
233
- $ out .= str_replace (' {day } ' , $ day , str_replace ( ' {content} ' , $ data [$ day ], $ temp ) );
213
+ $ temp = ($ is_current_month === TRUE AND $ day == $ cur_day ) ? $ this ->temp ['cal_cell_content_today ' ] : $ this ->temp ['cal_cell_content ' ];
214
+ $ out .= str_replace (array ( ' {content } ' , ' {day} ' ), array ( $ data [$ day ], $ day ), $ temp );
234
215
}
235
216
else
236
217
{
237
218
// Cells with no content
238
- $ temp = ($ is_current_month == TRUE AND $ day == $ cur_day ) ? $ this ->temp ['cal_cell_no_content_today ' ] : $ this ->temp ['cal_cell_no_content ' ];
219
+ $ temp = ($ is_current_month === TRUE AND $ day == $ cur_day ) ? $ this ->temp ['cal_cell_no_content_today ' ] : $ this ->temp ['cal_cell_no_content ' ];
239
220
$ out .= str_replace ('{day} ' , $ day , $ temp );
240
221
}
241
222
}
@@ -245,17 +226,14 @@ function generate($year = '', $month = '', $data = array())
245
226
$ out .= $ this ->temp ['cal_cell_blank ' ];
246
227
}
247
228
248
- $ out .= ($ is_current_month == TRUE AND $ day == $ cur_day ) ? $ this ->temp ['cal_cell_end_today ' ] : $ this ->temp ['cal_cell_end ' ];
229
+ $ out .= ($ is_current_month === TRUE AND $ day == $ cur_day ) ? $ this ->temp ['cal_cell_end_today ' ] : $ this ->temp ['cal_cell_end ' ];
249
230
$ day ++;
250
231
}
251
232
252
- $ out .= "\n" ;
253
- $ out .= $ this ->temp ['cal_row_end ' ];
254
- $ out .= "\n" ;
233
+ $ out .= "\n" . $ this ->temp ['cal_row_end ' ] . "\n" ;
255
234
}
256
235
257
- $ out .= "\n" ;
258
- $ out .= $ this ->temp ['table_close ' ];
236
+ $ out .= "\n" . $ this ->temp ['table_close ' ];
259
237
260
238
return $ out ;
261
239
}
@@ -272,7 +250,7 @@ function generate($year = '', $month = '', $data = array())
272
250
* @param integer the month
273
251
* @return string
274
252
*/
275
- function get_month_name ($ month )
253
+ public function get_month_name ($ month )
276
254
{
277
255
if ($ this ->month_type == 'short ' )
278
256
{
@@ -287,7 +265,7 @@ function get_month_name($month)
287
265
288
266
if ($ this ->CI ->lang ->line ($ month ) === FALSE )
289
267
{
290
- return ucfirst (str_replace ( ' cal_ ' , '' , $ month ));
268
+ return ucfirst (substr ( $ month, 4 ));
291
269
}
292
270
293
271
return $ this ->CI ->lang ->line ($ month );
@@ -305,7 +283,7 @@ function get_month_name($month)
305
283
* @param string
306
284
* @return array
307
285
*/
308
- function get_day_names ($ day_type = '' )
286
+ public function get_day_names ($ day_type = '' )
309
287
{
310
288
if ($ day_type != '' )
311
289
$ this ->day_type = $ day_type ;
@@ -324,9 +302,9 @@ function get_day_names($day_type = '')
324
302
}
325
303
326
304
$ days = array ();
327
- foreach ($ day_names as $ val )
305
+ for ($ i = 0 , $ c = count ( $ day_names); $ i < $ c ; $ i ++ )
328
306
{
329
- $ days [] = ($ this ->CI ->lang ->line ('cal_ ' .$ val ) === FALSE ) ? ucfirst ($ val ) : $ this ->CI ->lang ->line ('cal_ ' .$ val );
307
+ $ days [] = ($ this ->CI ->lang ->line ('cal_ ' .$ day_names [ $ i ] ) === FALSE ) ? ucfirst ($ day_names [ $ i ] ) : $ this ->CI ->lang ->line ('cal_ ' .$ day_names [ $ i ] );
330
308
}
331
309
332
310
return $ days ;
@@ -346,7 +324,7 @@ function get_day_names($day_type = '')
346
324
* @param integer the year
347
325
* @return array
348
326
*/
349
- function adjust_date ($ month , $ year )
327
+ public function adjust_date ($ month , $ year )
350
328
{
351
329
$ date = array ();
352
330
@@ -365,7 +343,7 @@ function adjust_date($month, $year)
365
343
$ date ['year ' ]--;
366
344
}
367
345
368
- if (strlen ($ date ['month ' ]) == 1 )
346
+ if (strlen ($ date ['month ' ]) === 1 )
369
347
{
370
348
$ date ['month ' ] = '0 ' .$ date ['month ' ];
371
349
}
@@ -383,7 +361,7 @@ function adjust_date($month, $year)
383
361
* @param integer the year
384
362
* @return integer
385
363
*/
386
- function get_total_days ($ month , $ year )
364
+ public function get_total_days ($ month , $ year )
387
365
{
388
366
$ days_in_month = array (31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 );
389
367
@@ -414,7 +392,7 @@ function get_total_days($month, $year)
414
392
* @access public
415
393
* @return array
416
394
*/
417
- function default_template ()
395
+ public function default_template ()
418
396
{
419
397
return array (
420
398
'table_open ' => '<table border="0" cellpadding="4" cellspacing="0"> ' ,
@@ -452,7 +430,7 @@ function default_template()
452
430
* @access public
453
431
* @return void
454
432
*/
455
- function parse_template ()
433
+ public function parse_template ()
456
434
{
457
435
$ this ->temp = $ this ->default_template ();
458
436
@@ -467,14 +445,11 @@ function parse_template()
467
445
{
468
446
if (preg_match ("/\{ " .$ val ."\}(.*?)\{\/ " .$ val ."\}/si " , $ this ->template , $ match ))
469
447
{
470
- $ this ->temp [$ val ] = $ match [' 1 ' ];
448
+ $ this ->temp [$ val ] = $ match [1 ];
471
449
}
472
- else
450
+ elseif ( in_array ( $ val , $ today , TRUE ))
473
451
{
474
- if (in_array ($ val , $ today , TRUE ))
475
- {
476
- $ this ->temp [$ val ] = $ this ->temp [str_replace ('_today ' , '' , $ val )];
477
- }
452
+ $ this ->temp [$ val ] = $ this ->temp [substr ($ val , 0 , -6 )];
478
453
}
479
454
}
480
455
}
@@ -484,4 +459,4 @@ function parse_template()
484
459
// END CI_Calendar class
485
460
486
461
/* End of file Calendar.php */
487
- /* Location: ./system/libraries/Calendar.php */
462
+ /* Location: ./system/libraries/Calendar.php */
0 commit comments