Merge pull request #99 from DakuTree/master
Auto resize on upload + Popular by Day/Month/Year
This commit is contained in:
commit
38aa55dafd
13 changed files with 178 additions and 31 deletions
|
@ -35,14 +35,15 @@ class AdminPageTheme extends Themelet {
|
|||
|
||||
/* First check
|
||||
Requires you to click the checkbox to enable the delete by query form */
|
||||
$dbqcheck = "
|
||||
if(document.getElementById("dbqcheck").checked == false){
|
||||
document.getElementById("dbqtags").disabled = true;
|
||||
document.getElementById("dbqsubmit").disabled = true;
|
||||
$dbqcheck = 'javascript:$(function() {
|
||||
if($("#dbqcheck:checked").length != 0){
|
||||
$("#dbqtags").attr("disabled", false);
|
||||
$("#dbqsubmit").attr("disabled", false);
|
||||
}else{
|
||||
document.getElementById("dbqtags").disabled = false;
|
||||
document.getElementById("dbqsubmit").disabled = false;
|
||||
}";
|
||||
$("#dbqtags").attr("disabled", true);
|
||||
$("#dbqsubmit").attr("disabled", true);
|
||||
}
|
||||
});';
|
||||
|
||||
/* Second check
|
||||
Requires you to confirm the deletion by clicking ok. */
|
||||
|
@ -52,7 +53,7 @@ class AdminPageTheme extends Themelet {
|
|||
if(confirm('Are you sure you wish to delete all images using these tags?')){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>"
|
||||
|
|
|
@ -104,6 +104,75 @@ class NumericScore implements Extension {
|
|||
$page->set_redirect(make_link());
|
||||
}
|
||||
}
|
||||
if($event->page_matches("popular_by_day") || $event->page_matches("popular_by_month") || $event->page_matches("popular_by_year")) {
|
||||
$t_images = $config->get_int("index_height") * $config->get_int("index_width");
|
||||
|
||||
//TODO: Somehow make popular_by_#/2012/12/31 > popular_by_#?day=31&month=12&year=2012 (So no problems with date formats)
|
||||
//TODO: Add Popular_by_week.
|
||||
|
||||
$sql =
|
||||
"SELECT *
|
||||
FROM images
|
||||
";
|
||||
|
||||
//year
|
||||
if(int_escape($event->get_arg(0)) == 0){
|
||||
$year = date("Y");
|
||||
}else{
|
||||
$year = $event->get_arg(0);
|
||||
}
|
||||
//month
|
||||
if(int_escape($event->get_arg(1)) == 0 || int_escape($event->get_arg(1)) > 12){
|
||||
$month = date("m");
|
||||
}else{
|
||||
$month = $event->get_arg(1);
|
||||
}
|
||||
//day
|
||||
if(int_escape($event->get_arg(2)) == 0 || int_escape($event->get_arg(2)) > 31){
|
||||
$day = date("d");
|
||||
}else{
|
||||
$day = $event->get_arg(2);
|
||||
}
|
||||
$totaldate = $year."/".$month."/".$day;
|
||||
|
||||
if($event->page_matches("popular_by_day")){
|
||||
$sql .=
|
||||
"WHERE YEAR(posted) =".$year."
|
||||
AND MONTH(posted) =".$month."
|
||||
AND DAY(posted) =".$day."
|
||||
AND NOT numeric_score=0
|
||||
";
|
||||
$dte = array($totaldate, date("F jS, Y", (strtotime($totaldate))), "Y/m/d", "day");
|
||||
}
|
||||
if($event->page_matches("popular_by_month")){
|
||||
$sql .=
|
||||
"WHERE YEAR(posted) =".$year."
|
||||
AND MONTH(posted) =".$month."
|
||||
AND NOT numeric_score=0
|
||||
";
|
||||
$title = date("F Y", (strtotime($totaldate)));
|
||||
$dte = array($totaldate, $title, "Y/m", "month");
|
||||
}
|
||||
if($event->page_matches("popular_by_year")){
|
||||
$sql .=
|
||||
"WHERE YEAR(posted) =".$year."
|
||||
AND NOT numeric_score=0
|
||||
";
|
||||
$dte = array($totaldate, $year, "Y", "year");
|
||||
}
|
||||
$sql .=
|
||||
"ORDER BY numeric_score DESC
|
||||
LIMIT 0 , ".$t_images;
|
||||
|
||||
//filter images by year/score != 0 > limit to max images on one page > order from highest to lowest score
|
||||
$result = $database->get_all($sql);
|
||||
|
||||
$images = array();
|
||||
foreach($result as $singleResult) {
|
||||
$images[] = Image::by_id($singleResult["id"]);
|
||||
}
|
||||
$this->theme->view_popular($images, $dte);
|
||||
}
|
||||
}
|
||||
|
||||
if($event instanceof NumericScoreSetEvent) {
|
||||
|
|
|
@ -55,6 +55,32 @@ class NumericScoreTheme extends Themelet {
|
|||
";
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function view_popular($images, $dte) {
|
||||
global $user, $page;
|
||||
|
||||
$pop_images = '';
|
||||
foreach($images as $image) {
|
||||
$thumb_html = $this->build_thumb_html($image);
|
||||
$pop_images .= '<span class="thumb">'.
|
||||
'<a href="$image_link">'.$thumb_html.'</a>'.
|
||||
'</span>';
|
||||
}
|
||||
|
||||
$b_dte = make_link("popular_by_".$dte[3]."/".date($dte[2], (strtotime('-1 '.$dte[3], strtotime($dte[0])))));
|
||||
$f_dte = make_link("popular_by_".$dte[3]."/".date($dte[2], (strtotime('+1 '.$dte[3], strtotime($dte[0])))));
|
||||
|
||||
$html = '<center><h3><a href="'.$b_dte.'">«</a> '.$dte[1]
|
||||
.' <a href="'.$f_dte.'">»</a>'
|
||||
.'</h3></center>
|
||||
<br>'.$pop_images;
|
||||
|
||||
|
||||
$nav_html = "<a href=".make_link().">Index</a>";
|
||||
|
||||
$page->add_block(new Block("Navigation", $nav_html, "left", 10));
|
||||
$page->add_block(new Block(null, $html, "main", 30));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -550,12 +550,12 @@ class Pools extends SimpleExtension {
|
|||
private function nuke_pool($poolID) {
|
||||
global $user, $database;
|
||||
|
||||
$p_id = $database->get_one("SELECT user_id FROM pools WHERE id = :pid", array("pid"=>$poolID));
|
||||
if($user->is_admin()) {
|
||||
$database->execute("DELETE FROM pool_history WHERE pool_id = :pid", array("pid"=>$poolID));
|
||||
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid", array("pid"=>$poolID));
|
||||
$database->execute("DELETE FROM pools WHERE id = :pid", array("pid"=>$poolID));
|
||||
} elseif(!$user->is_anonymous()) {
|
||||
// FIXME: WE CHECK IF THE USER IS THE OWNER OF THE POOL IF NOT HE CAN'T DO ANYTHING
|
||||
} elseif($user->id == $p_id) {
|
||||
$database->execute("DELETE FROM pool_history WHERE pool_id = :pid", array("pid"=>$poolID));
|
||||
$database->execute("DELETE FROM pool_images WHERE pool_id = :pid", array("pid"=>$poolID));
|
||||
$database->execute("DELETE FROM pools WHERE id = :pid AND user_id = :uid", array("pid"=>$poolID, "uid"=>$user->id));
|
||||
|
|
|
@ -64,7 +64,12 @@ class Ratings implements Extension {
|
|||
}
|
||||
|
||||
if($event instanceof RatingSetEvent) {
|
||||
$this->set_rating($event->image->id, $event->rating, $event->image->rating);
|
||||
if(empty($event->image->rating)){
|
||||
$old_rating = "";
|
||||
}else{
|
||||
$old_rating = $event->image->rating;
|
||||
}
|
||||
$this->set_rating($event->image->id, $event->rating, $old_rating);
|
||||
}
|
||||
|
||||
if($event instanceof ImageInfoBoxBuildingEvent) {
|
||||
|
@ -209,7 +214,7 @@ class Ratings implements Extension {
|
|||
global $database;
|
||||
if($old_rating != $rating){
|
||||
$database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id));
|
||||
log_info("core-image", "Rating for Image #{$image_id} set to: ".$this->theme->rating_to_name($rating));
|
||||
log_info("rating", "Rating for Image #{$image_id} set to: ".$this->theme->rating_to_name($rating));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ class ResizeImage extends SimpleExtension {
|
|||
public function onInitExt($event) {
|
||||
global $config;
|
||||
$config->set_default_bool('resize_enabled', true);
|
||||
$config->set_default_bool('resize_upload', false);
|
||||
$config->set_default_int('resize_default_width', 0);
|
||||
$config->set_default_int('resize_default_height', 0);
|
||||
}
|
||||
|
@ -46,6 +47,7 @@ class ResizeImage extends SimpleExtension {
|
|||
public function onSetupBuilding($event) {
|
||||
$sb = new SetupBlock("Image Resize");
|
||||
$sb->add_bool_option("resize_enabled", "Allow resizing images: ");
|
||||
$sb->add_bool_option("resize_upload", "<br>Resize on upload: ");
|
||||
$sb->add_label("<br>Preset/Default Width: ");
|
||||
$sb->add_int_option("resize_default_width");
|
||||
$sb->add_label(" px");
|
||||
|
@ -56,6 +58,37 @@ class ResizeImage extends SimpleExtension {
|
|||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
public function onDataUpload(DataUploadEvent $event) {
|
||||
global $config;
|
||||
$image_obj = Image::by_id($event->image_id);
|
||||
//No auto resizing for gifs due to animated gif causing errors :(
|
||||
//Also PNG resizing seems to be completely broken.
|
||||
if($config->get_bool("resize_upload") == true && ($image_obj->ext == "jpg")){
|
||||
$width = $height = 0;
|
||||
|
||||
if ($config->get_int("resize_default_width") !== 0) {
|
||||
$height = $config->get_int("resize_default_width");
|
||||
}
|
||||
if ($config->get_int("resize_default_height") !== 0) {
|
||||
$height = $config->get_int("resize_default_height");
|
||||
}
|
||||
|
||||
try {
|
||||
$this->resize_image($event->image_id, $width, $height);
|
||||
} catch (ImageResizeException $e) {
|
||||
$this->theme->display_resize_error($page, "Error Resizing", $e->error);
|
||||
}
|
||||
|
||||
//Need to generate thumbnail again...
|
||||
//This only seems to be an issue if one of the sizes was set to 0.
|
||||
$image_obj = Image::by_id($event->image_id); //Must be a better way to grab the new hash than setting this again..
|
||||
send_event(new ThumbnailGenerationEvent($image_obj->hash, $image_obj->ext, true));
|
||||
|
||||
log_info("core-image", "Image #{$event->image_id} has been resized to: ".$width."x".$height);
|
||||
//TODO: Notify user that image has been resized.
|
||||
}
|
||||
}
|
||||
|
||||
public function onPageRequest($event) {
|
||||
global $page, $user;
|
||||
|
||||
|
@ -167,7 +200,8 @@ class ResizeImage extends SimpleExtension {
|
|||
switch ( $info[2] ) {
|
||||
case IMAGETYPE_GIF: $image = imagecreatefromgif($image_filename); break;
|
||||
case IMAGETYPE_JPEG: $image = imagecreatefromjpeg($image_filename); break;
|
||||
case IMAGETYPE_PNG: $image = imagecreatefrompng($image_filename); break;
|
||||
/* FIXME: PNG support seems to be broken.
|
||||
case IMAGETYPE_PNG: $image = imagecreatefrompng($image_filename); break;*/
|
||||
default:
|
||||
throw new ImageResizeException("Unsupported image type.");
|
||||
}
|
||||
|
|
|
@ -348,6 +348,7 @@ class ImageIO extends SimpleExtension {
|
|||
$tags_to_set = $image->get_tag_array();
|
||||
$image->tag_array = array();
|
||||
send_event(new TagSetEvent($image, $tags_to_set));
|
||||
log_info("core-image", "Source for Image #{$image->id} set to: {$image->source}");
|
||||
}
|
||||
// }}} end add
|
||||
|
||||
|
|
16
lib/jquery-1.5.1.min.js
vendored
16
lib/jquery-1.5.1.min.js
vendored
File diff suppressed because one or more lines are too long
2
lib/jquery-1.7.1.min.js
vendored
Normal file
2
lib/jquery-1.7.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -140,9 +140,12 @@ class Layout {
|
|||
# be nice to be correct
|
||||
case "post":
|
||||
case "upload":
|
||||
if(file_exists("ext/numeric_score")){ $custom_sublinks .= "<li><b>Popular by </b><a href='".make_link('popular_by_day')."'>Day</a>/<a href='".make_link('popular_by_month')."'>Month</a>/<a href='".make_link('popular_by_year')."'>Year</a></li>";}
|
||||
$custom_sublinks .= "<li><a href='".make_link('post/list')."'>All</a></li>";
|
||||
$custom_sublinks .= "<li><a href='".make_link("post/list/favorited_by=$username/1")."'>My Favorites</a></li>";
|
||||
$custom_sublinks .= "<li><a href='".make_link("ext_doc/index")."'>Help</a></li>";
|
||||
if(file_exists("ext/random_image")){ $custom_sublinks .= "<li><a href='".make_link("random_image/view")."'>Random Image</a></li>";}
|
||||
if($hw){ $custom_sublinks .= "<li><a href='".make_link("wiki/posts")."'>Help</a></li>";
|
||||
}else{ $custom_sublinks .= "<li><a href='".make_link("ext_doc/index")."'>Help</a></li>";}
|
||||
break;
|
||||
case "comment":
|
||||
$custom_sublinks .= "<li><a href='".make_link('comment/list')."'>All</a></li>";
|
||||
|
|
|
@ -38,6 +38,14 @@ class CustomViewImageTheme extends ViewImageTheme {
|
|||
$html .= "<br>Source: <a href='$h_source'>link</a>";
|
||||
}
|
||||
|
||||
if(!is_null($image->rating) && file_exists("ext/rating")) {
|
||||
if($image->rating == null || $image->rating == "u"){
|
||||
$image->rating = "u";
|
||||
}
|
||||
$h_rating = Ratings::rating_to_human($image->rating);
|
||||
$html .= "<br>Rating: $h_rating";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ class Layout {
|
|||
$custom_links .= $this->navlinks(make_link('post/list'), "Posts", array("post", "view"));
|
||||
$custom_links .= $this->navlinks(make_link('comment/list'), "Comments", array("comment"));
|
||||
$custom_links .= $this->navlinks(make_link('tags'), "Tags", array("tags"));
|
||||
if(class_exists("Pools")) {
|
||||
$custom_links .= $this->navlinks(make_link('pool/list'), "Pools", array("pool"));
|
||||
}
|
||||
$custom_links .= $this->navlinks(make_link('upload'), "Upload", array("upload"));
|
||||
if(class_exists("Wiki")) {
|
||||
$custom_links .= $this->navlinks(make_link('wiki/rules'), "Rules", array("wiki/rules"));
|
||||
|
@ -91,10 +94,13 @@ class Layout {
|
|||
# the subnav links aren't shown, but it would
|
||||
# be nice to be correct
|
||||
case "post":
|
||||
if(file_exists("ext/numeric_score")){ $cs .= "<b>Popular by </b><a href='".make_link('popular_by_day')."'>Day</a><b>/</b><a href='".make_link('popular_by_month')."'>Month</a><b>/</b><a href='".make_link('popular_by_year')."'>Year</a> ";}
|
||||
$cs .= "<a class='tab' href='".make_link('post/list')."'>All</a>";
|
||||
$cs .= "<a class='tab' href='".make_link("post/list/favorited_by=$username/1")."'>My Favorites</a>";
|
||||
$cs .= "<a class='tab' href='".make_link('rss/images')."'>Feed</a>";
|
||||
if($hw) $cs .= "<a class='tab' href='".make_link("wiki/posts")."'>Help</a>";
|
||||
if(file_exists("ext/random_image")){ $cs .= "<a class='tab' href='".make_link("random_image/view")."'>Random Image</a>";}
|
||||
if($hw){ $cs .= "<a class='tab' href='".make_link("wiki/posts")."'>Help</a>";
|
||||
}else{ $cs .= "<a class='tab' href='".make_link("ext_doc/index")."'>Help</a>";}
|
||||
break;
|
||||
case "comment":
|
||||
$cs .= "<a class='tab' href='".make_link('comment/list')."'>All</a>";
|
||||
|
|
|
@ -44,6 +44,14 @@ class CustomViewImageTheme extends ViewImageTheme {
|
|||
$html .= "<br>Source: <a href='$h_source'>link</a>";
|
||||
}
|
||||
|
||||
if(!is_null($image->rating) && file_exists("ext/rating")) {
|
||||
if($image->rating == null || $image->rating == "u"){
|
||||
$image->rating = "u";
|
||||
}
|
||||
$h_rating = Ratings::rating_to_human($image->rating);
|
||||
$html .= "<br>Rating: $h_rating";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue