[1109] | 1 | <?php |
---|
[1055] | 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
| 5 | // +-----------------------------------------------------------------------+ |
---|
| 6 | // | branch : BSF (Best So Far) |
---|
| 7 | // | file : $RCSfile$ |
---|
| 8 | // | last update : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $ |
---|
| 9 | // | last modifier : $Author: rvelices $ |
---|
| 10 | // | revision : $Revision: 1014 $ |
---|
| 11 | // +-----------------------------------------------------------------------+ |
---|
| 12 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 13 | // | it under the terms of the GNU General Public License as published by | |
---|
| 14 | // | the Free Software Foundation | |
---|
| 15 | // | | |
---|
| 16 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 19 | // | General Public License for more details. | |
---|
| 20 | // | | |
---|
| 21 | // | You should have received a copy of the GNU General Public License | |
---|
| 22 | // | along with this program; if not, write to the Free Software | |
---|
| 23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 24 | // | USA. | |
---|
| 25 | // +-----------------------------------------------------------------------+ |
---|
| 26 | |
---|
| 27 | include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php'); |
---|
| 28 | |
---|
[1057] | 29 | define ('CYEAR', 0); |
---|
| 30 | define ('CMONTH', 1); |
---|
| 31 | define ('CDAY', 2); |
---|
| 32 | |
---|
[1055] | 33 | /** |
---|
| 34 | * Monthly calendar style (composed of years/months and days) |
---|
| 35 | */ |
---|
| 36 | class Calendar extends CalendarBase |
---|
| 37 | { |
---|
| 38 | |
---|
[1059] | 39 | /** |
---|
| 40 | * Initialize the calendar |
---|
| 41 | * @param string inner_sql used for queries (INNER JOIN or normal) |
---|
| 42 | */ |
---|
[1086] | 43 | function initialize($inner_sql) |
---|
[1059] | 44 | { |
---|
[1086] | 45 | parent::initialize($inner_sql); |
---|
[1059] | 46 | global $lang; |
---|
| 47 | $this->calendar_levels = array( |
---|
| 48 | array( |
---|
| 49 | 'sql'=> 'YEAR('.$this->date_field.')', |
---|
| 50 | 'labels' => null |
---|
| 51 | ), |
---|
| 52 | array( |
---|
| 53 | 'sql'=> 'MONTH('.$this->date_field.')', |
---|
| 54 | 'labels' => $lang['month'] |
---|
| 55 | ), |
---|
| 56 | array( |
---|
| 57 | 'sql'=> 'DAYOFMONTH('.$this->date_field.')', |
---|
| 58 | 'labels' => null |
---|
| 59 | ), |
---|
| 60 | ); |
---|
| 61 | } |
---|
| 62 | |
---|
[1055] | 63 | /** |
---|
| 64 | * Generate navigation bars for category page |
---|
| 65 | * @return boolean false to indicate that thumbnails |
---|
| 66 | * where not included here, true otherwise |
---|
| 67 | */ |
---|
[1086] | 68 | function generate_category_content() |
---|
[1055] | 69 | { |
---|
[1086] | 70 | global $conf, $page; |
---|
[1055] | 71 | |
---|
[1090] | 72 | $view_type = $page['chronology_view']; |
---|
[1057] | 73 | if ($view_type==CAL_VIEW_CALENDAR) |
---|
| 74 | { |
---|
[1086] | 75 | if ( count($page['chronology_date'])==0 ) |
---|
[1057] | 76 | {//case A: no year given - display all years+months |
---|
| 77 | if ($this->build_global_calendar()) |
---|
| 78 | return true; |
---|
| 79 | } |
---|
[1055] | 80 | |
---|
[1086] | 81 | if ( count($page['chronology_date'])==1 ) |
---|
[1057] | 82 | {//case B: year given - display all days in given year |
---|
| 83 | if ($this->build_year_calendar()) |
---|
| 84 | { |
---|
[1059] | 85 | $this->build_nav_bar(CYEAR); // years |
---|
[1057] | 86 | return true; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
[1086] | 90 | if ( count($page['chronology_date'])==2 ) |
---|
[1057] | 91 | {//case C: year+month given - display a nice month calendar |
---|
| 92 | $this->build_month_calendar(); |
---|
[1062] | 93 | //$this->build_nav_bar(CYEAR); // years |
---|
| 94 | //$this->build_nav_bar(CMONTH); // month |
---|
| 95 | $this->build_next_prev(); |
---|
[1055] | 96 | return true; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
[1086] | 100 | if ($view_type==CAL_VIEW_LIST or count($page['chronology_date'])==3) |
---|
[1055] | 101 | { |
---|
[1062] | 102 | $has_nav_bar = false; |
---|
[1086] | 103 | if ( count($page['chronology_date'])==0 ) |
---|
[1057] | 104 | { |
---|
[1059] | 105 | $this->build_nav_bar(CYEAR); // years |
---|
[1057] | 106 | } |
---|
[1086] | 107 | if ( count($page['chronology_date'])==1) |
---|
[1057] | 108 | { |
---|
[1059] | 109 | $this->build_nav_bar(CMONTH); // month |
---|
[1057] | 110 | } |
---|
[1086] | 111 | if ( count($page['chronology_date'])==2 ) |
---|
[1057] | 112 | { |
---|
[1062] | 113 | $day_labels = range( 1, $this->get_all_days_in_month( |
---|
[1086] | 114 | $page['chronology_date'][CYEAR] ,$page['chronology_date'][CMONTH] ) ); |
---|
[1062] | 115 | array_unshift($day_labels, 0); |
---|
| 116 | unset( $day_labels[0] ); |
---|
| 117 | $this->build_nav_bar( CDAY, $day_labels ); // days |
---|
[1057] | 118 | } |
---|
[1062] | 119 | $this->build_next_prev(); |
---|
[1055] | 120 | } |
---|
| 121 | return false; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | /** |
---|
| 126 | * Returns a sql where subquery for the date field |
---|
| 127 | * @param int max_levels return the where up to this level |
---|
| 128 | * (e.g. 2=only year and month) |
---|
| 129 | * @return string |
---|
| 130 | */ |
---|
[1057] | 131 | function get_date_where($max_levels=3) |
---|
[1055] | 132 | { |
---|
[1086] | 133 | global $page; |
---|
| 134 | $date = $page['chronology_date']; |
---|
[1057] | 135 | while (count($date)>$max_levels) |
---|
[1055] | 136 | { |
---|
[1057] | 137 | array_pop($date); |
---|
[1055] | 138 | } |
---|
| 139 | $res = ''; |
---|
[1069] | 140 | if (isset($date[CYEAR]) and $date[CYEAR]!=='any') |
---|
[1055] | 141 | { |
---|
[1057] | 142 | $b = $date[CYEAR] . '-'; |
---|
| 143 | $e = $date[CYEAR] . '-'; |
---|
[1069] | 144 | if (isset($date[CMONTH]) and $date[CMONTH]!=='any') |
---|
[1055] | 145 | { |
---|
[1057] | 146 | $b .= $date[CMONTH] . '-'; |
---|
| 147 | $e .= $date[CMONTH] . '-'; |
---|
[1069] | 148 | if (isset($date[CDAY]) and $date[CDAY]!=='any') |
---|
[1055] | 149 | { |
---|
[1057] | 150 | $b .= $date[CDAY]; |
---|
| 151 | $e .= $date[CDAY]; |
---|
[1055] | 152 | } |
---|
| 153 | else |
---|
| 154 | { |
---|
| 155 | $b .= '01'; |
---|
| 156 | $e .= '31'; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
| 161 | $b .= '01-01'; |
---|
| 162 | $e .= '12-31'; |
---|
[1069] | 163 | if (isset($date[CMONTH]) and $date[CMONTH]!=='any') |
---|
[1055] | 164 | { |
---|
[1059] | 165 | $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH]; |
---|
[1055] | 166 | } |
---|
[1069] | 167 | if (isset($date[CDAY]) and $date[CDAY]!=='any') |
---|
[1055] | 168 | { |
---|
[1059] | 169 | $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY]; |
---|
[1055] | 170 | } |
---|
| 171 | } |
---|
| 172 | $res = " AND $this->date_field BETWEEN '$b' AND '$e 23:59:59'" . $res; |
---|
| 173 | } |
---|
| 174 | else |
---|
| 175 | { |
---|
| 176 | $res = ' AND '.$this->date_field.' IS NOT NULL'; |
---|
[1069] | 177 | if (isset($date[CMONTH]) and $date[CMONTH]!=='any') |
---|
[1055] | 178 | { |
---|
[1059] | 179 | $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH]; |
---|
[1055] | 180 | } |
---|
[1069] | 181 | if (isset($date[CDAY]) and $date[CDAY]!=='any') |
---|
[1055] | 182 | { |
---|
[1059] | 183 | $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY]; |
---|
[1055] | 184 | } |
---|
| 185 | } |
---|
| 186 | return $res; |
---|
| 187 | } |
---|
| 188 | |
---|
[1057] | 189 | |
---|
[1059] | 190 | |
---|
| 191 | //--------------------------------------------------------- private members --- |
---|
| 192 | |
---|
| 193 | // returns an array with alll the days in a given month |
---|
| 194 | function get_all_days_in_month($year, $month) |
---|
[1057] | 195 | { |
---|
[1059] | 196 | $md= array(1=>31,28,31,30,31,30,31,31,30,31,30,31); |
---|
| 197 | |
---|
| 198 | if ( is_numeric($year) and $month==2) |
---|
[1057] | 199 | { |
---|
[1059] | 200 | $nb_days = $md[2]; |
---|
| 201 | if ( ($year%4==0) and ( ($year%100!=0) or ($year%400!=0) ) ) |
---|
| 202 | { |
---|
| 203 | $nb_days++; |
---|
| 204 | } |
---|
[1057] | 205 | } |
---|
[1059] | 206 | elseif ( is_numeric($month) ) |
---|
[1057] | 207 | { |
---|
[1059] | 208 | $nb_days = $md[ $month ]; |
---|
[1057] | 209 | } |
---|
[1059] | 210 | else |
---|
[1057] | 211 | { |
---|
[1059] | 212 | $nb_days = 31; |
---|
[1057] | 213 | } |
---|
[1061] | 214 | return $nb_days; |
---|
[1057] | 215 | } |
---|
| 216 | |
---|
| 217 | function build_global_calendar() |
---|
[1055] | 218 | { |
---|
[1086] | 219 | global $page; |
---|
| 220 | assert( count($page['chronology_date']) == 0 ); |
---|
[1055] | 221 | $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period, |
---|
[1059] | 222 | COUNT( DISTINCT(id) ) as count'; |
---|
[1055] | 223 | $query.= $this->inner_sql; |
---|
[1057] | 224 | $query.= $this->get_date_where(); |
---|
[1055] | 225 | $query.= ' |
---|
[1069] | 226 | GROUP BY period |
---|
[1092] | 227 | ORDER BY YEAR('.$this->date_field.') DESC, MONTH('.$this->date_field.')'; |
---|
[1055] | 228 | |
---|
| 229 | $result = pwg_query($query); |
---|
[1059] | 230 | $items=array(); |
---|
[1055] | 231 | while ($row = mysql_fetch_array($result)) |
---|
| 232 | { |
---|
| 233 | $y = substr($row['period'], 0, 4); |
---|
| 234 | $m = (int)substr($row['period'], 4, 2); |
---|
| 235 | if ( ! isset($items[$y]) ) |
---|
| 236 | { |
---|
| 237 | $items[$y] = array('nb_images'=>0, 'children'=>array() ); |
---|
| 238 | } |
---|
| 239 | $items[$y]['children'][$m] = $row['count']; |
---|
| 240 | $items[$y]['nb_images'] += $row['count']; |
---|
| 241 | } |
---|
| 242 | //echo ('<pre>'. var_export($items, true) . '</pre>'); |
---|
| 243 | if (count($items)==1) |
---|
| 244 | {// only one year exists so bail out to year view |
---|
| 245 | list($y) = array_keys($items); |
---|
[1086] | 246 | $page['chronology_date'][CYEAR] = $y; |
---|
[1055] | 247 | return false; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | global $lang, $template; |
---|
| 251 | foreach ( $items as $year=>$year_data) |
---|
| 252 | { |
---|
[1086] | 253 | $chronology_date = array( $year ); |
---|
| 254 | $url = duplicate_index_url( array('chronology_date'=>$chronology_date) ); |
---|
[1055] | 255 | |
---|
[1086] | 256 | $nav_bar = '<span class="calCalHead"><a href="'.$url.'">'.$year.'</a>'; |
---|
[1055] | 257 | $nav_bar .= ' ('.$year_data['nb_images'].')'; |
---|
| 258 | $nav_bar .= '</span><br>'; |
---|
| 259 | |
---|
[1086] | 260 | $nav_bar .= $this->get_nav_bar_from_items( $chronology_date, |
---|
[1059] | 261 | $year_data['children'], null, 'calCal', false, false, $lang['month'] ); |
---|
[1055] | 262 | |
---|
| 263 | $template->assign_block_vars( 'calendar.calbar', |
---|
| 264 | array( 'BAR' => $nav_bar) |
---|
| 265 | ); |
---|
| 266 | } |
---|
| 267 | return true; |
---|
| 268 | } |
---|
| 269 | |
---|
[1057] | 270 | function build_year_calendar() |
---|
[1055] | 271 | { |
---|
[1086] | 272 | global $page; |
---|
| 273 | assert( count($page['chronology_date']) == 1 ); |
---|
[1055] | 274 | $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period, |
---|
[1059] | 275 | COUNT( DISTINCT(id) ) as count'; |
---|
[1055] | 276 | $query.= $this->inner_sql; |
---|
[1057] | 277 | $query.= $this->get_date_where(); |
---|
[1055] | 278 | $query.= ' |
---|
| 279 | GROUP BY period'; |
---|
| 280 | |
---|
| 281 | $result = pwg_query($query); |
---|
[1059] | 282 | $items=array(); |
---|
[1055] | 283 | while ($row = mysql_fetch_array($result)) |
---|
| 284 | { |
---|
| 285 | $m = (int)substr($row['period'], 0, 2); |
---|
| 286 | $d = substr($row['period'], 2, 2); |
---|
| 287 | if ( ! isset($items[$m]) ) |
---|
| 288 | { |
---|
| 289 | $items[$m] = array('nb_images'=>0, 'children'=>array() ); |
---|
| 290 | } |
---|
| 291 | $items[$m]['children'][$d] = $row['count']; |
---|
| 292 | $items[$m]['nb_images'] += $row['count']; |
---|
| 293 | } |
---|
| 294 | if (count($items)==1) |
---|
| 295 | { // only one month exists so bail out to month view |
---|
| 296 | list($m) = array_keys($items); |
---|
[1086] | 297 | $page['chronology_date'][CMONTH] = $m; |
---|
[1055] | 298 | return false; |
---|
| 299 | } |
---|
| 300 | global $lang, $template; |
---|
| 301 | foreach ( $items as $month=>$month_data) |
---|
| 302 | { |
---|
[1086] | 303 | $chronology_date = array( $page['chronology_date'][CYEAR], $month ); |
---|
| 304 | $url = duplicate_index_url( array('chronology_date'=>$chronology_date) ); |
---|
[1055] | 305 | |
---|
[1086] | 306 | $nav_bar = '<span class="calCalHead"><a href="'.$url.'">'; |
---|
[1055] | 307 | $nav_bar .= $lang['month'][$month].'</a>'; |
---|
| 308 | $nav_bar .= ' ('.$month_data['nb_images'].')'; |
---|
| 309 | $nav_bar .= '</span><br>'; |
---|
| 310 | |
---|
[1086] | 311 | $nav_bar .= $this->get_nav_bar_from_items( $chronology_date, |
---|
[1056] | 312 | $month_data['children'], null, 'calCal', false ); |
---|
[1055] | 313 | |
---|
| 314 | $template->assign_block_vars( 'calendar.calbar', |
---|
| 315 | array( 'BAR' => $nav_bar) |
---|
| 316 | ); |
---|
| 317 | } |
---|
| 318 | return true; |
---|
| 319 | |
---|
| 320 | } |
---|
| 321 | |
---|
[1057] | 322 | function build_month_calendar() |
---|
[1055] | 323 | { |
---|
[1086] | 324 | global $page; |
---|
[1061] | 325 | $query='SELECT DISTINCT(DAYOFMONTH('.$this->date_field.')) as period, |
---|
| 326 | COUNT( DISTINCT(id) ) as count'; |
---|
[1055] | 327 | $query.= $this->inner_sql; |
---|
[1086] | 328 | $query.= $this->get_date_where(); |
---|
[1055] | 329 | $query.= ' |
---|
| 330 | GROUP BY period'; |
---|
| 331 | |
---|
| 332 | $result = pwg_query($query); |
---|
| 333 | while ($row = mysql_fetch_array($result)) |
---|
| 334 | { |
---|
[1061] | 335 | $d = (int)$row['period']; |
---|
[1059] | 336 | $items[$d] = array('nb_images'=>$row['count']); |
---|
[1055] | 337 | } |
---|
| 338 | |
---|
[1059] | 339 | foreach ( $items as $day=>$data) |
---|
[1055] | 340 | { |
---|
[1086] | 341 | $page['chronology_date'][CDAY]=$day; |
---|
[1055] | 342 | $query = ' |
---|
[1061] | 343 | SELECT file,tn_ext,path, width, height, DAYOFWEEK('.$this->date_field.')-1 as dow'; |
---|
[1055] | 344 | $query.= $this->inner_sql; |
---|
[1057] | 345 | $query.= $this->get_date_where(); |
---|
[1055] | 346 | $query.= ' |
---|
| 347 | ORDER BY RAND() |
---|
| 348 | LIMIT 0,1'; |
---|
[1086] | 349 | unset ( $page['chronology_date'][CDAY] ); |
---|
[1055] | 350 | |
---|
| 351 | $row = mysql_fetch_array(pwg_query($query)); |
---|
[1059] | 352 | $items[$day]['tn_path'] = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
[1092] | 353 | $items[$day]['file'] = $row['file']; |
---|
| 354 | $items[$day]['path'] = $row['path']; |
---|
| 355 | $items[$day]['tn_ext'] = @$row['tn_ext']; |
---|
[1061] | 356 | $items[$day]['width'] = $row['width']; |
---|
| 357 | $items[$day]['height'] = $row['height']; |
---|
| 358 | $items[$day]['dow'] = $row['dow']; |
---|
[1059] | 359 | } |
---|
[1055] | 360 | |
---|
[1061] | 361 | global $lang, $template, $conf; |
---|
| 362 | |
---|
| 363 | if ( !empty($items) |
---|
| 364 | and $conf['calendar_month_cell_width']>0 |
---|
| 365 | and $conf['calendar_month_cell_height']>0) |
---|
[1059] | 366 | { |
---|
[1061] | 367 | list($known_day) = array_keys($items); |
---|
| 368 | $known_dow = $items[$known_day]['dow']; |
---|
| 369 | $first_day_dow = ($known_dow-($known_day-1))%7; |
---|
| 370 | if ($first_day_dow<0) |
---|
| 371 | { |
---|
| 372 | $first_day_dow += 7; |
---|
| 373 | } |
---|
| 374 | //first_day_dow = week day corresponding to the first day of this month |
---|
| 375 | $wday_labels = $lang['day']; |
---|
[1055] | 376 | |
---|
[1061] | 377 | // BEGIN - pass now in week starting Monday |
---|
| 378 | if ($first_day_dow==0) |
---|
| 379 | { |
---|
| 380 | $first_day_dow = 6; |
---|
| 381 | } |
---|
| 382 | else |
---|
| 383 | { |
---|
| 384 | $first_day_dow -= 1; |
---|
| 385 | } |
---|
| 386 | array_push( $wday_labels, array_shift($wday_labels) ); |
---|
| 387 | // END - pass now in week starting Monday |
---|
[1059] | 388 | |
---|
[1061] | 389 | $cell_width = $conf['calendar_month_cell_width']; |
---|
| 390 | $cell_height = $conf['calendar_month_cell_height']; |
---|
| 391 | |
---|
| 392 | $template->set_filenames( |
---|
| 393 | array( |
---|
| 394 | 'month_calendar'=>'month_calendar.tpl', |
---|
| 395 | ) |
---|
| 396 | ); |
---|
| 397 | |
---|
| 398 | $template->assign_block_vars('calendar.thumbnails', |
---|
[1055] | 399 | array( |
---|
[1061] | 400 | 'WIDTH'=>$cell_width, |
---|
| 401 | 'HEIGHT'=>$cell_height, |
---|
[1055] | 402 | ) |
---|
[1061] | 403 | ); |
---|
| 404 | |
---|
| 405 | //fill the heading with day names |
---|
| 406 | $template->assign_block_vars('calendar.thumbnails.head', array()); |
---|
| 407 | foreach( $wday_labels as $d => $label) |
---|
| 408 | { |
---|
| 409 | $template->assign_block_vars('calendar.thumbnails.head.col', |
---|
| 410 | array('LABEL'=>$label) |
---|
| 411 | ); |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | $template->assign_block_vars('calendar.thumbnails.row', array()); |
---|
| 415 | |
---|
| 416 | //fill the empty days in the week before first day of this month |
---|
| 417 | for ($i=0; $i<$first_day_dow; $i++) |
---|
| 418 | { |
---|
| 419 | $template->assign_block_vars('calendar.thumbnails.row.col', array()); |
---|
| 420 | $template->assign_block_vars('calendar.thumbnails.row.col.blank', array()); |
---|
| 421 | } |
---|
[1086] | 422 | for ( $day = 1; |
---|
| 423 | $day <= $this->get_all_days_in_month( |
---|
| 424 | $page['chronology_date'][CYEAR], $page['chronology_date'][CMONTH] |
---|
| 425 | ); |
---|
| 426 | $day++) |
---|
[1061] | 427 | { |
---|
| 428 | $dow = ($first_day_dow + $day-1)%7; |
---|
| 429 | if ($dow==0) |
---|
| 430 | { |
---|
| 431 | $template->assign_block_vars('calendar.thumbnails.row', array()); |
---|
| 432 | } |
---|
| 433 | $template->assign_block_vars('calendar.thumbnails.row.col', array()); |
---|
| 434 | if ( !isset($items[$day]) ) |
---|
| 435 | { |
---|
| 436 | $template->assign_block_vars('calendar.thumbnails.row.col.empty', |
---|
| 437 | array('LABEL'=>$day)); |
---|
| 438 | } |
---|
| 439 | else |
---|
| 440 | { |
---|
| 441 | // first try to guess thumbnail size |
---|
| 442 | if ( !empty($items[$day]['width']) ) |
---|
| 443 | { |
---|
| 444 | $tn_size = get_picture_size( |
---|
| 445 | $items[$day]['width'], $items[$day]['height'], |
---|
| 446 | $conf['tn_width'], $conf['tn_height'] ); |
---|
| 447 | } |
---|
| 448 | else |
---|
| 449 | {// item not an image (tn is either mime type or an image) |
---|
[1092] | 450 | $thumb = get_thumbnail_src( |
---|
| 451 | $items[$day]['path'], @$items[$day]['tn_ext'], false |
---|
| 452 | ); |
---|
| 453 | $tn_size = @getimagesize($thumb); |
---|
[1061] | 454 | } |
---|
| 455 | $tn_width = $tn_size[0]; |
---|
| 456 | $tn_height = $tn_size[1]; |
---|
| 457 | |
---|
| 458 | // now need to fit the thumbnail of size tn_size within |
---|
| 459 | // a cell of size cell_size by playing with CSS position (left/top) |
---|
| 460 | // and the width and height of <img>. |
---|
| 461 | $ratio_w = $tn_width/$cell_width; |
---|
| 462 | $ratio_h = $tn_height/$cell_height; |
---|
| 463 | |
---|
[1063] | 464 | |
---|
[1061] | 465 | $pos_top=$pos_left=0; |
---|
| 466 | $img_width=$img_height=''; |
---|
| 467 | if ( $ratio_w>1 and $ratio_h>1) |
---|
| 468 | {// cell completely smaller than the thumbnail so we will let the browser |
---|
| 469 | // resize the thumbnail |
---|
| 470 | if ($ratio_w > $ratio_h ) |
---|
| 471 | {// thumbnail ratio compared to cell -> wide format |
---|
| 472 | $img_height = 'height="'.$cell_height.'"'; |
---|
| 473 | $browser_img_width = $cell_height*$tn_width/$tn_height; |
---|
[1063] | 474 | $pos_left = ($browser_img_width-$cell_width)/2; |
---|
[1061] | 475 | } |
---|
| 476 | else |
---|
| 477 | { |
---|
| 478 | $img_width = 'width="'.$cell_width.'"'; |
---|
| 479 | $browser_img_height = $cell_width*$tn_height/$tn_width; |
---|
[1063] | 480 | $pos_top = ($browser_img_height-$cell_height)/2; |
---|
[1061] | 481 | } |
---|
| 482 | } |
---|
| 483 | else |
---|
| 484 | { |
---|
| 485 | $pos_left = ($tn_width-$cell_width)/2; |
---|
| 486 | $pos_top = ($tn_height-$cell_height)/2; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | $css_style = ''; |
---|
| 490 | if ( round($pos_left)!=0) |
---|
| 491 | { |
---|
| 492 | $css_style.='left:'.round(-$pos_left).'px;'; |
---|
| 493 | } |
---|
| 494 | if ( round($pos_top)!=0) |
---|
| 495 | { |
---|
| 496 | $css_style.='top:'.round(-$pos_top).'px;'; |
---|
| 497 | } |
---|
[1086] | 498 | $url = duplicate_index_url( |
---|
| 499 | array( |
---|
| 500 | 'chronology_date' => |
---|
| 501 | array( |
---|
| 502 | $page['chronology_date'][CYEAR], |
---|
| 503 | $page['chronology_date'][CMONTH], |
---|
| 504 | $day |
---|
| 505 | ) |
---|
| 506 | ) |
---|
| 507 | ); |
---|
[1061] | 508 | $alt = $wday_labels[$dow] . ' ' . $day. |
---|
| 509 | ' ('.$items[$day]['nb_images'].')'; |
---|
| 510 | $template->assign_block_vars('calendar.thumbnails.row.col.full', |
---|
| 511 | array( |
---|
| 512 | 'LABEL' => $day, |
---|
| 513 | 'IMAGE' => $items[$day]['tn_path'], |
---|
| 514 | 'U_IMG_LINK'=> $url, |
---|
| 515 | 'STYLE' => $css_style, |
---|
| 516 | 'IMG_WIDTH' => $img_width, |
---|
| 517 | 'IMG_HEIGHT'=> $img_height, |
---|
| 518 | 'IMAGE_ALT' => $alt, |
---|
| 519 | ) |
---|
| 520 | ); |
---|
| 521 | } |
---|
| 522 | } |
---|
| 523 | //fill the empty days in the week after the last day of this month |
---|
| 524 | while ( $dow<6 ) |
---|
| 525 | { |
---|
| 526 | $template->assign_block_vars('calendar.thumbnails.row.col', array()); |
---|
| 527 | $template->assign_block_vars('calendar.thumbnails.row.col.blank', array()); |
---|
| 528 | $dow++; |
---|
| 529 | } |
---|
| 530 | $template->assign_var_from_handle('MONTH_CALENDAR', 'month_calendar'); |
---|
[1055] | 531 | } |
---|
[1061] | 532 | else |
---|
| 533 | { |
---|
| 534 | $template->assign_block_vars('thumbnails', array()); |
---|
| 535 | $template->assign_block_vars('thumbnails.line', array()); |
---|
| 536 | foreach ( $items as $day=>$data) |
---|
| 537 | { |
---|
[1086] | 538 | $url = duplicate_index_url( |
---|
| 539 | array( |
---|
| 540 | 'chronology_date' => |
---|
| 541 | array( |
---|
| 542 | $page['chronology_date'][CYEAR], |
---|
| 543 | $page['chronology_date'][CMONTH], |
---|
| 544 | $day |
---|
| 545 | ) |
---|
| 546 | ) |
---|
| 547 | ); |
---|
[1059] | 548 | |
---|
[1061] | 549 | $thumbnail_title = $lang['day'][$data['dow']] . ' ' . $day; |
---|
| 550 | $name = $thumbnail_title .' ('.$data['nb_images'].')'; |
---|
| 551 | |
---|
| 552 | $template->assign_block_vars( |
---|
| 553 | 'thumbnails.line.thumbnail', |
---|
| 554 | array( |
---|
| 555 | 'IMAGE'=>$data['tn_path'], |
---|
[1092] | 556 | 'IMAGE_ALT'=>$data['file'], |
---|
[1061] | 557 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
| 558 | 'U_IMG_LINK'=>$url |
---|
| 559 | ) |
---|
| 560 | ); |
---|
| 561 | $template->assign_block_vars( |
---|
| 562 | 'thumbnails.line.thumbnail.category_name', |
---|
| 563 | array( |
---|
| 564 | 'NAME' => $name |
---|
| 565 | ) |
---|
| 566 | ); |
---|
| 567 | } |
---|
| 568 | } |
---|
| 569 | |
---|
[1055] | 570 | return true; |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | } |
---|
[1050] | 574 | ?> |
---|