Page 1 of 1
Getting forwarded after adding media
Posted: Tue May 19, 2009 12:01 am
by onli
When adding media to the library, the user sees only some messages. After that, he still sees a almost blank page with the messages on it. He definitely has to choose where to go - probably into the media-library. But if we send him directly into the library and present him the messages there, he could still choose to go to a different place, but if he wanted to go to the library he would already be there. I can't see a drawback.
So, is there a cause why that's not done that way till now, or do you think it's a bad idea? If not: Which way to go to make this possible? Should include/admin/images.inc.php open the media-library with the attaches status message (is there an example how to do this?)?
sincerely
Re: Getting forwarded after adding media
Posted: Tue May 19, 2009 9:31 am
by garvinhicking
Hi!
The cause is that the messages are only available on the next request. If we forwarded it again, we would need to carry over all messages somehow. So it's "just" technical work; it's easier without forwarding.
Regards,
Garvin
Re: Getting forwarded after adding media
Posted: Thu May 21, 2009 1:06 pm
by onli
I implemented it
Code: Select all
diff -Nur serendipity-nightly/include/admin/images.inc.php /var/www/include/admin/images.inc.php
--- serendipity-nightly/include/admin/images.inc.php 2008-04-09 03:57:10.000000000 +0200
+++ /var/www/include/admin/images.inc.php 2009-05-21 12:59:11.000000000 +0200
@@ -115,6 +115,7 @@
$file = $serendipity['GET']['fname'];
serendipity_deleteImage($serendipity['GET']['fid']);
+ showMediaLibrary();
break;
case 'delete':
@@ -179,7 +180,7 @@
if (!serendipity_checkFormToken() || !serendipity_checkPermission('adminImagesAdd')) {
return;
}
-
+ $messages = array();
if ($serendipity['POST']['adminSubAction'] == 'properties') {
$properties = serendipity_parsePropertyForm();
$image_id = $properties['image_id'];
@@ -196,8 +197,6 @@
}
?>
- <div class="image_add"><b><?php echo ADDING_IMAGE; ?></b></div>
- <br /><br />
<?php
$authorid = (isset($serendipity['POST']['all_authors']) && $serendipity['POST']['all_authors'] == 'true') ? '0' : $serendipity['authorid'];
@@ -221,7 +220,7 @@
$tfile = serendipity_uploadSecure(basename($tfile));
if (serendipity_isActiveFile($tfile)) {
- printf(ERROR_FILE_FORBIDDEN, $tfile);
+ $messages[] = sprintf(ERROR_FILE_FORBIDDEN, $tfile);
break;
}
@@ -229,13 +228,13 @@
$target = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$tindex] . $tfile;
if (!serendipity_checkDirUpload($serendipity['POST']['target_directory'][$tindex])) {
- echo PERM_DENIED;
+ $messages[] = PERM_DENIED;
return;
}
$realname = $tfile;
if (file_exists($target)) {
- echo '(' . $target . ') ' . ERROR_FILE_EXISTS_ALREADY . '<br />';
+ $messages[] = '(' . $target . ') ' . ERROR_FILE_EXISTS_ALREADY . '';
$realname = serendipity_imageAppend($tfile, $target, $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$tindex]);
}
@@ -247,7 +246,7 @@
// Try to get the URL
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
- printf(REMOTE_FILE_NOT_FOUND, $serendipity['POST']['imageurl']);
+ $messages[] = sprintf(REMOTE_FILE_NOT_FOUND, $serendipity['POST']['imageurl']);
} else {
// Fetch file
$fContent = $req->getResponseBody();
@@ -259,14 +258,14 @@
fclose($fp);
$image_id = @serendipity_insertHotlinkedImageInDatabase($tfile, $serendipity['POST']['imageurl'], $authorid, null, $tempfile);
- printf(HOTLINK_DONE. '<br />', $serendipity['POST']['imageurl'], $tfile);
+ $messages[] = sprintf( HOTLINK_DONE , $serendipity['POST']['imageurl'] , $tfile .'');
serendipity_plugin_api::hook_event('backend_image_addHotlink', $tempfile);
} else {
$fp = fopen($target, 'w');
fwrite($fp, $fContent);
fclose($fp);
- printf(FILE_FETCHED . '<br />', $serendipity['POST']['imageurl'], $tfile);
+ $messages[] = sprintf(FILE_FETCHED , $serendipity['POST']['imageurl'] , $tfile);
if (serendipity_checkMediaSize($target)) {
$thumbs = array(array(
@@ -278,7 +277,7 @@
foreach($thumbs as $thumb) {
// Create thumbnail
if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$tindex], $thumb['thumbSize'], $thumb['thumb']) ) {
- echo THUMB_CREATED_DONE . '<br />';
+ $messages[] = THUMB_CREATED_DONE . '';
}
}
@@ -314,15 +313,14 @@
$tfile = serendipity_uploadSecure(basename($tfile));
if (serendipity_isActiveFile($tfile)) {
- printf(ERROR_FILE_FORBIDDEN, $tfile);
- echo '<br />';
+ $messages[] = ''. ERROR_FILE_FORBIDDEN.' '. $tfile.'';
continue;
}
$serendipity['POST']['target_directory'][$idx] = serendipity_uploadSecure($serendipity['POST']['target_directory'][$idx], true, true);
if (!serendipity_checkDirUpload($serendipity['POST']['target_directory'][$idx])) {
- echo PERM_DENIED;
+ $messages[] = PERM_DENIED;
continue;
}
@@ -330,13 +328,13 @@
$realname = $tfile;
if (file_exists($target)) {
- echo '(' . $target . ') ' . ERROR_FILE_EXISTS_ALREADY . '<br />';
+ $messages[] = '(' . $target . ') ' . ERROR_FILE_EXISTS_ALREADY . '';
$realname = serendipity_imageAppend($tfile, $target, $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$idx]);
}
// Accept file
if (is_uploaded_file($uploadtmp) && serendipity_checkMediaSize($uploadtmp) && move_uploaded_file($uploadtmp, $target)) {
- printf(FILE_UPLOADED . '<br />', $uploadfile, $target);
+ $messages[] = sprintf( FILE_UPLOADED , $uploadfile , $target);
@umask(0000);
@chmod($target, 0664);
@@ -349,7 +347,7 @@
foreach($thumbs as $thumb) {
// Create thumbnail
if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$idx], $thumb['thumbSize'], $thumb['thumb']) ) {
- echo THUMB_CREATED_DONE . '<br />';
+ $messages[] = THUMB_CREATED_DONE . '';
}
}
@@ -362,7 +360,7 @@
'created_thumbnail' => $created_thumbnail
);
} else {
- echo ERROR_UNKNOWN_NOUPLOAD . '<br />';
+ $messages[] = ERROR_UNKNOWN_NOUPLOAD . '';
}
}
}
@@ -379,6 +377,8 @@
serendipity_insertMediaProperty('base_hidden', '', $nm['image_id'], $hidden);
}
}
+ showMediaLibrary($messages);
+
break;
@@ -816,10 +816,24 @@
break;
default:
- if (!serendipity_checkPermission('adminImagesView')) {
+ showMediaLibrary();
+
+ break;
+}
+
+function showMediaLibrary($messages=false) {
+ if (!serendipity_checkPermission('adminImagesView')) {
return;
}
+ if(!empty($messages)) {
+ echo '<div class="imageMessage"><ul>';
+ foreach($messages as $message) {
+ echo '<li>'. $message .'</li>';
+ }
+ echo '</ul></div>';
+ }
+
?>
<script type="text/javascript" language="javascript">
<!--
@@ -840,7 +854,5 @@
$serendipity['thumbPerPage'],
true
);
-
- break;
}
/* vim: set sts=4 ts=4 expandtab : */
If you agree with that way, It would be a nice-to-have change to modify serendipity_deleteImage() and serendipity_imageAppend() to also output it's text in a div class=imageMessage or return the text to append it to the messages-array. The last option is of course only possible if that wouldn't break anything.
sincerely
Re: Getting forwarded after adding media
Posted: Mon May 25, 2009 10:58 am
by garvinhicking
Hi!
When I copy&paste the diff, I cannot apply it:
Code: Select all
patching file images.inc.php
patch: **** malformed patch at line 24: ?>
Can you re-attach it, and upload it instead of pasting?
Also, I noticed you often use the . '' concatenation, is there a reason for you to do that? For better readability, I would strip that.
Regards,
Garvin
Re: Getting forwarded after adding media
Posted: Mon May 25, 2009 9:12 pm
by onli
The '' served as kind of placehodlers for the html-tags inserted there before, removed.
The extension diff is not allowed, diff added as txt.
Re: Getting forwarded after adding media
Posted: Tue May 26, 2009 11:54 am
by garvinhicking
Hi!
Thanks, it seems to work well here. Committed!
Regards,
Garvin
Re: Getting forwarded after adding media
Posted: Sun Oct 25, 2009 10:43 pm
by onli
http://board.s9y.org/viewtopic.php?f=10&t=15941&start=0 made clear there was a bug: when uploading an image via the image_selector of the entry-editor it's not good to fordward to the library, because the option to place the added image will be below that library. Attached diff tries to solve this.
Re: Getting forwarded after adding media
Posted: Mon Oct 26, 2009 2:04 pm
by garvinhicking
Hi!
I'm wondering if this return might need to be called after the $messages return? If something goes wrong, the $messages would else not be shown, like when a file was not uploaded due to PHP memory_limit?
Regards,
Garvin
Re: Getting forwarded after adding media
Posted: Mon Oct 26, 2009 5:21 pm
by onli
Yes. It wouldn't hurt and could possibly catch those cases (and the normal messages should be displayed when uploading, shouldn't they?).
sincerely
Re: Getting forwarded after adding media
Posted: Tue Oct 27, 2009 10:13 am
by garvinhicking
Hi!
Committed!
Regards,
Garvin