Ignore:
Timestamp:
Feb 28, 2006, 5:28:06 AM (18 years ago)
Author:
rvelices
Message:

calendar improvements: week on weekly list starts on Monday,
ability to show grayed months/weeks/days (without any picture in it),
added icons for created/posted fields
language uniformization

calendar fixes: correct number of pictures in calendar view,
code simplification (I hope so)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/calendar_monthly.class.php

    r1057 r1059  
    3737{
    3838
     39  /**
     40   * Initialize the calendar
     41   * @param string date_field db column on which this calendar works
     42   * @param string inner_sql used for queries (INNER JOIN or normal)
     43   * @param array date_components
     44   */
     45  function initialize($date_field, $inner_sql, $date_components)
     46  {
     47    parent::initialize($date_field, $inner_sql, $date_components);
     48    global $lang;
     49    $this->calendar_levels = array(
     50      array(
     51          'sql'=> 'YEAR('.$this->date_field.')',
     52          'labels' => null
     53        ),
     54      array(
     55          'sql'=> 'MONTH('.$this->date_field.')',
     56          'labels' => $lang['month']
     57        ),
     58      array(
     59          'sql'=> 'DAYOFMONTH('.$this->date_field.')',
     60          'labels' => null
     61        ),
     62     );
     63  }
     64
    3965/**
    4066 * Generate navigation bars for category page
     
    4470function generate_category_content($url_base, $view_type)
    4571{
    46   global $lang, $conf;
     72  global $conf;
    4773
    4874  $this->url_base = $url_base;
     
    6086      if ($this->build_year_calendar())
    6187      {
    62         if ( $conf['calendar_multi_bar'] )
    63           $this->build_nav_bar2(CYEAR, 'YEAR'); // years
     88        $this->build_nav_bar(CYEAR); // years
    6489        return true;
    6590      }
     
    6994    {//case C: year+month given - display a nice month calendar
    7095      $this->build_month_calendar();
    71       if ( $conf['calendar_multi_bar'] )
    72       {
    73         $this->build_nav_bar2(CYEAR, 'YEAR'); // years
    74       }
    75       if (count($this->date_components)>=1 and
    76           ( $conf['calendar_multi_bar'] or count($this->date_components)==1 ) )
    77       {
    78         $this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month
    79       }
     96      $this->build_nav_bar(CYEAR); // years
     97      $this->build_nav_bar(CMONTH); // month
    8098      return true;
    8199    }
     
    84102  if ($view_type==CAL_VIEW_LIST or count($this->date_components)==3)
    85103  {
    86     if ( $conf['calendar_multi_bar'] or count($this->date_components)==0 )
    87     {
    88       $this->build_nav_bar2(CYEAR, 'YEAR'); // years
    89     }
    90     if ( count($this->date_components)>=1 and
    91         ( $conf['calendar_multi_bar'] or count($this->date_components)==1 )
    92        )
    93     {
    94       $this->build_nav_bar2(CMONTH, 'MONTH', $lang['month']); // month
     104    if ( count($this->date_components)>=0 )
     105    {
     106      $this->build_nav_bar(CYEAR); // years
     107    }
     108    if ( count($this->date_components)>=1)
     109    {
     110      $this->build_nav_bar(CMONTH); // month
    95111    }
    96112    if ( count($this->date_components)>=2 )
    97113    {
    98       $this->build_nav_bar2(CDAY, 'DAYOFMONTH' ); // days
     114      $this->build_nav_bar(
     115          CDAY,
     116          $this->get_all_days_in_month(
     117              $this->date_components[CYEAR] ,$this->date_components[CMONTH]
     118            )
     119        ); // days
    99120    }
    100121  }
     
    142163      if (isset($date[CMONTH]) and $date[CMONTH]!='any')
    143164      {
    144         $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];
    145       }
    146       if (isset($date[2]) and $date[2]!='any')
    147       {
    148         $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];
     165        $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH];
     166      }
     167      if (isset($date[CDAY]) and $date[CDAY]!='any')
     168      {
     169        $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
    149170      }
    150171    }
     
    156177    if (isset($date[CMONTH]) and $date[CMONTH]!='any')
    157178    {
    158       $res .= ' AND MONTH('.$this->date_field.')='.$date[CMONTH];
     179      $res .= ' AND '.$this->calendar_levels[CMONTH]['sql'].'='.$date[CMONTH];
    159180    }
    160181    if (isset($date[CDAY]) and $date[CDAY]!='any')
    161182    {
    162       $res .= ' AND DAYOFMONTH('.$this->date_field.')='.$date[CDAY];
     183      $res .= ' AND '.$this->calendar_levels[CDAY]['sql'].'='.$date[CDAY];
    163184    }
    164185  }
     
    167188
    168189
    169 function get_display_name()
    170 {
    171   global $conf, $lang;
    172   $res = '';
    173   $url = $this->url_base;
    174   if ( isset($this->date_components[CYEAR]) )
    175   {
    176     $res .= $conf['level_separator'];
    177     $url .= $this->date_components[CYEAR].'-';
    178     $res .=
    179       '<a href="'.$url.'">'
    180       .$this->get_date_component_label($this->date_components[CYEAR])
    181       .'</a>';
    182   }
    183   if ( isset($this->date_components[CMONTH]) )
    184   {
    185     $res .= $conf['level_separator'];
    186     $url .= $this->date_components[CMONTH].'-';
    187     $res .=
    188       '<a href="'.$url.'">'
    189       .$this->get_date_component_label(
    190                      $this->date_components[CMONTH],
    191                      $lang['month']
    192                     )
    193       .'</a>';
    194   }
    195   if ( isset($this->date_components[CDAY]) )
    196   {
    197     $res .= $conf['level_separator'];
    198     $url .= $this->date_components[CDAY].'-';
    199     $res .=
    200       '<a href="'.$url.'">'
    201       .$this->get_date_component_label($this->date_components[CDAY])
    202       .'</a>';
    203   }
    204 
    205   return $res;
    206 }
    207 
    208190
    209191//--------------------------------------------------------- private members ---
    210 function build_nav_bar2($level, $sql_func, $labels=null)
    211 {
    212   parent::build_nav_bar($level, $sql_func, '', $labels);
     192
     193// returns an array with alll the days in a given month
     194function get_all_days_in_month($year, $month)
     195{
     196  $md= array(1=>31,28,31,30,31,30,31,31,30,31,30,31);
     197
     198  if ( is_numeric($year) and $month==2)
     199  {
     200    $nb_days = $md[2];
     201    if ( ($year%4==0)  and ( ($year%100!=0) or ($year%400!=0) ) )
     202    {
     203      $nb_days++;
     204    }
     205  }
     206  elseif ( is_numeric($month) )
     207  {
     208    $nb_days = $md[ $month ];
     209  }
     210  else
     211  {
     212    $nb_days = 31;
     213  }
     214  return range(1, $nb_days);
    213215}
    214216
     
    217219  assert( count($this->date_components) == 0 );
    218220  $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%Y%m")) as period,
    219             COUNT(id) as count';
     221            COUNT( DISTINCT(id) ) as count';
    220222  $query.= $this->inner_sql;
    221223  $query.= $this->get_date_where();
     
    224226
    225227  $result = pwg_query($query);
     228  $items=array();
    226229  while ($row = mysql_fetch_array($result))
    227230  {
     
    253256
    254257    $url_base .= '-';
    255     $nav_bar .= $this->get_nav_bar_from_items( $url_base, 
    256             $year_data['children'], null, 'calCal', false, $lang['month'] );
     258    $nav_bar .= $this->get_nav_bar_from_items( $url_base,
     259            $year_data['children'], null, 'calCal', false, false, $lang['month'] );
    257260
    258261    $template->assign_block_vars( 'calendar.calbar',
     
    267270  assert( count($this->date_components) == 1 );
    268271  $query='SELECT DISTINCT(DATE_FORMAT('.$this->date_field.',"%m%d")) as period,
    269             COUNT(id) as count';
     272            COUNT( DISTINCT(id) ) as count';
    270273  $query.= $this->inner_sql;
    271274  $query.= $this->get_date_where();
     
    274277
    275278  $result = pwg_query($query);
     279  $items=array();
    276280  while ($row = mysql_fetch_array($result))
    277281  {
     
    308312
    309313    $url_base .= '-';
    310     $nav_bar .= $this->get_nav_bar_from_items( $url_base, 
     314    $nav_bar .= $this->get_nav_bar_from_items( $url_base,
    311315                     $month_data['children'], null, 'calCal', false );
    312316
     
    332336  {
    333337    $d = $row['period'];
    334     $items[$d] = $row['count'];
    335   }
    336 
    337   global $lang, $template;
    338 
    339   $template->assign_block_vars('thumbnails', array());
    340   $template->assign_block_vars('thumbnails.line', array());
    341   foreach ( $items as $day=>$nb_images)
    342   {
    343     $url_base = $this->url_base.
    344           $this->date_components[CYEAR].'-'.
    345           $this->date_components[CMONTH].'-'.$day;
     338    $items[$d] = array('nb_images'=>$row['count']);
     339  }
     340
     341  foreach ( $items as $day=>$data)
     342  {
    346343    $this->date_components[CDAY]=$day;
    347344    $query = '
     
    355352
    356353    $row = mysql_fetch_array(pwg_query($query));
    357 
    358     $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    359     $thumbnail_title = $lang['day'][$row['dw']] . ' ' . $day;
    360     $name = $thumbnail_title .' ('.$nb_images.')';
     354    $items[$day]['tn_path'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
     355    $items[$day]['tn_file'] = $row['file'];
     356    $items[$day]['tn_dw'] = $row['dw'];
     357  }
     358
     359  global $lang, $template;
     360  $template->assign_block_vars('thumbnails', array());
     361  $template->assign_block_vars('thumbnails.line', array());
     362  foreach ( $items as $day=>$data)
     363  {
     364    $url_base = $this->url_base.
     365          $this->date_components[CYEAR].'-'.
     366          $this->date_components[CMONTH].'-'.$day;
     367
     368    $thumbnail_title = $lang['day'][$data['tn_dw']] . ' ' . $day;
     369    $name = $thumbnail_title .' ('.$data['nb_images'].')';
    361370
    362371    $template->assign_block_vars(
    363372        'thumbnails.line.thumbnail',
    364373        array(
    365           'IMAGE'=>$thumbnail_src,
    366           'IMAGE_ALT'=>$row['file'],
     374          'IMAGE'=>$data['tn_path'],
     375          'IMAGE_ALT'=>$data['tn_file'],
    367376          'IMAGE_TITLE'=>$thumbnail_title,
    368377          'U_IMG_LINK'=>$url_base
     
    376385        );
    377386  }
     387
    378388  return true;
    379389}
Note: See TracChangeset for help on using the changeset viewer.