mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-15 10:57:01 +00:00
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:
commit
e969e67631
4 changed files with 31 additions and 37 deletions
6
libs/load_timezone.php
Normal file
6
libs/load_timezone.php
Normal 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');
|
||||||
|
}
|
||||||
|
|
@ -17,31 +17,21 @@ declare (strict_types = 1);
|
||||||
#
|
#
|
||||||
# hash(string) =
|
# hash(string) =
|
||||||
|
|
||||||
require_once('libs/session.php');
|
require_once 'libs/session.php';
|
||||||
require_once('libs/twtxt.php');
|
require_once 'libs/twtxt.php';
|
||||||
require_once('libs/hash.php');
|
require_once 'libs/hash.php';
|
||||||
require_once('libs/Parsedown.php');
|
require_once 'libs/Parsedown.php';
|
||||||
|
require_once 'libs/load_timezone.php';
|
||||||
const TWTS_PER_PAGE = 10;
|
|
||||||
|
|
||||||
// TODO: Move twts per page to config.ini
|
// TODO: Move twts per page to config.ini
|
||||||
// Add a fallback if the number is invalid (it should be between 1 and 999)
|
// 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');
|
$config = parse_ini_file('private/config.ini');
|
||||||
|
|
||||||
// TODO: Take the title from the config.ini
|
$title = $config['site_title'] ?? "Timeline";
|
||||||
$title = "Timeline"; // Fallback, should be set in all views
|
|
||||||
|
|
||||||
if (isset($config['site_title'])) {
|
|
||||||
$title = $config['site_title'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// HACKED by sp@darch.dk
|
// HACKED by sp@darch.dk
|
||||||
if(!empty($_GET['list'])) {
|
$url = !empty($_GET['list']) ? $baseURL.$_GET['list'] : $config['public_txt_url'];
|
||||||
$url = $baseURL.$_GET['list'];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$url = $config['public_txt_url'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if(isset($_GET['selectList'])){
|
if(isset($_GET['selectList'])){
|
||||||
|
|
@ -57,11 +47,7 @@ if(isset($_GET['selectList'])){
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
$url = !empty($_GET['url']) ? filter_var($_GET['url'], FILTER_SANITIZE_URL) : $url;
|
||||||
|
|
||||||
if (!empty($_GET['url'])) {
|
|
||||||
$url = $_GET['url'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
|
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
|
||||||
die('Not a valid URL');
|
die('Not a valid URL');
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,14 @@ public_txt_url = "https://example.com/timeline/twtxt.txt"
|
||||||
public_avatar = "https://example.com/timeline/avatar.png"
|
public_avatar = "https://example.com/timeline/avatar.png"
|
||||||
public_nick = "Timeline"
|
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:
|
; Check available timezones here:
|
||||||
; https://www.php.net/manual/en/timezones.php
|
; https://www.php.net/manual/en/timezones.php
|
||||||
timezone = "Europe/Copenhagen"
|
timezone = "UTC"
|
||||||
|
;timezone = "Europe/Copenhagen"
|
||||||
|
|
||||||
twts_per_page = 50
|
twts_per_page = 50
|
||||||
|
|
||||||
|
|
@ -54,6 +59,9 @@ password = "change_me"
|
||||||
totp_digits = 10
|
totp_digits = 10
|
||||||
totp_secret = "1234567890"
|
totp_secret = "1234567890"
|
||||||
|
|
||||||
|
; Simple password for unnamed user
|
||||||
|
password = "123"
|
||||||
|
|
||||||
; It's recommended that your site is hosted on HTTPS
|
; It's recommended that your site is hosted on HTTPS
|
||||||
; In case it's in HTTP (not secure), set this to false
|
; In case it's in HTTP (not secure), set this to false
|
||||||
secure_cookies = true
|
secure_cookies = true
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
require_once 'libs/session.php';
|
require_once 'libs/session.php';
|
||||||
|
|
||||||
checkValidSessionOrRedirectToLogin();
|
checkValidSessionOrRedirectToLogin();
|
||||||
|
|
||||||
// TODO: Give a warning if the file is not found
|
// 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'];
|
$txt_file_path = $config['txt_file_path'];
|
||||||
$public_txt_url = $config['public_txt_url'];
|
$public_txt_url = $config['public_txt_url'];
|
||||||
$timezone = $config['timezone'];
|
|
||||||
|
|
||||||
|
$timezone = $config['timezone'];
|
||||||
|
require_once 'libs/load_timezone.php';
|
||||||
|
|
||||||
if (isset($_POST['submit'])) {
|
if (isset($_POST['submit'])) {
|
||||||
$new_post = filter_input(INPUT_POST, 'new_post');
|
$new_post = filter_input(INPUT_POST, 'new_post');
|
||||||
|
|
@ -26,11 +26,7 @@ if (isset($_POST['submit'])) {
|
||||||
// Remove Carriage return if needed
|
// Remove Carriage return if needed
|
||||||
$new_post = str_replace("\r", '', $new_post);
|
$new_post = str_replace("\r", '', $new_post);
|
||||||
|
|
||||||
// TODO: If twt is emply, show an error
|
// TODO: If twt is empty, show an error
|
||||||
/*
|
|
||||||
if ($new_post) {
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Check if we have a point to insert the next Twt
|
// Check if we have a point to insert the next Twt
|
||||||
define('NEW_TWT_MARKER', "#~~~#\n");
|
define('NEW_TWT_MARKER', "#~~~#\n");
|
||||||
|
|
@ -50,7 +46,7 @@ if (isset($_POST['submit'])) {
|
||||||
//$twt = $datetime . "\t$new_post\n";
|
//$twt = $datetime . "\t$new_post\n";
|
||||||
//$twt = date('c') . "\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
|
$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?
|
// TODO: Delete?
|
||||||
/*if (strpos($contents, NEW_TWT_MARKER) !== false) {
|
/*if (strpos($contents, NEW_TWT_MARKER) !== false) {
|
||||||
|
|
@ -67,7 +63,7 @@ if (isset($_POST['submit'])) {
|
||||||
// Append twt at the end of file
|
// Append twt at the end of file
|
||||||
$contents .= $twt;
|
$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
|
// 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
|
// 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 {
|
} else {
|
||||||
require_once "partials/base.php";
|
require_once "partials/base.php";
|
||||||
$title = "New post - ".$title;
|
$title = "New post - $title";
|
||||||
include_once 'partials/header.php';
|
include_once 'partials/header.php';
|
||||||
|
|
||||||
if (!isset($textareaValue)) {
|
$textareaValue = $textareaValue ?? '';
|
||||||
$textareaValue = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_GET['hash'])) {
|
if (isset($_GET['hash'])) {
|
||||||
$hash = $_GET['hash'];
|
$hash = $_GET['hash'];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue