diff options
author | z0rglub <z0rglub@piwigo.org> | 2003-07-21 19:47:14 +0000 |
---|---|---|
committer | z0rglub <z0rglub@piwigo.org> | 2003-07-21 19:47:14 +0000 |
commit | 2fa9252446a78d349ca2f50096430591cc5e012f (patch) | |
tree | bbf5cd282c8b9424b05d970c70e30610ea8b0e4f /admin | |
parent | 55a0a61aaf58a02e2ac5d2c489f81b1be4730cd8 (diff) |
*** empty log message ***
git-svn-id: http://piwigo.org/svn/trunk@26 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r-- | admin/admin.php | 38 | ||||
-rw-r--r-- | admin/configuration.php | 97 | ||||
-rw-r--r-- | admin/historique.php | 102 | ||||
-rw-r--r-- | admin/images/arrow_up.gif | bin | 88 -> 0 bytes | |||
-rw-r--r-- | admin/images/moins.gif | bin | 867 -> 0 bytes | |||
-rw-r--r-- | admin/images/plus.gif | bin | 870 -> 0 bytes | |||
-rw-r--r-- | admin/images/puce.gif | bin | 839 -> 0 bytes | |||
-rw-r--r-- | admin/include/functions.php | 7 | ||||
-rw-r--r-- | admin/infos_images.php | 6 | ||||
-rw-r--r-- | admin/thumbnail.php | 678 | ||||
-rw-r--r-- | admin/update.php | 55 | ||||
-rw-r--r-- | admin/waiting.php | 223 |
12 files changed, 541 insertions, 665 deletions
diff --git a/admin/admin.php b/admin/admin.php index 3825ca71a..388ce9eb0 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -21,8 +21,8 @@ include_once( './include/isadmin.inc.php' ); $vtp = new VTemplate; $handle = $vtp->Open( '../template/'.$user['template'].'/admin/admin.vtp' ); // language -$vtp->setGlobalVar( $handle, 'page_title', $lang['title_default'] ); -$vtp->setGlobalVar( $handle, 'menu_title', $lang['menu_title'] ); +$tpl = array( 'menu_title', 'title_default', 'charset' ); +templatize_array( $tpl, 'lang', $handle ); //--------------------------------------- validating page and creation of title $page_valide = false; $title = ''; @@ -75,13 +75,13 @@ switch ( $_GET['page'] ) $page_valide = false; } break; - case 'historique': + case 'stats': $title = $lang['title_history']; $page_valide = true; break; case 'update': $title = $lang['title_update']; $page_valide = true; break; case 'configuration': $title = $lang['title_configuration']; $page_valide = true; break; - case 'manuel': + case 'help': $title = $lang['title_instructions']; $page_valide = true; break; case 'cat_perm': $title = $lang['title_cat_perm']; @@ -124,6 +124,10 @@ switch ( $_GET['page'] ) } $page_valide = true; break; + case 'comments' : + $title = $lang['title_comments']; + $page_valide = true; + break; default: $title = $lang['title_default']; break; } @@ -177,7 +181,10 @@ $vtp->addSession( $handle, 'summary' ); $vtp->setVar( $handle, 'summary.indent', '' ); $vtp->setVar( $handle, 'summary.link', add_session_id( $link_start.'waiting' ) ); -$query = 'select id from '.PREFIX_TABLE.'waiting;'; +$query = 'SELECT id'; +$query.= ' FROM '.PREFIX_TABLE.'waiting'; +$query.= " WHERE validated='false'"; +$query.= ';'; $result = mysql_query( $query ); $nb_waiting = ''; if ( mysql_num_rows( $result ) > 0 ) @@ -186,6 +193,23 @@ if ( mysql_num_rows( $result ) > 0 ) } $vtp->setVar( $handle, 'summary.name', $lang['menu_waiting'].$nb_waiting ); $vtp->closeSession( $handle, 'summary' ); +// comments +$vtp->addSession( $handle, 'summary' ); +$vtp->setVar( $handle, 'summary.indent', '' ); +$vtp->setVar( $handle, 'summary.link', + add_session_id( $link_start.'comments' ) ); +$query = 'SELECT id'; +$query.= ' FROM '.PREFIX_TABLE.'comments'; +$query.= " WHERE validated='false'"; +$query.= ';'; +$result = mysql_query( $query ); +$nb_waiting = ''; +if ( mysql_num_rows( $result ) > 0 ) +{ + $nb_waiting = ' [ '.mysql_num_rows( $result ).' ]'; +} +$vtp->setVar( $handle, 'summary.name', $lang['menu_comments'].$nb_waiting ); +$vtp->closeSession( $handle, 'summary' ); // update $vtp->addSession( $handle, 'summary' ); $vtp->setVar( $handle, 'summary.indent', '' ); @@ -204,14 +228,14 @@ $vtp->closeSession( $handle, 'summary' ); $vtp->addSession( $handle, 'summary' ); $vtp->setVar( $handle, 'summary.indent', '' ); $vtp->setVar( $handle, 'summary.link', - add_session_id( $link_start.'historique' ) ); + add_session_id( $link_start.'stats' ) ); $vtp->setVar( $handle, 'summary.name', $lang['menu_history'] ); $vtp->closeSession( $handle, 'summary' ); // instructions $vtp->addSession( $handle, 'summary' ); $vtp->setVar( $handle, 'summary.indent', '' ); $vtp->setVar( $handle, 'summary.link', - add_session_id( $link_start.'manuel' ) ); + add_session_id( $link_start.'help' ) ); $vtp->setVar( $handle, 'summary.name', $lang['menu_instructions'] ); $vtp->closeSession( $handle, 'summary' ); // back to thumbnails page diff --git a/admin/configuration.php b/admin/configuration.php index 34e148c4d..3292ffbc2 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -40,9 +40,10 @@ array( 'prefix_thumbnail','webmaster','mail_webmaster','access', 'session_id_size','session_time','session_keyword','max_user_listbox', 'show_comments','nb_comment_page','upload_available', 'upload_maxfilesize', 'upload_maxwidth','upload_maxheight', - 'upload_maxwidth_thumbnail','upload_maxheight_thumbnail' ); + 'upload_maxwidth_thumbnail','upload_maxheight_thumbnail','log', + 'comments_validation' ); $default_user_infos = -array( 'nb_image_line','nb_line_page','theme','language','maxwidth', +array( 'nb_image_line','nb_line_page','language','maxwidth', 'maxheight','expand','show_nb_comments','short_period','long_period', 'template' ); $error = array(); @@ -73,7 +74,7 @@ if ( isset( $_POST['submit'] ) ) { array_push( $error, $lang['conf_err_prefixe'] ); } - // mail mail must be formatted as follows : name@server.com + // mail must be formatted as follows : name@server.com $pattern = '/^[\w-]+(\.[\w-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/'; if ( !preg_match( $pattern, $_POST['mail_webmaster'] ) ) { @@ -194,9 +195,6 @@ if ( isset( $_POST['submit'] ) ) echo $query; mysql_query( $query ); - $tab_theme = explode( ' - ', $_POST['theme'] ); - $_POST['theme'] = $tab_theme[0].'/'.$tab_theme[1]; - $query = 'UPDATE '.PREFIX_TABLE.'users'; $query.= ' SET'; foreach ( $default_user_infos as $i => $default_user_info ) { @@ -371,6 +369,38 @@ $vtp->setVar( $sub, 'param_line.def', $lang['conf_general_max_user_listbox_info'] ); $vtp->closeSession( $sub, 'param_line' ); $vtp->closeSession( $sub, 'line' ); +// activate log +$vtp->addSession( $sub, 'line' ); +$vtp->addSession( $sub, 'param_line' ); +$vtp->setVar( $sub, 'param_line.name', $lang['conf_general_log'] ); +$vtp->addSession( $sub, 'group' ); +$vtp->addSession( $sub, 'radio' ); +$vtp->setVar( $sub, 'radio.name', 'log' ); +$vtp->setVar( $sub, 'radio.value', 'true' ); +$vtp->setVar( $sub, 'radio.option', $lang['yes'] ); +$checked = ''; +if ( $log == 'true' ) +{ + $checked = ' checked="checked"'; +} +$vtp->setVar( $sub, 'radio.checked', $checked ); +$vtp->closeSession( $sub, 'radio' ); +$vtp->addSession( $sub, 'radio' ); +$vtp->setVar( $sub, 'radio.name', 'log' ); +$vtp->setVar( $sub, 'radio.value', 'false' ); +$vtp->setVar( $sub, 'radio.option', $lang['no'] ); +$checked = ''; +if ( $log == 'false' ) +{ + $checked = ' checked="checked"'; +} +$vtp->setVar( $sub, 'radio.checked', $checked ); +$vtp->closeSession( $sub, 'radio' ); +$vtp->closeSession( $sub, 'group' ); +$vtp->setVar( $sub, 'param_line.def', + $lang['conf_general_log_info'] ); +$vtp->closeSession( $sub, 'param_line' ); +$vtp->closeSession( $sub, 'line' ); $vtp->addSession( $sub, 'line' ); $vtp->addSession( $sub, 'space_line' ); @@ -432,6 +462,38 @@ $vtp->setVar( $sub, 'param_line.def', $lang['conf_comments_comments_number_info'] ); $vtp->closeSession( $sub, 'param_line' ); $vtp->closeSession( $sub, 'line' ); +// coments validation +$vtp->addSession( $sub, 'line' ); +$vtp->addSession( $sub, 'param_line' ); +$vtp->setVar( $sub, 'param_line.name', $lang['conf_comments_validation'] ); +$vtp->addSession( $sub, 'group' ); +$vtp->addSession( $sub, 'radio' ); +$vtp->setVar( $sub, 'radio.name', 'comments_validation' ); +$vtp->setVar( $sub, 'radio.value', 'true' ); +$vtp->setVar( $sub, 'radio.option', $lang['yes'] ); +$checked = ''; +if ( $comments_validation == 'true' ) +{ + $checked = ' checked="checked"'; +} +$vtp->setVar( $sub, 'radio.checked', $checked ); +$vtp->closeSession( $sub, 'radio' ); +$vtp->addSession( $sub, 'radio' ); +$vtp->setVar( $sub, 'radio.name', 'comments_validation' ); +$vtp->setVar( $sub, 'radio.value', 'false' ); +$vtp->setVar( $sub, 'radio.option', $lang['no'] ); +$checked = ''; +if ( $comments_validation == 'false' ) +{ + $checked = ' checked="checked"'; +} +$vtp->setVar( $sub, 'radio.checked', $checked ); +$vtp->closeSession( $sub, 'radio' ); +$vtp->closeSession( $sub, 'group' ); +$vtp->setVar( $sub, 'param_line.def', + $lang['conf_comments_validation_info'] ); +$vtp->closeSession( $sub, 'param_line' ); +$vtp->closeSession( $sub, 'line' ); $vtp->addSession( $sub, 'line' ); $vtp->addSession( $sub, 'space_line' ); @@ -514,7 +576,7 @@ $vtp->closeSession( $sub, 'line' ); // template $vtp->addSession( $sub, 'line' ); $vtp->addSession( $sub, 'param_line' ); -$vtp->setVar( $sub, 'param_line.name', $lang['customize_template'] ); +$vtp->setVar( $sub, 'param_line.name', $lang['customize_theme'] ); $vtp->addSession( $sub, 'select' ); $vtp->setVar( $sub, 'select.name', 'template' ); $option = get_dirs( '../template/' ); @@ -529,27 +591,6 @@ for ( $i = 0; $i < sizeof( $option ); $i++ ) $vtp->closeSession( $sub, 'option' ); } $vtp->closeSession( $sub, 'select' ); -$vtp->setVar( $sub, 'param_line.def', $lang['conf_default_template_info'] ); -$vtp->closeSession( $sub, 'param_line' ); -$vtp->closeSession( $sub, 'line' ); -// theme -$vtp->addSession( $sub, 'line' ); -$vtp->addSession( $sub, 'param_line' ); -$vtp->setVar( $sub, 'param_line.name', $lang['customize_theme'] ); -$vtp->addSession( $sub, 'select' ); -$vtp->setVar( $sub, 'select.name', 'theme' ); -$option = get_themes( '../theme/' ); -for ( $i = 0; $i < sizeof( $option ); $i++ ) -{ - $vtp->addSession( $sub, 'option' ); - $vtp->setVar( $sub, 'option.option', $option[$i] ); - if ( $option[$i] == str_replace( "/", " - ", $theme ) ) - { - $vtp->setVar( $sub, 'option.selected', ' selected="selected"' ); - } - $vtp->closeSession( $sub, 'option' ); -} -$vtp->closeSession( $sub, 'select' ); $vtp->setVar( $sub, 'param_line.def', $lang['conf_default_theme_info'] ); $vtp->closeSession( $sub, 'param_line' ); $vtp->closeSession( $sub, 'line' ); diff --git a/admin/historique.php b/admin/historique.php deleted file mode 100644 index eda2b1b27..000000000 --- a/admin/historique.php +++ /dev/null @@ -1,102 +0,0 @@ -<?php -/*************************************************************************** - * historique.php is a part of PhpWebGallery * - * ------------------- * - * last update : Monday, July 15, 2002 * - * email : pierrick@z0rglub.com * - * * - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; * - * * - ***************************************************************************/ - include_once( "./include/isadmin.inc.php" ); - - if ( $HTTP_GET_VARS['empty'] == 1 ) - { - mysql_query( "delete from PREFIX_TABLE"."history;" ); - } - define (NB_JOUR_HISTO,"7"); - $tMois = array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"); - $tJours = array("dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"); - - // on affiche les visites pour les 48 dernières heures - // il faut trouver le unix date de la veille à 00h00 : - // time (); nous donne le nombre de secondes actuelle - $date_ref = time() - (7*24*60*60); - $result = mysql_query( "select date,login,IP,categorie,page,titre,commentaire from PREFIX_TABLE"."history where date > '$date_ref' order by date desc;"); - echo"<div style=\"text-align:center;\"><a href=\"".add_session_id_to_url( "./admin.php?page=historique&empty=1" )."\">empty / vider</a></div>"; - echo"<div style=\"color:green;text-align:center;margin:10px\">"; - // affichage de la date du jour - echo $tJours[date("w")] ." "; - echo date("j").(date("j") == 1 ? "er " : " "); - echo $tMois[date("n")-1]." ".date("Y")." "; - echo " à ".date("G")."h".date("i"); - echo"</div>"; -?> - <table width='100%'> - <tr> - <th width='1%'>date</th> - <th>login</th> - <th>IP</th> - <th>page</th> - <th>categorie</th> - <th>image</th> - </tr> - <tr> - <td colspan=7 height=5><div class='style1'></div></td> - </tr> - <? - $fin = time(); - $debut = mktime ( 23,59,59,date("n"),date("j")-1,date("Y") ); - for ( $i = 0; $i < NB_JOUR_HISTO; $i++ ) - { - // 1. affichage du nom du jour - echo" <tr> - <td><nobr>"; - echo"<img src=\"".$conf['repertoire_image']."moins.gif\"> <b>"; - echo $tJours[date("w",$fin)] ." "; - echo date("j",$fin).(date("j",$fin) == 1 ? "er " : " "); - echo $tMois[date("n",$fin)-1]." ".date("Y",$fin)."</b>"; - echo" </nobr></td> - <td> </td> - <td> </td> - <td> </td> - <td> </td> - <td> </td> - </tr>"; - // 2. affichage de tous les évènements pour le jour donné - // entre la veille à 23h59m59s et le jour même 23h59m59s - $result = mysql_query("select date,login,IP,categorie,page,titre,commentaire from PREFIX_TABLE"."history where date > '$debut' and date < '$fin' order by date desc;"); - $fin = $debut; - // on recule le début d'une journée complète - $debut = $debut - 24*60*60; - while($row=mysql_fetch_array($result)) - { - $date = date("G\hi s", $row[date]); - $date = str_replace ( " ","min ", $date ); - $date .= " sec"; - // on réduit la taille du commentaire à ses premiers caractères - $affichage_commentaire = ""; - if($row[commentaire] != '') - { - $affichage_commentaire = substr($row[commentaire],0,10); - $affichage_commentaire .= "..."; - } - echo" <tr> - <td> |- $date</td> - <td>$row[login]</td> - <td>$row[IP]</td> - <td>$row[page]</td> - <td>$row[categorie]</td> - <td>$row[titre]</td> - </tr>"; - } - } - echo" </table> - </center>"; -?>
\ No newline at end of file diff --git a/admin/images/arrow_up.gif b/admin/images/arrow_up.gif Binary files differdeleted file mode 100644 index 90da978cd..000000000 --- a/admin/images/arrow_up.gif +++ /dev/null diff --git a/admin/images/moins.gif b/admin/images/moins.gif Binary files differdeleted file mode 100644 index 74fa8736f..000000000 --- a/admin/images/moins.gif +++ /dev/null diff --git a/admin/images/plus.gif b/admin/images/plus.gif Binary files differdeleted file mode 100644 index 2fa7116c1..000000000 --- a/admin/images/plus.gif +++ /dev/null diff --git a/admin/images/puce.gif b/admin/images/puce.gif Binary files differdeleted file mode 100644 index b8494bb77..000000000 --- a/admin/images/puce.gif +++ /dev/null diff --git a/admin/include/functions.php b/admin/include/functions.php index cd58d0822..6a5ed195e 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -17,11 +17,16 @@ $tab_ext_create_TN = array ( 'jpg', 'png', 'JPG', 'PNG' ); +// is_image returns true if the given $filename (including the path) is a +// picture according to its format and its extension. +// As GD library can only generate pictures from jpeg and png files, if you +// ask if the filename is an image for thumbnail creation (second parameter +// set to true), the only authorized formats are jpeg and png. function is_image( $filename, $create_thumbnail = false ) { global $conf, $tab_ext_create_TN; - if ( is_file ( $filename ) ) + if ( is_file( $filename ) ) { $size = getimagesize( $filename ); // $size[2] == 1 means GIF diff --git a/admin/infos_images.php b/admin/infos_images.php index 7735caba2..29957b478 100644 --- a/admin/infos_images.php +++ b/admin/infos_images.php @@ -18,7 +18,7 @@ include_once( './include/isadmin.inc.php' ); include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' ); //------------------------------------------------------------------- functions -function check_date_format ( $date ) +function check_date_format( $date ) { // date arrives at this format : DD/MM/YYYY // checkdate ( int month, int day, int year) @@ -144,7 +144,7 @@ if ( isset( $page['cat'] ) ) } else { - echo $lang['infoimage_err_date']; + echo $lang['err_date']; } } //--------------------------------------------------------- form initialization @@ -221,6 +221,8 @@ if ( isset( $page['cat'] ) ) $thumbnail_url.= 'thumbnail/'; $thumbnail_url.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; $vtp->setVar( $sub, 'picture.thumbnail_url', $thumbnail_url ); + $url = '../picture.php?cat='.$_GET['cat_id'].'&image_id='.$row['id']; + $vtp->setVar( $sub, 'picture.url', add_session_id( $url ) ); $vtp->closeSession( $sub, 'picture' ); } } diff --git a/admin/thumbnail.php b/admin/thumbnail.php index 72f384a45..538b536b7 100644 --- a/admin/thumbnail.php +++ b/admin/thumbnail.php @@ -1,9 +1,9 @@ <?php /*************************************************************************** - * thumbnail.php is a part of PhpWebGallery * + * thumbnail.php * * ------------------- * - * last update : Thursday, July 25, 2002 * - * email : pierrick@z0rglub.com * + * application : PhpWebGallery 1.3 * + * author : Pierrick LE GALL <pierrick@z0rglub.com> * * * ***************************************************************************/ @@ -14,116 +14,116 @@ * the Free Software Foundation; * * * ***************************************************************************/ -include_once( "./include/isadmin.inc.php" ); - -function get_subdirs( $rep ) +include_once( './include/isadmin.inc.php' ); +//------------------------------------------------------------------- functions +// get_subdirs returns an array containing all sub directory names, +// excepting : '.', '..' and 'thumbnail'. +function get_subdirs( $dir ) { - $sub_rep = array(); - $i = 0; - if ( $opendir = opendir ( $rep ) ) + $sub_dirs = array(); + if ( $opendir = opendir( $dir ) ) { - while ( $file = readdir ( $opendir ) ) + while ( $file = readdir( $opendir ) ) { - if ( $file != "thumbnail" && $file != "." - && $file != ".." && is_dir ( $rep.$file ) ) + if ( $file != 'thumbnail' and $file != '.' + and $file != '..' and is_dir( $dir.'/'.$file ) ) { - $sub_rep[$i++] = $file; + array_push( $sub_dirs, $file ); } } } - return $sub_rep; + return $sub_dirs; } -/* - $tab_ext = array ( 'jpg', 'JPG','png','PNG' ); - $tab_tn_ext = array ( 'jpg', 'JPG','png','PNG', 'gif', 'GIF' ); -*/ +// get_images_without_thumbnail returns an array with all the picture names +// that don't have associated thumbnail in the directory. Each picture name +// is associated with the width, heigh and filesize of the picture. function get_images_without_thumbnail( $dir ) { - $i = 0; - if ( $opendir = opendir ( $dir ) ) + $images = array(); + if ( $opendir = opendir( $dir ) ) { - while ( $file = readdir ( $opendir ) ) + while ( $file = readdir( $opendir ) ) { - $lien_image = $dir."/".$file; - if ( is_image( $lien_image, true ) ) + $path = $dir.'/'.$file; + if ( is_image( $path, true ) ) { - if ( !TN_exist( $dir, $file ) ) + if ( !TN_exists( $dir, $file ) ) { - $taille_image = getimagesize( $lien_image ); - $size = floor ( filesize( $lien_image ) / 1024 ). " KB"; - $images[$i++] = array( 'name' => $file, - 'width' => $taille_image[0], - 'height' => $taille_image[1], - 'size' => $size - ); + $image_infos = getimagesize( $path ); + $size = floor( filesize( $path ) / 1024 ). ' KB'; + array_push( $images, array( 'name' => $file, + 'width' => $image_infos[0], + 'height' => $image_infos[1], + 'size' => $size ) ); } } } } return $images; } - -function scandir( $DIR, $width, $height ) + +// scandir scans a dir to find pictures without thumbnails. Once found, +// creation of the thumbnails (RatioResizeImg). Only the first $_POST['n'] +// pictures without thumbnails are treated. +// scandir returns an array with the generation time of each thumbnail (for +// statistics purpose) +function scandir( $dir, $width, $height ) { - global $HTTP_POST_VARS, $conf, $output; - $compteur = 0; - $temps = array(); - if ( $ODIR = opendir( $DIR ) ) + global $conf; + $stats = array(); + if ( $opendir = opendir( $dir ) ) { - while ( $FILE = readdir ( $ODIR ) ) + while ( $file = readdir ( $opendir ) ) { - $TMP = $DIR."/".$FILE; - if ( is_image ( $TMP, true ) ) + $path = $dir.'/'.$file; + if ( is_image( $path, true ) ) { - if ( $compteur < $HTTP_POST_VARS['n'] && !TN_exist( $DIR, $FILE ) ) + if ( count( $stats ) < $_POST['n'] and !TN_exists( $dir, $file ) ) { - $t1 = explode( " ", microtime() ); - $t2 = explode( ".", $t1[0] ); - $t2 = $t1[1].".".$t2[1]; - $info = RatioResizeImg( $FILE, $width, $height, $DIR."/", "jpg" ); - $t3 = explode( " ", microtime() ); - $t4 = explode( ".", $t3[0] ); - $t4 = $t3[1].".".$t4[1]; - $info['temps'] = ( $t4 - $t2 ) * 1000; - $temps[$compteur++] = $info; - //$output.= " (".number_format( $temps[$compteur-1], 2, '.', ' ')." ms)<br />";; + $starttime = get_moment(); + $info = RatioResizeImg( $file, $width, $height, $dir.'/', 'jpg' ); + $endtime = get_moment(); + $info['time'] = ( $endtime - $starttime ) * 1000; + array_push( $stats, $info ); } } } } - return $temps; + return $stats; } - -function RatioResizeImg( $image, $newWidth, $newHeight, $path, $extension) + +// RatioResizeImg creates a new picture (a thumbnail since it is supposed to +// be smaller than original picture !) in the sub directory named +// "thumbnail". +function RatioResizeImg( $filename, $newWidth, $newHeight, $path, $tn_ext ) { - global $conf, $HTTP_POST_VARS; - // chemin complet de l'image : - $chemin = $path.$image; - // détéction du type de l'image - eregi( "(...)$", $chemin, $regs); - $type = $regs[1]; - switch( $type ) + global $conf, $lang; + // full path to picture + $filepath = $path.$filename; + // extension of the picture filename + $extension = get_extension( $filepath ); + switch( $extension ) { - case "jpg": $srcImage = @imagecreatefromjpeg( $chemin ); break; - case "JPG": $srcImage = @imagecreatefromjpeg( $chemin ); break; - case "png": $srcImage = @imagecreatefrompng( $chemin ); break; - case "PNG": $srcImage = @imagecreatefrompng( $chemin ); break; - default : unset( $type ); break; + case 'jpg': $srcImage = @imagecreatefromjpeg( $filepath ); break; + case 'JPG': $srcImage = @imagecreatefromjpeg( $filepath ); break; + case 'png': $srcImage = @imagecreatefrompng( $filepath ); break; + case 'PNG': $srcImage = @imagecreatefrompng( $filepath ); break; + default : unset( $extension ); break; } - if( $srcImage ) + if ( isset( $srcImage ) ) { - // hauteurs/largeurs - $srcWidth = imagesx( $srcImage ); - $srcHeight = imagesy( $srcImage ); - $ratioWidth = $srcWidth/$newWidth; + // width/height + $srcWidth = imagesx( $srcImage ); + $srcHeight = imagesy( $srcImage ); + $ratioWidth = $srcWidth/$newWidth; $ratioHeight = $srcHeight/$newHeight; - - // taille maximale dépassée ? - if (($ratioWidth > 1) || ($ratioHeight > 1)) + + // maximal size exceeded ? + if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) ) { - if( $ratioWidth < $ratioHeight) + if ( $ratioWidth < $ratioHeight) { $destWidth = $srcWidth/$ratioHeight; $destHeight = $newHeight; @@ -139,58 +139,59 @@ function RatioResizeImg( $image, $newWidth, $newHeight, $path, $extension) $destWidth = $srcWidth; $destHeight = $srcHeight; } - // selon votre version de GD installée sur le serveur hébergeur - if ( $HTTP_POST_VARS['gd'] == 2 ) + // according to the GD version installed on the server + if ( $_POST['gd'] == 2 ) { - // Partie 1 : GD 2.0 ou supérieur, résultat très bons + // GD 2.0 or more recent -> good results (but slower) $destImage = imagecreatetruecolor( $destWidth, $destHeight); - imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0, $destWidth,$destHeight,$srcWidth,$srcHeight ); + imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0, + $destWidth,$destHeight,$srcWidth,$srcHeight ); } else { - // Partie 2 : GD inférieur à 2, résultat très moyens + // GD prior to version 2 -> pretty bad results :-/ (but fast) $destImage = imagecreate( $destWidth, $destHeight); - imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0, $destWidth,$destHeight,$srcWidth,$srcHeight ); + imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0, + $destWidth,$destHeight,$srcWidth,$srcHeight ); } - if( !is_dir( $path."thumbnail" ) ) + if( !is_dir( $path.'thumbnail' ) ) { - umask(0000); - mkdir( $path."thumbnail", 0777 ); + umask( 0000 ); + mkdir( $path.'thumbnail', 0777 ); } - $dest_file = $path."thumbnail/".$conf['prefix_thumbnail'].substr ( $image, 0, strrpos ( $image, ".") ).".".$extension; + $dest_file = $path.'thumbnail/'.$conf['prefix_thumbnail']; + $dest_file.= get_filename_wo_extension( $filename ); + $dest_file.= '.'.$tn_ext; - // création et sauvegarde de l'image finale - imagejpeg($destImage, $dest_file); - // libère la mémoire + // creation and backup of final picture + imagejpeg( $destImage, $dest_file ); + // freeing memory ressources imagedestroy( $srcImage ); imagedestroy( $destImage ); - // renvoit l'URL de l'image - //return $dest_file; - $taille_image = getimagesize( $chemin ); - $size = number_format( floor ( filesize( $chemin ) / 1024 ), 0, '', ' ')." KB"; - $tn_taille_image = getimagesize( $dest_file ); - $tn_size = number_format( floor ( filesize( $dest_file ) ), 0, '', ' ')." octets"; - $info = array( 'name' => $image, - 'width' => $taille_image[0], - 'height' => $taille_image[1], - 'size' => $size, - 'tn_name' => $conf['prefix_thumbnail'].substr ( $image, 0, strrpos ( $image, ".") ).".".$extension, - 'tn_width' => $tn_taille_image[0], - 'tn_height' => $tn_taille_image[1], - 'tn_size' => $tn_size - ); + list( $width,$height ) = getimagesize( $filepath ); + $size = floor( filesize( $filepath ) / 1024 ).' KB'; + list( $tn_width,$tn_height ) = getimagesize( $dest_file ); + $tn_size = floor( filesize( $dest_file ) / 1024 ).' KB'; + $info = array( 'file' => $filename, + 'width' => $width, + 'height' => $height, + 'size' => $size, + 'tn_file' => $dest_file, + 'tn_width' => $tn_width, + 'tn_height' => $tn_height, + 'tn_size' => $tn_size ); return $info; } - // erreur + // error else { echo $lang['tn_no_support']." "; - if ($type) + if ( isset( $extenstion ) ) { - echo $lang['tn_format']." $type"; + echo $lang['tn_format'].' '.$extension; } else { @@ -199,370 +200,227 @@ function RatioResizeImg( $image, $newWidth, $newHeight, $path, $extension) exit(); } } - + +// array_max returns the highest value of the given array function array_max( $array ) { - $max = 0; - for ( $i = 0; $i < sizeof( $array ); $i++ ) - { - if ( $array[$i] > $max ) - { - $max = $array[$i]; - } - } - return $max; + sort( $array, SORT_NUMERIC ); + return array_pop( $array ); } - + +// array_min returns the lowest value of the given array function array_min( $array ) { - $min = 99999999999999; - for ( $i = 0; $i < sizeof( $array ); $i++ ) - { - if ( $array[$i] < $min ) - { - $min = $array[$i]; - } - } - return $min; + sort( $array, SORT_NUMERIC ); + return array_shift( $array ); } - -function array_moy( $array ) + +// array_avg returns the average value of the array +function array_avg( $array ) { return array_sum( $array ) / sizeof( $array ); } -// get_dirs retourne un tableau contenant tous les sous-répertoires d'un répertoire -function get_displayed_dirs( $rep, $indent ) +// get_displayed_dirs builds the tree of dirs under "galleries". If a +// directory contains pictures without thumbnails, the become linked to the +// page of thumbnails creation. +function get_displayed_dirs( $dir, $indent ) { - global $conf,$lang; + global $conf,$lang,$vtp,$sub; - $sub_rep = array(); - $i = 0; - $dirs = ""; - if ( $opendir = opendir ( $rep ) ) - { - while ( $file = readdir ( $opendir ) ) - { - if ( $file != "." && $file != ".." && is_dir ( $rep."/".$file ) && $file != "thumbnail" ) - { - $sub_rep[$i++] = $file; - } - } - } + $sub_dirs = get_subdirs( $dir ); // write of the dirs - for ( $i = 0; $i < sizeof( $sub_rep ); $i++ ) - { - $images = get_images_without_thumbnail( $rep."/".$sub_rep[$i] ); - $nb_picture_without_TN = sizeof( $images ); - $dirs.= $indent; - if ( $nb_picture_without_TN > 0 ) + foreach ( $sub_dirs as $sub_dir ) { + $pictures = get_images_without_thumbnail( $dir.'/'.$sub_dir ); + $vtp->addSession( $sub, 'dir' ); + $vtp->setVar( $sub, 'dir.indent', $indent ); + if ( count( $pictures ) > 0 ) { - $dirs.= "<a href=\"".add_session_id_to_url( "./admin.php?page=thumbnail&dir=".$rep."/".$sub_rep[$i] )."\">"; + $vtp->addSession( $sub, 'linked' ); + $url = './admin.php?page=thumbnail&dir='.$dir."/".$sub_dir; + $vtp->setVar( $sub, 'linked.url', add_session_id( $url ) ); + $vtp->setVar( $sub, 'linked.name', $sub_dir ); + $vtp->setVar( $sub, 'linked.nb_pic', count( $pictures ) ); + $vtp->closeSession( $sub, 'linked' ); } - $dirs.= "<img src=\"".$conf['lien_puce']."\" style=\"border:none;\" alt=\">\"/>".$sub_rep[$i]; - if ( $nb_picture_without_TN > 0 ) - { - $dirs.= "</a>"; - } - if ( $nb_picture_without_TN > 0 ) + else { - $dirs.= " [ $nb_picture_without_TN ".$lang['tn_dirs_alone']." ]"; + $vtp->addSession( $sub, 'unlinked' ); + $vtp->setVar( $sub, 'unlinked.name', $sub_dir ); + $vtp->closeSession( $sub, 'unlinked' ); } - $dirs.= "<br />"; - $dirs.= get_displayed_dirs( $rep."/".$sub_rep[$i], $indent." " ); + $vtp->closeSession( $sub, 'dir' ); + // recursive call + $dirs.= get_displayed_dirs( $dir.'/'.$sub_dir, + $indent+30 ); + } - return $dirs; } - -$output = ""; - -if ( isset( $HTTP_GET_VARS['dir'] ) ) +//----------------------------------------------------- template initialization +$sub = $vtp->Open( '../template/'.$user['template'].'/admin/thumbnail.vtp' ); +$tpl = array( + 'tn_dirs_title','tn_dirs_alone','tn_params_title','tn_params_GD', + 'tn_params_GD_info','tn_width','tn_params_width_info','tn_height', + 'tn_params_height_info','tn_params_create','tn_params_create_info', + 'tn_params_format','tn_params_format_info','submit','tn_alone_title', + 'filesize','tn_picture','tn_results_title','thumbnail', + 'tn_results_gen_time','tn_stats','tn_stats_nb','tn_stats_total', + 'tn_stats_max','tn_stats_min','tn_stats_mean' ); +templatize_array( $tpl, 'lang', $sub ); +//----------------------------------------------------- miniaturization results +if ( isset( $_GET['dir'] ) ) { - //---------------vérification de la présence d'images sans thumbnail - $images = get_images_without_thumbnail( $HTTP_GET_VARS['dir'] ); - if ( sizeof( $images ) == 0 ) + $pictures = get_images_without_thumbnail( $_GET['dir'] ); + if ( count( $pictures ) == 0 ) { - $output.= "<div style=\"text-align:center;font-weight:bold;margin:10px;\"> [ 0 ".$lang['tn_dirs_alone']." ]</div>"; + $vtp->addSession( $sub, 'warning' ); + $vtp->closeSession( $sub, 'warning' ); } - else if ( isset( $HTTP_POST_VARS['submit'] ) ) + elseif ( isset( $_POST['submit'] ) ) { - //----------------------------------------vérification des variables - $nb_erreur = 0; - $erreur = ""; - if ( !ereg( "^[0-9]{2,3}$", $HTTP_POST_VARS['width'] ) || $HTTP_POST_VARS['width'] < 10 ) + // checking criteria + $errors = array(); + if ( !ereg( "^[0-9]{2,3}$", $_POST['width'] ) or $_POST['width'] < 10 ) { - $nb_erreur++; - $erreur.= "<li>".$lang['tn_err_width']." 10</li>"; + array_push( $errors, $lang['tn_err_width'].' 10' ); } - if ( !ereg( "^[0-9]{2,3}$", $HTTP_POST_VARS['height'] ) || $HTTP_POST_VARS['height'] < 10 ) + if ( !ereg( "^[0-9]{2,3}$", $_POST['height'] ) or $_POST['height'] < 10 ) { - $nb_erreur++; - $erreur.= "<li>".$lang['tn_err_height']." 10</li>"; + array_push( $errors, $lang['tn_err_height'].' 10' ); } - if ( !isset( $HTTP_POST_VARS['gd'] ) ) + // picture miniaturization + if ( count( $errors ) == 0 ) { - $nb_erreur++; - $erreur.= "<li>".$lang['tn_err_GD']."</li>"; - } - - //---------------------------------------------listing des résultats - if ( $nb_erreur == 0 ) - { - $style = "class=\"row2\" style=\"text-align:center;font-weight:bold;"; - $output.= " - <table style=\"width:100%;\"> - <tr> - <th colspan=\"10\">".$lang['tn_results_title']."</th> - </tr> - <tr> - <td ".$style."\"> </td> - <td ".$style."\">".$lang['tn_picture']."</td> - <td ".$style."\">".$lang['tn_filesize']."</td> - <td ".$style."\">".$lang['tn_width']."</td> - <td ".$style."\">".$lang['tn_height']."</td> - <td ".$style."background-color:#D3DCE3;\">".$lang['tn_results_gen_time']."</td> - <td ".$style."\">".$lang['thumbnail']."</td> - <td ".$style."\">".$lang['tn_filesize']."</td> - <td ".$style."\">".$lang['tn_width']."</td> - <td ".$style."\">".$lang['tn_height']."</td> - </tr>"; - $tab_infos = scandir( $HTTP_GET_VARS['dir'], $HTTP_POST_VARS['width'], $HTTP_POST_VARS['height'] ); - for ( $i = 0; $i < sizeof ( $tab_infos ); $i++ ) - { - $temps[$i] = $tab_infos[$i]['temps']; + $vtp->addSession( $sub, 'results' ); + $stats = scandir( $_GET['dir'], $_POST['width'], $_POST['height'] ); + $times = array(); + foreach ( $stats as $stat ) { + array_push( $times, $stat['time'] ); } - $max = array_max( $temps ); - $min = array_min( $temps ); - for ( $i = 0; $i < sizeof ( $tab_infos ); $i++ ) - { - $temps[$i] = $tab_infos[$i]['temps']; - $num = $i + 1; - $class = ""; - if ( $i%2 == 1 ) + $max = array_max( $times ); + $min = array_min( $times ); + foreach ( $stats as $i => $stat ) { + $vtp->addSession( $sub, 'picture' ); + if ( $i % 2 == 1 ) { - $class = "class=\"row2\""; + $vtp->setVar( $sub, 'picture.class', 'row2' ); } - $output.= " - <tr> - <td class=\"row2\">$num</td> - <td $class>".$tab_infos[$i]['name']."</td> - <td $class style=\"text-align:right;\">".$tab_infos[$i]['size']."</td> - <td $class style=\"text-align:right;\">".$tab_infos[$i]['width']."</td> - <td $class style=\"text-align:right;\">".$tab_infos[$i]['height']."</td> - <th><div style=\"text-align:right;margin-right:5px;"; - if ( $tab_infos[$i]['temps'] == $max ) + $vtp->setVar( $sub, 'picture.num', ($i+1) ); + $vtp->setVar( $sub, 'picture.file', $stat['file'] ); + $vtp->setVar( $sub, 'picture.filesize', $stat['size'] ); + $vtp->setVar( $sub, 'picture.width', $stat['width'] ); + $vtp->setVar( $sub, 'picture.height', $stat['height'] ); + $vtp->setVar( $sub, 'picture.thumb_file', $stat['tn_file'] ); + $vtp->setVar( $sub, 'picture.thumb_filesize', $stat['tn_size'] ); + $vtp->setVar( $sub, 'picture.thumb_width', $stat['tn_width'] ); + $vtp->setVar( $sub, 'picture.thumb_height', $stat['tn_height'] ); + $vtp->setVar( $sub, 'picture.time', + number_format( $stat['time'], 2, '.', ' ').' ms' ); + if ( $stat['time'] == $max ) { - $output.= "color:red;"; + $vtp->setVar( $sub, 'picture.color', 'red' ); } - if ( $tab_infos[$i]['temps'] == $min ) + else if ( $stat['time'] == $min ) { - $output.= "color:green;"; + $vtp->setVar( $sub, 'picture.color', 'green' ); } - $output.= "\">".number_format( $tab_infos[$i]['temps'], 2, '.', ' ')." ms</div></th> - <td $class>".$tab_infos[$i]['tn_name']."</td> - <td $class style=\"text-align:right;\">".$tab_infos[$i]['tn_size']."</td> - <td $class style=\"text-align:right;\">".$tab_infos[$i]['tn_width']."</td> - <td $class style=\"text-align:right;\">".$tab_infos[$i]['tn_height']."</td> - </tr>"; + $vtp->closeSession( $sub, 'picture' ); } - $output.= " - <tr> - <td colspan=\"10\"> </td> - </tr> - </table> - <table style=\"margin:auto;border:1px solid black;\"> - <tr> - <td colspan=\"2\" style=\"text-align:center;font-weight:bold;\" class=\"row2\">".$lang['tn_stats']."</td> - </tr> - <tr> - <td>".$lang['tn_stats_nb']." : </td> - <td style=\"text-align:center;\">".sizeof( $temps )."</td> - </tr> - <tr> - <td>".$lang['tn_stats_total']." : </td> - <td style=\"text-align:right;\">".number_format( array_sum( $temps ), 2, '.', ' ')." ms</td> - </tr> - <tr> - <td>".$lang['tn_stats_max']." : </td> - <td style=\"text-align:right;\">".number_format( $max, 2, '.', ' ')." ms</td> - </tr> - <tr> - <td>".$lang['tn_stats_min']." : </td> - <td style=\"text-align:right;\">".number_format( $min, 2, '.', ' ')." ms</td> - </tr> - <tr> - <td>".$lang['tn_stats_mean']." : </td> - <td style=\"text-align:right;\">".number_format( array_moy( $temps ), 2, '.', ' ')." ms</td> - </tr> - </table> - <table> - <tr> - <td> </td> - </tr> - </table>"; + // general statistics + $vtp->setVar( $sub, 'results.stats_nb', count( $stats ) ); + $vtp->setVar( $sub, 'results.stats_total', + number_format( array_sum( $times ), 2, '.', ' ').' ms' ); + $vtp->setVar( $sub, 'results.stats_max', + number_format( $max, 2, '.', ' ').' ms' ); + $vtp->setVar( $sub, 'results.stats_min', + number_format( $min, 2, '.', ' ').' ms' ); + $vtp->setVar( $sub, 'results.stats_mean', + number_format( array_avg( $times ), 2, '.', ' ').' ms' ); + $vtp->closeSession( $sub, 'results' ); } else { - $output.= " - <div class=\"erreur\" style=\"margin-top:10px;\">".$lang['tn_err']."</div> - <div class=\"erreur\" style=\"text-align:left;margin-left:20px;\"> - <ul> - $erreur - </ul> - </div>"; + $vtp->addSession( $sub, 'errors' ); + foreach ( $errors as $error ) { + $vtp->addSession( $sub, 'li' ); + $vtp->setVar( $sub, 'li.li', $error ); + $vtp->closeSession( $sub, 'li' ); + } + $vtp->closeSession( $sub, 'errors' ); } } - //-------------------------------------paramètres de miniaturisation - if ( sizeof( $images ) != 0 ) +//-------------------------------------------------- miniaturization parameters + if ( sizeof( $pictures ) != 0 ) { - $output.= " - <style> - div.key - { - margin-left : 10px; - } - td.choice - { - text-align : center; - } - </style>"; - $output.= " - <form method=\"post\" action=\"".add_session_id_to_url( "./admin.php?page=thumbnail&dir=".$HTTP_GET_VARS['dir'] )."\"> - <table style=\"width:100%;\"> - <tr> - <th colspan=\"3\">".$lang['tn_params_title']."</th> - </tr>"; - $output.= " - <tr> - <td colspan=\"3\"> </td> - </tr>"; - $output.= " - <tr> - <td><div class=\"key\">".$lang['tn_params_GD']."</div></td> - <td class=\"choice\"> - <input type=\"radio\" name=\"gd\" value=\"2\"/ checked=\"checked\">2.x - <input type=\"radio\" name=\"gd\" value=\"1\""; - if ( $HTTP_POST_VARS['gd'] == 1 ) + $vtp->addSession( $sub, 'params' ); + $url = './admin.php?page=thumbnail&dir='.$_GET['dir']; + $vtp->setVar( $sub, 'params.action', add_session_id( $url ) ); + // GD version selected... + if ( $_POST['gd'] == 1 ) + { + $vtp->setVar( $sub, 'params.gd1_checked', ' checked="checked"' ); + } + else { - $output.= " checked=\"checked\""; + $vtp->setVar( $sub, 'params.gd2_checked', ' checked="checked"' ); } - $output.= "/>1.x - </td> - <td style=\"width:50%;\" class=\"row2\">".$lang['tn_params_GD_info']."</td> - </tr> - <tr> - <td><div class=\"key\">".$lang['tn_width']."</div></td> - <td class=\"choice\"><input type=\"text\" name=\"width\" value=\""; - if ( isset( $HTTP_POST_VARS['width'] ) ) + // width values + if ( isset( $_POST['width'] ) ) { - $output.= $HTTP_POST_VARS['width']; + $vtp->setVar( $sub, 'params.width_value', $_POST['width'] ); } else { - $output.= "128"; + $vtp->setVar( $sub, 'params.width_value', '128' ); } - $output.="\"/></td> - <td class=\"row2\">".$lang['tn_params_width_info']."</td> - </tr> - <tr> - <td><div class=\"key\">".$lang['tn_height']."</div></td> - <td class=\"choice\"><input type=\"text\" name=\"height\" value=\""; - if ( isset( $HTTP_POST_VARS['height'] ) ) + // height value + if ( isset( $_POST['height'] ) ) { - $output.= $HTTP_POST_VARS['height']; + $vtp->setVar( $sub, 'params.height_value', $_POST['height'] ); } else { - $output.= "96"; + $vtp->setVar( $sub, 'params.height_value', '96' ); } - $output.="\"/></td> - <td class=\"row2\">".$lang['tn_params_height_info']."</td> - </tr> - <tr> - <td><div class=\"key\">".$lang['tn_params_create']."</div></td> - <td class=\"choice\"> - <select name=\"n\"> - <option>5</option> - <option>10</option> - <option>20</option> - <option>40</option> - </select> - </td> - <td class=\"row2\">".$lang['tn_params_create_info']."</td> - </tr> - <tr> - <td><div class=\"key\">".$lang['tn_params_format']."</div></td> - <td class=\"choice\"><span style=\"font-weight:bold;\">jpeg</span></td> - <td class=\"row2\">".$lang['tn_params_format_info']."</td> - </tr> - <tr> - <td colspan=\"3\"> </td> - </tr> - <tr> - <td colspan=\"3\" style=\"text-align:center;\"> - <input type=\"submit\" name=\"submit\" value=\"".$lang['submit']."\"/> - </td> - </tr>"; - $output.= " - </table> - </form>"; - //-----------------------------------liste des images sans miniature - $images = get_images_without_thumbnail( $HTTP_GET_VARS['dir'] ); - $style = "class=\"row2\" style=\"text-align:center;font-weight:bold;"; - $output.= " - <table style=\"width:100%;\"> - <tr> - <th colspan=\"5\"><span style=\"color:#006699;\">".sizeof( $images )."</span> ".$lang['tn_alone_title']."</th> - </tr> - <tr> - <td ".$style."\"> </td> - <td ".$style."width:50%;\">".$lang['tn_picture']."</td> - <td ".$style."width:17%;\">".$lang['tn_filesize']."</td> - <td ".$style."width:17%;\">".$lang['tn_width']."</td> - <td ".$style."width:16%;\">".$lang['tn_height']."</td> - </tr>"; - for ( $i = 0; $i < sizeof( $images ); $i++ ) - { - $num = $i + 1; - $class = ""; - if ( $i%2 == 1 ) + // options for the number of picture to miniaturize : "n" + $options = array( 5,10,20,40 ); + foreach ( $options as $option ) { + $vtp->addSession( $sub, 'n_option' ); + $vtp->setVar( $sub, 'n_option.option', $option ); + if ( $option == $_POST['n'] ) + { + $vtp->setVar( $sub, 'n_option.selected', ' selected="selected"' ); + } + $vtp->closeSession( $sub, 'n_option' ); + } + $vtp->closeSession( $sub, 'params' ); +//---------------------------------------------------------- remaining pictures + $vtp->addSession( $sub, 'remainings' ); + $pictures = get_images_without_thumbnail( $_GET['dir'] ); + $vtp->setVar( $sub, 'remainings.total', count( $pictures ) ); + foreach ( $pictures as $i => $picture ) { + $vtp->addSession( $sub, 'remaining' ); + if ( $i % 2 == 1 ) { - $class = " class=\"row2\""; + $vtp->setVar( $sub, 'remaining.class', 'row2' ); } - $output.= " - <tr> - <td class=\"row2\">".$num."</td> - <td $class><div style=\"margin-left:10px;\">".$images[$i]['name']."</div></td> - <td $class><div style=\"margin-left:10px;\">".$images[$i]['size']."</div></td> - <td $class><div style=\"margin-left:10px;\">".$images[$i]['width']."</div></td> - <td $class><div style=\"margin-left:10px;\">".$images[$i]['height']."</div></td> - </tr>"; + $vtp->setVar( $sub, 'remaining.num', ($i+1) ); + $vtp->setVar( $sub, 'remaining.file', $picture['name'] ); + $vtp->setVar( $sub, 'remaining.filesize', $picture['size'] ); + $vtp->setVar( $sub, 'remaining.width', $picture['width'] ); + $vtp->setVar( $sub, 'remaining.height', $picture['height'] ); + $vtp->closeSession( $sub, 'remaining' ); } - $output.= " - </table>"; + $vtp->closeSession( $sub, 'remainings' ); } } -//-----------------------------------liste des répertoires -//-------------------------si aucun répertoire selectionné +//-------------------------------------------------------------- directory list else { - $output = " - <table style=\"width:100%;\"> - <tr> - <th>".$lang['tn_dirs_title']."</th> - </tr>"; - $output.= " - <tr> - <td> - <div class=\"retrait\"> - <img src=\"".$conf['lien_puce']."\" alt=\"\"/>galleries"; - $output.= "<br />"; - $output.= get_displayed_dirs( "../galleries", " " ); - $output.= " - </div> - </td> - </tr> - </table>"; + $vtp->addSession( $sub, 'directory_list' ); + get_displayed_dirs( '../galleries', 60 ); + $vtp->closeSession( $sub, 'directory_list' ); } -echo $output; +//----------------------------------------------------------- sending html code +$vtp->Parse( $handle , 'sub', $sub ); ?>
\ No newline at end of file diff --git a/admin/update.php b/admin/update.php index bdd4d8a43..eefd913c1 100644 --- a/admin/update.php +++ b/admin/update.php @@ -187,20 +187,21 @@ function insert_local_image( $rep, $category_id ) // searching the new images in the directory $pictures = array(); $tn_ext = ''; - if ( $opendir = opendir ( $rep ) ) + if ( $opendir = opendir( $rep ) ) { - while ( $file = readdir ( $opendir ) ) + while ( $file = readdir( $opendir ) ) { if ( is_file( $rep.'/'.$file ) and is_image( $rep.'/'.$file ) ) { // is the picture waiting for validation by an administrator ? - $query = 'SELECT id'; + $query = 'SELECT id,validated,infos'; $query.= ' FROM '.PREFIX_TABLE.'waiting'; $query.= ' WHERE cat_id = '.$category_id; $query.= " AND file = '".$file."'"; $query.= ';'; $result = mysql_query( $query ); - if ( mysql_num_rows( $result ) == 0 ) + $waiting = mysql_fetch_array( $result ); + if (mysql_num_rows( $result ) == 0 or $waiting['validated'] == 'true') { if ( $tn_ext = TN_exists( $rep, $file ) ) { @@ -214,13 +215,33 @@ function insert_local_image( $rep, $category_id ) if ( mysql_num_rows( $result ) == 0 ) { $picture = array(); - $picture['file'] = $file; - $picture['tn_ext'] = $tn_ext; + $picture['file'] = $file; + $picture['tn_ext'] = $tn_ext; $picture['date'] = date( 'Y-m-d', filemtime ( $rep.'/'.$file ) ); $picture['filesize'] = floor( filesize( $rep.'/'.$file ) / 1024); $image_size = @getimagesize( $rep.'/'.$file ); - $picture['width'] = $image_size[0]; - $picture['height'] = $image_size[1]; + $picture['width'] = $image_size[0]; + $picture['height'] = $image_size[1]; + if ( $waiting['validated'] == 'true' ) + { + // retrieving infos from the XML description of + // $waiting['infos'] + $infos = nl2br( $waiting['infos'] ); + $picture['author'] = getAttribute( $infos, 'author' ); + $picture['comment'] = getAttribute( $infos, 'comment' ); + $unixtime = getAttribute( $infos, 'date_creation' ); + $picture['date_creation'] = ''; + if ( $unixtime != '' ) + { + $picture['date_creation'] = date( 'Y-m-d', $unixtime ); + } + $picture['name'] = getAttribute( $infos, 'name' ); + // deleting the waiting element + $query = 'DELETE FROM '.PREFIX_TABLE.'waiting'; + $query.= ' WHERE id = '.$waiting['id']; + $query.= ';'; + mysql_query( $query ); + } array_push( $pictures, $picture ); } } @@ -242,13 +263,23 @@ function insert_local_image( $rep, $category_id ) // inserting the pictures found in the directory foreach ( $pictures as $picture ) { $query = 'INSERT INTO '.PREFIX_TABLE.'images'; - $query.= ' (file,cat_id,date_available,tn_ext,filesize,width,height)'; + $query.= ' (file,cat_id,date_available,tn_ext,filesize,width,height'; + $query.= ',name,author,comment,date_creation)'; $query.= ' VALUES '; $query.= "('".$picture['file']."','".$category_id."'"; $query.= ",'".$picture['date']."','".$picture['tn_ext']."'"; $query.= ",'".$picture['filesize']."','".$picture['width']."'"; - $query.= ",'".$picture['height']."')"; - $query.= ';'; + $query.= ",'".$picture['height']."','".$picture['name']."'"; + $query.= ",'".$picture['author']."','".$picture['comment']."'"; + if ( $picture['date_creation'] != '' ) + { + $query.= ",'".$picture['date_creation']."'"; + } + else + { + $query.= ',NULL'; + } + $query.= ');'; mysql_query( $query ); $count_new++; @@ -283,7 +314,7 @@ function update_cat_info( $category_id ) $nb_images = $row['nb_images']; $query = 'UPDATE '.PREFIX_TABLE.'categories'; - $query.= " SET date_dernier = '".$date_last."'"; + $query.= " SET date_last = '".$date_last."'"; $query.= ', nb_images = '.$nb_images; $query.= ' where id = '.$category_id; $query.= ';'; diff --git a/admin/waiting.php b/admin/waiting.php index 2f1964266..2525c95ab 100644 --- a/admin/waiting.php +++ b/admin/waiting.php @@ -1,9 +1,9 @@ <?php /*************************************************************************** - * waiting.php is a part of PhpWebGallery * + * waiting.php * * ------------------- * - * last update : Monday, October 28, 2002 * - * email : pierrick@z0rglub.com * + * application : PhpWebGallery 1.3 * + * author : Pierrick LE GALL <pierrick@z0rglub.com> * * * ***************************************************************************/ @@ -14,104 +14,121 @@ * the Free Software Foundation; * * * ***************************************************************************/ - include_once( "./include/isadmin.inc.php" ); - //-------------------------------------------------------------- mise à jour - if ( isset( $HTTP_POST_VARS['submit'] ) ) - { - $query = "select id,cat_id,file,tn_ext"; - $query.= " from PREFIX_TABLE"."waiting"; - $query.= ";"; - $result = mysql_query( $query ); - while ( $row = mysql_fetch_array( $result ) ) - { - $key = "validate-".$row['id']; - if ( isset( $HTTP_POST_VARS[$key] ) ) - { - $query = "delete from PREFIX_TABLE"."waiting"; - $query.= " where id = ".$row['id']; - $query.= ";"; - mysql_query( $query ); - if ( $HTTP_POST_VARS[$key] == "false" ) - { - // we have to delete the picture and the thumbnail if it exists - $cat = get_cat_info( $row['cat_id'] ); - unlink( ".".$cat['dir'].$row['file'] ); - if ( $row['tn_ext'] != "" ) - { - $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); - unlink( ".".$cat['dir']."thumbnail/".$conf['prefix_thumbnail'].$file.".".$row['tn_ext'] ); - } - } - } - } - } - //--------------------------------------------------------------- formulaire - $cat_names = array(); - echo " - <form action=\"".add_session_id_to_url( "./admin.php?page=waiting" )."\" method=\"post\"> - <table style=\"width:100%;\"> - <tr> - <th style=\"width:20%;\">".$lang['category']."</th> - <th style=\"width:20%;\">".$lang['date']."</th> - <th style=\"width:20%;\">".$lang['file']."</th> - <th style=\"width:20%;\">".$lang['thumbnail']."</th> - <th style=\"width:20%;\">".$lang['author']."</th> - <th style=\"width:1px;\"> </th> - </tr>"; - $query = "select id,cat_id,file,username,mail_address,date,tn_ext"; - $query.= " from PREFIX_TABLE"."waiting"; - $query.= " order by cat_id"; - $query.= ";"; - $result = mysql_query( $query ); - $i = 0; - while ( $row = mysql_fetch_array( $result ) ) - { - $style = ""; - if ( $i%2 == 0 ) - { - $style = "class=\"row2\""; - } - if ( !isset( $cat_names[$row['cat_id']] ) ) - { - $cat = get_cat_info( $row['cat_id'] ); - $cat_names[$row['cat_id']] = array(); - $cat_names[$row['cat_id']]['dir'] = ".".$cat['dir']; - $cat_names[$row['cat_id']]['display_name'] = get_cat_display_name( $cat['name'], " - ", "font-style:italic;" ); - } - echo " - <tr> - <td $style style=\"white-space:nowrap;\">".$cat_names[$row['cat_id']]['display_name']."</td> - <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> - <td $style style=\"white-space:nowrap;\"> - <a target=\"_blank\" href=\"".$cat_names[$row['cat_id']]['dir'].$row['file']."\">".$row['file']."</td> - </td> - <td $style style=\"white-space:nowrap;\">"; - if ( $row['tn_ext'] != "" ) - { - $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") ); - 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']; - } - else - { - echo " "; - } - echo " - </td> - <td $style style=\"white-space:nowrap;\"> - <a href=\"mailto:".$row['mail_address']."\">".$row['username']."</a> - </td> - <td $style style=\"white-space:nowrap;\"> - <input type=\"radio\" name=\"validate-".$row['id']."\" value=\"true\" />".$lang['submit']." - <input type=\"radio\" name=\"validate-".$row['id']."\" value=\"false\" />".$lang['delete']." - </td> - </tr>"; - $i++; - } - echo " - <tr> - <td colspan=\"5\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"".$lang['submit']."\" style=\"margin:5px;\" /></td> - </tr>"; - echo " - </table> - </form>"; +include_once( './include/isadmin.inc.php' ); +//--------------------------------------------------------------------- updates +if ( isset( $_POST['submit'] ) ) +{ + $query = 'SELECT id,cat_id,file,tn_ext'; + $query.= ' FROM '.PREFIX_TABLE.'waiting'; + $query.= " WHERE validated = 'false'"; + $query.= ';'; + $result = mysql_query( $query ); + while ( $row = mysql_fetch_array( $result ) ) + { + $key = 'validate-'.$row['id']; + if ( isset( $_POST[$key] ) ) + { + if ( $_POST[$key] == 'true' ) + { + // The uploaded element was validated, we have to set the + // "validated" field to "true" + $query = 'UPDATE '.PREFIX_TABLE.'waiting'; + $query.= " SET validated = 'true'"; + $query.= ' WHERE id = '.$row['id']; + $query.= ';'; + mysql_query( $query ); + } + else + { + // The uploaded element was refused, we have to delete its reference + // in the database and to delete the element as well. + $query = 'DELETE FROM '.PREFIX_TABLE.'waiting'; + $query.= ' WHERE id = '.$row['id']; + $query.= ';'; + mysql_query( $query ); + // deletion of the associated files + $cat = get_cat_info( $row['cat_id'] ); + unlink( '.'.$cat['dir'].$row['file'] ); + if ( $row['tn_ext'] != '' ) + { + $thumbnail = $conf['prefix_thumbnail']; + $thumbnail.= get_filename_wo_extension( $row['file'] ); + $thumbnail.= '.'.$row['tn_ext']; + $url = '.'.$cat['dir'].'thumbnail/'.$thumbnail; + unlink( $url ); + } + } + } + } +} +//----------------------------------------------------- template initialization +$sub = $vtp->Open( '../template/'.$user['template'].'/admin/waiting.vtp' ); +$tpl = array( 'category','date','author','thumbnail','file','delete', + 'submit' ); +templatize_array( $tpl, 'lang', $sub ); +//---------------------------------------------------------------- form display +$cat_names = array(); +$query = 'SELECT id,cat_id,file,username,mail_address,date,tn_ext'; +$query.= ' FROM '.PREFIX_TABLE.'waiting'; +$query.= " WHERE validated = 'false'"; +$query.= ' ORDER BY cat_id'; +$query.= ';'; +$result = mysql_query( $query ); +$i = 0; +while ( $row = mysql_fetch_array( $result ) ) +{ + $vtp->addSession( $sub, 'picture' ); + $vtp->setVar( $sub, 'picture.id', $row['id'] ); + if ( $i++ % 2 == 0 ) + { + $vtp->setVar( $sub, 'picture.class', 'row2' ); + } + if ( !isset( $cat_names[$row['cat_id']] ) ) + { + $cat = get_cat_info( $row['cat_id'] ); + $cat_names[$row['cat_id']] = array(); + $cat_names[$row['cat_id']]['dir'] = '.'.$cat['dir']; + $cat_names[$row['cat_id']]['display_name'] = + get_cat_display_name( $cat['name'], ' > ', 'font-weight:bold;' ); + } + // category name + $vtp->setVar( $sub, 'picture.cat_name', + $cat_names[$row['cat_id']]['display_name'] ); + // date displayed like this (in English ) : + // Sunday 15 June 2003 21:29 + $date = $lang['day'][date( 'w', $row['date'] )]; // Sunday + $date.= date( ' j ', $row['date'] ); // 15 + $date.= $lang['month'][date( 'n', $row['date'] )]; // June + $date.= date( ' Y G:i', $row['date'] ); // 2003 21:29 + $vtp->setVar( $sub, 'picture.date', $date ); + // file preview link + $url = $cat_names[$row['cat_id']]['dir'].$row['file']; + $vtp->setVar( $sub, 'picture.preview_url', $url ); + // file name + $vtp->setVar( $sub, 'picture.file', $row['file'] ); + // is there an existing associated thumnail ? + if ( $row['tn_ext'] != '' ) + { + $vtp->addSession( $sub, 'thumbnail' ); + $thumbnail = $conf['prefix_thumbnail']; + $thumbnail.= get_filename_wo_extension( $row['file'] ); + $thumbnail.= '.'.$row['tn_ext']; + $url = $cat_names[$row['cat_id']]['dir'].'thumbnail/'.$thumbnail; + $vtp->setVar( $sub, 'thumbnail.preview_url', $url ); + $vtp->setVar( $sub, 'thumbnail.file', $thumbnail ); + $vtp->closeSession( $sub, 'thumbnail' ); + } + else + { + $vtp->addSession( $sub, 'no_thumbnail' ); + $vtp->closeSession( $sub, 'no_thumbnail' ); + } + // username and associated mail address + $vtp->setVar( $sub, 'picture.mail_address', $row['mail_address'] ); + $vtp->setVar( $sub, 'picture.username', $row['username'] ); + + $vtp->closeSession( $sub, 'picture' ); +} +//----------------------------------------------------------- sending html code +$vtp->Parse( $handle , 'sub', $sub ); ?>
\ No newline at end of file |