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 {
var $theme;
public function get_priority() {return 50;}
public function receive_event(Event $event)
{
class Artists extends SimpleExtension {
public function onImageInfoSet(ImageInfoSetEvent $event) {
global $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if ($event instanceof ImageInfoSetEvent)
if (isset($_POST["tag_edit__author"]))
if (isset($_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);
}
if($event instanceof InitExtEvent)
public function onInitExt(InitExtEvent $event) {
$this->try_install();
}
if ($event instanceof ImageInfoBoxBuildingEvent)
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
$this->add_author_field_to_image($event);
}
if ($event instanceof PageRequestEvent)
public function onPageRequest(PageRequestEvent $event) {
$this->handle_commands($event);
}
if ($event instanceof SearchTermParseEvent) {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
if(preg_match("/^author=(.*)$/", $event->term, $matches)) {
$char = $matches[1];
$event->add_querylet(new Querylet("Author = :author_char", array("author_char"=>$char)));
}
}
}
public function try_install() {
global $config, $database;

View File

@ -5,15 +5,9 @@
* Description: Handle SVG files
*/
class SVGFileHandler implements Extension {
var $theme;
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)) {
class SVGFileHandler extends SimpleExtension {
public function onDataUpload(DataUploadEvent $event) {
if($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;
@ -26,33 +20,28 @@ class SVGFileHandler implements Extension {
send_event($iae);
$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;
$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)) {
public function onDisplayingImage(DisplayingImageEvent $event) {
global $page;
if($this->supported_ext($event->image->ext)) {
$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;
if($event->page_matches("get_svg")) {
$id = int_escape($event->get_arg(0));
$image = Image::by_id($id);
$hash = $image->hash;

View File

@ -17,20 +17,13 @@ class RatingSetEvent extends Event {
}
}
class Ratings implements Extension {
var $theme;
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) {
class Ratings extends SimpleExtension {
public function onAdminBuilding(AdminBuildingEvent $event) {
$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;
if(!$user->is_admin()) {
throw PermissionDeniedException();
@ -54,8 +47,11 @@ class Ratings implements Extension {
$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) {
$this->install();
}
@ -65,7 +61,7 @@ class Ratings implements Extension {
$config->set_default_string("ext_rating_admin_privs", 'sqeu');
}
if($event instanceof RatingSetEvent) {
public function onRatingSet(RatingSetEvent $event) {
if(empty($event->image->rating)){
$old_rating = "";
}else{
@ -74,19 +70,20 @@ class Ratings implements Extension {
$this->set_rating($event->image->id, $event->rating, $old_rating);
}
if($event instanceof ImageInfoBoxBuildingEvent) {
public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) {
if($this->can_rate()) {
$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"])) {
send_event(new RatingSetEvent($event->image, $user, $_POST['rating']));
}
}
if($event instanceof SetupBuildingEvent) {
public function onSetupBuilding(SetupBuildingEvent $event) {
$privs = array();
$privs['Safe Only'] = 's';
$privs['Safe and Unknown'] = 'su';
@ -101,11 +98,11 @@ class Ratings implements Extension {
$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));
}
if($event instanceof SearchTermParseEvent) {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
if(is_null($event->term) && $this->no_rating_query($event->context)) {
$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.
**/
global $user, $database, $page;
global $user, $page;
$user_view_level = Ratings::get_user_privs($user);
$user_view_level = preg_split('//', $user_view_level, -1);
if(!in_array($event->image->rating, $user_view_level)) {
@ -140,9 +137,8 @@ class Ratings implements Extension {
$page->set_redirect(make_link("post/list"));
}
}
}
public static function get_user_privs($user) {
public static function get_user_privs(User $user) {
global $config;
if($user->is_anonymous()) {
$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
* theme junk
*/
class TagEditCloud implements Extension {
var $theme;
class TagEditCloud extends SimpleExtension {
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($this->can_tag($event->image)) {
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_usedfirst",true);
$config->set_default_string("tageditcloud_sort",'a');
@ -45,7 +40,7 @@ class TagEditCloud implements Extension {
$config->set_default_int("tageditcloud_maxcount",4096);
}
if($event instanceof SetupBuildingEvent) {
public function onSetupBuilding(SetupBuildingEvent $event) {
$sort_by = array('Alphabetical'=>'a','Popularity'=>'p');
$sb = new SetupBlock("Tag Edit Cloud");
@ -62,7 +57,6 @@ class TagEditCloud implements Extension {
$event->panel->add_block($sb);
}
}
private function tag_link($tag) {
$u_tag = url_escape($tag);