[1109] | 1 | <?php |
---|
[1055] | 2 | // +-----------------------------------------------------------------------+ |
---|
[8728] | 3 | // | Piwigo - a PHP based photo gallery | |
---|
[2297] | 4 | // +-----------------------------------------------------------------------+ |
---|
[12922] | 5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[1055] | 23 | |
---|
| 24 | include_once(PHPWG_ROOT_PATH.'include/calendar_base.class.php'); |
---|
| 25 | |
---|
[1057] | 26 | define ('CYEAR', 0); |
---|
| 27 | define ('CMONTH', 1); |
---|
| 28 | define ('CDAY', 2); |
---|
| 29 | |
---|
[1055] | 30 | /** |
---|
| 31 | * Monthly calendar style (composed of years/months and days) |
---|
| 32 | */ |
---|
| 33 | class Calendar extends CalendarBase |
---|
| 34 | { |
---|
| 35 | |
---|
[1059] | 36 | /** |
---|
| 37 | * Initialize the calendar |
---|
| 38 | * @param string inner_sql used for queries (INNER JOIN or normal) |
---|
| 39 | */ |
---|
[1086] | 40 | function initialize($inner_sql) |
---|
[1059] | 41 | { |
---|
[1086] | 42 | parent::initialize($inner_sql); |
---|
[1059] | 43 | global $lang; |
---|
| 44 | $this->calendar_levels = array( |
---|
| 45 | array( |
---|
[4398] | 46 | 'sql'=> pwg_db_get_year($this->date_field), |
---|
[1059] | 47 | 'labels' => null |
---|
| 48 | ), |
---|
| 49 | array( |
---|
[4398] | 50 | 'sql'=> pwg_db_get_month($this->date_field), |
---|
| 51 | 'labels' => $lang['month'] |
---|
[1059] | 52 | ), |
---|
| 53 | array( |
---|
[4398] | 54 | 'sql'=> pwg_db_get_dayofmonth($this->date_field), |
---|
[1059] | 55 | 'labels' => null |
---|
| 56 | ), |
---|
| 57 | ); |
---|
| 58 | } |
---|
| 59 | |
---|
[1055] | 60 | /** |
---|
| 61 | * Generate navigation bars for category page |
---|
| 62 | * @return boolean false to indicate that thumbnails |
---|
| 63 | * where not included here, true otherwise |
---|
| 64 | */ |
---|
[1086] | 65 | function generate_category_content() |
---|
[1055] | 66 | { |
---|
[1086] | 67 | global $conf, $page; |
---|
[1055] | 68 | |
---|
[1090] | 69 | $view_type = $page['chronology_view']; |
---|
[1057] | 70 | if ($view_type==CAL_VIEW_CALENDAR) |
---|
| 71 | { |
---|
[2231] | 72 | global $template; |
---|
| 73 | $tpl_var = array(); |
---|
[1086] | 74 | if ( count($page['chronology_date'])==0 ) |
---|
[1057] | 75 | {//case A: no year given - display all years+months |
---|
[2231] | 76 | if ($this->build_global_calendar($tpl_var)) |
---|
| 77 | { |
---|
| 78 | $template->assign('chronology_calendar', $tpl_var); |
---|
[1057] | 79 | return true; |
---|
[2231] | 80 | } |
---|
[1057] | 81 | } |
---|
[1055] | 82 | |
---|
[1086] | 83 | if ( count($page['chronology_date'])==1 ) |
---|
[1057] | 84 | {//case B: year given - display all days in given year |
---|
[2231] | 85 | if ($this->build_year_calendar($tpl_var)) |
---|
[1057] | 86 | { |
---|
[2231] | 87 | $template->assign('chronology_calendar', $tpl_var); |
---|
[1059] | 88 | $this->build_nav_bar(CYEAR); // years |
---|
[1057] | 89 | return true; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
[1086] | 93 | if ( count($page['chronology_date'])==2 ) |
---|
[1057] | 94 | {//case C: year+month given - display a nice month calendar |
---|
[2231] | 95 | if ( $this->build_month_calendar($tpl_var) ) |
---|
| 96 | { |
---|
| 97 | $template->assign('chronology_calendar', $tpl_var); |
---|
| 98 | } |
---|
[1062] | 99 | $this->build_next_prev(); |
---|
[1055] | 100 | return true; |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
[1086] | 104 | if ($view_type==CAL_VIEW_LIST or count($page['chronology_date'])==3) |
---|
[1055] | 105 | { |
---|
[1086] | 106 | if ( count($page['chronology_date'])==0 ) |
---|
[1057] | 107 | { |
---|
[1059] | 108 | $this->build_nav_bar(CYEAR); // years |
---|
[1057] | 109 | } |
---|
[1086] | 110 | if ( count($page['chronology_date'])==1) |
---|
[1057] | 111 | { |
---|
[1059] | 112 | $this->build_nav_bar(CMONTH); // month |
---|
[1057] | 113 | } |
---|
[1086] | 114 | if ( count($page['chronology_date'])==2 ) |
---|
[1057] | 115 | { |
---|
[1062] | 116 | $day_labels = range( 1, $this->get_all_days_in_month( |
---|
[1086] | 117 | $page['chronology_date'][CYEAR] ,$page['chronology_date'][CMONTH] ) ); |
---|
[1062] | 118 | array_unshift($day_labels, 0); |
---|
| 119 | unset( $day_labels[0] ); |
---|
| 120 | $this->build_nav_bar( CDAY, $day_labels ); // days |
---|
[1057] | 121 | } |
---|
[1062] | 122 | $this->build_next_prev(); |
---|
[1055] | 123 | } |
---|
| 124 | return false; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | /** |
---|
| 129 | * Returns a sql where subquery for the date field |
---|
| 130 | * @param int max_levels return the where up to this level |
---|
| 131 | * (e.g. 2=only year and month) |
---|
| 132 | * @return string |
---|
| 133 | */ |
---|
[1057] | 134 | function get_date_where($max_levels=3) |
---|
[1055] | 135 | { |
---|
[1086] | 136 | global $page; |
---|
[4398] | 137 | |
---|
[1086] | 138 | $date = $page['chronology_date']; |
---|
[1057] | 139 | while (count($date)>$max_levels) |
---|
[1055] | 140 | { |
---|
[1057] | 141 | array_pop($date); |
---|
[1055] | 142 | } |
---|
| 143 | $res = ''; |
---|
[1069] | 144 | if (isset($date[CYEAR]) and $date[CYEAR]!=='any') |
---|
[1055] | 145 | { |
---|
[1057] | 146 | $b = $date[CYEAR] . '-'; |
---|
| 147 | $e = $date[CYEAR] . '-'; |
---|
[1069] | 148 | if (isset($date[CMONTH]) and $date[CMONTH]!=='any') |
---|
[1055] | 149 | { |
---|
[4781] | 150 | $b .= sprintf('%02d-', $date[CMONTH]); |
---|
| 151 | $e .= sprintf('%02d-', $date[CMONTH]); |
---|
[1069] | 152 | if (isset($date[CDAY]) and $date[CDAY]!=='any') |
---|
[1055] | 153 | { |
---|
[4781] | 154 | $b .= sprintf('%02d', $date[CDAY]); |
---|
| 155 | $e .= sprintf('%02d', $date[CDAY]); |
---|
[1055] | 156 | } |
---|
| 157 | else |
---|
| 158 | { |
---|
| 159 | $b .= '01'; |
---|
[4398] | 160 | $e .= $this->get_all_days_in_month($date[CYEAR], $date[CMONTH]); |
---|
[1055] | 161 | } |
---|
| 162 | } |
---|
| 163 | else |
---|
| 164 | { |
---|
| 165 | $b .= '01-01'; |
---|
| 166 | $e .= '12-31'; |
---|
[1069] | 167 | if (isset($date[CMONTH]) and $date[CMONTH]!=='any') |
---|
[1055] | 168 | { |
---|
[1059] | 169 | $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH]; |
---|
[1055] | 170 | } |
---|
[1069] | 171 | if (isset($date[CDAY]) and $date[CDAY]!=='any') |
---|
[1055] | 172 | { |
---|
[1059] | 173 | $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY]; |
---|
[1055] | 174 | } |
---|
| 175 | } |
---|
| 176 | $res = " AND $this->date_field BETWEEN '$b' AND '$e 23:59:59'" . $res; |
---|
| 177 | } |
---|
| 178 | else |
---|
| 179 | { |
---|
| 180 | $res = ' AND '.$this->date_field.' IS NOT NULL'; |
---|
[1069] | 181 | if (isset($date[CMONTH]) and $date[CMONTH]!=='any') |
---|
[1055] | 182 | { |
---|
[1059] | 183 | $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH]; |
---|
[1055] | 184 | } |
---|
[1069] | 185 | if (isset($date[CDAY]) and $date[CDAY]!=='any') |
---|
[1055] | 186 | { |
---|
[1059] | 187 | $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY]; |
---|
[1055] | 188 | } |
---|
| 189 | } |
---|
| 190 | return $res; |
---|
| 191 | } |
---|
| 192 | |
---|
[1057] | 193 | |
---|
[1059] | 194 | |
---|
| 195 | //--------------------------------------------------------- private members --- |
---|
| 196 | |
---|
[4398] | 197 | // returns an array with all the days in a given month |
---|
[1059] | 198 | function get_all_days_in_month($year, $month) |
---|
[1057] | 199 | { |
---|
[1059] | 200 | $md= array(1=>31,28,31,30,31,30,31,31,30,31,30,31); |
---|
| 201 | |
---|
| 202 | if ( is_numeric($year) and $month==2) |
---|
[1057] | 203 | { |
---|
[1059] | 204 | $nb_days = $md[2]; |
---|
| 205 | if ( ($year%4==0) and ( ($year%100!=0) or ($year%400!=0) ) ) |
---|
| 206 | { |
---|
| 207 | $nb_days++; |
---|
| 208 | } |
---|
[1057] | 209 | } |
---|
[1059] | 210 | elseif ( is_numeric($month) ) |
---|
[1057] | 211 | { |
---|
[1059] | 212 | $nb_days = $md[ $month ]; |
---|
[1057] | 213 | } |
---|
[1059] | 214 | else |
---|
[1057] | 215 | { |
---|
[1059] | 216 | $nb_days = 31; |
---|
[1057] | 217 | } |
---|
[1061] | 218 | return $nb_days; |
---|
[1057] | 219 | } |
---|
| 220 | |
---|
[2231] | 221 | function build_global_calendar(&$tpl_var) |
---|
[1055] | 222 | { |
---|
[1086] | 223 | global $page; |
---|
[4398] | 224 | |
---|
[1086] | 225 | assert( count($page['chronology_date']) == 0 ); |
---|
[4398] | 226 | $query=' |
---|
[12118] | 227 | SELECT '.pwg_db_get_date_YYYYMM($this->date_field).' as period, |
---|
| 228 | COUNT(distinct id) as count'; |
---|
[1055] | 229 | $query.= $this->inner_sql; |
---|
[1057] | 230 | $query.= $this->get_date_where(); |
---|
[1055] | 231 | $query.= ' |
---|
[12118] | 232 | GROUP BY period |
---|
| 233 | ORDER BY '.pwg_db_get_year($this->date_field).' DESC, '.pwg_db_get_month($this->date_field).' ASC'; |
---|
[1055] | 234 | |
---|
| 235 | $result = pwg_query($query); |
---|
[1059] | 236 | $items=array(); |
---|
[4325] | 237 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1055] | 238 | { |
---|
| 239 | $y = substr($row['period'], 0, 4); |
---|
| 240 | $m = (int)substr($row['period'], 4, 2); |
---|
| 241 | if ( ! isset($items[$y]) ) |
---|
| 242 | { |
---|
| 243 | $items[$y] = array('nb_images'=>0, 'children'=>array() ); |
---|
| 244 | } |
---|
| 245 | $items[$y]['children'][$m] = $row['count']; |
---|
| 246 | $items[$y]['nb_images'] += $row['count']; |
---|
| 247 | } |
---|
| 248 | //echo ('<pre>'. var_export($items, true) . '</pre>'); |
---|
| 249 | if (count($items)==1) |
---|
| 250 | {// only one year exists so bail out to year view |
---|
| 251 | list($y) = array_keys($items); |
---|
[1086] | 252 | $page['chronology_date'][CYEAR] = $y; |
---|
[1055] | 253 | return false; |
---|
| 254 | } |
---|
| 255 | |
---|
[2231] | 256 | global $lang; |
---|
[1055] | 257 | foreach ( $items as $year=>$year_data) |
---|
| 258 | { |
---|
[1086] | 259 | $chronology_date = array( $year ); |
---|
| 260 | $url = duplicate_index_url( array('chronology_date'=>$chronology_date) ); |
---|
[1055] | 261 | |
---|
[2231] | 262 | $nav_bar = $this->get_nav_bar_from_items( $chronology_date, |
---|
[3168] | 263 | $year_data['children'], false, false, $lang['month'] ); |
---|
[1055] | 264 | |
---|
[2231] | 265 | $tpl_var['calendar_bars'][] = |
---|
| 266 | array( |
---|
| 267 | 'U_HEAD' => $url, |
---|
| 268 | 'NB_IMAGES' => $year_data['nb_images'], |
---|
| 269 | 'HEAD_LABEL' => $year, |
---|
[3168] | 270 | 'items' => $nav_bar, |
---|
[2231] | 271 | ); |
---|
[1055] | 272 | } |
---|
| 273 | return true; |
---|
| 274 | } |
---|
| 275 | |
---|
[2231] | 276 | function build_year_calendar(&$tpl_var) |
---|
[1055] | 277 | { |
---|
[1086] | 278 | global $page; |
---|
[4398] | 279 | |
---|
[1086] | 280 | assert( count($page['chronology_date']) == 1 ); |
---|
[4398] | 281 | $query='SELECT '.pwg_db_get_date_MMDD($this->date_field).' as period, |
---|
| 282 | COUNT(DISTINCT id) as count'; |
---|
[1055] | 283 | $query.= $this->inner_sql; |
---|
[1057] | 284 | $query.= $this->get_date_where(); |
---|
[1055] | 285 | $query.= ' |
---|
[4398] | 286 | GROUP BY period |
---|
| 287 | ORDER BY period ASC'; |
---|
[1055] | 288 | |
---|
| 289 | $result = pwg_query($query); |
---|
[1059] | 290 | $items=array(); |
---|
[4325] | 291 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1055] | 292 | { |
---|
| 293 | $m = (int)substr($row['period'], 0, 2); |
---|
| 294 | $d = substr($row['period'], 2, 2); |
---|
| 295 | if ( ! isset($items[$m]) ) |
---|
| 296 | { |
---|
| 297 | $items[$m] = array('nb_images'=>0, 'children'=>array() ); |
---|
| 298 | } |
---|
| 299 | $items[$m]['children'][$d] = $row['count']; |
---|
| 300 | $items[$m]['nb_images'] += $row['count']; |
---|
| 301 | } |
---|
| 302 | if (count($items)==1) |
---|
| 303 | { // only one month exists so bail out to month view |
---|
| 304 | list($m) = array_keys($items); |
---|
[1086] | 305 | $page['chronology_date'][CMONTH] = $m; |
---|
[1055] | 306 | return false; |
---|
| 307 | } |
---|
[2231] | 308 | global $lang; |
---|
[1055] | 309 | foreach ( $items as $month=>$month_data) |
---|
| 310 | { |
---|
[1086] | 311 | $chronology_date = array( $page['chronology_date'][CYEAR], $month ); |
---|
| 312 | $url = duplicate_index_url( array('chronology_date'=>$chronology_date) ); |
---|
[1055] | 313 | |
---|
[2231] | 314 | $nav_bar = $this->get_nav_bar_from_items( $chronology_date, |
---|
[3168] | 315 | $month_data['children'], false ); |
---|
[1055] | 316 | |
---|
[2231] | 317 | $tpl_var['calendar_bars'][] = |
---|
| 318 | array( |
---|
| 319 | 'U_HEAD' => $url, |
---|
| 320 | 'NB_IMAGES' => $month_data['nb_images'], |
---|
| 321 | 'HEAD_LABEL' => $lang['month'][$month], |
---|
[3168] | 322 | 'items' => $nav_bar, |
---|
[2231] | 323 | ); |
---|
[1055] | 324 | } |
---|
| 325 | return true; |
---|
| 326 | |
---|
| 327 | } |
---|
| 328 | |
---|
[2231] | 329 | function build_month_calendar(&$tpl_var) |
---|
[1055] | 330 | { |
---|
[8626] | 331 | global $page, $lang, $conf; |
---|
[4398] | 332 | |
---|
| 333 | $query='SELECT '.pwg_db_get_dayofmonth($this->date_field).' as period, |
---|
| 334 | COUNT(DISTINCT id) as count'; |
---|
[1055] | 335 | $query.= $this->inner_sql; |
---|
[1086] | 336 | $query.= $this->get_date_where(); |
---|
[1055] | 337 | $query.= ' |
---|
[4398] | 338 | GROUP BY period |
---|
| 339 | ORDER BY period ASC'; |
---|
[1055] | 340 | |
---|
[1558] | 341 | $items=array(); |
---|
[1055] | 342 | $result = pwg_query($query); |
---|
[4325] | 343 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1055] | 344 | { |
---|
[1061] | 345 | $d = (int)$row['period']; |
---|
[1059] | 346 | $items[$d] = array('nb_images'=>$row['count']); |
---|
[1055] | 347 | } |
---|
| 348 | |
---|
[1059] | 349 | foreach ( $items as $day=>$data) |
---|
[1055] | 350 | { |
---|
[1086] | 351 | $page['chronology_date'][CDAY]=$day; |
---|
[1055] | 352 | $query = ' |
---|
[14143] | 353 | SELECT id, file,representative_ext,path,width,height,rotation, '.pwg_db_get_dayofweek($this->date_field).'-1 as dow'; |
---|
[1055] | 354 | $query.= $this->inner_sql; |
---|
[1057] | 355 | $query.= $this->get_date_where(); |
---|
[1055] | 356 | $query.= ' |
---|
[4367] | 357 | ORDER BY '.DB_RANDOM_FUNCTION.'() |
---|
[4334] | 358 | LIMIT 1'; |
---|
[1086] | 359 | unset ( $page['chronology_date'][CDAY] ); |
---|
[1055] | 360 | |
---|
[4325] | 361 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[12796] | 362 | $derivative = new DerivativeImage(IMG_SQUARE, new SrcImage($row)); |
---|
| 363 | $items[$day]['derivative'] = $derivative; |
---|
[1092] | 364 | $items[$day]['file'] = $row['file']; |
---|
[1061] | 365 | $items[$day]['dow'] = $row['dow']; |
---|
[1059] | 366 | } |
---|
[1055] | 367 | |
---|
[12796] | 368 | if ( !empty($items) ) |
---|
[1059] | 369 | { |
---|
[1061] | 370 | list($known_day) = array_keys($items); |
---|
| 371 | $known_dow = $items[$known_day]['dow']; |
---|
| 372 | $first_day_dow = ($known_dow-($known_day-1))%7; |
---|
| 373 | if ($first_day_dow<0) |
---|
| 374 | { |
---|
| 375 | $first_day_dow += 7; |
---|
| 376 | } |
---|
| 377 | //first_day_dow = week day corresponding to the first day of this month |
---|
| 378 | $wday_labels = $lang['day']; |
---|
[1055] | 379 | |
---|
[12118] | 380 | if ('monday' == $conf['week_starts_on']) |
---|
[1061] | 381 | { |
---|
[12118] | 382 | if ($first_day_dow==0) |
---|
| 383 | { |
---|
| 384 | $first_day_dow = 6; |
---|
| 385 | } |
---|
| 386 | else |
---|
| 387 | { |
---|
| 388 | $first_day_dow -= 1; |
---|
| 389 | } |
---|
[8626] | 390 | |
---|
| 391 | array_push( $wday_labels, array_shift($wday_labels) ); |
---|
| 392 | } |
---|
[1059] | 393 | |
---|
[12796] | 394 | list($cell_width, $cell_height) = ImageStdParams::get_by_type(IMG_SQUARE)->sizing->ideal_size; |
---|
[14143] | 395 | if ($cell_width>120) |
---|
| 396 | { |
---|
| 397 | $cell_width = $cell_height = 120; |
---|
| 398 | } |
---|
[1061] | 399 | |
---|
[2231] | 400 | $tpl_weeks = array(); |
---|
| 401 | $tpl_crt_week = array(); |
---|
[1061] | 402 | |
---|
| 403 | //fill the empty days in the week before first day of this month |
---|
| 404 | for ($i=0; $i<$first_day_dow; $i++) |
---|
| 405 | { |
---|
[2231] | 406 | $tpl_crt_week[] = array(); |
---|
[1061] | 407 | } |
---|
[2231] | 408 | |
---|
[1086] | 409 | for ( $day = 1; |
---|
| 410 | $day <= $this->get_all_days_in_month( |
---|
| 411 | $page['chronology_date'][CYEAR], $page['chronology_date'][CMONTH] |
---|
| 412 | ); |
---|
| 413 | $day++) |
---|
[1061] | 414 | { |
---|
| 415 | $dow = ($first_day_dow + $day-1)%7; |
---|
[1352] | 416 | if ($dow==0 and $day!=1) |
---|
[1061] | 417 | { |
---|
[2231] | 418 | $tpl_weeks[] = $tpl_crt_week; // add finished week to week list |
---|
| 419 | $tpl_crt_week = array(); // start new week |
---|
[1061] | 420 | } |
---|
[2231] | 421 | |
---|
[1061] | 422 | if ( !isset($items[$day]) ) |
---|
[2231] | 423 | {// empty day |
---|
| 424 | $tpl_crt_week[] = |
---|
| 425 | array( |
---|
| 426 | 'DAY' => $day |
---|
| 427 | ); |
---|
[1061] | 428 | } |
---|
| 429 | else |
---|
| 430 | { |
---|
[12796] | 431 | list($tn_width,$tn_height) = $items[$day]['derivative']->get_size(); |
---|
[2231] | 432 | |
---|
[1061] | 433 | // now need to fit the thumbnail of size tn_size within |
---|
| 434 | // a cell of size cell_size by playing with CSS position (left/top) |
---|
| 435 | // and the width and height of <img>. |
---|
| 436 | $ratio_w = $tn_width/$cell_width; |
---|
| 437 | $ratio_h = $tn_height/$cell_height; |
---|
| 438 | |
---|
[2231] | 439 | $pos_top=$pos_left=0; |
---|
| 440 | $css_style = ''; |
---|
[1063] | 441 | |
---|
[1061] | 442 | if ( $ratio_w>1 and $ratio_h>1) |
---|
| 443 | {// cell completely smaller than the thumbnail so we will let the browser |
---|
| 444 | // resize the thumbnail |
---|
| 445 | if ($ratio_w > $ratio_h ) |
---|
| 446 | {// thumbnail ratio compared to cell -> wide format |
---|
[2231] | 447 | $css_style = 'height:'.$cell_height.'px;'; |
---|
[1061] | 448 | $browser_img_width = $cell_height*$tn_width/$tn_height; |
---|
[1063] | 449 | $pos_left = ($browser_img_width-$cell_width)/2; |
---|
[1061] | 450 | } |
---|
| 451 | else |
---|
| 452 | { |
---|
[2231] | 453 | $css_style = 'width:'.$cell_width.'px;'; |
---|
[1061] | 454 | $browser_img_height = $cell_width*$tn_height/$tn_width; |
---|
[1063] | 455 | $pos_top = ($browser_img_height-$cell_height)/2; |
---|
[1061] | 456 | } |
---|
| 457 | } |
---|
| 458 | else |
---|
| 459 | { |
---|
| 460 | $pos_left = ($tn_width-$cell_width)/2; |
---|
| 461 | $pos_top = ($tn_height-$cell_height)/2; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | if ( round($pos_left)!=0) |
---|
| 465 | { |
---|
| 466 | $css_style.='left:'.round(-$pos_left).'px;'; |
---|
| 467 | } |
---|
| 468 | if ( round($pos_top)!=0) |
---|
| 469 | { |
---|
| 470 | $css_style.='top:'.round(-$pos_top).'px;'; |
---|
| 471 | } |
---|
[1086] | 472 | $url = duplicate_index_url( |
---|
| 473 | array( |
---|
| 474 | 'chronology_date' => |
---|
| 475 | array( |
---|
| 476 | $page['chronology_date'][CYEAR], |
---|
| 477 | $page['chronology_date'][CMONTH], |
---|
| 478 | $day |
---|
| 479 | ) |
---|
| 480 | ) |
---|
| 481 | ); |
---|
[2231] | 482 | |
---|
| 483 | $tpl_crt_week[] = |
---|
| 484 | array( |
---|
[2265] | 485 | 'DAY' => $day, |
---|
| 486 | 'DOW' => $dow, |
---|
| 487 | 'NB_ELEMENTS' => $items[$day]['nb_images'], |
---|
[12796] | 488 | 'IMAGE' => $items[$day]['derivative']->get_url(), |
---|
[2265] | 489 | 'U_IMG_LINK' => $url, |
---|
| 490 | 'IMAGE_STYLE' => $css_style, |
---|
| 491 | 'IMAGE_ALT' => $items[$day]['file'], |
---|
[1061] | 492 | ); |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | //fill the empty days in the week after the last day of this month |
---|
| 496 | while ( $dow<6 ) |
---|
| 497 | { |
---|
[2231] | 498 | $tpl_crt_week[] = array(); |
---|
[1061] | 499 | $dow++; |
---|
| 500 | } |
---|
[2231] | 501 | $tpl_weeks[] = $tpl_crt_week; |
---|
[1059] | 502 | |
---|
[2231] | 503 | $tpl_var['month_view'] = |
---|
| 504 | array( |
---|
| 505 | 'CELL_WIDTH' => $cell_width, |
---|
| 506 | 'CELL_HEIGHT' => $cell_height, |
---|
| 507 | 'wday_labels' => $wday_labels, |
---|
| 508 | 'weeks' => $tpl_weeks, |
---|
[1061] | 509 | ); |
---|
| 510 | } |
---|
| 511 | |
---|
[1055] | 512 | return true; |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | } |
---|
[12118] | 516 | ?> |
---|