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

@ -1,77 +1,43 @@
<?php <?php
# Shows the timeline for a user # Shows the timeline for a user
declare(strict_types=1); declare (strict_types = 1);
# Parameters require_once "libs/session.php";
# require_once 'libs/twtxt.php';
# url(string): Gets require_once 'libs/hash.php';
# Default: public_txt_url in config.ini require_once 'libs/Slimdown.php';
#
# 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');
const TWTS_PER_PAGE = 50; const TWTS_PER_PAGE = 50;
// TODO: Move twts per page to config.ini // 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'); $config = parse_ini_file('private/config.ini');
//$url = $config['public_txt_url'];
// TODO: Take the title from the config.ini // TODO: Take the title from the config.ini
$title = "Timeline"; // Fallback, should be set in all views $title = "Timeline"; // Fallback, should be set in all views
// HACKED by sp@darch.dk // HACKED by sp@darch.dk
if(!empty($_GET['list'])) { if (!empty($_GET['list'])) {
$url = "https://darch.dk/twtxt-lists/".$_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 { } else {
$url = $config['public_txt_url']; $url = $config['public_txt_url'];
//$url = "https://darch.dk/twtxt-lists/twtxt.txt";
} }
*/
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
if (!empty($_GET['url'])) { if (!empty($_GET['url'])) {
$url = $_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');
} }
//$validSession = has_valid_session();
//echo("Valid session: $validSession");
$cacheRefreshTime = $config['cache_refresh_time']; $cacheRefreshTime = $config['cache_refresh_time'];
$fileContent = getCachedFileContentsOrUpdate($url, $cacheRefreshTime); $fileContent = getCachedFileContentsOrUpdate($url, $cacheRefreshTime);
if ($fileContent === false) { if ($fileContent === false) {
die("$url couldn't be retrieved."); die("$url couldn't be retrieved.");
} }
$fileContent = mb_convert_encoding($fileContent, 'UTF-8'); $fileContent = mb_convert_encoding($fileContent, 'UTF-8');
@ -79,64 +45,66 @@ $fileLines = explode("\n", $fileContent);
$twtFollowingList = []; $twtFollowingList = [];
if (!empty($_GET['profile'])) { // Show profile for some user if (!empty($_GET['profile'])) { // Show profile for some user
$twtsURL = $_GET['profile']; $twtsURL = $_GET['profile'];
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');
} }
$parsedTwtxtFile = getTwtsFromTwtxtString($twtsURL); $parsedTwtxtFile = getTwtsFromTwtxtString($twtsURL);
if (!is_null($parsedTwtxtFile)) { if (!is_null($parsedTwtxtFile)) {
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile; $parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
} }
} else { // Show timeline for the URL } else { // Show timeline for the URL
$parsedTwtxtFiles = []; $parsedTwtxtFiles = [];
foreach ($fileLines as $currentLine) { foreach ($fileLines as $currentLine) {
if (str_starts_with($currentLine, '#')) { if (str_starts_with($currentLine, '#')) {
if (!is_null(getDoubleParameter('follow', $currentLine))) { if (!is_null(getDoubleParameter('follow', $currentLine))) {
$follow = getDoubleParameter('follow', $currentLine); $follow = getDoubleParameter('follow', $currentLine);
$twtFollowingList[] = $follow; $twtFollowingList[] = $follow;
// Read the parsed files if in Cache // Read the parsed files if in Cache
$followURL = $follow[1]; $followURL = $follow[1];
$parsedTwtxtFile = getTwtsFromTwtxtString($followURL); $parsedTwtxtFile = getTwtsFromTwtxtString($followURL);
if (!is_null($parsedTwtxtFile)) { if (!is_null($parsedTwtxtFile)) {
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile; $parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
} }
} }
} }
} }
} }
$twts = []; $twts = [];
# Combine all the followers twts # Combine all the followers twts
foreach ($parsedTwtxtFiles as $currentTwtFile) { foreach ($parsedTwtxtFiles as $currentTwtFile) {
if (!is_null($currentTwtFile)) { if (!is_null($currentTwtFile)) {
$twts += $currentTwtFile->twts; $twts += $currentTwtFile->twts;
} }
} }
if (!empty($_GET['hash'])) { if (!empty($_GET['hash'])) {
$hash = $_GET['hash']; $hash = $_GET['hash'];
$twts = array_filter($twts, function($twt) use ($hash) { $twts = array_filter($twts, function ($twt) use ($hash) {
return $twt->hash === $hash || $twt->replyToHash === $hash; return $twt->hash === $hash || $twt->replyToHash === $hash;
}); });
} }
krsort($twts, SORT_NUMERIC); krsort($twts, SORT_NUMERIC);
if (!empty($_GET['hash'])) { if (!empty($_GET['hash'])) {
$twts = array_reverse($twts, true); $twts = array_reverse($twts, true);
} }
$page = 1; $page = 1;
if (!empty($_GET['page'])) { if (!empty($_GET['page'])) {
$page = intval($_GET['page']); $page = intval($_GET['page']);
} }
$startingTwt = (($page - 1) * TWTS_PER_PAGE); // If we should paginate our twts list
$twts = array_slice($twts, $startingTwt, TWTS_PER_PAGE); 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']); $baseURL = str_replace("/index.php", "", $_SERVER['SCRIPT_NAME']);

