Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php
require_once('vendor/autoload.php');
require_once('localization.php');

// Locale things

$locale = new UILocale;
$encoding = $locale->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 = "";
Expand All @@ -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 :( <br>";
$error_text .= tr('error_fail_to_fetch')."<br>";
}
$simple_results=$results_html;
$simple_results = str_replace( 'strong>', 'b>', $simple_results ); //change <strong> to <b>
Expand All @@ -25,16 +40,17 @@
// 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("</a>","",explode("\n", $result_topline[1]));
$result_title = mb_convert_encoding(str_replace("</a>","",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]);
// result snippet
$result_snippet = explode('class="result__snippet"', $result_blocks[$x])[1];
$result_snippet = explode('">', $result_snippet)[1];
$result_snippet = explode('</a>', $result_snippet)[0];
$result_snippet = mb_convert_encoding($result_snippet, $encoding, 'UTF-8');

$final_result_html .= "<br><a href='" . $result_link . "'><font size='4'><b>" . $result_title[0] . "</b></font><br><font color='#008000' size='2'>"
. $result_display_url . "</font></a><br>" . $result_snippet . "<br><br><hr>";
Expand All @@ -56,42 +72,44 @@ function clean_str($str) {

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 2.0//EN">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; CHARSET=<?= $encoding ?>">
<title>FrogFind!</title>
</head>
<body>

<?php if($show_results) { // there's a search query in q, so show search results ?>

<form action="/" method="get">
<a href="/"><font size=6 color="#008000">Frog</font><font size=6 color="#000000">Find!</font></a> Leap again: <input type="text" size="30" name="q" value="<?php echo urldecode($query) ?>">
<input type="submit" value="Ribbbit!">
<a href="/"><font size=6 color="#008000">Frog</font><font size=6 color="#000000">Find!</font></a> <?= tr('leap_to') ?>: <input type="text" size="30" name="q" value="<?php echo urldecode($query) ?>">
<input type="submit" value="<?= tr('ribbbit_button') ?>">
</form>
<hr>
<br>
<center>Search Results for <b><?php echo strip_tags(urldecode($query)) ?></b></center>
<center><?= tr('search_results') ?> <b><?php echo strip_tags(urldecode($query)) ?></b></center>
<br>
<?php echo $final_result_html ?>

<?php } else { // no search query, so show new search ?>
<br><br><center><h1><font size=7><font color="#008000">Frog</font>Find!</font></h1></center>
<center><h3>The Search Engine for Vintage Computers</h3></center>
<center><h3><?= tr('frogfind_description') ?></h3></center>
<br><br>
<center>
<form action="/" method="get">
Leap to: <input type="text" size="30" name="q"><br>
<input type="submit" value="Ribbbit!">
<?= tr('leap_to') ?>: <input type="text" size="30" name="q"><br>
<?php if(isset($_GET['lg'])) { ?> <input type="hidden" name="lg" value="<?= $_GET['lg'] ?>"> <?php } ?>
<input type="submit" value="<?= tr('ribbbit_button') ?>">
</center>
<br><br><br>
<small><center>Built by <b><a href="https://youtube.com/ActionRetro">Action Retro</a></b> on YouTube | <a href="about.php">Why build such a thing?</a></center><br>
<small><center>Powered by DuckDuckGo</center></small>
<small><center><?= tr('footer_author') ?> | <a href="about.php"><?= tr('footer_about') ?></a></center><br>
<small><center><a href="?lg=en-us">English</a> | <a href="?lg=ru-ru">Russian</a></center></small>
<small><center><?= tr('footer_powered') ?></center></small>
</form>
</form>

<?php } ?>

</body>
</html>
</html>
21 changes: 21 additions & 0 deletions languages/en-us.strings
Original file line number Diff line number Diff line change
@@ -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 :(";
22 changes: 22 additions & 0 deletions languages/ru-ru.strings
Original file line number Diff line number Diff line change
@@ -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" = "Не получилось показать страницу :(";
30 changes: 30 additions & 0 deletions localization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php


class UILocale {
protected function parseLang($file): array
{
$string = file_get_contents($file);
$string = preg_replace("%^\%{.*\%}\r?$%m", "", $string); #Remove comments
$array = [];

foreach(preg_split("%;[\\r\\n]++%", $string) as $statement) {
$s = explode(" = ", trim($statement));

try {
$array[eval("return $s[0];")] = eval("return $s[1];");
} catch(\ParseError $ex) {
echo "Could not parse locale :( At " . $s[0];
}
}

return $array;
}

function trRaw($string, $locale) {
$lang = empty($locale) ? "en-us" : $locale;
$array = $this->parseLang(dirname(__FILE__) . "/languages/$lang.strings");

return $array[$string] ?? "@$string";
}
}
36 changes: 28 additions & 8 deletions read.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<?php
require_once('vendor/autoload.php');
require_once('localization.php');

// Locale things

$locale = new UILocale;
$encoding = $locale->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 = "";
Expand All @@ -18,7 +37,7 @@
}

if (substr( $article_url, 0, 4 ) != "http") {
echo("That's not a web page :(");
echo(tr("error_not_webpage"));
die();
}

Expand All @@ -37,7 +56,7 @@
$readability = new Readability($configuration);

if(!$article_html = file_get_contents($article_url)) {
$error_text .= "Failed to get the article :( <br>";
$error_text .= tr("error_article_fail")." <br>";
}

try {
Expand All @@ -47,7 +66,7 @@
$readable_article = str_replace( 'em>', 'i>', $readable_article ); //change <em> to <i>

$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() . '<br>';
Expand All @@ -74,12 +93,13 @@ function clean_str($str) {
<body>
<p>
<form action="/read.php" method="get">
<a href="/">Back to <b><font color="#008000">Frog</font><font color="000000">Find!</font></a></b> | Browsing URL: <input type="text" size="38" name="a" value="<?php echo $article_url ?>">
<input type="submit" value="Go!">
<a href="/?lg=<?= $_GET['lg'] ?>"><?= tr('back_to_frogfind'); ?> <b><font color="#008000">Frog</font><font color="000000">Find!</font></a></b> | <?= tr('browsing_url'); ?>: <input type="text" size="38" name="a" value="<?php echo $article_url ?>">
<input type="hidden" name="lg" value="<?= $_GET['lg']; ?>">
<input type="submit" value="<?= tr('go'); ?>">
</form>
</p>
<hr>
<h1><?php echo clean_str($readability->getTitle());?></h1>
<h1><?php echo localeEncode(clean_str($readability->getTitle()));?></h1>
<p> <?php
$img_num = 0;
$imgline_html = "View page images:";
Expand All @@ -95,6 +115,6 @@ function clean_str($str) {
}
?></small></p>
<?php if($error_text) { echo "<p><font color='red'>" . $error_text . "</font></p>"; } ?>
<p><font size="4"><?php echo $readable_article;?></font></p>
<p><font size="4"><?php echo localeEncode($readable_article);?></font></p>
</body>
</html>
</html>