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 | |
parent | 55a0a61aaf58a02e2ac5d2c489f81b1be4730cd8 (diff) |
*** empty log message ***
git-svn-id: http://piwigo.org/svn/trunk@26 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-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 | ||||
-rw-r--r-- | category.php | 138 | ||||
-rw-r--r-- | identification.php | 8 | ||||
-rw-r--r-- | include/config.inc.php | 13 | ||||
-rw-r--r-- | include/functions.inc.php | 29 | ||||
-rw-r--r-- | include/functions_category.inc.php | 381 | ||||
-rw-r--r-- | include/functions_user.inc.php | 19 | ||||
-rw-r--r-- | include/init.inc.php | 6 | ||||
-rw-r--r-- | include/user.inc.php | 18 | ||||
-rw-r--r-- | language/francais.php | 66 | ||||
-rw-r--r-- | picture.php | 82 | ||||
-rw-r--r-- | profile.php | 125 | ||||
-rwxr-xr-x | template/default/images/php_sqreuil_artistes.gif | bin | 0 -> 17884 bytes | |||
-rw-r--r-- | upload.php | 83 |
25 files changed, 1058 insertions, 1116 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 diff --git a/category.php b/category.php index 37e7deea0..0e5c8077d 100644 --- a/category.php +++ b/category.php @@ -20,7 +20,13 @@ $t2 = explode( '.', $t1[0] ); $t2 = $t1[1].'.'.$t2[1]; //----------------------------------------------------------- personnal include include_once( './include/init.inc.php' ); +$output.= 'after init.inc.php : '.get_elapsed_time( $t2, get_moment() ).'<br />'; //-------------------------------------------------- access authorization check +// creating the plain structure : array of all the available categories and +// their relative informations, see the definition of the function +// get_plain_structure for further details. +$page['plain_structure'] = get_plain_structure(); + check_cat_id( $_GET['cat'] ); check_login_authorization(); if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) @@ -34,33 +40,18 @@ if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) $page['tab_expand'] = array(); if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' ) { - $j = 0; - $tab_expand = explode( ",", $_GET['expand'] ); - $size = sizeof( $tab_expand ); - for ( $i = 0; $i < $size; $i++ ) - { - if ( is_numeric( $tab_expand[$i] ) ) - { - $page['tab_expand'][$j++] = $tab_expand[$i]; - } + $tab_expand = explode( ',', $_GET['expand'] ); + foreach ( $tab_expand as $id ) { + if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id ); } $page['expand'] = implode( ',', $page['tab_expand'] ); } // in case of expanding all authorized cats // The $page['expand'] equals 'all' and // $page['tab_expand'] contains all the authorized cat ids -if ( $user['expand'] == 'true' or $_GET['expand'] == 'all' ) +if ( $user['expand'] or $_GET['expand'] == 'all' ) { $page['tab_expand'] = array(); - $query = 'SELECT id'; - $query.= ' FROM '.PREFIX_TABLE.'categories'; - $query.= ' WHERE id_uppercat IS NULL;'; - $result = mysql_query( $query ); - $i = 0; - while ( $row = mysql_fetch_array( $result ) ) - { - $page['tab_expand'][$i++] = $row['id']; - } $page['expand'] = 'all'; } // detection of the start picture to display @@ -83,23 +74,28 @@ if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 ) $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] ); $page['start']*= $user['nb_image_page']; } +// creating the structure of the categories (useful for displaying the menu) +$page['structure'] = create_structure( '', $user['restrictions'] ); +$page['structure'] = update_structure( $page['structure'] ); initialize_category(); +$output.= 'before template init : '.get_elapsed_time( $t2, get_moment() ).'<br />'; //----------------------------------------------------- template initialization $vtp = new VTemplate; $handle = $vtp->Open( './template/'.$user['template'].'/category.vtp' ); initialize_template(); - -$tpl = array( 'categories','hint_category','sub-cat','images_available', - 'total','title_menu','nb_image_category','send_mail', - 'title_send_mail','generation_time','upload_name', - 'connected_user','recent_image','days','generation_time', - 'favorite_cat_hint','favorite_cat','stats', - 'most_visited_cat_hint','most_visited_cat','recent_cat', - 'recent_cat_hint' ); +$output.= 'before lang array : '.get_elapsed_time( $t2, get_moment() ).'<br />'; +$tpl = array( + 'categories','hint_category','sub-cat','images_available','total', + 'title_menu','nb_image_category','send_mail','title_send_mail', + 'generation_time','connected_user','recent_image','days','generation_time', + 'favorite_cat_hint','favorite_cat','stats','most_visited_cat_hint', + 'most_visited_cat','recent_cat','recent_cat_hint','upload_picture' ); templatize_array( $tpl, 'lang', $handle ); +$output.= 'after lang array : '.get_elapsed_time( $t2, get_moment() ).'<br />'; $tpl = array( 'mail_webmaster','webmaster','top_number','version','site_url' ); templatize_array( $tpl, 'conf', $handle ); +$output.= 'after conf array : '.get_elapsed_time( $t2, get_moment() ).'<br />'; $tpl = array( 'short_period','long_period','lien_collapsed', 'username' ); templatize_array( $tpl, 'user', $handle ); @@ -111,17 +107,22 @@ templatize_array( $tpl, 'page', $handle ); $vtp->setGlobalVar( $handle, 'icon_short', get_icon( time() ) ); $icon_long = get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) ); $vtp->setGlobalVar( $handle, 'icon_long', $icon_long ); -$nb_total_pictures = get_total_image( "", $user['restrictions'] ); +$nb_total_pictures = count_images( $page['structure'] ); $vtp->setGlobalVar( $handle, 'nb_total_pictures',$nb_total_pictures ); //------------------------------------------------------------- categories menu +$output.= 'before menu : '.get_elapsed_time( $t2, get_moment() ).'<br />'; // normal categories -display_cat( '', ' ', $user['restrictions'], $page['tab_expand'] ); +foreach ( $page['structure'] as $category ) { + // display category is a function relative to the template + display_category( $category, ' ', $handle ); +} +$output.= 'after menu : '.get_elapsed_time( $t2, get_moment() ).'<br />'; // favorites cat if ( !$user['is_the_guest'] ) { $vtp->addSession( $handle, 'favorites' ); - $url = add_session_id('./category.php?cat=fav&expand='.$page['expand'] ); - $vtp->setVar( $handle, 'favorites.url', $url ); + $url = './category.php?cat=fav&expand='.$page['expand']; + $vtp->setVar( $handle, 'favorites.url', add_session_id( $url ) ); // searching the number of favorite picture $query = 'SELECT COUNT(*) AS count'; $query.= ' FROM '.PREFIX_TABLE.'favorites'; @@ -132,27 +133,23 @@ if ( !$user['is_the_guest'] ) $vtp->closeSession( $handle, 'favorites' ); } // most visited pictures category -$url = add_session_id( './category.php?cat=most_visited'. - '&expand='.$page['expand'] ); -$vtp->setGlobalVar( $handle, 'most_visited_url', $url ); +$url = './category.php?cat=most_visited&expand='.$page['expand']; +$vtp->setGlobalVar( $handle, 'most_visited_url', add_session_id( $url ) ); // recent pictures -$url = add_session_id( './category.php?cat=recent'. - '&expand='.$page['expand'] ); -$vtp->setGlobalVar( $handle, 'recent_url', $url ); +$url = './category.php?cat=recent&expand='.$page['expand']; +$vtp->setGlobalVar( $handle, 'recent_url', add_session_id( $url ) ); //--------------------------------------------------------------------- summary $vtp->addSession( $handle, 'summary' ); $vtp->setVar( $handle, 'summary.url', './identification.php' ); if ( !$user['is_the_guest'] ) { $vtp->setVar( $handle, 'summary.title', '' ); - $vtp->setVar( $handle, 'summary.name', - replace_space( $lang['change_login'] ) ); + $vtp->setVar( $handle, 'summary.name',replace_space($lang['change_login'])); } else { $vtp->setVar( $handle, 'summary.title', $lang['hint_login'] ); - $vtp->setVar( $handle, 'summary.name', - replace_space( $lang['login'] ) ); + $vtp->setVar( $handle, 'summary.name', replace_space( $lang['login'] ) ); } $vtp->closeSession( $handle, 'summary' ); // links for registered users @@ -185,8 +182,8 @@ $vtp->setVar( $handle, 'summary.name', replace_space( $lang['search'] ) ); $vtp->closeSession( $handle, 'summary' ); // about link $vtp->addSession( $handle, 'summary' ); -$vtp->setVar( $handle, 'summary.url', - add_session_id( './about.php?'.$_SERVER['QUERY_STRING'] ) ); +$vtp->setVar( $handle, 'summary.url', './about.php?'. + str_replace( '&', '&', $_SERVER['QUERY_STRING'] ) ); $vtp->setVar( $handle, 'summary.title', $lang['hint_about'] ); $vtp->setVar( $handle, 'summary.name', replace_space( $lang['about'] ) ); $vtp->closeSession( $handle, 'summary' ); @@ -226,6 +223,7 @@ else replace_space( $lang['no_category'] ) ); } //------------------------------------------------------------------ thumbnails +$output.= 'before thumbs : '.get_elapsed_time( $t2, get_moment() ).'<br />'; if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 ) { if ( is_numeric( $page['cat'] ) ) @@ -317,6 +315,7 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 ) $query = 'SELECT COUNT(*) AS nb_comments'; $query.= ' FROM '.PREFIX_TABLE.'comments'; $query.= ' WHERE image_id = '.$row['id']; + $query.= " AND validated = 'true'"; $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); $vtp->setVar( $handle, 'nb_comments.nb', $row['nb_comments'] ); @@ -341,65 +340,58 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 ) } $vtp->closeSession( $handle, 'thumbnails' ); } -elseif ( isset( $page['cat'] ) - and is_numeric( $page['cat'] ) - and $page['cat_nb_images'] == 0 ) +//-------------------------------------------------------------- empty category +elseif ( ( isset( $page['cat'] ) + and is_numeric( $page['cat'] ) + and $page['cat_nb_images'] == 0 ) + or $_GET['cat'] == '' ) { $vtp->addSession( $handle, 'thumbnails' ); $vtp->addSession( $handle, 'line' ); - $subcats = get_non_empty_sub_cat_ids( $page['cat'] ); + $subcats = get_non_empty_subcat_ids( $page['cat'] ); $cell_number = 1; - foreach ( $subcats as $id => $subcat ) { - $result = get_cat_info( $subcat['non_empty_cat'] ); - $cat_directory = $result['dir']; + $i = 0; + foreach ( $subcats as $subcat_id => $non_empty_id ) { + $subcat_infos = get_cat_info( $subcat_id ); + $non_empty_infos = get_cat_info( $non_empty_id ); - $name = '[ <span style="font-weight:bold;">'; - if ( $subcat['name'] != '' ) - { - $name.= $subcat['name']; - } - else - { - $name.= $subcat['dir']; - } + $name ='[ <span style="font-weight:bold;">'; + $name.= $subcat_infos['name'][0]; $name.= '</span> ]'; - $name = replace_space( $name ); $query = 'SELECT file,tn_ext'; $query.= ' FROM '.PREFIX_TABLE.'images'; - $query.= ' WHERE cat_id = '.$subcat['non_empty_cat']; + $query.= ' WHERE cat_id = '.$non_empty_id; $query.= ' ORDER BY RAND()'; $query.= ' LIMIT 0,1'; $query.= ';'; $image_result = mysql_query( $query ); - $image_row = mysql_fetch_array( $image_result ); + $image_row = mysql_fetch_array( $image_result ); $file = get_filename_wo_extension( $image_row['file'] ); // creating links for thumbnail and associated category - $lien_image = $cat_directory; - $lien_thumbnail = $lien_image; - $lien_thumbnail.= 'thumbnail/'.$conf['prefix_thumbnail']; - $lien_thumbnail.= $file.'.'.$image_row['tn_ext']; - $lien_image.= $image_row['file']; + $thumbnail_link = $non_empty_infos['dir']; + $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; + $thumbnail_link.= $file.'.'.$image_row['tn_ext']; $thumbnail_title = $lang['hint_category']; - $url_link = './category.php?cat='.$subcat['id']; + $url_link = './category.php?cat='.$subcat_id; if ( !in_array( $page['cat'], $page['tab_expand'] ) ) { array_push( $page['tab_expand'], $page['cat'] ); $page['expand'] = implode( ',', $page['tab_expand'] ); } $url_link.= '&expand='.$page['expand']; - list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] ); + list( $year,$month,$day ) = explode( '-', $subcat_infos['date_last'] ); $date = mktime( 0, 0, 0, $month, $day, $year ); // sending vars to display $vtp->addSession( $handle, 'thumbnail' ); $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) ); - $vtp->setVar( $handle, 'thumbnail.src', $lien_thumbnail ); + $vtp->setVar( $handle, 'thumbnail.src', $thumbnail_link ); $vtp->setVar( $handle, 'thumbnail.alt', $image_row['file'] ); $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title ); $vtp->setVar( $handle, 'thumbnail.name', $name ); @@ -411,18 +403,19 @@ elseif ( isset( $page['cat'] ) $vtp->closeSession( $handle, 'line' ); $cell_number = 1; // we open a new line if the subcat was not the last one - if ( $id < count( $subcats ) - 1 ) + if ( $i++ < count( $subcats ) - 1 ) { $vtp->addSession( $handle, 'line' ); } } } - if ( $id < count( $subcats ) - 1 ) + if ( $i < count( $subcats ) - 1 ) { $vtp->closeSession( $handle, 'line' ); } $vtp->closeSession( $handle, 'thumbnails' ); } +$output.= 'after thumbs : '.get_elapsed_time( $t2, get_moment() ).'<br />'; //------------------------------------------------------- category informations if ( isset ( $page['cat'] ) ) { @@ -469,5 +462,6 @@ $time = get_elapsed_time( $t2, get_moment() ); $vtp->setGlobalVar( $handle, 'time', $time ); //----------------------------------------------------------- html code display $code = $vtp->Display( $handle, 0 ); +echo $output; echo $code; ?>
\ No newline at end of file diff --git a/identification.php b/identification.php index 5f10f106a..c88719d03 100644 --- a/identification.php +++ b/identification.php @@ -57,12 +57,8 @@ $vtp->setGlobalVar( $handle, 'ident_forgotten_password', // conf $vtp->setGlobalVar( $handle, 'mail_webmaster', $conf['mail_webmaster'] ); // user -$vtp->setGlobalVar( $handle, 'page_style', $user['style'] ); -$vtp->setGlobalVar( $handle, 'user_theme', $user['theme'] ); -// structure -$vtp->setGlobalVar( $handle, 'frame_start', get_frame_start() ); -$vtp->setGlobalVar( $handle, 'frame_begin', get_frame_begin() ); -$vtp->setGlobalVar( $handle, 'frame_end', get_frame_end() ); +$vtp->setGlobalVar( $handle, 'user_template', $user['template'] ); +initialize_template(); //-------------------------------------------------------------- errors display if ( sizeof( $error ) != 0 ) { diff --git a/include/config.inc.php b/include/config.inc.php index 7df262d11..e664d37e5 100644 --- a/include/config.inc.php +++ b/include/config.inc.php @@ -22,7 +22,6 @@ $lang = array(); include_once( PREFIX_INCLUDE.'./include/functions.inc.php' ); include_once( PREFIX_INCLUDE.'./include/vtemplate.class.php' ); - // How to change the order of display for images in a category ? // // You have to modify $conf['order_by']. @@ -39,8 +38,10 @@ include_once( PREFIX_INCLUDE.'./include/vtemplate.class.php' ); // without taking into account the date_available $conf['order_by'] = ' ORDER BY date_available DESC, file ASC'; -$conf['nb_image_row'] = array('4','5','6','7','8'); -$conf['nb_row_page'] = array('2','3','4','5','6','7','10','20','1000'); +$conf['nb_image_row'] = array(4,5,6,7,8); +$conf['nb_row_page'] = array(2,3,4,5,6,7,10,20,1000); +$conf['slideshow_period'] = array(2,5,10); +$conf['last_days'] = array(1,2,3,10,30,365); $conf['version'] = '1.3'; $conf['site_url'] = 'http://www.phpwebgallery.net'; $conf['forum_url'] = 'http://forum.phpwebgallery.net'; @@ -58,12 +59,11 @@ $infos = array( 'prefix_thumbnail', 'webmaster', 'mail_webmaster', 'access', 'max_user_listbox', 'show_comments', 'nb_comment_page', 'upload_available', 'upload_maxfilesize', 'upload_maxwidth', 'upload_maxheight', 'upload_maxwidth_thumbnail', - 'upload_maxheight_thumbnail' ); + 'upload_maxheight_thumbnail','log','comments_validation' ); -$query = 'SELECT'; +$query = 'SELECT '; foreach ( $infos as $i => $info ) { if ( $i > 0 ) $query.= ','; - else $query.= ' '; $query.= $info; } $query.= ' FROM '.PREFIX_TABLE.'config;'; @@ -81,6 +81,5 @@ foreach ( $infos as $info ) { $conf[$info] = get_boolean( $row[$info] ); } } -$conf['log'] = false; $conf['top_number'] = 20; ?>
\ No newline at end of file diff --git a/include/functions.inc.php b/include/functions.inc.php index ec9081dce..5a672a0d4 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -66,16 +66,14 @@ function get_boolean( $string ) // this array. function array_remove( $array, $value ) { - $i = 0; $output = array(); - foreach ( $array as $v ) + foreach ( $array as $v ) { + if ( $v != $value ) { - if ( $v != $value ) - { - $output[$i++] = $v; - } + array_push( $output, $v ); } - return implode( ',', $output ); + } + return $output; } // The function get_moment returns a float value coresponding to the number @@ -320,15 +318,6 @@ function replace_search( $string, $search ) function database_connection() { -// $xml_content = getXmlCode( PREFIXE_INCLUDE.'./include/database_config.xml' ); -// $mysql_conf = getChild( $xml_content, 'mysql' ); - -// $cfgHote = getAttribute( $mysql_conf, 'host' ); -// $cfgUser = getAttribute( $mysql_conf, 'user' ); -// $cfgPassword = getAttribute( $mysql_conf, 'password' ); -// $cfgBase = getAttribute( $mysql_conf, 'base' ); -// define( PREFIX_TABLE, getAttribute( $mysql_conf, 'tablePrefix' ) ); - include( PREFIX_INCLUDE.'./include/mysql.inc.php' ); define( PREFIX_TABLE, $prefix_table ); @@ -346,7 +335,7 @@ function pwg_log( $file, $category, $picture = '' ) { $query = 'insert into '.PREFIX_TABLE.'history'; $query.= ' (date,login,IP,file,category,picture) values'; - $query.= " (".time().", '".$user['pseudo']."'"; + $query.= " (".time().", '".$user['username']."'"; $query.= ",'".$_SERVER['REMOTE_ADDR']."'"; $query.= ",'".$file."','".$category."','".$picture."');"; mysql_query( $query ); @@ -357,10 +346,8 @@ function templatize_array( $array, $global_array_name, $handle ) { global $vtp, $lang, $page, $user, $conf; - for( $i = 0; $i < sizeof( $array ); $i++ ) - { - $vtp->setGlobalVar( $handle, $array[$i], - ${$global_array_name}[$array[$i]] ); + foreach ( $array as $value ) { + $vtp->setGlobalVar( $handle, $value, ${$global_array_name}[$value] ); } } ?>
\ No newline at end of file diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index de868db82..989349466 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -59,11 +59,18 @@ function check_cat_id( $cat ) unset( $page['cat'] ); if ( isset( $cat ) ) { - if ( is_numeric( $cat ) ) + if ( isset( $page['plain_structure'] ) ) { - $query = 'select id'; - $query.= ' from '.PREFIX_TABLE.'categories'; - $query.= ' where id = '.$cat; + if ( isset( $page['plain_structure'][$cat] ) ) + { + $page['cat'] = $cat; + } + } + else if ( is_numeric( $cat ) ) + { + $query = 'SELECT id'; + $query.= ' FROM '.PREFIX_TABLE.'categories'; + $query.= ' WHERE id = '.$cat; $query. ';'; $result = mysql_query( $query ); if ( mysql_num_rows( $result ) != 0 ) @@ -71,176 +78,189 @@ function check_cat_id( $cat ) $page['cat'] = $cat; } } - if ( $cat == 'fav' or $cat == 'search' or $cat == 'most_visited' - or $cat == 'best_rated' or $cat == 'recent' ) + if ( $cat == 'fav' + or $cat == 'search' + or $cat == 'most_visited' + or $cat == 'best_rated' + or $cat == 'recent' ) { $page['cat'] = $cat; } } } -function display_cat( $id_uppercat, $indent, $restriction, $tab_expand ) +function get_plain_structure() { - global $user,$lang,$conf,$page,$vtp,$handle; + $infos = array( 'name','id','date_last','nb_images','dir','id_uppercat', + 'rank'); - $query = 'select name,id,date_dernier,nb_images,dir'; - $query.= ' from '.PREFIX_TABLE.'categories'; - $query.= ' where id_uppercat'; - if ( $id_uppercat == "" ) - { - $query.= ' is NULL'; + $query = 'SELECT '; + foreach ( $infos as $i => $info ) { + if ( $i > 0 ) $query.= ','; + $query.= $info; } - else - { - $query.= ' = '.$id_uppercat; - } - $query.= ' order by rank asc;'; + $query.= ' FROM '.PREFIX_TABLE.'categories'; + $query.= ' ORDER BY id_uppercat ASC, rank ASC'; + $query.= ';'; + + $plain_structure = array(); $result = mysql_query( $query ); while ( $row = mysql_fetch_array( $result ) ) { - if ( !in_array( $row['id'], $restriction ) ) - { - $nb_subcats = get_nb_subcats( $row['id'] ); - - $expand = ""; - // si la catégorie n'a pas de sous catégorie - // ou que l'on doit développer toutes les catégories par défaut - // alors on utilise l'expand par défaut - if ( $nb_subcats == 0 or $user['expand'] == "true" ) + $category = array(); + foreach ( $infos as $info ) { + $category[$info] = $row[$info]; + if ( $info == 'date_last' ) { - $expand = $page['expand']; - } - // si la catégorie n'est pas dans les catégories à développer - // alors on l'ajoute aux catégories à développer - else if ( !in_array( $row['id'], $tab_expand ) ) - { - $expand = implode( ",", $tab_expand ); - if ( strlen( $expand ) > 0 ) - { - $expand.= ","; - } - $expand.= $row['id']; - } - // si la catégorie est déjà dans les catégories à développer - // alors on la retire des catégories à développer - else - { - $expand = array_remove( $tab_expand, $row['id'] ); - } - $url = "./category.php?cat=".$page['cat']."&expand=$expand"; - if ( $page['cat'] == 'search' ) - { - $url.= "&search=".$_GET['search'].'&mode='.$_GET['mode']; - } - $lien_cat = add_session_id( $url ); - if ( $row['name'] == "" ) - { - $name = str_replace( "_", " ", $row['dir'] ); - } - else - { - $name = $row['name']; + list($year,$month,$day) = explode( '-', $row[$info] ); + $category[$info] = mktime(0,0,0,$month,$day,$year); } + } + $plain_structure[$row['id']] = $category; + } - $vtp->addSession( $handle, 'category' ); - $vtp->setVar( $handle, 'category.indent', $indent ); + return $plain_structure; +} - if ( $user['expand'] == "true" or $nb_subcats == 0 ) - { - $vtp->addSession( $handle, 'bullet_wo_link' ); - $vtp->setVar( $handle, 'bullet_wo_link.bullet_url', - $user['lien_collapsed'] ); - $vtp->setVar( $handle, 'bullet_wo_link.bullet_alt', '>' ); - $vtp->closeSession( $handle, 'bullet_wo_link' ); - } - else - { - $vtp->addSession( $handle, 'bullet_w_link' ); - $vtp->setVar( $handle, 'bullet_w_link.bullet_link', $lien_cat ); - $vtp->setVar( $handle, 'bullet_w_link.bullet_alt', '>' ); - if ( in_array( $row['id'], $tab_expand ) ) - { - $vtp->setVar( $handle, 'bullet_w_link.bullet_url', - $user['lien_expanded'] ); - } - else - { - $vtp->setVar( $handle, 'bullet_w_link.bullet_url', - $user['lien_collapsed'] ); - } - $vtp->closeSession( $handle, 'bullet_w_link' ); - } - $vtp->setVar( $handle, 'category.link_url', - add_session_id( './category.php?cat='. - $row['id'].'&expand='.$expand ) ); - $vtp->setVar( $handle, 'category.link_name', $name ); - if ( $id_uppercat == "" ) - { - $vtp->setVar( $handle, 'category.name_style', 'font-weight:bold;' ); - } - if ( $nb_subcats > 0 ) +function create_structure( $id_uppercat, $restrictions ) +{ + global $page; + + $structure = array(); + $ids = get_subcat_ids( $id_uppercat ); + foreach ( $ids as $id ) { + if ( !in_array( $id, $restrictions ) ) + { + $category = $page['plain_structure'][$id]; + $category['subcats'] = create_structure( $id, $restrictions ); + array_push( $structure, $category ); + } + } + return $structure; +} + +function get_subcat_ids( $id_uppercat ) +{ + global $page; + + $ids = array(); + foreach ( $page['plain_structure'] as $id => $category ) { + if ( $category['id_uppercat'] == $id_uppercat ) array_push( $ids, $id ); + else if ( count( $ids ) > 0 ) return $ids; + } + return $ids; +} + +// update_structure updates or add informations about each node of the +// structure : the last date, should the category be expanded in the menu ?, +// the associated expand string "48,14,54" +// +// 1. last date +// for each category of the structure, we have to find the most recent +// subcat so that the parent cat has the same last_date info. +// For example : we have : +// > pets (2003.02.15) +// > dogs (2003.06.14) +// > rex (2003.06.18) +// > toby (2003.06.13) +// > kitten (2003.07.05) +// We finally want to have : +// > pets (2003.07.05) <- changed to pets > kitten last date +// > dogs (2003.06.18) <- changed to pets > dogs > rex last date +// > rex (2003.06.18) +// > toby (2003.06.13) +// > kitten (2003.07.05) +// +// 2. should the category be expanded in the menu ? +// If the category has to be expanded (ie its id is in the +// $page['tab_expand'] or all the categories must be expanded by default), +// $category['expanded'] is set to true. +// +// 3. associated expand string +// in the menu, there is a expand string (used in the URL) to tell which +// categories must be expanded in the menu if this category is chosen +function update_structure( $categories ) +{ + global $page, $user; + + $updated_categories = array(); + + foreach ( $categories as $category ) { + // update the last date of the category + $last_date = search_last_date( $category ); + $category['date_last'] = $last_date; + // update the "expanded" key + if ( $user['expand'] + or $page['expand'] == 'all' + or in_array( $category['id'], $page['tab_expand'] ) ) + { + $category['expanded'] = true; + } + else + { + $category['expanded'] = false; + } + // update the "expand_string" key + if ( $page['expand'] == 'all' ) + { + $category['expand_string'] = 'all'; + } + else + { + $tab_expand = $page['tab_expand']; + if ( in_array( $category['id'], $page['tab_expand'] ) ) { - $vtp->addSession( $handle, 'subcat' ); - $vtp->setVar( $handle, 'subcat.nb_subcats', $nb_subcats ); - $vtp->closeSession( $handle, 'subcat' ); + // the expand string corresponds to the $page['tab_expand'] without + // the $category['id'] + $tab_expand = array_diff( $page['tab_expand'],array($category['id']) ); } - $vtp->setVar( $handle, 'category.total_cat', $row['nb_images'] ); - $date_dispo = explode( "-", $row['date_dernier'] ); - $date_cat = mktime( 0, 0, 0, $date_dispo[1], $date_dispo[2], - $date_dispo[0] ); - $vtp->setVar( $handle, 'category.cat_icon', get_icon( $date_cat ) ); - $vtp->closeSession( $handle, 'category' ); - - if ( in_array( $row['id'], $tab_expand ) or $user['expand'] == "true" ) + else if ( count( $category['subcats'] ) > 0 ) { - display_cat( $row['id'], $indent.' ', - $restriction, $tab_expand ); + // we have this time to add the $category['id']... + $tab_expand = array_merge($page['tab_expand'],array($category['id'])); } + $category['expand_string'] = implode( ',', $tab_expand ); } + // recursive call + $category['subcats'] = update_structure( $category['subcats'] ); + // adding the updated category + array_push( $updated_categories, $category ); } + + return $updated_categories; } - -function get_nb_subcats( $id ) + +// search_last_date searchs the last date for a given category. If we take +// back the example given for update_last_dates, we should have : +// search_last_date( pets ) --> 2003.07.05 +// search_last_date( pets > dogs ) --> 2003.06.18 +// and so on +function search_last_date( $category ) { - global $user; - - $query = 'select count(*) as count'; - $query.= ' from '.PREFIX_TABLE.'categories'; - $query.= ' where id_uppercat = '.$id; - for ( $i = 0; $i < sizeof( $user['restrictions'] ); $i++ ) - { - $query.= " and id != ".$user['restrictions'][$i]; + $date_last = $category['date_last']; + foreach ( $category['subcats'] as $subcat ) { + $subcat_date_last = search_last_date( $subcat ); + if ( $subcat_date_last > $date_last ) + { + $date_last = $subcat_date_last; + } } - $query.= ';'; - $result = mysql_query( $query ); - $row = mysql_fetch_array( $result ); - return $row['count']; + return $date_last; } - -function get_total_image( $id, $restriction ) + +// count_images returns the number of pictures contained in the given +// category represented by an array, in this array, we have (among other +// things) : +// $category['nb_images'] -> number of pictures in this category +// $category['subcats'] -> array of sub-categories +// count_images goes to the deepest sub-category to find the total number of +// pictures contained in the given given category +function count_images( $categories ) { $total = 0; - - $query = 'select id,nb_images'; - $query.= ' from '.PREFIX_TABLE.'categories'; - $query.= ' where id_uppercat'; - if ( !is_numeric( $id ) ) - { - $query.= ' is NULL'; - } - else - { - $query.= ' = '.$id; - } - $query.= ";"; - $result = mysql_query( $query ); - while ( $row = mysql_fetch_array( $result ) ) - { - if ( !in_array( $row['id'], $restriction ) ) - { - $total+= $row['nb_images']; - $total+= get_total_image( $row['id'], $restriction ); - } + foreach ( $categories as $category ) { + $total+= $category['nb_images']; + $total+= count_images( $category['subcats'] ); } return $total; } @@ -261,17 +281,19 @@ function get_cat_info( $id ) $cat = array(); $cat['name'] = array(); - $query = 'select nb_images,id_uppercat,comment,site_id,galleries_url,dir'; - $query.= ' from '.PREFIX_TABLE.'categories as a'; - $query.= ', '.PREFIX_TABLE.'sites as b'; - $query.= ' where a.id = '.$id; - $query.= ' and a.site_id = b.id;'; + $query = 'SELECT nb_images,id_uppercat,comment,site_id,galleries_url,dir'; + $query.= ',date_last'; + $query.= ' FROM '.PREFIX_TABLE.'categories AS a'; + $query.= ', '.PREFIX_TABLE.'sites AS b'; + $query.= ' WHERE a.id = '.$id; + $query.= ' AND a.site_id = b.id;'; $row = mysql_fetch_array( mysql_query( $query ) ); $cat['site_id'] = $row['site_id']; $cat['id_uppercat'] = $row['id_uppercat']; $cat['comment'] = nl2br( $row['comment'] ); $cat['nb_images'] = $row['nb_images']; $cat['last_dir'] = $row['dir']; + $cat['date_last'] = $row['date_last']; $galleries_url = $row['galleries_url']; $cat['dir'] = ""; @@ -280,11 +302,11 @@ function get_cat_info( $id ) $row['id_uppercat'] = $id; while ( !$is_root ) { - $query = 'select name,dir,id_uppercat'; - $query.= ' from '.PREFIX_TABLE.'categories'; - $query.= ' where id = '.$row['id_uppercat'].';'; + $query = 'SELECT name,dir,id_uppercat'; + $query.= ' FROM '.PREFIX_TABLE.'categories'; + $query.= ' WHERE id = '.$row['id_uppercat'].';'; $row = mysql_fetch_array( mysql_query( $query ) ); - $cat['dir'] = $row['dir']."/".$cat['dir']; + $cat['dir'] = $row['dir'].'/'.$cat['dir']; if ( $row['name'] == "" ) { $cat['name'][$i] = str_replace( "_", " ", $row['dir'] ); @@ -502,42 +524,36 @@ function initialize_category( $calling_page = 'category' ) } } -// get_non_empty_sub_cat_ids returns an array composing of the infos of the -// direct sub-categories of the given uppercat id. Each of these infos is -// associated to the first found non empty category id. eg : +// get_non_empty_subcat_ids returns an array with sub-categories id +// associated with their first non empty category id. +// +// example : // // - catname [cat_id] // - cat1 [1] -> given uppercat -// - cat1.1 [2] (empty) +// - cat1.1 [12] (empty) // - cat1.1.1 [5] (empty) // - cat1.1.2 [6] // - cat1.2 [3] // - cat1.3 [4] // // get_non_empty_sub_cat_ids will return : -// $cats[0]['id'] = 2; -// $cats[0]['name'] = ''; -// $cats[0]['dir'] = 'cat1'; -// $cats[0]['date_dernier'] = '2003-05-17'; -// $cats[0]['non_empty_cat'] = 6; -// -// $cats[1]['id'] = 3; -// $cats[1]['non_empty_cat'] = 3; -// -// $cats[1]['id'] = 4; -// $cats[1]['non_empty_cat'] = 4; -function get_non_empty_sub_cat_ids( $id_uppercat ) +// $ids[12] = 6; +// $ids[3] = 3; +// $ids[4] = 4; +function get_non_empty_subcat_ids( $id_uppercat ) { global $user; - $cats = array(); + $ids = array(); - $query = 'SELECT id,name,dir,date_dernier,nb_images'; + $query = 'SELECT id,nb_images'; $query.= ' FROM '.PREFIX_TABLE.'categories'; - $query.= ' WHERE id_uppercat = '.$id_uppercat; + $query.= ' WHERE id_uppercat '; + if ( !is_numeric( $id_uppercat ) ) $query.= 'is NULL'; + else $query.= '= '.$id_uppercat; // we must not show pictures of a forbidden category - $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); - foreach ( $restricted_cats as $restricted_cat ) { + foreach ( $user['restrictions'] as $restricted_cat ) { $query.= ' AND id != '.$restricted_cat; } $query.= ' ORDER BY rank'; @@ -551,16 +567,10 @@ function get_non_empty_sub_cat_ids( $id_uppercat ) if ( ( $row['nb_images'] != 0 and $non_empty_cat = $row['id'] ) or $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ) ) { - $temp_cat = array( - 'id' => $row['id'], - 'name' => $row['name'], - 'dir' => $row['dir'], - 'date_dernier' => $row['date_dernier'], - 'non_empty_cat' => $non_empty_cat ); - array_push( $cats, $temp_cat ); + $ids[$row['id']] = $non_empty_cat; } } - return $cats; + return $ids; } // get_first_non_empty_cat_id returns the id of the first non empty @@ -574,8 +584,7 @@ function get_first_non_empty_cat_id( $id_uppercat ) $query.= ' FROM '.PREFIX_TABLE.'categories'; $query.= ' WHERE id_uppercat = '.$id_uppercat; // we must not show pictures of a forbidden category - $restricted_cats = get_all_restrictions( $user['id'],$user['status'] ); - foreach ( $restricted_cats as $restricted_cat ) { + foreach ( $user['restrictions'] as $restricted_cat ) { $query.= ' AND id != '.$restricted_cat; } $query.= ' ORDER BY RAND()'; diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index 0f286b970..1d55d4bbe 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -313,7 +313,7 @@ function get_all_restrictions( $user_id, $user_status ) function is_user_allowed( $category_id, $restrictions ) { $lowest_category_id = $category_id; - + $is_root = false; while ( !$is_root and !in_array( $category_id, $restrictions ) ) { @@ -322,21 +322,12 @@ function is_user_allowed( $category_id, $restrictions ) $query.= ' WHERE id = '.$category_id; $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); - if ( $row['id_uppercat'] == '' ) - { - $is_root = true; - } + if ( $row['id_uppercat'] == '' ) $is_root = true; $category_id = $row['id_uppercat']; } - - if ( in_array( $lowest_category_id, $restrictions ) ) - { - return 1; - } - if ( in_array( $category_id, $restrictions ) ) - { - return 2; - } + + if ( in_array( $lowest_category_id, $restrictions ) ) return 1; + if ( in_array( $category_id, $restrictions ) ) return 2; // this user is allowed to go in this category return 0; } diff --git a/include/init.inc.php b/include/init.inc.php index ad25a679b..823695753 100644 --- a/include/init.inc.php +++ b/include/init.inc.php @@ -18,10 +18,7 @@ define( PREFIX_INCLUDE, '' ); include_once( './include/config.inc.php' ); include_once( './include/user.inc.php' ); - -include( './theme/'.$user['theme'].'/conf.php' ); -$user['lien_expanded'] = './theme/'.$user['theme'].'/expanded.gif'; -$user['lien_collapsed'] = './theme/'.$user['theme'].'/collapsed.gif'; + // calculation of the number of picture to display per page $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page']; // retrieving the restrictions for this user @@ -35,6 +32,5 @@ if ( $user['is_the_guest'] ) { $user['username'] = $lang['guest']; } -include_once( './template/'.$user['template'].'/style.inc.php' ); include_once( './template/'.$user['template'].'/htmlfunctions.inc.php' ); ?>
\ No newline at end of file diff --git a/include/user.inc.php b/include/user.inc.php index 8efd8219f..f950b3a1e 100644 --- a/include/user.inc.php +++ b/include/user.inc.php @@ -20,22 +20,14 @@ // Example : // status --> $user['status'] $infos = array( 'id', 'username', 'mail_address', 'nb_image_line', - 'nb_line_page', 'status', 'theme', 'language', 'maxwidth', + 'nb_line_page', 'status', 'language', 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', 'short_period', 'long_period', 'template' ); -$query_user = 'SELECT'; -for ( $i = 0; $i < sizeof( $infos ); $i++ ) -{ - if ( $i > 0 ) - { - $query_user.= ','; - } - else - { - $query_user.= ' '; - } - $query_user.= $infos[$i]; +$query_user = 'SELECT '; +foreach ( $infos as $i => $info ) { + if ( $i > 0 ) $query_user.= ','; + $query_user.= $info; } $query_user.= ' FROM '.PREFIX_TABLE.'users'; $query_done = false; diff --git a/language/francais.php b/language/francais.php index cbf36d2bd..cba6596c4 100644 --- a/language/francais.php +++ b/language/francais.php @@ -1,4 +1,7 @@ <?php +// start version 1.3 +$lang['charset'] = 'Shift_JIS';//'ISO_8859-1'; +// end version 1.3 $lang['only_members'] = 'Seuls les membres du site peuvent accéder à cette page'; $lang['invalid_pwd'] = 'le mot de passe rentré n\'est pas valide'; $lang['access_forbiden'] = 'Vous n\'êtes pas autorisé à aller dans cette section'; @@ -19,6 +22,12 @@ $lang['public'] = 'publique'; $lang['private'] = 'privée'; $lang['add'] = 'ajouter'; $lang['dissociate'] = 'dissocier'; +$lang['mandatory'] = 'obligatoire'; +$lang['err_date'] = 'date erronée'; +$lang['picture'] = 'image'; +$lang['IP'] = 'IP'; +$lang['close'] = 'fermer'; +$lang['open'] = 'ouvrir'; // end version 1.3 // page diapo @@ -132,8 +141,8 @@ $lang['maxwidth'] = 'largeur maximum des images'; $lang['maxheight'] = 'hauteur maximum des images'; $lang['err_maxwidth'] = 'la largeur maximum des images doit être un entier supérieur à 50'; $lang['err_maxheight'] = 'la hauteur maximum des images doit être un entier supérieur à 50'; - -// page photo + +// picture.php $lang['previous_image'] = 'Précédent'; $lang['next_image'] = 'Suivant'; $lang['back'] = 'Cliquez sur l\'image pour revenir à la page des miniatures'; @@ -166,7 +175,14 @@ $lang['add_favorites_alt'] = 'Ajouter aux favoris'; $lang['add_favorites_hint'] = 'ajouter cette image à vos favoris'; $lang['del_favorites_alt'] = 'Retirer des favoris'; $lang['del_favorites_hint'] = 'supprimer cette image de vos favoris'; - +// start version 1.3 +$lang['slideshow'] = 'diaporama'; +$lang['period_seconds'] = 'secondes par image'; +$lang['slideshow_stop'] = 'stopper le diaporama'; +$lang['comment_added'] = 'Votre commentaire a été enregistré'; +$lang['comment_to_validate'] = 'Un administrateur doit valider votre commentaire pour qu\'il soit visible'; +// end version 1.3 + // page register $lang['register_page_title'] = 'Enregistrement'; $lang['register_title'] = 'Enregistrement'; @@ -208,6 +224,12 @@ $lang['upload_advise_filetype'] = 'l\'image doit être au format jpg, gif ou png' $lang['upload_err_username'] = 'le nom de l\'utilisateur doit être renseigné'; $lang['upload_username'] = 'Nom d\'utilisateur'; $lang['upload_successful'] = 'Image uploadée avec succès, un administrateur validera celle-ci dès que possible.'; +// start version 1.3 +$lang['upload_name'] = 'Nom de l\'image'; +$lang['upload_author'] = 'Auteur (eg "Pierrick LE GALL")'; +$lang['upload_creation_date'] = 'Date de création (JJ/MM/AAAA)'; +$lang['upload_comment'] = 'Commentaire'; +// end version 1.3 //----------------------------------administration if ( $isadmin ) @@ -234,6 +256,7 @@ if ( $isadmin ) $lang['title_user_perm'] = 'Modifier les permissions pour l\'utilisateur'; $lang['title_cat_perm'] = 'Modifier les permissions pour la catégorie'; $lang['title_group_perm'] = 'Modifier les permissions pour le groupe'; + $lang['title_comments'] = 'Commentaires des visiteurs'; // end version 1.3 $lang['title_categories'] = 'Gestion des catégories'; $lang['title_edit_cat'] = 'Editer une catégorie'; @@ -255,6 +278,7 @@ if ( $isadmin ) $lang['menu_back'] = 'Page diapo'; // start version 1.3 $lang['menu_groups'] = 'Groupes'; + $lang['menu_comments'] = 'Commentaires'; // end version 1.3 $lang['title_waiting'] = 'Images en attente de validation'; @@ -306,6 +330,8 @@ if ( $isadmin ) // $lang['conf_general_default_page_info'] = 'page sur laquelle les utilisateurs sont redirigés s\'ils vont à la racine du site.'; // $lang['conf_general_expand'] = 'développer toutes les catégories'; // $lang['conf_general_expand_info'] = 'développer toutes les catégories par défaut dans le menu ?'; + $lang['conf_general_log'] = 'historique'; + $lang['conf_general_log_info'] = 'historiser les visites sur le site ? Les visites seront visibles dans l\'historique de l\'administration'; // end version 1.3 $lang['conf_comments'] = 'commentaires utilisateurs'; $lang['conf_comments_title'] = 'Configuration des '.$lang['conf_comments']; @@ -315,6 +341,8 @@ if ( $isadmin ) $lang['conf_comments_comments_number_info'] = 'nombre de commentaire à afficher sur chaque page. Le nombre de commentaires pour une image reste illimité. Entrer un nombre entre 5 et 50.'; $lang['conf_err_comment_number'] = 'le nombre de commentaires par page doit être compris entre 5 et 50 inclus.'; // start version 1.3 + $lang['conf_comments_validation'] = 'validation'; + $lang['conf_comments_validation_info'] = 'L\'administrateur valide les commentaires avant qu\'ils apparaissent sur le site'; // $lang['conf_remote_site_title'] = 'Site distant'; // end version 1.3 $lang['conf_remote_site_delete_info'] = 'Supprimer un site revient à supprimer toutes les images et les catégories en relation avec ce site.'; @@ -336,7 +364,7 @@ if ( $isadmin ) $lang['conf_upload_maxheight_thumbnail'] = 'hauteur maximum miniatures'; $lang['conf_upload_maxheight_thumbnail_info'] = 'Hauteur maximum autorisée pour les miniatures. Celle-ci doit être un entier supérieur à 10, en pixels.'; $lang['conf_err_upload_maxheight_thumbnail'] = 'la hauteur maximum des miniatures uploadées doit être un entier supérieur à 10.'; - + $lang['conf_default_title'] = 'Affichage par défaut pour les visiteurs non enregistrés et les nouveaux comptes'; // start version 1.3 // $lang['conf_default_language'] = 'langue par défaut'; @@ -462,7 +490,9 @@ if ( $isadmin ) $lang['editcat_visible'] = 'Visible'; // end version 1.3 // page info images - $lang['infoimage_err_date'] = 'date erronée'; +// start version 1.3 + // $lang['infoimage_err_date'] = 'date erronée'; +// end version 1.3 $lang['infoimage_general'] = 'Options générale pour la catégorie'; $lang['infoimage_useforall'] = 'utiliser pour toutes les images ?'; $lang['infoimage_creation_date'] = 'date de création'; @@ -493,11 +523,15 @@ if ( $isadmin ) $lang['tn_thisformat'] = 'pour ce format de fichier'; $lang['tn_err_width'] = 'la largeur doit être un entier supérieur à'; $lang['tn_err_height'] = 'la hauteur doit être un entier supérieur à'; - $lang['tn_err_GD'] = 'il faut choisir une version de GD'; +// start version 1.3 + // $lang['tn_err_GD'] = 'il faut choisir une version de GD'; +// end version 1.3 $lang['tn_results_title'] = 'Résultats de la miniaturisation'; $lang['tn_picture'] = 'image'; - $lang['tn_filesize'] = 'poids'; +// start version 1.3 + // $lang['tn_filesize'] = 'poids'; +// end version 1.3 $lang['tn_results_gen_time'] = 'généré en'; $lang['tn_stats'] = 'Statistiques générales'; @@ -523,7 +557,19 @@ if ( $isadmin ) $lang['tn_dirs_title'] = 'Liste des répertoires'; $lang['tn_dirs_alone'] = 'images sans miniatures'; - + +// start version 1.3 + $lang['stats_last_days'] = 'derniers jours'; + $lang['stats_pages_seen'] = 'pages vues'; + $lang['stats_visitors'] = 'visiteurs'; + $lang['stats_empty'] = 'vider l\'historique'; + $lang['stats_pages_seen_graph_title'] = 'Nombre de pages vues par jour'; + $lang['stats_visitors_graph_title'] = 'Nombre de visiteurs par jour'; + + $lang['comments_last_title'] = 'Derniers commentaires'; + $lang['comments_non_validated_title'] = 'Commentaires non validés'; +// end version 1.3 + // help page $lang['help_images_title'] = 'Ajout d\'images'; $lang['help_images_intro'] = 'Voici comment il faut placer les images dans vos répertoires'; @@ -544,9 +590,7 @@ if ( $isadmin ) $lang['help_database_title'] = 'Remplissage de la base de données'; $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.'; -// start version 1.3 - // $lang['help_remote_title'] = 'Site distant'; -// end version 1.3 + $lang['help_remote_title'] = 'Site distant'; $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 :'; $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-".'; $lang['help_remote'][2] = '2. placez le fichier "create_listing_file.php" modifié sur votre site distant, dans le répertoire racine de vos répertoires d\'images (comme le répertoire "galleries" du présent site) par ftp.'; diff --git a/picture.php b/picture.php index 4723d4aac..2fb3d3f3a 100644 --- a/picture.php +++ b/picture.php @@ -16,8 +16,6 @@ ***************************************************************************/ // this page shows the image full size -// (or resized to the max size the user has chosen) -// and two thumbnail : previous and next picture of your gallery //----------------------------------------------------------- personnal include include_once( './include/init.inc.php' ); //-------------------------------------------------- access authorization check @@ -147,9 +145,50 @@ $handle = $vtp->Open( './template/'.$user['template'].'/picture.vtp' ); initialize_template(); $tpl = array( 'back','submit','comments_title','comments_del','delete', - 'comments_add','author' ); + 'comments_add','author','slideshow','slideshow_stop', + 'period_seconds' ); templatize_array( $tpl, 'lang', $handle ); +$vtp->setGlobalVar( $handle, 'user_template', $user['template'] ); $vtp->setGlobalVar( $handle, 'text_color', $user['couleur_text'] ); +//-------------------------------------------------------- slideshow management +if ( isset( $_GET['slideshow'] ) ) +{ + if ( !is_numeric( $_GET['slideshow'] ) ) + $_GET['slideshow'] = $conf['slideshow_period'][0]; + $vtp->addSession( $handle, 'stop_slideshow' ); + $url = './picture.php'; + $url.= '?image_id='.$page['id']; + $url.= '&cat='.$page['cat']; + $url.= '&expand='.$_GET['expand']; + if ( $page['cat'] == 'search' ) + { + $url.= '&search='.$_GET['search']; + $url.= '&mode='.$_GET['mode']; + } + $vtp->setVar( $handle, 'stop_slideshow.url', add_session_id( $url ) ); + $vtp->closeSession( $handle, 'stop_slideshow' ); +} +else +{ + $vtp->addSession( $handle, 'start_slideshow' ); + foreach ( $conf['slideshow_period'] as $option ) { + $vtp->addSession( $handle, 'second' ); + $vtp->setVar( $handle, 'second.option', $option ); + $url = './picture.php'; + $url.= '?image_id='.$page['id']; + $url.= '&cat='.$page['cat']; + $url.= '&expand='.$_GET['expand']; + if ( $page['cat'] == 'search' ) + { + $url.= '&search='.$_GET['search']; + $url.= '&mode='.$_GET['mode']; + } + $url.= '&slideshow='.$option; + $vtp->setVar( $handle, 'second.url', add_session_id( $url ) ); + $vtp->closeSession( $handle, 'second' ); + } + $vtp->closeSession( $handle, 'start_slideshow' ); +} //------------------------------------------------------------------ page title if ( $page['name'] != '' ) { @@ -376,7 +415,7 @@ if ( $page['cat'] != 'fav' and !$user['is_the_guest'] ) $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] ); $vtp->setVar( $handle, 'favorite.src', - './theme/'.$user['theme'].'/favorite.gif' ); + './template/'.$user['template'].'/theme/favorite.gif' ); $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['add_favorites_alt'].' ]' ); $vtp->closeSession( $handle, 'favorite' ); } @@ -388,7 +427,7 @@ if ( $page['cat'] == 'fav' ) $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) ); $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] ); $vtp->setVar( $handle, 'favorite.src', - './theme/'.$user['theme'].'/del_favorite.gif' ); + './template/'.$user['template'].'/theme/del_favorite.gif' ); $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['del_favorites_alt'].' ]' ); $vtp->closeSession( $handle, 'favorite' ); } @@ -452,6 +491,15 @@ if ( $page['num'] < $page['cat_nb_images']-1 ) $vtp->setGlobalVar( $handle, 'next.src', $lien_thumbnail ); $vtp->setGlobalVar( $handle, 'next.alt', $alt_thumbnail ); $vtp->closeSession( $handle, 'next' ); + // slideshow + if ( isset( $_GET['slideshow'] ) ) + { + $vtp->addSession( $handle, 'refresh' ); + $vtp->setVar( $handle, 'refresh.time', 2 ); + $url = $url_link.'&slideshow='.$_GET['slideshow']; + $vtp->setVar( $handle, 'refresh.url', add_session_id( $url ) ); + $vtp->closeSession( $handle, 'refresh' ); + } } else { @@ -471,10 +519,23 @@ if ( $conf['show_comments'] ) $author = $_POST['author']; } $query = 'INSERT INTO '.PREFIX_TABLE.'comments'; - $query.= ' (author,date,image_id,content) VALUES'; + $query.= ' (author,date,image_id,content,validated) VALUES'; $query.= " ('".$author."',".time().",".$page['id']; - $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."');"; + $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'"; + if ( !$conf['comments_validation'] or $user['status'] == 'admin' ) + $query.= ",'true'"; + else + $query.= ",'false'"; + $query.= ');'; mysql_query( $query ); + $vtp->addSession( $handle, 'information' ); + $message = $lang['comment_added']; + if ( $conf['comments_validation'] and $user['status'] != 'admin' ) + { + $message.= '<br />'.$lang['comment_to_validate']; + } + $vtp->setVar( $handle, 'information.content', $message ); + $vtp->closeSession( $handle, 'information' ); } // comment deletion if ( isset( $_GET['del'] ) @@ -488,7 +549,9 @@ if ( $conf['show_comments'] ) // number of comment for this picture $query = 'SELECT COUNT(*) AS nb_comments'; $query.= ' FROM '.PREFIX_TABLE.'comments'; - $query.= ' WHERE image_id = '.$page['id'].';'; + $query.= ' WHERE image_id = '.$page['id']; + $query.= " AND validated = 'true'"; + $query.= ';'; $row = mysql_fetch_array( mysql_query( $query ) ); $page['nb_comments'] = $row['nb_comments']; // navigation bar creation @@ -519,6 +582,7 @@ if ( $conf['show_comments'] ) $query = 'SELECT id,author,date,image_id,content'; $query.= ' FROM '.PREFIX_TABLE.'comments'; $query.= ' WHERE image_id = '.$page['id']; + $query.= " AND validated = 'true'"; $query.= ' ORDER BY date ASC'; $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';'; $result = mysql_query( $query ); @@ -530,7 +594,7 @@ if ( $conf['show_comments'] ) $displayed_date = $lang['day'][date( "w", $row['date'] )]; $displayed_date.= date( " j ", $row['date'] ); $displayed_date.= $lang['month'][date( "n", $row['date'] )]; - $displayed_date.= date( " Y G:i", $row['date'] ); + $displayed_date.= date( ' Y G:i', $row['date'] ); $vtp->setVar( $handle, 'comment.date', $displayed_date ); $vtp->setVar( $handle, 'comment.content', nl2br( $row['content'] ) ); if ( $user['status'] == 'admin' ) diff --git a/profile.php b/profile.php index 30e28c256..7a47783a5 100644 --- a/profile.php +++ b/profile.php @@ -28,111 +28,86 @@ if ( $user['is_the_guest'] ) //-------------------------------------------------------------- initialization check_cat_id( $_GET['cat'] ); //------------------------------------------------------ update & customization -$infos = array( 'nb_image_line', 'nb_line_page', 'theme', 'language', +$infos = array( 'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', 'short_period', 'long_period', 'template', 'mail_address' ); // mise à jour dans la base de données des valeurs // des paramètres pour l'utilisateur courant // - on teste si chacune des variables est passée en argument à la page // - ce qui signifie que l'on doit venir de la page de personnalisation -$error = array(); +$errors = array(); if ( isset( $_POST['submit'] ) ) { - $i = 0; - if ( $_POST['maxwidth'] != '' ) + $int_pattern = '/^\d+$/'; + if ( $_POST['maxwidth'] != '' + and ( !preg_match( $int_pattern, $_POST['maxwidth'] ) + or $_POST['maxwidth'] < 50 ) ) { - if ( !ereg( "^[0-9]{2,}$", $_POST['maxwidth'] ) - || $_POST['maxwidth'] < 50 ) - { - $error[$i++] = $lang['err_maxwidth']; - } + array_push( $errors, $lang['err_maxwidth'] ); } - if ( $_POST['maxheight'] != '' ) + if ( $_POST['maxheight'] + and ( !preg_match( $int_pattern, $_POST['maxheight'] ) + or $_POST['maxheight'] < 50 ) ) { - if ( !ereg( "^[0-9]{2,}$", $_POST['maxheight'] ) - || $_POST['maxheight'] < 50 ) - { - $error[$i++] = $lang['err_maxheight']; - } + array_push( $errors, $lang['err_maxheight'] ); } - // les période doivent être des entiers, il représentent des nombres de jours - if ( !ereg( "^[0-9]*$", $_POST['short_period'] ) - || !ereg("^[0-9]*$", $_POST['long_period'] ) ) + // periods must be integer values, they represents number of days + if ( !preg_match( $int_pattern, $_POST['short_period'] ) + or !preg_match( $int_pattern, $_POST['long_period'] ) ) { - $error[$i++] = $lang['err_periods']; + array_push( $errors, $lang['err_periods'] ); } else { - // la période longue doit être supérieure à la période courte + // long period must be longer than short period if ( $_POST['long_period'] <= $_POST['short_period'] - || $_POST['short_period'] <= 0 ) + or $_POST['short_period'] <= 0 ) { - $error[$i++] = $lang['err_periods_2']; + array_push( $errors, $lang['err_periods_2'] ); } } - // le mail doit être conforme à qqch du type : nom@serveur.com - if( $_POST['mail_address'] != "" - && !ereg( "([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)", - $_POST['mail_address'] ) ) + $mail_error = validate_mail_address( $_POST['mail_address'] ); + if ( $mail_error != '' ) { - $error[$i++] = $lang['reg_err_mail_address']; + array_push( $errors, $mail_error ); } if ( $_POST['use_new_pwd'] == 1 ) { - // on vérifie que le password rentré correspond bien - // à la confirmation faite par l'utilisateur + // password must be the same as its confirmation if ( $_POST['password'] != $_POST['passwordConf'] ) { - $error[$i++] = $lang['reg_err_pass']; + array_push( $errors, $lang['reg_err_pass'] ); } } - if ( sizeof( $error ) == 0 ) + if ( count( $errors ) == 0 ) { - $tab_theme = explode( ' - ', $_POST['theme'] ); - $_POST['theme'] = $tab_theme[0].'/'.$tab_theme[1]; - - $query = 'update '.PREFIX_TABLE.'users'; - $query.= ' set'; - for ( $i = 0; $i < sizeof( $infos ); $i++ ) - { - if ( $i > 0 ) - { - $query.= ','; - } - else - { - $query.= ' '; - } - $query.= $infos[$i]; + $query = 'UPDATE '.PREFIX_TABLE.'users'; + $query.= ' SET '; + foreach ( $infos as $i => $info ) { + if ( $i > 0 ) $query.= ','; + $query.= $info; $query.= ' = '; - if ( $_POST[$infos[$i]] == '' ) - { - $query.= 'NULL'; - } - else - { - $query.= "'".$_POST[$infos[$i]]."'"; - } + if ( $_POST[$info] == '' ) $query.= 'NULL'; + else $query.= "'".$_POST[$info]."'"; } - $query.= ' where id = '.$user['id']; + $query.= ' WHERE id = '.$user['id']; $query.= ';'; mysql_query( $query ); if ( $_POST['use_new_pwd'] == 1 ) { - $query = 'update '.PREFIX_TABLE.'users'; - $query.= " set password = '".md5( $_POST['password'] )."'"; - $query.= ' where id = '.$user['id']; + $query = 'UPDATE '.PREFIX_TABLE.'users'; + $query.= " SET password = '".md5( $_POST['password'] )."'"; + $query.= ' WHERE id = '.$user['id']; $query.= ';'; mysql_query( $query ); - echo '<br />'.$query; } // redirection $url = 'category.php?cat='.$page['cat'].'&expand='.$_GET['expand']; if ( $page['cat'] == 'search' ) { - $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; + $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; } $url = add_session_id( $url, true ); header( 'Request-URI: '.$url ); @@ -156,13 +131,12 @@ if ( $page['cat'] == 'search' ) } $vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) ); //-------------------------------------------------------------- errors display -if ( sizeof( $error ) != 0 ) +if ( count( $errors ) != 0 ) { $vtp->addSession( $handle, 'errors' ); - for ( $i = 0; $i < sizeof( $error ); $i++ ) - { + foreach ( $errors as $error ) { $vtp->addSession( $handle, 'li' ); - $vtp->setVar( $handle, 'li.li', $error[$i] ); + $vtp->setVar( $handle, 'li.li', $error ); $vtp->closeSession( $handle, 'li' ); } $vtp->closeSession( $handle, 'errors' ); @@ -228,27 +202,6 @@ if ( in_array( 'template', $infos ) ) $vtp->closeSession( $handle, 'select' ); $vtp->closeSession( $handle, 'line' ); } -//----------------------------------------------------------------------- theme -if ( in_array( 'theme', $infos ) ) -{ - $vtp->addSession( $handle, 'line' ); - $vtp->setVar( $handle, 'line.name', $lang['customize_theme'] ); - $vtp->addSession( $handle, 'select' ); - $vtp->setVar( $handle, 'select.name', 'theme' ); - $option = get_themes( './theme/' ); - for ( $i = 0; $i < sizeof( $option ); $i++ ) - { - $vtp->addSession( $handle, 'option' ); - $vtp->setVar( $handle, 'option.option', $option[$i] ); - if ( $option[$i] == str_replace( '/', ' - ', $user['theme'] ) ) - { - $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); - } - $vtp->closeSession( $handle, 'option' ); - } - $vtp->closeSession( $handle, 'select' ); - $vtp->closeSession( $handle, 'line' ); -} //-------------------------------------------------------------------- language if ( in_array( 'language', $infos ) ) { diff --git a/template/default/images/php_sqreuil_artistes.gif b/template/default/images/php_sqreuil_artistes.gif Binary files differnew file mode 100755 index 000000000..88cff0c01 --- /dev/null +++ b/template/default/images/php_sqreuil_artistes.gif diff --git a/upload.php b/upload.php index a03824de2..7e320c1fa 100644 --- a/upload.php +++ b/upload.php @@ -16,7 +16,6 @@ ***************************************************************************/ //------------------------------------------------------------------- functions - // The validate_upload function checks if the image of the given path is valid. // A picture is valid when : // - width, height and filesize are not higher than the maximum @@ -114,10 +113,10 @@ else } if ( $access_forbidden == true or $page['cat_site_id'] != 1 - or $conf['upload_available'] == 'false' ) + or !$conf['upload_available'] ) { echo '<div style="text-align:center;">'.$lang['upload_forbidden'].'<br />'; - echo '<a href="'.add_session_id_to_url( './category.php' ).'">'; + echo '<a href="'.add_session_id( './category.php' ).'">'; echo $lang['thumbnails'].'</a></div>'; exit(); } @@ -127,44 +126,66 @@ $handle = $vtp->Open( './template/'.$user['template'].'/upload.vtp' ); initialize_template(); $tpl = array( 'upload_title', 'upload_username', 'mail_address', 'submit', - 'upload_successful', 'search_return_main_page' ); -templatize_array( $tpl, 'lang', $sub ); -// user -$vtp->setGlobalVar( $handle, 'style', $user['style'] ); -$vtp->setGlobalVar( $handle, 'user_login', $user['username'] ); -$vtp->setGlobalVar( $handle, 'user_mail_address',$user['mail_address'] ); + 'upload_successful', 'search_return_main_page','upload_author', + 'upload_name','upload_creation_date','upload_comment', + 'mandatory' ); +templatize_array( $tpl, 'lang', $handle ); $error = array(); -$i = 0; $page['upload_successful'] = false; if ( isset( $_GET['waiting_id'] ) ) { $page['waiting_id'] = $_GET['waiting_id']; } //-------------------------------------------------------------- picture upload -// vérification de la présence et de la validité des champs. +// verfying fields if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) ) { $path = $page['cat_dir'].$_FILES['picture']['name']; if ( @is_file( $path ) ) { - $error[$i++] = $lang['upload_file_exists']; + array_push( $error, $lang['upload_file_exists'] ); } // test de la présence des champs obligatoires - if ( $_FILES['picture']['name'] == "" ) + if ( $_FILES['picture']['name'] == '' ) { - $error[$i++] = $lang['upload_filenotfound']; + array_push( $error, $lang['upload_filenotfound'] ); } if ( !ereg( "([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)", $_POST['mail_address'] ) ) { - $error[$i++] = $lang['reg_err_mail_address']; + array_push( $error, $lang['reg_err_mail_address'] ); } if ( $_POST['username'] == '' ) { - $error[$i++] = $lang['upload_err_username']; + array_push( $error, $lang['upload_err_username'] ); } + if ( $_POST['date_creation'] != '' ) + { + list( $day,$month,$year ) = explode( '/', $_POST['date_creation'] ); + // int checkdate ( int month, int day, int year) + if ( checkdate( $month, $day, $year ) ) + { + // int mktime ( int hour, int minute, int second, + // int month, int day, int year [, int is_dst]) + $date_creation = mktime( 0, 0, 0, $month, $day, $year ); + } + else + { + array_push( $error, $lang['err_date'] ); + } + } + // creation of the "infos" field : + // <infos author="Pierrick LE GALL" comment="my comment" + // date_creation="1056891767" name="" /> + $xml_infos = '<infos'; + $xml_infos.= ' author="'.htmlspecialchars($_POST['author'],ENT_QUOTES).'"'; + $xml_infos.= ' comment="'.htmlspecialchars($_POST['comment'],ENT_QUOTES).'"'; + $xml_infos.= ' date_creation="'.$date_creation.'"'; + $xml_infos.= ' name="'.htmlspecialchars( $_POST['name'], ENT_QUOTES).'"'; + $xml_infos.= ' />'; + if ( sizeof( $error ) == 0 ) { $result = validate_upload( $path, $conf['upload_maxfilesize'], @@ -173,17 +194,17 @@ if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) ) $upload_type = $result['type']; for ( $j = 0; $j < sizeof( $result['error'] ); $j++ ) { - $error[$i++] = $result['error'][$j]; + array_push( $error, $result['error'][$j] ); } } if ( sizeof( $error ) == 0 ) { $query = 'insert into '.PREFIX_TABLE.'waiting'; - $query.= ' (cat_id,file,username,mail_address,date) values'; + $query.= ' (cat_id,file,username,mail_address,date,infos) values'; $query.= " (".$page['cat'].",'".$_FILES['picture']['name']."'"; $query.= ",'".htmlspecialchars( $_POST['username'], ENT_QUOTES)."'"; - $query.= ",'".$_POST['mail_address']."',".time().")"; + $query.= ",'".$_POST['mail_address']."',".time().",'".$xml_infos."')"; $query.= ';'; mysql_query( $query ); $page['waiting_id'] = mysql_insert_id(); @@ -209,7 +230,7 @@ if ( isset( $_POST['submit'] ) and isset( $_GET['waiting_id'] ) ) $upload_type = $result['type']; for ( $j = 0; $j < sizeof( $result['error'] ); $j++ ) { - $error[$i++] = $result['error'][$j]; + array_push( $error, $result['error'][$j] ); } if ( sizeof( $error ) == 0 ) { @@ -243,7 +264,7 @@ if ( !$page['upload_successful'] ) { $url.= '&waiting_id='.$page['waiting_id']; } - $vtp->setGlobalVar( $handle, 'form_action', $url ); + $vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) ); //--------------------------------------------------------------------- advises if ( $conf['upload_maxfilesize'] != '' ) { @@ -307,7 +328,27 @@ if ( !$page['upload_successful'] ) if ( !isset( $page['waiting_id'] ) ) { $vtp->addSession( $handle, 'fields' ); + // username + if ( isset( $_POST['username'] ) ) $username = $_POST['username']; + else $username = $user['username']; + $vtp->setVar( $handle, 'fields.username', $username ); + // mail address + if ( isset( $_POST['mail_address'] ) )$mail_address=$_POST['mail_address']; + else $mail_address=$user['mail_address']; + $vtp->setGlobalVar( $handle, 'user_mail_address',$user['mail_address'] ); + // name of the picture + $vtp->setVar( $handle, 'fields.name', $_POST['name'] ); + // author + $vtp->setVar( $handle, 'fields.author', $_POST['author'] ); + // date of creation + $vtp->setVar( $handle, 'fields.date_creation', $_POST['date_creation'] ); + // comment + $vtp->setVar( $handle, 'fields.comment', $_POST['comment'] ); + $vtp->closeSession( $handle, 'fields' ); + + $vtp->addSession( $handle, 'note' ); + $vtp->closeSession( $handle, 'note' ); } $vtp->closeSession( $handle, 'upload_not_successful' ); } |