Profile as default if not logged in is working

This commit is contained in:
sorenpeter 2023-10-31 22:50:37 +01:00
parent 69b2b9765f
commit f6e9e9577b
5 changed files with 89 additions and 46 deletions

View file

@ -81,7 +81,7 @@ $twtFollowingList = [];
// Show twts only for URL in query request, else show user timeline
if (!empty($_GET['twts'])) { // Show twts for some user
if (!empty($_GET['twts'])) { // Show twts for some user --> /profile
$twtsURL = $_GET['twts'];
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');
@ -92,7 +92,7 @@ if (!empty($_GET['twts'])) { // Show twts for some user
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
}
} else { // Show timeline for the URL
} else { // Show timeline for the URL --> / (home)
$parsedTwtxtFiles = [];
foreach ($fileLines as $currentLine) {
if (str_starts_with($currentLine, '#')) {
@ -120,7 +120,7 @@ foreach ($parsedTwtxtFiles as $currentTwtFile) {
}
}
// Show individual posts
# Show individual posts
if (!empty($_GET['hash'])) {
$hash = $_GET['hash'];
$twts = array_filter($twts, function($twt) use ($hash) {

View file

@ -1,3 +1,10 @@
<?php
$profile = getTwtsFromTwtxtString($config['public_txt_url']);
$profile = getTwtsFromTwtxtString("http://darch.dk/twtxt.txt");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
@ -10,18 +17,23 @@
<header>
<p>
🧶 <a href="/">Timeline</a> for
<a href="http://localhost:8000/?twts=http://darch.dk/twtxt.txt">sorenpeter</a>@darch.dk
(<a href="http://localhost:8000/twtxt.txt">twtxt.txt</a>)
<a href="/">
<img class="avatar" src="<?= $profile->avatar ?>" alt="" loading="lazy">
Timeline for <?= $profile->nick ?>@<?= parse_url($profile->mainURL, PHP_URL_HOST); ?>
</a>
<!-- <a href="/">🧶 Timeline for <?= $url ?> </a> -->
<!-- for <a href="http://localhost:8000/?twts=http://darch.dk/twtxt.txt">sorenpeter</a>@darch.dk -->
<!-- (<a href="http://localhost:8000/twtxt.txt">twtxt.txt</a>) -->
</p>
<nav>
<!-- TODO: make automatic via PHP and show avatar as well -->
<ul class="secondary">
<li><a href="/refresh?url=<?= $url ?>">Refresh</a></li>
<li><a href="/following">Following <?php // echo count($twtFollowingList); ?></a></li>
<?php //if ($validSession) { // TODO: Make login seqcure ?>
<?php if( isset($_SESSION['password'])) { /*
if($_SESSION['password']=="$password") {*/ // Hacky login ?>
<li><a href="/refresh?url=<?= $url ?>">Refresh</a></li>
<li><a href="/following">Following <?php // echo count($twtFollowingList); ?></a></li>
<!-- <li><a href="/new">New post</a></li> -->
<li><a href="/add">Add feed</a></li>
<!-- <li><a href="/admin">Settings</a></li> -->

View file

@ -68,7 +68,11 @@ header > nav a {
margin: 0.25rem 0rem;
}*/
header img.avatar {
height: 1.5rem;
width: 1.5rem;
vertical-align: sub;
}
header p a,
header p a:visited {
@ -152,6 +156,16 @@ a.author {
color: var(--text-light);
}
.profile a,
.profile a:visited {
color: var(--text);
}
.profile a:hover {
color: var(--accent);
}
/* === TIMELINE === */
article {
@ -204,6 +218,10 @@ article small a:visited {
}
article small a:hover {
color: var(--accent);
}
/* === New Post Form === */
#new_twt {

View file

@ -33,13 +33,44 @@ if (!empty($_GET['twts'])) { // Show profile for some user
if (isset($_SESSION['password'])) {
include 'views/new_twt.php'; // TODO: Split up new_twt into a view and a partial
}
/*
else {
$url = "Location: /?twts=".$config['public_txt_url'];
//header($url);
$twtsURL = $config['public_txt_url'];
// $twtsURL = "http://darch.dk/twtxt.txt";
header("Location: /profile?url=".$twtsURL);
// die();
}
?>
<?php // Load user timeline
$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;
}
}
}
}
$twts = [];
# Combine all the followers twts
foreach ($parsedTwtxtFiles as $currentTwtFile) {
if (!is_null($currentTwtFile)) {
$twts += $currentTwtFile->twts;
}
}
*/
?>

View file

@ -9,19 +9,19 @@ include('partials/header.php');
<!-- PHP: PROFILE CARD -->
<?php
$twtsURL = $config['public_txt_url'];
// $twtsURL = "http://darch.dk/twtxt.txt";
//$twtsURL = $config['public_txt_url'];
//$profile = getTwtsFromTwtxtString($twtsURL);
/* from base.php */
# Show twts only for URL in query request, else show user timeline
if (!empty($_GET['url'])) { // Show twts for some user
echo "before GET(url): ".$twtsURL."<br>";
$twtsURL = $_GET['url'];
echo "after GET(url): ".$twtsURL."<br>";
$profile = getTwtsFromTwtxtString($twtsURL);
if (filter_var($twtsurl, FILTER_VALIDATE_URL) === FALSE) {
if (filter_var($twtsURL, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');
}
@ -30,18 +30,22 @@ if (!empty($_GET['url'])) { // Show twts for some user
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
}
} else { // Show timeline for the URL
}
else { // Show timeline for the URL
$twtsURL = $config['public_txt_url'];
//$twtsURL = "http://darch.dk/twtxt.txt";
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
// $twtsURL = "https://lyse.isobeef.org/twtxt.txt";
// $profile = getTwtsFromTwtxtString($twtsURL);
header("Location: /profile?url=".$twtsURL);
/*
if (filter_var($twtsURL, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');
}
$parsedTwtxtFile = getTwtsFromTwtxtString($twtsURL);
if (!is_null($parsedTwtxtFile)) {
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
}
}*/
}
$twts = [];
@ -55,28 +59,6 @@ foreach ($parsedTwtxtFiles as $currentTwtFile) {
krsort($twts, SORT_NUMERIC);
/* Profile header
if (empty($_GET['url'])) { // Show twts for some user
$twtsURL = $config['txt_file_path'];
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
die('Not a valid URL');
}
$parsedTwtxtFile = getTwtsFromTwtxtString($twtsURL);
if (!is_null($parsedTwtxtFile)) {
$parsedTwtxtFiles[$parsedTwtxtFile->mainURL] = $parsedTwtxtFile;
}
}
*/
echo $twtsURL;
$profile = getTwtsFromTwtxtString($twtsURL);
?>
<div class="profile">