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

@ -2,32 +2,16 @@
# 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
@ -35,24 +19,9 @@ $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);
@ -124,7 +90,6 @@ if (!empty($_GET['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']);
} }
// If we should paginate our twts list
if (!empty($paginateTwts)) {
$startingTwt = (($page - 1) * TWTS_PER_PAGE); $startingTwt = (($page - 1) * TWTS_PER_PAGE);
$twts = array_slice($twts, $startingTwt, 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,10 +4,9 @@
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">
@ -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,10 +1,10 @@
<!-- <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?>">
@ -18,17 +18,10 @@
<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>';
@ -51,7 +44,6 @@
<?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,28 +1,35 @@
<?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
@ -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,7 +84,6 @@ 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;

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