aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrub <rub@piwigo.org>2006-12-03 22:32:02 +0000
committerrub <rub@piwigo.org>2006-12-03 22:32:02 +0000
commit4c7e7fb0fb9cca9b2d32940a0b1477b03e0801ee (patch)
treeadb063ca78b20e995425fcd3fb889a5e97ba5148
parent9ba8fb139787b6c6392a51fcf2da25afc00f3b86 (diff)
Fixed Issue ID 0000494: Stats do not currently include Uploads
Fixed: Error when thumbnail directory not exists Fixed: Apply current translation norme Fixed: Improvement style sheet (like other PWG sheet) git-svn-id: http://piwigo.org/svn/trunk@1631 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/thumbnail.php18
-rw-r--r--include/functions.inc.php28
-rw-r--r--template/yoga/content.css1
-rw-r--r--template/yoga/upload.tpl195
-rw-r--r--upload.php116
5 files changed, 195 insertions, 163 deletions
diff --git a/admin/thumbnail.php b/admin/thumbnail.php
index d46a05b9c..594125a84 100644
--- a/admin/thumbnail.php
+++ b/admin/thumbnail.php
@@ -63,7 +63,7 @@ function RatioResizeImg($path, $newWidth, $newHeight, $tn_ext)
{
unset($extension);
}
-
+
if ( isset( $srcImage ) )
{
// width/height
@@ -106,20 +106,12 @@ function RatioResizeImg($path, $newWidth, $newHeight, $tn_ext)
imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0,
$destWidth,$destHeight,$srcWidth,$srcHeight );
}
-
- $tndir = $dirname.'/thumbnail';
- if (!is_dir($tndir))
+
+ if (($tndir = mkget_thumbnail_dir($dirname, $page['errors'])) == false)
{
- if (!is_writable($dirname))
- {
- array_push($page['errors'],
- '['.$dirname.'] : '.$lang['no_write_access']);
- return false;
- }
- umask(0000);
- mkdir($tndir, 0777);
+ return false;
}
-
+
$dest_file = $tndir.'/'.$conf['prefix_thumbnail'];
$dest_file.= get_filename_wo_extension($filename);
$dest_file.= '.'.$tn_ext;
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 7851021a3..537edc32a 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -215,6 +215,34 @@ function get_dirs($directory)
return $sub_dirs;
}
+/**
+ * returns thumbnail directory name of input diretoty name
+ * make thumbnail directory is necessary
+ * set error messages on array messages
+ *
+ * @param:
+ * string $dirname
+ * arrayy $errors
+ * @return bool false on error else string directory name
+ */
+function mkget_thumbnail_dir($dirname, &$errors)
+{
+ $tndir = $dirname.'/thumbnail';
+ if (!is_dir($tndir))
+ {
+ if (!is_writable($dirname))
+ {
+ array_push($errors,
+ '['.$dirname.'] : '.l10n('no_write_access'));
+ return false;
+ }
+ umask(0000);
+ mkdir($tndir, 0777);
+ }
+
+ return $tndir;
+}
+
// The get_picture_size function return an array containing :
// - $picture_size[0] : final width
// - $picture_size[1] : final height
diff --git a/template/yoga/content.css b/template/yoga/content.css
index 9eccdeed1..6b61ea72c 100644
--- a/template/yoga/content.css
+++ b/template/yoga/content.css
@@ -5,6 +5,7 @@
}
BODY#theCommentsPage #content,
+BODY#theUploadPage #content,
BODY#theRegisterPage #content,
BODY#theIdentificationPage #content,
BODY#theProfilePage #content,
diff --git a/template/yoga/upload.tpl b/template/yoga/upload.tpl
index fcf27b543..ef7498aa9 100644
--- a/template/yoga/upload.tpl
+++ b/template/yoga/upload.tpl
@@ -1,93 +1,102 @@
-<h2>{L_TITLE}</h2>
-<!-- BEGIN upload_not_successful -->
-<form enctype="multipart/form-data" method="post" action="{F_ACTION}">
- <table style="width:80%;margin-left:auto;margin-right:auto;">
- <!-- BEGIN errors -->
- <tr>
- <td colspan="2">
- <div class="errors">
- <ul>
- <!-- BEGIN error -->
- <li>{upload_not_successful.errors.error.ERROR}</li>
- <!-- END error -->
- </ul>
- </div>
- </td>
- </tr>
- <!-- END errors -->
- <tr>
- <td colspan="2" class="menu">
- <div style="text-align:center;">{ADVISE_TITLE}</div>
- <ul>
- <!-- BEGIN advise -->
- <li>{upload_not_successful.advise.ADVISE}</li>
- <!-- END advise -->
- </ul>
- </td>
- </tr>
- <tr>
- <td colspan="2" align="center" style="padding:10px;">
- <input name="picture" type="file" value="" />
- </td>
- </tr>
- <!-- BEGIN fields -->
- <!-- username -->
- <tr>
- <td class="menu">{L_USERNAME} <span style="color:red;">*</span></td>
- <td align="center" style="padding:10px;">
- <input name="username" type="text" value="{NAME}" />
- </td>
- </tr>
- <!-- mail address -->
- <tr>
- <td class="menu">{L_EMAIL} <span style="color:red;">*</span></td>
- <td align="center" style="padding:10px;">
- <input name="mail_address" type="text" value="{EMAIL}" />
- </td>
- </tr>
- <!-- name of the picture -->
- <tr>
- <td class="menu">{L_NAME_IMG}</td>
- <td align="center" style="padding:10px;">
- <input name="name" type="text" value="{NAME_IMG}" />
- </td>
- </tr>
- <!-- author -->
- <tr>
- <td class="menu">{L_AUTHOR}</td>
- <td align="center" style="padding:10px;">
- <input name="author" type="text" value="{AUTHOR_IMG}" />
- </td>
- </tr>
- <!-- date of creation -->
- <tr>
- <td class="menu">{L_CREATION_DATE}</td>
- <td align="center" style="padding:10px;">
- <input name="date_creation" type="text" value="{DATE_IMG}" />
- </td>
- </tr>
- <!-- comment -->
- <tr>
- <td class="menu">{L_COMMENT}</td>
- <td align="center" style="padding:10px;">
- <textarea name="comment" rows="3" cols="40" style="overflow:auto">{COMMENT_IMG}</textarea>
- </td>
- </tr>
- <!-- END fields -->
- <tr>
- <td colspan="2" align="center">
- <input name="submit" type="submit" value="{L_SUBMIT}" class="bouton" />
- </td>
- </tr>
- </table>
-</form>
-<!-- END upload_not_successful -->
-<!-- BEGIN upload_successful -->
-{L_UPLOAD_DONE}<br />
-<!-- END upload_successful -->
-<div style="text-align:center;">
- <a href="{U_RETURN}">[ {L_RETURN} ]</a>
-</div>
-<!-- BEGIN note -->
-<div style="text-align:left;"><span style="color:red;">*</span> : {L_MANDATORY}</div>
-<!-- END note -->
+<div id="content">
+
+ <div class="titrePage">
+ <ul class="categoryActions">
+ <li><a href="{U_HOME}" title="{lang:return to homepage}"><img src="{themeconf:icon_dir}/home.png" class="button" alt="{lang:home}"/></a></li>
+ </ul>
+ <h2>{lang:upload_title}</h2>
+ </div>
+
+ <!-- BEGIN upload_not_successful -->
+ <form enctype="multipart/form-data" method="post" action="{F_ACTION}">
+ <table style="width:80%;margin-left:auto;margin-right:auto;">
+ <!-- BEGIN errors -->
+ <tr>
+ <td colspan="2">
+ <div class="errors">
+ <ul>
+ <!-- BEGIN error -->
+ <li>{upload_not_successful.errors.error.ERROR}</li>
+ <!-- END error -->
+ </ul>
+ </div>
+ </td>
+ </tr>
+ <!-- END errors -->
+ <tr>
+ <td colspan="2" class="menu">
+ <div style="text-align:center;">{ADVISE_TITLE}</div>
+ <ul>
+ <!-- BEGIN advise -->
+ <li>{upload_not_successful.advise.ADVISE}</li>
+ <!-- END advise -->
+ </ul>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2" align="center" style="padding:10px;">
+ <input name="picture" type="file" value="" />
+ </td>
+ </tr>
+ <!-- BEGIN fields -->
+ <!-- username -->
+ <tr>
+ <td class="menu">{lang:upload_username} <span style="color:red;">*</span></td>
+ <td align="left" style="padding:10px;">
+ <input name="username" type="text" value="{NAME}" />
+ </td>
+ </tr>
+ <!-- mail address -->
+ <tr>
+ <td class="menu">{lang:mail_address} <span style="color:red;">*</span></td>
+ <td align="left" style="padding:10px;">
+ <input name="mail_address" type="text" value="{EMAIL}" />
+ </td>
+ </tr>
+ <!-- name of the picture -->
+ <tr>
+ <td class="menu">{lang:upload_name}</td>
+ <td align="left" style="padding:10px;">
+ <input name="name" type="text" value="{NAME_IMG}" />
+ </td>
+ </tr>
+ <!-- author -->
+ <tr>
+ <td class="menu">{lang:upload_author}</td>
+ <td align="left" style="padding:10px;">
+ <input name="author" type="text" value="{AUTHOR_IMG}" />
+ </td>
+ </tr>
+ <!-- date of creation -->
+ <tr>
+ <td class="menu">{lang:upload_creation_date}</td>
+ <td align="left" style="padding:10px;">
+ <input name="date_creation" type="text" value="{DATE_IMG}" />
+ </td>
+ </tr>
+ <!-- comment -->
+ <tr>
+ <td class="menu">{lang:comment}</td>
+ <td align="left" style="padding:10px;">
+ <textarea name="comment" rows="3" cols="40" style="overflow:auto">{COMMENT_IMG}</textarea>
+ </td>
+ </tr>
+ <!-- END fields -->
+ <tr>
+ <td colspan="2" align="center">
+ <input name="submit" type="submit" value="{lang:submit}" class="bouton" />
+ </td>
+ </tr>
+ </table>
+ </form>
+ <!-- END upload_not_successful -->
+ <!-- BEGIN upload_successful -->
+ {lang:upload_successful}<br />
+ <div style="text-align:center;">
+ <a href="{U_RETURN}">[ {lang:home} ]</a>
+ </div>
+ <!-- END upload_successful -->
+ <!-- BEGIN note -->
+ <div style="text-align:left;"><span style="color:red;">*</span> : {lang:mandatory}</div>
+ <!-- END note -->
+</div> <!-- content -->
diff --git a/upload.php b/upload.php
index e01778dbb..fdfa6d54e 100644
--- a/upload.php
+++ b/upload.php
@@ -27,6 +27,13 @@
define('PHPWG_ROOT_PATH','./');
include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
+$username = !empty($_POST['username'])?$_POST['username']:$user['username'];
+$mail_address = !empty($_POST['mail_address'])?$_POST['mail_address']:@$user['mail_address'];
+$name = !empty($_POST['name'])?$_POST['name']:'';
+$author = !empty($_POST['author'])?$_POST['author']:'';
+$date_creation = !empty($_POST['date_creation'])?$_POST['date_creation']:'';
+$comment = !empty($_POST['comment'])?$_POST['comment']:'';
+
//------------------------------------------------------------------- functions
// The validate_upload function checks if the image of the given path is valid.
// A picture is valid when :
@@ -40,15 +47,15 @@ include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
function validate_upload( $temp_name, $my_max_file_size,
$image_max_width, $image_max_height )
{
- global $conf, $lang;
-
+ global $conf, $lang, $page, $mail_address;
+
$result = array();
$result['error'] = array();
//echo $_FILES['picture']['name']."<br />".$temp_name;
$extension = get_extension( $_FILES['picture']['name'] );
if (!in_array($extension, $conf['picture_ext']))
{
- array_push( $result['error'], $lang['upload_advise_filetype'] );
+ array_push( $result['error'], l10n('upload_advise_filetype') );
return $result;
}
if ( !isset( $_FILES['picture'] ) )
@@ -59,7 +66,7 @@ function validate_upload( $temp_name, $my_max_file_size,
else if ( $_FILES['picture']['size'] > $my_max_file_size * 1024 )
{
array_push( $result['error'],
- $lang['upload_advise_filesize'].$my_max_file_size.' KB' );
+ l10n('upload_advise_filesize').$my_max_file_size.' KB' );
}
else
{
@@ -67,7 +74,7 @@ function validate_upload( $temp_name, $my_max_file_size,
// upload de la photo sous un nom temporaire
if ( !move_uploaded_file( $_FILES['picture']['tmp_name'], $temp_name ) )
{
- array_push( $result['error'], $lang['upload_cannot_upload'] );
+ array_push( $result['error'], l10n('upload_cannot_upload') );
}
else
{
@@ -77,14 +84,14 @@ function validate_upload( $temp_name, $my_max_file_size,
and $size[0] > $image_max_width )
{
array_push( $result['error'],
- $lang['upload_advise_width'].$image_max_width.' px' );
+ l10n('upload_advise_width').$image_max_width.' px' );
}
if ( isset( $image_max_height )
and $image_max_height != ""
and $size[1] > $image_max_height )
{
array_push( $result['error'],
- $lang['upload_advise_height'].$image_max_height.' px' );
+ l10n('upload_advise_height').$image_max_height.' px' );
}
// $size[2] == 1 means GIF
// $size[2] == 2 means JPG
@@ -95,7 +102,7 @@ function validate_upload( $temp_name, $my_max_file_size,
case 2 : $result['type'] = 'jpg'; break;
case 3 : $result['type'] = 'png'; break;
default :
- array_push( $result['error'], $lang['upload_advise_filetype'] );
+ array_push( $result['error'], l10n('upload_advise_filetype') );
}
}
}
@@ -108,8 +115,15 @@ function validate_upload( $temp_name, $my_max_file_size,
{
@chmod( $temp_name, 0644);
}
+
+ //------------------------------------------------------------ log informations
+ pwg_log('upload',
+ get_cat_display_name($page['cat_name']),
+ $_FILES['picture']['name'].
+ ' ['.$mail_address.'] '.'['.($result ? 'OK' : 'KO').']');
+
return $result;
-}
+}
//-------------------------------------------------- access authorization check
if (is_numeric($_GET['cat']))
@@ -145,21 +159,21 @@ if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) )
$path = $page['cat_dir'].$_FILES['picture']['name'];
if ( @is_file( $path ) )
{
- array_push( $error, $lang['upload_file_exists'] );
+ array_push( $error, l10n('upload_file_exists') );
}
// test de la présence des champs obligatoires
if ( empty($_FILES['picture']['name']))
{
- array_push( $error, $lang['upload_filenotfound'] );
+ array_push( $error, l10n('upload_filenotfound') );
}
if ( !ereg( "([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)",
$_POST['mail_address'] ) )
{
- array_push( $error, $lang['reg_err_mail_address'] );
+ array_push( $error, l10n('reg_err_mail_address') );
}
if ( empty($_POST['username']) )
{
- array_push( $error, $lang['upload_err_username'] );
+ array_push( $error, l10n('upload_err_username') );
}
$date_creation = '';
@@ -173,7 +187,7 @@ if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) )
}
else
{
- array_push( $error, $lang['err_date'] );
+ array_push( $error, l10n('err_date') );
}
}
// creation of the "infos" field :
@@ -188,7 +202,7 @@ if ( isset( $_POST['submit'] ) and !isset( $_GET['waiting_id'] ) )
if ( !preg_match( '/^[a-zA-Z0-9-_.]+$/', $_FILES['picture']['name'] ) )
{
- array_push( $error, $lang['update_wrong_dirname'] );
+ array_push( $error, l10n('update_wrong_dirname') );
}
if ( sizeof( $error ) == 0 )
@@ -228,15 +242,19 @@ if ( isset( $_POST['submit'] ) and isset( $_GET['waiting_id'] ) )
$row = mysql_fetch_array( $result );
$file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
$extension = get_extension( $_FILES['picture']['name'] );
- $path = $page['cat_dir'].'thumbnail/';
- $path.= $conf['prefix_thumbnail'].$file.'.'.$extension;
- $result = validate_upload( $path, $conf['upload_maxfilesize'],
- $conf['upload_maxwidth_thumbnail'],
- $conf['upload_maxheight_thumbnail'] );
- for ( $j = 0; $j < sizeof( $result['error'] ); $j++ )
+
+ if (($path = mkget_thumbnail_dir($page['cat_dir'], $error)) != false)
{
- array_push( $error, $result['error'][$j] );
+ $path.= '/'.$conf['prefix_thumbnail'].$file.'.'.$extension;
+ $result = validate_upload( $path, $conf['upload_maxfilesize'],
+ $conf['upload_maxwidth_thumbnail'],
+ $conf['upload_maxheight_thumbnail'] );
+ for ( $j = 0; $j < sizeof( $result['error'] ); $j++ )
+ {
+ array_push( $error, $result['error'][$j] );
+ }
}
+
if ( sizeof( $error ) == 0 )
{
$query = 'update '.WAITING_TABLE;
@@ -251,7 +269,8 @@ if ( isset( $_POST['submit'] ) and isset( $_GET['waiting_id'] ) )
//
// Start output of page
//
-$title= $lang['upload_title'];
+$title= l10n('upload_title');
+$page['body_id'] = 'theUploadPage';
include(PHPWG_ROOT_PATH.'include/page_header.php');
$template->set_filenames(array('upload'=>'upload.tpl'));
@@ -263,23 +282,18 @@ $u_form.= '&amp;waiting_id='.$page['waiting_id'];
if ( isset( $page['waiting_id'] ) )
{
- $advise_title=$lang['upload_advise_thumbnail'].$_FILES['picture']['name'];
+ $advise_title=l10n('upload_advise_thumbnail').$_FILES['picture']['name'];
}
else
{
- $advise_title = $lang['upload_advise'];
+ $advise_title = l10n('upload_advise');
$advise_title.= get_cat_display_name($page['cat_name']);
}
-$username = !empty($_POST['username'])?$_POST['username']:$user['username'];
-$mail_address = !empty($_POST['mail_address'])?$_POST['mail_address']:@$user['mail_address'];
-$name = !empty($_POST['name'])?$_POST['name']:'';
-$author = !empty($_POST['author'])?$_POST['author']:'';
-$date_creation = !empty($_POST['date_creation'])?$_POST['date_creation']:'';
-$comment = !empty($_POST['comment'])?$_POST['comment']:'';
-
$template->assign_vars(
array(
+ 'U_HOME' => make_index_url(),
+
'ADVISE_TITLE' => $advise_title,
'NAME' => $username,
'EMAIL' => $mail_address,
@@ -287,20 +301,7 @@ $template->assign_vars(
'AUTHOR_IMG' => $author,
'DATE_IMG' => $date_creation,
'COMMENT_IMG' => $comment,
-
- 'L_TITLE' => $lang['upload_title'],
- 'L_USERNAME' => $lang['upload_username'],
- 'L_EMAIL' => $lang['mail_address'],
- 'L_NAME_IMG' => $lang['upload_name'],
- 'L_SUBMIT' => $lang['submit'],
- 'L_AUTHOR' => $lang['upload_author'],
- 'L_CREATION_DATE' => $lang['upload_creation_date'],
- 'L_COMMENT' => $lang['comment'],
- 'L_RETURN' => $lang['home'],
- 'L_RETURN_HINT' => $lang['home_hint'],
- 'L_UPLOAD_DONE' => $lang['upload_successful'],
- 'L_MANDATORY' => $lang['mandatory'],
-
+
'F_ACTION' => $u_form,
'U_RETURN' => make_index_url(array('category' => $page['cat'])),
@@ -323,7 +324,7 @@ if ( sizeof( $error ) != 0 )
//--------------------------------------------------------------------- advises
if ( !empty($conf['upload_maxfilesize']) )
{
- $content = $lang['upload_advise_filesize'];
+ $content = l10n('upload_advise_filesize');
$content.= $conf['upload_maxfilesize'].' KB';
$template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
}
@@ -332,45 +333,46 @@ if ( sizeof( $error ) != 0 )
{
if ( $conf['upload_maxwidth_thumbnail'] != '' )
{
- $content = $lang['upload_advise_width'];
+ $content = l10n('upload_advise_width');
$content.= $conf['upload_maxwidth_thumbnail'].' px';
- $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
+ $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
}
if ( $conf['upload_maxheight_thumbnail'] != '' )
{
- $content = $lang['upload_advise_height'];
+ $content = l10n('upload_advise_height');
$content.= $conf['upload_maxheight_thumbnail'].' px';
- $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
+ $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
}
}
else
{
if ( $conf['upload_maxwidth'] != '' )
{
- $content = $lang['upload_advise_width'];
+ $content = l10n('upload_advise_width');
$content.= $conf['upload_maxwidth'].' px';
- $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
+ $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
}
if ( $conf['upload_maxheight'] != '' )
{
- $content = $lang['upload_advise_height'];
+ $content = l10n('upload_advise_height');
$content.= $conf['upload_maxheight'].' px';
- $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
+ $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$content));
}
}
- $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>$lang['upload_advise_filetype']));
+ $template->assign_block_vars('upload_not_successful.advise',array('ADVISE'=>l10n('upload_advise_filetype')));
//----------------------------------------- optionnal username and mail address
if ( !isset( $page['waiting_id'] ) )
{
$template->assign_block_vars('upload_not_successful.fields',array());
- $template->assign_block_vars('note',array());
+ $template->assign_block_vars('note',array());
}
}
else
{
$template->assign_block_vars('upload_successful',array());
}
+
//----------------------------------------------------------- html code display
$template->parse('upload');
include(PHPWG_ROOT_PATH.'include/page_tail.php');