Merge pull request #39 from eapl-gemugami/34-different-time-zone-is-being-used-in-new-twts-and-in-replies

fix(timezone): fixes wrong timezone in replies
This commit is contained in:
sørenpeter 2025-01-07 07:42:38 +01:00 committed by GitHub
commit e969e67631
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 37 deletions

6
libs/load_timezone.php Normal file
View file

@ -0,0 +1,6 @@
<?php
$config = parse_ini_file('private/config.ini');
if (!date_default_timezone_set($config['timezone'])) {
die('Not a valid timezone - Check your config.ini file');
}

View file

@ -17,31 +17,21 @@ declare (strict_types = 1);
#
# hash(string) =
require_once('libs/session.php');
require_once('libs/twtxt.php');
require_once('libs/hash.php');
require_once('libs/Parsedown.php');
const TWTS_PER_PAGE = 10;
require_once 'libs/session.php';
require_once 'libs/twtxt.php';
require_once 'libs/hash.php';
require_once 'libs/Parsedown.php';
require_once 'libs/load_timezone.php';
// TODO: Move twts per page to config.ini
// Add a fallback if the number is invalid (it should be between 1 and 999)
const TWTS_PER_PAGE = 50;
$config = parse_ini_file('private/config.ini');
// TODO: Take the title from the config.ini
$title = "Timeline"; // Fallback, should be set in all views
if (isset($config['site_title'])) {
$title = $config['site_title'];
}
$title = $config['site_title'] ?? "Timeline";
// HACKED by sp@darch.dk
if(!empty($_GET['list'])) {
$url = $baseURL.$_GET['list'];
}
else {
$url = $config['public_txt_url'];
}
$url = !empty($_GET['list']) ? $baseURL.$_GET['list'] : $config['public_txt_url'];
/*
if(isset($_GET['selectList'])){
@ -57,11 +47,7 @@ if(isset($_GET['selectList'])){
}
*/
date_default_timezone_set('UTC');
if (!empty($_GET['url'])) {
$url = $_GET['url'];
}
$url = !empty($_GET['url']) ? filter_var($_GET['url'], FILTER_SANITIZE_URL) : $url;
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');

View file

@ -28,9 +28,14 @@ public_txt_url = "https://example.com/timeline/twtxt.txt"
public_avatar = "https://example.com/timeline/avatar.png"
public_nick = "Timeline"
; Timezone for twts in your twtxt.txt
; If you use "UTC", the time will be shown as "2024-12-13T21:39:32Z"
; Otherwise, a time offset will be show as in "2024-12-13T16:51:20-05:00"
; Check available timezones here:
; https://www.php.net/manual/en/timezones.php
timezone = "Europe/Copenhagen"
timezone = "UTC"
;timezone = "Europe/Copenhagen"
twts_per_page = 50
@ -54,6 +59,9 @@ password = "change_me"
totp_digits = 10
totp_secret = "1234567890"
; Simple password for unnamed user
password = "123"
; It's recommended that your site is hosted on HTTPS
; In case it's in HTTP (not secure), set this to false
secure_cookies = true

View file

@ -1,6 +1,5 @@
<?php
require_once 'libs/session.php';
checkValidSessionOrRedirectToLogin();
// TODO: Give a warning if the file is not found
@ -14,8 +13,9 @@ if ($config['debug_mode']) {
$txt_file_path = $config['txt_file_path'];
$public_txt_url = $config['public_txt_url'];
$timezone = $config['timezone'];
$timezone = $config['timezone'];
require_once 'libs/load_timezone.php';
if (isset($_POST['submit'])) {
$new_post = filter_input(INPUT_POST, 'new_post');
@ -26,11 +26,7 @@ if (isset($_POST['submit'])) {
// Remove Carriage return if needed
$new_post = str_replace("\r", '', $new_post);
// TODO: If twt is emply, show an error
/*
if ($new_post) {
}
*/
// TODO: If twt is empty, show an error
// Check if we have a point to insert the next Twt
define('NEW_TWT_MARKER', "#~~~#\n");
@ -50,7 +46,7 @@ if (isset($_POST['submit'])) {
//$twt = $datetime . "\t$new_post\n";
//$twt = date('c') . "\t$new_post\n";
$datetime = date('Y-m-d\TH:i:sp'); // abracting to be used for webmentions
$twt = "\n" . $datetime . "\t" .$new_post; // NB: only works with PHP 8
$twt = "\n$datetime\t$new_post"; // NB: only works with PHP 8
// TODO: Delete?
/*if (strpos($contents, NEW_TWT_MARKER) !== false) {
@ -67,7 +63,7 @@ if (isset($_POST['submit'])) {
// Append twt at the end of file
$contents .= $twt;
// TODO: Add error handling if write to the file fails
// TODO: Add error handling if write to the file fails
// For example due to permissions problems
// https://www.w3docs.com/snippets/php/how-can-i-handle-the-warning-of-file-get-contents-function-in-php.html
@ -83,12 +79,10 @@ if (isset($_POST['submit'])) {
} else {
require_once "partials/base.php";
$title = "New post - ".$title;
$title = "New post - $title";
include_once 'partials/header.php';
if (!isset($textareaValue)) {
$textareaValue = '';
}
$textareaValue = $textareaValue ?? '';
if (isset($_GET['hash'])) {
$hash = $_GET['hash'];