From fa182b95a84ec3c7144e84c69305b724c440422f Mon Sep 17 00:00:00 2001
From: veselcraft
Date: Sun, 18 Jul 2021 02:58:12 +0300
Subject: [PATCH 1/2] Implementation of Localization It features native
encoding support, not only UTF-8 (for example: if the language is Russian,
then the script will encode everything to Windows-1251)
---
index.php | 42 +++++++++++++++++++++++++++++------------
languages/en-us.strings | 21 +++++++++++++++++++++
languages/ru-ru.strings | 22 +++++++++++++++++++++
localization.php | 30 +++++++++++++++++++++++++++++
read.php | 31 ++++++++++++++++++++++++------
5 files changed, 128 insertions(+), 18 deletions(-)
create mode 100644 languages/en-us.strings
create mode 100644 languages/ru-ru.strings
create mode 100644 localization.php
diff --git a/index.php b/index.php
index c5aa35e..9922e7a 100644
--- a/index.php
+++ b/index.php
@@ -1,5 +1,20 @@
trRaw('encoding', $_GET['lg']);
+
+function tr($string) {
+ global $locale;
+ global $encoding;
+ return mb_convert_encoding($locale->trRaw($string, $_GET['lg']), $encoding, 'UTF-8');
+}
+header('Content-Type: text/html;charset='.$encoding);
+
+// Searching
$show_results = FALSE;
$results_html = "";
@@ -10,7 +25,7 @@
$show_results = TRUE;
$search_url = "https://html.duckduckgo.com/html?q=" . $query;
if(!$results_html = file_get_contents($search_url)) {
- $error_text .= "Failed to get results, sorry :(
";
+ $error_text .= tr('error_fail_to_fetch')."
";
}
$simple_results=$results_html;
$simple_results = str_replace( 'strong>', 'b>', $simple_results ); //change to
@@ -25,9 +40,9 @@
// result link, redirected through our proxy
$result_link = explode('class="result__a" href="', $result_blocks[$x])[1];
$result_topline = explode('">', $result_link);
- $result_link = str_replace( '//duckduckgo.com/l/?uddg=', '/read.php?a=', $result_topline[0]);
+ $result_link = str_replace( '//duckduckgo.com/l/?uddg=', '/read.php?lg='.$_GET['lg'].'&a=', $result_topline[0]);
// result title
- $result_title = str_replace("","",explode("\n", $result_topline[1]));
+ $result_title = mb_convert_encoding(str_replace("","",explode("\n", $result_topline[1])), $encoding, 'UTF-8');
// result display url
$result_display_url = explode('class="result__url"', $result_blocks[$x])[1];
$result_display_url = trim(explode("\n", $result_display_url)[1]);
@@ -35,6 +50,7 @@
$result_snippet = explode('class="result__snippet"', $result_blocks[$x])[1];
$result_snippet = explode('">', $result_snippet)[1];
$result_snippet = explode('', $result_snippet)[0];
+ $result_snippet = mb_convert_encoding($result_snippet, $encoding, 'UTF-8');
$final_result_html .= "
" . $result_title[0] . "
"
. $result_display_url . "
" . $result_snippet . "
";
@@ -56,10 +72,10 @@ function clean_str($str) {
?>
-
+
FrogFind!
@@ -67,27 +83,29 @@ function clean_str($str) {
- Search Results for
+ = tr('search_results') ?>
FrogFind!
- The Search Engine for Vintage Computers
+ = tr('frogfind_description') ?>
- Built by Action Retro on YouTube | Why build such a thing?
- Powered by DuckDuckGo
+ = tr('footer_author') ?> | = tr('footer_about') ?>
+ English | Russian
+ = tr('footer_powered') ?>
diff --git a/languages/en-us.strings b/languages/en-us.strings
new file mode 100644
index 0000000..5fb18a2
--- /dev/null
+++ b/languages/en-us.strings
@@ -0,0 +1,21 @@
+"encoding" = "ISO-8859-1";
+"author" = "Sean";
+
+"frogfind_description" = "The Search Engine for Vintage Computers";
+"leap_to" = "Leap to";
+"ribbbit_button" = "Ribbbit!";
+"footer_author" = "Built by Action Retro on YouTube";
+"footer_about" = "Why build such a thing?";
+"footer_powered" = "Powered by DuckDuckGo";
+
+"search_results" = "Search Results for";
+
+%{ Read %}
+"back_to_frogfind" = "Back to";
+"browsing_url" = "Browsing URL";
+"go" = "Go!";
+
+%{ Errors %}
+
+"error_fail_to_fetch" = "Failed to get results, sorry :(";
+"error_not_webpage" = "That's not a web page :(";
\ No newline at end of file
diff --git a/languages/ru-ru.strings b/languages/ru-ru.strings
new file mode 100644
index 0000000..eef70bf
--- /dev/null
+++ b/languages/ru-ru.strings
@@ -0,0 +1,22 @@
+"encoding" = "Windows-1251";
+"author" = "Vladimir Barinov (veselcraft)";
+
+"frogfind_description" = "Поисковая система для винтажных компьютеров";
+"leap_to" = "Запрос";
+"ribbbit_button" = "Найти!";
+"footer_author" = "Сайт создан YouTube-каналом Action Retro";
+"footer_about" = "Зачем нужна эта штука? (на английском)";
+"footer_powered" = "Работает с помощью DuckDuckGo";
+
+"search_results" = "Результаты поиска для запроса";
+
+%{ Read %}
+"back_to_frogfind" = "Вернуться в";
+"browsing_url" = "Адресная строка";
+"go" = "Перейти!";
+
+%{ Errors %}
+
+"error_fail_to_fetch" = "Не удалось выполнить поиск, извините :c";
+"error_not_webpage" = "Это не веб-страница :(";
+"error_article_fail" = "Не получилось показать страницу :(";
diff --git a/localization.php b/localization.php
new file mode 100644
index 0000000..dbd1ef8
--- /dev/null
+++ b/localization.php
@@ -0,0 +1,30 @@
+parseLang(dirname(__FILE__) . "/languages/$lang.strings");
+
+ return $array[$string] ?? "@$string";
+ }
+}
diff --git a/read.php b/read.php
index 922177c..179f403 100644
--- a/read.php
+++ b/read.php
@@ -1,5 +1,24 @@
trRaw('encoding', $_GET['lg']);
+
+function tr($string) {
+ global $encoding;
+ global $locale;
+ return mb_convert_encoding($locale->trRaw($string, $_GET['lg']), $encoding, 'UTF-8');
+}
+
+function localeEncode($string) {
+ global $encoding;
+ return mb_convert_encoding($string, $encoding, 'UTF-8');
+}
+
+header('Content-Type: text/html;charset='.$encoding);
$article_url = "";
$article_html = "";
@@ -18,7 +37,7 @@
}
if (substr( $article_url, 0, 4 ) != "http") {
- echo("That's not a web page :(");
+ echo(tr("error_not_webpage"));
die();
}
@@ -37,7 +56,7 @@
$readability = new Readability($configuration);
if(!$article_html = file_get_contents($article_url)) {
- $error_text .= "Failed to get the article :(
";
+ $error_text .= tr("error_article_fail")."
";
}
try {
@@ -74,12 +93,12 @@ function clean_str($str) {
- getTitle());?>
+ getTitle()));?>
" . $error_text . ""; } ?>
-
+
\ No newline at end of file
From bc091f4950333a108a99a8caaac108fbc262c71d Mon Sep 17 00:00:00 2001
From: veselcraft
Date: Wed, 4 Aug 2021 17:43:06 +0300
Subject: [PATCH 2/2] Fix compatibility with PHP 8
---
index.php | 4 ++--
localization.php | 2 +-
read.php | 7 ++++---
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/index.php b/index.php
index 9922e7a..a407177 100644
--- a/index.php
+++ b/index.php
@@ -4,7 +4,7 @@
// Locale things
-$locale = new Locale;
+$locale = new UILocale;
$encoding = $locale->trRaw('encoding', $_GET['lg']);
function tr($string) {
@@ -112,4 +112,4 @@ function clean_str($str) {
-