Changeset 665


Ignore:
Timestamp:
Dec 30, 2004, 1:55:27 AM (19 years ago)
Author:
plg
Message:
  • admin/update : deletion of useless lines
  • admin/thumbnail : use new process for finding pictures without thumbnails. No more recursivity
  • admin/thumbnail : only show list of directory containing pictures without thumbnails, not the whole directory tree
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/thumbnail.php

    r593 r665  
    216216}
    217217
    218 // get_displayed_dirs builds the tree of dirs under "galleries". If a
    219 // directory contains pictures without thumbnails, the become linked to the
    220 // page of thumbnails creation.
    221 function get_displayed_dirs( $dir, $indent )
    222 {
    223   global $lang;
    224                
    225   $sub_dirs = get_subdirs( $dir );
    226   $output = '';
    227   if (!empty($sub_dirs))
    228   {
    229   $output.='<ul class="menu">';
    230   // write of the dirs
    231   foreach ( $sub_dirs as $sub_dir ) {
    232     $output.='<li>';
    233     $pictures = get_images_without_thumbnail( $dir.'/'.$sub_dir );
    234     if ( count( $pictures ) > 0 )
    235     {
    236           $url = add_session_id(PHPWG_ROOT_PATH.'admin.php?page=thumbnail&amp;dir='.$dir.'/'.$sub_dir);
    237       $output.='<a class="adminMenu" href="'.$url.'">'.$sub_dir.'</a> [ '.count( $pictures ).' ';
    238           $output.=$lang['thumbnail'].' ]';
    239     }
    240     else
    241     {
    242       $output.=$sub_dir;
    243     }
    244     // recursive call
    245     $output.=get_displayed_dirs( $dir.'/'.$sub_dir,
    246                                 $indent+30 );
    247         $output.='</li>';   
    248   }
    249   $output.='</ul>';
    250   }
    251   return $output;
    252 }
    253 
    254218$errors = array();
    255219$pictures = array();
     
    282246  'L_THUMBNAIL_TITLE'=>$lang['tn_dirs_title'],
    283247  'L_UNLINK'=>$lang['tn_dirs_alone'],
     248  'L_MISSING_THUMBNAILS'=>$lang['tn_dirs_alone'],
    284249  'L_RESULTS'=>$lang['tn_results_title'],
    285250  'L_TN_PICTURE'=>$lang['tn_picture'],
     
    319284  }
    320285}
    321 else if ( isset( $_GET['dir'] ) &&  isset( $_POST['submit'] ) && !empty($stats))
     286else if (isset($_GET['dir']) and isset($_POST['submit']) and !empty($stats))
    322287{
    323288  $times = array();
    324   foreach ( $stats as $stat ) {
    325         array_push( $times, $stat['time'] );
     289  foreach ($stats as $stat)
     290  {
     291    array_push( $times, $stat['time'] );
    326292  }
    327293  $sum=array_sum( $times );
     
    331297  $min = array_shift( $times);
    332298 
    333   $template->assign_block_vars('results',array(
    334     'TN_NB'=>count( $stats ),
    335         'TN_TOTAL'=>number_format( $sum, 2, '.', ' ').' ms',
    336         'TN_MAX'=>number_format( $max, 2, '.', ' ').' ms',
    337         'TN_MIN'=>number_format( $min, 2, '.', ' ').' ms',
    338         'TN_AVERAGE'=>number_format( $average, 2, '.', ' ').' ms'
    339         ));
    340   if ( !count( $pictures ) )
     299  $template->assign_block_vars(
     300    'results',
     301    array(
     302      'TN_NB'=>count( $stats ),
     303      'TN_TOTAL'=>number_format( $sum, 2, '.', ' ').' ms',
     304      'TN_MAX'=>number_format( $max, 2, '.', ' ').' ms',
     305      'TN_MIN'=>number_format( $min, 2, '.', ' ').' ms',
     306      'TN_AVERAGE'=>number_format( $average, 2, '.', ' ').' ms'
     307      ));
     308  if (!count($pictures))
    341309  {
    342310    $template->assign_block_vars('warning',array());
    343311  }
    344 
    345   foreach ( $stats as $i => $stat )
    346   {
    347         $class = ($i % 2)? 'row1':'row2';
     312 
     313  foreach ($stats as $i => $stat)
     314  {
     315    $class = ($i % 2)? 'row1':'row2';
    348316    $color='';
    349         if ($stat['time']==$max) $color = 'red';
    350         elseif ($stat['time']==$min) $color = '#33FF00';
    351         $template->assign_block_vars('results.picture',array(
    352           'NB_IMG'=>($i+1),
    353           'FILE_IMG'=>$stat['file'],
    354           'FILESIZE_IMG'=>$stat['size'],
    355           'WIDTH_IMG'=>$stat['width'],
    356           'HEIGHT_IMG'=>$stat['height'],
    357           'TN_FILE_IMG'=>$stat['tn_file'],
    358           'TN_FILESIZE_IMG'=>$stat['tn_size'],
    359           'TN_WIDTH_IMG'=>$stat['tn_width'],
    360           'TN_HEIGHT_IMG'=>$stat['tn_height'],
    361           'GEN_TIME'=>number_format( $stat['time'], 2, '.', ' ').' ms',
    362          
    363           'T_COLOR'=>$color,
    364           'T_CLASS'=>$class
    365           ));
    366     }
    367   }
     317    if ($stat['time'] == $max)
     318    {
     319      $color = 'red';
     320    }
     321    else if ($stat['time'] == $min)
     322    {
     323      $color = '#33FF00';
     324    }
     325   
     326    $template->assign_block_vars(
     327      'results.picture',
     328      array(
     329        'NB_IMG'=>($i+1),
     330        'FILE_IMG'=>$stat['file'],
     331        'FILESIZE_IMG'=>$stat['size'],
     332        'WIDTH_IMG'=>$stat['width'],
     333        'HEIGHT_IMG'=>$stat['height'],
     334        'TN_FILE_IMG'=>$stat['tn_file'],
     335        'TN_FILESIZE_IMG'=>$stat['tn_size'],
     336        'TN_WIDTH_IMG'=>$stat['tn_width'],
     337        'TN_HEIGHT_IMG'=>$stat['tn_height'],
     338        'GEN_TIME'=>number_format( $stat['time'], 2, '.', ' ').' ms',
     339       
     340        'T_COLOR'=>$color,
     341        'T_CLASS'=>$class
     342        ));
     343  }
     344}
    368345//-------------------------------------------------- miniaturization parameters
    369 if ( isset( $_GET['dir'] ) && !sizeof( $pictures ))
    370 {
    371     $form_url = PHPWG_ROOT_PATH.'admin.php?page=thumbnail&amp;dir='.$_GET['dir'];
    372     $gd = !empty( $_POST['gd'] )?$_POST['gd']:2;
    373         $width = !empty( $_POST['width'] )?$_POST['width']:128;
    374         $height = !empty( $_POST['height'] )?$_POST['height']:96;
    375         $gdlabel = 'GD'.$gd.'_CHECKED';
    376 
    377     $template->assign_block_vars('params',array(
    378           'F_ACTION'=>add_session_id($form_url),
    379           $gdlabel=>'checked="checked"',
    380           'WIDTH_TN'=>$width,
    381           'HEIGHT_TN'=>$height
    382           ));
    383 
     346if (isset($_GET['dir']) and !sizeof($pictures))
     347{
     348  $form_url = PHPWG_ROOT_PATH.'admin.php?page=thumbnail&amp;dir='.$_GET['dir'];
     349  $gd = !empty( $_POST['gd'] )?$_POST['gd']:2;
     350  $width = !empty( $_POST['width'] )?$_POST['width']:128;
     351  $height = !empty( $_POST['height'] )?$_POST['height']:96;
     352  $gdlabel = 'GD'.$gd.'_CHECKED';
     353 
     354  $template->assign_block_vars(
     355    'params',
     356    array(
     357      'F_ACTION'=>add_session_id($form_url),
     358      $gdlabel=>'checked="checked"',
     359      'WIDTH_TN'=>$width,
     360      'HEIGHT_TN'=>$height
     361      ));
    384362//---------------------------------------------------------- remaining pictures
    385363  $pictures = get_images_without_thumbnail( $_GET['dir'] );
    386   $template->assign_block_vars('remainings',array('TOTAL_IMG'=>count( $pictures )));
    387 
    388   foreach ( $pictures as $i => $picture )
     364  $template->assign_block_vars(
     365    'remainings',
     366    array('TOTAL_IMG'=>count($pictures)));
     367
     368  foreach ($pictures as $i => $picture)
    389369  {
    390370    $class = ($i % 2)? 'row1':'row2';
    391     $template->assign_block_vars('remainings.remaining',array(
    392           'NB_IMG'=>($i+1),
    393           'FILE_TN'=>$picture['name'],
    394           'FILESIZE_IMG'=>$picture['size'],
    395           'WIDTH_IMG'=>$picture['width'],
    396           'HEIGHT_IMG'=>$picture['height'],
     371    $template->assign_block_vars(
     372      'remainings.remaining',
     373      array(
     374        'NB_IMG'=>($i+1),
     375        'FILE_TN'=>$picture['name'],
     376        'FILESIZE_IMG'=>$picture['size'],
     377        'WIDTH_IMG'=>$picture['width'],
     378        'HEIGHT_IMG'=>$picture['height'],
    397379         
    398           'T_CLASS'=>$class
    399           ));
    400     }
     380        'T_CLASS'=>$class
     381        ));
     382  }
    401383}
    402384//-------------------------------------------------------------- directory list
    403385else
    404386{
    405   $categories = get_displayed_dirs( './galleries', 60 );
    406   $template->assign_block_vars('directory_list',array('CATEGORY_LIST'=>$categories));
    407 }
    408 
     387  $wo_thumbnails = array();
     388 
     389  // what is the directory to search in ?
     390  $query = '
     391SELECT galleries_url
     392  FROM '.SITES_TABLE.'
     393  WHERE id = 1
     394;';
     395  list($galleries_url) = mysql_fetch_array(pwg_query($query));
     396  $basedir = preg_replace('#/*$#', '', $galleries_url);
     397
     398  $fs = get_fs($basedir);
     399  // because isset is one hundred time faster than in_array
     400  $fs['thumbnails'] = array_flip($fs['thumbnails']);
     401
     402  foreach ($fs['elements'] as $path)
     403  {
     404    // only pictures need thumbnails
     405    if (in_array(get_extension($path), $conf['picture_ext']))
     406    {
     407      $dirname = dirname($path);
     408      $filename = basename($path);
     409      // searching the element
     410      $filename_wo_ext = get_filename_wo_extension($filename);
     411      $tn_ext = '';
     412      $base_test = $dirname.'/thumbnail/';
     413      $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.';
     414      foreach ($conf['picture_ext'] as $ext)
     415      {
     416        if (isset($fs['thumbnails'][$base_test.$ext]))
     417        {
     418          $tn_ext = $ext;
     419          break;
     420        }
     421      }
     422     
     423      if (empty($tn_ext))
     424      {
     425        if (!isset($wo_thumbnails[$dirname]))
     426        {
     427          $wo_thumbnails[$dirname] = 1;
     428        }
     429        else
     430        {
     431          $wo_thumbnails[$dirname]++;
     432        }
     433      }
     434    }
     435  }
     436
     437  if (count($wo_thumbnails) > 0)
     438  {
     439    $template->assign_block_vars('directory_list', array());
     440    foreach ($wo_thumbnails as $directory => $nb_missing)
     441    {
     442      $url = PHPWG_ROOT_PATH.'admin.php?page=thumbnail&amp;dir='.$directory;
     443     
     444      $template->assign_block_vars(
     445        'directory_list.directory',
     446        array(
     447          'DIRECTORY'=>$directory,
     448          'URL'=>add_session_id($url),
     449          'NB_MISSING'=>$nb_missing));
     450    }
     451  }
     452}
    409453$template->assign_var_from_handle('ADMIN_CONTENT', 'thumbnail');
    410454?>
  • trunk/admin/update.php

    r660 r665  
    342342        break;
    343343      }
    344       else
    345       {
    346         continue;
    347       }
    348344    }
    349345
     
    387383          $representative_ext = $ext;
    388384          break;
    389         }
    390         else
    391         {
    392           continue;
    393385        }
    394386      }
  • trunk/template/default/admin/thumbnail.tpl

    r393 r665  
    22<div class="admin">{L_THUMBNAIL_TITLE}</div>
    33<ul class="menu">
    4 <li>galleries</li>
    5 {directory_list.CATEGORY_LIST}
     4  <!-- BEGIN directory -->
     5  <li>[<a href="{directory_list.directory.URL}">{directory_list.directory.DIRECTORY}</a>] {directory_list.directory.NB_MISSING} {L_MISSING_THUMBNAILS}</li>
     6  <!-- END directory -->
    67</ul>
    78<!-- END directory_list -->
     
    4546      <div style="text-align:right;margin-right:5px;color:{results.picture.T_COLOR};">{results.picture.GEN_TIME}</div>
    4647    </th>
    47     <td>{results.picture.TN_FILE_IMG}</td>
     48    <td><img src="{results.picture.TN_FILE_IMG}" /></td>
    4849    <td style="text-align:right;">{results.picture.TN_FILESIZE_IMG}</td>
    4950    <td style="text-align:right;">{results.picture.TN_WIDTH_IMG}</td>
Note: See TracChangeset for help on using the changeset viewer.