📱Add mobile support

This commit is contained in:
Victor Bodinaud
2025-03-18 11:26:37 +01:00
parent d70edb9f2e
commit dd78fcafd9
7 changed files with 391 additions and 226 deletions

104
read.php
View File

@@ -17,15 +17,15 @@ $compatible_content_types = [
// a direct link to the file.
$proxy_download_max_filesize = 8000000; // ~ 8Mb
if( isset( $_GET['a'] ) ) {
if (isset($_GET['a'])) {
$article_url = $_GET["a"];
} else {
echo "What do you think you're doing... >:(";
exit();
}
if (substr( $article_url, 0, 4 ) != "http") {
echo("That's not a web page :(");
if (substr($article_url, 0, 4) != "http") {
echo ("That's not a web page :(");
die();
}
@@ -38,8 +38,7 @@ $headers = get_headers($article_url, true, $context);
if (!array_key_exists('Content-Type', $headers) || !array_key_exists('Content-Length', $headers)) {
$error_text .= "Failed to get the article, its server did not return expected details :( <br>";
}
else {
} else {
// Attempt to handle downloads or other mime-types by passing proxying them through.
if (!in_array($headers['Content-Type'], $compatible_content_types)) {
$filesize = $headers['Content-Length'];
@@ -49,12 +48,11 @@ else {
echo 'Failed to proxy file download, it\'s too large. :( <br>';
echo 'You can try downloading the file directly: ' . $article_url;
die();
}
else {
} else {
$contentType = $headers['Content-Type'];
// Only use the last-provided content type if an array was returned (ie. when there were redirects involved)
if (is_array($contentType)) {
$contentType = $contentType[count($contentType)-1];
$contentType = $contentType[count($contentType) - 1];
}
$filename = basename($url['path']);
@@ -63,12 +61,12 @@ else {
if (!$filename) {
$filename = "download";
}
// Set the content headers based on the file we're proxying through.
header('Content-Type: ' . $contentType);
header('Content-Length: ' . $filesize);
// Set the content-disposition to encourage the browser to download the file.
header('Content-Disposition: attachment; filename="'. $filename . '"');
header('Content-Disposition: attachment; filename="' . $filename . '"');
// Use readfile
readfile($article_url);
@@ -89,50 +87,73 @@ $configuration
$readability = new Readability($configuration);
if(!$article_html = file_get_contents($article_url)) {
if (!$article_html = file_get_contents($article_url)) {
$error_text .= "Failed to get the article :( <br>";
}
try {
$readability->parse($article_html);
$readable_article = strip_tags($readability->getContent(), '<a><ol><ul><li><br><p><small><font><b><strong><i><em><blockquote><h1><h2><h3><h4><h5><h6>');
$readable_article = str_replace( 'strong>', 'b>', $readable_article ); //change <strong> to <b>
$readable_article = str_replace( 'em>', 'i>', $readable_article ); //change <em> to <i>
$readable_article = str_replace('strong>', 'b>', $readable_article); //change <strong> to <b>
$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?a=http', $readable_article); //route links through proxy
} catch (ParseException $e) {
$error_text .= 'Sorry! ' . $e->getMessage() . '<br>';
}
//replace chars that old machines probably can't handle
function clean_str($str) {
$str = str_replace( "", "'", $str );
$str = str_replace( "", "'", $str );
$str = str_replace( "", '"', $str );
$str = str_replace( "", '"', $str );
$str = str_replace( "", '-', $str );
function clean_str($str)
{
$str = str_replace("", "'", $str);
$str = str_replace("", "'", $str);
$str = str_replace("", '"', $str);
$str = str_replace("", '"', $str);
$str = str_replace("", '-', $str);
return $str;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 2.0//EN">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html>
<head>
<title><?php echo $readability->getTitle();?></title>
</head>
<body>
<html>
<head>
<title><?php echo $readability->getTitle(); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<style type="text/css">
a {
padding: 4px 0;
display: inline-block;
}
input[type="text"] {
font-size: 16px;
height: 24px;
}
input[type="submit"] {
font-size: 16px;
height: 32px;
padding: 2px 8px;
}
</style>
</head>
<body style="margin: 5px; padding: 0;">
<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 ?>">
<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!">
</form>
</form>
</p>
<hr>
<h1><?php echo clean_str($readability->getTitle());?></h1>
<h1><?php echo clean_str($readability->getTitle()); ?></h1>
<p> <?php
$img_num = 0;
$imgline_html = "View page images:";
@@ -143,11 +164,16 @@ function clean_str($str) {
$imgline_html .= " <a href='image.php?i=" . $image_url . "'>[$img_num]</a> ";
}
endforeach;
if($img_num>0) {
echo $imgline_html ;
if ($img_num > 0) {
echo $imgline_html;
}
?></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>
</body>
</html>
?></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>
</body>
</html>