source: trunk/include/functions_calendar.inc.php @ 1086

Last change on this file since 1086 was 1086, checked in by rvelices, 18 years ago

URL rewrite for chronology: uses $pagechronology and
$pagechronology_date. $pagechronology is an array with 'field',
'style' and 'view' keys. This is step 1.

  • Property svn:eol-style set to native
File size: 8.3 KB
Line 
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
27define('CAL_VIEW_LIST',     'list');
28define('CAL_VIEW_CALENDAR', 'calendar');
29
30function 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;
36
37  if (!isset($page['category']) or is_numeric($page['category']))
38  { // we will regenerate the items by including subcats elements
39    $page['cat_nb_images'] = 0;
40    $page['items'] = array();
41    $inner_sql .= '
42INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
43
44    if (isset($page['category']) and is_numeric($page['category']))
45    {
46      $sub_ids = array_diff(
47        get_subcat_ids(array($page['category'])),
48        explode(',', $user['forbidden_categories'])
49        );
50
51      if (empty($sub_ids))
52      {
53        return; // nothing to do
54      }
55      $inner_sql .= '
56WHERE category_id IN ('.implode(',',$sub_ids).')';
57    }
58    else
59    {
60      $inner_sql .= '
61WHERE 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 .= '
71WHERE id IN (' . implode(',',$page['items']) .')';
72  }
73
74//-------------------------------------- initialize the calendar parameters ---
75  pwg_debug('start initialize_calendar');
76
77  $fields = array(
78    // Created
79    'created' => array(
80      'label'          => l10n('Creation date'),
81      ),
82    // Posted
83    'posted' => array(
84      'label'          => l10n('Post date'),
85      ),
86    );
87
88  $styles = array(
89    // Monthly style
90    'monthly' => array(
91      'include'        => 'calendar_monthly.class.php',
92      'view_calendar'  => true,
93      ),
94    // Weekly style
95    'weekly' => array(
96      'include'        => 'calendar_weekly.class.php',
97      'view_calendar'  => false,
98      ),
99    );
100
101  $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR);
102
103  // Retrieve calendar field
104  if ( !isset( $fields[ $page['chronology']['field'] ] ) )
105  {
106    die('bad field');
107  }
108
109  // Retrieve style
110  if ( !isset( $styles[ $page['chronology']['style'] ] ) )
111  {
112    $page['chronology']['style'] = 'monthly';
113  }
114  $cal_style = $page['chronology']['style'];
115  include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']);
116  $calendar = new Calendar();
117
118  // Retrieve view
119
120  if ( !isset($page['chronology']['view']) or
121       !in_array( $page['chronology']['view'], $views ) )
122  {
123    $page['chronology']['view'] = CAL_VIEW_LIST;
124  }
125
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
134  // perform a sanity check on $requested
135  if (!isset($page['chronology_date']))
136  {
137    $page['chronology_date'] = array();
138  }
139  while ( count($page['chronology_date']) > 3)
140  {
141    array_pop($page['chronology_date']);
142  }
143
144  $any_count = 0;
145  for ($i = 0; $i < count($page['chronology_date']); $i++)
146  {
147    if ($page['chronology_date'][$i] == 'any')
148    {
149      if ($cal_view == CAL_VIEW_CALENDAR)
150      {// we dont allow any in calendar view
151        while ($i < count($page['chronology_date']))
152        {
153          array_pop($page['chronology_date']);
154        }
155        break;
156      }
157      $any_count++;
158    }
159    elseif ($page['chronology_date'][$i] == '')
160    {
161      while ($i < count($page['chronology_date']))
162      {
163        array_pop($page['chronology_date']);
164      }
165    }
166    else
167    {
168      $page['chronology_date'][$i] = (int)$page['chronology_date'][$i];
169    }
170  }
171  if ($any_count == 3)
172  {
173    array_pop($page['chronology_date']);
174  }
175
176  $calendar->initialize($inner_sql);
177
178  //echo ('<pre>'. var_export($calendar, true) . '</pre>');
179
180/*  $url_base = get_query_string_diff(array('start', 'calendar'));
181  $url_base =
182    PHPWG_ROOT_PATH.'category.php'
183    .$url_base
184    .(empty($url_base) ? '?' : '&')
185    .'calendar='.$cal_field.'-'
186    ;*/
187  $must_show_list = true; // true until calendar generates its own display
188  if (basename($_SERVER["PHP_SELF"]) == 'category.php')
189  {
190    $template->assign_block_vars('calendar', array());
191
192    if ($calendar->generate_category_content())
193    {
194      unset(
195        $page['thumbnails_include'],
196        $page['items'],
197        $page['cat_nb_images']
198        );
199
200      $must_show_list = false;
201    }
202
203    $template->assign_block_vars( 'calendar.views', array() );
204    foreach ($styles as $style => $style_data)
205    {
206      foreach ($views as $view)
207      {
208        if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
209        {
210          $selected = '';
211          $chronology = $page['chronology'];
212          $chronology['style'] = $style;
213          $chronology['view'] = $view;
214
215          if ($style!=$cal_style)
216          {
217            $chronology_date = array();
218            if ( isset($page['chronology_date'][0]) )
219            {
220              array_push($chronology_date, $page['chronology_date'][0]);
221            }
222          }
223          else
224          {
225            $chronology_date = $page['chronology_date'];
226          }
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
239          $template->assign_block_vars(
240            'calendar.views.view',
241            array(
242              'VALUE' => $url,
243              'CONTENT' => l10n('calendar_'.$style.'_'.$view),
244              'SELECTED' => $selected,
245              )
246            );
247        }
248      }
249    }
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>';
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;
259  } // end category calling
260
261  if ($must_show_list)
262  {
263    $query = 'SELECT DISTINCT(id)';
264    $query .= $calendar->inner_sql.'
265  '.$calendar->get_date_where();
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 ',
275        'ORDER BY '.$calendar->date_field.' DESC,', $conf['order_by']
276        );
277      $query .= '
278  '.$order_by;
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
288?>
Note: See TracBrowser for help on using the repository browser.