Fix /conv not showing some threads.

This commit is contained in:
e-emmanuel_parada 2023-12-28 11:42:23 -06:00
parent c65003e3db
commit a4cb00d918
12 changed files with 146 additions and 194 deletions

View file

@ -1,58 +1,27 @@
<?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');
@ -64,9 +33,6 @@ 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);
@ -119,12 +85,11 @@ foreach ($parsedTwtxtFiles as $currentTwtFile) {
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'])) {
@ -136,7 +101,10 @@ 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

@ -4,33 +4,32 @@
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,36 +1,29 @@
<!-- <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?>
<!-- Not sure what this does...
<?php foreach ($twt->mentions as $mention) { ?>
<br><?= $mention['nick'] ?>(<?= $mention['url'] ?>)
<?php } ?>
-->
</div> </div>
<small> <small>
<?php <?php
if ($twt->replyToHash) {
if($twt->replyToHash) { echo 'In reply to: <a href="' . $baseURL . '/conv/' . $twt->replyToHash . '">#' . $twt->replyToHash . '</a>';
echo 'In reply to: <a href="'.$baseURL.'/conv/'.$twt->replyToHash.'">#'.$twt->replyToHash.'</a>';
//echo '<a href="/conv/'.$twt->replyToHash.'">Convesation</a>'; //echo '<a href="/conv/'.$twt->replyToHash.'">Convesation</a>';
} }
@ -39,21 +32,20 @@
} }
if (isset($_SESSION['password'])) { if (isset($_SESSION['password'])) {
echo '<a href="'.$baseURL.'/new?hash='.$twt->hash.'">Reply</a>'; 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="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> <a href='<?=$baseURL?>/post/<?=$twt->hash?>' class="right"><span title="<?=$twt->fullDate?> "><?=$twt->displayDate?></span></a>
</small> </small>
</div> </div>
</article> </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

@ -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

@ -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

@ -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)) {