Ignore:
Timestamp:
Mar 20, 2004, 1:52:37 AM (20 years ago)
Author:
gweltas
Message:
  • Template migration
  • Admin Control Panel migration
  • Language migration
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/thumbnail.php

    r362 r393  
    2525// | USA.                                                                  |
    2626// +-----------------------------------------------------------------------+
    27 include_once( './admin/include/isadmin.inc.php' );
     27include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
    2828//------------------------------------------------------------------- functions
    2929// get_subdirs returns an array containing all sub directory names,
     
    212212}
    213213
    214 // array_max returns the highest value of the given array
    215 function array_max( $array )
    216 {
    217   sort( $array, SORT_NUMERIC );
    218   return array_pop( $array );
    219 }
    220 
    221 // array_min returns the lowest value of the given array
    222 function array_min( $array )
    223 {
    224   sort( $array, SORT_NUMERIC );
    225   return array_shift( $array );
    226 }
    227 
    228 // array_avg returns the average value of the array
    229 function array_avg( $array )
    230 {
    231   return array_sum( $array ) / sizeof( $array );
    232 }
    233        
    234214// get_displayed_dirs builds the tree of dirs under "galleries". If a
    235215// directory contains pictures without thumbnails, the become linked to the
     
    237217function get_displayed_dirs( $dir, $indent )
    238218{
    239   global $conf,$lang,$vtp,$sub;
     219  global $lang;
    240220               
    241221  $sub_dirs = get_subdirs( $dir );
     222  $output = '';
     223  if (!empty($sub_dirs))
     224  {
     225  $output.='<ul class="menu">';
    242226  // write of the dirs
    243227  foreach ( $sub_dirs as $sub_dir ) {
     228    $output.='<li>';
    244229    $pictures = get_images_without_thumbnail( $dir.'/'.$sub_dir );
    245     $vtp->addSession( $sub, 'dir' );
    246     $vtp->setVar( $sub, 'dir.indent', $indent );
    247230    if ( count( $pictures ) > 0 )
    248231    {
    249       $vtp->addSession( $sub, 'linked' );
    250       $url = './admin.php?page=thumbnail&amp;dir='.$dir."/".$sub_dir;
    251       $vtp->setVar( $sub, 'linked.url', add_session_id( $url ) );
    252       $vtp->setVar( $sub, 'linked.name', $sub_dir );
    253       $vtp->setVar( $sub, 'linked.nb_pic', count( $pictures ) );
    254       $vtp->closeSession( $sub, 'linked' );
     232          $url = add_session_id(PHPWG_ROOT_PATH.'admin.php?page=thumbnail&amp;dir='.$dir.'/'.$sub_dir);
     233      $output.='<a class="adminMenu" href="'.$url.'">'.$sub_dir.'</a> [ '.count( $pictures ).' ';
     234          $output.=$lang['thumbnail'].' ]';
    255235    }
    256236    else
    257237    {
    258       $vtp->addSession( $sub, 'unlinked' );
    259       $vtp->setVar( $sub, 'unlinked.name', $sub_dir );
    260       $vtp->closeSession( $sub, 'unlinked' );
    261     }
    262     $vtp->closeSession( $sub, 'dir' );
     238      $output.=$sub_dir;
     239    }
    263240    // recursive call
    264     get_displayed_dirs( $dir.'/'.$sub_dir,
    265                                 $indent+30 );   
    266   }
    267 }
     241    $output.=get_displayed_dirs( $dir.'/'.$sub_dir,
     242                                $indent+30 );
     243        $output.='</li>';   
     244  }
     245  $output.='</ul>';
     246  }
     247  return $output;
     248}
     249
     250$errors = array();
     251$pictures = array();
     252$stats = array();
     253
     254if ( isset( $_GET['dir'] ) &&  isset( $_POST['submit'] ))
     255{
     256  $pictures = get_images_without_thumbnail( $_GET['dir'] );
     257  // checking criteria
     258  if ( !ereg( "^[0-9]{2,3}$", $_POST['width'] ) or $_POST['width'] < 10 )
     259  {
     260    array_push( $errors, $lang['tn_err_width'].' 10' );
     261  }
     262  if ( !ereg( "^[0-9]{2,3}$", $_POST['height'] ) or $_POST['height'] < 10 )
     263  {
     264    array_push( $errors, $lang['tn_err_height'].' 10' );
     265  }
     266 
     267  // picture miniaturization
     268  if ( count( $errors ) == 0 )
     269  {
     270    $stats = scandir( $_GET['dir'], $_POST['width'], $_POST['height'] );
     271  }
     272}
     273               
    268274//----------------------------------------------------- template initialization
    269 $sub = $vtp->Open( './template/'.$user['template'].'/admin/thumbnail.vtp' );
    270 $tpl = array(
    271   'tn_dirs_title','tn_dirs_alone','tn_params_title','tn_params_GD',
    272   'tn_params_GD_info','tn_width','tn_params_width_info','tn_height',
    273   'tn_params_height_info','tn_params_create','tn_params_create_info',
    274   'tn_params_format','tn_params_format_info','submit','tn_alone_title',
    275   'filesize','tn_picture','tn_results_title','thumbnail',
    276   'tn_results_gen_time','tn_stats','tn_stats_nb','tn_stats_total',
    277   'tn_stats_max','tn_stats_min','tn_stats_mean' );
    278 templatize_array( $tpl, 'lang', $sub );
    279 $vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
     275$template->set_filenames( array('thumbnail'=>'admin/thumbnail.tpl') );
     276
     277$template->assign_vars(array(
     278  'L_THUMBNAIL_TITLE'=>$lang['tn_dirs_title'],
     279  'L_UNLINK'=>$lang['tn_dirs_alone'],
     280  'L_RESULTS'=>$lang['tn_results_title'],
     281  'L_TN_PICTURE'=>$lang['tn_picture'],
     282  'L_FILESIZE'=>$lang['filesize'],
     283  'L_WIDTH'=>$lang['tn_width'],
     284  'L_HEIGHT'=>$lang['tn_height'],
     285  'L_GENERATED'=>$lang['tn_results_gen_time'],
     286  'L_THUMBNAIL'=>$lang['thumbnail'],
     287  'L_PARAMS'=>$lang['tn_params_title'],
     288  'L_GD'=>$lang['tn_params_GD'],
     289  'L_GD_INFO'=>$lang['tn_params_GD_info'],
     290  'L_WIDTH_INFO'=>$lang['tn_params_width_info'],
     291  'L_HEIGHT_INFO'=>$lang['tn_params_height_info'],
     292  'L_CREATE'=>$lang['tn_params_create'],
     293  'L_CREATE_INFO'=>$lang['tn_params_create_info'],
     294  'L_FORMAT'=>$lang['tn_params_format'],
     295  'L_FORMAT_INFO'=>$lang['tn_params_format_info'],
     296  'L_SUBMIT'=>$lang['submit'],
     297  'L_REMAINING'=>$lang['tn_alone_title'],
     298  'L_TN_STATS'=>$lang['tn_stats'],
     299  'L_TN_NB_STATS'=>$lang['tn_stats_nb'],
     300  'L_TN_TOTAL'=>$lang['tn_stats_total'],
     301  'L_TN_MAX'=>$lang['tn_stats_max'],
     302  'L_TN_MIN'=>$lang['tn_stats_min'],
     303  'L_TN_AVERAGE'=>$lang['tn_stats_mean'],
     304 
     305  'T_STYLE'=>$user['template']
     306  ));
     307
    280308//----------------------------------------------------- miniaturization results
    281 if ( isset( $_GET['dir'] ) )
    282 {
     309if ( sizeof( $errors ) != 0 )
     310{
     311  $template->assign_block_vars('errors',array());
     312  for ( $i = 0; $i < sizeof( $errors ); $i++ )
     313  {
     314    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
     315  }
     316}
     317else if ( isset( $_GET['dir'] ) &&  isset( $_POST['submit'] ) && !empty($stats))
     318{
     319  $times = array();
     320  foreach ( $stats as $stat ) {
     321        array_push( $times, $stat['time'] );
     322  }
     323  $sum=array_sum( $times );
     324  $average = $sum/sizeof($times);
     325  sort( $times, SORT_NUMERIC );
     326  $max = array_pop($times);
     327  $min = array_shift( $times);
     328 
     329  $template->assign_block_vars('results',array(
     330    'TN_NB'=>count( $stats ),
     331        'TN_TOTAL'=>number_format( $sum, 2, '.', ' ').' ms',
     332        'TN_MAX'=>number_format( $max, 2, '.', ' ').' ms',
     333        'TN_MIN'=>number_format( $min, 2, '.', ' ').' ms',
     334        'TN_AVERAGE'=>number_format( $average, 2, '.', ' ').' ms'
     335        ));
     336  if ( !count( $pictures ) )
     337  {
     338    $template->assign_block_vars('warning',array());
     339  }
     340
     341  foreach ( $stats as $i => $stat )
     342  {
     343        $class = ($i % 2)? 'row1':'row2';
     344    $color='';
     345        if ($stat['time']==$max) $color = 'red';
     346        elseif ($stat['time']==$min) $color = '#33FF00';
     347        $template->assign_block_vars('results.picture',array(
     348          'NB_IMG'=>($i+1),
     349          'FILE_IMG'=>$stat['file'],
     350          'FILESIZE_IMG'=>$stat['size'],
     351          'WIDTH_IMG'=>$stat['width'],
     352          'HEIGHT_IMG'=>$stat['height'],
     353          'TN_FILE_IMG'=>$stat['tn_file'],
     354          'TN_FILESIZE_IMG'=>$stat['tn_size'],
     355          'TN_WIDTH_IMG'=>$stat['tn_width'],
     356          'TN_HEIGHT_IMG'=>$stat['tn_height'],
     357          'GEN_TIME'=>number_format( $stat['time'], 2, '.', ' ').' ms',
     358         
     359          'T_COLOR'=>$color,
     360          'T_CLASS'=>$class
     361          ));
     362    }
     363  }
     364//-------------------------------------------------- miniaturization parameters
     365if ( isset( $_GET['dir'] ) && !sizeof( $pictures ))
     366{
     367    $form_url = PHPWG_ROOT_PATH.'admin.php?page=thumbnail&amp;dir='.$_GET['dir'];
     368    $gd = !empty( $_POST['gd'] )?$_POST['gd']:2;
     369        $width = !empty( $_POST['width'] )?$_POST['width']:128;
     370        $height = !empty( $_POST['height'] )?$_POST['height']:96;
     371        $gdlabel = 'GD'.$gd.'_CHECKED';
     372
     373    $template->assign_block_vars('params',array(
     374          'F_ACTION'=>add_session_id($form_url),
     375          $gdlabel=>'checked="checked"',
     376          'WIDTH_TN'=>$width,
     377          'HEIGHT_TN'=>$height
     378          ));
     379
     380//---------------------------------------------------------- remaining pictures
    283381  $pictures = get_images_without_thumbnail( $_GET['dir'] );
    284   if ( count( $pictures ) == 0 )
    285   {
    286     $vtp->addSession( $sub, 'warning' );
    287     $vtp->closeSession( $sub, 'warning' );
    288   }
    289   elseif ( isset( $_POST['submit'] ) )
    290   {
    291     // checking criteria
    292     $errors = array();
    293     if ( !ereg( "^[0-9]{2,3}$", $_POST['width'] ) or $_POST['width'] < 10 )
    294     {
    295       array_push( $errors, $lang['tn_err_width'].' 10' );
    296     }
    297     if ( !ereg( "^[0-9]{2,3}$", $_POST['height'] ) or $_POST['height'] < 10 )
    298     {
    299       array_push( $errors, $lang['tn_err_height'].' 10' );
    300     }
    301     // picture miniaturization
    302     if ( count( $errors ) == 0 )
    303     {
    304       $vtp->addSession( $sub, 'results' );
    305       $stats = scandir( $_GET['dir'], $_POST['width'], $_POST['height'] );
    306       $times = array();
    307       foreach ( $stats as $stat ) {
    308         array_push( $times, $stat['time'] );
    309       }
    310       $max = array_max( $times );
    311       $min = array_min( $times );
    312       foreach ( $stats as $i => $stat ) {
    313         $vtp->addSession( $sub, 'picture' );
    314         if ( $i % 2 == 1 )
    315         {
    316           $vtp->setVar( $sub, 'picture.class', 'row2' );
    317         }
    318         $vtp->setVar( $sub, 'picture.num',            ($i+1) );
    319         $vtp->setVar( $sub, 'picture.file',           $stat['file'] );
    320         $vtp->setVar( $sub, 'picture.filesize',       $stat['size'] );
    321         $vtp->setVar( $sub, 'picture.width',          $stat['width'] );
    322         $vtp->setVar( $sub, 'picture.height',         $stat['height'] );
    323         $vtp->setVar( $sub, 'picture.thumb_file',     $stat['tn_file'] );
    324         $vtp->setVar( $sub, 'picture.thumb_filesize', $stat['tn_size'] );
    325         $vtp->setVar( $sub, 'picture.thumb_width',    $stat['tn_width'] );
    326         $vtp->setVar( $sub, 'picture.thumb_height',   $stat['tn_height'] );
    327         $vtp->setVar( $sub, 'picture.time',
    328                       number_format( $stat['time'], 2, '.', ' ').' ms' );
    329         if ( $stat['time'] == $max )
    330         {
    331           $vtp->setVar( $sub, 'picture.color', 'red' );
    332         }
    333         else if ( $stat['time'] == $min )
    334         {
    335           $vtp->setVar( $sub, 'picture.color', 'green' );
    336         }
    337         $vtp->closeSession( $sub, 'picture' );
    338       }
    339       // general statistics
    340       $vtp->setVar( $sub, 'results.stats_nb', count( $stats ) );
    341       $vtp->setVar( $sub, 'results.stats_total',
    342                     number_format( array_sum( $times ), 2, '.', ' ').' ms' );
    343       $vtp->setVar( $sub, 'results.stats_max',
    344                     number_format( $max, 2, '.', ' ').' ms' );
    345       $vtp->setVar( $sub, 'results.stats_min',
    346                     number_format( $min, 2, '.', ' ').' ms' );
    347       $vtp->setVar( $sub, 'results.stats_mean',
    348                     number_format( array_avg( $times ), 2, '.', ' ').' ms' );
    349       $vtp->closeSession( $sub, 'results' );
    350     }
    351     else
    352     {
    353       $vtp->addSession( $sub, 'errors' );
    354       foreach ( $errors as $error ) {
    355         $vtp->addSession( $sub, 'li' );
    356         $vtp->setVar( $sub, 'li.li', $error );
    357         $vtp->closeSession( $sub, 'li' );
    358       }
    359       $vtp->closeSession( $sub, 'errors' );
    360     }
    361   }
    362 //-------------------------------------------------- miniaturization parameters
    363   if ( sizeof( $pictures ) != 0 )
    364   {
    365     $vtp->addSession( $sub, 'params' );
    366     $url = './admin.php?page=thumbnail&amp;dir='.$_GET['dir'];
    367     $vtp->setVar( $sub, 'params.action', add_session_id( $url ) );
    368     // GD version selected...
    369     if ( isset( $_POST['gd'] ) and $_POST['gd'] == 1 )
    370     {
    371       $vtp->setVar( $sub, 'params.gd1_checked', ' checked="checked"' );
    372     }
    373     else
    374     {
    375       $vtp->setVar( $sub, 'params.gd2_checked', ' checked="checked"' );
    376     }
    377     // width values
    378     if ( isset( $_POST['width'] ) )
    379     {
    380       $vtp->setVar( $sub, 'params.width_value', $_POST['width'] );
    381     }
    382     else
    383     {
    384       $vtp->setVar( $sub, 'params.width_value', '128' );
    385     }
    386     // height value
    387     if ( isset( $_POST['height'] ) )
    388     {
    389       $vtp->setVar( $sub, 'params.height_value', $_POST['height'] );
    390     }
    391     else
    392     {
    393       $vtp->setVar( $sub, 'params.height_value', '96' );
    394     }
    395     // options for the number of picture to miniaturize : "n"
    396     $options = array( 5,10,20,40 );
    397     if ( isset( $_POST['n'] ) ) $n = $_POST['n'];
    398     else                        $n = 5;
    399     foreach ( $options as $option ) {
    400       $vtp->addSession( $sub, 'n_option' );
    401       $vtp->setVar( $sub, 'n_option.option', $option );
    402       if ( $option == $n )
    403       {
    404         $vtp->setVar( $sub, 'n_option.selected', ' selected="selected"' );
    405       }
    406       $vtp->closeSession( $sub, 'n_option' );
    407     }
    408     $vtp->closeSession( $sub, 'params' );
    409 //---------------------------------------------------------- remaining pictures
    410     $vtp->addSession( $sub, 'remainings' );
    411     $pictures = get_images_without_thumbnail( $_GET['dir'] );
    412     $vtp->setVar( $sub, 'remainings.total', count( $pictures ) );
    413     foreach ( $pictures as $i => $picture ) {
    414       $vtp->addSession( $sub, 'remaining' );
    415       if ( $i % 2 == 1 )
    416       {
    417         $vtp->setVar( $sub, 'remaining.class', 'row2' );
    418       }
    419       $vtp->setVar( $sub, 'remaining.num',      ($i+1) );
    420       $vtp->setVar( $sub, 'remaining.file',     $picture['name'] );
    421       $vtp->setVar( $sub, 'remaining.filesize', $picture['size'] );
    422       $vtp->setVar( $sub, 'remaining.width',    $picture['width'] );
    423       $vtp->setVar( $sub, 'remaining.height',   $picture['height'] );
    424       $vtp->closeSession( $sub, 'remaining' );
    425     }
    426     $vtp->closeSession( $sub, 'remainings' );
    427   }
     382  $template->assign_block_vars('remainings',array('TOTAL_IMG'=>count( $pictures )));
     383
     384  foreach ( $pictures as $i => $picture )
     385  {
     386    $class = ($i % 2)? 'row1':'row2';
     387    $template->assign_block_vars('remainings.remaining',array(
     388          'NB_IMG'=>($i+1),
     389          'FILE_TN'=>$picture['name'],
     390          'FILESIZE_IMG'=>$picture['size'],
     391          'WIDTH_IMG'=>$picture['width'],
     392          'HEIGHT_IMG'=>$picture['height'],
     393         
     394          'T_CLASS'=>$class
     395          ));
     396    }
    428397}
    429398//-------------------------------------------------------------- directory list
    430399else
    431400{
    432   $vtp->addSession( $sub, 'directory_list' );
    433   get_displayed_dirs( './galleries', 60 );
    434   $vtp->closeSession( $sub, 'directory_list' );
    435 }
    436 //----------------------------------------------------------- sending html code
    437 $vtp->Parse( $handle , 'sub', $sub );
     401  $categories = get_displayed_dirs( './galleries', 60 );
     402  $template->assign_block_vars('directory_list',array('CATEGORY_LIST'=>$categories));
     403}
     404
     405$template->assign_var_from_handle('ADMIN_CONTENT', 'thumbnail');
    438406?>
Note: See TracChangeset for help on using the changeset viewer.