From d30665d274e08fb20e38ee6e57d43c61ed976bad Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 27 Sep 2015 21:09:27 +0100 Subject: [PATCH] more deduping --- core/imageboard.pack.php | 185 +++++++++++++++++++------------------ ext/artists/theme.php | 149 +++++++++++++++-------------- ext/numeric_score/main.php | 6 +- ext/ouroboros_api/main.php | 2 +- ext/rss_comments/main.php | 16 ++-- ext/rss_images/main.php | 2 +- ext/shimmie_api/main.php | 4 +- ext/sitemap/main.php | 6 +- ext/tag_editcloud/main.php | 42 ++++----- 9 files changed, 203 insertions(+), 209 deletions(-) diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 63c76e1a..dc92b145 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -63,7 +63,7 @@ class Image { public $tag_array; public $owner_id, $owner_ip; - public $posted, $posted_timestamp; + public $posted; public $source; public $locked; @@ -82,7 +82,6 @@ class Image { $name = str_replace("images.", "", $name); $this->$name = $value; // hax, this is likely the cause of much scrutinizer-ci complaints. } - $this->posted_timestamp = strtotime($this->posted); // pray $this->locked = bool_escape($this->locked); assert(is_numeric($this->id)); @@ -291,7 +290,6 @@ class Image { return ceil(Image::count_images($tags) / $config->get_int('index_images')); } - /* * Accessors & mutators */ @@ -747,9 +745,58 @@ class Image { return Image::build_accurate_search_querylet($terms); } + /** + * @param string[] $terms + * @return ImgQuerylet[] + */ + private static function parse_meta_terms($terms) { + $img_querylets = array(); + $stpe = new SearchTermParseEvent(null, $terms); + send_event($stpe); + if ($stpe->is_querylet_set()) { + foreach ($stpe->get_querylets() as $querylet) { + $img_querylets[] = new ImgQuerylet($querylet, true); + } + } + return $img_querylets; + } + + /** + * @param ImgQuerylet[] $img_querylets + * @return Querylet + */ + private static function build_img_search($img_querylets) { + // merge all the image metadata searches into one generic querylet + $n = 0; + $sql = ""; + $terms = array(); + foreach ($img_querylets as $iq) { + if ($n++ > 0) $sql .= " AND"; + if (!$iq->positive) $sql .= " NOT"; + $sql .= " (" . $iq->qlet->sql . ")"; + $terms = array_merge($terms, $iq->qlet->variables); + } + return new Querylet($sql, $terms); + } + + /** + * @param Querylet $img_search + * @return Querylet + */ + private static function build_simple_query($img_search) { + $query = new Querylet("SELECT images.* FROM images "); + + if (!empty($img_search->sql)) { + $query->append_sql(" WHERE "); + $query->append($img_search); + return $query; + } + return $query; + } + /** * WARNING: this description is no longer accurate, though it does get across - * the general idea - the actual method has a few extra optimisiations + * the general idea - the actual method has a few extra optimisations * * "foo bar -baz user=foo" becomes * @@ -763,7 +810,7 @@ class Image { * A) Incredibly simple: * Each search term maps to a list of image IDs * B) Runs really fast on a good database: - * These lists are calucalted once, and the set intersection taken + * These lists are calculated once, and the set intersection taken * C) Runs really slow on bad databases: * All the subqueries are executed every time for every row in the * images table. Yes, MySQL does suck this much. @@ -775,21 +822,12 @@ class Image { global $database; $tag_querylets = array(); - $img_querylets = array(); + $img_querylets = self::parse_meta_terms($terms); $positive_tag_count = 0; - $stpe = new SearchTermParseEvent(null, $terms); - send_event($stpe); - if($stpe->is_querylet_set()) { - foreach($stpe->get_querylets() as $querylet) { - $img_querylets[] = new ImgQuerylet($querylet, true); - } - } - - $terms = Tag::resolve_aliases($terms); - // parse the words that are searched for into // various types of querylet + $terms = Tag::resolve_aliases($terms); foreach($terms as $term) { $positive = true; if(is_string($term) && !empty($term) && ($term[0] == '-')) { @@ -815,41 +853,25 @@ class Image { } } } - - - // merge all the image metadata searches into one generic querylet - $n = 0; - $sql = ""; - $terms = array(); - foreach($img_querylets as $iq) { - if($n++ > 0) $sql .= " AND"; - if(!$iq->positive) $sql .= " NOT"; - $sql .= " (" . $iq->qlet->sql . ")"; - $terms = array_merge($terms, $iq->qlet->variables); - } - $img_search = new Querylet($sql, $terms); + $img_search = self::build_img_search($img_querylets); // How many tag querylets are there? $count_tag_querylets = count($tag_querylets); // no tags, do a simple search (+image metadata if we have any) if($count_tag_querylets === 0) { - $query = new Querylet("SELECT images.* FROM images "); - - if(!empty($img_search->sql)) { - $query->append_sql(" WHERE "); - $query->append($img_search); - } + $query = self::build_simple_query($img_search); } // one positive tag (a common case), do an optimised search else if($count_tag_querylets === 1 && $tag_querylets[0]->positive) { $query = new Querylet($database->scoreql_to_sql(" - SELECT images.* FROM images + SELECT images.* + FROM images JOIN image_tags ON images.id=image_tags.image_id JOIN tags ON image_tags.tag_id=tags.id WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag) - "), array("tag"=>$tag_querylets[0]->tag)); + "), array("tag"=>$tag_querylets[0]->tag)); if(!empty($img_search->sql)) { $query->append_sql(" AND "); @@ -865,10 +887,12 @@ class Image { foreach($tag_querylets as $tq) { $tag_ids = $database->get_col( - $database->scoreql_to_sql( - "SELECT id FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)" - ), - array("tag"=>$tq->tag)); + $database->scoreql_to_sql(" + SELECT id + FROM tags + WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag) + "), array("tag"=>$tq->tag) + ); if($tq->positive) { $positive_tag_id_array = array_merge($positive_tag_id_array, $tag_ids); $tags_ok = count($tag_ids) > 0; @@ -883,7 +907,7 @@ class Image { $have_pos = count($positive_tag_id_array) > 0; $have_neg = count($negative_tag_id_array) > 0; - $sql = "SELECT images.* FROM images WHERE images.id IN ("; + $sql = ""; if($have_pos) { $positive_tag_id_list = join(', ', $positive_tag_id_array); $sql .= " @@ -905,8 +929,11 @@ class Image { WHERE tag_id IN ($negative_tag_id_list) "; } - $sql .= ")"; - $query = new Querylet($sql); + $query = new Querylet(" + SELECT images.* + FROM images + WHERE images.id IN ($sql) + "); if(strlen($img_search->sql) > 0) { $query->append_sql(" AND "); @@ -932,23 +959,16 @@ class Image { * build_accurate_search_querylet() for a full explanation * * @param array $terms + * @return Querylet */ private static function build_ugly_search_querylet($terms) { global $database; $tag_querylets = array(); - $img_querylets = array(); + $img_querylets = self::parse_meta_terms($terms); $positive_tag_count = 0; $negative_tag_count = 0; - $stpe = new SearchTermParseEvent(null, $terms); - send_event($stpe); - if($stpe->is_querylet_set()) { - foreach($stpe->get_querylets() as $querylet) { - $img_querylets[] = new ImgQuerylet($querylet, true); - } - } - $terms = Tag::resolve_aliases($terms); reset($terms); // rewind to first element in array. @@ -990,44 +1010,24 @@ class Image { else $negative_tag_count++; } $tag_search = new Querylet($sql, $terms); - - // merge all the image metadata searches into one generic querylet - $n = 0; - $sql = ""; - $terms = array(); - foreach($img_querylets as $iq) { - if($n++ > 0) $sql .= " AND"; - if(!$iq->positive) $sql .= " NOT"; - $sql .= " (" . $iq->qlet->sql . ")"; - $terms = array_merge($terms, $iq->qlet->variables); - } - $img_search = new Querylet($sql, $terms); - + $img_search = self::build_img_search($img_querylets); // no tags, do a simple search (+image metadata if we have any) if($positive_tag_count + $negative_tag_count == 0) { - $query = new Querylet("SELECT images.*,UNIX_TIMESTAMP(posted) AS posted_timestamp FROM images "); - - if(!empty($img_search->sql)) { - $query->append_sql(" WHERE "); - $query->append($img_search); - } + $query = self::build_simple_query($img_search); } // one positive tag (a common case), do an optimised search else if($positive_tag_count === 1 && $negative_tag_count === 0) { - $query = new Querylet( - // MySQL is braindead, and does a full table scan on images, running the subquery once for each row -_- - // "{$this->get_images} WHERE images.id IN (SELECT image_id FROM tags WHERE tag LIKE ?) ", - " - SELECT images.*, UNIX_TIMESTAMP(posted) AS posted_timestamp - FROM tags, image_tags, images - WHERE - tag LIKE :tag0 - AND tags.id = image_tags.tag_id - AND image_tags.image_id = images.id - ", - $tag_search->variables); + // MySQL is braindead, and does a full table scan on images, running the subquery once for each row -_- + // "{$this->get_images} WHERE images.id IN (SELECT image_id FROM tags WHERE tag LIKE ?) ", + $query = new Querylet(" + SELECT images.* + FROM images + JOIN image_tags ON images.id=image_tags.image_id + JOIN tags ON image_tags.tag_id=tags.id + WHERE tag LIKE :tag0 + ", $tag_search->variables); if(!empty($img_search->sql)) { $query->append_sql(" AND "); @@ -1042,7 +1042,10 @@ class Image { $x = 0; foreach($tag_search->variables as $tag) { - $tag_ids = $database->get_col("SELECT id FROM tags WHERE tag LIKE :tag", array("tag"=>$tag)); + $tag_ids = $database->get_col( + "SELECT id FROM tags WHERE tag LIKE :tag", + array("tag"=>$tag) + ); $tag_id_array = array_merge($tag_id_array, $tag_ids); $tags_ok = count($tag_ids) > 0 || !$tag_querylets[$x]->positive; @@ -1068,7 +1071,7 @@ class Image { ) ); $query = new Querylet(' - SELECT *, UNIX_TIMESTAMP(posted) AS posted_timestamp + SELECT * FROM ('.$subquery->sql.') AS images ', $subquery->variables); if(!empty($img_search->sql)) { @@ -1224,7 +1227,10 @@ class Tag { global $database; $db_wild_tag = str_replace("%", "\%", $tag); $db_wild_tag = str_replace("*", "%", $db_wild_tag); - $newtags = $database->get_col($database->scoreql_to_sql("SELECT tag FROM tags WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(?)"), array($db_wild_tag)); + $newtags = $database->get_col( + $database->scoreql_to_sql("SELECT tag FROM tags WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(?)"), + array($db_wild_tag) + ); if(count($newtags) > 0) { $resolved = $newtags; } else { @@ -1295,7 +1301,7 @@ function move_upload_to_archive(DataUploadEvent $event) { * @param $base string * @return array */ -function add_dir(/*string*/ $base) { +function add_dir($base) { $results = array(); foreach(list_files($base) as $full_path) { @@ -1323,7 +1329,7 @@ function add_dir(/*string*/ $base) { * @param string $tags * @throws UploadException */ -function add_image(/*string*/ $tmpname, /*string*/ $filename, /*string*/ $tags) { +function add_image($tmpname, $filename, $tags) { assert(file_exists($tmpname)); $pathinfo = pathinfo($filename); @@ -1374,4 +1380,3 @@ function get_thumbnail_size(/*int*/ $orig_width, /*int*/ $orig_height) { } } - diff --git a/ext/artists/theme.php b/ext/artists/theme.php index 21be1ccd..cc30e6bd 100644 --- a/ext/artists/theme.php +++ b/ext/artists/theme.php @@ -343,11 +343,8 @@ class ArtistsTheme extends Themelet { "; - if ($userIsLogged) - $html .= ""; - - if ($userIsAdmin) - $html .= ""; + if ($userIsLogged) $html .= ""; + if ($userIsAdmin) $html .= ""; $html .= " @@ -359,17 +356,9 @@ class ArtistsTheme extends Themelet { if ($userIsAdmin) $html .= ""; $html .= ""; - if (count($aliases) > 0) { - $html .= $this->render_aliases($aliases, $userIsLogged, $userIsAdmin); - } - - if (count($members) > 0) { - $html .= $this->render_members($members, $userIsLogged, $userIsAdmin); - } - - if (count($urls) > 0) { - $html .= $this->render_urls($urls, $userIsLogged, $userIsAdmin); - } + $html .= $this->render_aliases($aliases, $userIsLogged, $userIsAdmin); + $html .= $this->render_members($members, $userIsLogged, $userIsAdmin); + $html .= $this->render_urls($urls, $userIsLogged, $userIsAdmin); $html .= " Notes: @@ -406,37 +395,39 @@ class ArtistsTheme extends Themelet { */ private function render_aliases($aliases, $userIsLogged, $userIsAdmin) { $html = ""; - $aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore - $aliasEditLink = "Edit"; - $aliasDeleteLink = "Delete"; + if(count($aliases) > 0) { + $aliasViewLink = str_replace("_", " ", $aliases[0]['alias_name']); // no link anymore + $aliasEditLink = "Edit"; + $aliasDeleteLink = "Delete"; - $html .= " + $html .= " Aliases: " . $aliasViewLink . ""; - if ($userIsLogged) - $html .= "" . $aliasEditLink . ""; + if ($userIsLogged) + $html .= "" . $aliasEditLink . ""; - if ($userIsAdmin) - $html .= "" . $aliasDeleteLink . ""; + if ($userIsAdmin) + $html .= "" . $aliasDeleteLink . ""; - $html .= ""; + $html .= ""; - if (count($aliases) > 1) { - for ($i = 1; $i < count($aliases); $i++) { - $aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore - $aliasEditLink = "Edit"; - $aliasDeleteLink = "Delete"; + if (count($aliases) > 1) { + for ($i = 1; $i < count($aliases); $i++) { + $aliasViewLink = str_replace("_", " ", $aliases[$i]['alias_name']); // no link anymore + $aliasEditLink = "Edit"; + $aliasDeleteLink = "Delete"; - $html .= " + $html .= "   " . $aliasViewLink . ""; - if ($userIsLogged) - $html .= "" . $aliasEditLink . ""; - if ($userIsAdmin) - $html .= "" . $aliasDeleteLink . ""; + if ($userIsLogged) + $html .= "" . $aliasEditLink . ""; + if ($userIsAdmin) + $html .= "" . $aliasDeleteLink . ""; - $html .= ""; + $html .= ""; + } } } return $html; @@ -450,35 +441,37 @@ class ArtistsTheme extends Themelet { */ private function render_members($members, $userIsLogged, $userIsAdmin) { $html = ""; - $memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore - $memberEditLink = "Edit"; - $memberDeleteLink = "Delete"; + if(count($members) > 0) { + $memberViewLink = str_replace("_", " ", $members[0]['name']); // no link anymore + $memberEditLink = "Edit"; + $memberDeleteLink = "Delete"; - $html .= " + $html .= " Members: " . $memberViewLink . ""; - if ($userIsLogged) - $html .= "" . $memberEditLink . ""; - if ($userIsAdmin) - $html .= "" . $memberDeleteLink . ""; + if ($userIsLogged) + $html .= "" . $memberEditLink . ""; + if ($userIsAdmin) + $html .= "" . $memberDeleteLink . ""; - $html .= ""; + $html .= ""; - if (count($members) > 1) { - for ($i = 1; $i < count($members); $i++) { - $memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore - $memberEditLink = "Edit"; - $memberDeleteLink = "Delete"; + if (count($members) > 1) { + for ($i = 1; $i < count($members); $i++) { + $memberViewLink = str_replace("_", " ", $members[$i]['name']); // no link anymore + $memberEditLink = "Edit"; + $memberDeleteLink = "Delete"; - $html .= " + $html .= "   " . $memberViewLink . ""; - if ($userIsLogged) - $html .= "" . $memberEditLink . ""; - if ($userIsAdmin) - $html .= "" . $memberDeleteLink . ""; + if ($userIsLogged) + $html .= "" . $memberEditLink . ""; + if ($userIsAdmin) + $html .= "" . $memberDeleteLink . ""; - $html .= ""; + $html .= ""; + } } } return $html; @@ -492,40 +485,42 @@ class ArtistsTheme extends Themelet { */ private function render_urls($urls, $userIsLogged, $userIsAdmin) { $html = ""; - $urlViewLink = "" . str_replace("_", " ", $urls[0]['url']) . ""; - $urlEditLink = "Edit"; - $urlDeleteLink = "Delete"; + if(count($urls) > 0) { + $urlViewLink = "" . str_replace("_", " ", $urls[0]['url']) . ""; + $urlEditLink = "Edit"; + $urlDeleteLink = "Delete"; - $html .= " + $html .= " URLs: " . $urlViewLink . ""; - if ($userIsLogged) - $html .= "" . $urlEditLink . ""; + if ($userIsLogged) + $html .= "" . $urlEditLink . ""; - if ($userIsAdmin) - $html .= "" . $urlDeleteLink . ""; + if ($userIsAdmin) + $html .= "" . $urlDeleteLink . ""; - $html .= ""; + $html .= ""; - if (count($urls) > 1) { - for ($i = 1; $i < count($urls); $i++) { - $urlViewLink = "" . str_replace("_", " ", $urls[$i]['url']) . ""; - $urlEditLink = "Edit"; - $urlDeleteLink = "Delete"; + if (count($urls) > 1) { + for ($i = 1; $i < count($urls); $i++) { + $urlViewLink = "" . str_replace("_", " ", $urls[$i]['url']) . ""; + $urlEditLink = "Edit"; + $urlDeleteLink = "Delete"; - $html .= " + $html .= "   " . $urlViewLink . ""; - if ($userIsLogged) - $html .= "" . $urlEditLink . ""; + if ($userIsLogged) + $html .= "" . $urlEditLink . ""; - if ($userIsAdmin) - $html .= "" . $urlDeleteLink . ""; + if ($userIsAdmin) + $html .= "" . $urlDeleteLink . ""; - $html .= ""; + $html .= ""; + } + return $html; } - return $html; } return $html; } diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php index 7a3d63e8..8cb65a7b 100644 --- a/ext/numeric_score/main.php +++ b/ext/numeric_score/main.php @@ -107,15 +107,15 @@ class NumericScore extends Extension { if(!empty($_GET['day'])){ $D = (int) $_GET['day']; - if($D >= 1 && $D <= 31) $day = $D; + $day = clamp($D, 1, 31); } if(!empty($_GET['month'])){ $M = (int) $_GET['month']; - if($M >= 1 && $M <= 12) $month = $M; + $month = clamp($M, 1 ,12); } if(!empty($_GET['year'])){ $Y = (int) $_GET['year']; - if($Y >= 1970 && $Y < 2100) $year = $Y; + $year = clamp($Y, 1970, 2100); } $totaldate = $year."/".$month."/".$day; diff --git a/ext/ouroboros_api/main.php b/ext/ouroboros_api/main.php index 674b3da8..69a98433 100644 --- a/ext/ouroboros_api/main.php +++ b/ext/ouroboros_api/main.php @@ -208,7 +208,7 @@ class _SafeOuroborosImage // meta $this->change = intval($img->id); //DaFug is this even supposed to do? ChangeID? // Should be JSON specific, just strip this when converting to XML - $this->created_at = array('n' => 123456789, 's' => $img->posted_timestamp, 'json_class' => 'Time'); + $this->created_at = array('n' => 123456789, 's' => strtotime($img->posted), 'json_class' => 'Time'); $this->id = intval($img->id); $this->parent_id = null; if (defined('ENABLED_EXTS')) { diff --git a/ext/rss_comments/main.php b/ext/rss_comments/main.php index 7b3c17db..91b6a004 100644 --- a/ext/rss_comments/main.php +++ b/ext/rss_comments/main.php @@ -25,16 +25,16 @@ class RSS_Comments extends Extension { $page->set_type("application/rss+xml"); $comments = $database->get_all(" - SELECT + SELECT users.id as user_id, users.name as user_name, comments.comment as comment, comments.id as comment_id, comments.image_id as image_id, comments.owner_ip as poster_ip, - UNIX_TIMESTAMP(posted) AS posted_timestamp - FROM comments - LEFT JOIN users ON comments.owner_id=users.id - ORDER BY comments.id DESC - LIMIT 10 - "); + comments.posted as posted + FROM comments + LEFT JOIN users ON comments.owner_id=users.id + ORDER BY comments.id DESC + LIMIT 10 + "); $data = ""; foreach($comments as $comment) { @@ -42,7 +42,7 @@ class RSS_Comments extends Extension { $comment_id = $comment['comment_id']; $link = make_http(make_link("post/view/$image_id")); $owner = html_escape($comment['user_name']); - $posted = date(DATE_RSS, $comment['posted_timestamp']); + $posted = date(DATE_RSS, strtotime($comment['posted'])); $comment = html_escape($comment['comment']); $content = html_escape("$owner: $comment"); diff --git a/ext/rss_images/main.php b/ext/rss_images/main.php index 4fb500af..5edffddf 100644 --- a/ext/rss_images/main.php +++ b/ext/rss_images/main.php @@ -98,7 +98,7 @@ class RSS_Images extends Extension { $owner = $image->get_owner(); $thumb_url = $image->get_thumb_link(); $image_url = $image->get_image_link(); - $posted = date(DATE_RSS, $image->posted_timestamp); + $posted = date(DATE_RSS, strtotime($image->posted)); $content = html_escape( "

" . $this->theme->build_thumb_html($image) . "

" . "

Uploaded by " . html_escape($owner->name) . "

" diff --git a/ext/shimmie_api/main.php b/ext/shimmie_api/main.php index 4c455f56..7fb13d47 100644 --- a/ext/shimmie_api/main.php +++ b/ext/shimmie_api/main.php @@ -19,8 +19,6 @@ class _SafeImage { -#{"id":"2","height":"768","width":"1024","hash":"71cdfaabbcdad3f777e0b60418532e94","filesize":"439561","filename":"HeilAmu.png","ext":"png","owner_ip":"0.0.0.0","posted":"0000-00-00 00:00:00","source":null,"locked":"N","owner_id":"0","rating":"u","numeric_score":"0","text_score":"0","notes":"0","favorites":"0","posted_timestamp":-62169955200,"tag_array":["cat","kunimitsu"]} - public $id; public $height; public $width; @@ -39,7 +37,7 @@ class _SafeImage { $this->hash = $img->hash; $this->filesize = $img->filesize; $this->ext = $img->ext; - $this->posted = $img->posted_timestamp; + $this->posted = strtotime($img->posted); $this->source = $img->source; $this->owner_id = $img->owner_id; $this->tags = $img->get_tag_array(); diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index 904c36fc..9c34890a 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -56,7 +56,7 @@ class XMLSitemap extends Extension $latestimages_urllist[$arrayid] = "post/view/$image->id"; } - $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp)); + $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", strtotime($image->posted))); /* --- Display page --- */ // when sitemap is ok, display it from the file @@ -88,7 +88,7 @@ class XMLSitemap extends Extension // create url from image id's $latestimages_urllist[$arrayid] = "post/view/$image->id"; } - $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp)); + $this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", strtotime($image->posted))); /* --- Add other tags --- */ $other_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 21,10000000"); @@ -106,7 +106,7 @@ class XMLSitemap extends Extension // create url from image id's $otherimages[$arrayid] = "post/view/$image->id"; } - $this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", $image->posted_timestamp)); + $this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", strtotime($image->posted))); /* --- Display page --- */ diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php index 9efb6b99..aca32af7 100644 --- a/ext/tag_editcloud/main.php +++ b/ext/tag_editcloud/main.php @@ -22,7 +22,7 @@ class TagEditCloud extends Extension { } } } - + public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_bool("tageditcloud_disable", false); @@ -74,16 +74,14 @@ class TagEditCloud extends Extension { $ignore_tags = Tag::explode($config->get_string("tageditcloud_ignoretags")); - if(class_exists("TagCategories")){ + if(ext_is_live("TagCategories")) { $categories = $database->get_all("SELECT category, color FROM image_tag_categories"); $cat_color = array(); - foreach($categories as $row){ + foreach($categories as $row) { $cat_color[$row['category']] = $row['color']; } } - $tag_data = null; - switch($sort_method) { case 'a': case 'p': @@ -99,31 +97,29 @@ class TagEditCloud extends Extension { break; case 'r': $relevant_tags = array_diff($image->get_tag_array(),$ignore_tags); - if(count($relevant_tags) > 0) { - $relevant_tags = implode(",",array_map(array($database,"escape"),$relevant_tags)); - $tag_data = $database->get_all(" - SELECT t2.tag AS tag, COUNT(image_id) AS count, FLOOR(LN(LN(COUNT(image_id) - :tag_min1 + 1)+1)*150)/200 AS scaled - FROM image_tags it1 - JOIN image_tags it2 USING(image_id) - JOIN tags t1 ON it1.tag_id = t1.id - JOIN tags t2 ON it2.tag_id = t2.id - WHERE t1.count >= :tag_min2 AND t1.tag IN($relevant_tags) - GROUP BY t2.tag - ORDER BY count DESC - LIMIT :limit", - array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count)); + if(count($relevant_tags) == 0) { + return null; } + $relevant_tags = implode(",",array_map(array($database,"escape"),$relevant_tags)); + $tag_data = $database->get_all(" + SELECT t2.tag AS tag, COUNT(image_id) AS count, FLOOR(LN(LN(COUNT(image_id) - :tag_min1 + 1)+1)*150)/200 AS scaled + FROM image_tags it1 + JOIN image_tags it2 USING(image_id) + JOIN tags t1 ON it1.tag_id = t1.id + JOIN tags t2 ON it2.tag_id = t2.id + WHERE t1.count >= :tag_min2 AND t1.tag IN($relevant_tags) + GROUP BY t2.tag + ORDER BY count DESC + LIMIT :limit", + array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count)); break; } - if(is_null($tag_data)) { - return null; - } - + $counter = 1; foreach($tag_data as $row) { $full_tag = $row['tag']; - if(class_exists("TagCategories")){ + if(ext_is_live("TagCategories")){ $tc = explode(':',$row['tag']); if(isset($tc[1]) && isset($cat_color[$tc[0]])){ $h_tag = html_escape($tc[1]);