Working on image replace.
Getting unknown 404 errors.
This commit is contained in:
parent
0d863c898e
commit
b02c747ac1
@ -57,7 +57,8 @@ class ImageDeletionEvent extends Event {
|
||||
class ImageReplaceEvent extends Event {
|
||||
var $image;
|
||||
|
||||
public function ImageReplaceEvent(Image $image) {
|
||||
public function ImageReplaceEvent($id, Image $image) {
|
||||
$this->id = $id;
|
||||
$this->image = $image;
|
||||
}
|
||||
}
|
||||
@ -162,7 +163,7 @@ class ImageIO extends SimpleExtension {
|
||||
$page->set_redirect(make_link('upload/replace/'.$image->id));
|
||||
} else {
|
||||
/* Invalid image ID */
|
||||
// fail silently?
|
||||
throw new ImageReplaceException("Image to replace does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,7 +191,7 @@ class ImageIO extends SimpleExtension {
|
||||
|
||||
public function onImageReplace($event) {
|
||||
try {
|
||||
$this->replace_image($event->image_old, $event->image_new);
|
||||
$this->replace_image($event->id, $event->image);
|
||||
}
|
||||
catch(ImageReplaceException $e) {
|
||||
throw new UploadException($e->error);
|
||||
|
@ -28,7 +28,14 @@ class ImageIOTheme {
|
||||
";
|
||||
}
|
||||
|
||||
$html .= "<a href='".make_link("upload/replace/".$i_image_id)."'>Replace Image</a>";
|
||||
if($config->get_bool("upload_replace")) {
|
||||
$html .= "
|
||||
".make_form(make_link("image_admin/replace"))."
|
||||
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||
<input type='submit' value='Replace' />
|
||||
</form>
|
||||
";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
@ -69,25 +69,58 @@ class Upload implements Extension {
|
||||
}
|
||||
|
||||
if($event instanceof PageRequestEvent) {
|
||||
/* Upload and Replace Image */
|
||||
if ($event->page_matches("upload/replace"))
|
||||
{
|
||||
/* Replace Image Request */
|
||||
if (!$config->get_bool("upload_replace")) {
|
||||
throw new UploadException("Upload Replacing Images is not enabled.");
|
||||
}
|
||||
if($is_full) {
|
||||
throw new UploadException("Can not replace Image: disk nearly full");
|
||||
}
|
||||
// Try to get the image ID
|
||||
$image_id = int_escape($event->get_arg(0));
|
||||
$image_old = Image::by_id($image_id);
|
||||
if (empty($image_id)) {
|
||||
$image_id = isset($_POST['image_id']) ? $_POST['image_id'] : null;
|
||||
}
|
||||
|
||||
if (empty($image_id)) {
|
||||
throw new UploadException("Can not replace Image: No valid Image ID given.");
|
||||
}
|
||||
|
||||
$image_old = Image::by_id($image_id);
|
||||
if(is_null($image_old)) {
|
||||
$this->theme->display_error($page, "Image not found", "No image in the database has the ID #$image_id");
|
||||
}
|
||||
|
||||
$this->theme->display_replace_page($page, $image_id);
|
||||
|
||||
}
|
||||
else if ($event->page_matches("upload"))
|
||||
{
|
||||
// Try to get the image ID
|
||||
$image_id = int_escape($event->get_arg(0));
|
||||
if (empty($image_id)) {
|
||||
$image_id = isset($_POST['image_id']) ? $_POST['image_id'] : null;
|
||||
}
|
||||
if (!empty($image_id))
|
||||
{
|
||||
/* Upload and Replace Image */
|
||||
if (!$config->get_bool("upload_replace")) {
|
||||
throw new UploadException("Upload Replacing Images is not enabled.");
|
||||
}
|
||||
if($is_full) {
|
||||
throw new UploadException("Can not replace Image: disk nearly full");
|
||||
}
|
||||
$image_old = Image::by_id($image_id);
|
||||
if(is_null($image_old)) {
|
||||
$this->theme->display_error($page, "Image not found", "No image in the database has the ID #$image_id");
|
||||
}
|
||||
if(count($_FILES) + count($_POST) > 0)
|
||||
{
|
||||
if (count($_FILES) > 1) {
|
||||
throw new UploadException("Can not upload more than one image for replacing.");
|
||||
}
|
||||
|
||||
if($this->can_upload($user)) {
|
||||
if (count($_FILES)) {
|
||||
$ok = $this->try_upload($_FILES, $tags, $source, $image_id);
|
||||
@ -100,7 +133,7 @@ class Upload implements Extension {
|
||||
}
|
||||
}
|
||||
/* Could replace with a page saying the image replace was successful? */
|
||||
$this->theme->display_upload_status($page, $ok);
|
||||
$this->theme->display_replace_upload_status($page, $ok);
|
||||
} else {
|
||||
$this->theme->display_permission_denied($page);
|
||||
}
|
||||
@ -111,19 +144,18 @@ class Upload implements Extension {
|
||||
$url = $_GET['url'];
|
||||
$ok = $this->try_transload($url, $tags, $url, $image_id);
|
||||
/* Replace with a page saying the image replace was successful */
|
||||
$this->theme->display_upload_status($page, $ok);
|
||||
$this->theme->display_replace_upload_status($page, $ok);
|
||||
}
|
||||
else {
|
||||
$this->theme->display_permission_denied($page);
|
||||
}
|
||||
} else {
|
||||
$this->theme->display_replace_page($page);
|
||||
}
|
||||
}
|
||||
/* Upload Image */
|
||||
else if ($event->page_matches("upload"))
|
||||
else
|
||||
{
|
||||
/* Regular Upload Image */
|
||||
if(count($_FILES) + count($_POST) > 0)
|
||||
{
|
||||
if(count($_FILES) + count($_POST) > 0) {
|
||||
$tags = Tag::explode($_POST['tags']);
|
||||
$source = isset($_POST['source']) ? $_POST['source'] : null;
|
||||
if($this->can_upload($user)) {
|
||||
@ -165,6 +197,7 @@ class Upload implements Extension {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof SetupBuildingEvent) {
|
||||
$tes = array();
|
||||
|
@ -76,7 +76,7 @@ class UploadTheme extends Themelet {
|
||||
}
|
||||
|
||||
/* only allows 1 file to be uploaded - for replacing another image file */
|
||||
public function display_replace_page(Page $page) {
|
||||
public function display_replace_page(Page $page, $image_id) {
|
||||
global $config;
|
||||
$tl_enabled = ($config->get_string("transload_engine", "none") != "none");
|
||||
|
||||
@ -99,7 +99,9 @@ class UploadTheme extends Themelet {
|
||||
|
||||
$max_size = $config->get_int('upload_size');
|
||||
$max_kb = to_shorthand_int($max_size);
|
||||
$html = make_form(make_link("upload/replace"), "POST", $multipart=True)."
|
||||
$html = "<p>Replacing Image ID# ".$image_id."</p>"
|
||||
.make_form(make_link("upload"), "POST", $multipart=True)."
|
||||
<input type='hidden' name='image_id' value='$image_id'>
|
||||
<table id='large_upload_form'>
|
||||
$upload_list
|
||||
<tr><td>Source</td><td colspan='3'><input name='source' type='text'></td></tr>
|
||||
@ -108,15 +110,7 @@ class UploadTheme extends Themelet {
|
||||
</form>
|
||||
<small>(Max file size is $max_kb)</small>
|
||||
";
|
||||
/*
|
||||
if($tl_enabled) {
|
||||
$link = make_http(make_link("upload"));
|
||||
$title = "Upload to " . $config->get_string('title');
|
||||
$html .= '<p><a href="javascript:location.href="' .
|
||||
$link . '?url="+location.href+"&tags="+prompt("enter tags")">' .
|
||||
$title . '</a> (Drag & drop onto your bookmarks toolbar, then click when looking at an image)';
|
||||
}
|
||||
*/
|
||||
|
||||
$page->set_title("Replace Image Upload");
|
||||
$page->set_heading("Replace Image Upload");
|
||||
$page->add_block(new NavBlock());
|
||||
@ -135,6 +129,22 @@ class UploadTheme extends Themelet {
|
||||
}
|
||||
}
|
||||
|
||||
public function display_replace_upload_status(Page $page, $ok) {
|
||||
if($ok) {
|
||||
$page->set_title("GREAT SUCCESS!");
|
||||
$page->set_heading("GREAT SUCCESS!");
|
||||
$page->add_block(new NavBlock());
|
||||
/*
|
||||
$page->set_mode("redirect");
|
||||
$page->set_redirect(make_link());*/
|
||||
}
|
||||
else {
|
||||
$page->set_title("poo");
|
||||
$page->set_heading("Upload Status");
|
||||
$page->add_block(new NavBlock());
|
||||
}
|
||||
}
|
||||
|
||||
public function display_upload_error(Page $page, $title, $message) {
|
||||
$page->add_block(new Block($title, $message));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user