featured image extension
git-svn-id: file:///home/shish/svn/shimmie2/trunk@861 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
3c0d687bf6
commit
1fba968ffe
56
contrib/featured/main.php
Normal file
56
contrib/featured/main.php
Normal 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());
|
||||
?>
|
21
contrib/featured/theme.php
Normal file
21
contrib/featured/theme.php
Normal 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"));
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user