This commit is contained in:
sørenpeter 2023-12-28 19:18:20 +01:00
commit 43c29c28ab
12 changed files with 146 additions and 196 deletions

View file

@ -2,32 +2,16 @@
# Shows the timeline for a user
declare (strict_types = 1);
# Parameters
#
# url(string): Gets
# Default: public_txt_url in config.ini
#
# timeline_url(string) = Gets the timeline for that specificed URL (twtxt)
# Default: public_txt_url in config.ini
#
# page(int):
# Default: Page 1 of N
# If page is higher than N, shows nothing
#
# hash(string) =
#
require_once("libs/session.php");
require_once('libs/twtxt.php');
require_once('libs/hash.php');
require_once('libs/Slimdown.php');
require_once "libs/session.php";
require_once 'libs/twtxt.php';
require_once 'libs/hash.php';
require_once 'libs/Slimdown.php';
const TWTS_PER_PAGE = 50;
// TODO: Move twts per page to config.ini
// Add a fallback if the number tis invalid (it should be between 1 and 999)
// Add a fallback if the number is invalid (it should be between 1 and 999)
$config = parse_ini_file('private/config.ini');
//$url = $config['public_txt_url'];
// TODO: Take the title from the config.ini
$title = "Timeline"; // Fallback, should be set in all views
@ -35,24 +19,9 @@ $title = "Timeline"; // Fallback, should be set in all views
// HACKED by sp@darch.dk
if (!empty($_GET['list'])) {
$url = "https://darch.dk/twtxt-lists/" . $_GET['list'];
}
else {
$url = $config['public_txt_url'];
}
/*
if(isset($_GET['selectList'])){
if(!empty($_GET['lists'])) {
$url = "https://darch.dk/twtxt-lists/".$_GET['lists'];
}
// else {
// $url = $config['public_txt_url'];
// }
} else {
$url = $config['public_txt_url'];
//$url = "https://darch.dk/twtxt-lists/twtxt.txt";
}
*/
date_default_timezone_set('UTC');
@ -64,9 +33,6 @@ if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');
}
//$validSession = has_valid_session();
//echo("Valid session: $validSession");
$cacheRefreshTime = $config['cache_refresh_time'];
$fileContent = getCachedFileContentsOrUpdate($url, $cacheRefreshTime);
@ -124,7 +90,6 @@ if (!empty($_GET['hash'])) {
});
}
krsort($twts, SORT_NUMERIC);
if (!empty($_GET['hash'])) {
@ -136,7 +101,10 @@ if (!empty($_GET['page'])) {
$page = intval($_GET['page']);
}
// If we should paginate our twts list
if (!empty($paginateTwts)) {
$startingTwt = (($page - 1) * TWTS_PER_PAGE);
$twts = array_slice($twts, $startingTwt, TWTS_PER_PAGE);
}
$baseURL = str_replace("/index.php", "", $_SERVER['SCRIPT_NAME']);

View file

@ -4,10 +4,9 @@
if (!empty($_GET['profile'])) {
$url = $twtsURL;
}
$profile = getTwtsFromTwtxtString($url);
$profileURL = $baseURL . '/?profile=' . $profile->mainURL;
?>
<div class="profile">
@ -39,17 +38,3 @@ $profileURL = $baseURL.'/?profile='.$profile->mainURL;
</div>
</div>
<!-- <nav>
<ul>
<li><a href="">Posts</a></li>
<li><a href="">Replies</a></li>
<li><a href="">Gallery</a></li>
</ul>
<ul class="right">
<li><a href="https://yarn.social" class="button">How to follow...</a></li>
<li><a href="following.php">Following <?php echo count($twtFollowingList); ?></a></li>
<li><a target="_blank" href="<?= $profile->mainURL ?>"></i>twtxt.txt</a></li>
</ul>
</nav> -->

View file

@ -1,10 +1,10 @@
<!-- <center>
<!--
<?php if (!empty($_GET['profile'])) {?>
<em>Twts for <a href="<?=$twtsURL?>"><?=$twtsURL?></a></em>
<?php } else {?>
<em>Timeline for <a href="<?=$url?>"><?=$url?></a></em>
<?php }?>
</center> -->
-->
<?php foreach ($twts as $twt) {?>
<article class="post-entry" id="<?=$twt->hash?>">
@ -18,17 +18,10 @@
<div class="twt-msg">
<?=$twt->content?>
<!-- Not sure what this does...
<?php foreach ($twt->mentions as $mention) { ?>
<br><?= $mention['nick'] ?>(<?= $mention['url'] ?>)
<?php } ?>
-->
</div>
<small>
<?php
if ($twt->replyToHash) {
echo 'In reply to: <a href="' . $baseURL . '/conv/' . $twt->replyToHash . '">#' . $twt->replyToHash . '</a>';
//echo '<a href="/conv/'.$twt->replyToHash.'">Convesation</a>';
@ -51,7 +44,6 @@
<?php }
if (!isset($_SESSION['password'])) {
echo '<center><a href="mailto:' . $config['email'] . '?subject=RE: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="button">Comment via email</a></center>';
}

View file

@ -1,4 +1,5 @@
<?php require_once('partials/base.php');
<?php
require_once('partials/base.php');
// TODO: Give a warning if the file is not found
$config = parse_ini_file('private/config.ini');
@ -66,8 +67,6 @@ if (isset($_POST['url'])) {
} else { ?>
<?php
require_once("partials/base.php");
$title = "Add feed - ".$title;
include 'partials/header.php';

View file

@ -1,4 +1,6 @@
<?php require_once("partials/base.php");
<?php
$paginateTwts = false;
require_once("partials/base.php");
// Get the hashes (both post and replies) as $id from the router and return an inverted list
if (!empty($id)) {
@ -19,7 +21,7 @@ include_once 'partials/header.php';
<p>Recent twts in reply to <a href="<?= $baseURL ?>/post/<?= $id ?>">#<?= $id ?></a></p>
<!-- PHP: GET TIMELIE --><?php include_once 'partials/timeline.php'?>
<!-- PHP: GET TIMELINE --><?php include_once 'partials/timeline.php'?>
<?php
if (isset($_SESSION['password'])) {

View file

@ -35,7 +35,6 @@ if (!empty($_GET['profile'])) { // Show twts for some user
<div class="gallery">
<?php
foreach ($twts as $twt) {
$img_array = getImagesFromTwt($twt->content);
@ -43,8 +42,7 @@ foreach ($twts as $twt) {
$img_link = $img[0];
echo '<a href="'.$baseURL.'/post/'.$twt->hash.'">'.$img_link.'</a>';
// Workaround until cache issue is resolved
//echo '<a href="'.$baseURL.'/?profile='.$twt->mainURL.'#'.$twt->hash.'">'.$img[0].'</a>';
//echo '<a href="'.$baseURL.'/?profile='.$twt->mainURL.'#'.$twt->hash.'">'.$img[0].'</a>'; // Workaround until cache issue is resolved
}
}
?>

View file

@ -1,28 +1,35 @@
<?php
require_once("partials/base.php");
// Only paginate if it's a main timeline view
$paginateTwts = true;
//$title = "Login - ".$title;
if (!empty($_GET['profile'])) { // Show twts for some user (Profile view)
$twtsURL = $_GET['profile'];
// TODO: Give a proper error if URL is not valid
if (filter_var($twtsURL, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');
}
// If it's a profile, don't paginate
$paginateTwts = false;
}
// Load twts, taking $paginateTwts into consideration
require_once 'partials/base.php';
include_once 'partials/header.php';
?>
<!-- PHP: PROFILE CARD -->
<?php
if (!empty($_GET['profile'])) { // Show twts for some user
if (!empty($_GET['profile'])) { // Show twts for some user (Profile view)
$twtsURL = $_GET['profile'];
// TODO: Give a propper error if feed is not valid
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');
}
// $parsedTwtxtFile = getTwtsFromTwtxtString($twtsURL);
if (!is_null($parsedTwtxtFile)) {
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
include 'partials/profile.php';
}
} ?>
}
?>
<!-- PHP: NEW POST BOX -->
<?php
@ -34,4 +41,3 @@ if( isset($_SESSION['password'])) {
<!-- PHP: TIMELINE --><?php include_once 'partials/timeline.php'?>
<!-- PHP: FOOTER --><?php include_once 'partials/footer.php';?>

View file

@ -84,7 +84,6 @@ if (isset($_POST['submit'])) {
exit;
} else {
require_once("partials/base.php");
$title = "New post - ".$title;

View file

@ -1,4 +1,5 @@
<?php require_once("partials/base.php");
<?php
require_once("partials/base.php");
// Get the hash (only post, not replies) as $id from the router
if (!empty($id)) {