From a3bf8741ef46485052114b83cdde5b9e22aaa045 Mon Sep 17 00:00:00 2001 From: friol Date: Tue, 9 Jun 2020 21:24:41 +0200 Subject: [PATCH 1/3] Adding some autocomplete to pouet's search page. --- ajax_bbspost.php | 26 ++++++++++- autocompleter.js | 10 +++- script.js | 116 +++++++++++++++++++++++++++++++++++++++++++++++ search.php | 12 ++++- 4 files changed, 159 insertions(+), 5 deletions(-) diff --git a/ajax_bbspost.php b/ajax_bbspost.php index 59c2ec7..e70031c 100644 --- a/ajax_bbspost.php +++ b/ajax_bbspost.php @@ -3,8 +3,30 @@ header("Content-type: application/json; charset=utf-8"); -$sql = sprintf_esc("select * from bbs_posts where id = %d limit 1",$_POST["id"]); -$r = SQLLib::selectRow($sql); +$sql = new SQLSelect(); +$sql->AddTable("bbs_posts"); +$sql->AddField("bbs_topics.topic as topic"); +$sql->AddField("bbs_topics.id as topicID"); +$sql->AddField("bbs_posts.id as id"); +if ($_POST["search"]) $sql->AddField("'".$_POST["search"]."' as searchQuery"); +$sql->AddField("bbs_posts.post as post"); +$sql->AddField("bbs_posts.added as postDate"); +$sql->AddJoin("left","bbs_topics","bbs_posts.topic = bbs_topics.id"); + +$r = array(); +if ($_POST["search"]) +{ + $sql->AddWhere(sprintf_esc("(bbs_posts.post LIKE '%%%s%%' or bbs_topics.topic LIKE '%%%s%%')",_like($_POST["search"]),_like($_POST["search"]))); + $sql->AddOrder("bbs_posts.added DESC"); + $sql->SetLimit(5); + $r = SQLLib::selectRows( $sql->GetQuery() ); +} +else if ($_POST["id"]) +{ + $sql->AddWhere(sprintf_esc("id = %d",$_POST["id"])); + $sql->SetLimit(1); + $r = SQLLib::selectRows( $sql->GetQuery() ); +} echo json_encode($r); ?> diff --git a/autocompleter.js b/autocompleter.js index 720fb81..f8d068a 100644 --- a/autocompleter.js +++ b/autocompleter.js @@ -25,7 +25,9 @@ Autocompleter = Class.create({ parent.insert(this.finalSelection); } - this.searchBox = new Element("input",{"class":"autocompleteSearch","style":"position:relative","placeholder":this.options.placeholder}); + var searchBoxOptions={"class":"autocompleteSearch","style":"position:relative","placeholder":this.options.placeholder}; + if (this.options.searchBox) { searchBoxOptions["name"]="what"; searchBoxOptions["autocomplete"]="off"; } + this.searchBox = new Element("input",searchBoxOptions); parent.insert( this.searchBox ); if (this.options.dropdown) @@ -163,6 +165,12 @@ Autocompleter = Class.create({ { var item = li.retrieve("item"); + if (this.options.onClickUrl) + { + location.href=this.options.onClickUrl+item.id; + return; + } + this.select( item.id, item.name ); } else diff --git a/script.js b/script.js index 77d4b28..8ddeb5d 100644 --- a/script.js +++ b/script.js @@ -726,6 +726,122 @@ function checkForNewsTickers() }); } +// trims the post content of a bbs topic message, so it fits the autocomplete list +function trimPostContent(postContent,query,maxlen) +{ + if (postContent.indexOf(query)>=0) + { + return postContent.substring(Math.max(0,postContent.indexOf(query)-Math.floor(maxlen/2)),postContent.indexOf(query)+Math.floor(maxlen/2)); + } + else + { + return postContent.substring(0,maxlen); + } +} + +String.prototype.replaceAll = function(strReplace, strWith) +{ + var esc = strReplace.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + var reg = new RegExp(esc, 'ig'); + return this.replace(reg, strWith); +}; + +// switches between different search types on search page: +// "prod","group","party","user","bbs" +function changeSearchType(searchType,pouetContentUrl) +{ + var urlArray={"prod":"./ajax_prods.php", + "group":"./ajax_groups.php", + "party":"./ajax_parties.php", + "user":"./ajax_users.php", + "bbs":"./ajax_bbspost.php"}; + + // empty the search field container + var e = document.getElementById("searchInputSpan"); + var child = e.lastElementChild; + while (child) + { + e.removeChild(child); + child = e.lastElementChild; + } + + // re-add the input field + e.innerHTML=""; + + if (searchType=="prod") + { + new Autocompleter(document.getElementById("pouetSearchInput"), + { + "dataUrl":urlArray[searchType], + "processRow": function(item) { + var s = item.name.escapeHTML(); + if (item.groupName) s += " " + item.groupName.escapeHTML() + ""; + return s; + }, + "onClickUrl":"prod.php?which=", + "searchBox":true + } + ); + } + else if (searchType=="group") + { + new Autocompleter(document.getElementById("pouetSearchInput"), { + "dataUrl":urlArray[searchType], + "processRow": function(item) { + return item.name.escapeHTML() + (item.disambiguation ? " " + item.disambiguation.escapeHTML() + "" : ""); + }, + "onClickUrl":"groups.php?which=", + "searchBox":true + }); + } + else if (searchType=="party") + { + new Autocompleter(document.getElementById("pouetSearchInput"), { + "dataUrl":urlArray[searchType], + "onClickUrl":"party.php?which=", + "searchBox":true + }); + } + else if (searchType=="user") + { + new Autocompleter(document.getElementById("pouetSearchInput"), {"dataUrl":urlArray[searchType], + "processRow": function(item) { + return " " + item.name.escapeHTML() + " " + item.glops + " glöps"; + }, + "onClickUrl":"user.php?who=", + "searchBox":true + }); + } + else if (searchType=="bbs") + { + new Autocompleter(document.getElementById("pouetSearchInput"), {"dataUrl":urlArray[searchType], + "width":500, + "processRow": function(item) + { + var topicName=item.topic; + var postContent=item.post; + + if (topicName.toLowerCase().indexOf(item.searchQuery.toLowerCase())>=0) + { + topicName=topicName.replaceAll(item.searchQuery,""+item.searchQuery+"") + } + + // trim post content to a reasonable size + postContent=trimPostContent(postContent.toLowerCase(),item.searchQuery.toLowerCase(),60); + + if (postContent.toLowerCase().indexOf(item.searchQuery.toLowerCase())>=0) + { + postContent = postContent.replaceAll(item.searchQuery,""+item.searchQuery+"") + } + + return ""+topicName+"
... "+postContent+" ..." ; + }, + "onClickUrl":"topic.php?post=", + "searchBox":true + }); + } +} + // on load scripts - keep this to minimum document.observe("dom:loaded",function(){ Cookie.init({name: 'pouetSettings', expires: 365}); diff --git a/search.php b/search.php index ac63199..82e7b74 100644 --- a/search.php +++ b/search.php @@ -12,14 +12,14 @@ function __construct() { function RenderBody() { echo "
\n"; echo "I'm looking for\n"; - echo "\n"; + echo "\n"; echo "and this is a [\n"; $types = array("prod","group","party"/*,"board"*/,"user","bbs"); $a = array(); $selected = $_GET["type"] ? $_GET["type"] : "prod"; foreach($types as $t) - $a[] = " \n"; + $a[] = " \n"; echo implode(" |\n",$a); @@ -592,3 +592,11 @@ function GetForwardURL() require("include_pouet/menu.inc.php"); require_once("include_pouet/footer.php"); ?> + + From f0a49ea9e4e1dc1a32816f248a0dffce1c13a14b Mon Sep 17 00:00:00 2001 From: friol Date: Thu, 2 Jul 2020 18:27:45 +0200 Subject: [PATCH 2/3] Added the ability to sort productions in the lists.php page --- lists.php | 57 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/lists.php b/lists.php index e73166f..7d80396 100644 --- a/lists.php +++ b/lists.php @@ -103,6 +103,18 @@ function LoadFromDB() $s->Attach(array("list_items"=>"itemid"),array("prods as prod"=>"id")); $s->AddWhere(sprintf_esc("list_items.list=%d",$this->id)); $s->AddWhere("list_items.type='prod'"); + + $dir = "ASC"; + if ($_GET["reverse"]) + $dir = "DESC"; + switch($_GET["order"]) + { + case "type": $s->AddOrder("list_items_prod.type ".$dir); break; + case "name": $s->AddOrder("list_items_prod.name ".$dir); break; + case "party": $s->AddOrder("list_items_prod_party.name ".$dir); break; + case "release date": $s->AddOrder("list_items_prod_releaseDate ".$dir); break; + } + $this->prods = $s->perform(); $a = array(); @@ -193,29 +205,52 @@ function Render() if ($this->prods) { echo "

