public function receive_event(Event $event) { if (is_null($this->theme)) { $this->theme = get_theme_object($this); } if ($event instanceof DataUploadEvent && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { $hash = $event->hash; $ha = substr($hash, 0, 2); if (!move_upload_to_archive($event)) { return; } send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); $image = $this->create_image_from_data(warehouse_path("images", $hash), $event->metadata); if (is_null($image)) { throw new UploadException("SVG handler failed to create image object from data"); } $iae = new ImageAdditionEvent($event->user, $image); send_event($iae); $event->image_id = $iae->image->id; } if ($event instanceof ThumbnailGenerationEvent && $this->supported_ext($event->type)) { $hash = $event->hash; $ha = substr($hash, 0, 2); global $config; // if($config->get_string("thumb_engine") == "convert") { // $w = $config->get_int("thumb_width"); // $h = $config->get_int("thumb_height"); // $q = $config->get_int("thumb_quality"); // $mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB // // exec("convert images/{$ha}/{$hash}[0] -geometry {$w}x{$h} -quality {$q} jpg:thumbs/{$ha}/{$hash}"); // } // else { copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash)); // } } if ($event instanceof DisplayingImageEvent && $this->supported_ext($event->image->ext)) { global $page; $this->theme->display_image($page, $event->image); } if ($event instanceof PageRequestEvent && $event->page_matches("get_svg")) { global $config, $database, $page; $id = int_escape($event->get_arg(0)); $image = Image::by_id($id); $hash = $image->hash; $page->set_type("image/svg+xml"); $page->set_mode("data"); $page->set_data(file_get_contents(warehouse_path("images", $hash))); } }
public function onDataUpload(DataUploadEvent $event) { if ($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { $hash = $event->hash; if (!move_upload_to_archive($event)) { return; } send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); $image = $this->create_image_from_data(warehouse_path("images", $hash), $event->metadata); if (is_null($image)) { throw new UploadException("SVG handler failed to create image object from data"); } $iae = new ImageAdditionEvent($image); send_event($iae); $event->image_id = $iae->image->id; } }
public function receive_event(Event $event) { if (is_null($this->theme)) { $this->theme = get_theme_object($this); } if ($event instanceof DataUploadEvent && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { if (!move_upload_to_archive($event)) { return; } send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); $image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata); if (is_null($image)) { throw new UploadException("Data handler failed to create image object from data"); } $iae = new ImageAdditionEvent($event->user, $image); send_event($iae); $event->image_id = $iae->image->id; } if ($event instanceof ThumbnailGenerationEvent && $this->supported_ext($event->type)) { $this->create_thumb($event->hash); } if ($event instanceof DisplayingImageEvent && $this->supported_ext($event->image->ext)) { global $page; $this->theme->display_image($page, $event->image); } }
/** * @param DataUploadEvent $event * @throws UploadException */ public function onDataUpload(DataUploadEvent $event) { $supported_ext = $this->supported_ext($event->type); $check_contents = $this->check_contents($event->tmpname); if ($supported_ext && $check_contents) { if (!move_upload_to_archive($event)) { return; } send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); /* Check if we are replacing an image */ if (array_key_exists('replace', $event->metadata) && isset($event->metadata['replace'])) { /* hax: This seems like such a dirty way to do this.. */ /* Validate things */ $image_id = int_escape($event->metadata['replace']); /* Check to make sure the image exists. */ $existing = Image::by_id($image_id); if (is_null($existing)) { throw new UploadException("Image to replace does not exist!"); } if ($existing->hash === $event->metadata['hash']) { throw new UploadException("The uploaded image is the same as the one to replace."); } // even more hax.. $event->metadata['tags'] = $existing->get_tag_list(); $image = $this->create_image_from_data(warehouse_path("images", $event->metadata['hash']), $event->metadata); if (is_null($image)) { throw new UploadException("Data handler failed to create image object from data"); } $ire = new ImageReplaceEvent($image_id, $image); send_event($ire); $event->image_id = $image_id; } else { $image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata); if (is_null($image)) { throw new UploadException("Data handler failed to create image object from data"); } $iae = new ImageAdditionEvent($image); send_event($iae); $event->image_id = $iae->image->id; // Rating Stuff. if (!empty($event->metadata['rating'])) { $rating = $event->metadata['rating']; send_event(new RatingSetEvent($image, $rating)); } // Locked Stuff. if (!empty($event->metadata['locked'])) { $locked = $event->metadata['locked']; send_event(new LockSetEvent($image, !empty($locked))); } } } elseif ($supported_ext && !$check_contents) { throw new UploadException("Invalid or corrupted file"); } }
public function receive_event(Event $event) { if (is_null($this->theme)) { $this->theme = get_theme_object($this); } if ($event instanceof DataUploadEvent && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) { if (!move_upload_to_archive($event)) { return; } send_event(new ThumbnailGenerationEvent($event->hash, $event->type)); /* Check if we are replacing an image */ if (array_key_exists('replace', $event->metadata) && isset($event->metadata['replace'])) { /* hax: This seems like such a dirty way to do this.. */ /* Validate things */ $image_id = int_escape($event->metadata['replace']); /* Check to make sure the image exists. */ $existing = Image::by_id($image_id); if (is_null($existing)) { throw new UploadException("Image to replace does not exist!"); } if ($existing->hash === $event->metadata['hash']) { throw new UploadException("The uploaded image is the same as the one to replace."); } // even more hax.. $event->metadata['tags'] = $existing->get_tag_list(); $image = $this->create_image_from_data(warehouse_path("images", $event->metadata['hash']), $event->metadata); if (is_null($image)) { throw new UploadException("Data handler failed to create image object from data"); } $ire = new ImageReplaceEvent($image_id, $image); send_event($ire); $event->image_id = $image_id; } else { $image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata); if (is_null($image)) { throw new UploadException("Data handler failed to create image object from data"); } $iae = new ImageAdditionEvent($event->user, $image); send_event($iae); $event->image_id = $iae->image->id; // Rating Stuff. if (!empty($event->metadata['rating'])) { global $user; $rating = $event->metadata['rating']; send_event(new RatingSetEvent($image, $user, $rating)); } // Locked Stuff. if (!empty($event->metadata['locked'])) { $locked = $event->metadata['locked']; send_event(new LockSetEvent($image, !empty($locked))); } } } if ($event instanceof ThumbnailGenerationEvent && $this->supported_ext($event->type)) { $this->create_thumb($event->hash); } if ($event instanceof DisplayingImageEvent && $this->supported_ext($event->image->ext)) { global $page; $this->theme->display_image($page, $event->image); } if ($event instanceof SetupBuildingEvent) { $sb = $this->setup(); if ($sb) { $event->panel->add_block($sb); } } }