[1053] | 1 | <?php |
---|
| 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 | |
---|
[1086] | 27 | define('CAL_VIEW_LIST', 'list'); |
---|
| 28 | define('CAL_VIEW_CALENDAR', 'calendar'); |
---|
[1053] | 29 | |
---|
| 30 | function initialize_calendar() |
---|
| 31 | { |
---|
| 32 | global $page, $conf, $user, $template; |
---|
| 33 | |
---|
| 34 | //------------------ initialize the condition on items to take into account --- |
---|
| 35 | $inner_sql = ' FROM ' . IMAGES_TABLE; |
---|
[1059] | 36 | |
---|
[1086] | 37 | if (!isset($page['category']) or is_numeric($page['category'])) |
---|
[1053] | 38 | { // we will regenerate the items by including subcats elements |
---|
| 39 | $page['cat_nb_images'] = 0; |
---|
| 40 | $page['items'] = array(); |
---|
| 41 | $inner_sql .= ' |
---|
| 42 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
[1059] | 43 | |
---|
[1086] | 44 | if (isset($page['category']) and is_numeric($page['category'])) |
---|
[1053] | 45 | { |
---|
| 46 | $sub_ids = array_diff( |
---|
[1086] | 47 | get_subcat_ids(array($page['category'])), |
---|
[1053] | 48 | explode(',', $user['forbidden_categories']) |
---|
| 49 | ); |
---|
[1059] | 50 | |
---|
[1053] | 51 | if (empty($sub_ids)) |
---|
| 52 | { |
---|
| 53 | return; // nothing to do |
---|
| 54 | } |
---|
| 55 | $inner_sql .= ' |
---|
| 56 | WHERE category_id IN ('.implode(',',$sub_ids).')'; |
---|
| 57 | } |
---|
| 58 | else |
---|
| 59 | { |
---|
| 60 | $inner_sql .= ' |
---|
| 61 | WHERE category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
| 66 | if ( empty($page['items']) ) |
---|
| 67 | { |
---|
| 68 | return; // nothing to do |
---|
| 69 | } |
---|
| 70 | $inner_sql .= ' |
---|
| 71 | WHERE id IN (' . implode(',',$page['items']) .')'; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | //-------------------------------------- initialize the calendar parameters --- |
---|
| 75 | pwg_debug('start initialize_calendar'); |
---|
[1057] | 76 | |
---|
| 77 | $fields = array( |
---|
| 78 | // Created |
---|
| 79 | 'created' => array( |
---|
| 80 | 'label' => l10n('Creation date'), |
---|
| 81 | ), |
---|
| 82 | // Posted |
---|
| 83 | 'posted' => array( |
---|
[1059] | 84 | 'label' => l10n('Post date'), |
---|
[1057] | 85 | ), |
---|
| 86 | ); |
---|
| 87 | |
---|
| 88 | $styles = array( |
---|
[1056] | 89 | // Monthly style |
---|
[1057] | 90 | 'monthly' => array( |
---|
[1053] | 91 | 'include' => 'calendar_monthly.class.php', |
---|
| 92 | 'view_calendar' => true, |
---|
| 93 | ), |
---|
[1059] | 94 | // Weekly style |
---|
[1057] | 95 | 'weekly' => array( |
---|
[1053] | 96 | 'include' => 'calendar_weekly.class.php', |
---|
[1056] | 97 | 'view_calendar' => false, |
---|
[1053] | 98 | ), |
---|
| 99 | ); |
---|
| 100 | |
---|
[1086] | 101 | $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR); |
---|
[1057] | 102 | |
---|
| 103 | // Retrieve calendar field |
---|
[1086] | 104 | if ( !isset( $fields[ $page['chronology']['field'] ] ) ) |
---|
| 105 | { |
---|
| 106 | die('bad field'); |
---|
| 107 | } |
---|
[1059] | 108 | |
---|
[1057] | 109 | // Retrieve style |
---|
[1086] | 110 | if ( !isset( $styles[ $page['chronology']['style'] ] ) ) |
---|
| 111 | { |
---|
| 112 | $page['chronology']['style'] = 'monthly'; |
---|
| 113 | } |
---|
| 114 | $cal_style = $page['chronology']['style']; |
---|
[1057] | 115 | include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']); |
---|
| 116 | $calendar = new Calendar(); |
---|
| 117 | |
---|
| 118 | // Retrieve view |
---|
[1086] | 119 | |
---|
| 120 | if ( !isset($page['chronology']['view']) or |
---|
| 121 | !in_array( $page['chronology']['view'], $views ) ) |
---|
[1053] | 122 | { |
---|
[1086] | 123 | $page['chronology']['view'] = CAL_VIEW_LIST; |
---|
[1053] | 124 | } |
---|
| 125 | |
---|
[1086] | 126 | if ( CAL_VIEW_CALENDAR==$page['chronology']['view'] and |
---|
| 127 | !$styles[$cal_style]['view_calendar'] ) |
---|
| 128 | { |
---|
| 129 | |
---|
| 130 | $page['chronology']['view'] = CAL_VIEW_LIST; |
---|
| 131 | } |
---|
| 132 | $cal_view = $page['chronology']['view']; |
---|
| 133 | |
---|
[1053] | 134 | // perform a sanity check on $requested |
---|
[1086] | 135 | if (!isset($page['chronology_date'])) |
---|
[1053] | 136 | { |
---|
[1086] | 137 | $page['chronology_date'] = array(); |
---|
[1053] | 138 | } |
---|
[1086] | 139 | while ( count($page['chronology_date']) > 3) |
---|
| 140 | { |
---|
| 141 | array_pop($page['chronology_date']); |
---|
| 142 | } |
---|
[1053] | 143 | |
---|
| 144 | $any_count = 0; |
---|
[1086] | 145 | for ($i = 0; $i < count($page['chronology_date']); $i++) |
---|
[1053] | 146 | { |
---|
[1086] | 147 | if ($page['chronology_date'][$i] == 'any') |
---|
[1053] | 148 | { |
---|
[1057] | 149 | if ($cal_view == CAL_VIEW_CALENDAR) |
---|
[1053] | 150 | {// we dont allow any in calendar view |
---|
[1086] | 151 | while ($i < count($page['chronology_date'])) |
---|
[1053] | 152 | { |
---|
[1086] | 153 | array_pop($page['chronology_date']); |
---|
[1053] | 154 | } |
---|
| 155 | break; |
---|
| 156 | } |
---|
| 157 | $any_count++; |
---|
| 158 | } |
---|
[1086] | 159 | elseif ($page['chronology_date'][$i] == '') |
---|
[1053] | 160 | { |
---|
[1086] | 161 | while ($i < count($page['chronology_date'])) |
---|
[1053] | 162 | { |
---|
[1086] | 163 | array_pop($page['chronology_date']); |
---|
[1053] | 164 | } |
---|
| 165 | } |
---|
[1059] | 166 | else |
---|
| 167 | { |
---|
[1086] | 168 | $page['chronology_date'][$i] = (int)$page['chronology_date'][$i]; |
---|
[1059] | 169 | } |
---|
[1053] | 170 | } |
---|
| 171 | if ($any_count == 3) |
---|
| 172 | { |
---|
[1086] | 173 | array_pop($page['chronology_date']); |
---|
[1053] | 174 | } |
---|
[1059] | 175 | |
---|
[1086] | 176 | $calendar->initialize($inner_sql); |
---|
[1053] | 177 | |
---|
[1059] | 178 | //echo ('<pre>'. var_export($calendar, true) . '</pre>'); |
---|
| 179 | |
---|
[1086] | 180 | /* $url_base = get_query_string_diff(array('start', 'calendar')); |
---|
[1057] | 181 | $url_base = |
---|
| 182 | PHPWG_ROOT_PATH.'category.php' |
---|
[1059] | 183 | .$url_base |
---|
[1057] | 184 | .(empty($url_base) ? '?' : '&') |
---|
| 185 | .'calendar='.$cal_field.'-' |
---|
[1086] | 186 | ;*/ |
---|
[1057] | 187 | $must_show_list = true; // true until calendar generates its own display |
---|
[1053] | 188 | if (basename($_SERVER["PHP_SELF"]) == 'category.php') |
---|
| 189 | { |
---|
| 190 | $template->assign_block_vars('calendar', array()); |
---|
| 191 | |
---|
[1086] | 192 | if ($calendar->generate_category_content()) |
---|
[1053] | 193 | { |
---|
| 194 | unset( |
---|
| 195 | $page['thumbnails_include'], |
---|
| 196 | $page['items'], |
---|
| 197 | $page['cat_nb_images'] |
---|
| 198 | ); |
---|
[1059] | 199 | |
---|
[1053] | 200 | $must_show_list = false; |
---|
| 201 | } |
---|
[1059] | 202 | |
---|
[1057] | 203 | $template->assign_block_vars( 'calendar.views', array() ); |
---|
| 204 | foreach ($styles as $style => $style_data) |
---|
[1053] | 205 | { |
---|
[1086] | 206 | foreach ($views as $view) |
---|
[1053] | 207 | { |
---|
[1057] | 208 | if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR) |
---|
[1053] | 209 | { |
---|
[1057] | 210 | $selected = ''; |
---|
[1086] | 211 | $chronology = $page['chronology']; |
---|
| 212 | $chronology['style'] = $style; |
---|
| 213 | $chronology['view'] = $view; |
---|
| 214 | |
---|
| 215 | if ($style!=$cal_style) |
---|
[1057] | 216 | { |
---|
[1086] | 217 | $chronology_date = array(); |
---|
| 218 | if ( isset($page['chronology_date'][0]) ) |
---|
[1057] | 219 | { |
---|
[1086] | 220 | array_push($chronology_date, $page['chronology_date'][0]); |
---|
[1057] | 221 | } |
---|
| 222 | } |
---|
| 223 | else |
---|
| 224 | { |
---|
[1086] | 225 | $chronology_date = $page['chronology_date']; |
---|
[1057] | 226 | } |
---|
[1086] | 227 | $url = duplicate_index_url( |
---|
| 228 | array( |
---|
| 229 | 'chronology' => $chronology, |
---|
| 230 | 'chronology_date' => $chronology_date, |
---|
| 231 | ) |
---|
| 232 | ); |
---|
| 233 | |
---|
| 234 | if ($style==$cal_style and $view==$cal_view ) |
---|
| 235 | { |
---|
| 236 | $selected = 'SELECTED'; |
---|
| 237 | } |
---|
| 238 | |
---|
[1057] | 239 | $template->assign_block_vars( |
---|
| 240 | 'calendar.views.view', |
---|
| 241 | array( |
---|
| 242 | 'VALUE' => $url, |
---|
[1059] | 243 | 'CONTENT' => l10n('calendar_'.$style.'_'.$view), |
---|
[1057] | 244 | 'SELECTED' => $selected, |
---|
| 245 | ) |
---|
| 246 | ); |
---|
[1053] | 247 | } |
---|
| 248 | } |
---|
| 249 | } |
---|
[1086] | 250 | $url = duplicate_index_url( |
---|
| 251 | array('chronology_date'=>array()), array('start') |
---|
| 252 | ); |
---|
| 253 | $calendar_title = '<a href="'.$url.'">' |
---|
| 254 | .$fields[$chronology['field']]['label'].'</a>'; |
---|
[1062] | 255 | $calendar_title.= $calendar->get_display_name(); |
---|
| 256 | //this should be an assign_block_vars, but I need to assign 'calendar' |
---|
| 257 | //above and at that point I don't have the title yet. |
---|
| 258 | $template->_tpldata['calendar.'][0]['TITLE'] = $calendar_title; |
---|
[1053] | 259 | } // end category calling |
---|
| 260 | |
---|
| 261 | if ($must_show_list) |
---|
| 262 | { |
---|
| 263 | $query = 'SELECT DISTINCT(id)'; |
---|
[1062] | 264 | $query .= $calendar->inner_sql.' |
---|
| 265 | '.$calendar->get_date_where(); |
---|
[1053] | 266 | if ( isset($page['super_order_by']) ) |
---|
| 267 | { |
---|
| 268 | $query .= ' |
---|
| 269 | '.$conf['order_by']; |
---|
| 270 | } |
---|
| 271 | else |
---|
| 272 | { |
---|
| 273 | $order_by = str_replace( |
---|
| 274 | 'ORDER BY ', |
---|
[1059] | 275 | 'ORDER BY '.$calendar->date_field.' DESC,', $conf['order_by'] |
---|
[1053] | 276 | ); |
---|
[1062] | 277 | $query .= ' |
---|
| 278 | '.$order_by; |
---|
[1053] | 279 | } |
---|
| 280 | |
---|
| 281 | $page['items'] = array_from_query($query, 'id'); |
---|
| 282 | $page['cat_nb_images'] = count($page['items']); |
---|
| 283 | $page['thumbnails_include'] = 'include/category_default.inc.php'; |
---|
| 284 | } |
---|
| 285 | pwg_debug('end initialize_calendar'); |
---|
| 286 | } |
---|
| 287 | |
---|
[1047] | 288 | ?> |
---|