From ac2af2d1c0536ff54fe2c999c4e026fdab5d85e1 Mon Sep 17 00:00:00 2001 From: shish Date: Sun, 4 Nov 2007 08:16:41 +0000 Subject: [PATCH] ParseLinkTemplateEvent, and handlers for text_score, numeric_score and rating git-svn-id: file:///home/shish/svn/shimmie2/trunk@611 7f39781d-f577-437e-ae19-be835c7a54ca --- contrib/numeric_score/main.php | 4 ++++ contrib/rating/main.php | 4 ++++ contrib/rating/theme.php | 9 +++++++++ contrib/text_score/main.php | 4 ++++ contrib/text_score/theme.php | 19 ++++++++++++------- core/events/parselinktemplate.event.php | 17 +++++++++++++++++ core/image.class.php | 4 ++++ 7 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 core/events/parselinktemplate.event.php diff --git a/contrib/numeric_score/main.php b/contrib/numeric_score/main.php index daf13a72..f50587d3 100644 --- a/contrib/numeric_score/main.php +++ b/contrib/numeric_score/main.php @@ -69,6 +69,10 @@ class NumericScore extends Extension { $sb->add_bool_option("numeric_score_anon", "Allow anonymous votes: "); $event->panel->add_block($sb); } + + if(is_a($event, 'ParseLinkTemplateEvent')) { + $event->replace('$score', $event->image->numeric_score); + } } private function install() { diff --git a/contrib/rating/main.php b/contrib/rating/main.php index bd617efc..2b9048e4 100644 --- a/contrib/rating/main.php +++ b/contrib/rating/main.php @@ -67,6 +67,10 @@ class Ratings extends Extension { $sb->add_choice_option("ext_rating_user_privs", $privs, "
Logged in: "); $event->panel->add_block($sb); } + + if(is_a($event, 'ParseLinkTemplateEvent')) { + $event->replace('$rating', $this->theme->rating_to_name($event->image->rating)); + } } private function install() { diff --git a/contrib/rating/theme.php b/contrib/rating/theme.php index 67b1863b..55ca5758 100644 --- a/contrib/rating/theme.php +++ b/contrib/rating/theme.php @@ -17,6 +17,15 @@ class RatingsTheme extends Themelet { "; $page->add_block(new Block(null, $html, "main", 7)); } + + public function rating_to_name($rating) { + switch($rating) { + case 's': return "Safe"; + case 'q': return "Questionable"; + case 'e': return "Explicit"; + default: return "Unknown"; + } + } } ?> diff --git a/contrib/text_score/main.php b/contrib/text_score/main.php index f755bf22..77c05d60 100644 --- a/contrib/text_score/main.php +++ b/contrib/text_score/main.php @@ -69,6 +69,10 @@ class TextScore extends Extension { $sb->add_bool_option("text_score_anon", "Allow anonymous votes: "); $event->panel->add_block($sb); } + + if(is_a($event, 'ParseLinkTemplateEvent')) { + $event->replace('$text_score', $this->theme->score_to_name($event->image->text_score)); + } } private function install() { diff --git a/contrib/text_score/theme.php b/contrib/text_score/theme.php index c9046e43..30e5b70c 100644 --- a/contrib/text_score/theme.php +++ b/contrib/text_score/theme.php @@ -4,13 +4,7 @@ class TextScoreTheme extends Themelet { public function display_scorer($page, $image_id, $score) { $i_image_id = int_escape($image_id); - $words = array(); - $words[-2] = "Delete"; - $words[-1] = "Bad"; - $words[ 0] = "Ok"; - $words[ 1] = "Good"; - $words[ 2] = "Favourite"; - $s_score = $words[$score]; + $s_score = $this->score_to_name($score); $html = " Current score is \"$s_score\"
@@ -25,6 +19,17 @@ class TextScoreTheme extends Themelet { "; $page->add_block(new Block(null, $html, "main", 7)); } + + public function score_to_name($score) { + $words = array(); + $words[-2] = "Delete"; + $words[-1] = "Bad"; + $words[ 0] = "Ok"; + $words[ 1] = "Good"; + $words[ 2] = "Favourite"; + $s_score = $words[$score]; + return $s_score; + } } ?> diff --git a/core/events/parselinktemplate.event.php b/core/events/parselinktemplate.event.php new file mode 100644 index 00000000..7dcb2093 --- /dev/null +++ b/core/events/parselinktemplate.event.php @@ -0,0 +1,17 @@ +link = $link; + $this->original = $link; + $this->image = $image; + } + + public function replace($needle, $replace) { + $this->link = str_replace($needle, $replace, $this->link); + } +} +?> diff --git a/core/image.class.php b/core/image.class.php index bb168633..f1dc9f28 100644 --- a/core/image.class.php +++ b/core/image.class.php @@ -155,6 +155,10 @@ class Image { $tmpl = str_replace('$filename', $_escape($base_fname), $tmpl); $tmpl = str_replace('$title', $_escape($config->get_string("title")), $tmpl); + $plte = new ParseLinkTemplateEvent($tmpl, $this); + send_event($plte); + $tmpl = $plte->link; + return $tmpl; } }