Ignore:
Timestamp:
Mar 1, 2008, 2:12:07 PM (16 years ago)
Author:
rvelices
Message:
  • index.tpl, menubar.tpl, mainpage_categories.tpl and month_calendar.tpl go smarty
  • better template debugging tweak (the smarty console is shown only once at the end)
File:
1 edited

Legend:

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

    r2101 r2231  
    7272  if ($view_type==CAL_VIEW_CALENDAR)
    7373  {
     74    global $template;
     75    $tpl_var = array();
    7476    if ( count($page['chronology_date'])==0 )
    7577    {//case A: no year given - display all years+months
    76       if ($this->build_global_calendar())
     78      if ($this->build_global_calendar($tpl_var))
     79      {
     80        $template->assign('chronology_calendar', $tpl_var);
    7781        return true;
     82      }
    7883    }
    7984
    8085    if ( count($page['chronology_date'])==1 )
    8186    {//case B: year given - display all days in given year
    82       if ($this->build_year_calendar())
    83       {
     87      if ($this->build_year_calendar($tpl_var))
     88      {
     89        $template->assign('chronology_calendar', $tpl_var);
    8490        $this->build_nav_bar(CYEAR); // years
    8591        return true;
     
    8995    if ( count($page['chronology_date'])==2 )
    9096    {//case C: year+month given - display a nice month calendar
    91       $this->build_month_calendar();
    92       //$this->build_nav_bar(CYEAR); // years
    93       //$this->build_nav_bar(CMONTH); // month
     97      if ( $this->build_month_calendar($tpl_var) )
     98      {
     99        $template->assign('chronology_calendar', $tpl_var);
     100      }
    94101      $this->build_next_prev();
    95102      return true;
     
    99106  if ($view_type==CAL_VIEW_LIST or count($page['chronology_date'])==3)
    100107  {
    101     $has_nav_bar = false;
    102108    if ( count($page['chronology_date'])==0 )
    103109    {
     
    214220}
    215221
    216 function build_global_calendar()
     222function build_global_calendar(&$tpl_var)
    217223{
    218224  global $page;
     
    247253  }
    248254
    249   global $lang, $template;
     255  global $lang;
    250256  foreach ( $items as $year=>$year_data)
    251257  {
     
    253259    $url = duplicate_index_url( array('chronology_date'=>$chronology_date) );
    254260
    255     $nav_bar = '<span class="calCalHead"><a href="'.$url.'">'.$year.'</a>';
    256     $nav_bar .= ' ('.$year_data['nb_images'].')';
    257     $nav_bar .= '</span><br>';
    258 
    259     $nav_bar .= $this->get_nav_bar_from_items( $chronology_date,
     261    $nav_bar = $this->get_nav_bar_from_items( $chronology_date,
    260262            $year_data['children'], 'calCal', false, false, $lang['month'] );
    261263
    262     $template->assign_block_vars( 'calendar.calbar',
    263          array( 'BAR' => $nav_bar)
    264          );
     264    $tpl_var['calendar_bars'][] =
     265      array(
     266        'U_HEAD'  => $url,
     267        'NB_IMAGES' => $year_data['nb_images'],
     268        'HEAD_LABEL' => $year,
     269        'NAV_BAR' => $nav_bar,
     270      );
    265271  }
    266272  return true;
    267273}
    268274
    269 function build_year_calendar()
     275function build_year_calendar(&$tpl_var)
    270276{
    271277  global $page;
     
    297303    return false;
    298304  }
    299   global $lang, $template;
     305  global $lang;
    300306  foreach ( $items as $month=>$month_data)
    301307  {
     
    303309    $url = duplicate_index_url( array('chronology_date'=>$chronology_date) );
    304310
    305     $nav_bar = '<span class="calCalHead"><a href="'.$url.'">';
    306     $nav_bar .= $lang['month'][$month].'</a>';
    307     $nav_bar .= ' ('.$month_data['nb_images'].')';
    308     $nav_bar .= '</span><br>';
    309 
    310     $nav_bar .= $this->get_nav_bar_from_items( $chronology_date,
     311    $nav_bar = $this->get_nav_bar_from_items( $chronology_date,
    311312                     $month_data['children'], 'calCal', false );
    312313
    313     $template->assign_block_vars( 'calendar.calbar',
    314          array( 'BAR' => $nav_bar)
    315          );
     314    $tpl_var['calendar_bars'][] =
     315      array(
     316        'U_HEAD'  => $url,
     317        'NB_IMAGES' => $month_data['nb_images'],
     318        'HEAD_LABEL' => $lang['month'][$month],
     319        'NAV_BAR' => $nav_bar,
     320      );
    316321  }
    317322  return true;
     
    319324}
    320325
    321 function build_month_calendar()
     326function build_month_calendar(&$tpl_var)
    322327{
    323328  global $page;
     
    359364  }
    360365
    361   global $lang, $template, $conf;
     366  global $lang, $conf;
    362367
    363368  if ( !empty($items)
     
    390395    $cell_height = $conf['calendar_month_cell_height'];
    391396
    392     $template->set_filenames(
    393       array(
    394         'month_calendar'=>'month_calendar.tpl',
    395         )
    396       );
    397 
    398     $template->assign_block_vars('calendar.thumbnails',
    399         array(
    400            'WIDTH'=>$cell_width,
    401            'HEIGHT'=>$cell_height,
    402           )
    403       );
    404 
    405     //fill the heading with day names
    406     $template->assign_block_vars('calendar.thumbnails.head', array());
    407     foreach( $wday_labels as $d => $label)
    408     {
    409       $template->assign_block_vars('calendar.thumbnails.head.col',
    410                     array('LABEL'=>$label)
    411                   );
    412     }
    413 
    414     $template->assign_block_vars('calendar.thumbnails.row', array());
     397    $tpl_weeks    = array();
     398    $tpl_crt_week = array();
    415399
    416400    //fill the empty days in the week before first day of this month
    417401    for ($i=0; $i<$first_day_dow; $i++)
    418402    {
    419       $template->assign_block_vars('calendar.thumbnails.row.col', array());
    420       $template->assign_block_vars('calendar.thumbnails.row.col.blank', array());
    421     }
     403      $tpl_crt_week[] = array();
     404    }
     405
    422406    for ( $day = 1;
    423407          $day <= $this->get_all_days_in_month(
     
    429413      if ($dow==0 and $day!=1)
    430414      {
    431         $template->assign_block_vars('calendar.thumbnails.row', array());
    432       }
    433       $template->assign_block_vars('calendar.thumbnails.row.col', array());
     415        $tpl_weeks[]    = $tpl_crt_week; // add finished week to week list
     416        $tpl_crt_week   = array(); // start new week
     417      }
     418
    434419      if ( !isset($items[$day]) )
    435       {
    436         $template->assign_block_vars('calendar.thumbnails.row.col.empty',
    437               array('LABEL'=>$day));
     420      {// empty day
     421        $tpl_crt_week[]   =
     422          array(
     423              'DAY' => $day
     424            );
    438425      }
    439426      else
    440427      {
    441 /*        // first try to guess thumbnail size
    442         if ( !empty($items[$day]['width']) )
    443         {
    444           $tn_size = get_picture_size(
    445                  $items[$day]['width'], $items[$day]['height'],
    446                  $conf['tn_width'], $conf['tn_height'] );
    447         }
    448         else*/
    449         {// item not an image (tn is either mime type or an image)
    450           $thumb = get_thumbnail_path($items[$day]);
    451           $tn_size = @getimagesize($thumb);
    452         }
     428        $thumb = get_thumbnail_path($items[$day]);
     429        $tn_size = @getimagesize($thumb);
     430
    453431        $tn_width = $tn_size[0];
    454432        $tn_height = $tn_size[1];
     
    460438        $ratio_h = $tn_height/$cell_height;
    461439
    462 
    463440        $pos_top=$pos_left=0;
    464         $img_width=$img_height='';
     441        $css_style = '';
     442
    465443        if ( $ratio_w>1 and $ratio_h>1)
    466444        {// cell completely smaller than the thumbnail so we will let the browser
     
    468446          if ($ratio_w > $ratio_h )
    469447          {// thumbnail ratio compared to cell -> wide format
    470             $img_height = 'height="'.$cell_height.'"';
     448            $css_style = 'height:'.$cell_height.'px;';
    471449            $browser_img_width = $cell_height*$tn_width/$tn_height;
    472450            $pos_left = ($browser_img_width-$cell_width)/2;
     
    474452          else
    475453          {
    476             $img_width = 'width="'.$cell_width.'"';
     454            $css_style = 'width:'.$cell_width.'px;';
    477455            $browser_img_height = $cell_width*$tn_height/$tn_width;
    478456            $pos_top = ($browser_img_height-$cell_height)/2;
     
    485463        }
    486464
    487         $css_style = '';
    488465        if ( round($pos_left)!=0)
    489466        {
     
    506483        $alt = $wday_labels[$dow] . ' ' . $day.
    507484               ' ('.sprintf("%d ".l10n('pictures'), $items[$day]['nb_images']).')';
    508         $template->assign_block_vars('calendar.thumbnails.row.col.full',
    509               array(
    510                 'LABEL'     => $day,
    511                 'IMAGE'     => $items[$day]['tn_url'],
    512                 'U_IMG_LINK'=> $url,
    513                 'STYLE'     => $css_style,
    514                 'IMG_WIDTH' => $img_width,
    515                 'IMG_HEIGHT'=> $img_height,
    516                 'IMAGE_ALT' => $alt,
    517               )
     485
     486        $tpl_crt_week[]   =
     487          array(
     488              'DAY' => $day,
     489              'IMAGE'     => $items[$day]['tn_url'],
     490              'U_IMG_LINK'=> $url,
     491              'IMAGE_STYLE'     => $css_style,
     492              'IMAGE_ALT' => $alt,
    518493            );
    519494      }
     
    522497    while ( $dow<6 )
    523498    {
    524       $template->assign_block_vars('calendar.thumbnails.row.col', array());
    525       $template->assign_block_vars('calendar.thumbnails.row.col.blank', array());
     499      $tpl_crt_week[] = array();
    526500      $dow++;
    527501    }
    528     $template->assign_var_from_handle('MONTH_CALENDAR', 'month_calendar');
    529   }
    530   else
    531   {
    532     $template->assign_block_vars('thumbnails', array());
    533     $template->assign_block_vars('thumbnails.line', array());
    534     foreach ( $items as $day=>$data)
    535     {
    536       $url = duplicate_index_url(
    537           array(
    538             'chronology_date' =>
    539               array(
    540                 $page['chronology_date'][CYEAR],
    541                 $page['chronology_date'][CMONTH],
    542                 $day
    543               )
    544           )
    545         );
    546 
    547       $thumbnail_title = $lang['day'][$data['dow']] . ' ' . $day;
    548       $name = $thumbnail_title .' ('.$data['nb_images'].')';
    549 
    550       $template->assign_block_vars(
    551           'thumbnails.line.thumbnail',
    552           array(
    553             'IMAGE'=>$data['tn_url'],
    554             'IMAGE_ALT'=>$data['file'],
    555             'IMAGE_TITLE'=>$thumbnail_title,
    556             'U_IMG_LINK'=>$url
    557            )
     502    $tpl_weeks[]    = $tpl_crt_week;
     503
     504    $tpl_var['month_view'] =
     505        array(
     506           'CELL_WIDTH'   => $cell_width,
     507           'CELL_HEIGHT' => $cell_height,
     508           'wday_labels' => $wday_labels,
     509           'weeks' => $tpl_weeks,
    558510          );
    559       $template->assign_block_vars(
    560           'thumbnails.line.thumbnail.category_name',
    561           array(
    562             'NAME' => $name
    563             )
    564           );
    565     }
    566511  }
    567512
Note: See TracChangeset for help on using the changeset viewer.