View file

@ -2,35 +2,34 @@
// Get info about profile from URL as an objects // Get info about profile from URL as an objects
if (!empty($_GET['profile'])) { if (!empty($_GET['profile'])) {
$url = $twtsURL; $url = $twtsURL;
} }
$profile = getTwtsFromTwtxtString($url); $profile = getTwtsFromTwtxtString($url);
$profileURL = $baseURL . '/?profile=' . $profile->mainURL;
$profileURL = $baseURL.'/?profile='.$profile->mainURL; ?>
?>
<div class="profile"> <div class="profile">
<a href="<?= $profileURL ?>"> <a href="<?=$profileURL?>">
<img class="avatar" src="<?= $profile->avatar ?>" alt="" loading="lazy"> <img class="avatar" src="<?=$profile->avatar?>" alt="" loading="lazy">
</a> </a>
<div> <div>
<a href="<?= $profileURL ?>" class="author"> <a href="<?=$profileURL?>" class="author">
<strong><?= $profile->nick ?></strong>@<?= parse_url($profile->mainURL, PHP_URL_HOST); ?> <strong><?=$profile->nick?></strong>@<?=parse_url($profile->mainURL, PHP_URL_HOST);?>
</a> </a>
<p><?= $profile->description ?></p> <p><?=$profile->description?></p>
<small> <small>
<a href="<?= $profileURL ?>">Posts</a> | <a href="<?=$profileURL?>">Posts</a> |
<!-- <a href="">Replies</a> | --> <!-- <a href="">Replies</a> | -->
<a href="<?= $baseURL ?>/gallery?profile=<?= $profile->mainURL ?>">Gallery</a> <a href="<?=$baseURL?>/gallery?profile=<?=$profile->mainURL?>">Gallery</a>
<span class="right"> <span class="right">
<!-- <a href="following.php">Following <?php echo count($twtFollowingList); ?></a> | --> <!-- <a href="following.php">Following <?php echo count($twtFollowingList); ?></a> | -->
<a target="_blank" href="<?= $profile->mainURL ?>"></i><?= $profile->mainURL ?></a> <a target="_blank" href="<?=$profile->mainURL?>"></i><?=$profile->mainURL?></a>
(<a href="https://yarn.social">How to follow</a>) (<a href="https://yarn.social">How to follow</a>)
</span> </span>
@ -39,17 +38,3 @@ $profileURL = $baseURL.'/?profile='.$profile->mainURL;
</div> </div>
</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,59 +1,51 @@
<!-- <center> <!--
<?php if (!empty($_GET['profile'])) { ?> <?php if (!empty($_GET['profile'])) {?>
<em>Twts for <a href="<?= $twtsURL ?>"><?= $twtsURL ?></a></em> <em>Twts for <a href="<?=$twtsURL?>"><?=$twtsURL?></a></em>
<?php } else { ?> <?php } else {?>
<em>Timeline for <a href="<?= $url ?>"><?= $url ?></a></em> <em>Timeline for <a href="<?=$url?>"><?=$url?></a></em>
<?php } ?> <?php }?>
</center> --> -->
<?php foreach ($twts as $twt) { ?> <?php foreach ($twts as $twt) {?>
<article class="post-entry" id="<?= $twt->hash ?>"> <article class="post-entry" id="<?=$twt->hash?>">
<a href="<?= $baseURL ?>/?profile=<?= $twt->mainURL ?>"> <a href="<?=$baseURL?>/?profile=<?=$twt->mainURL?>">
<img src='<?= $twt->avatar ?>' class="avatar" onerror="this.onerror=null;this.src='imgs/image_not_found.png';"> <img src='<?=$twt->avatar?>' class="avatar" onerror="this.onerror=null;this.src='imgs/image_not_found.png';">
</a> </a>
<div> <div>
<a href="<?= $baseURL ?>/?profile=<?= $twt->mainURL ?>" class="author"> <a href="<?=$baseURL?>/?profile=<?=$twt->mainURL?>" class="author">
<strong><?= $twt->nick ?></strong>@<?= parse_url($twt->mainURL, PHP_URL_HOST); ?> <strong><?=$twt->nick?></strong>@<?=parse_url($twt->mainURL, PHP_URL_HOST);?>
</a> </a>
<div class="twt-msg"> <div class="twt-msg">
<?= $twt->content ?> <?=$twt->content?>
</div>
<!-- Not sure what this does... <small>
<?php foreach ($twt->mentions as $mention) { ?> <?php
<br><?= $mention['nick'] ?>(<?= $mention['url'] ?>) if ($twt->replyToHash) {
<?php } ?> echo 'In reply to: <a href="' . $baseURL . '/conv/' . $twt->replyToHash . '">#' . $twt->replyToHash . '</a>';
--> //echo '<a href="/conv/'.$twt->replyToHash.'">Convesation</a>';
</div> }
<small> if ($twt->replyToHash && isset($_SESSION['password'])) {
<?php echo ' | ';
}
if($twt->replyToHash) {
echo 'In reply to: <a href="'.$baseURL.'/conv/'.$twt->replyToHash.'">#'.$twt->replyToHash.'</a>';
//echo '<a href="/conv/'.$twt->replyToHash.'">Convesation</a>';
}
if ($twt->replyToHash && isset($_SESSION['password'])) { if (isset($_SESSION['password'])) {
echo ' | '; echo '<a href="' . $baseURL . '/new?hash=' . $twt->hash . '">Reply</a>';
} }
if (isset($_SESSION['password'])) { ?>
echo '<a href="'.$baseURL.'/new?hash='.$twt->hash.'">Reply</a>'; <!-- (<a href="new_twt.php?hash=<?=$twt->hash?>">via email</a>) TODO: mailto-link -->
} <a href='<?=$baseURL?>/post/<?=$twt->hash?>' class="right"><span title="<?=$twt->fullDate?> "><?=$twt->displayDate?></span></a>
</small>
?> </div>
<!-- (<a href="new_twt.php?hash=<?= $twt->hash ?>">via email</a>) TODO: mailto-link --> </article>
<a href='<?= $baseURL ?>/post/<?= $twt->hash ?>' class="right"><span title="<?= $twt->fullDate ?> "><?= $twt->displayDate ?></span></a>
</small>
</div>
</article>
<?php }
<?php }
if (!isset($_SESSION['password'])) { 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>'; echo '<center><a href="mailto:' . $config['email'] . '?subject=RE: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="button">Comment via email</a></center>';
} }
?> ?>

