|
@@ -17,31 +17,37 @@
|
|
|
*/
|
|
|
|
|
|
$SCRIPTNAME='pfaltgall';
|
|
|
-$SCRIPTVERSION='0.1';
|
|
|
+$SCRIPTVERSION='0.2';
|
|
|
|
|
|
require 'lib/ckratelimit.php';
|
|
|
require 'lib/httpjson.php';
|
|
|
|
|
|
$configfp=null;
|
|
|
+$outfp=null;
|
|
|
|
|
|
$conf=[
|
|
|
'host'=>null,
|
|
|
'token'=>null,
|
|
|
- 'accid'=>null
|
|
|
];
|
|
|
|
|
|
$help=
|
|
|
"[[[ SYNOPSIS ]]]
|
|
|
|
|
|
- {$SCRIPTNAME} [options] <configuration file path>
|
|
|
+ {$SCRIPTNAME} [options] <configuration file path> <output file path>
|
|
|
|
|
|
[[[ DESCRIPTION ]]]
|
|
|
|
|
|
This is {$SCRIPTNAME} v{$SCRIPTVERSION}, a CLI PHP script that can generate an html file with
|
|
|
-a gallery from your Pixelfed profile.
|
|
|
- In order to create it, you just need to login to your Pixelfed account and
|
|
|
-get an app token (Settings -> Applications -> Create new token), then create
|
|
|
-a configuration file for {$SCRIPTNAME} like this (don’t write the «---» lines):
|
|
|
+a gallery from your Pixelfed profile. The html gallery file will load images
|
|
|
+dynamically, display each one using almost all the available screen space and
|
|
|
+will let you jump right from the start to any point in the timeline. It will
|
|
|
+also show each post’s text content, its date, and each image description
|
|
|
+(alt-text), if present.
|
|
|
+ See my example gallery here: https://rame.altervista.org/foto-pixelfed
|
|
|
+ In order to create the html gallery file, you just need to login to your
|
|
|
+Pixelfed account and get an app token (Settings -> Applications -> Create new
|
|
|
+token), then create a configuration file for {$SCRIPTNAME} like this (don’t write
|
|
|
+the «---» lines):
|
|
|
|
|
|
---
|
|
|
host=your_instance_host
|
|
@@ -55,10 +61,11 @@ host=pixelfed.social
|
|
|
token=as7f8a7s0d89f7as97df09a8s7d90f81jkl2h34lkj12h3jkl4
|
|
|
---
|
|
|
|
|
|
- Then run {$SCRIPTNAME} with the path of the configuration file you have
|
|
|
-created as an argument. This will create an «index.html» file in the current
|
|
|
-directory, that will be ready to be put where you want (you can also see it
|
|
|
-locally, obviously).
|
|
|
+ Then run {$SCRIPTNAME} with the path of the configuration file you have created
|
|
|
+and the path of an output file as arguments (if the output file exists, it
|
|
|
+will be overwritten), e.g.: «{$SCRIPTNAME} goofy@pixelfed.social.conf index.html».
|
|
|
+ This will create an html file that will be ready to be put where you want
|
|
|
+(you’ll also be able to see it locally, obviously).
|
|
|
|
|
|
[[[ OPTIONS ]]]
|
|
|
|
|
@@ -80,14 +87,24 @@ for ($i=1; $i<$argc; $i++) {
|
|
|
exit(0);
|
|
|
} elseif (is_null($configfp)) {
|
|
|
$configfp=$argv[$i];
|
|
|
+ } elseif (is_null($outfp)) {
|
|
|
+ $outfp=$argv[$i];
|
|
|
} else {
|
|
|
- eecho("Error: «{$argv[$i]}» is not a valid option and the configuration file has already been set to «{$configfp}» (use «-h» or «--help» to read help).\n");
|
|
|
+ eecho("Error: «{$argv[$i]}» is not a valid option and configuration file and output file have already been set to «{$configfp}» and «{$outfp}» (use «-h» or «--help» to read help).\n");
|
|
|
exit(1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-if (is_null($configfp)) {
|
|
|
- eecho("Error: you have not specified a config file (use «-h» or «--help» to read help).\n");
|
|
|
+$errors=[];
|
|
|
+if (is_null($configfp))
|
|
|
+ $errors[]="you have not specified a config file";
|
|
|
+if (is_null($outfp))
|
|
|
+ $errors[]="you have not specified an output file";
|
|
|
+if (count($errors)>0) {
|
|
|
+ eecho("Errors:\n");
|
|
|
+ foreach ($errors as $val)
|
|
|
+ eecho(" - {$val}\n");
|
|
|
+ eecho("Use «-h» or «--help» to read help.\n");
|
|
|
exit(1);
|
|
|
}
|
|
|
|
|
@@ -117,13 +134,13 @@ foreach ($conf as $key=>$val)
|
|
|
$acc=httpjson("https://{$conf['host']}/api/v1/accounts/verify_credentials",null,null,null,null,$conf['token']);
|
|
|
//print_r($res);
|
|
|
if (!$acc['ok']) {
|
|
|
- eecho("Error: {$SCRIPTNAME} could not retrieve the account id associated with the given token ({$acc['errors']}).\n");
|
|
|
+ eecho("Error: {$SCRIPTNAME} could not retrieve the account associated with the given token ({$acc['errors']}).\n");
|
|
|
exit(2);
|
|
|
}
|
|
|
ckrl($acc['headers']);
|
|
|
$acc=$acc['content'];
|
|
|
|
|
|
-$urls=[];
|
|
|
+$imgurls=[];
|
|
|
$imgs='';
|
|
|
$i=0;
|
|
|
$ic=0;
|
|
@@ -143,7 +160,7 @@ do {
|
|
|
foreach ($res['content'] as $status) {
|
|
|
if (isset($status['created_at']) && preg_match('#^\s+$#',$status['created_at'])!==1) {
|
|
|
$date=strtotime($status['created_at']);
|
|
|
- $date=' ['.date('Y/m/d',$date).']';
|
|
|
+ $date=' <span class="grey">['.date('Y/m/d',$date).']</span>';
|
|
|
} else {
|
|
|
$date='';
|
|
|
}
|
|
@@ -159,7 +176,8 @@ do {
|
|
|
$ia=0;
|
|
|
foreach ($status['media_attachments'] as $attachment) {
|
|
|
if (isset($attachment['url'])) {
|
|
|
- $url=$attachment['url'];
|
|
|
+ $imgurl=$attachment['url'];
|
|
|
+ $imgurls[]=$imgurl;
|
|
|
$ia++;
|
|
|
if (isset($attachment['description']) && preg_match('#^\s+$#',$attachment['description'])!==1)
|
|
|
$altdesc=' alt="'.htmlspecialchars(trim($attachment['description']),ENT_QUOTES|ENT_HTML5).'"';
|
|
@@ -169,7 +187,7 @@ do {
|
|
|
$icnt=" ({$ia}/{$ca})";
|
|
|
else
|
|
|
$icnt='';
|
|
|
- $imgs.="<div class=\"page\"><table class=\"imgtab\"><tr><td class=\"imgcel\"><a href=\"{$url}\" name=\"img{$ic}\"><img class=\"img\" decoding=\"async\" loading=\"lazy\" src=\"{$url}\"{$altdesc}></a></td></tr><caption class=\"imgcaptcel\">{$desc}{$icnt}{$date}</caption></table></div>\n";
|
|
|
+ $imgs.="<div class=\"page\"><table class=\"imgtab\"><tr><td class=\"imgcel\"><a href=\"{$imgurl}\" name=\"img{$ic}\"><img class=\"img\" decoding=\"async\" loading=\"lazy\" id=\"img{$ic}\" src=\"{$acc['avatar_static']}\"{$altdesc}></a></td></tr><caption class=\"imgcaptcel\">{$desc}{$icnt}{$date}</caption></table></div>\n";
|
|
|
$ic++;
|
|
|
}
|
|
|
}
|
|
@@ -261,6 +279,10 @@ p.center {
|
|
|
border-radius: 12px;
|
|
|
}
|
|
|
|
|
|
+.grey {
|
|
|
+ color: #888;
|
|
|
+}
|
|
|
+
|
|
|
hr {
|
|
|
display: block;
|
|
|
border: none;
|
|
@@ -381,9 +403,48 @@ hr {
|
|
|
}
|
|
|
}
|
|
|
</style>
|
|
|
+<script type="text/javascript">
|
|
|
+let imgurls=["'.implode('", "',$imgurls).'"];
|
|
|
+let phimgurl="'.$acc['avatar_static'].'";//placeholder image url
|
|
|
+function prel() {
|
|
|
+ var md=document.getElementById("maindiv"),
|
|
|
+ ph=window.innerHeight,
|
|
|
+ th=md.scrollHeight,
|
|
|
+ pages=Math.round(th/ph),
|
|
|
+ sy=Math.round(md.scrollTop),
|
|
|
+ page=Math.round(pages-(th-sy)/ph)+1,
|
|
|
+ img,
|
|
|
+ u;
|
|
|
+ //console.log(ph+" "+th+" "+pages+" "+sy+" "+page);
|
|
|
+ if (page>1) {//current
|
|
|
+ img=document.getElementById("img"+(page-2));
|
|
|
+ if (img.src==phimgurl) {
|
|
|
+ u=imgurls[page-2];
|
|
|
+ img.src=u;
|
|
|
+ img.loading="eager";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (page<pages) {//next
|
|
|
+ img=document.getElementById("img"+(page-1));
|
|
|
+ if (img.src==phimgurl) {
|
|
|
+ u=imgurls[page-1];
|
|
|
+ img.src=u;
|
|
|
+ img.loading="eager";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (page>2) {//previous
|
|
|
+ img=document.getElementById("img"+(page-3));
|
|
|
+ if (img.src==phimgurl) {
|
|
|
+ u=imgurls[page-3];
|
|
|
+ img.src=u;
|
|
|
+ img.loading="eager";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
</head>
|
|
|
-<body>
|
|
|
-<div id="maindiv">
|
|
|
+<body onload="prel();">
|
|
|
+<div id="maindiv" onscrollend="prel();">
|
|
|
<div class="page">
|
|
|
<div class="profile">
|
|
|
<p class="center"><img src="'.$acc['avatar_static'].'" class="avatar"></p>
|
|
@@ -397,7 +458,10 @@ hr {
|
|
|
</html>
|
|
|
';
|
|
|
|
|
|
-file_put_contents('index.html',$html);
|
|
|
+if (@file_put_contents($outfp,$html)===false) {
|
|
|
+ eecho("Error: {$SCRIPTNAME} could not save html into «{$outfp}».\n");
|
|
|
+ exit(2);
|
|
|
+}
|
|
|
|
|
|
exit(0);
|
|
|
|