featured image for 2.2

git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.2@862 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-05-19 02:21:47 +00:00
parent aaa8ccf874
commit 482312b11e
4 changed files with 87 additions and 3 deletions

56
contrib/featured/main.php Normal file
View File

@ -0,0 +1,56 @@
<?php
/**
* Name: Featured Image
* Author: Shish <webmaster@shishnet.org>
* License: GPLv2
* Description: Bring a specific image to the users' attentions
*/
class Featured extends Extension {
var $theme;
public function receive_event($event) {
if(is_null($this->theme)) $this->theme = get_theme_object("featured", "FeaturedTheme");
if(is_a($event, 'InitExtEvent')) {
global $config;
$config->set_default_int('featured_id', 0);
}
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "set_feature")) {
global $user;
if($user->is_admin() && isset($_POST['image_id'])) {
global $config;
$id = int_escape($_POST['image_id']);
if($id > 0) {
$config->set_int("featured_id", $id);
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/$id"));
}
}
}
if(is_a($event, 'PostListBuildingEvent')) {
global $config, $database;
$fid = $config->get_int("featured_id");
if($fid > 0) {
$this->theme->display_featured($event->page, $database->get_image($fid));
}
}
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("Featured Image");
$sb->add_int_option("featured_id", "Image ID: ");
$event->panel->add_block($sb);
}
if(is_a($event, 'DisplayingImageEvent')) {
global $user;
if($user->is_admin()) {
$this->theme->display_buttons($event->page, $event->image->id);
}
}
}
}
add_event_listener(new Featured());
?>

View File

@ -0,0 +1,21 @@
<?php
class FeaturedTheme extends Themelet {
/*
* Show $text on the $page
*/
public function display_featured($page, $image) {
$page->add_block(new Block("Featured Image", $this->build_thumb_html($image), "left", 3));
}
public function display_buttons($page, $image_id) {
$html = "
<form action='".make_link("set_feature")."' method='POST'>
<input type='hidden' name='image_id' value='$image_id'>
<input type='submit' value='Featue This'>
</form>
";
$page->add_block(new Block("Featured Image", $html, "left"));
}
}
?>

View File

@ -18,7 +18,8 @@ class BBCode extends Extension {
$text = preg_replace("/&gt;&gt;([^\d].+)/", "<blockquote><small>\\1</small></blockquote>", $text);
$text = preg_replace("/\[url=((?:https?|ftp|irc):\/\/.*?)\](.*?)\[\/url\]/s", "<a href='\\1'>\\2</a>", $text);
$text = preg_replace("/\[url\]((?:https?|ftp|irc):\/\/.*?)\[\/url\]/s", "<a href='\\1'>\\1</a>", $text);
$text = preg_replace("/\[\[(.*?)\]\]/s", "<a href='".make_link("wiki/\\1")."'>\\1</a>", $text);
$text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "<a href='".make_link("wiki/\\1")."'>\\2</a>", $text);
$text = preg_replace("/\[\[([^\]]+)\]\]/s", "<a href='".make_link("wiki/\\1")."'>\\1</a>", $text);
$text = str_replace("\n", "\n<br>", $text);
$text = preg_replace("/\[quote\](.*?)\[\/quote\]/s", "<blockquote><small>\\1</small></blockquote>", $text);
$text = preg_replace("/\[quote=(.*?)\](.*?)\[\/quote\]/s", "<small><small>Quoting \\1</small></small><blockquote><small>\\2</small></blockquote>", $text);
@ -44,7 +45,8 @@ class BBCode extends Extension {
$text = preg_replace("/\[code\](.*?)\[\/code\]/s", "\\1", $text);
$text = preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/s", "\\2", $text);
$text = preg_replace("/\[url\](.*?)\[\/url\]/s", "\\1", $text);
$text = preg_replace("/\[\[(.*?)\]\]/s", "\\1", $text);
$text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "\\2", $text);
$text = preg_replace("/\[\[([^\]]+)\]\]/s", "\\1", $text);
$text = preg_replace("/\[quote\](.*?)\[\/quote\]/s", "", $text);
$text = preg_replace("/\[quote=(.*?)\](.*?)\[\/quote\]/s", "", $text);
$text = preg_replace("/\[h1\](.*?)\[\/h1\]/s", "\\1", $text);

View File

@ -84,7 +84,12 @@ class CommentList extends Extension {
if($event->count_args() == 3) {
send_event(new CommentDeletionEvent($event->get_arg(1)));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/".$event->get_arg(2)));
if(!empty($_SERVER['HTTP_REFERER'])) {
$event->page->set_redirect($_SERVER['HTTP_REFERER']);
}
else {
$event->page->set_redirect(make_link("post/view/".$event->get_arg(2)));
}
}
}
else {