prods

"; - echo "
    \n"; + echo "\n"; + + $headers = array( + "type"=>"type", + "name"=>"prodname", + "party"=>"release party", + "release date"=>"release date" + ); + echo "\n"; + foreach($headers as $key=>$text) + { + $out = sprintf("\n", + adjust_query_header(array("order"=>$key)),$_GET["order"]==$key?"selected":"",($_GET["order"]==$key && $_GET["reverse"])?" reverse":"","sort_".$key,$text); + if ($key == "type" || $key == "name") $out = str_replace("","",$out); + if ($key == "platform" || $key == "name") $out = str_replace(""; + } + echo "\n"; + foreach($this->prods as $d) { - echo "
  • \n"; - echo "\n"; + echo "
  • \n"; + echo "\n"; + echo "\n"; + echo "\n"; if ($this->CanEdit()) { - printf(" ",$d->prod->id); + printf(" ",$d->prod->id); } - echo "\n"; + echo "\n"; } - echo "\n"; + + echo "
    %s"," ",$out); + echo $out; + } + if ($this->CanEdit()) + { + echo "
    \n"; echo $d->prod->RenderTypeIcons(); echo $d->prod->RenderPlatformIcons(); echo $d->prod->RenderSingleRowShort(); - echo "\n"; - echo "\n"; + echo "\n"; if ($d->prod->placings) echo $d->prod->placings[0]->PrintResult($p->year); - echo "\n"; - echo "\n"; + echo "\n"; echo $d->prod->RenderReleaseDate(); - echo "\n"; + echo "
    "; } if ($this->parties) From 4fb53fc7611b279aee64ef15effd4929c4474a50 Mon Sep 17 00:00:00 2001 From: friol Date: Fri, 3 Jul 2020 15:55:56 +0200 Subject: [PATCH 3/3] Revert "Added the ability to sort productions in the lists.php page" This reverts commit f0a49ea9e4e1dc1a32816f248a0dffce1c13a14b. --- lists.php | 57 +++++++++++-------------------------------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/lists.php b/lists.php index 7d80396..e73166f 100644 --- a/lists.php +++ b/lists.php @@ -103,18 +103,6 @@ function LoadFromDB() $s->Attach(array("list_items"=>"itemid"),array("prods as prod"=>"id")); $s->AddWhere(sprintf_esc("list_items.list=%d",$this->id)); $s->AddWhere("list_items.type='prod'"); - - $dir = "ASC"; - if ($_GET["reverse"]) - $dir = "DESC"; - switch($_GET["order"]) - { - case "type": $s->AddOrder("list_items_prod.type ".$dir); break; - case "name": $s->AddOrder("list_items_prod.name ".$dir); break; - case "party": $s->AddOrder("list_items_prod_party.name ".$dir); break; - case "release date": $s->AddOrder("list_items_prod_releaseDate ".$dir); break; - } - $this->prods = $s->perform(); $a = array(); @@ -205,52 +193,29 @@ function Render() if ($this->prods) { echo "

    prods

    "; - echo "\n"; - - $headers = array( - "type"=>"type", - "name"=>"prodname", - "party"=>"release party", - "release date"=>"release date" - ); - echo "\n"; - foreach($headers as $key=>$text) - { - $out = sprintf("\n", - adjust_query_header(array("order"=>$key)),$_GET["order"]==$key?"selected":"",($_GET["order"]==$key && $_GET["reverse"])?" reverse":"","sort_".$key,$text); - if ($key == "type" || $key == "name") $out = str_replace("","",$out); - if ($key == "platform" || $key == "name") $out = str_replace(""; - } - echo "\n"; - + echo "
      \n"; foreach($this->prods as $d) { - echo "
    \n"; - echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; if ($this->CanEdit()) { - printf(" ",$d->prod->id); + printf(" ",$d->prod->id); } - echo "\n"; + echo "\n"; } - - echo "
    %s"," ",$out); - echo $out; - } - if ($this->CanEdit()) - { - echo "
    \n"; + echo "
  • \n"; + echo "\n"; echo $d->prod->RenderTypeIcons(); echo $d->prod->RenderPlatformIcons(); echo $d->prod->RenderSingleRowShort(); - echo "
  • \n"; + echo "\n"; + echo "\n"; if ($d->prod->placings) echo $d->prod->placings[0]->PrintResult($p->year); - echo "\n"; + echo "\n"; + echo "\n"; echo $d->prod->RenderReleaseDate(); - echo "
    "; + echo "
\n"; } if ($this->parties)