Ignore:
Timestamp:
Feb 23, 2006, 5:53:11 PM (18 years ago)
Author:
plg
Message:

modification: DAY() MySQL function replaced by DAYOFMONTH() to improve
backward compatibility (this function was added in MySQL 4.1)

bug fixed: with chronology mode, PWG displays thumbnails on main page if
even if no category (which will soon be called "section") is set. This was
producing warnings on category.php from include/category_default.inc.php.

refactoring: on include/calendar_base.class.php and
include/functions_calendar.inc.php. Unix file format, coding guidelines,
etc. While trying to understand the code, I've made some presentation
modification to clarify variable names and so on.

File:
1 edited

Legend:

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

    r1051 r1053  
    2525// +-----------------------------------------------------------------------+
    2626
    27 define('CAL_VIEW_LIST','l');
    28 define('CAL_VIEW_CALENDAR','c');
     27define('CAL_VIEW_LIST',     'l');
     28define('CAL_VIEW_CALENDAR', 'c');
    2929
    3030function initialize_calendar()
     
    3434//------------------ initialize the condition on items to take into account ---
    3535  $inner_sql = ' FROM ' . IMAGES_TABLE;
    36   if ( !isset($page['cat']) or is_numeric($page['cat']) )
     36 
     37  if (!isset($page['cat']) or is_numeric($page['cat']))
    3738  { // we will regenerate the items by including subcats elements
    38     $page['cat_nb_images']=0;
    39     $page['items']=array();
     39    $page['cat_nb_images'] = 0;
     40    $page['items'] = array();
    4041    $inner_sql .= '
    4142INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
    42     if ( is_numeric($page['cat']) )
    43     {
    44       $sub_ids = get_subcat_ids(array($page['cat']));
    45       $sub_ids = array_diff($sub_ids,
    46                             explode(',', $user['forbidden_categories']) );
     43   
     44    if (isset($page['cat']) and is_numeric($page['cat']))
     45    {
     46      $sub_ids = array_diff(
     47        get_subcat_ids(array($page['cat'])),
     48        explode(',', $user['forbidden_categories'])
     49        );
     50     
    4751      if (empty($sub_ids))
    4852      {
     
    7074//-------------------------------------- initialize the calendar parameters ---
    7175  pwg_debug('start initialize_calendar');
     76 
    7277  $cal_styles = array(
    73     array('link'=>'m', 'default_link'=>'', 'name'=>l10n('Monthly'),
    74           'include'=>'calendar_monthly.class.php', 'view_calendar'=>true ),
    75     array('link'=>'w', 'default_link'=>'w-', 'name'=>l10n('Weekly'),
    76           'include'=>'calendar_weekly.class.php', ),
     78    // Weekly style
     79    array(
     80      'link'           => 'm',
     81      'default_link'   => '',
     82      'name'           => l10n('Monthly'),
     83      'include'        => 'calendar_monthly.class.php',
     84      'view_calendar'  => true,
     85      ),
     86    // Monthly style
     87    array(
     88      'link'           => 'w',
     89      'default_link'   => 'w-',
     90      'name'           => l10n('Weekly'),
     91      'include'        => 'calendar_weekly.class.php',
     92      ),
    7793    );
    7894
    7995  $requested = explode('-', $_GET['calendar']);
    8096  $calendar = null;
    81   foreach( $cal_styles as $cal_style)
    82   {
    83     if ($requested[0]==$cal_style['link'])
    84     {
    85       include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
     97  foreach ($cal_styles as $cal_style)
     98  {
     99    if ($requested[0] == $cal_style['link'])
     100    {
     101      include(PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
    86102      $calendar = new Calendar();
    87103      array_shift($requested);
     
    89105    }
    90106  }
    91   if ( !isset($calendar) )
    92   {
    93     foreach( $cal_styles as $cal_style)
    94     {
    95       if (''==$cal_style['default_link'])
     107 
     108  if (!isset($calendar))
     109  {
     110    foreach($cal_styles as $cal_style)
     111    {
     112      if ('' == $cal_style['default_link'])
     113      {
    96114        break;
     115      }
    97116    }
    98117    include( PHPWG_ROOT_PATH.'include/'.$cal_style['include']);
     
    100119  }
    101120
    102   $view_type=CAL_VIEW_LIST;
    103   if ($requested[0]==CAL_VIEW_LIST)
     121  $view_type = CAL_VIEW_LIST;
     122  if ($requested[0] == CAL_VIEW_LIST)
    104123  {
    105124    array_shift($requested);
    106125  }
    107   elseif ($requested[0]==CAL_VIEW_CALENDAR)
     126  elseif ($requested[0] == CAL_VIEW_CALENDAR)
    108127  {
    109128    if ($cal_style['view_calendar'])
    110129    {
    111       $view_type=CAL_VIEW_CALENDAR;
     130      $view_type = CAL_VIEW_CALENDAR;
    112131    }
    113132    array_shift($requested);
    114133  }
    115134  // perform a sanity check on $requested
    116   while (count($requested)>3)
     135  while (count($requested) > 3)
    117136  {
    118137    array_pop($requested);
     
    120139
    121140  $any_count = 0;
    122   for ($i=0; $i<count($requested); $i++)
    123   {
    124     if ($requested[$i]=='any')
    125     {
    126       if ($view_type==CAL_VIEW_CALENDAR)
     141  for ($i = 0; $i < count($requested); $i++)
     142  {
     143    if ($requested[$i] == 'any')
     144    {
     145      if ($view_type == CAL_VIEW_CALENDAR)
    127146      {// we dont allow any in calendar view
    128         while ($i<count($requested))
    129         {
    130           array_pop( $requested );
     147        while ($i < count($requested))
     148        {
     149          array_pop($requested);
    131150        }
    132151        break;
     
    134153      $any_count++;
    135154    }
    136     elseif ( $requested[$i]=='' )
    137     {
    138       while ($i<count($requested))
    139       {
    140         array_pop( $requested );
    141       }
    142     }
    143   }
    144   if ($any_count==3)
     155    elseif ($requested[$i] == '')
     156    {
     157      while ($i < count($requested))
     158      {
     159        array_pop($requested);
     160      }
     161    }
     162  }
     163  if ($any_count == 3)
    145164  {
    146165    array_pop($requested);
     
    151170  //echo ('<pre>'. var_export($calendar, true) . '</pre>');
    152171
    153   $category_calling = false;
     172  // TODO: what makes the list view required?
     173  $must_show_list = true;
     174 
    154175  if (basename($_SERVER["PHP_SELF"]) == 'category.php')
    155176  {
    156     $category_calling = true;
    157   }
    158 
    159   $must_show_list = true;
    160   if ($category_calling)
    161   {
    162177    $template->assign_block_vars('calendar', array());
    163178
    164     $url_base = get_query_string_diff(array('start','calendar'));
    165     $url_base .= empty($url_base) ? '?' : '&';
    166     $url_base .= 'calendar=';
    167     $url_base = PHPWG_ROOT_PATH.'category.php'.$url_base;
    168 
    169     if ( $calendar->generate_category_content(
    170               $url_base.$cal_style['default_link'], $view_type, $requested) )
    171     {
    172       unset( $page['thumbnails_include'] );
    173       unset( $page['items'] );
    174       unset( $page['cat_nb_images'] );
     179    $url_base =
     180      PHPWG_ROOT_PATH.'category.php'
     181      .get_query_string_diff(array('start', 'calendar'))
     182      .(empty($url_base) ? '?' : '&')
     183      .'calendar='
     184      ;
     185
     186    if ($calendar->generate_category_content(
     187          $url_base.$cal_style['default_link'],
     188          $view_type,
     189          $requested
     190          )
     191       )
     192    {
     193      unset(
     194        $page['thumbnails_include'],
     195        $page['items'],
     196        $page['cat_nb_images']
     197        );
     198     
    175199      $must_show_list = false;
    176200    }
    177201
    178202    if ($cal_style['view_calendar'])
    179     { // Build bar for view modes (List/Calendar)
     203    { // Build bar for views (List/Calendar)
    180204      $views = array(
    181         array(CAL_VIEW_LIST, l10n('List') ),
    182         array(CAL_VIEW_CALENDAR, l10n('calendar') ),
    183         );
     205        // list view
     206        array(
     207          'type'  => CAL_VIEW_LIST,
     208          'label' => l10n('List')
     209          ),
     210        // calendar view
     211        array(
     212          'type'  => CAL_VIEW_CALENDAR,
     213          'label' => l10n('calendar')
     214          ),
     215        );
     216     
    184217      $views_bar = '';
    185       foreach( $views as $view )
    186       {
    187         $v = $view[1];
    188         if ( $view_type!=$view[0] )
    189         {
    190           $url = $url_base.$cal_style['default_link'].$view[0].'-';
    191           $url .= implode('-', $requested);
    192           $v = '<a href="'.$url.'">'.$v.'</a> ';
     218
     219      foreach ($views as $view)
     220      {
     221        if ($view_type != $view['type'])
     222        {
     223          $views_bar.=
     224            '<a href="'
     225            .$url_base.$cal_style['default_link'].$view['type'].'-'
     226            .implode('-', $requested)
     227            .'">'.$view['label'].'</a> ';
    193228        }
    194229        else
    195230        {
    196           $v = $v.' ';
    197         }
    198         $views_bar .= $v . ' ';
    199       }
    200       $template->assign_block_vars('calendar.views', array(
    201         'BAR'=>$views_bar
    202         ));
     231          $views_bar.= $view['label'].' ';
     232        }
     233       
     234        $views_bar.= ' ';
     235      }
     236     
     237      $template->assign_block_vars(
     238        'calendar.views',
     239        array(
     240          'BAR' => $views_bar,
     241          )
     242        );
    203243    }
    204244
    205245    // Build bar for calendar styles (Monthly, Weekly)
    206246    $styles_bar = '';
    207     foreach ( $cal_styles as $style)
    208     {
    209       if ($cal_style['link']!=$style['link'])
     247    foreach ($cal_styles as $style)
     248    {
     249      if ($cal_style['link'] != $style['link'])
    210250      {
    211251        $url = $url_base.$style['default_link'];
     
    222262      }
    223263    }
    224     $template->assign_block_vars( 'calendar.styles',
    225                array( 'BAR' => $styles_bar)
    226                );
     264    $template->assign_block_vars(
     265      'calendar.styles',
     266      array(
     267        'BAR' => $styles_bar,
     268        )
     269      );
    227270  } // end category calling
    228271
     
    240283    {
    241284      $order_by = str_replace(
    242                 'ORDER BY ',
    243                 'ORDER BY '.$calendar->date_field.',', $conf['order_by']
    244                );
     285        'ORDER BY ',
     286        'ORDER BY '.$calendar->date_field.',', $conf['order_by']
     287        );
    245288      $query .= $order_by;
    246289    }
    247290
    248     $page['items'] = array_from_query($query, 'id');
    249     $page['cat_nb_images'] = count($page['items']);
     291    $page['items']              = array_from_query($query, 'id');
     292    $page['cat_nb_images']      = count($page['items']);
    250293    $page['thumbnails_include'] = 'include/category_default.inc.php';
    251294  }
Note: See TracChangeset for help on using the changeset viewer.