view and download featured

This commit is contained in:
Shish 2010-01-02 10:16:49 +00:00
parent ec0d732a26
commit 73abe594d1
2 changed files with 31 additions and 8 deletions

View File

@ -9,6 +9,13 @@
* to the other image control buttons (delete, rotate, etc). * to the other image control buttons (delete, rotate, etc).
* Clicking it will set the image as the site's current feature, * Clicking it will set the image as the site's current feature,
* which will be shown in the side bar of the post list. * which will be shown in the side bar of the post list.
* <p><b>Viewing a featured image</b>
* <br>Visit <code>/featured_image/view</code>
* <p><b>Downloading a featured image</b>
* <br>Link to <code>/featured_image/download</code>. This will give
* the raw data for an image (no HTML). This is useful so that you
* can set your desktop wallpaper to be the download URL, refreshed
* every couple of hours.
*/ */
class Featured extends SimpleExtension { class Featured extends SimpleExtension {
@ -19,13 +26,29 @@ class Featured extends SimpleExtension {
public function onPageRequest($event) { public function onPageRequest($event) {
global $config, $page, $user; global $config, $page, $user;
if($event->page_matches("set_feature")) { if($event->page_matches("featured_image")) {
if($user->is_admin() && isset($_POST['image_id'])) { if($event->get_arg(0) == "set") {
$id = int_escape($_POST['image_id']); if($user->is_admin() && isset($_POST['image_id'])) {
if($id > 0) { $id = int_escape($_POST['image_id']);
$config->set_int("featured_id", $id); if($id > 0) {
$page->set_mode("redirect"); $config->set_int("featured_id", $id);
$page->set_redirect(make_link("post/view/$id")); $page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$id"));
}
}
}
if($event->get_arg(0) == "download") {
$image = Image::by_id($config->get_int("featured_id"));
if(!is_null($image)) {
$page->set_mode("data");
$page->set_type("image/jpeg");
$page->set_data(file_get_contents($image->get_image_filename()));
}
}
if($event->get_arg(0) == "view") {
$image = Image::by_id($config->get_int("featured_id"));
if(!is_null($image)) {
send_event(new DisplayingImageEvent($image, $page));
} }
} }
} }

View File

@ -10,7 +10,7 @@ class FeaturedTheme extends Themelet {
public function get_buttons_html($image_id) { public function get_buttons_html($image_id) {
return " return "
<form action='".make_link("set_feature")."' method='POST'> <form action='".make_link("featured_image/set")."' method='POST'>
<input type='hidden' name='image_id' value='$image_id'> <input type='hidden' name='image_id' value='$image_id'>
<input type='submit' value='Feature This'> <input type='submit' value='Feature This'>
</form> </form>