mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-15 19:07:01 +00:00
merged
This commit is contained in:
commit
43c29c28ab
12 changed files with 146 additions and 196 deletions
|
|
@ -1,77 +1,43 @@
|
|||
<?php
|
||||
# Shows the timeline for a user
|
||||
declare(strict_types=1);
|
||||
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
|
||||
|
||||
// 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'];
|
||||
// }
|
||||
if (!empty($_GET['list'])) {
|
||||
$url = "https://darch.dk/twtxt-lists/" . $_GET['list'];
|
||||
} else {
|
||||
$url = $config['public_txt_url'];
|
||||
//$url = "https://darch.dk/twtxt-lists/twtxt.txt";
|
||||
$url = $config['public_txt_url'];
|
||||
}
|
||||
*/
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
if (!empty($_GET['url'])) {
|
||||
$url = $_GET['url'];
|
||||
$url = $_GET['url'];
|
||||
}
|
||||
|
||||
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'];
|
||||
$fileContent = getCachedFileContentsOrUpdate($url, $cacheRefreshTime);
|
||||
|
||||
if ($fileContent === false) {
|
||||
die("$url couldn't be retrieved.");
|
||||
die("$url couldn't be retrieved.");
|
||||
}
|
||||
|
||||
$fileContent = mb_convert_encoding($fileContent, 'UTF-8');
|
||||
|
|
@ -79,64 +45,66 @@ $fileLines = explode("\n", $fileContent);
|
|||
$twtFollowingList = [];
|
||||
|
||||
if (!empty($_GET['profile'])) { // Show profile for some user
|
||||
$twtsURL = $_GET['profile'];
|
||||
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
|
||||
die('Not a valid URL');
|
||||
}
|
||||
$twtsURL = $_GET['profile'];
|
||||
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
|
||||
die('Not a valid URL');
|
||||
}
|
||||
|
||||
$parsedTwtxtFile = getTwtsFromTwtxtString($twtsURL);
|
||||
if (!is_null($parsedTwtxtFile)) {
|
||||
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
|
||||
}
|
||||
$parsedTwtxtFile = getTwtsFromTwtxtString($twtsURL);
|
||||
if (!is_null($parsedTwtxtFile)) {
|
||||
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
|
||||
}
|
||||
|
||||
} else { // Show timeline for the URL
|
||||
$parsedTwtxtFiles = [];
|
||||
foreach ($fileLines as $currentLine) {
|
||||
if (str_starts_with($currentLine, '#')) {
|
||||
if (!is_null(getDoubleParameter('follow', $currentLine))) {
|
||||
$follow = getDoubleParameter('follow', $currentLine);
|
||||
$twtFollowingList[] = $follow;
|
||||
$parsedTwtxtFiles = [];
|
||||
foreach ($fileLines as $currentLine) {
|
||||
if (str_starts_with($currentLine, '#')) {
|
||||
if (!is_null(getDoubleParameter('follow', $currentLine))) {
|
||||
$follow = getDoubleParameter('follow', $currentLine);
|
||||
$twtFollowingList[] = $follow;
|
||||
|
||||
// Read the parsed files if in Cache
|
||||
$followURL = $follow[1];
|
||||
$parsedTwtxtFile = getTwtsFromTwtxtString($followURL);
|
||||
if (!is_null($parsedTwtxtFile)) {
|
||||
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Read the parsed files if in Cache
|
||||
$followURL = $follow[1];
|
||||
$parsedTwtxtFile = getTwtsFromTwtxtString($followURL);
|
||||
if (!is_null($parsedTwtxtFile)) {
|
||||
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$twts = [];
|
||||
|
||||
# Combine all the followers twts
|
||||
foreach ($parsedTwtxtFiles as $currentTwtFile) {
|
||||
if (!is_null($currentTwtFile)) {
|
||||
$twts += $currentTwtFile->twts;
|
||||
}
|
||||
if (!is_null($currentTwtFile)) {
|
||||
$twts += $currentTwtFile->twts;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_GET['hash'])) {
|
||||
$hash = $_GET['hash'];
|
||||
$twts = array_filter($twts, function($twt) use ($hash) {
|
||||
return $twt->hash === $hash || $twt->replyToHash === $hash;
|
||||
});
|
||||
$hash = $_GET['hash'];
|
||||
$twts = array_filter($twts, function ($twt) use ($hash) {
|
||||
return $twt->hash === $hash || $twt->replyToHash === $hash;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
krsort($twts, SORT_NUMERIC);
|
||||
|
||||
if (!empty($_GET['hash'])) {
|
||||
$twts = array_reverse($twts, true);
|
||||
$twts = array_reverse($twts, true);
|
||||
}
|
||||
|
||||
$page = 1;
|
||||
if (!empty($_GET['page'])) {
|
||||
$page = intval($_GET['page']);
|
||||
$page = intval($_GET['page']);
|
||||
}
|
||||
|
||||
$startingTwt = (($page - 1) * TWTS_PER_PAGE);
|
||||
$twts = array_slice($twts, $startingTwt, TWTS_PER_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']);
|
||||
|
|
|
|||
|
|
@ -2,35 +2,34 @@
|
|||
|
||||
// Get info about profile from URL as an objects
|
||||
if (!empty($_GET['profile'])) {
|
||||
$url = $twtsURL;
|
||||
$url = $twtsURL;
|
||||
}
|
||||
|
||||
$profile = getTwtsFromTwtxtString($url);
|
||||
|
||||
$profileURL = $baseURL.'/?profile='.$profile->mainURL;
|
||||
|
||||
$profileURL = $baseURL . '/?profile=' . $profile->mainURL;
|
||||
?>
|
||||
|
||||
<div class="profile">
|
||||
|
||||
<a href="<?= $profileURL ?>">
|
||||
<img class="avatar" src="<?= $profile->avatar ?>" alt="" loading="lazy">
|
||||
<a href="<?=$profileURL?>">
|
||||
<img class="avatar" src="<?=$profile->avatar?>" alt="" loading="lazy">
|
||||
</a>
|
||||
|
||||
<div>
|
||||
<a href="<?= $profileURL ?>" class="author">
|
||||
<strong><?= $profile->nick ?></strong>@<?= parse_url($profile->mainURL, PHP_URL_HOST); ?>
|
||||
<a href="<?=$profileURL?>" class="author">
|
||||
<strong><?=$profile->nick?></strong>@<?=parse_url($profile->mainURL, PHP_URL_HOST);?>
|
||||
</a>
|
||||
|
||||
<p><?= $profile->description ?></p>
|
||||
<p><?=$profile->description?></p>
|
||||
|
||||
<small>
|
||||
<a href="<?= $profileURL ?>">Posts</a> |
|
||||
<a href="<?=$profileURL?>">Posts</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">
|
||||
<!-- <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>)
|
||||
</span>
|
||||
|
||||
|
|
@ -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> -->
|
||||
|
|
@ -1,59 +1,51 @@
|
|||
<!-- <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 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 }?>
|
||||
-->
|
||||
|
||||
<?php foreach ($twts as $twt) { ?>
|
||||
<article class="post-entry" id="<?= $twt->hash ?>">
|
||||
<a href="<?= $baseURL ?>/?profile=<?= $twt->mainURL ?>">
|
||||
<img src='<?= $twt->avatar ?>' class="avatar" onerror="this.onerror=null;this.src='imgs/image_not_found.png';">
|
||||
</a>
|
||||
<div>
|
||||
<a href="<?= $baseURL ?>/?profile=<?= $twt->mainURL ?>" class="author">
|
||||
<strong><?= $twt->nick ?></strong>@<?= parse_url($twt->mainURL, PHP_URL_HOST); ?>
|
||||
</a>
|
||||
<?php foreach ($twts as $twt) {?>
|
||||
<article class="post-entry" id="<?=$twt->hash?>">
|
||||
<a href="<?=$baseURL?>/?profile=<?=$twt->mainURL?>">
|
||||
<img src='<?=$twt->avatar?>' class="avatar" onerror="this.onerror=null;this.src='imgs/image_not_found.png';">
|
||||
</a>
|
||||
<div>
|
||||
<a href="<?=$baseURL?>/?profile=<?=$twt->mainURL?>" class="author">
|
||||
<strong><?=$twt->nick?></strong>@<?=parse_url($twt->mainURL, PHP_URL_HOST);?>
|
||||
</a>
|
||||
|
||||
<div class="twt-msg">
|
||||
<?= $twt->content ?>
|
||||
<div class="twt-msg">
|
||||
<?=$twt->content?>
|
||||
</div>
|
||||
|
||||
<!-- 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>';
|
||||
}
|
||||
|
||||
<small>
|
||||
<?php
|
||||
if ($twt->replyToHash && isset($_SESSION['password'])) {
|
||||
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 (isset($_SESSION['password'])) {
|
||||
echo '<a href="' . $baseURL . '/new?hash=' . $twt->hash . '">Reply</a>';
|
||||
}
|
||||
|
||||
if ($twt->replyToHash && isset($_SESSION['password'])) {
|
||||
echo ' | ';
|
||||
}
|
||||
|
||||
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>
|
||||
</article>
|
||||
?>
|
||||
<!-- (<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>
|
||||
</article>
|
||||
|
||||
<?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>';
|
||||
}
|
||||
echo '<center><a href="mailto:' . $config['email'] . '?subject=RE: ' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '" class="button">Comment via email</a></center>';
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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'])) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -1,32 +1,39 @@
|
|||
<?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
|
||||
if( isset($_SESSION['password'])) {
|
||||
if (isset($_SESSION['password'])) {
|
||||
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: FOOTER --><?php include_once 'partials/footer.php';?>
|
||||
|
||||
|
|
|
|||
|
|
@ -84,12 +84,11 @@ if (isset($_POST['submit'])) {
|
|||
exit;
|
||||
|
||||
} 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">
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue