[ Index ] |
PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * phpwcms Calendar frontend render class 5 */ 6 class phpwcmsCalendar { 7 8 var $mode = 'simple'; 9 var $dates = array(); 10 11 /** 12 * Initialize class 13 */ 14 function phpwcmsCalendar() { 15 16 // current 17 $this->current_date = getdate(); 18 19 // set today 00:00:00 as start date 20 $this->date_start = mktime(0, 0, 0, $this->current_date['mon'], $this->current_date['mday'], $this->current_date['year']); 21 22 // by default date_start + 1 year 23 $this->date_end = mktime(0, 0, 0, $this->current_date['mon'], $this->current_date['mday'], $this->current_date['year'] + 1) - 1; 24 25 $this->dbReset(); 26 } 27 28 /** 29 * Reset db base vars 30 */ 31 function dbReset() { 32 $this->where = ''; 33 $this->select = '*'; 34 $this->join_on = ''; 35 $this->group_by = ''; 36 $this->order_by = 'calendar_start ASC'; 37 $this->limit = 0; 38 } 39 40 function defaultTemplate() { 41 $this->template = ''; 42 $this->href = ''; 43 } 44 45 /** 46 * search string for calendar tag and parse 47 */ 48 function parse(& $string) { 49 50 if( preg_match_all('/\{CALENDAR:(.*?)\}/s', $string, $matches) ) { 51 52 if( isset($matches[1]) ) { 53 54 foreach($matches[1] as $key => $value) { 55 56 $this->parse_match($value); 57 $result = $this->render(); 58 59 // replace calendar by result 60 $string = str_replace($matches[0][$key], $result, $string); 61 62 } 63 64 $string = html_parser($string); 65 66 } 67 } 68 69 } 70 71 function render() { 72 73 $items = array(); 74 75 foreach($this->dates as $key => $date) { 76 77 $url = ''; 78 $target = ''; 79 $href = $this->href ? $this->href . '&show_date='.date('Y-m-d', $date['calendar_start_date']).'_'.$date['calendar_id'] : ''; 80 81 if(!empty($date['calendar_refid'])) { 82 83 $date['calendar_refid'] = get_redirect_link($date['calendar_refid'], ' ', ''); 84 $date['calendar_refid']['link'] = trim($date['calendar_refid']['link']); 85 $date['calendar_refid']['link'] = trim($date['calendar_refid']['link'], '#'); 86 87 $target = $date['calendar_refid']['target']; 88 89 if(is_intval($date['calendar_refid']['link'])) { 90 $url = rel_url(array(), array(), 'aid='.$date['calendar_refid']['link']); //'index.php?aid='.$date['calendar_refid']['link']; 91 92 } elseif(strpos($date['calendar_refid']['link'], '://') || strpos($date['calendar_refid']['link'], '?') || strpos($date['calendar_refid']['link'], '.')) { 93 $url = $date['calendar_refid']['link']; 94 95 } elseif(!empty($date['calendar_refid']['link'])) { 96 $url = rel_url(array(), array(), $date['calendar_refid']['link']); 97 98 } 99 } 100 101 $items[$key] = $this->template; 102 $items[$key] = render_cnt_template($items[$key], 'HREF', $href); 103 $items[$key] = render_cnt_template($items[$key], 'URL', $url); 104 $items[$key] = render_cnt_template($items[$key], 'TARGET', $target); 105 $items[$key] = render_cnt_template($items[$key], 'TITLE', html_specialchars($date['calendar_title'])); 106 $items[$key] = render_cnt_template($items[$key], 'TEXT', plaintext_htmlencode($date['calendar_teaser'])); 107 $items[$key] = render_cnt_template($items[$key], 'PLACE', html_specialchars($date['calendar_where'])); 108 $items[$key] = render_cnt_date($items[$key], $date['calendar_start_date'], $date['calendar_start_date'], $date['calendar_end_date']); 109 110 } 111 112 return implode(LF, $items); 113 114 } 115 116 /** 117 * Parse matched replacement tag 118 */ 119 function parse_match($match='') { 120 121 $default = array(); 122 $match = trim($match); 123 124 // set query defaults 125 $this->dbReset(); 126 $this->defaultTemplate(); 127 128 if($match !== '' && strpos($match, '=') !== FALSE ) { 129 130 // oh yes fix, in case LF was converted to <br /> by phpwcms 131 $match = str_replace('<br />', LF, $match); 132 133 // result is a normal array 134 $match = parse_ini_str($match, false); 135 136 $default['items'] = isset($match['items']) ? intval($match['items']) : 0; 137 $default['template'] = empty($match['template']) ? '' : trim($match['template']); 138 $default['lang'] = empty($match['lang']) ? '' : trim($match['lang']); 139 $default['tag'] = empty($match['tag']) ? '' : trim($match['tag']); 140 $default['tagmode'] = empty($match['tagmode']) ? 'OR' : ( trim($match['tagmode']) == 'AND' ? 'AND' : 'OR' ); 141 $default['href'] = empty($match['href']) ? '' : trim($match['href']); 142 143 } else { 144 145 // base format 146 // 2,main_page.tmpl,de en, href, tag1, tag2 tag2, tag3 : date_start, date_end 147 // [item count,[template[,language(en de - separated by space)[, href, tags, tag, tag, tag]]]] 148 $match = explode(',', $match, 5); 149 150 $default['items'] = intval($match[0]); 151 $default['lang'] = empty($match[1]) ? '' : $match[1]; 152 $default['template'] = empty($match[2]) ? '' : trim($match[2]) ; 153 $default['href'] = empty($match[3]) ? '' : trim($match[3]); 154 $default['tagmode'] = 'OR'; 155 156 if(empty($match[4])) { 157 $default['tag'] = ''; 158 } else { 159 // check for start/end date 160 $match[4] = explode(':', $match[4], 2); 161 if(isset($match[4][1])) { 162 $match[4][1] = explode(',', $match[4][1], 2); 163 if(!empty($match[4][1][0])) { 164 $match['date_start'] = $match[4][1][0]; 165 } else { 166 $match['date_start'] = 'TODAY'; 167 } 168 if(!empty($match[4][1][1])) { 169 $match['date_end'] = $match[4][1][1]; 170 } else { 171 $match['date_end'] = 364 * 24 * 60 * 60; // + 364 days 172 } 173 } 174 } 175 176 } 177 178 // set custom defined start/end date 179 if(!empty($match['date_start'])) { 180 $match['date_start'] = trim($match['date_start']); 181 if(strtoupper($match['date_start']) == 'TODAY') { 182 $this->date_start = mktime(0, 0, 0, $this->current_date['mon'], $this->current_date['mday'], $this->current_date['year']); 183 } else { 184 $match['date_start'] = strtotime($match['date_start']); 185 if($match['date_start']) { 186 $this->date_start = $match['date_start']; 187 } 188 } 189 } 190 if(!empty($match['date_end'])) { 191 $match['date_end'] = trim($match['date_end']); 192 if(is_intval($match['date_end'])) { 193 $this->date_end = $this->date_start + ($match['date_end'] * 24 * 60 * 60); 194 } elseif(strtoupper($match['date_end']) == 'TODAY') { 195 $this->date_end = mktime(23, 59, 59, $this->current_date['mon'], $this->current_date['mday'], $this->current_date['year']); 196 } else { 197 $match['date_end'] = strtotime($match['date_end']); 198 if($match['date_end']) { 199 $this->date_end = $match['date_end']; 200 } 201 } 202 } 203 if($this->date_end <= $this->date_start) { 204 $this->date_end = mktime(0, 0, 0, $this->current_date['mon'], $this->current_date['mday'], $this->current_date['year'] + 1) - 1; 205 } 206 207 //dumpVar($this->date_start . ' - ' . $this->date_end . ' / ' . date('d.m.Y, H:i:s', $this->date_start) . ' - ' . date('d.m.Y, H:i:s', $this->date_end)); 208 209 $this->limit = $default['items']; 210 $this->href = $default['href']; 211 212 if($default['template'] !== '') { 213 $default['template'] = preg_replace('/[\/\\:]/', '', $default['template']); 214 if(is_file(PHPWCMS_TEMPLATE.'calendar/'.$default['template'])) { 215 $this->template = file_get_contents(PHPWCMS_TEMPLATE.'calendar/'.$default['template']); 216 $this->template = str_replace('{STARTDATE', '{LIVEDATE', $this->template); 217 $this->template = str_replace('{ENDDATE', '{KILLDATE', $this->template); 218 } else { 219 $default['template'] = ''; 220 } 221 } 222 223 $where = array(); 224 225 if($default['lang'] !== '') { 226 227 $default['lang'] = str_replace(',', ' ', preg_replace('/[^a-z\-]/', '', strtolower($default['lang']))); 228 $default['lang'] = array_intersect( convertStringToArray( $default['lang'], ' '), $GLOBALS['phpwcms']['allowed_lang']); 229 230 if(count($default['lang'])) { 231 $where[] = "calendar_lang IN ('" . implode("','", $default['lang']) . "')"; 232 } 233 } 234 235 if($default['tag'] !== '') { 236 237 $default['tag'] = convertStringToArray( strtolower( $default['tag'] ), ','); 238 239 if(count($default['tag'])) { 240 241 $tag_where = array(); 242 243 foreach($default['tag'] as $tag) { 244 245 $tag_where[] = "cat_name='".aporeplace($tag)."'"; 246 247 } 248 249 if(count($tag_where)) { 250 251 $where[] = '(' . implode(' '.$default['tagmode'] . ' ', $tag_where) . ')'; 252 253 $this->join_on = 'LEFT JOIN '.DB_PREPEND.'phpwcms_categories ON cat_pid=calendar_id'; 254 $this->group_by = 'calendar_id'; 255 } 256 257 }; 258 } 259 260 $this->where = implode(' AND ', $where); 261 262 $this->getDate(); 263 264 return $default; 265 266 } 267 268 269 function getDate() { 270 271 // 1 daily 272 // 2 Every weekday (Mon-Fri) 273 // 3 Every Mon., Wed. and Fri. 274 // 4 Every Tues. and Thurs. 275 // 5 Weekly 276 // 6 Monthly 277 // 7 yearly 278 279 if(is_string($this->order_by) && trim($this->order_by) != '') { 280 $this->order_by = ' ORDER BY '.$this->order_by; 281 } else { 282 $this->order_by = ''; 283 } 284 if(is_int($this->limit) && $this->limit > 0) { 285 $this->limit = ' LIMIT '.$this->limit; 286 } else { 287 $this->limit = ''; 288 } 289 if(is_string($this->group_by) && trim($this->group_by) != '') { 290 $this->group_by = ' GROUP BY '.$this->group_by; 291 } else { 292 $this->group_by = ''; 293 } 294 295 296 $sql = 'SELECT '. $this->select .', '; 297 $sql .= "UNIX_TIMESTAMP(calendar_start) AS calendar_start_date, "; 298 $sql .= "UNIX_TIMESTAMP(calendar_end) AS calendar_end_date "; 299 $sql .= ' FROM '.DB_PREPEND.'phpwcms_calendar pc '; 300 $sql .= $this->join_on; 301 $sql .= ' WHERE '; 302 $sql .= 'calendar_status = 1 AND '; 303 $sql .= "calendar_start >= '".aporeplace( date('Y-m-d H:i:s', $this->date_start) )."' AND "; 304 $sql .= "calendar_start <= '".aporeplace( date('Y-m-d H:i:s', $this->date_end) )."'"; 305 if(!empty($this->where)) { 306 $sql .= ' AND ' . $this->where; 307 } 308 $sql .= $this->group_by; 309 $sql .= $this->order_by; 310 $sql .= $this->limit; 311 312 $this->dates = _dbQuery($sql); 313 if( !$this->dates ) { 314 $this->dates = array(); 315 } 316 } 317 318 } 319 320 321 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Nov 16 22:51:00 2010 | Cross-referenced by PHPXref 0.7 |