mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-15 10:57:01 +00:00
Webfinger lookup is now part of add_feed
This commit is contained in:
parent
a65727ccd4
commit
35e7d96780
6 changed files with 89 additions and 19 deletions
|
|
@ -190,7 +190,8 @@ article.post-entry {
|
|||
}
|
||||
|
||||
article .twt-msg {
|
||||
padding: 0.5rem 0;
|
||||
padding: 0.5rem 0.5rem 0.5rem 0 ;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
article .twt-msg > blockquote {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
// Private lists
|
||||
echo "<option disabled>Private Lists:</option>";
|
||||
foreach (glob("private/twtxt-*.txt") as $filename) {
|
||||
if($filename == $_GET['lists']) $attr="selected";
|
||||
if($filename == $_GET['list']) $attr="selected";
|
||||
else $attr = "";
|
||||
$listName = $filename;
|
||||
$listName = str_replace("private/twtxt-", "", $listName);
|
||||
|
|
@ -28,7 +28,7 @@
|
|||
}
|
||||
|
||||
foreach (glob("twtxt-*.txt") as $filename) {
|
||||
if($filename == $_GET['lists']) $attr="selected";
|
||||
if($filename == $_GET['list']) $attr="selected";
|
||||
else $attr = "";
|
||||
$listName = $filename;
|
||||
$listName = str_replace("twtxt-", "", $listName);
|
||||
|
|
|
|||
48
partials/webfinger_lookup.php
Normal file
48
partials/webfinger_lookup.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
function splitNickDomain($str) {
|
||||
$str = trim($str);
|
||||
$str = str_replace("acct:", "", $str); // remove "acct:" prefix
|
||||
$str = ltrim($str, "@"); // remove leading "@"
|
||||
if (filter_var($str, FILTER_VALIDATE_EMAIL) ) {
|
||||
return array("nick" => explode("@",$str)[0], "domain" => explode("@",$str)[1] );
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
$wf_acct = "";
|
||||
$wf_nick = "";
|
||||
$wf_url = "";
|
||||
$wf_error = "";
|
||||
|
||||
if(isset($_POST['submit'])) {
|
||||
$wf_request = $_POST["webfinger"];
|
||||
|
||||
$wf_acct = splitNickDomain($wf_request);
|
||||
if($wf_acct === FALSE) { $wf_error = "ERROR: ".$wf_request." does not look like a valid webfinger handle"; }
|
||||
|
||||
$wf_json = file_get_contents("https://".$wf_acct["domain"]."/.well-known/webfinger?resource=acct:".$wf_acct["nick"]."@".$wf_acct["domain"]);
|
||||
//if($wf_json === FALSE) { $wf_error = "ERROR: Chould not find a twtxt feed at webfinger endpoint ".$wf_request; }
|
||||
|
||||
$wf_array = json_decode($wf_json, true);
|
||||
|
||||
$wf_domain = splitNickDomain($wf_array["subject"])["domain"];
|
||||
|
||||
foreach( $wf_array["links"] as $link ) {
|
||||
|
||||
if ( $link["rel"] == "self" AND $link["type"] == "text/plain") {
|
||||
|
||||
if ( filter_var($link["href"], FILTER_VALIDATE_URL) ) {
|
||||
$wf_url = $link["href"];
|
||||
|
||||
$wf_nick = splitNickDomain($wf_array["subject"])["nick"];
|
||||
$wf_error = "URL to twtxt.txt found for ".$wf_nick ."@".$wf_domain;
|
||||
break;
|
||||
}
|
||||
} else { $wf_error = "ERROR: Chould not find a twtxt feed at webfinger endpoint ".$wf_acct["domain"]; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//else { $wf_error = "Chould not find webfinger endpoint at ".$wf_acct["domain"]; }
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
require_once('partials/base.php');
|
||||
require_once('partials/webfinger_lookup.php');
|
||||
|
||||
// TODO: Give a warning if the file is not found
|
||||
$config = parse_ini_file('private/config.ini');
|
||||
|
|
@ -72,17 +73,25 @@ $title = "Add feed - ".$title;
|
|||
include 'partials/header.php';
|
||||
?>
|
||||
|
||||
<h2>Webfinger lookup</h2>
|
||||
|
||||
<form method="post" action="">
|
||||
<label>Check if a webfinger handle has a link to a twtxt.txt feed</label>
|
||||
<input type="text" name="webfinger" size="50" autocomplete="off" required placeholder="name@example.com" value="<?= $wf_request; ?>">
|
||||
<br>
|
||||
<input type="submit" name="submit" value="Lookup"><br>
|
||||
</form>
|
||||
|
||||
<?= $wf_error; ?>
|
||||
|
||||
<h1>Add a new feed to follow</h1>
|
||||
|
||||
<form method="POST" class="column">
|
||||
<div id="follow">
|
||||
<label for="url">URL to follow</label>
|
||||
<br>
|
||||
<input type="url" id="url" name="url" class="input" size="50" autocomplete="off" required>
|
||||
<br>
|
||||
<label for="nick">Nick</label>
|
||||
<br>
|
||||
<input type="text" id="nick" name="nick" class="input" size="50" autocomplete="off" required>
|
||||
<input type="text" id="nick" name="nick" class="input" size="50" autocomplete="off" required value="<?= $wf_nick; ?>">
|
||||
<label for="url">URL to follow</label>
|
||||
<input type="url" id="url" name="url" class="input" size="50" autocomplete="off" required value="<?= $wf_url; ?>">
|
||||
<br>
|
||||
<input type="submit" value="Follow" class="btn">
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ include 'partials/header.php';
|
|||
<!-- <th></th> -->
|
||||
<th>Nick</th>
|
||||
<th>URL</th>
|
||||
<th>Time ago</th>
|
||||
<?php if($_SESSION['password']=="$password") { ?>
|
||||
<th>Time ago</th>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
|
||||
<?php foreach ($twtFollowingList as $currentFollower) { ?>
|
||||
|
|
@ -28,12 +30,13 @@ include 'partials/header.php';
|
|||
<!-- <a href="?remove_url=<?= $currentFollower[1] ?>">Remove</a> -->
|
||||
<!-- <?php // } ?> -->
|
||||
</td>
|
||||
<?php if($_SESSION['password']=="$password") { ?>
|
||||
<td>
|
||||
<?php
|
||||
// Test first if URL is a valid feed:
|
||||
if (is_array(getTwtsFromTwtxtString($currentFollower[1])->twts)) {
|
||||
|
||||
// Then test if latest twt is at top or bottom of file:
|
||||
// Then test if latest twt is at start or end of file:
|
||||
$resetVar = reset(getTwtsFromTwtxtString($currentFollower[1])->twts);
|
||||
$endVar = end(getTwtsFromTwtxtString($currentFollower[1])->twts);
|
||||
if ($resetVar->timestamp < $endVar->timestamp) { // TODO: this can be swapped to get time of first twt
|
||||
|
|
@ -45,6 +48,8 @@ include 'partials/header.php';
|
|||
?>
|
||||
|
||||
</td>
|
||||
<?php } ?>
|
||||
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
|
|
|
|||
|
|
@ -55,16 +55,18 @@ if (isset($_POST['submit'])) {
|
|||
|
||||
$contents = file_get_contents($txt_file_path);
|
||||
|
||||
if (!date_default_timezone_set($timezone)) {
|
||||
/*if (!date_default_timezone_set($timezone)) {
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
}*/ // Turned this off, so now the server need to have set the right timezone, seem to work for CET
|
||||
|
||||
//$datetime = gmdate('Y-m-d\TH:i:s\Z', $date->format('U'));
|
||||
//$twt = $datetime . "\t$new_post\n";
|
||||
$twt = date('c') . "\t$new_post\n";
|
||||
//$twt = date('c') . "\t$new_post\n";
|
||||
$datetime = date('Y-m-d\TH:i:sp'); // abracting to be used for webmentions
|
||||
$twt = "\n" . $datetime . "\t" .$new_post; // NB: only works with PHP 8
|
||||
|
||||
|
||||
if (strpos($contents, NEW_TWT_MARKER) !== false) {
|
||||
// TODO: Turn off append at top?!
|
||||
/*if (strpos($contents, NEW_TWT_MARKER) !== false) {
|
||||
// Add the previous marker
|
||||
// Take note that doesn't not work if twtxt file has CRLF line ending
|
||||
// (which is wrong anyway)
|
||||
|
|
@ -73,15 +75,20 @@ if (isset($_POST['submit'])) {
|
|||
} else {
|
||||
// Fall back if the marker is not found.
|
||||
$contents .= $twt;
|
||||
}
|
||||
}*/
|
||||
|
||||
// Append twt at the end of file
|
||||
$contents .= $twt;
|
||||
|
||||
|
||||
// TODO: Add error handling if write to the file fails
|
||||
// For example due to permissions problems
|
||||
// https://www.w3docs.com/snippets/php/how-can-i-handle-the-warning-of-file-get-contents-function-in-php.html
|
||||
$file_write_result = file_put_contents($txt_file_path, $contents);
|
||||
|
||||
header('Refresh:0; url=.');
|
||||
exit;
|
||||
//header('Refresh:0; url=.');
|
||||
header("Location: refresh?url=".$public_txt_url); // Trying to fix issue with douple posting
|
||||
exit; //
|
||||
|
||||
} else {
|
||||
require_once("partials/base.php");
|
||||
|
|
|
|||
Loading…
Reference in a new issue