all the extensions are simple now

This commit is contained in:
Shish 2012-02-08 11:45:35 +00:00
parent 4697e21fcd
commit 2b85e2d2fd
4 changed files with 169 additions and 194 deletions

View File

@ -19,41 +19,37 @@ class AuthorSetEvent extends Event {
} }
} }
class Artists implements Extension { class Artists extends SimpleExtension {
var $theme; public function onImageInfoSet(ImageInfoSetEvent $event) {
public function get_priority() {return 50;}
public function receive_event(Event $event)
{
global $user; global $user;
if (isset($_POST["tag_edit__author"])) {
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if ($event instanceof ImageInfoSetEvent)
if (isset($_POST["tag_edit__author"]))
send_event(new AuthorSetEvent($event->image, $user, $_POST["tag_edit__author"])); send_event(new AuthorSetEvent($event->image, $user, $_POST["tag_edit__author"]));
}
}
if ($event instanceof AuthorSetEvent) public function onAuthorSet(AuthorSetEvent $event) {
$this->update_author($event); $this->update_author($event);
}
if($event instanceof InitExtEvent) public function onInitExt(InitExtEvent $event) {
$this->try_install(); $this->try_install();
}
if ($event instanceof ImageInfoBoxBuildingEvent) public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
$this->add_author_field_to_image($event); $this->add_author_field_to_image($event);
}
if ($event instanceof PageRequestEvent) public function onPageRequest(PageRequestEvent $event) {
$this->handle_commands($event); $this->handle_commands($event);
}
if ($event instanceof SearchTermParseEvent) { public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array(); $matches = array();
if(preg_match("/^author=(.*)$/", $event->term, $matches)) { if(preg_match("/^author=(.*)$/", $event->term, $matches)) {
$char = $matches[1]; $char = $matches[1];
$event->add_querylet(new Querylet("Author = :author_char", array("author_char"=>$char))); $event->add_querylet(new Querylet("Author = :author_char", array("author_char"=>$char)));
} }
} }
}
public function try_install() { public function try_install() {
global $config, $database; global $config, $database;

View File

@ -5,15 +5,9 @@
* Description: Handle SVG files * Description: Handle SVG files
*/ */
class SVGFileHandler implements Extension { class SVGFileHandler extends SimpleExtension {
var $theme; public function onDataUpload(DataUploadEvent $event) {
if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
public function get_priority() {return 50;}
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; $hash = $event->hash;
$ha = substr($hash, 0, 2); $ha = substr($hash, 0, 2);
if(!move_upload_to_archive($event)) return; if(!move_upload_to_archive($event)) return;
@ -26,33 +20,28 @@ class SVGFileHandler implements Extension {
send_event($iae); send_event($iae);
$event->image_id = $iae->image->id; $event->image_id = $iae->image->id;
} }
}
if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) { public function onThumbnailGeneration(ThumbnailGenerationEvent $event) {
global $config;
if($this->supported_ext($event->type)) {
$hash = $event->hash; $hash = $event->hash;
$ha = substr($hash, 0, 2); $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)); copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash));
// } }
} }
if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) { public function onDisplayingImage(DisplayingImageEvent $event) {
global $page; global $page;
if($this->supported_ext($event->image->ext)) {
$this->theme->display_image($page, $event->image); $this->theme->display_image($page, $event->image);
} }
}
if(($event instanceof PageRequestEvent) && $event->page_matches("get_svg")) { public function onPageRequest(PageRequestEvent $event) {
global $config, $database, $page; global $config, $database, $page;
if($event->page_matches("get_svg")) {
$id = int_escape($event->get_arg(0)); $id = int_escape($event->get_arg(0));
$image = Image::by_id($id); $image = Image::by_id($id);
$hash = $image->hash; $hash = $image->hash;

View File

@ -17,20 +17,13 @@ class RatingSetEvent extends Event {
} }
} }
class Ratings implements Extension { class Ratings extends SimpleExtension {
var $theme; public function onAdminBuilding(AdminBuildingEvent $event) {
public function get_priority() {return 50;}
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof AdminBuildingEvent) {
$this->theme->display_bulk_rater(); $this->theme->display_bulk_rater();
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("admin/bulk_rate")) { public function onPageRequest(PageRequestEvent $event) {
if($event->page_matches("admin/bulk_rate")) {
global $database, $user, $page; global $database, $user, $page;
if(!$user->is_admin()) { if(!$user->is_admin()) {
throw PermissionDeniedException(); throw PermissionDeniedException();
@ -54,8 +47,11 @@ class Ratings implements Extension {
$page->set_redirect(make_link("admin")); $page->set_redirect(make_link("admin"));
} }
} }
}
public function onInitExt(InitExtEvent $event) {
global $config;
if($event instanceof InitExtEvent) {
if($config->get_int("ext_ratings2_version") < 2) { if($config->get_int("ext_ratings2_version") < 2) {
$this->install(); $this->install();
} }
@ -65,7 +61,7 @@ class Ratings implements Extension {
$config->set_default_string("ext_rating_admin_privs", 'sqeu'); $config->set_default_string("ext_rating_admin_privs", 'sqeu');
} }
if($event instanceof RatingSetEvent) { public function onRatingSet(RatingSetEvent $event) {
if(empty($event->image->rating)){ if(empty($event->image->rating)){
$old_rating = ""; $old_rating = "";
}else{ }else{
@ -74,19 +70,20 @@ class Ratings implements Extension {
$this->set_rating($event->image->id, $event->rating, $old_rating); $this->set_rating($event->image->id, $event->rating, $old_rating);
} }
if($event instanceof ImageInfoBoxBuildingEvent) { public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
if($this->can_rate()) { if($this->can_rate()) {
$event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80); $event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80);
} }
} }
if($event instanceof ImageInfoSetEvent) { public function onImageInfoSet(ImageInfoSetEvent $event) {
global $user;
if($this->can_rate() && isset($_POST["rating"])) { if($this->can_rate() && isset($_POST["rating"])) {
send_event(new RatingSetEvent($event->image, $user, $_POST['rating'])); send_event(new RatingSetEvent($event->image, $user, $_POST['rating']));
} }
} }
if($event instanceof SetupBuildingEvent) { public function onSetupBuilding(SetupBuildingEvent $event) {
$privs = array(); $privs = array();
$privs['Safe Only'] = 's'; $privs['Safe Only'] = 's';
$privs['Safe and Unknown'] = 'su'; $privs['Safe and Unknown'] = 'su';
@ -101,11 +98,11 @@ class Ratings implements Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
if($event instanceof ParseLinkTemplateEvent) { public function onParseLinkTemplate(ParseLinkTemplateEvent $event) {
$event->replace('$rating', $this->theme->rating_to_name($event->image->rating)); $event->replace('$rating', $this->theme->rating_to_name($event->image->rating));
} }
if($event instanceof SearchTermParseEvent) { public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array(); $matches = array();
if(is_null($event->term) && $this->no_rating_query($event->context)) { if(is_null($event->term) && $this->no_rating_query($event->context)) {
$set = Ratings::privs_to_sql(Ratings::get_user_privs($user)); $set = Ratings::privs_to_sql(Ratings::get_user_privs($user));
@ -128,11 +125,11 @@ class Ratings implements Extension {
} }
} }
if($event instanceof DisplayingImageEvent) { public function onDisplayingImage(DisplayingImageEvent $event) {
/** /**
* Deny images upon insufficient permissions. * Deny images upon insufficient permissions.
**/ **/
global $user, $database, $page; global $user, $page;
$user_view_level = Ratings::get_user_privs($user); $user_view_level = Ratings::get_user_privs($user);
$user_view_level = preg_split('//', $user_view_level, -1); $user_view_level = preg_split('//', $user_view_level, -1);
if(!in_array($event->image->rating, $user_view_level)) { if(!in_array($event->image->rating, $user_view_level)) {
@ -140,9 +137,8 @@ class Ratings implements Extension {
$page->set_redirect(make_link("post/list")); $page->set_redirect(make_link("post/list"));
} }
} }
}
public static function get_user_privs($user) { public static function get_user_privs(User $user) {
global $config; global $config;
if($user->is_anonymous()) { if($user->is_anonymous()) {
$sqes = $config->get_string("ext_rating_anon_privs"); $sqes = $config->get_string("ext_rating_anon_privs");

View File

@ -12,16 +12,10 @@
* colorize used tags in cloud || always show used tags in front of cloud * colorize used tags in cloud || always show used tags in front of cloud
* theme junk * theme junk
*/ */
class TagEditCloud implements Extension { class TagEditCloud extends SimpleExtension {
var $theme; public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
global $config;
public function get_priority() {return 50;}
public function receive_event(Event $event) {
global $config, $database, $page, $user;
//if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof ImageInfoBoxBuildingEvent) {
if(!$config->get_bool("tageditcloud_disable")) { if(!$config->get_bool("tageditcloud_disable")) {
if($this->can_tag($event->image)) { if($this->can_tag($event->image)) {
if(!$cfg_minusage=$config->get_int("tageditcloud_minusage")) $cfg_minusage=2; if(!$cfg_minusage=$config->get_int("tageditcloud_minusage")) $cfg_minusage=2;
@ -36,7 +30,8 @@ class TagEditCloud implements Extension {
} }
} }
if($event instanceof InitExtEvent) { public function onInitExt(InitExtEvent $event) {
global $config;
$config->set_default_bool("tageditcloud_disable",false); $config->set_default_bool("tageditcloud_disable",false);
$config->set_default_bool("tageditcloud_usedfirst",true); $config->set_default_bool("tageditcloud_usedfirst",true);
$config->set_default_string("tageditcloud_sort",'a'); $config->set_default_string("tageditcloud_sort",'a');
@ -45,7 +40,7 @@ class TagEditCloud implements Extension {
$config->set_default_int("tageditcloud_maxcount",4096); $config->set_default_int("tageditcloud_maxcount",4096);
} }
if($event instanceof SetupBuildingEvent) { public function onSetupBuilding(SetupBuildingEvent $event) {
$sort_by = array('Alphabetical'=>'a','Popularity'=>'p'); $sort_by = array('Alphabetical'=>'a','Popularity'=>'p');
$sb = new SetupBlock("Tag Edit Cloud"); $sb = new SetupBlock("Tag Edit Cloud");
@ -62,7 +57,6 @@ class TagEditCloud implements Extension {
$event->panel->add_block($sb); $event->panel->add_block($sb);
} }
}
private function tag_link($tag) { private function tag_link($tag) {
$u_tag = url_escape($tag); $u_tag = url_escape($tag);