feat: adding pulldown (merge pull request #50 from davidovski/language_dropdown)
Language selection dropdown
This commit is contained in:
commit
0cd23c8e0d
4 changed files with 25 additions and 10 deletions
|
@ -1,13 +1,15 @@
|
|||
<?php
|
||||
class WikipediaRequest extends EngineRequest {
|
||||
public function get_request_url() {
|
||||
$this->wikipedia_language = $this->opts->language;
|
||||
$this->wikipedia_domain = "wikipedia.org";
|
||||
$query_encoded = urlencode($this->query);
|
||||
|
||||
if (!in_array($this->wikipedia_language, json_decode(file_get_contents("static/misc/wikipedia_langs.json"), true)))
|
||||
$this->wikipedia_language = "en";
|
||||
$languages = json_decode(file_get_contents("static/misc/languages.json"), true);
|
||||
|
||||
return "https://$this->wikipedia_language.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
|
||||
if (array_key_exists($this->opts->language, $languages))
|
||||
$this->wikipedia_domain = $languages[$this->opts->language]["wikipedia"] . ".wikipedia.org";
|
||||
|
||||
return "https://$this->wikipedia_domain/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
|
||||
}
|
||||
|
||||
public function parse_results($response) {
|
||||
|
@ -20,7 +22,7 @@
|
|||
|
||||
$description = substr($first_page["extract"], 0, 250) . "...";
|
||||
|
||||
$source = "https://$this->wikipedia_language.wikipedia.org/wiki/$this->query";
|
||||
$source = "https://$this->wikipedia_domain/wiki/$this->query";
|
||||
$response = array(
|
||||
"special_response" => array(
|
||||
"response" => htmlspecialchars($description),
|
||||
|
|
21
settings.php
21
settings.php
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
require "misc/search_engine.php";
|
||||
$opts = load_opts();
|
||||
|
||||
// Reset all cookies when resetting, or before saving new cookies
|
||||
if (isset($_REQUEST["reset"]) || isset($_REQUEST["save"])) {
|
||||
|
@ -29,6 +28,8 @@
|
|||
die();
|
||||
}
|
||||
|
||||
$opts = load_opts();
|
||||
|
||||
require "misc/header.php";
|
||||
?>
|
||||
|
||||
|
@ -59,7 +60,7 @@
|
|||
<option value=\"ubuntu\">Ubuntu</option>
|
||||
<option value=\"tokyo_night\">Tokyo night</option>";
|
||||
|
||||
if (isset($_COOKIE["theme"])) {
|
||||
if (isset($opts->theme)) {
|
||||
$theme = $opts->theme;
|
||||
$themes = str_replace($theme . "\"", $theme . "\" selected", $themes);
|
||||
}
|
||||
|
@ -97,10 +98,22 @@
|
|||
<div class="settings-textbox-container">
|
||||
<div>
|
||||
<span>Language</span>
|
||||
<select name="language">
|
||||
<?php
|
||||
// TODO make this a dropdown
|
||||
echo "<input type=\"text\" name=\"language\" placeholder=\"any\" value=\"" . htmlspecialchars($opts->language ?? "") . "\">";
|
||||
|
||||
$languages = json_decode(file_get_contents("static/misc/languages.json"), true);
|
||||
$options = "";
|
||||
|
||||
$options .= "<option value=\"\" " . (!isset($opts->language) ? "selected" : "") . ">Any</option>";
|
||||
|
||||
foreach ($languages as $lang_code => $language) {
|
||||
$name = $language["name"];
|
||||
$selected = $opts->language == $lang_code ? "selected" : "";
|
||||
$options .= "<option value=\"$lang_code\" $selected>$name</option>";
|
||||
}
|
||||
echo $options;
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label>Number of results per page</label>
|
||||
|
|
1
static/misc/languages.json
Normal file
1
static/misc/languages.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
["ab","ace","ady","af","ak","als","am","an","ang","ar","arc","ary","arz","as","ast","atj","av","avk","awa","ay","az","azb","ba","ban","bar","bat-smg","bcl","be","be-tarask","bg","bh","bi","bjn","bm","bn","bo","bpy","br","bs","bug","bxr","ca","cbk-zam","cdo","ce","ceb","ch","chr","chy","ckb","co","cr","crh","cs","csb","cu","cv","cy","da","de","din","diq","dsb","dty","dv","dz","ee","el","eml","en","eo","es","et","eu","ext","fa","ff","fi","fiu-vro","fj","fo","fr","frp","frr","fur","fy","ga","gag","gan","gcr","gd","gl","glk","gn","gom","gor","got","gu","gv","ha","hak","haw","he","hi","hif","hr","hsb","ht","hu","hy","hyw","ia","id","ie","ig","ik","ilo","inh","io","is","it","iu","ja","jam","jbo","jv","ka","kaa","kab","kbd","kbp","kg","ki","kk","kl","km","kn","ko","koi","krc","ks","ksh","ku","kv","kw","ky","la","lad","lb","lbe","lez","lfn","lg","li","lij","lld","lmo","ln","lo","lt","ltg","lv","mad","mai","map-bms","mdf","mg","mhr","mi","min","mk","ml","mn","mnw","mr","mrj","ms","mt","mwl","my","myv","mzn","na","nah","nap","nds","nds-nl","ne","new","nia","nl","nn","no","nostalgia","nov","nqo","nrm","nso","nv","ny","oc","olo","om","or","os","pa","pag","pam","pap","pcd","pdc","pfl","pi","pih","pl","pms","pnb","pnt","ps","pt","qu","rm","rmy","rn","ro","roa-rup","roa-tara","ru","rue","rw","sa","sah","sat","sc","scn","sco","sd","se","sg","sh","shn","si","simple","sk","skr","sl","sm","smn","sn","so","sq","sr","srn","ss","st","stq","su","sv","sw","szl","szy","ta","tcy","te","tet","tg","th","ti","tk","tl","tn","to","tpi","tr","ts","tt","tum","tw","ty","tyv","udm","ug","uk","ur","uz","ve","vec","vep","vi","vls","vo","wa","war","wo","wuu","xal","xh","xmf","yi","yo","za","zea","zh","zh-classical","zh-min-nan","zh-yue","zu","zh-hans","zh-hant","zh-cn","zh-hk","zh-mo","zh-my","zh-sg","zh-tw"]
|
Loading…
Reference in a new issue