mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-15 10:57:01 +00:00
fix(timezone): fixes wrong timezone in replies
- Moves loading timezone from config file to 'load_timezone.php' - Applies code style suggestions from IDE
This commit is contained in:
parent
d3079b0be4
commit
af0a80c524
4 changed files with 30 additions and 38 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) =
|
||||
|
||||
require_once('libs/session.php');
|
||||
require_once('libs/twtxt.php');
|
||||
require_once('libs/hash.php');
|
||||
require_once('libs/Parsedown.php');
|
||||
|
||||
const TWTS_PER_PAGE = 50;
|
||||
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');
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -46,9 +51,9 @@ public_webmentions = "https://example.com/timeline/mentions.txt"
|
|||
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
|
||||
|
||||
; Simple password for unnamed user
|
||||
password = ""
|
||||
|
|
@ -13,6 +13,7 @@ $public_txt_url = $config['public_txt_url'];
|
|||
$timezone = $config['timezone'];
|
||||
|
||||
require_once 'libs/session.php';
|
||||
require_once 'libs/load_timezone.php';
|
||||
|
||||
if (!isset($_SESSION['password'])) {
|
||||
header('Location: ./login');
|
||||
|
|
@ -28,11 +29,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");
|
||||
|
|
@ -52,7 +49,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) {
|
||||
|
|
@ -69,7 +66,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
|
||||
|
||||
|
|
@ -85,12 +82,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'];
|
||||
|
|
|
|||
Loading…
Reference in a new issue