From cd11e75e405f1f8470750b929bd29197d37733ce Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 23 Dec 2011 21:27:38 +0000 Subject: [PATCH] Can now set rating/external source while uploading via the bookmarklets. --- core/extension.class.php | 7 ++++++ ext/upload/main.php | 46 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/core/extension.class.php b/core/extension.class.php index 9b514318..7906822b 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -177,6 +177,13 @@ abstract class DataHandlerExtension implements Extension { $iae = new ImageAdditionEvent($event->user, $image); send_event($iae); $event->image_id = $iae->image->id; + + // Rating Stuff. + if(file_exists("ext/rating") && !empty($event->metadata['rating'])){ + global $database; + $rating = $event->metadata['rating']; + $database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $event->image_id)); + } } } diff --git a/ext/upload/main.php b/ext/upload/main.php index 167bce07..fd8e5e6a 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -173,7 +173,35 @@ class Upload implements Extension { if(!empty($_GET['tags']) && $_GET['tags'] != "null") { $tags = Tag::explode($_GET['tags']); } - $ok = $this->try_transload($url, $tags, $url); + + + + // Checks if url contains rating, also checks if the rating extension is enabled. + if($config->get_string("transload_engine", "none") != "none" && file_exists("ext/rating") && !empty($_GET['rating'])) { + $rating = strtolower($_GET['rating']); + // There must be a less messy way to do this.. + if($rating !== "") { + if($rating == "s" || $rating == "safe" || $rating == "q" || $rating == "questionable" || $rating == "e" || $rating == "explicit") { + if($rating == "s" || $rating == "safe" || $rating == "q" || $rating == "questionable") { + if($rating == "s" || $rating == "safe") { + $rating = "s"; + }else{ + $rating = "q"; + } + }else{ + $rating = "e"; + } + }else{ + $rating = "u"; + } + }else{ + $rating = "u"; + } + }else{ + $rating = ""; + } + + $ok = $this->try_transload($url, $tags, $rating, $url); $this->theme->display_upload_status($page, $ok); } else @@ -250,7 +278,7 @@ class Upload implements Extension { } } - private function try_upload($file, $tags, $source, $replace='') { + private function try_upload($file, $tags, $rating, $source, $replace='') { global $page; global $config; global $user; @@ -296,13 +324,18 @@ class Upload implements Extension { return $ok; } - private function try_transload($url, $tags, $source, $replace='') { + private function try_transload($url, $tags, $rating, $source, $replace='') { global $page; global $config; $ok = true; - if(empty($source)) $source = $url; + //Allows external source to be set. + if(!empty($_GET['source'])){ + $source = $_GET['source']; + }else{ + $source = $url; + } // PHP falls back to system default if /tmp fails, can't we just // use the system default to start with? :-/ @@ -363,6 +396,11 @@ class Upload implements Extension { $metadata['tags'] = $tags; $metadata['source'] = $source; + /* check for rating > adds to metadata if it has */ + if($config->get_string("transload_engine", "none") != "none" && file_exists("ext/rating") && !empty($_GET['rating'])){ + $metadata['rating'] = $rating; + } + /* check if we have been given an image ID to replace */ if (!empty($replace)) { $metadata['replace'] = $replace;