Ignore:
Timestamp:
Mar 17, 2006, 5:13:19 AM (18 years ago)
Author:
rvelices
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_calendar.inc.php

    r1062 r1086  
    2525// +-----------------------------------------------------------------------+
    2626
    27 define('CAL_VIEW_LIST',     'l');
    28 define('CAL_VIEW_CALENDAR', 'c');
    29 
    30 function get_calendar_parameter($options, &$parameters )
    31 {
    32   if ( count($parameters) and isset($options[$parameters[0]]) )
    33   {
    34     return array_shift($parameters);
    35   }
    36   else
    37   {
    38     foreach ($options as $option => $data)
    39     {
    40        if ( empty( $data['default_link'] ) )
    41        {
    42          break;
    43        }
    44     }
    45     return $option;
    46   }
    47 }
     27define('CAL_VIEW_LIST',     'list');
     28define('CAL_VIEW_CALENDAR', 'calendar');
    4829
    4930function initialize_calendar()
     
    5435  $inner_sql = ' FROM ' . IMAGES_TABLE;
    5536
    56   if (!isset($page['cat']) or is_numeric($page['cat']))
     37  if (!isset($page['category']) or is_numeric($page['category']))
    5738  { // we will regenerate the items by including subcats elements
    5839    $page['cat_nb_images'] = 0;
     
    6142INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
    6243
    63     if (isset($page['cat']) and is_numeric($page['cat']))
     44    if (isset($page['category']) and is_numeric($page['category']))
    6445    {
    6546      $sub_ids = array_diff(
    66         get_subcat_ids(array($page['cat'])),
     47        get_subcat_ids(array($page['category'])),
    6748        explode(',', $user['forbidden_categories'])
    6849        );
     
    9374//-------------------------------------- initialize the calendar parameters ---
    9475  pwg_debug('start initialize_calendar');
    95   // the parameters look like (FIELD)?(STYLE)?(VIEW)?(DATE COMPONENTS)?
    96   // FIELD = (created-|posted-)
    97   // STYLE = (m-|w-)
    98   // VIEW  = (l-|c-)
    99   // DATE COMPONENTS= YEAR(-MONTH/WEEK)?(-DAY)?
    10076
    10177  $fields = array(
    10278    // Created
    10379    'created' => array(
    104       'default_link'   => 'created-',
    10580      'label'          => l10n('Creation date'),
    106       'db_field'       => 'date_creation',
    10781      ),
    10882    // Posted
    10983    'posted' => array(
    110       'default_link'   => 'posted-',
    11184      'label'          => l10n('Post date'),
    112       'db_field'       => 'date_available',
    11385      ),
    11486    );
     
    11789    // Monthly style
    11890    'monthly' => array(
    119       'default_link'   => '',
    12091      'include'        => 'calendar_monthly.class.php',
    12192      'view_calendar'  => true,
     
    12394    // Weekly style
    12495    'weekly' => array(
    125       'default_link'   => 'weekly-',
    12696      'include'        => 'calendar_weekly.class.php',
    12797      'view_calendar'  => false,
     
    12999    );
    130100
    131   $views = array(
    132     // list view
    133     CAL_VIEW_LIST => array(
    134       'default_link'   => '',
    135       ),
    136     // calendar view
    137     CAL_VIEW_CALENDAR => array(
    138       'default_link'   => CAL_VIEW_CALENDAR.'-',
    139       ),
    140     );
    141 
    142   $requested = explode('-', $_GET['calendar']);
     101  $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR);
    143102
    144103  // Retrieve calendar field
    145   $cal_field = get_calendar_parameter($fields, $requested);
     104  if ( !isset( $fields[ $page['chronology']['field'] ] ) )
     105  {
     106    die('bad field');
     107  }
    146108
    147109  // Retrieve style
    148   $cal_style = get_calendar_parameter($styles, $requested);
     110  if ( !isset( $styles[ $page['chronology']['style'] ] ) )
     111  {
     112    $page['chronology']['style'] = 'monthly';
     113  }
     114  $cal_style = $page['chronology']['style'];
    149115  include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']);
    150116  $calendar = new Calendar();
    151117
    152118  // Retrieve view
    153   $cal_view = get_calendar_parameter($views, $requested);
    154   if ( CAL_VIEW_CALENDAR==$cal_view and !$styles[$cal_style]['view_calendar'] )
    155   {
    156     $cal_view=CAL_VIEW_LIST;
    157   }
     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'];
    158133
    159134  // perform a sanity check on $requested
    160   while (count($requested) > 3)
    161   {
    162     array_pop($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']);
    163142  }
    164143
    165144  $any_count = 0;
    166   for ($i = 0; $i < count($requested); $i++)
    167   {
    168     if ($requested[$i] == 'any')
     145  for ($i = 0; $i < count($page['chronology_date']); $i++)
     146  {
     147    if ($page['chronology_date'][$i] == 'any')
    169148    {
    170149      if ($cal_view == CAL_VIEW_CALENDAR)
    171150      {// we dont allow any in calendar view
    172         while ($i < count($requested))
     151        while ($i < count($page['chronology_date']))
    173152        {
    174           array_pop($requested);
     153          array_pop($page['chronology_date']);
    175154        }
    176155        break;
     
    178157      $any_count++;
    179158    }
    180     elseif ($requested[$i] == '')
    181     {
    182       while ($i < count($requested))
     159    elseif ($page['chronology_date'][$i] == '')
     160    {
     161      while ($i < count($page['chronology_date']))
    183162      {
    184         array_pop($requested);
     163        array_pop($page['chronology_date']);
    185164      }
    186165    }
    187166    else
    188167    {
    189       $requested[$i] = (int)$requested[$i];
     168      $page['chronology_date'][$i] = (int)$page['chronology_date'][$i];
    190169    }
    191170  }
    192171  if ($any_count == 3)
    193172  {
    194     array_pop($requested);
    195   }
    196 
    197   $calendar->initialize($fields[$cal_field]['db_field'], $inner_sql, $requested);
     173    array_pop($page['chronology_date']);
     174  }
     175
     176  $calendar->initialize($inner_sql);
    198177
    199178  //echo ('<pre>'. var_export($calendar, true) . '</pre>');
    200179
    201   $url_base = get_query_string_diff(array('start', 'calendar'));
     180/*  $url_base = get_query_string_diff(array('start', 'calendar'));
    202181  $url_base =
    203182    PHPWG_ROOT_PATH.'category.php'
     
    205184    .(empty($url_base) ? '?' : '&')
    206185    .'calendar='.$cal_field.'-'
    207     ;
     186    ;*/
    208187  $must_show_list = true; // true until calendar generates its own display
    209188  if (basename($_SERVER["PHP_SELF"]) == 'category.php')
     
    211190    $template->assign_block_vars('calendar', array());
    212191
    213     if ($calendar->generate_category_content(
    214           $url_base.$cal_style.'-'.$cal_view.'-',
    215           $cal_view
    216           )
    217        )
     192    if ($calendar->generate_category_content())
    218193    {
    219194      unset(
     
    229204    foreach ($styles as $style => $style_data)
    230205    {
    231       foreach ($views as $view => $view_data)
     206      foreach ($views as $view)
    232207      {
    233208        if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR)
    234209        {
    235210          $selected = '';
    236           $url = $url_base.$style.'-'.$view;
    237           if ($style==$cal_style)
     211          $chronology = $page['chronology'];
     212          $chronology['style'] = $style;
     213          $chronology['view'] = $view;
     214
     215          if ($style!=$cal_style)
    238216          {
    239             $url .= '-'.implode('-', $calendar->date_components);
    240             if ( $view==$cal_view )
     217            $chronology_date = array();
     218            if ( isset($page['chronology_date'][0]) )
    241219            {
    242               $selected = 'SELECTED';
     220              array_push($chronology_date, $page['chronology_date'][0]);
    243221            }
    244222          }
    245223          else
    246224          {
    247             if (isset($calendar->date_components[0]))
    248             {
    249               $url .= '-' . $calendar->date_components[0];
    250             }
     225            $chronology_date = $page['chronology_date'];
    251226          }
     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
    252239          $template->assign_block_vars(
    253240            'calendar.views.view',
     
    261248      }
    262249    }
    263     $calendar_title =
    264         '<a href="'.$url_base.$cal_style.'-'.$cal_view.'">'
    265         .$fields[$cal_field]['label'].'</a>';
     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>';
    266255    $calendar_title.= $calendar->get_display_name();
    267256    //this should be an assign_block_vars, but I need to assign 'calendar'
Note: See TracChangeset for help on using the changeset viewer.