View file

@ -30,13 +30,13 @@ if (!empty($_GET['url'])) { // Show twts for some user
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile; $parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
} }
} }
else { // Show timeline for the URL else { // Show timeline for the URL
$twtsURL = $config['public_txt_url']; $twtsURL = $config['public_txt_url'];
// $twtsURL = "https://lyse.isobeef.org/twtxt.txt"; // $twtsURL = "https://lyse.isobeef.org/twtxt.txt";
// $profile = getTwtsFromTwtxtString($twtsURL); // $profile = getTwtsFromTwtxtString($twtsURL);
header("Location: ".$baseURL."/profile?url=".$twtsURL); header("Location: ".$baseURL."/profile?url=".$twtsURL);
/* /*
if (filter_var($twtsURL, FILTER_VALIDATE_URL) === FALSE) { if (filter_var($twtsURL, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL'); die('Not a valid URL');
@ -59,7 +59,7 @@ foreach ($parsedTwtxtFiles as $currentTwtFile) {
krsort($twts, SORT_NUMERIC); krsort($twts, SORT_NUMERIC);
?> ?>
<div class="profile"> <div class="profile">
@ -75,13 +75,13 @@ krsort($twts, SORT_NUMERIC);
<p><?= $profile->description ?></p> <p><?= $profile->description ?></p>
<small> <small>
<!-- <a href="">Posts</a> | <!-- <a href="">Posts</a> |
<a href="">Replies</a> | <a href="">Replies</a> |
<a href="">Gallery</a> | <a href="">Gallery</a> |
--> -->
<!-- <span class="right"> --> <!-- <span class="right"> -->
<!-- <a href="/following.php">Following <?php echo count($twtFollowingList); ?></a> | --> <!-- <a href="/following.php">Following <?php echo count($twtFollowingList); ?></a> | -->
<a target="_blank" href="<?= $profile->mainURL ?>"></i>twtxt.txt</a> | <a target="_blank" href="<?= $profile->mainURL ?>"></i>twtxt.txt</a> |
<a href="https://yarn.social">How to follow</a> <a href="https://yarn.social">How to follow</a>
<!-- </span> --> <!-- </span> -->
@ -94,7 +94,7 @@ krsort($twts, SORT_NUMERIC);
<!-- PHP: NEW POST BOX --> <!-- PHP: NEW POST BOX -->
<?php <?php
if( isset($_SESSION['password'])) { if( isset($_SESSION['password'])) {
include 'views/new_twt.php'; // TODO: Split up new_twt into a view and a partial include 'views/new_twt.php'; // TODO: Split up new_twt into a view and a partial
} ?> } ?>

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 // TODO: Give a warning if the file is not found
$config = parse_ini_file('private/config.ini'); $config = parse_ini_file('private/config.ini');
@ -66,8 +67,6 @@ if (isset($_POST['url'])) {
} else { ?> } else { ?>
<?php <?php
require_once("partials/base.php");
$title = "Add feed - ".$title; $title = "Add feed - ".$title;
include 'partials/header.php'; 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 // Get the hashes (both post and replies) as $id from the router and return an inverted list
if (!empty($id)) { 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> <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 <?php
if (isset($_SESSION['password'])) { if (isset($_SESSION['password'])) {

View file

@ -10,7 +10,7 @@ include 'partials/header.php';
<h1><?= $profile->nick ?> follows <?php echo count($twtFollowingList); ?> feeds</h1> <h1><?= $profile->nick ?> follows <?php echo count($twtFollowingList); ?> feeds</h1>
<table> <table>
<tr> <tr>
<!-- <th></th> --> <!-- <th></th> -->
<th>Nick</th> <th>Nick</th>

View file

@ -8,7 +8,7 @@ include_once 'partials/header.php';
<!-- PHP: PROFILE CARD --> <!-- PHP: PROFILE CARD -->
<?php <?php
if (!empty($_GET['profile'])) { // Show twts for some user if (!empty($_GET['profile'])) { // Show twts for some user
$twtsURL = $_GET['profile']; $twtsURL = $_GET['profile'];
@ -34,8 +34,7 @@ if (!empty($_GET['profile'])) { // Show twts for some user
<!-- PHP: GALLERY --> <!-- PHP: GALLERY -->
<div class="gallery"> <div class="gallery">
<?php <?php
foreach ($twts as $twt) { foreach ($twts as $twt) {
$img_array = getImagesFromTwt($twt->content); $img_array = getImagesFromTwt($twt->content);
@ -43,8 +42,7 @@ foreach ($twts as $twt) {
$img_link = $img[0]; $img_link = $img[0];
echo '<a href="'.$baseURL.'/post/'.$twt->hash.'">'.$img_link.'</a>'; 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>'; // Workaround until cache issue is resolved
//echo '<a href="'.$baseURL.'/?profile='.$twt->mainURL.'#'.$twt->hash.'">'.$img[0].'</a>';
} }
} }
?> ?>

View file

@ -1,32 +1,39 @@
<?php <?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'; include_once 'partials/header.php';
?> ?>
<!-- PHP: PROFILE CARD --> <!-- PHP: PROFILE CARD -->
<?php <?php
if (!empty($_GET['profile'])) { // Show twts for some user if (!empty($_GET['profile'])) { // Show twts for some user (Profile view)
$twtsURL = $_GET['profile']; $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)) { if (!is_null($parsedTwtxtFile)) {
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile; $parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
include 'partials/profile.php'; include 'partials/profile.php';
} }
} ?> }
?>
<!-- PHP: NEW POST BOX --> <!-- PHP: NEW POST BOX -->
<?php <?php
if( isset($_SESSION['password'])) { if (isset($_SESSION['password'])) {
include 'views/new_twt.php'; // TODO: Split up new_twt into a view and a partial include 'views/new_twt.php'; // TODO: Split up new_twt into a view and a partial
} }
?> ?>
@ -34,4 +41,3 @@ if( isset($_SESSION['password'])) {
<!-- PHP: TIMELINE --><?php include_once 'partials/timeline.php'?> <!-- PHP: TIMELINE --><?php include_once 'partials/timeline.php'?>
<!-- PHP: FOOTER --><?php include_once 'partials/footer.php';?> <!-- PHP: FOOTER --><?php include_once 'partials/footer.php';?>

View file

@ -5,11 +5,11 @@ $title = "Login - ".$title;
include 'partials/header.php'; include 'partials/header.php';
?> ?>
<?php <?php
//$config = parse_ini_file('private/config.ini'); //$config = parse_ini_file('private/config.ini');
//$password = $config['password']; //$password = $config['password'];
if( isset($_SESSION['password'])) { if( isset($_SESSION['password'])) {
if($_SESSION['password']=="$password") { if($_SESSION['password']=="$password") {
header("Location: ."); header("Location: .");

View file

@ -84,12 +84,11 @@ if (isset($_POST['submit'])) {
exit; exit;
} 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';
?> ?>
<article id="new_twt"> <article id="new_twt">

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 // Get the hash (only post, not replies) as $id from the router
if (!empty($id)) { if (!empty($id)) {