diff --git a/index.php b/index.php index c5aa35e..a407177 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,31 +83,33 @@ function clean_str($str) {
- FrogFind! Leap again: - + FrogFind! : +


-
Search Results for
+



FrogFind!

-

The Search Engine for Vintage Computers

+



- Leap to:
- + :
+ +



-
Built by Action Retro on YouTube | Why build such a thing?

-
Powered by DuckDuckGo
+
|

+
English | Russian
+
- \ No newline at end of file + 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..34b149c --- /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..a4ea678 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 { @@ -47,7 +66,7 @@ $readable_article = str_replace( 'em>', 'i>', $readable_article ); //change to $readable_article = clean_str($readable_article); - $readable_article = str_replace( 'href="http', 'href="/read.php?a=http', $readable_article ); //route links through proxy + $readable_article = str_replace( 'href="http', 'href="/read.php?lg=' . $_GET['lg'] . '&a=http', $readable_article ); //route links through proxy } catch (ParseException $e) { $error_text .= 'Sorry! ' . $e->getMessage() . '
'; @@ -74,12 +93,13 @@ function clean_str($str) {

- Back to FrogFind! | Browsing URL: - + FrogFind! | : + +


-

getTitle());?>

+

getTitle()));?>

" . $error_text . "

"; } ?> -

+

- \ No newline at end of file +