mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-13 01:47:01 +00:00
Add force httpS to .htaccess
This commit is contained in:
parent
a46d88a3c0
commit
a41ce42290
11 changed files with 130 additions and 66 deletions
|
|
@ -1,4 +1,6 @@
|
|||
RewriteEngine On
|
||||
RewriteCond %{HTTPS} off
|
||||
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.*)$ index.php [NC,L]
|
||||
|
|
@ -405,6 +405,22 @@ nav.pagnation {
|
|||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
|
||||
.pagnation {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 1rem;
|
||||
}
|
||||
|
||||
.pagnation a {
|
||||
text-decoration: none;
|
||||
background-color: var(--accent-bg);
|
||||
}
|
||||
|
||||
.pagnation strong {
|
||||
padding: 0 1rem;
|
||||
}
|
||||
|
||||
/* === FOOTER === */
|
||||
|
||||
body > footer {
|
||||
|
|
|
|||
|
|
@ -169,12 +169,21 @@ function replaceMentionsFromTwt(string $twtString): string {
|
|||
// Example output: Hello <a href="?url=https://eapl.mx/twtxt.txt">@eapl.mx@eapl.mx/twtxt.txt</a>, how are you? <a href="?url=https://server.com/something/twtxt.txt">@nick@server.com/something/twtxt.txt</a>
|
||||
|
||||
$pattern = '/@<([^ ]+)\s([^>]+)>/';
|
||||
|
||||
//$replacement = '<a href="/?url=$2">@$1</a>';
|
||||
$replacement = '<a href="' . str_replace("/index.php", "", $_SERVER["SCRIPT_NAME"]) . '/profile?url=$2">@$1</a>';
|
||||
$replacement .= '<a href="$2" class="webmention"></a>'; // Adds a hidden link direcly to the twtxt.txt of the mentioned target
|
||||
//$replacement .= '<a href="$2" class="webmention"></a>'; // Adds a hidden link direcly to the twtxt.txt of the mentioned target
|
||||
#$twtString = '@<nick https://eapl.mx/twtxt.txt>';
|
||||
#$pattern = '/@<([^ ]+) ([^>]+)>/';
|
||||
#$replacement = '@$1';
|
||||
|
||||
/*
|
||||
$pattern_only_url = '/@<(https?:\/\/[^>]+)>/';
|
||||
if (preg_match($pattern_only_url, $twtString)) {
|
||||
$replacement = '<a href="' . str_replace("/index.php", "", $_SERVER["SCRIPT_NAME"]) . '/profile?url=$1">@$1</a>';
|
||||
}
|
||||
*/
|
||||
|
||||
$result = preg_replace($pattern, $replacement, $twtString);
|
||||
return $result;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@ require_once('libs/twtxt.php');
|
|||
require_once('libs/hash.php');
|
||||
require_once('libs/Parsedown.php');
|
||||
|
||||
const TWTS_PER_PAGE = 10;
|
||||
|
||||
const TWTS_PER_PAGE = 20;
|
||||
// TODO: Move twts per page to config.ini
|
||||
// Add a fallback if the number is invalid (it should be between 1 and 999)
|
||||
|
||||
$config = parse_ini_file('private/config.ini');
|
||||
|
||||
// TODO: Take the title from the config.ini
|
||||
|
|
@ -157,6 +157,9 @@ if (!empty($_GET['hash'])) {
|
|||
}
|
||||
|
||||
// Pagnation
|
||||
|
||||
//$twts_per_page = $config['twts_per_page'];
|
||||
|
||||
$page = 1;
|
||||
if (!empty($_GET['page'])) {
|
||||
$page = intval($_GET['page']);
|
||||
|
|
|
|||
47
partials/pagnation.php
Normal file
47
partials/pagnation.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
|
||||
TODO: Make pagnation work with profile views
|
||||
|
||||
*/
|
||||
|
||||
$page_url = $_SERVER['REQUEST_URI'];
|
||||
//echo $page_url."<hr>";
|
||||
|
||||
if (!empty($_GET['page'])) {
|
||||
|
||||
if (preg_match('/\?page=/', $page_url)) {
|
||||
//echo "cotains ?page= so reuse that <hr>";
|
||||
$page_url = preg_replace('/\?page=\d*/', "", $page_url) . '?page=';
|
||||
}
|
||||
|
||||
if (preg_match('/&page=/', $page_url)) {
|
||||
//echo "cotains &page= so reuse that <hr>";
|
||||
$page_url = preg_replace('/&page=\d*/', "", $page_url) . '&page=';
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!preg_match('/(\?|&)/', $page_url)) {
|
||||
//echo "No param, so use ?page <hr>";
|
||||
$page_url = $page_url . '?page=';
|
||||
}
|
||||
|
||||
if (!preg_match('/(\?|&)page/', $page_url)) {
|
||||
//echo "other param than _page, so use &page <hr>";
|
||||
$page_url = $page_url . '&page=';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="pagnation">
|
||||
<?php if ($page > 1) { ?>
|
||||
<a href="<?= $page_url . $page-1 ?>"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>
|
||||
<?php } else { ?>
|
||||
<span style="color: var(--disabled);"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</span>
|
||||
<?php } ?>
|
||||
<strong> <?= $page ?> </strong>
|
||||
<a href="<?= $page_url . $page+1 ?>">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a>
|
||||
</div>
|
||||
|
|
@ -6,9 +6,11 @@
|
|||
<?php }?>
|
||||
-->
|
||||
|
||||
<?php // echo "count: " . count($twts); ?>
|
||||
|
||||
<?php include_once 'partials/search.php'; ?>
|
||||
|
||||
<?php foreach ($twts as $twt) {?>
|
||||
<?php foreach ($twts as $twt) { ?>
|
||||
<article class="post-entry" id="<?=$twt->hash?>">
|
||||
<a href="<?=$baseURL?>/profile?url=<?=$twt->mainURL?>">
|
||||
<img src='<?=$twt->avatar?>' class="avatar" onerror="this.onerror=null;this.src='<?= $baseURL ?>/media/default.png';">
|
||||
|
|
@ -50,55 +52,8 @@
|
|||
|
||||
<?php }
|
||||
|
||||
// Pagnation
|
||||
/*
|
||||
include_once 'partials/pagnation.php';
|
||||
|
||||
TODO: Merge with code in base.php / make new pagnation.php
|
||||
TODO: Make pagnation work with profile views
|
||||
|
||||
*/
|
||||
|
||||
$page_url = $_SERVER['REQUEST_URI'];
|
||||
//echo $page_url."<hr>";
|
||||
|
||||
if (!empty($_GET['page'])) {
|
||||
|
||||
if (preg_match('/\?page=/', $page_url)) {
|
||||
//echo "cotains ?page= so reuse that<hr>";
|
||||
$page_url = preg_replace('/\?page=\d*/', "", $page_url) . '?page=';
|
||||
}
|
||||
|
||||
if (preg_match('/&page=/', $page_url)) {
|
||||
echo "cotains &page= so reuse that<hr>";
|
||||
$page_url = preg_replace('/&page=\d*/', "", $page_url) . '&page=';
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!preg_match('/(\?|&)/', $page_url)) {
|
||||
//echo "No param, so use ?page<hr>";
|
||||
$page_url = $page_url . '?page=';
|
||||
}
|
||||
|
||||
if (!preg_match('/(\?|&)page/', $page_url)) {
|
||||
//echo "other param than _page, so use &page<hr>";
|
||||
$page_url = $page_url . '&page=';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<center><p>
|
||||
<?php if ($page > 1) { ?>
|
||||
<a href="<?= $page_url . $page-1 ?>">Prev</a>
|
||||
<?php } else { ?>
|
||||
<span style="color: var(--disabled);">Prev</span>
|
||||
<?php } ?>
|
||||
<strong> <?= $page ?> </strong>
|
||||
<a href="<?= $page_url . $page+1 ?>">Next</a>
|
||||
</p></center>
|
||||
|
||||
<?php
|
||||
require_once 'libs/session.php';
|
||||
|
||||
if (!hasValidSession()) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ site_title = "Timeline"
|
|||
; access.
|
||||
txt_file_path = "twtxt.txt"
|
||||
|
||||
; Path to folder where you want to upload images for your posts
|
||||
img_upload_dir = "./media"
|
||||
|
||||
; Full URL for your public twtxt.txt file
|
||||
public_txt_url = "https://example.com/timeline/twtxt.txt"
|
||||
public_avatar = "https://example.com/timeline/avatar.png"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
// Only paginate if it's a main timeline view
|
||||
$paginateTwts = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
<?php
|
||||
|
||||
//$paginateTwts = true;
|
||||
|
||||
if (!empty($_GET['url'])) { // Show twts for some user (Profile view)
|
||||
$twtsURL = $_GET['url'];
|
||||
} else {
|
||||
|
||||
// temp to get default url
|
||||
$config = parse_ini_file('private/config.ini');
|
||||
|
||||
$config = parse_ini_file('private/config.ini');
|
||||
$twtsURL = $config['public_txt_url'];
|
||||
}
|
||||
|
||||
|
|
@ -16,8 +15,6 @@ $title = "Posts by ".$title;
|
|||
|
||||
include_once 'partials/header.php';
|
||||
|
||||
//echo $twtsURL."bob";
|
||||
|
||||
include_once 'partials/profile_card.php';
|
||||
|
||||
if( isset($_SESSION['password'])) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
<?php
|
||||
|
||||
//$paginateTwts = true;
|
||||
|
||||
if (!empty($_GET['url'])) { // Show twts for some user (Profile view)
|
||||
$twtsURL = $_GET['url'];
|
||||
} else {
|
||||
|
||||
// temp to get default url
|
||||
$config = parse_ini_file('private/config.ini');
|
||||
|
||||
$config = parse_ini_file('private/config.ini');
|
||||
$twtsURL = $config['public_txt_url'];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,18 @@ $title = "Upload - $title";
|
|||
|
||||
include_once 'partials/header.php';
|
||||
|
||||
$media_upload = getcwd() . "/" . $config["media_upload"] . "/";
|
||||
|
||||
if (!empty($_POST)) {
|
||||
// Based on code from: https://www.w3schools.com/php/php_file_upload.asp
|
||||
|
||||
//echo getcwd() ."<br>";
|
||||
//echo __DIR__ . "<br>";
|
||||
//echo "upload path: " . $config["media_upload"];
|
||||
|
||||
$target_dir = getcwd()."/media/";
|
||||
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
||||
//$media_upload = getcwd()."/media/";
|
||||
$media_upload = getcwd().$config["media_upload"];
|
||||
$target_file = $media_upload . basename($_FILES["fileToUpload"]["name"]);
|
||||
$uploadOk = 1;
|
||||
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
|
||||
|
||||
|
|
@ -39,7 +43,7 @@ if (!empty($_POST)) {
|
|||
|
||||
// Check file size
|
||||
if ($_FILES["fileToUpload"]["size"] > 5000000) {
|
||||
echo "Sorry, your file is too large.<br>";
|
||||
echo "<p class='notice'>Sorry, your file is too large.</p>";
|
||||
$uploadOk = 0;
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +70,6 @@ if (!empty($_POST)) {
|
|||
|
||||
?>
|
||||
|
||||
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
Select image to upload:<br>
|
||||
<input type="file" name="fileToUpload" id="fileToUpload"><br>
|
||||
|
|
@ -74,4 +77,33 @@ if (!empty($_POST)) {
|
|||
</form>
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$imgs_on_server = glob($media_upload."*.{jpg,jpeg,png,gif}", GLOB_BRACE);
|
||||
|
||||
// Sort image files by date (based on: https://stackoverflow.com/questions/124958/glob-sort-array-of-files-by-last-modified-datetime-stamp
|
||||
usort($imgs_on_server, fn($a, $b) => -(filemtime($a) - filemtime($b)));
|
||||
|
||||
echo '<table class="center">';
|
||||
|
||||
foreach ($imgs_on_server as $img) {
|
||||
|
||||
$public_file = $config["public_media"] . "/" . basename($img);
|
||||
|
||||
echo '<tr class="preview">';
|
||||
echo '<td><a href="'.$public_file.'">';
|
||||
echo '<img src="'.$public_file.'" style="width=50px;">';
|
||||
echo '</a></td>';
|
||||
|
||||
//$img = str_replace('../', $base_url, $img);
|
||||
echo '<td><code></code></td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
echo '</table>';
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<!-- PHP: FOOTER --><?php include_once 'partials/footer.php';?>
|
||||
|
|
|
|||
Loading…
Reference in a new issue