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
|
// todo: add a "last updated on" header
|
||||||
|
|
||||||
$SCRIPTNAME='pfaltgall';
|
$SCRIPTNAME='pfaltgall';
|
||||||
$SCRIPTVERSION='0.3';
|
$SCRIPTVERSION='0.3.1';
|
||||||
$SCRIPTURL='https://git.lattuga.net/Jones/pfaltgall';
|
$SCRIPTURL='https://git.lattuga.net/Jones/pfaltgall';
|
||||||
|
|
||||||
require 'lib/ckratelimit.php';
|
require 'lib/ckratelimit.php';
|
||||||
|
@ -31,6 +31,7 @@ $outfp=null;
|
||||||
$conf=[
|
$conf=[
|
||||||
'host'=>null,
|
'host'=>null,
|
||||||
'token'=>null,
|
'token'=>null,
|
||||||
|
'lang'=>null
|
||||||
];
|
];
|
||||||
|
|
||||||
$help=
|
$help=
|
||||||
|
@ -42,19 +43,21 @@ $help=
|
||||||
|
|
||||||
This is {$SCRIPTNAME} v{$SCRIPTVERSION}, a CLI PHP script that can generate an html file
|
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
|
with a gallery from your Pixelfed profile. The html gallery file will load
|
||||||
images dynamically, display each one using almost all the available screen
|
images dynamically from your Pixelfed instance or its CDN, display each one
|
||||||
space and let you jump right from the start to any point in the timeline.
|
using almost all the available screen space and let you jump right from the
|
||||||
It will also show each post’s text content, its date, and provide each image
|
start to any point in the timeline.
|
||||||
with its description (alt-text), if present.
|
It will also show each post’s text content, its date, and provide each image
|
||||||
See my example gallery here: https://rame.altervista.org/foto-pixelfed
|
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
|
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
|
Pixelfed account from the official web frontend and get an app token
|
||||||
token), then create a configuration file for {$SCRIPTNAME} like this (don’t write
|
(Settings -> Applications -> Create new token), then create a configuration
|
||||||
the «---» lines):
|
file for {$SCRIPTNAME} like this (don’t write the «---» lines):
|
||||||
|
|
||||||
---
|
---
|
||||||
host=your_instance_host
|
host=your_instance_host
|
||||||
token=your_token
|
token=your_token
|
||||||
|
lang=your_html_page_language_code
|
||||||
---
|
---
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
@ -62,13 +65,16 @@ token=your_token
|
||||||
---
|
---
|
||||||
host=pixelfed.social
|
host=pixelfed.social
|
||||||
token=as7f8a7s0d89f7as97df09a8s7d90f81jkl2h34lkj12h3jkl4
|
token=as7f8a7s0d89f7as97df09a8s7d90f81jkl2h34lkj12h3jkl4
|
||||||
|
lang=it
|
||||||
---
|
---
|
||||||
|
|
||||||
Then run {$SCRIPTNAME} with the path of the configuration file you have created
|
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
|
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».
|
will be overwritten), e.g.: «{$SCRIPTNAME} pixelfed.social.conf index.html».
|
||||||
This will create an html file that will be ready to be put where you want
|
This will create an «index.html» file that will be ready to be put where you
|
||||||
(you’ll also be able to see it locally, obviously).
|
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 ]]]
|
[[[ OPTIONS ]]]
|
||||||
|
|
||||||
|
@ -122,6 +128,8 @@ if (!array_key_exists('host',$fconf))
|
||||||
$errors[]="no «host» defined";
|
$errors[]="no «host» defined";
|
||||||
if (!array_key_exists('token',$fconf))
|
if (!array_key_exists('token',$fconf))
|
||||||
$errors[]="no «token» defined";
|
$errors[]="no «token» defined";
|
||||||
|
if (!array_key_exists('lang',$fconf))
|
||||||
|
$errors[]="no «lang» defined";
|
||||||
if (count($errors)>0) {
|
if (count($errors)>0) {
|
||||||
eecho("Error: {$SCRIPTNAME} has found errors in «{$configfp}» configuration file:\n");
|
eecho("Error: {$SCRIPTNAME} has found errors in «{$configfp}» configuration file:\n");
|
||||||
foreach ($errors as $val)
|
foreach ($errors as $val)
|
||||||
|
@ -143,9 +151,9 @@ if (!$acc['ok']) {
|
||||||
ckrl($acc['headers']);
|
ckrl($acc['headers']);
|
||||||
$acc=$acc['content'];
|
$acc=$acc['content'];
|
||||||
|
|
||||||
$imgurls=[];
|
$imgsurls=[];
|
||||||
$imgs='';
|
$imgs='';
|
||||||
$thumburls=[];
|
$thumbsurls=[];
|
||||||
$thumbs='';
|
$thumbs='';
|
||||||
$i=0;
|
$i=0;
|
||||||
$ic=0;
|
$ic=0;
|
||||||
|
@ -183,9 +191,9 @@ do {
|
||||||
foreach ($status['media_attachments'] as $attachment) {
|
foreach ($status['media_attachments'] as $attachment) {
|
||||||
if (isset($attachment['url'])) {
|
if (isset($attachment['url'])) {
|
||||||
$thumburl=$attachment['preview_url'];
|
$thumburl=$attachment['preview_url'];
|
||||||
$thumburls[]=$thumburl;
|
$thumbsurls[]=$thumburl;
|
||||||
$imgurl=$attachment['url'];
|
$imgurl=$attachment['url'];
|
||||||
$imgurls[]=$imgurl;
|
$imgsurls[]=$imgurl;
|
||||||
$ia++;
|
$ia++;
|
||||||
if (isset($attachment['description']) && preg_match('#^\s+$#',$attachment['description'])!==1)
|
if (isset($attachment['description']) && preg_match('#^\s+$#',$attachment['description'])!==1)
|
||||||
$altdesc=' alt="'.htmlspecialchars(trim($attachment['description']),ENT_QUOTES|ENT_HTML5).'"';
|
$altdesc=' alt="'.htmlspecialchars(trim($attachment['description']),ENT_QUOTES|ENT_HTML5).'"';
|
||||||
|
@ -197,8 +205,8 @@ do {
|
||||||
$icnt='';
|
$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";
|
/* $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>";*/
|
$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";
|
$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=\"lazy\" src=\"{$acc['avatar_static']}\"{$altdesc}></div>";
|
$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++;
|
$ic++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,7 +231,7 @@ if ($acc['display_name']!='') {
|
||||||
}
|
}
|
||||||
|
|
||||||
$html='<!DOCTYPE HTML>
|
$html='<!DOCTYPE HTML>
|
||||||
<html lang="it">
|
<html lang="'.$conf['lang'].'">
|
||||||
<head>
|
<head>
|
||||||
<title>'.$title.'</title>
|
<title>'.$title.'</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
@ -465,9 +473,8 @@ hr {
|
||||||
</style>
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
let totimgs='.$ic.';
|
let totimgs='.$ic.';
|
||||||
let thumburls=["'.implode('", "',$thumburls).'"];
|
let thumbsurls=["'.implode('", "',$thumbsurls).'"];
|
||||||
let imgurls=["'.implode('", "',$imgurls).'"];
|
let imgsurls=["'.implode('", "',$imgsurls).'"];
|
||||||
let phimgurl="'.$acc['avatar_static'].'";//placeholder image url
|
|
||||||
window.onresize=setToolBar;
|
window.onresize=setToolBar;
|
||||||
function prel() {
|
function prel() {
|
||||||
let ph=window.innerHeight;
|
let ph=window.innerHeight;
|
||||||
|
@ -479,40 +486,45 @@ function prel() {
|
||||||
sy=md.scrollTop,
|
sy=md.scrollTop,
|
||||||
page=Math.floor(pages-(th-sy)/ph)+1,
|
page=Math.floor(pages-(th-sy)/ph)+1,
|
||||||
img;
|
img;
|
||||||
//console.log(ph+" "+th+" "+pages+" "+sy+" "+page);
|
// console.log("ph: "+ph+"; th: "+th+"; sy: "+sy+"; pages: "+pages+"; page: "+page);
|
||||||
if (page>1) {//current
|
if (page>1) {//current
|
||||||
img=document.getElementById("img"+(page-2));
|
img=document.getElementById("img"+(page-2));
|
||||||
if (img.src==phimgurl) {
|
if (img.getAttribute("isset")=="0") {
|
||||||
img.src=imgurls[page-2];
|
img.src=imgsurls[page-2];
|
||||||
img.loading="eager";
|
img.loading="eager";
|
||||||
|
img.setAttribute=("isset","1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (page+1<pages) {//next
|
if (page+1<pages) {//next
|
||||||
img=document.getElementById("img"+(page-1));
|
img=document.getElementById("img"+(page-1));
|
||||||
if (img.src==phimgurl) {
|
if (img.getAttribute("isset")=="0") {
|
||||||
img.src=imgurls[page-1];
|
img.src=imgsurls[page-1];
|
||||||
img.loading="eager";
|
img.loading="eager";
|
||||||
|
img.setAttribute=("isset","1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (page>2) {//previous
|
if (page>2) {//previous
|
||||||
img=document.getElementById("img"+(page-3));
|
img=document.getElementById("img"+(page-3));
|
||||||
if (img.src==phimgurl) {
|
if (img.getAttribute("isset")=="0") {
|
||||||
img.src=imgurls[page-3];
|
img.src=imgsurls[page-3];
|
||||||
img.loading="eager";
|
img.loading="eager";
|
||||||
|
img.setAttribute=("isset","1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (page+2<pages) {//next-next
|
if (page+2<pages) {//next-next
|
||||||
img=document.getElementById("img"+page);
|
img=document.getElementById("img"+page);
|
||||||
if (img.src==phimgurl) {
|
if (img.getAttribute("isset")=="0") {
|
||||||
img.src=imgurls[page];
|
img.src=imgsurls[page];
|
||||||
img.loading="eager";
|
img.loading="eager";
|
||||||
|
img.setAttribute=("isset","1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (page>3) {//previous-previous
|
if (page>3) {//previous-previous
|
||||||
img=document.getElementById("img"+(page-4));
|
img=document.getElementById("img"+(page-4));
|
||||||
if (img.src==phimgurl) {
|
if (img.getAttribute("isset")=="0") {
|
||||||
img.src=imgurls[page-4];
|
img.src=imgsurls[page-4];
|
||||||
img.loading="eager";
|
img.loading="eager";
|
||||||
|
img.setAttribute=("isset","1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -531,9 +543,10 @@ function prelb() {
|
||||||
let i, timg;
|
let i, timg;
|
||||||
for (i=0; i<totimgs; i++) {
|
for (i=0; i<totimgs; i++) {
|
||||||
timg=document.getElementById("thumb"+i);
|
timg=document.getElementById("thumb"+i);
|
||||||
if (timg.src==phimgurl && isInViewport(timg)) {
|
if (timg.getAttribute("isset")=="0" && isInViewport(timg)) {
|
||||||
// console.log(i);
|
console.log(i);
|
||||||
timg.src=thumburls[i];
|
timg.src=thumbsurls[i];
|
||||||
|
timg.setAttribute("isset","1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue