diff --git a/core/_bootstrap.inc.php b/core/_bootstrap.inc.php index df92da94..e8d6559a 100644 --- a/core/_bootstrap.inc.php +++ b/core/_bootstrap.inc.php @@ -10,6 +10,7 @@ require_once "core/sys_config.inc.php"; require_once "core/util.inc.php"; require_once "lib/context.php"; require_once "vendor/autoload.php"; +require_once "core/imageboard.pack.php"; // set up and purify the environment _version_check(); diff --git a/core/block.class.php b/core/block.class.php index 1fbe0e3f..0fffb41f 100644 --- a/core/block.class.php +++ b/core/block.class.php @@ -44,6 +44,14 @@ class Block { */ public $id; + /** + * Should this block count as content for the sake of + * the 404 handler + * + * @var boolean + */ + public $is_content = true; + /** * Construct a block. * @@ -58,7 +66,11 @@ class Block { $this->body = $body; $this->section = $section; $this->position = $position; - $this->id = preg_replace('/[^\w]/', '',str_replace(' ', '_', is_null($id) ? (is_null($header) ? md5($body) : $header) . $section : $id)); + + if(is_null($id)) { + $id = (empty($header) ? md5($body) : $header) . $section; + } + $this->id = preg_replace('/[^\w]/', '',str_replace(' ', '_', $id)); } /** diff --git a/core/database.class.php b/core/database.class.php index 40575f33..ec1a7ce2 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -314,13 +314,8 @@ class MemcacheCache implements CacheEngine { */ public function __construct($args) { $hp = explode(":", $args); - if(class_exists("Memcache")) { - $this->memcache = new Memcache; - @$this->memcache->pconnect($hp[0], $hp[1]); - } - else { - print "no memcache"; exit; - } + $this->memcache = new Memcache; + @$this->memcache->pconnect($hp[0], $hp[1]); } /** @@ -378,6 +373,100 @@ class MemcacheCache implements CacheEngine { */ public function get_misses() {return $this->misses;} } +class MemcachedCache implements CacheEngine { + /** @var \Memcached|null */ + public $memcache=null; + /** @var int */ + private $hits=0; + /** @var int */ + private $misses=0; + + /** + * @param string $args + */ + public function __construct($args) { + $hp = explode(":", $args); + $this->memcache = new Memcached; + #$this->memcache->setOption(Memcached::OPT_COMPRESSION, False); + #$this->memcache->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP); + #$this->memcache->setOption(Memcached::OPT_PREFIX_KEY, phpversion()); + $this->memcache->addServer($hp[0], $hp[1]); + } + + /** + * @param string $key + * @return array|bool|string + */ + public function get($key) { + assert('!is_null($key)'); + $key = urlencode($key); + + $val = $this->memcache->get($key); + $res = $this->memcache->getResultCode(); + + if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { + $hit = $res == Memcached::RES_SUCCESS ? "hit" : "miss"; + file_put_contents("data/cache.log", "Cache $hit: $key\n", FILE_APPEND); + } + if($res == Memcached::RES_SUCCESS) { + $this->hits++; + return $val; + } + else if($res == Memcached::RES_NOTFOUND) { + $this->misses++; + return false; + } + else { + error_log("Memcached error during get($key): $res"); + } + } + + /** + * @param string $key + * @param mixed $val + * @param int $time + */ + public function set($key, $val, $time=0) { + assert('!is_null($key)'); + $key = urlencode($key); + + $this->memcache->set($key, $val, $time); + $res = $this->memcache->getResultCode(); + if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { + file_put_contents("data/cache.log", "Cache set: $key ($time)\n", FILE_APPEND); + } + if($res != Memcached::RES_SUCCESS) { + error_log("Memcached error during set($key): $res"); + } + } + + /** + * @param string $key + */ + public function delete($key) { + assert('!is_null($key)'); + $key = urlencode($key); + + $this->memcache->delete($key); + $res = $this->memcache->getResultCode(); + if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { + file_put_contents("data/cache.log", "Cache delete: $key\n", FILE_APPEND); + } + if($res != Memcached::RES_SUCCESS && $res != Memcached::RES_NOTFOUND) { + error_log("Memcached error during delete($key): $res"); + } + } + + /** + * @return int + */ + public function get_hits() {return $this->hits;} + + /** + * @return int + */ + public function get_misses() {return $this->misses;} +} class APCCache implements CacheEngine { public $hits=0, $misses=0; @@ -466,10 +555,13 @@ class Database { private function connect_cache() { $matches = array(); - if(defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|apc)://(.*)#", CACHE_DSN, $matches)) { + if(defined("CACHE_DSN") && CACHE_DSN && preg_match("#(memcache|memcached|apc)://(.*)#", CACHE_DSN, $matches)) { if($matches[1] == "memcache") { $this->cache = new MemcacheCache($matches[2]); } + else if($matches[1] == "memcached") { + $this->cache = new MemcachedCache($matches[2]); + } else if($matches[1] == "apc") { $this->cache = new APCCache($matches[2]); } @@ -598,18 +690,15 @@ class Database { * @param string $sql */ private function count_execs($db, $sql, $inputarray) { - if ((defined('DEBUG_SQL') && DEBUG_SQL === true) || (!defined('DEBUG_SQL') && @$_GET['DEBUG_SQL'])) { - $fp = @fopen("data/sql.log", "a"); - if($fp) { - $sql = trim(preg_replace('/\s+/msi', ' ', $sql)); - if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) { - fwrite($fp, $sql." -- ".join(", ", $inputarray)."\n"); - } - else { - fwrite($fp, $sql."\n"); - } - fclose($fp); + if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { + $sql = trim(preg_replace('/\s+/msi', ' ', $sql)); + if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) { + $text = $sql." -- ".join(", ", $inputarray)."\n"; } + else { + $text = $sql."\n"; + } + file_put_contents("data/sql.log", $text, FILE_APPEND); } if(!is_array($inputarray)) $this->query_count++; # handle 2-dimensional input arrays @@ -617,6 +706,14 @@ class Database { else $this->query_count++; } + private function count_time($method, $start) { + if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { + $text = $method.":".(microtime(true) - $start)."\n"; + file_put_contents("data/sql.log", $text, FILE_APPEND); + } + $this->dbtime += microtime(true) - $start; + } + /** * Execute an SQL query and return an PDO result-set. * @@ -661,7 +758,7 @@ class Database { public function get_all($query, $args=array()) { $_start = microtime(true); $data = $this->execute($query, $args)->fetchAll(); - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_all", $_start); return $data; } @@ -675,7 +772,7 @@ class Database { public function get_row($query, $args=array()) { $_start = microtime(true); $row = $this->execute($query, $args)->fetch(); - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_row", $_start); return $row ? $row : null; } @@ -693,7 +790,7 @@ class Database { foreach($stmt as $row) { $res[] = $row[0]; } - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_col", $_start); return $res; } @@ -711,7 +808,7 @@ class Database { foreach($stmt as $row) { $res[$row[0]] = $row[1]; } - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_pairs", $_start); return $res; } @@ -725,7 +822,7 @@ class Database { public function get_one($query, $args=array()) { $_start = microtime(true); $row = $this->execute($query, $args)->fetch(); - $this->dbtime += microtime(true) - $_start; + $this->count_time("get_one", $_start); return $row[0]; } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 755de669..0ee89a09 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -189,7 +189,7 @@ class Image { * @param string[] $tags * @return boolean */ - public function validate_accel($tags) { + public static function validate_accel($tags) { $yays = 0; $nays = 0; foreach($tags as $tag) { @@ -209,7 +209,7 @@ class Image { * @return null|PDOStatement * @throws SCoreException */ - public function get_accelerated_result($tags, $offset, $limit) { + public static function get_accelerated_result($tags, $offset, $limit) { global $database; if(!Image::validate_accel($tags)) { @@ -282,8 +282,7 @@ class Image { } else { $querylet = Image::build_search_querylet($tags); - $result = $database->execute($querylet->sql, $querylet->variables); - return $result->rowCount(); + return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables); } } @@ -967,7 +966,7 @@ class Image { } } - assert('$positive_tag_id_array || $negative_tag_id_array'); + assert('$positive_tag_id_array || $negative_tag_id_array', @$_GET['q']); $wheres = array(); if (!empty($positive_tag_id_array)) { $positive_tag_id_list = join(', ', $positive_tag_id_array); @@ -1210,7 +1209,7 @@ function move_upload_to_archive(DataUploadEvent $event) { * Add a directory full of images * * @param $base string - * @return array + * @return array|string[] */ function add_dir($base) { $results = array(); @@ -1250,7 +1249,7 @@ function add_image($tmpname, $filename, $tags) { $metadata = array(); $metadata['filename'] = $pathinfo['basename']; $metadata['extension'] = $pathinfo['extension']; - $metadata['tags'] = $tags; + $metadata['tags'] = Tag::explode($tags); $metadata['source'] = null; $event = new DataUploadEvent($tmpname, $metadata); send_event($event); diff --git a/core/util.inc.php b/core/util.inc.php index 6b0e081c..f6a357ec 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -966,6 +966,17 @@ function data_path($filename) { return $filename; } +if (!function_exists('mb_strlen')) { + // TODO: we should warn the admin that they are missing multibyte support + function mb_strlen($str, $encoding) { + return strlen($str); + } + function mb_internal_encoding($encoding) {} + function mb_strtolower($str) { + return strtolower($str); + } +} + /** * @param string $url * @param string $mfile diff --git a/ext/blocks/main.php b/ext/blocks/main.php index 43043370..d1f0f6cf 100644 --- a/ext/blocks/main.php +++ b/ext/blocks/main.php @@ -42,7 +42,9 @@ class Blocks extends Extension { foreach($blocks as $block) { $path = implode("/", $event->args); if(strlen($path) < 4000 && fnmatch($block['pages'], $path)) { - $page->add_block(new Block($block['title'], $block['content'], $block['area'], $block['priority'])); + $b = new Block($block['title'], $block['content'], $block['area'], $block['priority']); + $b->is_content = false; + $page->add_block($b); } } diff --git a/ext/bulk_add_csv/main.php b/ext/bulk_add_csv/main.php index 34645e91..a5b999e7 100644 --- a/ext/bulk_add_csv/main.php +++ b/ext/bulk_add_csv/main.php @@ -73,7 +73,7 @@ class BulkAddCSV extends Extension { $metadata = array(); $metadata['filename'] = $pathinfo['basename']; $metadata['extension'] = $pathinfo['extension']; - $metadata['tags'] = $tags; + $metadata['tags'] = Tag::explode($tags); $metadata['source'] = $source; $event = new DataUploadEvent($tmpname, $metadata); send_event($event); diff --git a/ext/chatbox/main.php b/ext/chatbox/main.php index 1ac474c4..80081d46 100644 --- a/ext/chatbox/main.php +++ b/ext/chatbox/main.php @@ -30,6 +30,7 @@ class Chatbox extends Extension { // loads the chatbox at the set location $html = "
"; $chatblock = new Block("Chatbox", $html, "main", 97); + $chatblock->is_content = false; $page->add_block($chatblock); } } diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index 182a1848..a9b05650 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -304,9 +304,14 @@ class CronUploader extends Extension { /** * Generate the necessary DataUploadEvent for a given image and tags. + * + * @param string $tmpname + * @param string $filename + * @param string $tags */ private function add_image($tmpname, $filename, $tags) { assert ( file_exists ( $tmpname ) ); + assert('is_string($tags)'); $pathinfo = pathinfo ( $filename ); if (! array_key_exists ( 'extension', $pathinfo )) { @@ -315,7 +320,7 @@ class CronUploader extends Extension { $metadata = array(); $metadata ['filename'] = $pathinfo ['basename']; $metadata ['extension'] = $pathinfo ['extension']; - $metadata ['tags'] = ""; // = $tags; doesn't work when not logged in here + $metadata ['tags'] = array(); // = $tags; doesn't work when not logged in here $metadata ['source'] = null; $event = new DataUploadEvent ( $tmpname, $metadata ); send_event ( $event ); @@ -329,7 +334,7 @@ class CronUploader extends Extension { // Set tags $img = Image::by_id($event->image_id); - $img->set_tags($tags); + $img->set_tags(Tag::explode($tags)); } private function generate_image_queue($base = "", $subdir = "") { diff --git a/ext/handle_404/main.php b/ext/handle_404/main.php index b7996848..a17e80f7 100644 --- a/ext/handle_404/main.php +++ b/ext/handle_404/main.php @@ -43,10 +43,7 @@ class Handle404 extends Extension { private function count_main($blocks) { $n = 0; foreach($blocks as $block) { - if($block->section == "main") $n++; // more hax. - } - if(ext_is_live("Chatbox")) { - $n--; // even more hax. + if($block->section == "main" && $block->is_content) $n++; // more hax. } return $n; } diff --git a/ext/handle_archive/main.php b/ext/handle_archive/main.php index 1fe56ca6..ad43c4ac 100644 --- a/ext/handle_archive/main.php +++ b/ext/handle_archive/main.php @@ -35,8 +35,10 @@ class ArchiveFileHandler extends Extension { exec($cmd); $results = add_dir($tmpdir); if(count($results) > 0) { - // FIXME no theme? - $this->theme->add_status("Adding files", $results); + // Not all themes have the add_status() method, so need to check before calling. + if (method_exists($this->theme, "add_status")) { + $this->theme->add_status("Adding files", $results); + } } deltree($tmpdir); $event->image_id = -2; // default -1 = upload wasn't handled diff --git a/ext/handle_flash/main.php b/ext/handle_flash/main.php index 6122cb46..719648d4 100644 --- a/ext/handle_flash/main.php +++ b/ext/handle_flash/main.php @@ -37,7 +37,7 @@ class FlashFileHandler extends DataHandlerExtension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; $info = getimagesize($filename); diff --git a/ext/handle_ico/main.php b/ext/handle_ico/main.php index beda9596..31d5e337 100644 --- a/ext/handle_ico/main.php +++ b/ext/handle_ico/main.php @@ -67,7 +67,7 @@ class IcoFileHandler extends Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_mp3/main.php b/ext/handle_mp3/main.php index 9bbbe55a..4f0eae9e 100644 --- a/ext/handle_mp3/main.php +++ b/ext/handle_mp3/main.php @@ -43,7 +43,7 @@ class MP3FileHandler extends DataHandlerExtension { $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 38ba6b3d..149677eb 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -35,7 +35,7 @@ class PixelFileHandler extends DataHandlerExtension { $image->hash = $metadata['hash']; $image->filename = (($pos = strpos($metadata['filename'],'?')) !== false) ? substr($metadata['filename'],0,$pos) : $metadata['filename']; $image->ext = (($pos = strpos($metadata['extension'],'?')) !== false) ? substr($metadata['extension'],0,$pos) : $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_svg/main.php b/ext/handle_svg/main.php index c932f6ba..2e58dbd3 100644 --- a/ext/handle_svg/main.php +++ b/ext/handle_svg/main.php @@ -75,7 +75,7 @@ class SVGFileHandler extends Extension { $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; $image->ext = $metadata['extension']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index 4edbcc32..a31ac781 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -170,7 +170,7 @@ class VideoFileHandler extends DataHandlerExtension { $image->filesize = $metadata['size']; $image->hash = $metadata['hash']; $image->filename = $metadata['filename']; - $image->tag_array = $metadata['tags']; + $image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']); $image->source = $metadata['source']; return $image; diff --git a/ext/handle_video/theme.php b/ext/handle_video/theme.php index 9cc28fa5..21d4ac61 100644 --- a/ext/handle_video/theme.php +++ b/ext/handle_video/theme.php @@ -9,8 +9,9 @@ class VideoFileHandlerTheme extends Themelet { $full_url = make_http($ilink); $autoplay = $config->get_bool("video_playback_autoplay"); $loop = $config->get_bool("video_playback_loop"); + $player = make_link('lib/vendor/swf/flashmediaelement.swf'); - $html = "Video not playing? Click here to download the file.
"; + $html = "Video not playing? Click here to download the file.
"; //Browser media format support: https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats $supportedExts = ['mp4' => 'video/mp4', 'm4v' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm', 'flv' => 'video/flv']; @@ -22,8 +23,8 @@ class VideoFileHandlerTheme extends Themelet { } $html_fallback = " - - + + diff --git a/ext/index/main.php b/ext/index/main.php index 49e53781..29d225ea 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -265,7 +265,7 @@ class Index extends Extension { $images = $database->cache->get("post-list:$page_number"); if(!$images) { $images = Image::find_images(($page_number-1)*$page_size, $page_size, $search_terms); - $database->cache->set("post-list:$page_number", $images, 600); + $database->cache->set("post-list:$page_number", $images, 60); } } else { diff --git a/ext/oekaki/main.php b/ext/oekaki/main.php index bf4c804d..c26c1019 100644 --- a/ext/oekaki/main.php +++ b/ext/oekaki/main.php @@ -31,7 +31,7 @@ class Oekaki extends Extension { $metadata = array(); $metadata['filename'] = 'oekaki.png'; $metadata['extension'] = $pathinfo['extension']; - $metadata['tags'] = 'oekaki tagme'; + $metadata['tags'] = Tag::explode('oekaki tagme'); $metadata['source'] = null; $duev = new DataUploadEvent($tmpname, $metadata); send_event($duev); diff --git a/ext/ouroboros_api/main.php b/ext/ouroboros_api/main.php index 95a69d97..963832a2 100644 --- a/ext/ouroboros_api/main.php +++ b/ext/ouroboros_api/main.php @@ -500,7 +500,7 @@ class OuroborosAPI extends Extension } } $meta = array(); - $meta['tags'] = $post->tags; + $meta['tags'] = is_array($post->tags) ? $post->tags : Tag::explode($post->tags); $meta['source'] = $post->source; if (defined('ENABLED_EXTS')) { if (strstr(ENABLED_EXTS, 'rating') !== false) { @@ -536,7 +536,8 @@ class OuroborosAPI extends Extension if (!is_null($img)) { $handler = $config->get_string("upload_collision_handler"); if($handler == "merge") { - $merged = array_merge(Tag::explode($post->tags), $img->get_tag_array()); + $postTags = is_array($post->tags) ? $post->tags : Tag::explode($post->tags); + $merged = array_merge($postTags, $img->get_tag_array()); send_event(new TagSetEvent($img, $merged)); // This is really the only thing besides tags we should care diff --git a/ext/regen_thumb/main.php b/ext/regen_thumb/main.php index ec48c649..16a00f7a 100644 --- a/ext/regen_thumb/main.php +++ b/ext/regen_thumb/main.php @@ -15,13 +15,24 @@ class RegenThumb extends Extension { public function onPageRequest(PageRequestEvent $event) { - global $page, $user; + global $database, $page, $user; - if($event->page_matches("regen_thumb") && $user->can("delete_image") && isset($_POST['image_id'])) { + if($event->page_matches("regen_thumb/one") && $user->can("delete_image") && isset($_POST['image_id'])) { $image = Image::by_id(int_escape($_POST['image_id'])); send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true)); $this->theme->display_results($page, $image); } + if($event->page_matches("regen_thumb/mass") && $user->can("delete_image") && isset($_POST['tags'])) { + $tags = Tag::explode(strtolower($_POST['tags']), false); + $images = Image::find_images(0, 10000, $tags); + + foreach($images as $image) { + send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true)); + } + + $page->set_mode("redirect"); + $page->set_redirect(make_link("post/list")); + } } public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) { @@ -30,5 +41,12 @@ class RegenThumb extends Extension { $event->add_part($this->theme->get_buttons_html($event->image->id)); } } + + public function onPostListBuilding(PostListBuildingEvent $event) { + global $user; + if($user->can("delete_image") && !empty($event->search_terms)) { + $event->add_control($this->theme->mtr_html(implode(" ", $event->search_terms))); + } + } } diff --git a/ext/regen_thumb/theme.php b/ext/regen_thumb/theme.php index e7de3afb..aec02c9d 100644 --- a/ext/regen_thumb/theme.php +++ b/ext/regen_thumb/theme.php @@ -9,7 +9,7 @@ class RegenThumbTheme extends Themelet { */ public function get_buttons_html($image_id) { return " - ".make_form(make_link("regen_thumb"))." + ".make_form(make_link("regen_thumb/one"))." @@ -29,5 +29,15 @@ class RegenThumbTheme extends Themelet { $page->add_block(new NavBlock()); $page->add_block(new Block("Thumbnail", $this->build_thumb_html($image))); } + + public function mtr_html($terms) { + $h_terms = html_escape($terms); + $html = make_form(make_link("regen_thumb/mass"), "POST") . " + + + + "; + return $html; + } } diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index c97ebac4..8649a18a 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -46,7 +46,7 @@ class TagList extends Extension { $this->theme->display_page($page); } else if($event->page_matches("api/internal/tag_list/complete")) { - if(!isset($_GET["s"])) return; + if(!isset($_GET["s"]) || $_GET["s"] == "" || $_GET["s"] == "_") return; //$limit = 0; $cache_key = "autocomplete-" . strtolower($_GET["s"]); @@ -269,7 +269,7 @@ class TagList extends Extension { $cache_key = data_path("cache/tag_alpha-" . md5("ta" . $tags_min . $starts_with) . ".html"); if(file_exists($cache_key)) {return file_get_contents($cache_key);} - $tag_data = $database->get_all($database->scoreql_to_sql(" + $tag_data = $database->get_pairs($database->scoreql_to_sql(" SELECT tag, count FROM tags WHERE count >= :tags_min @@ -296,8 +296,10 @@ class TagList extends Extension { mb_internal_encoding('UTF-8'); $lastLetter = ""; - foreach($tag_data as $row) { - $tag = $row['tag']; + # postres utf8 string sort ignores punctuation, so we get "aza, a-zb, azc" + # which breaks down into "az, a-, az" :( + ksort($tag_data, SORT_STRING | SORT_FLAG_CASE); + foreach($tag_data as $tag => $count) { if($lastLetter != mb_strtolower(substr($tag, 0, count($starts_with)+1))) { $lastLetter = mb_strtolower(substr($tag, 0, count($starts_with)+1)); $h_lastLetter = html_escape($lastLetter); @@ -305,7 +307,6 @@ class TagList extends Extension { } $link = $this->tag_link($tag); $h_tag = html_escape($tag); - $count = $row['count']; $html .= "$h_tag ($count)\n"; } diff --git a/ext/view/theme.php b/ext/view/theme.php index 64bd1a57..17b96694 100644 --- a/ext/view/theme.php +++ b/ext/view/theme.php @@ -30,11 +30,9 @@ class ViewImageTheme extends Themelet { protected function build_pin(Image $image) { if(isset($_GET['search'])) { - $search_terms = explode(' ', $_GET['search']); $query = "search=".url_escape($_GET['search']); } else { - $search_terms = array(); $query = null; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d17b242a..961c0c0b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -132,7 +132,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit_Framework_TestCase { // post things /** * @param string $filename - * @param string|string[] $tags + * @param string $tags * @return int */ protected function post_image($filename, $tags) {