diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php
index 869e7de6..6d5cd1cd 100644
--- a/core/imageboard.pack.php
+++ b/core/imageboard.pack.php
@@ -26,6 +26,7 @@
$tag_n = 0; // temp hack
$_flexihash = null;
$_fh_last_opts = null;
+$order_sql = null; // this feels ugly
require_once "lib/flexihash.php";
@@ -114,7 +115,7 @@ class Image {
assert(is_numeric($start));
assert(is_numeric($limit));
assert(is_array($tags));
- global $database, $user;
+ global $database, $user, $config, $order_sql;
$images = array();
@@ -128,13 +129,15 @@ class Image {
}
$querylet = Image::build_search_querylet($tags);
- $querylet->append(new Querylet("ORDER BY images.id DESC LIMIT :limit OFFSET :offset", array("limit"=>$limit, "offset"=>$start)));
+ $querylet->append(new Querylet(" ORDER BY images.".($order_sql ?: $config->get_string("index_order"))));
+ $querylet->append(new Querylet(" LIMIT :limit OFFSET :offset", array("limit"=>$limit, "offset"=>$start)));
#var_dump($querylet->sql); var_dump($querylet->variables);
$result = $database->execute($querylet->sql, $querylet->variables);
while($row = $result->fetch()) {
$images[] = new Image($row);
}
+ $order_sql = null;
return $images;
}
@@ -476,11 +479,11 @@ class Image {
$this->delete_tags_from_image();
// insert each new tags
foreach($tags as $tag) {
- if(preg_match("/^source=(.*)$/i", $tag, $matches)) {
+ if(preg_match("/^source[=|:](.*)$/i", $tag, $matches)) {
$this->set_source($matches[1]);
continue;
}
- if(preg_match("/^pool=(.*)$/i", $tag, $matches)) {
+ if(preg_match("/^pool[=|:](.*)$/i", $tag, $matches)) {
if(class_exists("Pools")) {
$pls = new Pools();
$pls->add_post_from_tag($matches[1], $this->id);
@@ -663,6 +666,8 @@ class Image {
}
}
+ $terms = Tag::resolve_aliases($terms);
+
// parse the words that are searched for into
// various types of querylet
foreach($terms as $term) {
@@ -675,8 +680,6 @@ class Image {
continue;
}
- $term = Tag::resolve_alias($term);
-
$stpe = new SearchTermParseEvent($term, $terms);
send_event($stpe);
if($stpe->is_querylet_set()) {
@@ -824,6 +827,8 @@ class Image {
}
}
+ $terms = Tag::resolve_aliases($terms);
+
reset($terms); // rewind to first element in array.
// turn each term into a specific type of querylet
@@ -833,8 +838,6 @@ class Image {
$negative = true;
$term = substr($term, 1);
}
-
- $term = Tag::resolve_alias($term);
$stpe = new SearchTermParseEvent($term, $terms);
send_event($stpe);
@@ -1082,11 +1085,22 @@ class Tag {
assert(is_array($tags));
$new = array();
- foreach($tags as $tag) {
- $new_set = explode(' ', Tag::resolve_alias($tag));
- foreach($new_set as $new_one) {
- $new[] = $new_one;
+
+ $i = 0;
+ $tag_count = count($tags);
+ while($i<$tag_count) {
+ $aliases = explode(' ', Tag::resolve_alias($tags[$i]));
+ foreach($aliases as $alias){
+ if(!in_array($alias, $new)){
+ if($tags[$i] == $alias){
+ $new[] = $alias;
+ }elseif(!in_array($alias, $tags)){
+ $tags[] = $alias;
+ $tag_count++;
+ }
+ }
}
+ $i++;
}
$new = array_iunique($new); // remove any duplicate tags
diff --git a/core/util.inc.php b/core/util.inc.php
index b1331a4a..a4c5b244 100644
--- a/core/util.inc.php
+++ b/core/util.inc.php
@@ -509,14 +509,15 @@ function captcha_check() {
* @param string &$file File path
* @return string
*/
-function getMimeType($file, $ext="") {
+function getMimeType($file, $ext="", $list=false) {
// Static extension lookup
$ext = strtolower($ext);
static $exts = array(
'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
- 'swf' => 'application/x-shockwave-flash', 'pdf' => 'application/pdf',
+ 'swf' => 'application/x-shockwave-flash', 'video/x-flv' => 'flv',
+ 'svg' => 'image/svg+xml', 'pdf' => 'application/pdf',
'zip' => 'application/zip', 'gz' => 'application/x-gzip',
'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
@@ -529,6 +530,8 @@ function getMimeType($file, $ext="") {
'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm'
);
+ if ($list == true){ return $exts; }
+
if (isset($exts[$ext])) { return $exts[$ext]; }
$type = false;
@@ -556,6 +559,17 @@ function getMimeType($file, $ext="") {
return 'application/octet-stream';
}
+
+function getExtension ($mime_type){
+ if(empty($mime_type)){
+ return false;
+ }
+
+ $extensions = getMimeType(null, null, true);
+ $ext = array_search($mime_type, $extensions);
+ return ($ext ?: false);
+}
+
/**
* @private
*/
@@ -801,17 +815,24 @@ function transload($url, $mfile) {
$ch = curl_init($url);
$fp = fopen($mfile, "w");
- curl_setopt($ch, CURLOPT_FILE, $fp);
- curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_VERBOSE, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Shimmie-".VERSION);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_exec($ch);
+ $response = curl_exec($ch);
+
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $headers = http_parse_headers(implode("\n", preg_split('/\R/', rtrim(substr($response, 0, $header_size)))));
+ $body = substr($response, $header_size);
+
curl_close($ch);
+ fwrite($fp, $body);
fclose($fp);
- return true;
+ return $headers;
}
if($config->get_string("transload_engine") === "wget") {
@@ -839,12 +860,36 @@ function transload($url, $mfile) {
fwrite($fp, $data);
fclose($fp);
- return true;
+ $headers = http_parse_headers(implode("\n", $http_response_header));
+
+ return $headers;
}
return false;
}
+if (!function_exists('http_parse_headers')) { #http://www.php.net/manual/en/function.http-parse-headers.php#112917
+ function http_parse_headers ($raw_headers){
+ $headers = array(); // $headers = [];
+
+ foreach (explode("\n", $raw_headers) as $i => $h) {
+ $h = explode(':', $h, 2);
+
+ if (isset($h[1])){
+ if(!isset($headers[$h[0]])){
+ $headers[$h[0]] = trim($h[1]);
+ }else if(is_array($headers[$h[0]])){
+ $tmp = array_merge($headers[$h[0]],array(trim($h[1])));
+ $headers[$h[0]] = $tmp;
+ }else{
+ $tmp = array_merge(array($headers[$h[0]]),array(trim($h[1])));
+ $headers[$h[0]] = $tmp;
+ }
+ }
+ }
+ return $headers;
+ }
+}
$_included = array();
/**
diff --git a/ext/artists/main.php b/ext/artists/main.php
index d426d512..984b12af 100644
--- a/ext/artists/main.php
+++ b/ext/artists/main.php
@@ -45,7 +45,7 @@ class Artists extends Extension {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
- if(preg_match("/^author=(.*)$/", $event->term, $matches)) {
+ if(preg_match("/^author[=|:](.*)$/", $event->term, $matches)) {
$char = $matches[1];
$event->add_querylet(new Querylet("Author = :author_char", array("author_char"=>$char)));
}
diff --git a/ext/comment/main.php b/ext/comment/main.php
index 48d4f013..1c472626 100644
--- a/ext/comment/main.php
+++ b/ext/comment/main.php
@@ -262,12 +262,12 @@ class CommentList extends Extension {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
- if(preg_match("/comments(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
- $cmp = $matches[1];
+ if(preg_match("/^comments([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$comments = $matches[2];
$event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM comments GROUP BY image_id HAVING count(image_id) $cmp $comments)"));
}
- else if(preg_match("/commented_by=(.*)/i", $event->term, $matches)) {
+ else if(preg_match("/^commented_by[=|:](.*)$/i", $event->term, $matches)) {
global $database;
$user = User::by_name($matches[1]);
if(!is_null($user)) {
@@ -279,7 +279,7 @@ class CommentList extends Extension {
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM comments WHERE owner_id = $user_id)"));
}
- else if(preg_match("/commented_by_userid=([0-9]+)/i", $event->term, $matches)) {
+ else if(preg_match("/^commented_by_userno[=|:]([0-9]+)$/i", $event->term, $matches)) {
$user_id = int_escape($matches[1]);
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM comments WHERE owner_id = $user_id)"));
}
diff --git a/ext/danbooru_api/main.php b/ext/danbooru_api/main.php
index f5d8773e..2ba1b82d 100644
--- a/ext/danbooru_api/main.php
+++ b/ext/danbooru_api/main.php
@@ -54,14 +54,6 @@ class DanbooruApi extends Extension {
}
}
- public function onSearchTermParse(SearchTermParseEvent $event) {
- $matches = array();
- if(preg_match("/^md5:([0-9a-fA-F]*)$/i", $event->term, $matches)) {
- $hash = strtolower($matches[1]);
- $event->add_querylet(new Querylet("images.hash = '$hash'")); // :-O
- }
- }
-
// Danbooru API
private function api_danbooru(PageRequestEvent $event)
{
diff --git a/ext/favorites/main.php b/ext/favorites/main.php
index aee35d6a..6517377e 100644
--- a/ext/favorites/main.php
+++ b/ext/favorites/main.php
@@ -117,12 +117,12 @@ class Favorites extends Extension {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
- if(preg_match("/favorites(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
- $cmp = $matches[1];
+ if(preg_match("/^favorites([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$favorites = $matches[2];
$event->add_querylet(new Querylet("images.id IN (SELECT id FROM images WHERE favorites $cmp $favorites)"));
}
- else if(preg_match("/favorited_by=(.*)/i", $event->term, $matches)) {
+ else if(preg_match("/^favorited_by[=|:](.*)$/i", $event->term, $matches)) {
global $database;
$user = User::by_name($matches[1]);
if(!is_null($user)) {
@@ -134,7 +134,7 @@ class Favorites extends Extension {
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM user_favorites WHERE user_id = $user_id)"));
}
- else if(preg_match("/favorited_by_userno=([0-9]+)/i", $event->term, $matches)) {
+ else if(preg_match("/^favorited_by_userno[=|:](\d+)$/i", $event->term, $matches)) {
$user_id = int_escape($matches[1]);
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM user_favorites WHERE user_id = $user_id)"));
}
diff --git a/ext/index/main.php b/ext/index/main.php
index f851bde7..9cf5abfc 100644
--- a/ext/index/main.php
+++ b/ext/index/main.php
@@ -21,6 +21,16 @@
*
size>=500x500 -- no small images
* size<1000x1000 -- no large images
*
+ * width (=, <, >, <=, >=) width, eg
+ *
+ * - width=1024 -- find images with 1024 width
+ *
- width>2000 -- find images bigger than 2000 width
+ *
+ * height (=, <, >, <=, >=) height, eg
+ *
+ * - height=768 -- find images with 768 height
+ *
- height>1000 -- find images bigger than 1000 height
+ *
* ratio (=, <, >, <=, >=) width : height, eg
*
* - ratio=4:3, ratio=16:9 -- standard wallpaper
@@ -38,41 +48,67 @@
*
- id<20 -- search only the first few images
*
- id>=500 -- search later images
*
- * user=Username, eg
+ * user=Username & poster=Username, eg
*
* - user=Shish -- find all of Shish's posts
+ *
- poster=Shish -- same as above
*
- * hash=md5sum, eg
+ * user_id=userID & poster_id=userID, eg
+ *
+ * - user_id=2 -- find all posts by user id 2
+ *
- poster_id=2 -- same as above
+ *
+ * hash=md5sum & md5=md5sum, eg
*
* - hash=bf5b59173f16b6937a4021713dbfaa72 -- find the "Taiga want up!" image
+ *
- md5=bf5b59173f16b6937a4021713dbfaa72 -- same as above
*
- * filetype=type, eg
+ * filetype=type & ext=type, eg
*
* - filetype=png -- find all PNG images
+ *
- ext=png -- same as above
*
- * filename=blah, eg
+ * filename=blah & name=blah, eg
*
* - filename=kitten -- find all images with "kitten" in the original filename
+ *
- name=kitten -- same as above
*
* posted (=, <, >, <=, >=) date, eg
*
* - posted>=2009-12-25 posted<=2010-01-01 -- find images posted between christmas and new year
*
+ * tags (=, <, >, <=, >=) count, eg
+ *
+ * - tags=1 -- search for images with only 1 tag
+ *
- tags>=10 -- search for images with 10 or more tags
+ *
- tags<25 -- search for images with less than 25 tags
+ *
+ * source=(URL, any, none) eg
+ *
+ * - source=http://example.com -- find all images with "http://example.com" in the source
+ *
- source=any -- find all images with a source
+ *
- source=none -- find all images without a source
+ *
+ * order=(id, width, height, filesize, filename)_(ASC, DESC), eg
+ *
+ * - order=width -- find all images sorted from highest > lowest width
+ *
- order=filesize_asc -- find all images sorted from lowest > highest filesize
+ *
*
* Search items can be combined to search for images which match both,
* or you can stick "-" in front of an item to search for things that don't
* match it.
+ *
Metatags can be followed by ":" rather than "=" if you prefer.
+ *
I.E: "posted:2014-01-01", "id:>=500" etc.
*
Some search methods provided by extensions:
*
- * - Danbooru API
- *
- * - md5:[hash] -- same as "hash=", but the API calls it by a different name
- *
* - Numeric Score
*
* - score (=, <, >, <=, >=) number -- seach by score
*
- upvoted_by=Username -- search for a user's likes
*
- downvoted_by=Username -- search for a user's dislikes
+ *
- upvoted_by_id=UserID -- search for a user's likes by user ID
+ *
- downvoted_by_id=UserID -- search for a user's dislikes by user ID
*
* - Image Rating
*
@@ -81,11 +117,29 @@
* - Favorites
*
* - favorites (=, <, >, <=, >=) number -- search for images favourited a certain number of times
- *
- favourited_by=Username -- search for a user's choices
+ *
- favourited_by=Username -- search for a user's choices by username
+ *
- favorited_by_userno=UserID -- search for a user's choice by userID
*
* - Notes
*
* - notes (=, <, >, <=, >=) number -- search by the number of notes an image has
+ *
- notes_by=Username -- search for images containing notes created by username
+ *
- notes_by_userno=UserID -- search for images containing notes created by userID
+ *
+ * - Artists
+ *
+ * - author=ArtistName -- search for images by artist
+ *
+ * - Image Comments
+ *
+ * - comments (=, <, >, <=, >=) number -- search for images by number of comments
+ *
- commented_by=Username -- search for images containing user's comments by username
+ *
- commented_by_userno=UserID -- search for images containing user's comments by userID
+ *
+ * - Pools
+ *
+ * - pool=(PoolID, any, none) -- search for images in a pool by PoolID.
+ *
- pool_by_name=PoolName -- search for images in a pool by PoolName. underscores are replaced with spaces
*
*
*/
@@ -141,6 +195,7 @@ class Index extends Extension {
global $config;
$config->set_default_int("index_images", 24);
$config->set_default_bool("index_tips", true);
+ $config->set_default_string("index_order", "id DESC");
}
public function onPageRequest(PageRequestEvent $event) {
@@ -240,48 +295,70 @@ class Index extends Extension {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
// check for tags first as tag based searches are more common.
- if(preg_match("/tags(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
- $cmp = $matches[1];
+ if(preg_match("/^tags([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$tags = $matches[2];
$event->add_querylet(new Querylet('images.id IN (SELECT DISTINCT image_id FROM image_tags GROUP BY image_id HAVING count(image_id) '.$cmp.' '.$tags.')'));
}
- else if(preg_match("/^ratio(<|>|<=|>=|=)(\d+):(\d+)$/", $event->term, $matches)) {
- $cmp = $matches[1];
+ else if(preg_match("/^ratio([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+):(\d+)$/", $event->term, $matches)) {
+ $cmp = preg_replace('/^:/', '=', $matches[1]);
$args = array("width{$this->stpen}"=>int_escape($matches[2]), "height{$this->stpen}"=>int_escape($matches[3]));
$event->add_querylet(new Querylet("width / height $cmp :width{$this->stpen} / :height{$this->stpen}", $args));
}
- else if(preg_match("/^(filesize|id)(<|>|<=|>=|=)(\d+[kmg]?b?)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(filesize|id)([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+[kmg]?b?)$/i", $event->term, $matches)) {
$col = $matches[1];
- $cmp = $matches[2];
+ $cmp = ltrim($matches[2], ":") ?: "=";
$val = parse_shorthand_int($matches[3]);
$event->add_querylet(new Querylet("images.$col $cmp :val{$this->stpen}", array("val{$this->stpen}"=>$val)));
}
- else if(preg_match("/^(hash|md5)=([0-9a-fA-F]*)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(hash|md5)[=|:]([0-9a-fA-F]*)$/i", $event->term, $matches)) {
$hash = strtolower($matches[2]);
$event->add_querylet(new Querylet('images.hash = :hash', array("hash" => $hash)));
}
- else if(preg_match("/^(filetype|ext)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(filetype|ext)[=|:]([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
$ext = strtolower($matches[2]);
$event->add_querylet(new Querylet('images.ext = :ext', array("ext" => $ext)));
}
- else if(preg_match("/^(filename|name)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(filename|name)[=|:]([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
$filename = strtolower($matches[2]);
$event->add_querylet(new Querylet("images.filename LIKE :filename{$this->stpen}", array("filename{$this->stpen}"=>"%$filename%")));
}
- else if(preg_match("/^(source)=([a-zA-Z0-9]*)$/i", $event->term, $matches)) {
- $filename = strtolower($matches[2]);
- $event->add_querylet(new Querylet('images.source LIKE :src', array("src"=>"%$filename%")));
+ else if(preg_match("/^(source)[=|:](.*)$/i", $event->term, $matches)) {
+ $source = strtolower($matches[2]);
+
+ if(preg_match("/^(any|none)$/", $source)){
+ $not = ($source == "any" ? "NOT" : "");
+ $event->add_querylet(new Querylet("images.source IS $not NULL"));
+ }else{
+ $event->add_querylet(new Querylet('images.source LIKE :src', array("src"=>"%$source%")));
+ }
}
- else if(preg_match("/^posted(<|>|<=|>=|=)([0-9-]*)$/", $event->term, $matches)) {
- $cmp = $matches[1];
+ else if(preg_match("/^posted([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])([0-9-]*)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$val = $matches[2];
$event->add_querylet(new Querylet("images.posted $cmp :posted{$this->stpen}", array("posted{$this->stpen}"=>$val)));
}
- else if(preg_match("/^size(<|>|<=|>=|=)(\d+)x(\d+)$/", $event->term, $matches)) {
- $cmp = $matches[1];
+ else if(preg_match("/^size([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)x(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$args = array("width{$this->stpen}"=>int_escape($matches[2]), "height{$this->stpen}"=>int_escape($matches[3]));
$event->add_querylet(new Querylet("width $cmp :width{$this->stpen} AND height $cmp :height{$this->stpen}", $args));
}
+ else if(preg_match("/^width([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
+ $event->add_querylet(new Querylet("width $cmp :width{$this->stpen}", array("width{$this->stpen}"=>int_escape($matches[2]))));
+ }
+ else if(preg_match("/^height([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
+ $event->add_querylet(new Querylet("height $cmp :height{$this->stpen}",array("height{$this->stpen}"=>int_escape($matches[2]))));
+ }
+ else if(preg_match("/^order[=|:](id|width|height|filesize|filename)[_]?(desc|asc)?$/i", $event->term, $matches)){
+ global $order_sql;
+ $ord = strtolower($matches[1]);
+ $default_order_for_column = preg_match("/^(id|filename)$/", $matches[1]) ? "ASC" : "DESC";
+ $sort = isset($matches[2]) ? strtoupper($matches[2]) : $default_order_for_column;
+ $order_sql = "$ord $sort";
+ $event->add_querylet(new Querylet("1=1")); //small hack to avoid metatag being treated as normal tag
+ }
$this->stpen++;
}
diff --git a/ext/notes/main.php b/ext/notes/main.php
index 5bc09ef6..f29a22e9 100644
--- a/ext/notes/main.php
+++ b/ext/notes/main.php
@@ -210,16 +210,16 @@ class Notes extends Extension {
*/
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
- if(preg_match("/note=(.*)/i", $event->term, $matches)) {
+ if(preg_match("/^note[=|:](.*)$/i", $event->term, $matches)) {
$notes = int_escape($matches[1]);
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM notes WHERE note = $notes)"));
}
- else if(preg_match("/notes(<|>|<=|>=|=)(\d+)/", $event->term, $matches)) {
- $cmp = $matches[1];
+ else if(preg_match("/^notes([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(\d+)%/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$notes = $matches[2];
$event->add_querylet(new Querylet("images.id IN (SELECT id FROM images WHERE notes $cmp $notes)"));
}
- else if(preg_match("/notes_by=(.*)/i", $event->term, $matches)) {
+ else if(preg_match("/^notes_by[=|:](.*)$/i", $event->term, $matches)) {
global $database;
$user = User::by_name($matches[1]);
if(!is_null($user)) {
@@ -231,7 +231,7 @@ class Notes extends Extension {
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM notes WHERE user_id = $user_id)"));
}
- else if(preg_match("/notes_by_userno=([0-9]+)/i", $event->term, $matches)) {
+ else if(preg_match("/^notes_by_userno[=|:](\d+)$/i", $event->term, $matches)) {
$user_id = int_escape($matches[1]);
$event->add_querylet(new Querylet("images.id IN (SELECT image_id FROM notes WHERE user_id = $user_id)"));
}
diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php
index ed7597ab..2da74577 100644
--- a/ext/numeric_score/main.php
+++ b/ext/numeric_score/main.php
@@ -31,16 +31,14 @@ class NumericScore extends Extension {
public function onDisplayingImage(DisplayingImageEvent $event) {
global $user, $page;
if(!$user->is_anonymous()) {
- $html = $this->theme->get_voter_html($event->image);
- $page->add_block(new Block("Image Score", $html, "left", 20));
+ $this->theme->get_voter($event->image);
}
}
public function onUserPageBuilding(UserPageBuildingEvent $event) {
global $page, $user;
if($user->can("edit_other_vote")) {
- $html = $this->theme->get_nuller_html($event->display_user);
- $page->add_block(new Block("Votes", $html, "main", 60));
+ $this->theme->get_nuller($event->display_user);
}
}
@@ -219,12 +217,12 @@ class NumericScore extends Extension {
public function onSearchTermParse(SearchTermParseEvent $event) {
$matches = array();
- if(preg_match("/^score(<|<=|=|>=|>)(-?\d+)$/", $event->term, $matches)) {
- $cmp = $matches[1];
+ if(preg_match("/^score([:]?<|[:]?>|[:]?<=|[:]?>=|[:|=])(-?\d+)$/", $event->term, $matches)) {
+ $cmp = ltrim($matches[1], ":") ?: "=";
$score = $matches[2];
$event->add_querylet(new Querylet("numeric_score $cmp $score"));
}
- if(preg_match("/^upvoted_by=(.*)$/", $event->term, $matches)) {
+ if(preg_match("/^upvoted_by[=|:](.*)$/", $event->term, $matches)) {
$duser = User::by_name($matches[1]);
if(is_null($duser)) {
throw new SearchTermParseException(
@@ -234,7 +232,7 @@ class NumericScore extends Extension {
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)",
array("ns_user_id"=>$duser->id)));
}
- if(preg_match("/^downvoted_by=(.*)$/", $event->term, $matches)) {
+ if(preg_match("/^downvoted_by[=|:](.*)$/", $event->term, $matches)) {
$duser = User::by_name($matches[1]);
if(is_null($duser)) {
throw new SearchTermParseException(
@@ -244,13 +242,13 @@ class NumericScore extends Extension {
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
array("ns_user_id"=>$duser->id)));
}
- if(preg_match("/^upvoted_by_id=(\d+)$/", $event->term, $matches)) {
+ if(preg_match("/^upvoted_by_id[=|:](\d+)$/", $event->term, $matches)) {
$iid = int_escape($matches[1]);
$event->add_querylet(new Querylet(
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=1)",
array("ns_user_id"=>$iid)));
}
- if(preg_match("/^downvoted_by_id=(\d+)$/", $event->term, $matches)) {
+ if(preg_match("/^downvoted_by_id[=|:](\d+)$/", $event->term, $matches)) {
$iid = int_escape($matches[1]);
$event->add_querylet(new Querylet(
"images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=:ns_user_id AND score=-1)",
diff --git a/ext/numeric_score/theme.php b/ext/numeric_score/theme.php
index baefad39..e60af00c 100644
--- a/ext/numeric_score/theme.php
+++ b/ext/numeric_score/theme.php
@@ -1,8 +1,8 @@
id);
$i_score = int_escape($image->numeric_score);
@@ -46,11 +46,11 @@ class NumericScoreTheme extends Themelet {
";
}
- return $html;
+ $page->add_block(new Block("Image Score", $html, "left", 20));
}
- public function get_nuller_html(User $duser) {
- global $user;
+ public function get_nuller(User $duser) {
+ global $user, $page;
$html = "
";
- return $html;
+ $page->add_block(new Block("Votes", $html, "main", 60));
}
public function view_popular($images, $dte) {
diff --git a/ext/pools/main.php b/ext/pools/main.php
index 008838d3..6bcd8760 100644
--- a/ext/pools/main.php
+++ b/ext/pools/main.php
@@ -293,6 +293,28 @@ class Pools extends Extension {
}
}
+ public function onSearchTermParse(SearchTermParseEvent $event) {
+ $matches = array();
+ if(preg_match("/^pool[=|:]([0-9]+|any|none)$/", $event->term, $matches)) {
+ $poolID = $matches[1];
+
+ if(preg_match("/^(any|none)$/", $poolID)){
+ $not = ($poolID == "none" ? "NOT" : "");
+ $event->add_querylet(new Querylet("images.id $not IN (SELECT DISTINCT image_id FROM pool_images)"));
+ }else{
+ $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM pool_images WHERE pool_id = $poolID)"));
+ }
+ }
+ else if(preg_match("/^pool_by_name[=|:](.*)$/", $event->term, $matches)) {
+ $poolTitle = str_replace("_", " ", $matches[1]);
+
+ $pool = $this->get_single_pool_from_title($poolTitle);
+ $poolID = 0;
+ if ($pool){ $poolID = $pool['id']; }
+ $event->add_querylet(new Querylet("images.id IN (SELECT DISTINCT image_id FROM pool_images WHERE pool_id = $poolID)"));
+ }
+ }
+
public function add_post_from_tag(/*str*/ $poolTag, /*int*/ $imageID){
$poolTag = str_replace("_", " ", $poolTag);
//First check if pool tag is a title
diff --git a/ext/rating/main.php b/ext/rating/main.php
index be54cdb4..1b41b89f 100644
--- a/ext/rating/main.php
+++ b/ext/rating/main.php
@@ -116,7 +116,7 @@ class Ratings extends Extension {
$set = Ratings::privs_to_sql(Ratings::get_user_privs($user));
$event->add_querylet(new Querylet("rating IN ($set)"));
}
- if(preg_match("/^rating=(?:([sqeu]+)|(safe|questionable|explicit|unknown))$/D", strtolower($event->term), $matches)) {
+ if(preg_match("/^rating[=|:](?:([sqeu]+)|(safe|questionable|explicit|unknown))$/D", strtolower($event->term), $matches)) {
$ratings = $matches[1] ? $matches[1] : array($matches[2][0]);
$ratings = array_intersect(str_split($ratings), str_split(Ratings::get_user_privs($user)));
$set = "'" . join("', '", $ratings) . "'";
@@ -199,7 +199,7 @@ class Ratings extends Extension {
private function no_rating_query($context) {
foreach($context as $term) {
- if(preg_match("/^rating=/", $term)) {
+ if(preg_match("/^rating[=|:]/", $term)) {
return false;
}
}
diff --git a/ext/upload/main.php b/ext/upload/main.php
index 2e7a073e..b92fc479 100644
--- a/ext/upload/main.php
+++ b/ext/upload/main.php
@@ -329,9 +329,12 @@ class Upload extends Extension {
}
$tmp_filename = tempnam(ini_get('upload_tmp_dir'), "shimmie_transload");
- $filename = basename($url);
- if(!transload($url, $tmp_filename)) {
+ $headers = transload($url, $tmp_filename);
+ $h_filename = (isset($headers['Content-Disposition']) ? preg_replace('/^.*filename="([^ ]+)"/i', '$1', $headers['Content-Disposition']) : null);
+ $filename = $h_filename ?: basename($url);
+
+ if(!$headers) {
$this->theme->display_upload_error($page, "Error with ".html_escape($filename),
"Error reading from ".html_escape($url));
return false;
@@ -341,12 +344,11 @@ class Upload extends Extension {
$this->theme->display_upload_error($page, "Error with ".html_escape($filename),
"No data found -- perhaps the site has hotlink protection?");
$ok = false;
- }
- else {
+ }else{
global $user;
$pathinfo = pathinfo($url);
- $metadata['filename'] = $pathinfo['basename'];
- $metadata['extension'] = $pathinfo['extension'];
+ $metadata['filename'] = $filename;
+ $metadata['extension'] = getExtension($headers['Content-Type']) ?: $pathinfo['extension'];
$metadata['tags'] = $tags;
$metadata['source'] = $source;
diff --git a/ext/user/main.php b/ext/user/main.php
index 5a4058ca..67755004 100644
--- a/ext/user/main.php
+++ b/ext/user/main.php
@@ -309,7 +309,7 @@ class UserPage extends Extension {
global $user;
$matches = array();
- if(preg_match("/^(poster|user)=(.*)$/i", $event->term, $matches)) {
+ if(preg_match("/^(poster|user)[=|:](.*)$/i", $event->term, $matches)) {
$duser = User::by_name($matches[2]);
if(!is_null($duser)) {
$user_id = $duser->id;
@@ -319,11 +319,11 @@ class UserPage extends Extension {
}
$event->add_querylet(new Querylet("images.owner_id = $user_id"));
}
- else if(preg_match("/^(poster|user)_id=([0-9]+)$/i", $event->term, $matches)) {
+ else if(preg_match("/^(poster|user)_id[=|:]([0-9]+)$/i", $event->term, $matches)) {
$user_id = int_escape($matches[2]);
$event->add_querylet(new Querylet("images.owner_id = $user_id"));
}
- else if($user->can("view_ip") && preg_match("/^(poster|user)_ip=([0-9\.]+)$/i", $event->term, $matches)) {
+ else if($user->can("view_ip") && preg_match("/^(poster|user)_ip[=|:]([0-9\.]+)$/i", $event->term, $matches)) {
$user_ip = $matches[2]; // FIXME: ip_escape?
$event->add_querylet(new Querylet("images.owner_ip = '$user_ip'"));
}