Changeset 26


Ignore:
Timestamp:
Jul 21, 2003, 9:47:14 PM (21 years ago)
Author:
z0rglub
Message:

* empty log message *

Location:
trunk
Files:
2 added
5 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/admin.php

    r21 r26  
    2222$handle = $vtp->Open( '../template/'.$user['template'].'/admin/admin.vtp' );
    2323// language
    24 $vtp->setGlobalVar( $handle, 'page_title',  $lang['title_default'] );
    25 $vtp->setGlobalVar( $handle, 'menu_title',  $lang['menu_title'] );
     24$tpl = array( 'menu_title', 'title_default', 'charset' );
     25templatize_array( $tpl, 'lang', $handle );
    2626//--------------------------------------- validating page and creation of title
    2727$page_valide = false;
     
    7676   }
    7777   break;
    78  case 'historique':
     78 case 'stats':
    7979   $title = $lang['title_history'];       $page_valide = true; break;
    8080 case 'update':
     
    8282 case 'configuration':
    8383   $title = $lang['title_configuration']; $page_valide = true; break;
    84  case 'manuel':
     84 case 'help':
    8585   $title = $lang['title_instructions'];  $page_valide = true; break;
    8686 case 'cat_perm':
     
    125125   $page_valide = true;
    126126   break;
     127 case 'comments' :
     128   $title = $lang['title_comments'];
     129   $page_valide = true;
     130   break;
    127131 default:
    128132   $title = $lang['title_default']; break;
     
    178182$vtp->setVar( $handle, 'summary.link',
    179183              add_session_id( $link_start.'waiting' ) );
    180 $query = 'select id from '.PREFIX_TABLE.'waiting;';
     184$query = 'SELECT id';
     185$query.= ' FROM '.PREFIX_TABLE.'waiting';
     186$query.= " WHERE validated='false'";
     187$query.= ';';
    181188$result = mysql_query( $query );
    182189$nb_waiting = '';
     
    187194$vtp->setVar( $handle, 'summary.name', $lang['menu_waiting'].$nb_waiting );
    188195$vtp->closeSession( $handle, 'summary' );
     196// comments
     197$vtp->addSession( $handle, 'summary' );
     198$vtp->setVar( $handle, 'summary.indent', '' );
     199$vtp->setVar( $handle, 'summary.link',
     200              add_session_id( $link_start.'comments' ) );
     201$query = 'SELECT id';
     202$query.= ' FROM '.PREFIX_TABLE.'comments';
     203$query.= " WHERE validated='false'";
     204$query.= ';';
     205$result = mysql_query( $query );
     206$nb_waiting = '';
     207if ( mysql_num_rows( $result ) > 0 )
     208{
     209  $nb_waiting =  ' [ '.mysql_num_rows( $result ).' ]';
     210}
     211$vtp->setVar( $handle, 'summary.name', $lang['menu_comments'].$nb_waiting );
     212$vtp->closeSession( $handle, 'summary' );
    189213// update
    190214$vtp->addSession( $handle, 'summary' );
     
    205229$vtp->setVar( $handle, 'summary.indent', '' );
    206230$vtp->setVar( $handle, 'summary.link',
    207               add_session_id( $link_start.'historique' ) );
     231              add_session_id( $link_start.'stats' ) );
    208232$vtp->setVar( $handle, 'summary.name', $lang['menu_history'] );
    209233$vtp->closeSession( $handle, 'summary' );
     
    212236$vtp->setVar( $handle, 'summary.indent', '' );
    213237$vtp->setVar( $handle, 'summary.link',
    214               add_session_id( $link_start.'manuel' ) );
     238              add_session_id( $link_start.'help' ) );
    215239$vtp->setVar( $handle, 'summary.name', $lang['menu_instructions'] );
    216240$vtp->closeSession( $handle, 'summary' );
  • trunk/admin/configuration.php

    r21 r26  
    4141       'show_comments','nb_comment_page','upload_available',
    4242       'upload_maxfilesize', 'upload_maxwidth','upload_maxheight',
    43        'upload_maxwidth_thumbnail','upload_maxheight_thumbnail' );
     43       'upload_maxwidth_thumbnail','upload_maxheight_thumbnail','log',
     44       'comments_validation' );
    4445$default_user_infos =
    45 array( 'nb_image_line','nb_line_page','theme','language','maxwidth',
     46array( 'nb_image_line','nb_line_page','language','maxwidth',
    4647       'maxheight','expand','show_nb_comments','short_period','long_period',
    4748       'template' );
     
    7475    array_push( $error, $lang['conf_err_prefixe'] );
    7576  }
    76   // mail mail must be formatted as follows : name@server.com
     77  // mail must be formatted as follows : name@server.com
    7778  $pattern = '/^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/';
    7879  if ( !preg_match( $pattern, $_POST['mail_webmaster'] ) )
     
    195196    mysql_query( $query );
    196197
    197     $tab_theme = explode( ' - ', $_POST['theme'] );
    198     $_POST['theme'] = $tab_theme[0].'/'.$tab_theme[1];
    199 
    200198    $query = 'UPDATE '.PREFIX_TABLE.'users';
    201199    $query.= ' SET';
     
    372370$vtp->closeSession( $sub, 'param_line' );
    373371$vtp->closeSession( $sub, 'line' );
     372// activate log
     373$vtp->addSession( $sub, 'line' );
     374$vtp->addSession( $sub, 'param_line' );
     375$vtp->setVar( $sub, 'param_line.name', $lang['conf_general_log'] );
     376$vtp->addSession( $sub, 'group' );
     377$vtp->addSession( $sub, 'radio' );
     378$vtp->setVar( $sub, 'radio.name', 'log' );
     379$vtp->setVar( $sub, 'radio.value', 'true' );
     380$vtp->setVar( $sub, 'radio.option', $lang['yes'] );
     381$checked = '';
     382if ( $log == 'true' )
     383{
     384  $checked = ' checked="checked"';
     385}
     386$vtp->setVar( $sub, 'radio.checked', $checked );
     387$vtp->closeSession( $sub, 'radio' );
     388$vtp->addSession( $sub, 'radio' );
     389$vtp->setVar( $sub, 'radio.name', 'log' );
     390$vtp->setVar( $sub, 'radio.value', 'false' );
     391$vtp->setVar( $sub, 'radio.option', $lang['no'] );
     392$checked = '';
     393if ( $log == 'false' )
     394{
     395  $checked = ' checked="checked"';
     396}
     397$vtp->setVar( $sub, 'radio.checked', $checked );
     398$vtp->closeSession( $sub, 'radio' );
     399$vtp->closeSession( $sub, 'group' );
     400$vtp->setVar( $sub, 'param_line.def',
     401              $lang['conf_general_log_info'] );
     402$vtp->closeSession( $sub, 'param_line' );
     403$vtp->closeSession( $sub, 'line' );
    374404
    375405$vtp->addSession( $sub, 'line' );
     
    431461$vtp->setVar( $sub, 'param_line.def',
    432462              $lang['conf_comments_comments_number_info'] );
     463$vtp->closeSession( $sub, 'param_line' );
     464$vtp->closeSession( $sub, 'line' );
     465// coments validation
     466$vtp->addSession( $sub, 'line' );
     467$vtp->addSession( $sub, 'param_line' );
     468$vtp->setVar( $sub, 'param_line.name', $lang['conf_comments_validation'] );
     469$vtp->addSession( $sub, 'group' );
     470$vtp->addSession( $sub, 'radio' );
     471$vtp->setVar( $sub, 'radio.name', 'comments_validation' );
     472$vtp->setVar( $sub, 'radio.value', 'true' );
     473$vtp->setVar( $sub, 'radio.option', $lang['yes'] );
     474$checked = '';
     475if ( $comments_validation == 'true' )
     476{
     477  $checked = ' checked="checked"';
     478}
     479$vtp->setVar( $sub, 'radio.checked', $checked );
     480$vtp->closeSession( $sub, 'radio' );
     481$vtp->addSession( $sub, 'radio' );
     482$vtp->setVar( $sub, 'radio.name', 'comments_validation' );
     483$vtp->setVar( $sub, 'radio.value', 'false' );
     484$vtp->setVar( $sub, 'radio.option', $lang['no'] );
     485$checked = '';
     486if ( $comments_validation == 'false' )
     487{
     488  $checked = ' checked="checked"';
     489}
     490$vtp->setVar( $sub, 'radio.checked', $checked );
     491$vtp->closeSession( $sub, 'radio' );
     492$vtp->closeSession( $sub, 'group' );
     493$vtp->setVar( $sub, 'param_line.def',
     494              $lang['conf_comments_validation_info'] );
    433495$vtp->closeSession( $sub, 'param_line' );
    434496$vtp->closeSession( $sub, 'line' );
     
    515577$vtp->addSession( $sub, 'line' );
    516578$vtp->addSession( $sub, 'param_line' );
    517 $vtp->setVar( $sub, 'param_line.name', $lang['customize_template'] );
     579$vtp->setVar( $sub, 'param_line.name', $lang['customize_theme'] );
    518580$vtp->addSession( $sub, 'select' );
    519581$vtp->setVar( $sub, 'select.name', 'template' );
     
    524586  $vtp->setVar( $sub, 'option.option', $option[$i] );
    525587  if ( $option[$i] == $template )
    526   {
    527     $vtp->setVar( $sub, 'option.selected', ' selected="selected"' );
    528   }
    529   $vtp->closeSession( $sub, 'option' );
    530 }
    531 $vtp->closeSession( $sub, 'select' );
    532 $vtp->setVar( $sub, 'param_line.def', $lang['conf_default_template_info'] );
    533 $vtp->closeSession( $sub, 'param_line' );
    534 $vtp->closeSession( $sub, 'line' );
    535 // theme
    536 $vtp->addSession( $sub, 'line' );
    537 $vtp->addSession( $sub, 'param_line' );
    538 $vtp->setVar( $sub, 'param_line.name', $lang['customize_theme'] );
    539 $vtp->addSession( $sub, 'select' );
    540 $vtp->setVar( $sub, 'select.name', 'theme' );
    541 $option = get_themes( '../theme/' );
    542 for ( $i = 0; $i < sizeof( $option ); $i++ )
    543 {
    544   $vtp->addSession( $sub, 'option' );
    545   $vtp->setVar( $sub, 'option.option', $option[$i] );
    546   if ( $option[$i] == str_replace( "/", " - ", $theme ) )
    547588  {
    548589    $vtp->setVar( $sub, 'option.selected', ' selected="selected"' );
  • trunk/admin/include/functions.php

    r21 r26  
    1818$tab_ext_create_TN = array ( 'jpg', 'png', 'JPG', 'PNG' );
    1919
     20// is_image returns true if the given $filename (including the path) is a
     21// picture according to its format and its extension.
     22// As GD library can only generate pictures from jpeg and png files, if you
     23// ask if the filename is an image for thumbnail creation (second parameter
     24// set to true), the only authorized formats are jpeg and png.
    2025function is_image( $filename, $create_thumbnail = false )
    2126{
    2227  global $conf, $tab_ext_create_TN;
    2328
    24   if ( is_file ( $filename ) )
     29  if ( is_file( $filename ) )
    2530  {
    2631    $size = getimagesize( $filename );
  • trunk/admin/infos_images.php

    r19 r26  
    1919include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' );
    2020//------------------------------------------------------------------- functions
    21 function check_date_format ( $date )
     21function check_date_format( $date )
    2222{
    2323  // date arrives at this format : DD/MM/YYYY
     
    145145    else
    146146    {
    147       echo $lang['infoimage_err_date'];
     147      echo $lang['err_date'];
    148148    }
    149149  }
     
    222222    $thumbnail_url.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
    223223    $vtp->setVar( $sub, 'picture.thumbnail_url', $thumbnail_url );
     224    $url = '../picture.php?cat='.$_GET['cat_id'].'&amp;image_id='.$row['id'];
     225    $vtp->setVar( $sub, 'picture.url', add_session_id( $url ) );
    224226    $vtp->closeSession( $sub, 'picture' );
    225227  }
  • trunk/admin/thumbnail.php

    r19 r26  
    11<?php
    22/***************************************************************************
    3  *                 thumbnail.php is a part of PhpWebGallery                *
     3 *                              thumbnail.php                              *
    44 *                            -------------------                          *
    5  *   last update          : Thursday, July 25, 2002                        *
    6  *   email                : pierrick@z0rglub.com                           *
     5 *   application          : PhpWebGallery 1.3                              *
     6 *   author               : Pierrick LE GALL <pierrick@z0rglub.com>        *
    77 *                                                                         *
    88 ***************************************************************************/
     
    1515 *                                                                         *
    1616 ***************************************************************************/
    17 include_once( "./include/isadmin.inc.php" );
    18        
    19 function get_subdirs( $rep )
    20 {
    21   $sub_rep = array();
    22   $i = 0;
    23   if ( $opendir = opendir ( $rep ) )
     17include_once( './include/isadmin.inc.php' );
     18//------------------------------------------------------------------- functions
     19// get_subdirs returns an array containing all sub directory names,
     20// excepting : '.', '..' and 'thumbnail'.
     21function get_subdirs( $dir )
     22{
     23  $sub_dirs = array();
     24  if ( $opendir = opendir( $dir ) )
     25  {
     26    while ( $file = readdir( $opendir ) )
     27    {
     28      if ( $file != 'thumbnail' and $file != '.'
     29           and $file != '..' and is_dir( $dir.'/'.$file ) )
     30      {
     31        array_push( $sub_dirs, $file );
     32      }
     33    }
     34  }
     35  return $sub_dirs;
     36}
     37
     38// get_images_without_thumbnail returns an array with all the picture names
     39// that don't have associated thumbnail in the directory. Each picture name
     40// is associated with the width, heigh and filesize of the picture.
     41function get_images_without_thumbnail( $dir )
     42{
     43  $images = array();
     44  if ( $opendir = opendir( $dir ) )
     45  {
     46    while ( $file = readdir( $opendir ) )
     47    {
     48      $path = $dir.'/'.$file;
     49      if ( is_image( $path, true ) )
     50      {
     51        if ( !TN_exists( $dir, $file ) )
     52        {
     53          $image_infos = getimagesize( $path );
     54          $size = floor( filesize( $path ) / 1024 ). ' KB';
     55          array_push( $images, array( 'name' => $file,
     56                                      'width' => $image_infos[0],
     57                                      'height' => $image_infos[1],
     58                                      'size' => $size ) );
     59        }
     60      }
     61    }
     62  }
     63  return $images;
     64}
     65
     66// scandir scans a dir to find pictures without thumbnails. Once found,
     67// creation of the thumbnails (RatioResizeImg). Only the first $_POST['n']
     68// pictures without thumbnails are treated.
     69// scandir returns an array with the generation time of each thumbnail (for
     70// statistics purpose)
     71function scandir( $dir, $width, $height )
     72{
     73  global $conf;
     74  $stats = array();
     75  if ( $opendir = opendir( $dir ) )
    2476  {
    2577    while ( $file = readdir ( $opendir ) )
    2678    {
    27       if ( $file != "thumbnail" && $file != "."
    28            && $file != ".." && is_dir ( $rep.$file ) )
     79      $path = $dir.'/'.$file;
     80      if ( is_image( $path, true ) )
    2981      {
    30         $sub_rep[$i++] = $file;
    31       }
    32     }
    33   }
    34   return $sub_rep;
    35 }
    36 
    37 /*
    38         $tab_ext = array ( 'jpg', 'JPG','png','PNG' );
    39         $tab_tn_ext = array ( 'jpg', 'JPG','png','PNG', 'gif', 'GIF' );
    40 */
    41 function get_images_without_thumbnail( $dir )
    42 {
    43   $i = 0;
    44   if ( $opendir = opendir ( $dir ) )
    45   {
    46     while ( $file = readdir ( $opendir ) )
    47     {
    48       $lien_image = $dir."/".$file;
    49       if ( is_image( $lien_image, true ) )
    50       {
    51         if ( !TN_exist( $dir, $file ) )
     82        if ( count( $stats ) < $_POST['n'] and !TN_exists( $dir, $file ) )
    5283        {
    53           $taille_image = getimagesize( $lien_image );
    54           $size = floor ( filesize( $lien_image ) / 1024 ). " KB";
    55           $images[$i++] = array(        'name' => $file,
    56                                         'width' => $taille_image[0],
    57                                         'height' => $taille_image[1],
    58                                         'size' => $size
    59             );
     84          $starttime = get_moment();
     85          $info = RatioResizeImg( $file, $width, $height, $dir.'/', 'jpg' );
     86          $endtime = get_moment();
     87          $info['time'] = ( $endtime - $starttime ) * 1000;
     88          array_push( $stats, $info );
    6089        }
    6190      }
    6291    }
    6392  }
    64   return $images;
    65 }
    66        
    67 function scandir( $DIR, $width, $height )
    68 {
    69   global $HTTP_POST_VARS, $conf, $output;
    70   $compteur = 0;
    71   $temps = array();
    72   if ( $ODIR = opendir( $DIR ) )
    73   {
    74     while ( $FILE = readdir ( $ODIR ) )
    75     {
    76       $TMP = $DIR."/".$FILE;
    77       if ( is_image ( $TMP, true ) )
    78       {
    79         if ( $compteur < $HTTP_POST_VARS['n'] && !TN_exist( $DIR, $FILE ) )
    80         {
    81           $t1 = explode( " ", microtime() );
    82           $t2 = explode( ".", $t1[0] );
    83           $t2 = $t1[1].".".$t2[1];
    84           $info = RatioResizeImg( $FILE, $width, $height, $DIR."/", "jpg" );
    85           $t3 = explode( " ", microtime() );
    86           $t4 = explode( ".", $t3[0] );
    87           $t4 = $t3[1].".".$t4[1];
    88           $info['temps'] = ( $t4 - $t2 ) * 1000;
    89           $temps[$compteur++] = $info;
    90           //$output.= " (".number_format( $temps[$compteur-1], 2, '.', ' ')." ms)<br />";;
    91         }
    92       }
    93     }
    94   }
    95   return $temps;
    96 }
    97        
    98 function RatioResizeImg( $image, $newWidth, $newHeight, $path, $extension)
    99 {
    100   global $conf, $HTTP_POST_VARS;
    101   // chemin complet de l'image :
    102   $chemin = $path.$image;
    103   // détéction du type de l'image
    104   eregi( "(...)$", $chemin, $regs);
    105   $type = $regs[1];
    106   switch( $type )
    107   {
    108   case "jpg": $srcImage = @imagecreatefromjpeg( $chemin ); break;
    109   case "JPG": $srcImage = @imagecreatefromjpeg( $chemin ); break;
    110   case "png": $srcImage = @imagecreatefrompng( $chemin ); break;
    111   case "PNG": $srcImage = @imagecreatefrompng( $chemin ); break;
    112   default : unset( $type ); break;
     93  return $stats;
     94}
     95
     96// RatioResizeImg creates a new picture (a thumbnail since it is supposed to
     97// be smaller than original picture !) in the sub directory named
     98// "thumbnail".
     99function RatioResizeImg( $filename, $newWidth, $newHeight, $path, $tn_ext )
     100{
     101  global $conf, $lang;
     102  // full path to picture
     103  $filepath = $path.$filename;
     104  // extension of the picture filename
     105  $extension = get_extension( $filepath );
     106  switch( $extension )
     107  {
     108  case 'jpg': $srcImage = @imagecreatefromjpeg( $filepath ); break;
     109  case 'JPG': $srcImage = @imagecreatefromjpeg( $filepath ); break;
     110  case 'png': $srcImage = @imagecreatefrompng(  $filepath ); break;
     111  case 'PNG': $srcImage = @imagecreatefrompng(  $filepath ); break;
     112  default : unset( $extension ); break;
    113113  }
    114114               
    115   if( $srcImage )
    116   {
    117     // hauteurs/largeurs
    118     $srcWidth = imagesx( $srcImage );
    119     $srcHeight = imagesy( $srcImage );
    120     $ratioWidth = $srcWidth/$newWidth;
     115  if ( isset( $srcImage ) )
     116  {
     117    // width/height
     118    $srcWidth    = imagesx( $srcImage );
     119    $srcHeight   = imagesy( $srcImage );
     120    $ratioWidth  = $srcWidth/$newWidth;
    121121    $ratioHeight = $srcHeight/$newHeight;
    122                        
    123     // taille maximale dépassée ?
    124     if (($ratioWidth > 1) || ($ratioHeight > 1))
    125     {
    126       if( $ratioWidth < $ratioHeight)
     122
     123    // maximal size exceeded ?
     124    if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) )
     125    {
     126      if ( $ratioWidth < $ratioHeight)
    127127      {
    128128        $destWidth = $srcWidth/$ratioHeight;
     
    140140      $destHeight = $srcHeight;
    141141    }
    142     // selon votre version de GD installée sur le serveur hébergeur
    143     if ( $HTTP_POST_VARS['gd'] == 2 )
    144     {
    145       // Partie 1 : GD 2.0 ou supérieur, résultat très bons
     142    // according to the GD version installed on the server
     143    if ( $_POST['gd'] == 2 )
     144    {
     145      // GD 2.0 or more recent -> good results (but slower)
    146146      $destImage = imagecreatetruecolor( $destWidth, $destHeight);
    147       imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth,$destHeight,$srcWidth,$srcHeight );
    148     }
    149     else
    150     {
    151       // Partie 2 : GD inférieur à 2, résultat très moyens
     147      imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0,
     148                          $destWidth,$destHeight,$srcWidth,$srcHeight );
     149    }
     150    else
     151    {
     152      // GD prior to version  2 -> pretty bad results :-/ (but fast)
    152153      $destImage = imagecreate( $destWidth, $destHeight);
    153       imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth,$destHeight,$srcWidth,$srcHeight );
     154      imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0,
     155                        $destWidth,$destHeight,$srcWidth,$srcHeight );
    154156    }
    155157                       
    156158                       
    157     if( !is_dir( $path."thumbnail" ) )
    158     {
    159       umask(0000);
    160       mkdir( $path."thumbnail", 0777 );
    161     }
    162     $dest_file  = $path."thumbnail/".$conf['prefix_thumbnail'].substr ( $image, 0, strrpos ( $image, ".") ).".".$extension;
     159    if( !is_dir( $path.'thumbnail' ) )
     160    {
     161      umask( 0000 );
     162      mkdir( $path.'thumbnail', 0777 );
     163    }
     164    $dest_file = $path.'thumbnail/'.$conf['prefix_thumbnail'];
     165    $dest_file.= get_filename_wo_extension( $filename );
     166    $dest_file.= '.'.$tn_ext;
    163167                       
    164     // création et sauvegarde de l'image finale
    165     imagejpeg($destImage, $dest_file);
    166     // libère la mémoire
     168    // creation and backup of final picture
     169    imagejpeg( $destImage, $dest_file );
     170    // freeing memory ressources
    167171    imagedestroy( $srcImage );
    168172    imagedestroy( $destImage );
    169173                       
    170     // renvoit l'URL de l'image
    171     //return $dest_file;
    172     $taille_image = getimagesize( $chemin );
    173     $size = number_format( floor ( filesize( $chemin ) / 1024 ), 0, '', ' ')." KB";
    174     $tn_taille_image = getimagesize( $dest_file );
    175     $tn_size = number_format( floor ( filesize( $dest_file ) ), 0, '', ' ')." octets";
    176     $info = array(      'name' => $image,
    177                         'width' => $taille_image[0],
    178                         'height' => $taille_image[1],
    179                         'size' => $size,
    180                         'tn_name' => $conf['prefix_thumbnail'].substr ( $image, 0, strrpos ( $image, ".") ).".".$extension,
    181                         'tn_width' => $tn_taille_image[0],
    182                         'tn_height' => $tn_taille_image[1],
    183                         'tn_size' => $tn_size
    184       );
     174    list( $width,$height ) = getimagesize( $filepath );
     175    $size = floor( filesize( $filepath ) / 1024 ).' KB';
     176    list( $tn_width,$tn_height ) = getimagesize( $dest_file );
     177    $tn_size = floor( filesize( $dest_file ) / 1024 ).' KB';
     178    $info = array( 'file'      => $filename,
     179                   'width'     => $width,
     180                   'height'    => $height,
     181                   'size'      => $size,
     182                   'tn_file'   => $dest_file,
     183                   'tn_width'  => $tn_width,
     184                   'tn_height' => $tn_height,
     185                   'tn_size'   => $tn_size );
    185186    return $info;
    186187  }
    187   // erreur
     188  // error
    188189  else
    189190  {
    190191    echo $lang['tn_no_support']." ";
    191     if ($type)
    192     {
    193       echo $lang['tn_format']." $type";
     192    if ( isset( $extenstion ) )
     193    {
     194      echo $lang['tn_format'].' '.$extension;
    194195    }
    195196    else
     
    200201  }
    201202}
     203
     204// array_max returns the highest value of the given array
     205function array_max( $array )
     206{
     207  sort( $array, SORT_NUMERIC );
     208  return array_pop( $array );
     209}
     210
     211// array_min returns the lowest value of the given array
     212function array_min( $array )
     213{
     214  sort( $array, SORT_NUMERIC );
     215  return array_shift( $array );
     216}
     217
     218// array_avg returns the average value of the array
     219function array_avg( $array )
     220{
     221  return array_sum( $array ) / sizeof( $array );
     222}
    202223       
    203 function array_max( $array )
    204 {
    205   $max = 0;
    206   for ( $i = 0; $i < sizeof( $array ); $i++ )
    207   {
    208     if ( $array[$i] > $max )
    209     {
    210       $max = $array[$i];
    211     }
    212   }
    213   return $max;
    214 }
    215        
    216 function array_min( $array )
    217 {
    218   $min = 99999999999999;
    219   for ( $i = 0; $i < sizeof( $array ); $i++ )
    220   {
    221     if ( $array[$i] < $min )
    222     {
    223       $min = $array[$i];
    224     }
    225   }
    226   return $min;
    227 }
    228        
    229 function array_moy( $array )
    230 {
    231   return array_sum( $array ) / sizeof( $array );
    232 }
    233        
    234 // get_dirs retourne un tableau contenant tous les sous-répertoires d'un répertoire
    235 function get_displayed_dirs( $rep, $indent )
    236 {
    237   global $conf,$lang;
     224// get_displayed_dirs builds the tree of dirs under "galleries". If a
     225// directory contains pictures without thumbnails, the become linked to the
     226// page of thumbnails creation.
     227function get_displayed_dirs( $dir, $indent )
     228{
     229  global $conf,$lang,$vtp,$sub;
    238230               
    239   $sub_rep = array();
    240   $i = 0;
    241   $dirs = "";
    242   if ( $opendir = opendir ( $rep ) )
    243   {
    244     while ( $file = readdir ( $opendir ) )
    245     {
    246       if ( $file != "." && $file != ".." && is_dir ( $rep."/".$file ) && $file != "thumbnail" )
     231  $sub_dirs = get_subdirs( $dir );
     232  // write of the dirs
     233  foreach ( $sub_dirs as $sub_dir ) {
     234    $pictures = get_images_without_thumbnail( $dir.'/'.$sub_dir );
     235    $vtp->addSession( $sub, 'dir' );
     236    $vtp->setVar( $sub, 'dir.indent', $indent );
     237    if ( count( $pictures ) > 0 )
     238    {
     239      $vtp->addSession( $sub, 'linked' );
     240      $url = './admin.php?page=thumbnail&amp;dir='.$dir."/".$sub_dir;
     241      $vtp->setVar( $sub, 'linked.url', add_session_id( $url ) );
     242      $vtp->setVar( $sub, 'linked.name', $sub_dir );
     243      $vtp->setVar( $sub, 'linked.nb_pic', count( $pictures ) );
     244      $vtp->closeSession( $sub, 'linked' );
     245    }
     246    else
     247    {
     248      $vtp->addSession( $sub, 'unlinked' );
     249      $vtp->setVar( $sub, 'unlinked.name', $sub_dir );
     250      $vtp->closeSession( $sub, 'unlinked' );
     251    }
     252    $vtp->closeSession( $sub, 'dir' );
     253    // recursive call
     254    $dirs.= get_displayed_dirs( $dir.'/'.$sub_dir,
     255                                $indent+30 );
     256   
     257  }
     258}
     259//----------------------------------------------------- template initialization
     260$sub = $vtp->Open( '../template/'.$user['template'].'/admin/thumbnail.vtp' );
     261$tpl = array(
     262  'tn_dirs_title','tn_dirs_alone','tn_params_title','tn_params_GD',
     263  'tn_params_GD_info','tn_width','tn_params_width_info','tn_height',
     264  'tn_params_height_info','tn_params_create','tn_params_create_info',
     265  'tn_params_format','tn_params_format_info','submit','tn_alone_title',
     266  'filesize','tn_picture','tn_results_title','thumbnail',
     267  'tn_results_gen_time','tn_stats','tn_stats_nb','tn_stats_total',
     268  'tn_stats_max','tn_stats_min','tn_stats_mean' );
     269templatize_array( $tpl, 'lang', $sub );
     270//----------------------------------------------------- miniaturization results
     271if ( isset( $_GET['dir'] ) )
     272{
     273  $pictures = get_images_without_thumbnail( $_GET['dir'] );
     274  if ( count( $pictures ) == 0 )
     275  {
     276    $vtp->addSession( $sub, 'warning' );
     277    $vtp->closeSession( $sub, 'warning' );
     278  }
     279  elseif ( isset( $_POST['submit'] ) )
     280  {
     281    // checking criteria
     282    $errors = array();
     283    if ( !ereg( "^[0-9]{2,3}$", $_POST['width'] ) or $_POST['width'] < 10 )
     284    {
     285      array_push( $errors, $lang['tn_err_width'].' 10' );
     286    }
     287    if ( !ereg( "^[0-9]{2,3}$", $_POST['height'] ) or $_POST['height'] < 10 )
     288    {
     289      array_push( $errors, $lang['tn_err_height'].' 10' );
     290    }
     291    // picture miniaturization
     292    if ( count( $errors ) == 0 )
     293    {
     294      $vtp->addSession( $sub, 'results' );
     295      $stats = scandir( $_GET['dir'], $_POST['width'], $_POST['height'] );
     296      $times = array();
     297      foreach ( $stats as $stat ) {
     298        array_push( $times, $stat['time'] );
     299      }
     300      $max = array_max( $times );
     301      $min = array_min( $times );
     302      foreach ( $stats as $i => $stat ) {
     303        $vtp->addSession( $sub, 'picture' );
     304        if ( $i % 2 == 1 )
     305        {
     306          $vtp->setVar( $sub, 'picture.class', 'row2' );
     307        }
     308        $vtp->setVar( $sub, 'picture.num',            ($i+1) );
     309        $vtp->setVar( $sub, 'picture.file',           $stat['file'] );
     310        $vtp->setVar( $sub, 'picture.filesize',       $stat['size'] );
     311        $vtp->setVar( $sub, 'picture.width',          $stat['width'] );
     312        $vtp->setVar( $sub, 'picture.height',         $stat['height'] );
     313        $vtp->setVar( $sub, 'picture.thumb_file',     $stat['tn_file'] );
     314        $vtp->setVar( $sub, 'picture.thumb_filesize', $stat['tn_size'] );
     315        $vtp->setVar( $sub, 'picture.thumb_width',    $stat['tn_width'] );
     316        $vtp->setVar( $sub, 'picture.thumb_height',   $stat['tn_height'] );
     317        $vtp->setVar( $sub, 'picture.time',
     318                      number_format( $stat['time'], 2, '.', ' ').' ms' );
     319        if ( $stat['time'] == $max )
     320        {
     321          $vtp->setVar( $sub, 'picture.color', 'red' );
     322        }
     323        else if ( $stat['time'] == $min )
     324        {
     325          $vtp->setVar( $sub, 'picture.color', 'green' );
     326        }
     327        $vtp->closeSession( $sub, 'picture' );
     328      }
     329      // general statistics
     330      $vtp->setVar( $sub, 'results.stats_nb', count( $stats ) );
     331      $vtp->setVar( $sub, 'results.stats_total',
     332                    number_format( array_sum( $times ), 2, '.', ' ').' ms' );
     333      $vtp->setVar( $sub, 'results.stats_max',
     334                    number_format( $max, 2, '.', ' ').' ms' );
     335      $vtp->setVar( $sub, 'results.stats_min',
     336                    number_format( $min, 2, '.', ' ').' ms' );
     337      $vtp->setVar( $sub, 'results.stats_mean',
     338                    number_format( array_avg( $times ), 2, '.', ' ').' ms' );
     339      $vtp->closeSession( $sub, 'results' );
     340    }
     341    else
     342    {
     343      $vtp->addSession( $sub, 'errors' );
     344      foreach ( $errors as $error ) {
     345        $vtp->addSession( $sub, 'li' );
     346        $vtp->setVar( $sub, 'li.li', $error );
     347        $vtp->closeSession( $sub, 'li' );
     348      }
     349      $vtp->closeSession( $sub, 'errors' );
     350    }
     351  }
     352//-------------------------------------------------- miniaturization parameters
     353  if ( sizeof( $pictures ) != 0 )
     354  {
     355    $vtp->addSession( $sub, 'params' );
     356    $url = './admin.php?page=thumbnail&amp;dir='.$_GET['dir'];
     357    $vtp->setVar( $sub, 'params.action', add_session_id( $url ) );
     358    // GD version selected...
     359    if ( $_POST['gd'] == 1 )
     360    {
     361      $vtp->setVar( $sub, 'params.gd1_checked', ' checked="checked"' );
     362    }
     363    else
     364    {
     365      $vtp->setVar( $sub, 'params.gd2_checked', ' checked="checked"' );
     366    }
     367    // width values
     368    if ( isset( $_POST['width'] ) )
     369    {
     370      $vtp->setVar( $sub, 'params.width_value', $_POST['width'] );
     371    }
     372    else
     373    {
     374      $vtp->setVar( $sub, 'params.width_value', '128' );
     375    }
     376    // height value
     377    if ( isset( $_POST['height'] ) )
     378    {
     379      $vtp->setVar( $sub, 'params.height_value', $_POST['height'] );
     380    }
     381    else
     382    {
     383      $vtp->setVar( $sub, 'params.height_value', '96' );
     384    }
     385    // options for the number of picture to miniaturize : "n"
     386    $options = array( 5,10,20,40 );
     387    foreach ( $options as $option ) {
     388      $vtp->addSession( $sub, 'n_option' );
     389      $vtp->setVar( $sub, 'n_option.option', $option );
     390      if ( $option == $_POST['n'] )
    247391      {
    248         $sub_rep[$i++] = $file;
    249       }
    250     }
    251   }
    252   // write of the dirs
    253   for ( $i = 0; $i < sizeof( $sub_rep ); $i++ )
    254   {
    255     $images = get_images_without_thumbnail( $rep."/".$sub_rep[$i] );
    256     $nb_picture_without_TN = sizeof( $images );
    257     $dirs.= $indent;
    258     if ( $nb_picture_without_TN > 0 )
    259     {
    260       $dirs.= "<a href=\"".add_session_id_to_url( "./admin.php?page=thumbnail&amp;dir=".$rep."/".$sub_rep[$i] )."\">";
    261     }
    262     $dirs.= "<img src=\"".$conf['lien_puce']."\" style=\"border:none;\" alt=\"&gt;\"/>".$sub_rep[$i];
    263     if ( $nb_picture_without_TN > 0 )
    264     {
    265       $dirs.= "</a>";
    266     }
    267     if ( $nb_picture_without_TN > 0 )
    268     {
    269       $dirs.= " [ $nb_picture_without_TN ".$lang['tn_dirs_alone']." ]";
    270     }
    271     $dirs.= "<br />";
    272     $dirs.= get_displayed_dirs( $rep."/".$sub_rep[$i], $indent."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" );
    273   }
    274   return $dirs;         
    275 }
    276 
    277 $output = "";
    278        
    279 if ( isset( $HTTP_GET_VARS['dir'] ) )
    280 {
    281   //---------------vérification de la présence d'images sans thumbnail
    282   $images = get_images_without_thumbnail( $HTTP_GET_VARS['dir'] );
    283   if ( sizeof( $images ) == 0 )
    284   {
    285     $output.= "<div style=\"text-align:center;font-weight:bold;margin:10px;\"> [ 0 ".$lang['tn_dirs_alone']." ]</div>";
    286   }
    287   else if ( isset( $HTTP_POST_VARS['submit'] ) )
    288   {
    289     //----------------------------------------vérification des variables
    290     $nb_erreur = 0;
    291     $erreur = "";
    292     if ( !ereg( "^[0-9]{2,3}$", $HTTP_POST_VARS['width'] ) || $HTTP_POST_VARS['width'] < 10 )
    293     {
    294       $nb_erreur++;
    295       $erreur.= "<li>".$lang['tn_err_width']." 10</li>";
    296     }
    297     if ( !ereg( "^[0-9]{2,3}$", $HTTP_POST_VARS['height'] ) || $HTTP_POST_VARS['height'] < 10 )
    298     {
    299       $nb_erreur++;
    300       $erreur.= "<li>".$lang['tn_err_height']." 10</li>";
    301     }
    302     if ( !isset( $HTTP_POST_VARS['gd'] ) )
    303     {
    304       $nb_erreur++;
    305       $erreur.= "<li>".$lang['tn_err_GD']."</li>";
    306     }
    307                        
    308     //---------------------------------------------listing des résultats
    309     if ( $nb_erreur == 0 )
    310     {
    311       $style = "class=\"row2\" style=\"text-align:center;font-weight:bold;";
    312       $output.= "
    313         <table style=\"width:100%;\">
    314                 <tr>
    315                         <th colspan=\"10\">".$lang['tn_results_title']."</th>
    316                 </tr>
    317                 <tr>
    318                         <td ".$style."\">&nbsp;</td>
    319                         <td ".$style."\">".$lang['tn_picture']."</td>
    320                         <td ".$style."\">".$lang['tn_filesize']."</td>
    321                         <td ".$style."\">".$lang['tn_width']."</td>
    322                         <td ".$style."\">".$lang['tn_height']."</td>
    323                         <td ".$style."background-color:#D3DCE3;\">".$lang['tn_results_gen_time']."</td>
    324                         <td ".$style."\">".$lang['thumbnail']."</td>
    325                         <td ".$style."\">".$lang['tn_filesize']."</td>
    326                         <td ".$style."\">".$lang['tn_width']."</td>
    327                         <td ".$style."\">".$lang['tn_height']."</td>
    328                 </tr>";
    329       $tab_infos = scandir( $HTTP_GET_VARS['dir'], $HTTP_POST_VARS['width'], $HTTP_POST_VARS['height'] );
    330       for ( $i = 0; $i < sizeof ( $tab_infos ); $i++ )
     392        $vtp->setVar( $sub, 'n_option.selected', ' selected="selected"' );
     393      }
     394      $vtp->closeSession( $sub, 'n_option' );
     395    }
     396    $vtp->closeSession( $sub, 'params' );
     397//---------------------------------------------------------- remaining pictures
     398    $vtp->addSession( $sub, 'remainings' );
     399    $pictures = get_images_without_thumbnail( $_GET['dir'] );
     400    $vtp->setVar( $sub, 'remainings.total', count( $pictures ) );
     401    foreach ( $pictures as $i => $picture ) {
     402      $vtp->addSession( $sub, 'remaining' );
     403      if ( $i % 2 == 1 )
    331404      {
    332         $temps[$i] = $tab_infos[$i]['temps'];
    333       }
    334       $max = array_max( $temps );
    335       $min = array_min( $temps );
    336       for ( $i = 0; $i < sizeof ( $tab_infos ); $i++ )
    337       {
    338         $temps[$i] = $tab_infos[$i]['temps'];
    339         $num = $i + 1;
    340         $class = "";
    341         if ( $i%2 == 1 )
    342         {
    343           $class = "class=\"row2\"";
    344         }
    345         $output.= "
    346                 <tr>
    347                         <td class=\"row2\">$num</td>
    348                         <td $class>".$tab_infos[$i]['name']."</td>
    349                         <td $class style=\"text-align:right;\">".$tab_infos[$i]['size']."</td>
    350                         <td $class style=\"text-align:right;\">".$tab_infos[$i]['width']."</td>
    351                         <td $class style=\"text-align:right;\">".$tab_infos[$i]['height']."</td>
    352                         <th><div style=\"text-align:right;margin-right:5px;";
    353         if ( $tab_infos[$i]['temps'] == $max )
    354         {
    355           $output.= "color:red;";
    356         }
    357         if ( $tab_infos[$i]['temps'] == $min )
    358         {
    359           $output.= "color:green;";
    360         }
    361         $output.= "\">".number_format( $tab_infos[$i]['temps'], 2, '.', ' ')." ms</div></th>
    362                         <td $class>".$tab_infos[$i]['tn_name']."</td>
    363                         <td $class style=\"text-align:right;\">".$tab_infos[$i]['tn_size']."</td>
    364                         <td $class style=\"text-align:right;\">".$tab_infos[$i]['tn_width']."</td>
    365                         <td $class style=\"text-align:right;\">".$tab_infos[$i]['tn_height']."</td>
    366                 </tr>";
    367       }
    368       $output.= "
    369                 <tr>
    370                         <td colspan=\"10\">&nbsp;</td>
    371                 </tr>
    372         </table>
    373         <table style=\"margin:auto;border:1px solid black;\">
    374                 <tr>
    375                         <td colspan=\"2\" style=\"text-align:center;font-weight:bold;\" class=\"row2\">".$lang['tn_stats']."</td>
    376                 </tr>
    377                 <tr>
    378                         <td>".$lang['tn_stats_nb']." : </td>
    379                         <td style=\"text-align:center;\">".sizeof( $temps )."</td>
    380                 </tr>
    381                 <tr>
    382                         <td>".$lang['tn_stats_total']." : </td>
    383                         <td style=\"text-align:right;\">".number_format( array_sum( $temps ), 2, '.', ' ')." ms</td>
    384                 </tr>
    385                 <tr>
    386                         <td>".$lang['tn_stats_max']." : </td>
    387                         <td style=\"text-align:right;\">".number_format( $max, 2, '.', ' ')." ms</td>
    388                 </tr>
    389                 <tr>
    390                         <td>".$lang['tn_stats_min']." : </td>
    391                         <td style=\"text-align:right;\">".number_format( $min, 2, '.', ' ')." ms</td>
    392                 </tr>
    393                 <tr>
    394                         <td>".$lang['tn_stats_mean']." : </td>
    395                         <td style=\"text-align:right;\">".number_format( array_moy( $temps ), 2, '.', ' ')." ms</td>
    396                 </tr>
    397         </table>
    398         <table>
    399                 <tr>
    400                         <td>&nbsp;</td>
    401                 </tr>
    402         </table>";
    403     }
    404     else
    405     {
    406       $output.= "
    407         <div class=\"erreur\" style=\"margin-top:10px;\">".$lang['tn_err']."</div>
    408         <div class=\"erreur\" style=\"text-align:left;margin-left:20px;\">
    409                 <ul>
    410                         $erreur
    411                 </ul>
    412         </div>";
    413     }
    414   }
    415   //-------------------------------------paramètres de miniaturisation
    416   if ( sizeof( $images ) != 0 )
    417   {
    418     $output.= "
    419         <style>
    420                 div.key
    421                 {
    422                         margin-left : 10px;
    423                 }
    424                 td.choice
    425                 {
    426                         text-align : center;
    427                 }
    428         </style>";
    429     $output.= "
    430         <form method=\"post\" action=\"".add_session_id_to_url( "./admin.php?page=thumbnail&amp;dir=".$HTTP_GET_VARS['dir'] )."\">
    431         <table style=\"width:100%;\">
    432                 <tr>
    433                         <th colspan=\"3\">".$lang['tn_params_title']."</th>
    434                 </tr>";
    435     $output.= "
    436                 <tr>
    437                         <td colspan=\"3\">&nbsp;</td>
    438                 </tr>";
    439     $output.= "
    440                 <tr>
    441                         <td><div class=\"key\">".$lang['tn_params_GD']."</div></td>
    442                         <td class=\"choice\">
    443                                 <input type=\"radio\" name=\"gd\" value=\"2\"/ checked=\"checked\">2.x
    444                                 <input type=\"radio\" name=\"gd\" value=\"1\"";
    445     if ( $HTTP_POST_VARS['gd'] == 1 )
    446     {
    447       $output.= " checked=\"checked\"";
    448     }
    449     $output.= "/>1.x
    450                         </td>
    451                         <td style=\"width:50%;\" class=\"row2\">".$lang['tn_params_GD_info']."</td>
    452                 </tr>
    453                 <tr>
    454                         <td><div class=\"key\">".$lang['tn_width']."</div></td>
    455                         <td class=\"choice\"><input type=\"text\" name=\"width\" value=\"";
    456     if ( isset( $HTTP_POST_VARS['width'] ) )
    457     {
    458       $output.= $HTTP_POST_VARS['width'];
    459     }
    460     else
    461     {
    462       $output.= "128";
    463     }
    464     $output.="\"/></td>
    465                         <td class=\"row2\">".$lang['tn_params_width_info']."</td>
    466                 </tr>
    467                 <tr>
    468                         <td><div class=\"key\">".$lang['tn_height']."</div></td>
    469                         <td class=\"choice\"><input type=\"text\" name=\"height\" value=\"";
    470     if ( isset( $HTTP_POST_VARS['height'] ) )
    471     {
    472       $output.= $HTTP_POST_VARS['height'];
    473     }
    474     else
    475     {
    476       $output.= "96";
    477     }
    478     $output.="\"/></td>
    479                         <td class=\"row2\">".$lang['tn_params_height_info']."</td>
    480                 </tr>
    481                 <tr>
    482                         <td><div class=\"key\">".$lang['tn_params_create']."</div></td>
    483                         <td class=\"choice\">
    484                                 <select name=\"n\">
    485                                         <option>5</option>
    486                                         <option>10</option>
    487                                         <option>20</option>
    488                                         <option>40</option>
    489                                 </select>
    490                         </td>
    491                         <td class=\"row2\">".$lang['tn_params_create_info']."</td>
    492                 </tr>
    493                 <tr>
    494                         <td><div class=\"key\">".$lang['tn_params_format']."</div></td>
    495                         <td class=\"choice\"><span style=\"font-weight:bold;\">jpeg</span></td>
    496                         <td class=\"row2\">".$lang['tn_params_format_info']."</td>
    497                 </tr>
    498                 <tr>
    499                         <td colspan=\"3\">&nbsp;</td>
    500                 </tr>
    501                 <tr>
    502                         <td colspan=\"3\" style=\"text-align:center;\">
    503                                 <input type=\"submit\" name=\"submit\" value=\"".$lang['submit']."\"/>
    504                         </td>
    505                 </tr>";
    506     $output.= "
    507         </table>
    508         </form>";
    509     //-----------------------------------liste des images sans miniature
    510     $images = get_images_without_thumbnail( $HTTP_GET_VARS['dir'] );
    511     $style = "class=\"row2\" style=\"text-align:center;font-weight:bold;";
    512     $output.= "
    513         <table style=\"width:100%;\">
    514                 <tr>
    515                         <th colspan=\"5\"><span style=\"color:#006699;\">".sizeof( $images )."</span> ".$lang['tn_alone_title']."</th>
    516                 </tr>
    517                 <tr>
    518                         <td ".$style."\">&nbsp;</td>
    519                         <td ".$style."width:50%;\">".$lang['tn_picture']."</td>
    520                         <td ".$style."width:17%;\">".$lang['tn_filesize']."</td>
    521                         <td ".$style."width:17%;\">".$lang['tn_width']."</td>
    522                         <td ".$style."width:16%;\">".$lang['tn_height']."</td>
    523                 </tr>";
    524     for ( $i = 0; $i < sizeof( $images ); $i++ )
    525     {
    526       $num = $i + 1;
    527       $class = "";
    528       if ( $i%2 == 1 )
    529       {
    530         $class = " class=\"row2\"";
    531       }
    532       $output.= "
    533                 <tr>
    534                         <td class=\"row2\">".$num."</td>
    535                         <td $class><div style=\"margin-left:10px;\">".$images[$i]['name']."</div></td>
    536                         <td $class><div style=\"margin-left:10px;\">".$images[$i]['size']."</div></td>
    537                         <td $class><div style=\"margin-left:10px;\">".$images[$i]['width']."</div></td>
    538                         <td $class><div style=\"margin-left:10px;\">".$images[$i]['height']."</div></td>
    539                 </tr>";
    540     }
    541     $output.= "
    542         </table>";
    543   }
    544 }
    545 //-----------------------------------liste des répertoires
    546 //-------------------------si aucun répertoire selectionné
     405        $vtp->setVar( $sub, 'remaining.class', 'row2' );
     406      }
     407      $vtp->setVar( $sub, 'remaining.num',      ($i+1) );
     408      $vtp->setVar( $sub, 'remaining.file',     $picture['name'] );
     409      $vtp->setVar( $sub, 'remaining.filesize', $picture['size'] );
     410      $vtp->setVar( $sub, 'remaining.width',    $picture['width'] );
     411      $vtp->setVar( $sub, 'remaining.height',   $picture['height'] );
     412      $vtp->closeSession( $sub, 'remaining' );
     413    }
     414    $vtp->closeSession( $sub, 'remainings' );
     415  }
     416}
     417//-------------------------------------------------------------- directory list
    547418else
    548419{
    549   $output = "
    550                 <table style=\"width:100%;\">
    551                         <tr>
    552                                 <th>".$lang['tn_dirs_title']."</th>
    553                         </tr>";
    554   $output.= "
    555                         <tr>
    556                                 <td>
    557                                         <div class=\"retrait\">
    558                                                 <img src=\"".$conf['lien_puce']."\" alt=\"\"/>galleries";
    559   $output.= "<br />";
    560   $output.= get_displayed_dirs( "../galleries", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" );
    561   $output.= "
    562                                         </div>
    563                                 </td>
    564                         </tr>
    565                 </table>";
    566 }
    567 echo $output;
     420  $vtp->addSession( $sub, 'directory_list' );
     421  get_displayed_dirs( '../galleries', 60 );
     422  $vtp->closeSession( $sub, 'directory_list' );
     423}
     424//----------------------------------------------------------- sending html code
     425$vtp->Parse( $handle , 'sub', $sub );
    568426?>
  • trunk/admin/update.php

    r19 r26  
    188188  $pictures = array();         
    189189  $tn_ext = '';
    190   if ( $opendir = opendir ( $rep ) )
    191   {
    192     while ( $file = readdir ( $opendir ) )
     190  if ( $opendir = opendir( $rep ) )
     191  {
     192    while ( $file = readdir( $opendir ) )
    193193    {
    194194      if ( is_file( $rep.'/'.$file ) and is_image( $rep.'/'.$file ) )
    195195      {
    196196        // is the picture waiting for validation by an administrator ?
    197         $query = 'SELECT id';
     197        $query = 'SELECT id,validated,infos';
    198198        $query.= ' FROM '.PREFIX_TABLE.'waiting';
    199199        $query.= ' WHERE cat_id = '.$category_id;
     
    201201        $query.= ';';
    202202        $result = mysql_query( $query );
    203         if ( mysql_num_rows( $result ) == 0 )
     203        $waiting = mysql_fetch_array( $result );
     204        if (mysql_num_rows( $result ) == 0 or $waiting['validated'] == 'true')
    204205        {
    205206          if ( $tn_ext = TN_exists( $rep, $file ) )
     
    215216            {
    216217              $picture = array();
    217               $picture['file'] = $file;
    218               $picture['tn_ext'] = $tn_ext;
     218              $picture['file']     = $file;
     219              $picture['tn_ext']   = $tn_ext;
    219220              $picture['date'] = date( 'Y-m-d', filemtime ( $rep.'/'.$file ) );
    220221              $picture['filesize'] = floor( filesize( $rep.'/'.$file ) / 1024);
    221222              $image_size = @getimagesize( $rep.'/'.$file );
    222               $picture['width'] = $image_size[0];
    223               $picture['height'] = $image_size[1];
     223              $picture['width']    = $image_size[0];
     224              $picture['height']   = $image_size[1];
     225              if ( $waiting['validated'] == 'true' )
     226              {
     227                // retrieving infos from the XML description of
     228                // $waiting['infos']
     229                $infos = nl2br( $waiting['infos'] );
     230                $picture['author']        = getAttribute( $infos, 'author' );
     231                $picture['comment']       = getAttribute( $infos, 'comment' );
     232                $unixtime = getAttribute( $infos, 'date_creation' );
     233                $picture['date_creation'] = '';
     234                if ( $unixtime != '' )
     235                {
     236                  $picture['date_creation'] = date( 'Y-m-d', $unixtime );
     237                }
     238                $picture['name']          = getAttribute( $infos, 'name' );
     239                // deleting the waiting element
     240                $query = 'DELETE FROM '.PREFIX_TABLE.'waiting';
     241                $query.= ' WHERE id = '.$waiting['id'];
     242                $query.= ';';
     243                mysql_query( $query );
     244              }
    224245              array_push( $pictures, $picture );
    225246            }
     
    243264  foreach ( $pictures as $picture ) {
    244265    $query = 'INSERT INTO '.PREFIX_TABLE.'images';
    245     $query.= ' (file,cat_id,date_available,tn_ext,filesize,width,height)';
     266    $query.= ' (file,cat_id,date_available,tn_ext,filesize,width,height';
     267    $query.= ',name,author,comment,date_creation)';
    246268    $query.= ' VALUES ';
    247269    $query.= "('".$picture['file']."','".$category_id."'";
    248270    $query.= ",'".$picture['date']."','".$picture['tn_ext']."'";
    249271    $query.= ",'".$picture['filesize']."','".$picture['width']."'";
    250     $query.= ",'".$picture['height']."')";
    251     $query.= ';';
     272    $query.= ",'".$picture['height']."','".$picture['name']."'";
     273    $query.= ",'".$picture['author']."','".$picture['comment']."'";
     274    if ( $picture['date_creation'] != '' )
     275    {
     276      $query.= ",'".$picture['date_creation']."'";
     277    }
     278    else
     279    {
     280      $query.= ',NULL';
     281    }
     282    $query.= ');';
    252283    mysql_query( $query );
    253284    $count_new++;
     
    284315               
    285316  $query = 'UPDATE '.PREFIX_TABLE.'categories';
    286   $query.= " SET date_dernier = '".$date_last."'";
     317  $query.= " SET date_last = '".$date_last."'";
    287318  $query.= ', nb_images = '.$nb_images;
    288319  $query.= ' where id = '.$category_id;
  • trunk/admin/waiting.php

    r19 r26  
    11<?php
    22/***************************************************************************
    3  *                     waiting.php is a part of PhpWebGallery              *
     3 *                                waiting.php                              *
    44 *                            -------------------                          *
    5  *   last update          : Monday, October 28, 2002                         *
    6  *   email                : pierrick@z0rglub.com                           *
     5 *   application          : PhpWebGallery 1.3                              *
     6 *   author               : Pierrick LE GALL <pierrick@z0rglub.com>        *
    77 *                                                                         *
    88 ***************************************************************************/
     
    1515 *                                                                         *
    1616 ***************************************************************************/
    17         include_once( "./include/isadmin.inc.php" );
    18         //-------------------------------------------------------------- mise à jour
    19         if ( isset( $HTTP_POST_VARS['submit'] ) )
    20         {
    21                 $query = "select id,cat_id,file,tn_ext";
    22                 $query.= " from PREFIX_TABLE"."waiting";
    23                 $query.= ";";
    24                 $result = mysql_query( $query );
    25                 while ( $row = mysql_fetch_array( $result ) )
    26                 {
    27                         $key = "validate-".$row['id'];
    28                         if ( isset( $HTTP_POST_VARS[$key] ) )
    29                         {
    30                                 $query = "delete from PREFIX_TABLE"."waiting";
    31                                 $query.= " where id = ".$row['id'];
    32                                 $query.= ";";
    33                                 mysql_query( $query );
    34                                 if ( $HTTP_POST_VARS[$key] == "false" )
    35                                 {
    36                                         // we have to delete the picture and the thumbnail if it exists
    37                                         $cat = get_cat_info( $row['cat_id'] );
    38                                         unlink( ".".$cat['dir'].$row['file'] );
    39                                         if ( $row['tn_ext'] != "" )
    40                                         {
    41                                                 $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
    42                                                 unlink( ".".$cat['dir']."thumbnail/".$conf['prefix_thumbnail'].$file.".".$row['tn_ext'] );
    43                                         }
    44                                 }
    45                         }
    46                 }
    47         }
    48         //--------------------------------------------------------------- formulaire
    49         $cat_names = array();
    50         echo "
    51                 <form action=\"".add_session_id_to_url( "./admin.php?page=waiting" )."\" method=\"post\">
    52                         <table style=\"width:100%;\">
    53                                 <tr>
    54                                         <th style=\"width:20%;\">".$lang['category']."</th>
    55                                         <th style=\"width:20%;\">".$lang['date']."</th>
    56                                         <th style=\"width:20%;\">".$lang['file']."</th>
    57                                         <th style=\"width:20%;\">".$lang['thumbnail']."</th>
    58                                         <th style=\"width:20%;\">".$lang['author']."</th>
    59                                         <th style=\"width:1px;\">&nbsp;</th>
    60                                 </tr>";
    61         $query = "select id,cat_id,file,username,mail_address,date,tn_ext";
    62         $query.= " from PREFIX_TABLE"."waiting";
    63         $query.= " order by cat_id";
    64         $query.= ";";
    65         $result = mysql_query( $query );
    66         $i = 0;
    67         while ( $row = mysql_fetch_array( $result ) )
    68         {
    69                 $style = "";
    70                 if ( $i%2 == 0 )
    71                 {
    72                         $style = "class=\"row2\"";
    73                 }
    74                 if ( !isset( $cat_names[$row['cat_id']] ) )
    75                 {
    76                         $cat = get_cat_info( $row['cat_id'] );
    77                         $cat_names[$row['cat_id']] = array();
    78                         $cat_names[$row['cat_id']]['dir'] = ".".$cat['dir'];
    79                         $cat_names[$row['cat_id']]['display_name'] = get_cat_display_name( $cat['name'], " - ", "font-style:italic;" );
    80                 }
    81                 echo "
    82                                 <tr>
    83                                         <td $style style=\"white-space:nowrap;\">".$cat_names[$row['cat_id']]['display_name']."</td>
    84                                         <td $style style=\"white-space:nowrap;\">".$lang['day'][date( "w", $row['date'] )].date( " j ", $row['date'] ).$lang['month'][date( "n", $row['date'] )].date( " Y G:i", $row['date'] )."</td>
    85                                         <td $style style=\"white-space:nowrap;\">
    86                                                 <a target=\"_blank\" href=\"".$cat_names[$row['cat_id']]['dir'].$row['file']."\">".$row['file']."</td>
    87                                         </td>
    88                                         <td $style style=\"white-space:nowrap;\">";
    89                 if ( $row['tn_ext'] != "" )
    90                 {
    91                         $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
    92                         echo "<a target=\"_blank\" href=\"".$cat_names[$row['cat_id']]['dir']."thumbnail/".$conf['prefix_thumbnail'].$file.".".$row['tn_ext']."\">".$conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
    93                 }
    94                 else
    95                 {
    96                         echo "&nbsp;";
    97                 }
    98                 echo "
    99                                         </td>
    100                                         <td $style style=\"white-space:nowrap;\">
    101                                                 <a href=\"mailto:".$row['mail_address']."\">".$row['username']."</a>
    102                                         </td>
    103                                         <td $style style=\"white-space:nowrap;\">
    104                                                 <input type=\"radio\" name=\"validate-".$row['id']."\" value=\"true\" />".$lang['submit']."
    105                                                 <input type=\"radio\" name=\"validate-".$row['id']."\" value=\"false\" />".$lang['delete']."
    106                                         </td>
    107                                 </tr>";
    108                 $i++;
    109         }
    110         echo "
    111                                 <tr>
    112                                         <td colspan=\"5\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"".$lang['submit']."\" style=\"margin:5px;\" /></td>
    113                                 </tr>";
    114         echo "
    115                         </table>
    116                 </form>";
     17include_once( './include/isadmin.inc.php' );
     18//--------------------------------------------------------------------- updates
     19if ( isset( $_POST['submit'] ) )
     20{
     21  $query = 'SELECT id,cat_id,file,tn_ext';
     22  $query.= ' FROM '.PREFIX_TABLE.'waiting';
     23  $query.= " WHERE validated = 'false'";
     24  $query.= ';';
     25  $result = mysql_query( $query );
     26  while ( $row = mysql_fetch_array( $result ) )
     27  {
     28    $key = 'validate-'.$row['id'];
     29    if ( isset( $_POST[$key] ) )
     30    {
     31      if ( $_POST[$key] == 'true' )
     32      {
     33        // The uploaded element was validated, we have to set the
     34        // "validated" field to "true"
     35        $query = 'UPDATE '.PREFIX_TABLE.'waiting';
     36        $query.= " SET validated = 'true'";
     37        $query.= ' WHERE id = '.$row['id'];
     38        $query.= ';';
     39        mysql_query( $query );
     40      }
     41      else
     42      {
     43        // The uploaded element was refused, we have to delete its reference
     44        // in the database and to delete the element as well.
     45        $query = 'DELETE FROM '.PREFIX_TABLE.'waiting';
     46        $query.= ' WHERE id = '.$row['id'];
     47        $query.= ';';
     48        mysql_query( $query );
     49        // deletion of the associated files
     50        $cat = get_cat_info( $row['cat_id'] );
     51        unlink( '.'.$cat['dir'].$row['file'] );
     52        if ( $row['tn_ext'] != '' )
     53        {
     54          $thumbnail = $conf['prefix_thumbnail'];
     55          $thumbnail.= get_filename_wo_extension( $row['file'] );
     56          $thumbnail.= '.'.$row['tn_ext'];
     57          $url = '.'.$cat['dir'].'thumbnail/'.$thumbnail;
     58          unlink( $url );
     59        }
     60      }
     61    }
     62  }
     63}
     64//----------------------------------------------------- template initialization
     65$sub = $vtp->Open( '../template/'.$user['template'].'/admin/waiting.vtp' );
     66$tpl = array( 'category','date','author','thumbnail','file','delete',
     67              'submit' );
     68templatize_array( $tpl, 'lang', $sub );
     69//---------------------------------------------------------------- form display
     70$cat_names = array();
     71$query = 'SELECT id,cat_id,file,username,mail_address,date,tn_ext';
     72$query.= ' FROM '.PREFIX_TABLE.'waiting';
     73$query.= " WHERE validated = 'false'";
     74$query.= ' ORDER BY cat_id';
     75$query.= ';';
     76$result = mysql_query( $query );
     77$i = 0;
     78while ( $row = mysql_fetch_array( $result ) )
     79{
     80  $vtp->addSession( $sub, 'picture' );
     81  $vtp->setVar( $sub, 'picture.id', $row['id'] );
     82  if ( $i++ % 2 == 0 )
     83  {
     84    $vtp->setVar( $sub, 'picture.class', 'row2' );
     85  }
     86  if ( !isset( $cat_names[$row['cat_id']] ) )
     87  {
     88    $cat = get_cat_info( $row['cat_id'] );
     89    $cat_names[$row['cat_id']] = array();
     90    $cat_names[$row['cat_id']]['dir'] = '.'.$cat['dir'];
     91    $cat_names[$row['cat_id']]['display_name'] =
     92      get_cat_display_name( $cat['name'], ' &gt; ', 'font-weight:bold;' );
     93  }
     94  // category name
     95  $vtp->setVar( $sub, 'picture.cat_name',
     96                $cat_names[$row['cat_id']]['display_name'] );
     97  // date displayed like this (in English ) :
     98  //                     Sunday 15 June 2003 21:29
     99  $date = $lang['day'][date( 'w', $row['date'] )];   // Sunday
     100  $date.= date( ' j ', $row['date'] );               // 15
     101  $date.= $lang['month'][date( 'n', $row['date'] )]; // June
     102  $date.= date( ' Y G:i', $row['date'] );            // 2003 21:29
     103  $vtp->setVar( $sub, 'picture.date', $date );
     104  // file preview link
     105  $url = $cat_names[$row['cat_id']]['dir'].$row['file'];
     106  $vtp->setVar( $sub, 'picture.preview_url', $url );
     107  // file name
     108  $vtp->setVar( $sub, 'picture.file', $row['file'] );
     109  // is there an existing associated thumnail ?
     110  if ( $row['tn_ext'] != '' )
     111  {
     112    $vtp->addSession( $sub, 'thumbnail' );
     113    $thumbnail = $conf['prefix_thumbnail'];
     114    $thumbnail.= get_filename_wo_extension( $row['file'] );
     115    $thumbnail.= '.'.$row['tn_ext'];
     116    $url = $cat_names[$row['cat_id']]['dir'].'thumbnail/'.$thumbnail;
     117    $vtp->setVar( $sub, 'thumbnail.preview_url', $url );
     118    $vtp->setVar( $sub, 'thumbnail.file', $thumbnail );
     119    $vtp->closeSession( $sub, 'thumbnail' );
     120  }
     121  else
     122  {
     123    $vtp->addSession( $sub, 'no_thumbnail' );
     124    $vtp->closeSession( $sub, 'no_thumbnail' );
     125  }
     126  // username and associated mail address
     127  $vtp->setVar( $sub, 'picture.mail_address', $row['mail_address'] );
     128  $vtp->setVar( $sub, 'picture.username', $row['username'] );
     129
     130  $vtp->closeSession( $sub, 'picture' );
     131}
     132//----------------------------------------------------------- sending html code
     133$vtp->Parse( $handle , 'sub', $sub );
    117134?>
  • trunk/category.php

    r20 r26  
    2121//----------------------------------------------------------- personnal include
    2222include_once( './include/init.inc.php' );
     23$output.= 'after init.inc.php : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    2324//-------------------------------------------------- access authorization check
     25// creating the plain structure : array of all the available categories and
     26// their relative informations, see the definition of the function
     27// get_plain_structure for further details.
     28$page['plain_structure'] = get_plain_structure();
     29
    2430check_cat_id( $_GET['cat'] );
    2531check_login_authorization();
     
    3541if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' )
    3642{
    37   $j = 0;
    38   $tab_expand = explode( ",", $_GET['expand'] );
    39   $size = sizeof( $tab_expand );
    40   for ( $i = 0; $i < $size; $i++ )
    41   {
    42     if ( is_numeric( $tab_expand[$i] ) )
    43     {
    44       $page['tab_expand'][$j++] = $tab_expand[$i];
    45     }
     43  $tab_expand = explode( ',', $_GET['expand'] );
     44  foreach ( $tab_expand as $id ) {
     45    if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id );
    4646  }
    4747  $page['expand'] = implode( ',', $page['tab_expand'] );
     
    5050// The $page['expand'] equals 'all' and
    5151// $page['tab_expand'] contains all the authorized cat ids
    52 if ( $user['expand'] == 'true' or $_GET['expand'] == 'all' )
     52if ( $user['expand'] or $_GET['expand'] == 'all' )
    5353{
    5454  $page['tab_expand'] = array();
    55   $query = 'SELECT id';
    56   $query.= ' FROM '.PREFIX_TABLE.'categories';
    57   $query.= ' WHERE id_uppercat IS NULL;';
    58   $result = mysql_query( $query );
    59   $i = 0;
    60   while ( $row = mysql_fetch_array( $result ) )
    61   {
    62     $page['tab_expand'][$i++] = $row['id'];
    63   }
    6455  $page['expand'] = 'all';
    6556}
     
    8475  $page['start']*= $user['nb_image_page'];
    8576}
     77// creating the structure of the categories (useful for displaying the menu)
     78$page['structure'] = create_structure( '', $user['restrictions'] );
     79$page['structure'] = update_structure( $page['structure'] );
    8680initialize_category();
     81$output.= 'before template init : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    8782//----------------------------------------------------- template initialization
    8883$vtp = new VTemplate;
    8984$handle = $vtp->Open( './template/'.$user['template'].'/category.vtp' );
    9085initialize_template();
    91 
    92 $tpl = array( 'categories','hint_category','sub-cat','images_available',
    93               'total','title_menu','nb_image_category','send_mail',
    94               'title_send_mail','generation_time','upload_name',
    95               'connected_user','recent_image','days','generation_time',
    96               'favorite_cat_hint','favorite_cat','stats',
    97               'most_visited_cat_hint','most_visited_cat','recent_cat',
    98               'recent_cat_hint' );
     86$output.= 'before lang array : '.get_elapsed_time( $t2, get_moment() ).'<br />';
     87$tpl = array(
     88  'categories','hint_category','sub-cat','images_available','total',
     89  'title_menu','nb_image_category','send_mail','title_send_mail',
     90  'generation_time','connected_user','recent_image','days','generation_time',
     91  'favorite_cat_hint','favorite_cat','stats','most_visited_cat_hint',
     92  'most_visited_cat','recent_cat','recent_cat_hint','upload_picture' );
    9993templatize_array( $tpl, 'lang', $handle );
     94$output.= 'after lang array : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    10095
    10196$tpl = array( 'mail_webmaster','webmaster','top_number','version','site_url' );
    10297templatize_array( $tpl, 'conf', $handle );
     98$output.= 'after conf array : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    10399
    104100$tpl = array( 'short_period','long_period','lien_collapsed', 'username' );
     
    112108$icon_long = get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) );
    113109$vtp->setGlobalVar( $handle, 'icon_long', $icon_long );
    114 $nb_total_pictures = get_total_image( "", $user['restrictions'] );
     110$nb_total_pictures = count_images( $page['structure'] );
    115111$vtp->setGlobalVar( $handle, 'nb_total_pictures',$nb_total_pictures );
    116112//------------------------------------------------------------- categories menu
     113$output.= 'before menu : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    117114// normal categories
    118 display_cat( '', '&nbsp;', $user['restrictions'], $page['tab_expand'] );
     115foreach ( $page['structure'] as $category ) {
     116  // display category is a function relative to the template
     117  display_category( $category, '&nbsp;', $handle );
     118}
     119$output.= 'after menu : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    119120// favorites cat
    120121if ( !$user['is_the_guest'] )
    121122{
    122123  $vtp->addSession( $handle, 'favorites' );
    123   $url = add_session_id('./category.php?cat=fav&amp;expand='.$page['expand'] );
    124   $vtp->setVar( $handle, 'favorites.url', $url );
     124  $url = './category.php?cat=fav&amp;expand='.$page['expand'];
     125  $vtp->setVar( $handle, 'favorites.url', add_session_id( $url ) );
    125126  // searching the number of favorite picture
    126127  $query = 'SELECT COUNT(*) AS count';
     
    133134}
    134135// most visited pictures category
    135 $url = add_session_id( './category.php?cat=most_visited'.
    136                        '&amp;expand='.$page['expand'] );
    137 $vtp->setGlobalVar( $handle, 'most_visited_url', $url );
     136$url = './category.php?cat=most_visited&amp;expand='.$page['expand'];
     137$vtp->setGlobalVar( $handle, 'most_visited_url', add_session_id( $url ) );
    138138// recent pictures
    139 $url = add_session_id( './category.php?cat=recent'.
    140                        '&amp;expand='.$page['expand'] );
    141 $vtp->setGlobalVar( $handle, 'recent_url', $url );
     139$url = './category.php?cat=recent&amp;expand='.$page['expand'];
     140$vtp->setGlobalVar( $handle, 'recent_url', add_session_id( $url ) );
    142141//--------------------------------------------------------------------- summary
    143142$vtp->addSession( $handle, 'summary' );
     
    146145{
    147146  $vtp->setVar( $handle, 'summary.title', '' );
    148   $vtp->setVar( $handle, 'summary.name',
    149                 replace_space( $lang['change_login'] ) );
     147  $vtp->setVar( $handle, 'summary.name',replace_space($lang['change_login']));
    150148}
    151149else
    152150{
    153151  $vtp->setVar( $handle, 'summary.title', $lang['hint_login'] );
    154   $vtp->setVar( $handle, 'summary.name',
    155                 replace_space( $lang['login'] ) );
     152  $vtp->setVar( $handle, 'summary.name',  replace_space( $lang['login'] ) );
    156153}
    157154$vtp->closeSession( $handle, 'summary' );
     
    186183// about link
    187184$vtp->addSession( $handle, 'summary' );
    188 $vtp->setVar( $handle, 'summary.url',
    189               add_session_id( './about.php?'.$_SERVER['QUERY_STRING'] ) );
     185$vtp->setVar( $handle, 'summary.url', './about.php?'.
     186              str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) );
    190187$vtp->setVar( $handle, 'summary.title', $lang['hint_about'] );
    191188$vtp->setVar( $handle, 'summary.name', replace_space( $lang['about'] ) );
     
    227224}
    228225//------------------------------------------------------------------ thumbnails
     226$output.= 'before thumbs : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    229227if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
    230228{
     
    318316      $query.= ' FROM '.PREFIX_TABLE.'comments';
    319317      $query.= ' WHERE image_id = '.$row['id'];
     318      $query.= " AND validated = 'true'";
    320319      $query.= ';';
    321320      $row = mysql_fetch_array( mysql_query( $query ) );
     
    342341  $vtp->closeSession( $handle, 'thumbnails' );
    343342}
    344 elseif ( isset( $page['cat'] )
    345          and is_numeric( $page['cat'] )
    346          and $page['cat_nb_images'] == 0 )
     343//-------------------------------------------------------------- empty category
     344elseif ( ( isset( $page['cat'] )
     345           and is_numeric( $page['cat'] )
     346           and $page['cat_nb_images'] == 0 )
     347         or $_GET['cat'] == '' )
    347348{
    348349  $vtp->addSession( $handle, 'thumbnails' );
    349350  $vtp->addSession( $handle, 'line' );
    350351
    351   $subcats = get_non_empty_sub_cat_ids( $page['cat'] );
     352  $subcats = get_non_empty_subcat_ids( $page['cat'] );
    352353  $cell_number = 1;
    353   foreach ( $subcats as $id => $subcat ) {
    354     $result = get_cat_info( $subcat['non_empty_cat'] );
    355     $cat_directory = $result['dir'];
    356 
    357     $name = '[ <span style="font-weight:bold;">';
    358     if ( $subcat['name'] != '' )
    359     {
    360       $name.= $subcat['name'];
    361     }
    362     else
    363     {
    364       $name.= $subcat['dir'];
    365     }
     354  $i = 0;
     355  foreach ( $subcats as $subcat_id => $non_empty_id ) {
     356    $subcat_infos    = get_cat_info( $subcat_id );
     357    $non_empty_infos = get_cat_info( $non_empty_id );
     358
     359    $name ='[ <span style="font-weight:bold;">';
     360    $name.= $subcat_infos['name'][0];
    366361    $name.= '</span> ]';
    367     $name = replace_space( $name );
    368362   
    369363    $query = 'SELECT file,tn_ext';
    370364    $query.= ' FROM '.PREFIX_TABLE.'images';
    371     $query.= ' WHERE cat_id = '.$subcat['non_empty_cat'];
     365    $query.= ' WHERE cat_id = '.$non_empty_id;
    372366    $query.= ' ORDER BY RAND()';
    373367    $query.= ' LIMIT 0,1';
    374368    $query.= ';';
    375369    $image_result = mysql_query( $query );
    376     $image_row = mysql_fetch_array( $image_result );
     370    $image_row    = mysql_fetch_array( $image_result );
    377371
    378372    $file = get_filename_wo_extension( $image_row['file'] );
    379373
    380374    // creating links for thumbnail and associated category
    381     $lien_image = $cat_directory;
    382     $lien_thumbnail = $lien_image;
    383     $lien_thumbnail.= 'thumbnail/'.$conf['prefix_thumbnail'];
    384     $lien_thumbnail.= $file.'.'.$image_row['tn_ext'];
    385     $lien_image.= $image_row['file'];
     375    $thumbnail_link = $non_empty_infos['dir'];
     376    $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
     377    $thumbnail_link.= $file.'.'.$image_row['tn_ext'];
    386378
    387379    $thumbnail_title = $lang['hint_category'];
    388380
    389     $url_link = './category.php?cat='.$subcat['id'];
     381    $url_link = './category.php?cat='.$subcat_id;
    390382    if ( !in_array( $page['cat'], $page['tab_expand'] ) )
    391383    {
     
    394386    }
    395387    $url_link.= '&amp;expand='.$page['expand'];
    396     list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] );
     388    list( $year,$month,$day ) = explode( '-', $subcat_infos['date_last'] );
    397389    $date = mktime( 0, 0, 0, $month, $day, $year );
    398390
     
    400392    $vtp->addSession( $handle, 'thumbnail' );
    401393    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
    402     $vtp->setVar( $handle, 'thumbnail.src', $lien_thumbnail );
     394    $vtp->setVar( $handle, 'thumbnail.src', $thumbnail_link );
    403395    $vtp->setVar( $handle, 'thumbnail.alt', $image_row['file'] );
    404396    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
     
    412404      $cell_number = 1;
    413405      // we open a new line if the subcat was not the last one
    414       if ( $id < count( $subcats ) - 1 )
     406      if ( $i++ < count( $subcats ) - 1 )
    415407      {
    416408        $vtp->addSession( $handle, 'line' );
     
    418410    }
    419411  }
    420   if ( $id < count( $subcats ) - 1 )
     412  if ( $i < count( $subcats ) - 1 )
    421413  {
    422414    $vtp->closeSession( $handle, 'line' );
     
    424416  $vtp->closeSession( $handle, 'thumbnails' );
    425417}
     418$output.= 'after thumbs : '.get_elapsed_time( $t2, get_moment() ).'<br />';
    426419//------------------------------------------------------- category informations
    427420if ( isset ( $page['cat'] ) )
     
    470463//----------------------------------------------------------- html code display
    471464$code = $vtp->Display( $handle, 0 );
     465echo $output;
    472466echo $code;
    473467?>
  • trunk/identification.php

    r10 r26  
    5858$vtp->setGlobalVar( $handle, 'mail_webmaster',   $conf['mail_webmaster'] );
    5959// user
    60 $vtp->setGlobalVar( $handle, 'page_style',       $user['style'] );
    61 $vtp->setGlobalVar( $handle, 'user_theme',       $user['theme'] );
    62 // structure
    63 $vtp->setGlobalVar( $handle, 'frame_start',      get_frame_start() );
    64 $vtp->setGlobalVar( $handle, 'frame_begin',      get_frame_begin() );
    65 $vtp->setGlobalVar( $handle, 'frame_end',        get_frame_end() );
     60$vtp->setGlobalVar( $handle, 'user_template',    $user['template'] );
     61initialize_template();
    6662//-------------------------------------------------------------- errors display
    6763if ( sizeof( $error ) != 0 )
  • trunk/include/config.inc.php

    r21 r26  
    2323include_once( PREFIX_INCLUDE.'./include/functions.inc.php' );
    2424include_once( PREFIX_INCLUDE.'./include/vtemplate.class.php' );
    25 
    2625// How to change the order of display for images in a category ?
    2726//
     
    4039$conf['order_by'] = ' ORDER BY date_available DESC, file ASC';
    4140
    42 $conf['nb_image_row']       = array('4','5','6','7','8');
    43 $conf['nb_row_page']        = array('2','3','4','5','6','7','10','20','1000');
     41$conf['nb_image_row']       = array(4,5,6,7,8);
     42$conf['nb_row_page']        = array(2,3,4,5,6,7,10,20,1000);
     43$conf['slideshow_period']   = array(2,5,10);
     44$conf['last_days']          = array(1,2,3,10,30,365);
    4445$conf['version']            = '1.3';
    4546$conf['site_url']           = 'http://www.phpwebgallery.net';
     
    5960                'upload_available', 'upload_maxfilesize', 'upload_maxwidth',
    6061                'upload_maxheight', 'upload_maxwidth_thumbnail',
    61                 'upload_maxheight_thumbnail' );
     62                'upload_maxheight_thumbnail','log','comments_validation' );
    6263
    63 $query  = 'SELECT';
     64$query  = 'SELECT ';
    6465foreach ( $infos as $i => $info ) {
    6566  if ( $i > 0 ) $query.= ',';
    66   else          $query.= ' ';
    6767  $query.= $info;
    6868}
     
    8282  }
    8383}
    84 $conf['log']        = false;
    8584$conf['top_number'] = 20;
    8685?>
  • trunk/include/functions.inc.php

    r21 r26  
    6767function array_remove( $array, $value )
    6868{
    69   $i = 0;
    7069  $output = array();
    71   foreach ( $array as $v )
    72     {
    73       if ( $v != $value )
    74       {
    75         $output[$i++] = $v;
    76       }
    77     }
    78   return implode( ',', $output );
     70  foreach ( $array as $v ) {
     71    if ( $v != $value )
     72    {
     73      array_push( $output, $v );
     74    }
     75  }
     76  return $output;
    7977}
    8078
     
    321319function database_connection()
    322320{
    323 //   $xml_content = getXmlCode( PREFIXE_INCLUDE.'./include/database_config.xml' );
    324 //   $mysql_conf = getChild( $xml_content, 'mysql' );
    325 
    326 //   $cfgHote     = getAttribute( $mysql_conf, 'host' );
    327 //   $cfgUser     = getAttribute( $mysql_conf, 'user' );
    328 //   $cfgPassword = getAttribute( $mysql_conf, 'password' );
    329 //   $cfgBase     = getAttribute( $mysql_conf, 'base' );
    330 //   define( PREFIX_TABLE, getAttribute( $mysql_conf, 'tablePrefix' ) );
    331 
    332321  include( PREFIX_INCLUDE.'./include/mysql.inc.php' );
    333322  define( PREFIX_TABLE, $prefix_table );
     
    347336    $query = 'insert into '.PREFIX_TABLE.'history';
    348337    $query.= ' (date,login,IP,file,category,picture) values';
    349     $query.= " (".time().", '".$user['pseudo']."'";
     338    $query.= " (".time().", '".$user['username']."'";
    350339    $query.= ",'".$_SERVER['REMOTE_ADDR']."'";
    351340    $query.= ",'".$file."','".$category."','".$picture."');";
     
    358347  global $vtp, $lang, $page, $user, $conf;
    359348
    360   for( $i = 0; $i < sizeof( $array ); $i++ )
    361   {
    362     $vtp->setGlobalVar( $handle, $array[$i],
    363                         ${$global_array_name}[$array[$i]] );
     349  foreach ( $array as $value ) {
     350    $vtp->setGlobalVar( $handle, $value, ${$global_array_name}[$value] );
    364351  }
    365352}
  • trunk/include/functions_category.inc.php

    r21 r26  
    6060  if ( isset( $cat ) )
    6161  {
    62     if ( is_numeric( $cat ) )
    63     {
    64       $query = 'select id';
    65       $query.= ' from '.PREFIX_TABLE.'categories';
    66       $query.= ' where id = '.$cat;
     62    if ( isset( $page['plain_structure'] ) )
     63    {
     64      if ( isset( $page['plain_structure'][$cat] ) )
     65      {
     66        $page['cat'] = $cat;
     67      }
     68    }
     69    else if ( is_numeric( $cat ) )
     70    {
     71      $query = 'SELECT id';
     72      $query.= ' FROM '.PREFIX_TABLE.'categories';
     73      $query.= ' WHERE id = '.$cat;
    6774      $query. ';';
    6875      $result = mysql_query( $query );
     
    7279      }
    7380    }
    74     if ( $cat == 'fav' or $cat == 'search' or $cat == 'most_visited'
    75          or $cat == 'best_rated' or $cat == 'recent' )
     81    if ( $cat == 'fav'
     82         or $cat == 'search'
     83         or $cat == 'most_visited'
     84         or $cat == 'best_rated'
     85         or $cat == 'recent' )
    7686    {
    7787      $page['cat'] = $cat;
     
    8090}
    8191
    82 function display_cat( $id_uppercat, $indent, $restriction, $tab_expand )
    83 {
    84   global $user,$lang,$conf,$page,$vtp,$handle;
     92function get_plain_structure()
     93{
     94  $infos = array( 'name','id','date_last','nb_images','dir','id_uppercat',
     95                  'rank');
    8596 
    86   $query = 'select name,id,date_dernier,nb_images,dir';
    87   $query.= ' from '.PREFIX_TABLE.'categories';
    88   $query.= ' where id_uppercat';
    89   if ( $id_uppercat == "" )
    90   {
    91     $query.= ' is NULL';
    92   }
    93   else
    94   {
    95     $query.= ' = '.$id_uppercat;
    96   }
    97   $query.= ' order by rank asc;';
     97  $query = 'SELECT ';
     98  foreach ( $infos as $i => $info ) {
     99    if ( $i > 0 ) $query.= ',';
     100    $query.= $info;
     101  }
     102  $query.= ' FROM '.PREFIX_TABLE.'categories';
     103  $query.= ' ORDER BY id_uppercat ASC, rank ASC';
     104  $query.= ';';
     105
     106  $plain_structure = array();
    98107  $result = mysql_query( $query );
    99108  while ( $row = mysql_fetch_array( $result ) )
    100109  {
    101     if ( !in_array( $row['id'], $restriction ) )
    102     {
    103       $nb_subcats = get_nb_subcats( $row['id'] );
    104                                
    105       $expand = "";
    106       // si la catégorie n'a pas de sous catégorie
    107       // ou que l'on doit développer toutes les catégories par défaut
    108       // alors on utilise l'expand par défaut
    109       if ( $nb_subcats == 0 or $user['expand'] == "true" )
    110       {
    111         $expand = $page['expand'];
    112       }
    113       // si la catégorie n'est pas dans les catégories à développer
    114       // alors on l'ajoute aux catégories à développer
    115       else if ( !in_array( $row['id'], $tab_expand ) )
    116       {
    117         $expand = implode( ",", $tab_expand );
    118         if ( strlen( $expand ) > 0 )
    119         {
    120           $expand.= ",";
    121         }
    122         $expand.= $row['id'];
    123       }
    124       // si la catégorie est déjà dans les catégories à développer
    125       // alors on la retire des catégories à développer
    126       else
    127       {
    128         $expand = array_remove( $tab_expand, $row['id'] );
    129       }
    130       $url = "./category.php?cat=".$page['cat']."&amp;expand=$expand";
    131       if ( $page['cat'] == 'search' )
    132       {
    133         $url.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
    134       }
    135       $lien_cat = add_session_id( $url );
    136       if ( $row['name'] == "" )
    137       {
    138         $name = str_replace( "_", " ", $row['dir'] );
    139       }
    140       else
    141       {
    142         $name = $row['name'];
    143       }
    144 
    145       $vtp->addSession( $handle, 'category' );
    146       $vtp->setVar( $handle, 'category.indent', $indent );
    147 
    148       if ( $user['expand'] == "true" or $nb_subcats == 0 )
    149       {
    150         $vtp->addSession( $handle, 'bullet_wo_link' );
    151         $vtp->setVar( $handle, 'bullet_wo_link.bullet_url',
    152                       $user['lien_collapsed'] );
    153         $vtp->setVar( $handle, 'bullet_wo_link.bullet_alt', '&gt;' );
    154         $vtp->closeSession( $handle, 'bullet_wo_link' );
    155       }
    156       else
    157       {
    158         $vtp->addSession( $handle, 'bullet_w_link' );
    159         $vtp->setVar( $handle, 'bullet_w_link.bullet_link', $lien_cat );
    160         $vtp->setVar( $handle, 'bullet_w_link.bullet_alt', '&gt;' );
    161         if ( in_array( $row['id'], $tab_expand ) )
    162         {
    163           $vtp->setVar( $handle, 'bullet_w_link.bullet_url',
    164                         $user['lien_expanded'] );
    165         }
    166         else
    167         {
    168           $vtp->setVar( $handle, 'bullet_w_link.bullet_url',
    169                         $user['lien_collapsed'] );
    170         }
    171         $vtp->closeSession( $handle, 'bullet_w_link' );
    172       }
    173       $vtp->setVar( $handle, 'category.link_url',
    174                     add_session_id( './category.php?cat='.
    175                                     $row['id'].'&amp;expand='.$expand ) );
    176       $vtp->setVar( $handle, 'category.link_name', $name );
    177       if ( $id_uppercat == "" )
    178       {
    179         $vtp->setVar( $handle, 'category.name_style', 'font-weight:bold;' );
    180       }
    181       if ( $nb_subcats > 0 )
    182       {
    183         $vtp->addSession( $handle, 'subcat' );
    184         $vtp->setVar( $handle, 'subcat.nb_subcats', $nb_subcats );
    185         $vtp->closeSession( $handle, 'subcat' );
    186       }
    187       $vtp->setVar( $handle, 'category.total_cat', $row['nb_images'] );
    188       $date_dispo = explode( "-", $row['date_dernier'] );
    189       $date_cat = mktime( 0, 0, 0, $date_dispo[1], $date_dispo[2],
    190                           $date_dispo[0] );
    191       $vtp->setVar( $handle, 'category.cat_icon', get_icon( $date_cat ) );
    192       $vtp->closeSession( $handle, 'category' );
    193 
    194       if ( in_array( $row['id'], $tab_expand ) or $user['expand'] == "true" )
    195       {
    196         display_cat( $row['id'], $indent.'&nbsp;&nbsp;&nbsp;&nbsp;',
    197                      $restriction, $tab_expand );
    198       }
    199     }
    200   }
    201 }
    202        
    203 function get_nb_subcats( $id )
    204 {
    205   global $user;
    206                
    207   $query = 'select count(*) as count';
    208   $query.= ' from '.PREFIX_TABLE.'categories';
    209   $query.= ' where id_uppercat = '.$id;
    210   for ( $i = 0; $i < sizeof( $user['restrictions'] ); $i++ )
    211   {
    212     $query.= " and id != ".$user['restrictions'][$i];
    213   }
    214   $query.= ';';
    215   $result = mysql_query( $query );
    216   $row = mysql_fetch_array( $result );
    217   return $row['count'];
    218 }
    219        
    220 function get_total_image( $id, $restriction )
     110    $category = array();
     111    foreach ( $infos as $info ) {
     112      $category[$info] = $row[$info];
     113      if ( $info == 'date_last' )
     114      {
     115        list($year,$month,$day) = explode( '-', $row[$info] );
     116        $category[$info] = mktime(0,0,0,$month,$day,$year);
     117      }
     118    }
     119    $plain_structure[$row['id']] = $category;
     120  }
     121
     122  return $plain_structure;
     123}
     124
     125function create_structure( $id_uppercat, $restrictions )
     126{
     127  global $page;
     128
     129  $structure = array();
     130  $ids = get_subcat_ids( $id_uppercat );
     131  foreach ( $ids as $id ) {
     132    if ( !in_array( $id, $restrictions ) )
     133    {
     134      $category = $page['plain_structure'][$id];
     135      $category['subcats'] = create_structure( $id, $restrictions );
     136      array_push( $structure, $category );
     137    }
     138  }
     139  return $structure;
     140}
     141
     142function get_subcat_ids( $id_uppercat )
     143{
     144  global $page;
     145
     146  $ids = array();
     147  foreach ( $page['plain_structure'] as $id => $category ) {
     148    if ( $category['id_uppercat'] == $id_uppercat ) array_push( $ids, $id );
     149    else if ( count( $ids ) > 0 )                   return $ids;
     150  }
     151  return $ids;
     152}
     153
     154// update_structure updates or add informations about each node of the
     155// structure : the last date, should the category be expanded in the menu ?,
     156// the associated expand string "48,14,54"
     157//
     158// 1. last date
     159// for each category of the structure, we have to find the most recent
     160// subcat so that the parent cat has the same last_date info.
     161// For example : we have :
     162// > pets       (2003.02.15)
     163//    > dogs    (2003.06.14)
     164//       > rex  (2003.06.18)
     165//       > toby (2003.06.13)
     166//    > kitten  (2003.07.05)
     167// We finally want to have :
     168// > pets       (2003.07.05) <- changed to pets > kitten last date
     169//    > dogs    (2003.06.18) <- changed to pets > dogs > rex last date
     170//       > rex  (2003.06.18)
     171//       > toby (2003.06.13)
     172//    > kitten  (2003.07.05)
     173//
     174// 2. should the category be expanded in the menu ?
     175// If the category has to be expanded (ie its id is in the
     176// $page['tab_expand'] or all the categories must be expanded by default),
     177// $category['expanded'] is set to true.
     178//
     179// 3. associated expand string
     180// in the menu, there is a expand string (used in the URL) to tell which
     181// categories must be expanded in the menu if this category is chosen
     182function update_structure( $categories )
     183{
     184  global $page, $user;
     185
     186  $updated_categories = array();
     187
     188  foreach ( $categories as $category ) {
     189    // update the last date of the category
     190    $last_date = search_last_date( $category );
     191    $category['date_last'] = $last_date;
     192    // update the "expanded" key
     193    if ( $user['expand']
     194         or $page['expand'] == 'all'
     195         or in_array( $category['id'], $page['tab_expand'] ) )
     196    {
     197      $category['expanded'] = true;
     198    }
     199    else
     200    {
     201      $category['expanded'] = false;
     202    }
     203    // update the  "expand_string" key
     204    if ( $page['expand'] == 'all' )
     205    {
     206      $category['expand_string'] = 'all';
     207    }
     208    else
     209    {
     210      $tab_expand = $page['tab_expand'];
     211      if ( in_array( $category['id'], $page['tab_expand'] ) )
     212      {
     213        // the expand string corresponds to the $page['tab_expand'] without
     214        // the $category['id']
     215        $tab_expand = array_diff( $page['tab_expand'],array($category['id']) );
     216      }
     217      else if ( count( $category['subcats'] ) > 0 )
     218      {
     219        // we have this time to add the $category['id']...
     220        $tab_expand = array_merge($page['tab_expand'],array($category['id']));
     221      }
     222      $category['expand_string'] = implode( ',', $tab_expand );
     223    }
     224    // recursive call
     225    $category['subcats'] = update_structure( $category['subcats'] );
     226    // adding the updated category
     227    array_push( $updated_categories, $category );
     228  }
     229
     230  return $updated_categories;
     231}
     232
     233// search_last_date searchs the last date for a given category. If we take
     234// back the example given for update_last_dates, we should have :
     235// search_last_date( pets )        --> 2003.07.05
     236// search_last_date( pets > dogs ) --> 2003.06.18
     237// and so on
     238function search_last_date( $category )
     239{
     240  $date_last = $category['date_last'];
     241  foreach ( $category['subcats'] as $subcat ) {
     242    $subcat_date_last = search_last_date( $subcat );
     243    if ( $subcat_date_last > $date_last )
     244    {
     245      $date_last = $subcat_date_last;
     246    }
     247  }
     248  return $date_last;
     249}
     250
     251// count_images returns the number of pictures contained in the given
     252// category represented by an array, in this array, we have (among other
     253// things) :
     254// $category['nb_images'] -> number of pictures in this category
     255// $category['subcats'] -> array of sub-categories
     256// count_images goes to the deepest sub-category to find the total number of
     257// pictures contained in the given given category
     258function count_images( $categories )
    221259{
    222260  $total = 0;
    223                
    224   $query = 'select id,nb_images';
    225   $query.= ' from '.PREFIX_TABLE.'categories';
    226   $query.= ' where id_uppercat';
    227   if ( !is_numeric( $id ) )
    228   {
    229     $query.= ' is NULL';
    230   }
    231   else
    232   {
    233     $query.= ' = '.$id;
    234   }
    235   $query.= ";";
    236   $result = mysql_query( $query );
    237   while ( $row = mysql_fetch_array( $result ) )
    238   {
    239     if ( !in_array( $row['id'], $restriction ) )
    240     {
    241       $total+= $row['nb_images'];
    242       $total+= get_total_image( $row['id'], $restriction );
    243     }
     261  foreach ( $categories as $category ) {
     262    $total+= $category['nb_images'];
     263    $total+= count_images( $category['subcats'] );
    244264  }
    245265  return $total;
     
    262282  $cat['name'] = array();
    263283               
    264   $query = 'select nb_images,id_uppercat,comment,site_id,galleries_url,dir';
    265   $query.= ' from '.PREFIX_TABLE.'categories as a';
    266   $query.= ', '.PREFIX_TABLE.'sites as b';
    267   $query.= ' where a.id = '.$id;
    268   $query.= ' and a.site_id = b.id;';
     284  $query = 'SELECT nb_images,id_uppercat,comment,site_id,galleries_url,dir';
     285  $query.= ',date_last';
     286  $query.= ' FROM '.PREFIX_TABLE.'categories AS a';
     287  $query.= ', '.PREFIX_TABLE.'sites AS b';
     288  $query.= ' WHERE a.id = '.$id;
     289  $query.= ' AND a.site_id = b.id;';
    269290  $row = mysql_fetch_array( mysql_query( $query ) );
    270291  $cat['site_id']     = $row['site_id'];
     
    273294  $cat['nb_images']   = $row['nb_images'];
    274295  $cat['last_dir']    = $row['dir'];
     296  $cat['date_last']   = $row['date_last'];
    275297  $galleries_url = $row['galleries_url'];
    276298               
     
    281303  while ( !$is_root )
    282304  {
    283     $query = 'select name,dir,id_uppercat';
    284     $query.= ' from '.PREFIX_TABLE.'categories';
    285     $query.= ' where id = '.$row['id_uppercat'].';';
     305    $query = 'SELECT name,dir,id_uppercat';
     306    $query.= ' FROM '.PREFIX_TABLE.'categories';
     307    $query.= ' WHERE id = '.$row['id_uppercat'].';';
    286308    $row = mysql_fetch_array( mysql_query( $query ) );
    287     $cat['dir'] = $row['dir']."/".$cat['dir'];
     309    $cat['dir'] = $row['dir'].'/'.$cat['dir'];
    288310    if ( $row['name'] == "" )
    289311    {
     
    503525}
    504526
    505 // get_non_empty_sub_cat_ids returns an array composing of the infos of the
    506 // direct sub-categories of the given uppercat id. Each of these infos is
    507 // associated to the first found non empty category id. eg :
     527// get_non_empty_subcat_ids returns an array with sub-categories id
     528// associated with their first non empty category id.
     529//
     530//                          example :
    508531//
    509532// - catname [cat_id]
    510533// - cat1 [1] -> given uppercat
    511 //   - cat1.1 [2] (empty)
     534//   - cat1.1 [12] (empty)
    512535//     - cat1.1.1 [5] (empty)
    513536//     - cat1.1.2 [6]
     
    516539//
    517540// get_non_empty_sub_cat_ids will return :
    518 //   $cats[0]['id']            = 2;
    519 //   $cats[0]['name']          = '';
    520 //   $cats[0]['dir']           = 'cat1';
    521 //   $cats[0]['date_dernier']  = '2003-05-17';
    522 //   $cats[0]['non_empty_cat'] = 6;
    523 //
    524 //   $cats[1]['id']            = 3;
    525 //   $cats[1]['non_empty_cat'] = 3;
    526 //
    527 //   $cats[1]['id']            = 4;
    528 //   $cats[1]['non_empty_cat'] = 4;
    529 function get_non_empty_sub_cat_ids( $id_uppercat )
     541//   $ids[12] = 6;
     542//   $ids[3]  = 3;
     543//   $ids[4]  = 4;
     544function get_non_empty_subcat_ids( $id_uppercat )
    530545{
    531546  global $user;
    532547
    533   $cats = array();
    534 
    535   $query = 'SELECT id,name,dir,date_dernier,nb_images';
     548  $ids = array();
     549
     550  $query = 'SELECT id,nb_images';
    536551  $query.= ' FROM '.PREFIX_TABLE.'categories';
    537   $query.= ' WHERE id_uppercat = '.$id_uppercat;
     552  $query.= ' WHERE id_uppercat ';
     553  if ( !is_numeric( $id_uppercat ) ) $query.= 'is NULL';
     554  else                               $query.= '= '.$id_uppercat;
    538555  // we must not show pictures of a forbidden category
    539   $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
    540   foreach ( $restricted_cats as $restricted_cat ) {
     556  foreach ( $user['restrictions'] as $restricted_cat ) {
    541557    $query.= ' AND id != '.$restricted_cat;
    542558  }
     
    552568         or $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ) )
    553569    {
    554       $temp_cat = array(
    555         'id'            => $row['id'],
    556         'name'          => $row['name'],
    557         'dir'           => $row['dir'],
    558         'date_dernier'  => $row['date_dernier'],
    559         'non_empty_cat' => $non_empty_cat );
    560       array_push( $cats, $temp_cat );
    561     }
    562   }
    563   return $cats;
     570      $ids[$row['id']] = $non_empty_cat;
     571    }
     572  }
     573  return $ids;
    564574}
    565575
     
    575585  $query.= ' WHERE id_uppercat = '.$id_uppercat;
    576586  // we must not show pictures of a forbidden category
    577   $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
    578   foreach ( $restricted_cats as $restricted_cat ) {
     587  foreach ( $user['restrictions'] as $restricted_cat ) {
    579588    $query.= ' AND id != '.$restricted_cat;
    580589  }
  • trunk/include/functions_user.inc.php

    r21 r26  
    314314{
    315315  $lowest_category_id = $category_id;
    316                
     316
    317317  $is_root = false;
    318318  while ( !$is_root and !in_array( $category_id, $restrictions ) )
     
    323323    $query.= ';';
    324324    $row = mysql_fetch_array( mysql_query( $query ) );
    325     if ( $row['id_uppercat'] == '' )
    326     {
    327       $is_root = true;
    328     }
     325    if ( $row['id_uppercat'] == '' ) $is_root = true;
    329326    $category_id = $row['id_uppercat'];
    330327  }
    331                
    332   if ( in_array( $lowest_category_id, $restrictions ) )
    333   {
    334     return 1;
    335   }
    336   if ( in_array( $category_id, $restrictions ) )
    337   {
    338     return 2;
    339   }
     328
     329  if ( in_array( $lowest_category_id, $restrictions ) ) return 1;
     330  if ( in_array( $category_id,        $restrictions ) ) return 2;
    340331  // this user is allowed to go in this category
    341332  return 0;
  • trunk/include/init.inc.php

    r21 r26  
    1919include_once( './include/config.inc.php' );
    2020include_once( './include/user.inc.php' );
    21        
    22 include( './theme/'.$user['theme'].'/conf.php' );
    23 $user['lien_expanded']  = './theme/'.$user['theme'].'/expanded.gif';
    24 $user['lien_collapsed'] = './theme/'.$user['theme'].'/collapsed.gif';
     21
    2522// calculation of the number of picture to display per page
    2623$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
     
    3633  $user['username'] = $lang['guest'];
    3734}
    38 include_once( './template/'.$user['template'].'/style.inc.php' );
    3935include_once( './template/'.$user['template'].'/htmlfunctions.inc.php' );
    4036?>
  • trunk/include/user.inc.php

    r21 r26  
    2121//            status --> $user['status']
    2222$infos = array( 'id', 'username', 'mail_address', 'nb_image_line',
    23                 'nb_line_page', 'status', 'theme', 'language', 'maxwidth',
     23                'nb_line_page', 'status', 'language', 'maxwidth',
    2424                'maxheight', 'expand', 'show_nb_comments', 'short_period',
    2525                'long_period', 'template' );
    2626
    27 $query_user  = 'SELECT';
    28 for ( $i = 0; $i < sizeof( $infos ); $i++ )
    29 {
    30   if ( $i > 0 )
    31   {
    32     $query_user.= ',';
    33   }
    34   else
    35   {
    36     $query_user.= ' ';
    37   }
    38   $query_user.= $infos[$i];
     27$query_user  = 'SELECT ';
     28foreach ( $infos as $i => $info ) {
     29  if ( $i > 0 ) $query_user.= ',';
     30  $query_user.= $info;
    3931}
    4032$query_user.= ' FROM '.PREFIX_TABLE.'users';
  • trunk/language/francais.php

    r21 r26  
    11<?php
     2// start version 1.3
     3$lang['charset'] = 'Shift_JIS';//'ISO_8859-1';
     4// end version 1.3
    25$lang['only_members'] = 'Seuls les membres du site peuvent accéder à cette page';
    36$lang['invalid_pwd'] = 'le mot de passe rentré n\'est pas valide';
     
    2023$lang['add'] = 'ajouter';
    2124$lang['dissociate'] = 'dissocier';
     25$lang['mandatory'] = 'obligatoire';
     26$lang['err_date'] = 'date erronée';
     27$lang['picture'] = 'image';
     28$lang['IP'] = 'IP';
     29$lang['close'] = 'fermer';
     30$lang['open'] = 'ouvrir';
    2231// end version 1.3
    2332
     
    133142$lang['err_maxwidth'] = 'la largeur maximum des images doit être un entier supérieur à 50';
    134143$lang['err_maxheight'] = 'la hauteur maximum des images doit être un entier supérieur à 50';
    135        
    136 // page photo
     144
     145// picture.php
    137146$lang['previous_image'] = 'Précédent';
    138147$lang['next_image'] = 'Suivant';
     
    167176$lang['del_favorites_alt'] = 'Retirer des favoris';
    168177$lang['del_favorites_hint'] = 'supprimer cette image de vos favoris';
    169        
     178// start version 1.3
     179$lang['slideshow'] = 'diaporama';
     180$lang['period_seconds'] = 'secondes par image';
     181$lang['slideshow_stop'] = 'stopper le diaporama';
     182$lang['comment_added'] = 'Votre commentaire a été enregistré';
     183$lang['comment_to_validate'] = 'Un administrateur doit valider votre commentaire pour qu\'il soit visible';
     184// end version 1.3
     185
    170186// page register
    171187$lang['register_page_title'] = 'Enregistrement';
     
    209225$lang['upload_username'] = 'Nom d\'utilisateur';
    210226$lang['upload_successful'] = 'Image uploadée avec succès, un administrateur validera celle-ci dès que possible.';
     227// start version 1.3
     228$lang['upload_name'] = 'Nom de l\'image';
     229$lang['upload_author'] = 'Auteur (eg "Pierrick LE GALL")';
     230$lang['upload_creation_date'] = 'Date de création (JJ/MM/AAAA)';
     231$lang['upload_comment'] = 'Commentaire';
     232// end version 1.3
    211233
    212234//----------------------------------administration
     
    235257  $lang['title_cat_perm'] = 'Modifier les permissions pour la catégorie';
    236258  $lang['title_group_perm'] = 'Modifier les permissions pour le groupe';
     259  $lang['title_comments'] = 'Commentaires des visiteurs';
    237260// end version 1.3
    238261  $lang['title_categories'] = 'Gestion des catégories';
     
    256279// start version 1.3
    257280  $lang['menu_groups'] = 'Groupes';
     281  $lang['menu_comments'] = 'Commentaires';
    258282// end version 1.3
    259283 
     
    307331//  $lang['conf_general_expand'] = 'développer toutes les catégories';
    308332//  $lang['conf_general_expand_info'] = 'développer toutes les catégories par défaut dans le menu ?';
     333  $lang['conf_general_log'] = 'historique';
     334  $lang['conf_general_log_info'] = 'historiser les visites sur le site ? Les visites seront visibles dans l\'historique de l\'administration';
    309335  // end version 1.3
    310336  $lang['conf_comments'] = 'commentaires utilisateurs';
     
    316342  $lang['conf_err_comment_number'] = 'le nombre de commentaires par page doit être compris entre 5 et 50 inclus.';
    317343// start version 1.3
     344  $lang['conf_comments_validation'] = 'validation';
     345  $lang['conf_comments_validation_info'] = 'L\'administrateur valide les commentaires avant qu\'ils apparaissent sur le site';
    318346  // $lang['conf_remote_site_title'] = 'Site distant';
    319347// end version 1.3
     
    337365  $lang['conf_upload_maxheight_thumbnail_info'] = 'Hauteur maximum autorisée pour les miniatures. Celle-ci doit être un entier supérieur à 10, en pixels.';
    338366  $lang['conf_err_upload_maxheight_thumbnail'] = 'la hauteur maximum des miniatures uploadées doit être un entier supérieur à 10.';
    339                
     367
    340368  $lang['conf_default_title'] = 'Affichage par défaut pour les visiteurs non enregistrés et les nouveaux comptes';
    341369  // start version 1.3
     
    463491// end version 1.3
    464492  // page info images
    465   $lang['infoimage_err_date'] = 'date erronée';
     493// start version 1.3
     494  // $lang['infoimage_err_date'] = 'date erronée';
     495// end version 1.3
    466496  $lang['infoimage_general'] = 'Options générale pour la catégorie';
    467497  $lang['infoimage_useforall'] = 'utiliser pour toutes les images ?';
     
    494524  $lang['tn_err_width'] = 'la largeur doit être un entier supérieur à';
    495525  $lang['tn_err_height'] = 'la hauteur doit être un entier supérieur à';
    496   $lang['tn_err_GD'] = 'il faut choisir une version de GD';
     526// start version 1.3
     527  // $lang['tn_err_GD'] = 'il faut choisir une version de GD';
     528// end version 1.3
    497529               
    498530  $lang['tn_results_title'] = 'Résultats de la miniaturisation';
    499531  $lang['tn_picture'] = 'image';
    500   $lang['tn_filesize'] = 'poids';
     532// start version 1.3
     533  // $lang['tn_filesize'] = 'poids';
     534// end version 1.3
    501535  $lang['tn_results_gen_time'] = 'généré en';
    502536               
     
    524558  $lang['tn_dirs_title'] = 'Liste des répertoires';
    525559  $lang['tn_dirs_alone'] = 'images sans miniatures';
    526                
     560
     561// start version 1.3
     562  $lang['stats_last_days'] = 'derniers jours';
     563  $lang['stats_pages_seen'] = 'pages vues';
     564  $lang['stats_visitors'] = 'visiteurs';
     565  $lang['stats_empty'] = 'vider l\'historique';
     566  $lang['stats_pages_seen_graph_title'] = 'Nombre de pages vues par jour';
     567  $lang['stats_visitors_graph_title'] = 'Nombre de visiteurs par jour';
     568
     569  $lang['comments_last_title'] = 'Derniers commentaires';
     570  $lang['comments_non_validated_title'] = 'Commentaires non validés';
     571// end version 1.3
     572 
    527573  // help page
    528574  $lang['help_images_title'] = 'Ajout d\'images';
     
    545591  $lang['help_database'][0] = 'Une fois les fichiers placés correctement et les miniatures placées ou créées, cliquez sur "MaJ base d\'images" dans le menu de la zone d\'administration.';
    546592
    547 // start version 1.3
    548   // $lang['help_remote_title'] = 'Site distant';
    549 // end version 1.3
     593  $lang['help_remote_title'] = 'Site distant';
    550594  $lang['help_remote'][0] = 'PhpWebGallery offre la possibilité d\'utiliser plusieurs serveurs pour stocker les images qui composeront votre galerie. Cela peut être utile si votre galerie est installée sur une espace limité et que vous avez une grande quantité d\'images à montrer. Suivez la procédure suivante :';
    551595  $lang['help_remote'][1] = '1. éditez le fichier "create_listing_file.php" (vous le trouverez dans le répertoire "admin"), en modifiant la ligne "$prefix_thumbnail = "TN-";" si le préfixe pour vos miniatures n\'est pas "TN-".';
  • trunk/picture.php

    r21 r26  
    1717
    1818// this page shows the image full size
    19 // (or resized to the max size the user has chosen)
    20 // and two thumbnail : previous and next picture of your gallery
    2119//----------------------------------------------------------- personnal include
    2220include_once( './include/init.inc.php' );       
     
    148146
    149147$tpl = array( 'back','submit','comments_title','comments_del','delete',
    150               'comments_add','author' );
     148              'comments_add','author','slideshow','slideshow_stop',
     149              'period_seconds' );
    151150templatize_array( $tpl, 'lang', $handle );
     151$vtp->setGlobalVar( $handle, 'user_template', $user['template'] );
    152152$vtp->setGlobalVar( $handle, 'text_color', $user['couleur_text'] );
     153//-------------------------------------------------------- slideshow management
     154if ( isset( $_GET['slideshow'] ) )
     155{
     156  if ( !is_numeric( $_GET['slideshow'] ) )
     157    $_GET['slideshow'] = $conf['slideshow_period'][0];
     158  $vtp->addSession( $handle, 'stop_slideshow' );
     159  $url = './picture.php';
     160  $url.= '?image_id='.$page['id'];
     161  $url.= '&amp;cat='.$page['cat'];
     162  $url.= '&amp;expand='.$_GET['expand'];
     163  if ( $page['cat'] == 'search' )
     164  {
     165    $url.= '&amp;search='.$_GET['search'];
     166    $url.= '&amp;mode='.$_GET['mode'];
     167  }
     168  $vtp->setVar( $handle, 'stop_slideshow.url', add_session_id( $url ) );
     169  $vtp->closeSession( $handle, 'stop_slideshow' );
     170}
     171else
     172{
     173  $vtp->addSession( $handle, 'start_slideshow' );
     174  foreach ( $conf['slideshow_period'] as $option ) {
     175    $vtp->addSession( $handle, 'second' );
     176    $vtp->setVar( $handle, 'second.option', $option );
     177    $url = './picture.php';
     178    $url.= '?image_id='.$page['id'];
     179    $url.= '&amp;cat='.$page['cat'];
     180    $url.= '&amp;expand='.$_GET['expand'];
     181    if ( $page['cat'] == 'search' )
     182    {
     183      $url.= '&amp;search='.$_GET['search'];
     184      $url.= '&amp;mode='.$_GET['mode'];
     185    }
     186    $url.= '&amp;slideshow='.$option;
     187    $vtp->setVar( $handle, 'second.url', add_session_id( $url ) );
     188    $vtp->closeSession( $handle, 'second' );
     189  }
     190  $vtp->closeSession( $handle, 'start_slideshow' );
     191}
    153192//------------------------------------------------------------------ page title
    154193if ( $page['name'] != '' )
     
    377416  $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] );
    378417  $vtp->setVar( $handle, 'favorite.src',
    379                 './theme/'.$user['theme'].'/favorite.gif' );
     418                './template/'.$user['template'].'/theme/favorite.gif' );
    380419  $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['add_favorites_alt'].' ]' );
    381420  $vtp->closeSession( $handle, 'favorite' );
     
    389428  $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] );
    390429  $vtp->setVar( $handle, 'favorite.src',
    391                 './theme/'.$user['theme'].'/del_favorite.gif' );
     430                './template/'.$user['template'].'/theme/del_favorite.gif' );
    392431  $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['del_favorites_alt'].' ]' );
    393432  $vtp->closeSession( $handle, 'favorite' );
     
    453492  $vtp->setGlobalVar( $handle, 'next.alt', $alt_thumbnail );
    454493  $vtp->closeSession( $handle, 'next' );
     494  // slideshow
     495  if ( isset( $_GET['slideshow'] ) )
     496  {
     497    $vtp->addSession( $handle, 'refresh' );
     498    $vtp->setVar( $handle, 'refresh.time', 2 );
     499    $url = $url_link.'&amp;slideshow='.$_GET['slideshow'];
     500    $vtp->setVar( $handle, 'refresh.url', add_session_id( $url ) );
     501    $vtp->closeSession( $handle, 'refresh' );
     502  }
    455503}
    456504else
     
    472520    }
    473521    $query = 'INSERT INTO '.PREFIX_TABLE.'comments';
    474     $query.= ' (author,date,image_id,content) VALUES';
     522    $query.= ' (author,date,image_id,content,validated) VALUES';
    475523    $query.= " ('".$author."',".time().",".$page['id'];
    476     $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."');";
     524    $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'";
     525    if ( !$conf['comments_validation'] or $user['status'] == 'admin' )
     526      $query.= ",'true'";
     527    else
     528      $query.= ",'false'";
     529    $query.= ');';
    477530    mysql_query( $query );
     531    $vtp->addSession( $handle, 'information' );
     532    $message = $lang['comment_added'];
     533    if ( $conf['comments_validation'] and $user['status'] != 'admin' )
     534    {
     535      $message.= '<br />'.$lang['comment_to_validate'];
     536    }
     537    $vtp->setVar( $handle, 'information.content', $message );
     538    $vtp->closeSession( $handle, 'information' );
    478539  }
    479540  // comment deletion
     
    489550  $query = 'SELECT COUNT(*) AS nb_comments';
    490551  $query.= ' FROM '.PREFIX_TABLE.'comments';
    491   $query.= ' WHERE image_id = '.$page['id'].';';
     552  $query.= ' WHERE image_id = '.$page['id'];
     553  $query.= " AND validated = 'true'";
     554  $query.= ';';
    492555  $row = mysql_fetch_array( mysql_query( $query ) );
    493556  $page['nb_comments'] = $row['nb_comments'];
     
    520583  $query.= ' FROM '.PREFIX_TABLE.'comments';
    521584  $query.= ' WHERE image_id = '.$page['id'];
     585  $query.= " AND validated = 'true'";
    522586  $query.= ' ORDER BY date ASC';
    523587  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
     
    531595    $displayed_date.= date( " j ", $row['date'] );
    532596    $displayed_date.= $lang['month'][date( "n", $row['date'] )];
    533     $displayed_date.= date( " Y G:i", $row['date'] );
     597    $displayed_date.= date( ' Y G:i', $row['date'] );
    534598    $vtp->setVar( $handle, 'comment.date', $displayed_date );
    535599    $vtp->setVar( $handle, 'comment.content', nl2br( $row['content'] ) );
  • trunk/profile.php

    r17 r26  
    2929check_cat_id( $_GET['cat'] );
    3030//------------------------------------------------------ update & customization
    31 $infos = array( 'nb_image_line', 'nb_line_page', 'theme', 'language',
     31$infos = array( 'nb_image_line', 'nb_line_page', 'language',
    3232                'maxwidth', 'maxheight', 'expand', 'show_nb_comments',
    3333                'short_period', 'long_period', 'template', 'mail_address' );
     
    3636//    - on teste si chacune des variables est passée en argument à la page
    3737//    - ce qui signifie que l'on doit venir de la page de personnalisation
    38 $error = array();
     38$errors = array();
    3939if ( isset( $_POST['submit'] ) )
    4040{
    41   $i = 0;
    42   if ( $_POST['maxwidth'] != '' )
    43   {
    44     if ( !ereg( "^[0-9]{2,}$", $_POST['maxwidth'] )
    45          || $_POST['maxwidth'] < 50 )
    46     {
    47       $error[$i++] = $lang['err_maxwidth'];
    48     }
    49   }
    50   if ( $_POST['maxheight'] != '' )
    51   {
    52     if ( !ereg( "^[0-9]{2,}$", $_POST['maxheight'] )
    53          || $_POST['maxheight'] < 50 )
    54     {
    55       $error[$i++] = $lang['err_maxheight'];
    56     }
    57   }
    58   // les période doivent être des entiers, il représentent des nombres de jours
    59   if ( !ereg( "^[0-9]*$", $_POST['short_period'] )
    60        || !ereg("^[0-9]*$", $_POST['long_period'] ) )
    61   {
    62     $error[$i++] = $lang['err_periods'];
     41  $int_pattern = '/^\d+$/';
     42  if ( $_POST['maxwidth'] != ''
     43       and ( !preg_match( $int_pattern, $_POST['maxwidth'] )
     44             or $_POST['maxwidth'] < 50 ) )
     45  {
     46    array_push( $errors, $lang['err_maxwidth'] );
     47  }
     48  if ( $_POST['maxheight']
     49       and ( !preg_match( $int_pattern, $_POST['maxheight'] )
     50             or $_POST['maxheight'] < 50 ) )
     51  {
     52    array_push( $errors, $lang['err_maxheight'] );
     53  }
     54  // periods must be integer values, they represents number of days
     55  if ( !preg_match( $int_pattern, $_POST['short_period'] )
     56       or !preg_match( $int_pattern, $_POST['long_period'] ) )
     57  {
     58    array_push( $errors, $lang['err_periods'] );
    6359  }
    6460  else
    6561  {
    66     // la période longue doit être supérieure à la période courte
     62    // long period must be longer than short period
    6763    if ( $_POST['long_period'] <= $_POST['short_period']
    68          || $_POST['short_period'] <= 0 )
    69     {
    70       $error[$i++] = $lang['err_periods_2'];
    71     }
    72   }
    73   // le mail doit être conforme à qqch du type : nom@serveur.com
    74   if( $_POST['mail_address'] != ""
    75       && !ereg( "([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)",
    76                 $_POST['mail_address'] ) )
    77   {
    78     $error[$i++] = $lang['reg_err_mail_address'];
     64         or $_POST['short_period'] <= 0 )
     65    {
     66      array_push( $errors, $lang['err_periods_2'] );
     67    }
     68  }
     69  $mail_error = validate_mail_address( $_POST['mail_address'] );
     70  if ( $mail_error != '' )
     71  {
     72    array_push( $errors, $mail_error );
    7973  }
    8074  if ( $_POST['use_new_pwd'] == 1 )
    8175  {
    82     // on vérifie que le password rentré correspond bien
    83     // à la confirmation faite par l'utilisateur
     76    // password must be the same as its confirmation
    8477    if ( $_POST['password'] != $_POST['passwordConf'] )
    8578    {
    86       $error[$i++] = $lang['reg_err_pass'];
     79      array_push( $errors, $lang['reg_err_pass'] );
    8780    }
    8881  }
    8982
    90   if ( sizeof( $error ) == 0 )
    91   {
    92     $tab_theme = explode( ' - ', $_POST['theme'] );
    93     $_POST['theme'] = $tab_theme[0].'/'.$tab_theme[1];
    94 
    95     $query = 'update '.PREFIX_TABLE.'users';
    96     $query.= ' set';
    97     for ( $i = 0; $i < sizeof( $infos ); $i++ )
    98     {
    99       if ( $i > 0 )
    100       {
    101         $query.= ',';
    102       }
    103       else
    104       {
    105         $query.= ' ';
    106       }
    107       $query.= $infos[$i];
     83  if ( count( $errors ) == 0 )
     84  {
     85    $query = 'UPDATE '.PREFIX_TABLE.'users';
     86    $query.= ' SET ';
     87    foreach ( $infos as $i => $info ) {
     88      if ( $i > 0 ) $query.= ',';
     89      $query.= $info;
    10890      $query.= ' = ';
    109       if ( $_POST[$infos[$i]] == '' )
    110       {
    111         $query.= 'NULL';
    112       }
    113       else
    114       {
    115         $query.= "'".$_POST[$infos[$i]]."'";
    116       }
    117     }
    118     $query.= ' where id = '.$user['id'];
     91      if ( $_POST[$info] == '' ) $query.= 'NULL';
     92      else                       $query.= "'".$_POST[$info]."'";
     93    }
     94    $query.= ' WHERE id = '.$user['id'];
    11995    $query.= ';';
    12096    mysql_query( $query );
     
    12298    if ( $_POST['use_new_pwd'] == 1 )
    12399    {
    124       $query = 'update '.PREFIX_TABLE.'users';
    125       $query.= " set password = '".md5( $_POST['password'] )."'";
    126       $query.= ' where id = '.$user['id'];
     100      $query = 'UPDATE '.PREFIX_TABLE.'users';
     101      $query.= " SET password = '".md5( $_POST['password'] )."'";
     102      $query.= ' WHERE id = '.$user['id'];
    127103      $query.= ';';
    128104      mysql_query( $query );
    129       echo '<br />'.$query;
    130105    }
    131106    // redirection
     
    133108    if ( $page['cat'] == 'search' )
    134109    {
    135       $url.= '&search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
     110      $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode'];
    136111    }
    137112    $url = add_session_id( $url, true );
     
    157132$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
    158133//-------------------------------------------------------------- errors display
    159 if ( sizeof( $error ) != 0 )
     134if ( count( $errors ) != 0 )
    160135{
    161136  $vtp->addSession( $handle, 'errors' );
    162   for ( $i = 0; $i < sizeof( $error ); $i++ )
    163   {
     137  foreach ( $errors as $error ) {
    164138    $vtp->addSession( $handle, 'li' );
    165     $vtp->setVar( $handle, 'li.li', $error[$i] );
     139    $vtp->setVar( $handle, 'li.li', $error );
    166140    $vtp->closeSession( $handle, 'li' );
    167141  }
     
    221195    $vtp->setVar( $handle, 'option.option', $option[$i] );
    222196    if ( $option[$i] == $user['template'] )
    223     {
    224       $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
    225     }
    226     $vtp->closeSession( $handle, 'option' );
    227   }
    228   $vtp->closeSession( $handle, 'select' );
    229   $vtp->closeSession( $handle, 'line' );
    230 }
    231 //----------------------------------------------------------------------- theme
    232 if ( in_array( 'theme', $infos ) )
    233 {
    234   $vtp->addSession( $handle, 'line' );
    235   $vtp->setVar( $handle, 'line.name', $lang['customize_theme'] );
    236   $vtp->addSession( $handle, 'select' );
    237   $vtp->setVar( $handle, 'select.name', 'theme' );
    238   $option = get_themes( './theme/' );
    239   for ( $i = 0; $i < sizeof( $option ); $i++ )
    240   {
    241     $vtp->addSession( $handle, 'option' );
    242     $vtp->setVar( $handle, 'option.option', $option[$i] );
    243     if ( $option[$i] == str_replace( '/', ' - ', $user['theme'] ) )
    244197    {
    245198      $vtp->setVar( $handle, 'option.selected', ' selected="selected"' );
  • trunk/upload.php

    r20 r26  
    1717
    1818//------------------------------------------------------------------- functions
    19 
    2019// The validate_upload function checks if the image of the given path is valid.
    2120// A picture is valid when :
     
    115114if ( $access_forbidden == true
    116115     or $page['cat_site_id'] != 1
    117      or $conf['upload_available'] == 'false' )
     116     or !$conf['upload_available'] )
    118117{
    119118  echo '<div style="text-align:center;">'.$lang['upload_forbidden'].'<br />';
    120   echo '<a href="'.add_session_id_to_url( './category.php' ).'">';
     119  echo '<a href="'.add_session_id( './category.php' ).'">';
    121120  echo $lang['thumbnails'].'</a></div>';
    122121  exit();
     
    128127
    129128$tpl = array( 'upload_title', 'upload_username', 'mail_address', 'submit',
    130               'upload_successful', 'search_return_main_page' );
    131 templatize_array( $tpl, 'lang', $sub );
    132 // user
    133 $vtp->setGlobalVar( $handle, 'style',            $user['style'] );
    134 $vtp->setGlobalVar( $handle, 'user_login',       $user['username'] );
    135 $vtp->setGlobalVar( $handle, 'user_mail_address',$user['mail_address'] );
     129              'upload_successful', 'search_return_main_page','upload_author',
     130              'upload_name','upload_creation_date','upload_comment',
     131              'mandatory' );
     132templatize_array( $tpl, 'lang', $handle );
    136133
    137134$error = array();
    138 $i = 0;
    139135$page['upload_successful'] = false;
    140136if ( isset( $_GET['waiting_id'] ) )
     
    143139}
    144140//-------------------------------------------------------------- picture upload
    145 // vérification de la présence et de la validité des champs.
     141// verfying fields
    146142if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) )
    147143{
     
    149145  if ( @is_file( $path ) )
    150146  {
    151     $error[$i++] = $lang['upload_file_exists'];
     147    array_push( $error, $lang['upload_file_exists'] );
    152148  }
    153149  // test de la présence des champs obligatoires
    154   if ( $_FILES['picture']['name'] == "" )
    155   {
    156     $error[$i++] = $lang['upload_filenotfound'];
     150  if ( $_FILES['picture']['name'] == '' )
     151  {
     152    array_push( $error, $lang['upload_filenotfound'] );
    157153  }
    158154  if ( !ereg( "([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)",
    159155             $_POST['mail_address'] ) )
    160156  {
    161     $error[$i++] = $lang['reg_err_mail_address'];
     157    array_push( $error, $lang['reg_err_mail_address'] );
    162158  }
    163159  if ( $_POST['username'] == '' )
    164160  {
    165     $error[$i++] = $lang['upload_err_username'];
    166   }
    167 
     161    array_push( $error, $lang['upload_err_username'] );
     162  }
     163
     164  if ( $_POST['date_creation'] != '' )
     165  {
     166    list( $day,$month,$year ) = explode( '/', $_POST['date_creation'] );
     167    // int checkdate ( int month, int day, int year)
     168    if ( checkdate( $month, $day, $year ) )
     169    {
     170      // int mktime ( int hour, int minute, int second,
     171      //              int month, int day, int year [, int is_dst])
     172      $date_creation = mktime( 0, 0, 0, $month, $day, $year );
     173    }
     174    else
     175    {
     176      array_push( $error, $lang['err_date'] );
     177    }
     178  }
     179  // creation of the "infos" field :
     180  // <infos author="Pierrick LE GALL" comment="my comment"
     181  //        date_creation="1056891767" name="" />
     182  $xml_infos = '<infos';
     183  $xml_infos.= ' author="'.htmlspecialchars($_POST['author'],ENT_QUOTES).'"';
     184  $xml_infos.= ' comment="'.htmlspecialchars($_POST['comment'],ENT_QUOTES).'"';
     185  $xml_infos.= ' date_creation="'.$date_creation.'"';
     186  $xml_infos.= ' name="'.htmlspecialchars( $_POST['name'], ENT_QUOTES).'"';
     187  $xml_infos.= ' />';
     188 
    168189  if ( sizeof( $error ) == 0 )
    169190  {
     
    174195    for ( $j = 0; $j < sizeof( $result['error'] ); $j++ )
    175196    {
    176       $error[$i++] = $result['error'][$j];
     197      array_push( $error, $result['error'][$j] );
    177198    }
    178199  }
     
    181202  {
    182203    $query = 'insert into '.PREFIX_TABLE.'waiting';
    183     $query.= ' (cat_id,file,username,mail_address,date) values';
     204    $query.= ' (cat_id,file,username,mail_address,date,infos) values';
    184205    $query.= " (".$page['cat'].",'".$_FILES['picture']['name']."'";
    185206    $query.= ",'".htmlspecialchars( $_POST['username'], ENT_QUOTES)."'";
    186     $query.= ",'".$_POST['mail_address']."',".time().")";
     207    $query.= ",'".$_POST['mail_address']."',".time().",'".$xml_infos."')";
    187208    $query.= ';';
    188209    mysql_query( $query );
     
    210231  for ( $j = 0; $j < sizeof( $result['error'] ); $j++ )
    211232  {
    212     $error[$i++] = $result['error'][$j];
     233    array_push( $error, $result['error'][$j] );
    213234  }
    214235  if ( sizeof( $error ) == 0 )
     
    244265    $url.= '&amp;waiting_id='.$page['waiting_id'];
    245266  }
    246   $vtp->setGlobalVar( $handle, 'form_action', $url );
     267  $vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
    247268//--------------------------------------------------------------------- advises
    248269  if ( $conf['upload_maxfilesize'] != '' )
     
    308329  {
    309330    $vtp->addSession( $handle, 'fields' );
     331    // username
     332    if ( isset( $_POST['username'] ) ) $username = $_POST['username'];
     333    else                               $username = $user['username'];
     334    $vtp->setVar( $handle, 'fields.username',  $username );
     335    // mail address
     336    if ( isset( $_POST['mail_address'] ) )$mail_address=$_POST['mail_address'];
     337    else                                  $mail_address=$user['mail_address'];
     338    $vtp->setGlobalVar( $handle, 'user_mail_address',$user['mail_address'] );
     339    // name of the picture
     340    $vtp->setVar( $handle, 'fields.name', $_POST['name'] );
     341    // author
     342    $vtp->setVar( $handle, 'fields.author', $_POST['author'] );
     343    // date of creation
     344    $vtp->setVar( $handle, 'fields.date_creation', $_POST['date_creation'] );
     345    // comment
     346    $vtp->setVar( $handle, 'fields.comment', $_POST['comment'] );
     347
    310348    $vtp->closeSession( $handle, 'fields' );
     349
     350    $vtp->addSession( $handle, 'note' );
     351    $vtp->closeSession( $handle, 'note' );
    311352  }
    312353  $vtp->closeSession( $handle, 'upload_not_successful' );
Note: See TracChangeset for help on using the changeset viewer.