Added “lang” config parameter; using “isset” custom attribute in “img” tags; changed a bit the help text; bumped version to 0.3.1
This commit is contained in:
parent
017e527709
commit
65f7d7beaa
1 changed files with 49 additions and 36 deletions
85
pfaltgall
85
pfaltgall
|
@ -19,7 +19,7 @@
|
|||
// todo: add a "last updated on" header
|
||||
|
||||
$SCRIPTNAME='pfaltgall';
|
||||
$SCRIPTVERSION='0.3';
|
||||
$SCRIPTVERSION='0.3.1';
|
||||
$SCRIPTURL='https://git.lattuga.net/Jones/pfaltgall';
|
||||
|
||||
require 'lib/ckratelimit.php';
|
||||
|
@ -31,6 +31,7 @@ $outfp=null;
|
|||
$conf=[
|
||||
'host'=>null,
|
||||
'token'=>null,
|
||||
'lang'=>null
|
||||
];
|
||||
|
||||
$help=
|
||||
|
@ -42,19 +43,21 @@ $help=
|
|||
|
||||
This is {$SCRIPTNAME} v{$SCRIPTVERSION}, a CLI PHP script that can generate an html file
|
||||
with 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 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 provide each image
|
||||
with its description (alt-text), if present.
|
||||
See my example gallery here: https://rame.altervista.org/foto-pixelfed
|
||||
images dynamically from your Pixelfed instance or its CDN, display each one
|
||||
using almost all the available screen space and 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 provide each image
|
||||
with its description (alt-text), if it’s present on Pixelfed.
|
||||
Here is example gallery: 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):
|
||||
Pixelfed account from the official web frontend 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
|
||||
token=your_token
|
||||
lang=your_html_page_language_code
|
||||
---
|
||||
|
||||
For example:
|
||||
|
@ -62,13 +65,16 @@ token=your_token
|
|||
---
|
||||
host=pixelfed.social
|
||||
token=as7f8a7s0d89f7as97df09a8s7d90f81jkl2h34lkj12h3jkl4
|
||||
lang=it
|
||||
---
|
||||
|
||||
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).
|
||||
will be overwritten), e.g.: «{$SCRIPTNAME} pixelfed.social.conf index.html».
|
||||
This will create an «index.html» file that will be ready to be put where you
|
||||
want (you’ll also be able to see it locally, obviously). There is a sample
|
||||
bash script that you can adapt to run {$SCRIPTNAME} and automatically upload
|
||||
it where you want.
|
||||
|
||||
[[[ OPTIONS ]]]
|
||||
|
||||
|
@ -122,6 +128,8 @@ if (!array_key_exists('host',$fconf))
|
|||
$errors[]="no «host» defined";
|
||||
if (!array_key_exists('token',$fconf))
|
||||
$errors[]="no «token» defined";
|
||||
if (!array_key_exists('lang',$fconf))
|
||||
$errors[]="no «lang» defined";
|
||||
if (count($errors)>0) {
|
||||
eecho("Error: {$SCRIPTNAME} has found errors in «{$configfp}» configuration file:\n");
|
||||
foreach ($errors as $val)
|
||||
|
@ -143,9 +151,9 @@ if (!$acc['ok']) {
|
|||
ckrl($acc['headers']);
|
||||
$acc=$acc['content'];
|
||||
|
||||
$imgurls=[];
|
||||
$imgsurls=[];
|
||||
$imgs='';
|
||||
$thumburls=[];
|
||||
$thumbsurls=[];
|
||||
$thumbs='';
|
||||
$i=0;
|
||||
$ic=0;
|
||||
|
@ -183,9 +191,9 @@ do {
|
|||
foreach ($status['media_attachments'] as $attachment) {
|
||||
if (isset($attachment['url'])) {
|
||||
$thumburl=$attachment['preview_url'];
|
||||
$thumburls[]=$thumburl;
|
||||
$thumbsurls[]=$thumburl;
|
||||
$imgurl=$attachment['url'];
|
||||
$imgurls[]=$imgurl;
|
||||
$imgsurls[]=$imgurl;
|
||||
$ia++;
|
||||
if (isset($attachment['description']) && preg_match('#^\s+$#',$attachment['description'])!==1)
|
||||
$altdesc=' alt="'.htmlspecialchars(trim($attachment['description']),ENT_QUOTES|ENT_HTML5).'"';
|
||||
|
@ -197,8 +205,8 @@ do {
|
|||
$icnt='';
|
||||
/* $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=\"{$imgurl}\"{$altdesc}></a></td></tr><caption class=\"imgcaptcel\">{$desc}{$icnt}{$date}</caption></table></div>\n";
|
||||
$thumbs.="<div class=\"thumbd\" id=\"thumbdiv{$ic}\" onclick=\"goto({$ic});\"><img class=\"thumb\" id=\"thumb{$ic}\" decoding=\"async\" loading=\"lazy\" src=\"{$thumburl}\"{$altdesc}></div>";*/
|
||||
$imgs.="<div class=\"page\"><table class=\"imgtab\"><tr><td class=\"imgcel\"><a href=\"{$imgurl}\" name=\"img{$ic}\"><img class=\"img\" decoding=\"async\" loading=\"eager\" id=\"img{$ic}\" src=\"{$acc['avatar_static']}\"{$altdesc}></a></td></tr><caption class=\"imgcaptcel\">{$desc}{$icnt}{$date}</caption></table></div>\n";
|
||||
$thumbs.="<div class=\"thumbd\" id=\"thumbdiv{$ic}\" onclick=\"goto({$ic});\"><img class=\"thumb\" id=\"thumb{$ic}\" decoding=\"async\" loading=\"lazy\" src=\"{$acc['avatar_static']}\"{$altdesc}></div>";
|
||||
$imgs.="<div class=\"page\"><table class=\"imgtab\"><tr><td class=\"imgcel\"><a href=\"{$imgurl}\" name=\"img{$ic}\"><img class=\"img\" decoding=\"async\" loading=\"eager\" isset=\"0\" id=\"img{$ic}\" src=\"{$acc['avatar_static']}\"{$altdesc}></a></td></tr><caption class=\"imgcaptcel\">{$desc}{$icnt}{$date}</caption></table></div>\n";
|
||||
$thumbs.="<div class=\"thumbd\" id=\"thumbdiv{$ic}\" onclick=\"goto({$ic});\"><img class=\"thumb\" id=\"thumb{$ic}\" decoding=\"async\" loading=\"eager\" isset=\"0\" src=\"{$acc['avatar_static']}\"{$altdesc}></div>";
|
||||
$ic++;
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +231,7 @@ if ($acc['display_name']!='') {
|
|||
}
|
||||
|
||||
$html='<!DOCTYPE HTML>
|
||||
<html lang="it">
|
||||
<html lang="'.$conf['lang'].'">
|
||||
<head>
|
||||
<title>'.$title.'</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
|
@ -465,9 +473,8 @@ hr {
|
|||
</style>
|
||||
<script type="text/javascript">
|
||||
let totimgs='.$ic.';
|
||||
let thumburls=["'.implode('", "',$thumburls).'"];
|
||||
let imgurls=["'.implode('", "',$imgurls).'"];
|
||||
let phimgurl="'.$acc['avatar_static'].'";//placeholder image url
|
||||
let thumbsurls=["'.implode('", "',$thumbsurls).'"];
|
||||
let imgsurls=["'.implode('", "',$imgsurls).'"];
|
||||
window.onresize=setToolBar;
|
||||
function prel() {
|
||||
let ph=window.innerHeight;
|
||||
|
@ -479,40 +486,45 @@ function prel() {
|
|||
sy=md.scrollTop,
|
||||
page=Math.floor(pages-(th-sy)/ph)+1,
|
||||
img;
|
||||
//console.log(ph+" "+th+" "+pages+" "+sy+" "+page);
|
||||
// console.log("ph: "+ph+"; th: "+th+"; sy: "+sy+"; pages: "+pages+"; page: "+page);
|
||||
if (page>1) {//current
|
||||
img=document.getElementById("img"+(page-2));
|
||||
if (img.src==phimgurl) {
|
||||
img.src=imgurls[page-2];
|
||||
if (img.getAttribute("isset")=="0") {
|
||||
img.src=imgsurls[page-2];
|
||||
img.loading="eager";
|
||||
img.setAttribute=("isset","1");
|
||||
}
|
||||
}
|
||||
if (page+1<pages) {//next
|
||||
img=document.getElementById("img"+(page-1));
|
||||
if (img.src==phimgurl) {
|
||||
img.src=imgurls[page-1];
|
||||
if (img.getAttribute("isset")=="0") {
|
||||
img.src=imgsurls[page-1];
|
||||
img.loading="eager";
|
||||
img.setAttribute=("isset","1");
|
||||
}
|
||||
}
|
||||
if (page>2) {//previous
|
||||
img=document.getElementById("img"+(page-3));
|
||||
if (img.src==phimgurl) {
|
||||
img.src=imgurls[page-3];
|
||||
if (img.getAttribute("isset")=="0") {
|
||||
img.src=imgsurls[page-3];
|
||||
img.loading="eager";
|
||||
img.setAttribute=("isset","1");
|
||||
}
|
||||
}
|
||||
if (page+2<pages) {//next-next
|
||||
img=document.getElementById("img"+page);
|
||||
if (img.src==phimgurl) {
|
||||
img.src=imgurls[page];
|
||||
if (img.getAttribute("isset")=="0") {
|
||||
img.src=imgsurls[page];
|
||||
img.loading="eager";
|
||||
img.setAttribute=("isset","1");
|
||||
}
|
||||
}
|
||||
if (page>3) {//previous-previous
|
||||
img=document.getElementById("img"+(page-4));
|
||||
if (img.src==phimgurl) {
|
||||
img.src=imgurls[page-4];
|
||||
if (img.getAttribute("isset")=="0") {
|
||||
img.src=imgsurls[page-4];
|
||||
img.loading="eager";
|
||||
img.setAttribute=("isset","1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -531,9 +543,10 @@ function prelb() {
|
|||
let i, timg;
|
||||
for (i=0; i<totimgs; i++) {
|
||||
timg=document.getElementById("thumb"+i);
|
||||
if (timg.src==phimgurl && isInViewport(timg)) {
|
||||
// console.log(i);
|
||||
timg.src=thumburls[i];
|
||||
if (timg.getAttribute("isset")=="0" && isInViewport(timg)) {
|
||||
console.log(i);
|
||||
timg.src=thumbsurls[i];
|
||||
timg.setAttribute("isset","1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue