2023-11-20 12:42:57 +01:00
< ? php
/*
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
// Logorrh, Verbose, Charliero, Tashugo?
2024-10-23 23:11:08 +02:00
$dodebug = false ;
$debug = '' ;
2023-11-20 12:42:57 +01:00
require 'lib/gettlds.php' ;
2024-10-23 23:11:08 +02:00
$tlds = gettlds ( 'storage/tlds.txt' , false ); // we don't get them in "regex format" because we need them for js too, so we'll rsort them later
if ( ! is_null ( $tlds [ 'warnings' ])) $debug .= " GetTLDs warning: { $tlds [ 'warnings' ] } .<br> \n " ;
rsort ( $tlds );
$retlds = implode ( '|' , $tlds [ 'tlds' ]);
$jstlds = " const tlds=[' " . implode ( " ', ' " , $tlds [ 'tlds' ]) . " ']; \n " ;
$jstldsfp = 'storage/tlds.js' ;
if ( @ file_put_contents ( $jstldsfp , $jstlds ) === false )
dieyoung ( " Error: could not save « { $jstldsfp } » " );
2023-11-20 12:42:57 +01:00
unset ( $tlds , $jstlds );
require 'lib/mastodon.php' ;
require 'lib/ckratelimit.php' ;
require 'lib/getfirstbrowserlang.php' ;
require 'lib/ght.php' ;
require 'lib/booltostr.php' ;
const SNAME = 'Verbose' ;
2024-07-26 10:05:28 +02:00
const SVERS = '0.3.7' ;
2024-07-14 21:53:11 +02:00
const SREPO = 'https://git.lattuga.net/jones/verbose' ;
2023-11-20 12:42:57 +01:00
const DEFAC = 500 ;
const MINAC = 100 ;
const MAXAC = 100000 ;
const MINCL = 40 ;
const MAXPOSTC = 50000 ;
const MAXREPTOLEN = 1500 ;
const POSTPAUSE = 250 ; // pause between sending split posts (in milliseconds)
const REQSTOPRESV = 10 ; // requests to preserve
const CONFFN = 'conf.ini' ;
$sname = SNAME ;
$svers = SVERS ;
$now = time ();
$timeout = 5 ;
$formact = preg_replace ( '#[^/]+$#' , '' , $_SERVER [ 'REQUEST_URI' ]);
ini_set ( 'max_execution_time' , 360 ); // 6 minutes: default mastodon ratelimits: https://docs.joinmastodon.org/api/rate-limits/
$conf = [ 'link' => " \n \n [This post was split using " . SREPO . ']' ];
if ( file_exists ( CONFFN )) {
$fconf =@ parse_ini_file ( CONFFN , false , INI_SCANNER_RAW );
if ( $fconf === false ) {
dieyoung ( 'Error: configuration file «' . CONFFN . '» was found but could not be opened for reading.' );
} else {
if ( isset ( $fconf [ 'link' ]))
$conf [ 'link' ] = " \n \n { $fconf [ 'link' ] } " ;
if ( isset ( $fconf [ 'footer' ]))
$conf [ 'footer' ] = $fconf [ 'footer' ];
if ( isset ( $fconf [ 'webservertimeout' ])) {
if ( preg_match ( '#^\d+$#' , $fconf [ 'webservertimeout' ]) === 1 )
$conf [ 'webservertimeout' ] = $fconf [ 'webservertimeout' ] + 0 ;
else
dieyoung ( 'Error: configuration file «' . CONFFN . '»: value «' . $fconf [ 'webservertimeout' ] . '» is not valid for «webservertimeout».' );
} else {
dieyoung ( 'Error: configuration file «' . CONFFN . '» does not define «webservertimeout».' );
}
}
unset ( $fconf );
} else {
dieyoung ( 'Error: configuration file «' . CONFFN . '» was not found.' );
}
$debug .= 'CONF: ' . preprint ( $conf ) . " <br> \n " ;
$coopts = [
'expires' => $now + 365 * 24 * 60 * 60 ,
2024-01-09 19:55:16 +01:00
'path' => preg_replace ( '#[^/]+$#' , '' , $_SERVER [ 'REQUEST_URI' ]),
2023-11-20 12:42:57 +01:00
'domain' => $_SERVER [ 'SERVER_NAME' ],
'secure' => false ,
'httponly' => false ,
'samesite' => 'Lax' // None || Lax || Strict
];
$cooptsx = $coopts ;
$cooptsx [ 'expires' ] = $now - 3600 ;
/* setcookie ( 'verbose_client_id' , '' , $cooptsx );
setcookie ( 'verbose_client_secret' , '' , $cooptsx );
setcookie ( 'verbose_host' , '' , $cooptsx );
setcookie ( 'verbose_token' , '' , $cooptsx ); */
$debug .= 'COOKIES: ' . preprint ( $_COOKIE );
$debug .= 'POST: ' . preprint ( $_POST );
$blang = getfirstbrowserlang ();
$blang = preg_replace ( '#^([a-z]+).*#' , '$1' , $blang );
$host = false ;
$token = false ;
( isset ( $_SERVER [ 'HTTPS' ])) ? $proto = 'https' : $proto = 'http' ;
$rediruri = $proto . '://' . $_SERVER [ 'HTTP_HOST' ] . preg_replace ( '#^([^?]*).*#' , '$1' , $_SERVER [ 'REQUEST_URI' ]);
$authmsgs = '' ;
$scope = 'read write:statuses' ;
$provided = 'you provided' ;
setcookie ( 'verbose_client_id' , '' , $cooptsx );
setcookie ( 'verbose_client_secret' , '' , $cooptsx );
( isset ( $_POST [ 'host' ])) ? $_POST [ 'host' ] = trim ( $_POST [ 'host' ]) : $_POST [ 'host' ] = '' ;
( isset ( $_POST [ 'token' ])) ? $_POST [ 'token' ] = trim ( $_POST [ 'token' ]) : $_POST [ 'token' ] = '' ;
if ( isset ( $_GET [ 'code' ]) && isset ( $_COOKIE [ 'verbose_host' ]) && isset ( $_COOKIE [ 'verbose_client_id' ]) && isset ( $_COOKIE [ 'verbose_client_secret' ])) {
$host = $_COOKIE [ 'verbose_host' ];
$postcont = [ 'grant_type' => 'authorization_code' , 'code' => $_GET [ 'code' ], 'client_id' => $_COOKIE [ 'verbose_client_id' ], 'client_secret' => $_COOKIE [ 'verbose_client_secret' ], 'redirect_uri' => $rediruri , 'scope' => $scope ];
$res = mastpost ( $host , null , '/oauth/token' , $postcont , $timeout );
if ( $res [ 'ok' ]) {
$res = $res [ 'data' ];
$token = $res [ 'access_token' ];
setcookie ( 'verbose_token' , $token , $coopts );
$authmsgs .= " <div class= \" normtext \" >You successfully authorized { $sname } to use your account on { $host } .<br> \n Your access token is <span class= \" hili \" > { $token } </span><br> \n Please save it somewhere safe, like in a password manager (i suggest <a href= \" https://keepassxc.org/ \" >KeePassXC</a>), because { $sname } does not save it on the server, but only in a cookie in your browser that lasts one year since your last visit, so it may expire or you may loose it and, without your access token, you would have to repeat the authorization process.</div> \n " ;
} else {
$authmsgs .= '<div class="error">Sorry, there was an error trying to authorize you: ' . htmlentities ( $res [ 'error' ]) . " </div> \n " ;
}
} elseif ( isset ( $_POST [ 'act' ]) && $_POST [ 'act' ] == 'login' && $_POST [ 'host' ] != '' && $_POST [ 'token' ] == '' ) {
$host = $_POST [ 'host' ];
2024-07-14 21:53:11 +02:00
$postcont = [ 'client_name' => 'Verbose' , 'redirect_uris' => $rediruri , 'scopes' => $scope , 'website' => 'https://git.lattuga.net/jones/verbose' ];
2023-11-20 12:42:57 +01:00
$res = mastpost ( $host , $token , '/api/v1/apps' , $postcont , $timeout );
//$debug.='AUTH RESULTS: '.preprint($res);
if ( $res [ 'ok' ]) {
$res = $res [ 'data' ];
setcookie ( 'verbose_host' , $host , $coopts );
setcookie ( 'verbose_client_id' , $res [ 'client_id' ], $coopts );
setcookie ( 'verbose_client_secret' , $res [ 'client_secret' ], $coopts );
$location = 'https://' . $host . '/oauth/authorize?client_id=' . $res [ 'client_id' ] . '&redirect_uri=' . urlencode ( $rediruri ) . '&response_type=code&scope=' . urlencode ( $postcont [ 'scopes' ]) . '&force_login=0&lang=' . $blang ;
if ( $debug )
header ( 'Location: ' . $location , true , 302 );
else
echo " <a href= \" { $location } \" > " . htmlentities ( $location ) . " </a><br> \n " ;
2024-01-09 19:55:16 +01:00
exit ( 0 );
2023-11-20 12:42:57 +01:00
} else {
$authmsgs .= '<div class="error">Sorry, there was an error trying to authorize you: ' . htmlentities ( $res [ 'error' ]) . " </div> \n " ;
}
} elseif ( isset ( $_POST [ 'act' ]) && $_POST [ 'act' ] == 'login' && $_POST [ 'host' ] != '' && $_POST [ 'token' ] != '' ) {
$host = $_POST [ 'host' ];
$token = $_POST [ 'token' ];
} elseif ( isset ( $_POST [ 'act' ]) && $_POST [ 'act' ] == 'logout' ) {
setcookie ( 'verbose_host' , '' , $cooptsx );
setcookie ( 'verbose_token' , '' , $cooptsx );
$_COOKIE = [];
//$authmsgs.="<div class=\"success\">You have been successfully logged out :-)</div>\n";
} elseif ( isset ( $_COOKIE [ 'verbose_host' ]) && isset ( $_COOKIE [ 'verbose_token' ])) {
$host = $_COOKIE [ 'verbose_host' ];
$token = $_COOKIE [ 'verbose_token' ];
$provided = 'provided by your cookies' ;
}
( isset ( $_POST [ 'round' ])) ? $_POST [ 'round' ] ++ : $_POST [ 'round' ] = 0 ;
$loggedin = false ;
if ( $host !== false && $token !== false && trim ( $token ) != '' ) { // trim($token)!='' is to keep it usable without js
$res = mastget ( $host , $token , '/api/v1/apps/verify_credentials' , $timeout );
//$debug.='TOKEN: '.$token."<br>\nRES:".preprint($res);
if ( $res [ 'ok' ]) {
$myacc = mastget ( $host , $token , '/api/v1/accounts/verify_credentials' , $timeout );
//$debug.=preprint($myacc);
if ( $myacc [ 'ok' ]) {
setcookie ( 'verbose_host' , $host , $coopts );
setcookie ( 'verbose_token' , $token , $coopts );
$myacc = $myacc [ 'data' ];
$loggedin = true ;
2024-01-09 19:55:16 +01:00
if ( $_POST [ 'round' ] == 0 || ( isset ( $_POST [ 'act' ]) && $_POST [ 'act' ] == 'login' )) {
2023-11-20 12:42:57 +01:00
$res = mastget ( $host , $token , '/api/v1/instance' , $timeout );
if ( $res [ 'ok' ] && isset ( $res [ 'data' ][ 'configuration' ][ 'statuses' ][ 'max_characters' ]) && preg_match ( '#^\d+$#' , $res [ 'data' ][ 'configuration' ][ 'statuses' ][ 'max_characters' ]) === 1 ) {
$avchars = $res [ 'data' ][ 'configuration' ][ 'statuses' ][ 'max_characters' ] + 0 ;
} else {
$authmsgs .= " <div class= \" warning \" >Sorry, { $sname } could not detect how many characters per post your instance allows.</div> \n " ;
}
}
} else {
$authmsgs .= '<div class="error">Sorry, verification of your account’ s credentials failed (error: ' . htmlentities ( $myacc [ 'error' ]) . " )</div> \n " ;
setcookie ( 'verbose_host' , '' , $cooptsx );
setcookie ( 'verbose_token' , '' , $cooptsx );
}
} else {
$authmsgs .= " <div class= \" error \" >Sorry, authentication with the credentials { $provided } failed (error: " . htmlentities ( $res [ 'error' ]) . " )</div> \n " ;
setcookie ( 'verbose_host' , '' , $cooptsx );
setcookie ( 'verbose_token' , '' , $cooptsx );
}
}
$splitmsgs = '' ;
if ( isset ( $avchars )) {
$_POST [ 'avchars' ] = $avchars ;
} elseif ( isset ( $_POST [ 'avchars' ])) {
//if (!$loggedin) $authmsgs='<div class="warning">Warning: if you authorize now you’ ll loose your current split session</div>';
( preg_match ( '#^\d+$#' , $_POST [ 'avchars' ]) === 1 ) ? $_POST [ 'avchars' ] += 0 : $_POST [ 'avchars' ] = DEFAC ;
} else {
$_POST [ 'avchars' ] = DEFAC ;
}
if ( $_POST [ 'avchars' ] < MINAC ) $_POST [ 'avchars' ] = MINAC ;
if ( $_POST [ 'avchars' ] > MAXAC ) $_POST [ 'avchars' ] = MAXAC ;
$maxcwprec = $_POST [ 'avchars' ] - MINCL ;
if ( ! isset ( $_POST [ 'cw' ]) || trim ( $_POST [ 'cw' ]) == '' ) $_POST [ 'cw' ] = '' ;
$cwlen = mb_strlen ( $_POST [ 'cw' ], 'UTF-8' );
if ( ! isset ( $_POST [ 'pre' ]) || trim ( $_POST [ 'pre' ]) == '' ) $_POST [ 'pre' ] = '' ;
$prelen = mb_strlen ( $_POST [ 'pre' ], 'UTF-8' ) + 2 ;
$cwprelen = $cwlen + $prelen ;
if ( $cwprelen > $maxcwprec ) $splitmsgs .= " <div class= \" error \" >“Content Warning” + “Text to prepend” is { $cwprelen } characters long, that is " . ( $cwprelen - $maxcwprec ) . " characters longer than its maximum allowed length ( { $maxcwprec } characters, that is { $_POST [ 'avchars' ] } available characters minus " . MINCL . " characters)</div> \n " ;
//$_POST['pre']=mb_substr($_POST['pre'],0,$maxprec,'UTF-8');
if ( ! isset ( $_POST [ 'post' ]) || trim ( $_POST [ 'post' ]) == '' ) $_POST [ 'post' ] = '' ;
$postlen = mb_strlen ( $_POST [ 'post' ], 'UTF-8' );
if ( $postlen > MAXPOSTC ) $splitmsgs .= " <div class= \" error \" >“Post to split” is { $postlen } characters long, that is " . ( $postlen - MAXPOSTC ) . " characters longer than its maximum allowed length, " . MAXPOSTC . " characters</div> \n " ;
//$_POST['post']=mb_substr($_POST['post'],0,MAXPOSTC,'UTF-8');
$rbsck = [
'cntpos_before' => '' ,
'cntpos_after' => '' ,
'addref_no' => '' ,
'addref_ifav' => '' ,
];
if ( isset ( $_POST [ 'cntpos' ]) && $_POST [ 'cntpos' ] == 'before' ) {
$cntbef = true ;
$rbsck [ 'cntpos_before' ] = ' checked' ;
} else {
$_POST [ 'cntpos' ] = 'after' ;
$cntbef = false ;
$rbsck [ 'cntpos_after' ] = ' checked' ;
}
if ( isset ( $_POST [ 'addref' ]) && $_POST [ 'addref' ] == 'no' ) {
$aliif = false ; // "add link if it fits"
$rbsck [ 'addref_no' ] = ' checked' ;
} else {
$_POST [ 'addref' ] = 'ifav' ;
$aliif = true ;
$rbsck [ 'addref_ifav' ] = ' checked' ;
}
if ( ! isset ( $_POST [ 'replyto' ]) || trim ( $_POST [ 'replyto' ]) == '' ) $_POST [ 'replyto' ] = '' ;
if ( strlen ( $_POST [ 'replyto' ]) > MAXREPTOLEN ) {
$_POST [ 'replyto' ] = '' ;
$splitmsgs .= '<div class="error">The “URL of post to reply to” you specified is too long (its maximum allowed length is ' . MAXREPTOLEN . " characters)</div> \n " ;
}
if ( ! isset ( $_POST [ 'lang' ]) || trim ( $_POST [ 'lang' ]) == '' ) $_POST [ 'lang' ] = $blang ;
if ( ! isset ( $_POST [ 'visib' ]) || trim ( $_POST [ 'visib' ]) == '' ) $_POST [ 'visib' ] = 'public' ;
if ( $_POST [ 'round' ] == 0 ) {
$_POST [ 'setcws' ] = '1' ;
$setcwsck = ' checked' ;
$_POST [ 'setments' ] = '1' ;
$setmentsck = ' checked' ;
$_POST [ 'setvisib' ] = '1' ;
$setvisibck = ' checked' ;
$_POST [ 'setlang' ] = '1' ;
$setlangck = ' checked' ;
} else {
( isset ( $_POST [ 'setcws' ]) && $_POST [ 'setcws' ] == '1' ) ? $setcwsck = ' checked' : $setcwsck = '' ;
( isset ( $_POST [ 'setments' ]) && $_POST [ 'setments' ] == '1' ) ? $setmentsck = ' checked' : $setmentsck = '' ;
( isset ( $_POST [ 'setvisib' ]) && $_POST [ 'setvisib' ] == '1' ) ? $setvisibck = ' checked' : $setvisibck = '' ;
( isset ( $_POST [ 'setlang' ]) && $_POST [ 'setlang' ] == '1' ) ? $setlangck = ' checked' : $setlangck = '' ;
}
function getpostmentions ( $post , $exclude , $format ) {
$ments = [];
if ( isset ( $post [ 'account' ][ 'acct' ]) && ! in_array ( $post [ 'account' ][ 'acct' ], $exclude ))
$ments [] = $post [ 'account' ][ 'acct' ];
if ( isset ( $post [ 'mentions' ]) && is_array ( $post [ 'mentions' ]))
foreach ( $post [ 'mentions' ] as $ment )
if ( isset ( $ment [ 'acct' ]) && ! in_array ( $ment [ 'acct' ], $exclude ) && ! in_array ( $ment [ 'acct' ], $ments ))
$ments [] = $ment [ 'acct' ];
if ( $format == 'array' )
return $ments ;
elseif ( $format == 'list' )
return implode ( ' ' , $ments );
elseif ( $format == 'recipients' )
return '@' . implode ( ' @' , $ments );
}
$reptoid = '' ;
if ( $loggedin && $_POST [ 'replyto' ] != '' ) {
//https://livellosegreto.it/@geranio/110627337076323759
$res = mastget ( $host , $token , '/api/v2/search?type=statuses&resolve=1&limit=1&q=' . urlencode ( $_POST [ 'replyto' ]), $timeout );
$debug .= 'accsearch res: <pre>' . preprint ( $res ) . " </pre> \n " ;
if ( $res [ 'ok' ]) {
if ( isset ( $res [ 'data' ][ 'statuses' ][ 0 ][ 'id' ]))
$reptopost = $res [ 'data' ][ 'statuses' ][ 0 ];
else
$splitmsgs .= " <div class= \" error \" >Sorry, { $sname } found no post with the URL you provided as “URL of post to reply to”, please check it and make sure it points to a post you have access to.</div> \n " ;
} else {
$splitmsgs .= " <div class= \" error \" >Sorry, { $sname } encountered the following error while trying to retrieve the URL you provided as “URL of post to reply to”: " . htmlentities ( $res [ 'error' ]) . " ; please check the URL and make sure it points to a post you have access to.</div> \n " ;
}
if ( isset ( $reptopost )) {
if ( isset ( $reptopost [ 'id' ]))
$reptoid = $reptopost [ 'id' ];
if ( isset ( $_POST [ 'setcws' ]) && $_POST [ 'setcws' ] == '1' && isset ( $reptopost [ 'spoiler_text' ]) && trim ( $reptopost [ 'spoiler_text' ]) != '' )
$_POST [ 'cw' ] = $reptopost [ 'spoiler_text' ];
if ( isset ( $_POST [ 'setments' ]) && $_POST [ 'setments' ] == '1' && isset ( $reptopost [ 'mentions' ]))
$_POST [ 'pre' ] = getpostmentions ( $reptopost ,[ $myacc [ 'acct' ]], 'recipients' );
if ( isset ( $_POST [ 'setvisib' ]) && $_POST [ 'setvisib' ] == '1' && isset ( $reptopost [ 'visibility' ]))
$_POST [ 'visib' ] = $reptopost [ 'visibility' ];
if ( isset ( $_POST [ 'setlang' ]) && $_POST [ 'setlang' ] == '1' && isset ( $reptopost [ 'language' ]))
$_POST [ 'lang' ] = $reptopost [ 'language' ];
}
}
$headmsgs = '' ;
$intro = " <div class= \" normtext \" ><p class= \" firstp \" >Hello, this is a { $sname } instance, it can split your long post considering <a href= \" https://docs.joinmastodon.org/user/posting/#text \" >Mastodon rules</a>: every http(s) link counts for 23 characters and every mention counts only for its username part. Each split post comes with “…” signs where it makes sense and with a counter in “[n/t]” form, where “n” is current post number and “t” is total posts number.</p>
< p > { $sname } doesn’ t save anywhere what you write or paste into it , it doesn’ t use third parties’ cookies , it sets some cookies of its own only if you choose to connect it to your account , and it can be used even without Javascript .</ p >
2024-08-27 21:32:46 +02:00
< p > If you find issues please report them to < a href = \ " https://kolektiva.social/@jones_ \" >me on Mastodon</a>, or <a href= \" https://git.lattuga.net/jones/verbose/issues \" >here</a>.</p></div> \n " ;
2023-11-20 12:42:57 +01:00
$postmsgs = '' ;
$postsoffset = 0 ;
$postscount = 0 ;
$postingok = true ;
$postwait = 0 ;
$postwaituntil = 0 ;
$pbtext = 'Post all' ;
if ( isset ( $_POST [ 'postsoffset' ]) && preg_match ( '#^\d+$#' , $_POST [ 'postsoffset' ]) === 1 )
$postsoffset = $_POST [ 'postsoffset' ] + 0 ;
if ( $loggedin && isset ( $_POST [ 'postwaituntil' ]) && preg_match ( '#^\d+$#' , $_POST [ 'postwaituntil' ]) === 1 && isset ( $_POST [ 'postscount' ]) && preg_match ( '#^\d+$#' , $_POST [ 'postscount' ]) === 1 && isset ( $_POST [ 'act' ]) && $_POST [ 'act' ] == 'sendposts' && isset ( $_POST [ 'cw' ]) && isset ( $_POST [ 'post_' . $postsoffset ]) && isset ( $_POST [ 'mastlen_' . $postsoffset ])) {
$postscount = $_POST [ 'postscount' ] + 0 ;
if ( isset ( $_POST [ 'lastsentpostid' ]) && $_POST [ 'lastsentpostid' ] != '' )
$lspostid = $_POST [ 'lastsentpostid' ];
$posts = [];
$i = $postsoffset ;
do {
$_POST [ 'post_' . $i ] = str_replace ( " \r \n " , " \n " , $_POST [ 'post_' . $i ]);
$posts [ $i ] = [ 'cw' => $_POST [ 'cw' ], 'post' => $_POST [ 'post_' . $i ], 'mastlen' => $_POST [ 'mastlen_' . $i ]];
$i ++ ;
} while ( isset ( $_POST [ 'post_' . $i ]));
if ( $now < $_POST [ 'postwaituntil' ]) {
$debug .= " WAIT MORE!!!<br> \n " ;
$postingok = false ;
$postwait = $_POST [ 'postwaituntil' ] - $now + 1 ;
$postwaituntil = $_POST [ 'postwaituntil' ] + 1 ;
$postmsgs .= " <div class= \" warning \" >Sorry, you have to wait " . ght ( $postwait ) . " more before { $sname } can post the remaining split post(s).</div> \n " ;
$pbtext = 'Please wait ' . ght ( $postwait ) . ' before posting' ;
} else {
for ( $i = $postsoffset ; $i < $postscount ; $i ++ ) {
if ( time () - $now + 1 >= $conf [ 'webservertimeout' ]) {
$postingok = false ;
$postsoffset = $i ;
$postmsgs .= " <div class= \" warning \" > { $sname } could not post all the split posts because « { $_SERVER [ 'SERVER_NAME' ] } » HTTP server was reaching its timeout ( " . ght ( $conf [ 'webservertimeout' ]) . '). You can send the remaining split posts ' . ( $i + 1 ) . " - { $postscount } below.</div> \n " ;
break ;
} else {
$post = $posts [ $i ];
$cont = [
'status' => $post [ 'post' ],
'visibility' => $_POST [ 'visib' ],
'language' => $_POST [ 'lang' ]
];
if ( $post [ 'cw' ] != '' )
$cont [ 'spoiler_text' ] = $post [ 'cw' ];
if ( $i == 0 && $reptoid != '' )
$cont [ 'in_reply_to_id' ] = $reptoid ;
elseif ( isset ( $lspostid ))
$cont [ 'in_reply_to_id' ] = $lspostid ;
if ( $i > 0 && $_POST [ 'visib' ] == 'public' )
$cont [ 'visibility' ] = 'unlisted' ;
//echo ($i+1).preprint($cont)."<br>\n";
$res = mastpost ( $host , $token , '/api/v1/statuses' , $cont , $timeout );
//if ($i==2) $res=['ok'=>false,'error'=>'server exploded'];// test err
//$res=['ok'=>true,'data'=>['id'=>'12345']];// test err
if ( $res [ 'ok' ]) {
$lspostid = $res [ 'data' ][ 'id' ];
$debug .= " lspostid: { $lspostid } <br> \n " ;
2024-08-27 21:17:07 +02:00
$rls = ckratelimit ( $res [ 'headers' ]);
2024-09-28 06:06:22 +02:00
//if ($i==2) $rls=['ok'=>true,'remaining'=>0,'sleep'=>3895];// test err
//$rls=['ok'=>true,'remaining'=>0,'sleep'=>5];// test err
2024-08-27 21:17:07 +02:00
if ( $rls [ 'ok' ] && $rls [ 'remaining' ] <= REQSTOPRESV && $i < $postscount - 1 ) {
$postingok = false ;
2024-09-28 06:06:22 +02:00
$postwait = $rls [ 'sleep' ];
2024-08-27 21:17:07 +02:00
$postwaituntil = time () + $postwait ;
$postsoffset = $i + 1 ;
$postmsgs .= '<div class="warning">Sending split post ' . ( $i + 1 ) . " / { $postscount } , { $sname } reached your { $host } ’ s account posting rate limit, so it stopped sending; you’ ll find the rest of your split posts (those which have not been sent, " . ( $i + 2 ) . " - { $postscount } ) below; before posting them, you’ ll have to wait " . ght ( $postwait ) . " for rate limit reset.</div> \n " ;
$pbtext = 'Please wait ' . ght ( $postwait ) . ' before posting' ;
break ;
2023-11-20 12:42:57 +01:00
}
if ( $i < $postscount - 1 )
usleep ( POSTPAUSE * 1000 );
} else {
$postingok = false ;
$postsoffset = $i ;
$postmsgs .= '<div class="warning">Trying to send split post ' . ( $i + 1 ) . " / { $postscount } , { $sname } encountered the following error: « " . htmlentities ( $res [ 'error' ]) . '»; so it stopped sending. You can (re)try sending split posts ' . ( $i + 1 ) . " - { $postscount } below.</div> \n " ;
break ;
}
}
}
if ( $postingok ) {
$postmsgs .= " <div class= \" success \" > { $sname } successfully sent { $i } / { $postscount } split posts :-)</div> \n " ;
$posts = [];
$postscount = 0 ;
}
}
}
$replyto = '' ;
$language = '' ;
$displang = '' ;
$visibility = '' ;
$dispvisib = '' ;
if ( ! $loggedin ) {
$auth = " <a name= \" connect \" ></a><h2>Connect?</h2>
{ $authmsgs }
< div class = \ " normtext \" >
< p class = \ " firstp \" >If you don’ t want to connect { $sname } to your account, you can just <a href= \" #split \" >skip to the “Split post” section</a>, but after splitting your long post you’ ll have to copy and paste by hand each split post in sequence into Mastodon (i recommend “chain posting”, that is replying to the first post with the second, to the second with the third, and so on).</p>
< p > If you choose instead to connect { $sname } to your account , < span class = \ " hili \" >you’ ll be able to post all split posts at once directly from within { $sname } </span>, they will be automatically “chain posted” and, before posting them, you may set their visibility, language, and a post to reply to with the first split post.</p>
< p >& nbsp ; </ p >
< p class = \ " firstp \" >To connect { $sname } to your account</p>
< ul class = \ " ul \" >
< li > if you already have an authentication token you just need to specify your server’ s hostname and your token ( your current split session will be unaffected ); </ li >
< li > if you have not an authentication token yet , you first have to authorize { $sname } to access your account by specifying only your server’ s hostname , leaving the “Your token” field empty ; then you’ ll be guided through a very quick and easy one - time authorization process , at the end of which { $sname } will tell you your token for future connections , and will be already connected to your account - but please < span class = \ " hili \" >note that this process will make you loose your current split session</span>.</li>
</ ul >
</ div >
< form method = \ " post \" id= \" authform \" name= \" authform \" action= \" { $formact } \" >
" .oldpost2hid(). "
< div class = \ " inputdiv \" ><label for= \" host \" >Your server’ s hostname</label><input type= \" text \" id= \" host \" name= \" host \" class= \" input \" maxlength= \" 253 \" placeholder= \" E.g.: mastodon.whatever.net \" value= \" " . htmlentities ( $_POST [ 'host' ]) . " \" required></div>
< div class = \ " inputdiv \" ><label for= \" token \" >Your token</label><input type= \" password \" id= \" token \" name= \" token \" class= \" input \" maxlength= \" 43 \" placeholder= \" Leave blank if you want to authorize { $sname } to access your account \" value= \" " . htmlentities ( $_POST [ 'token' ]) . " \" ></div>
< div class = \ " lastinputdiv \" ><button type= \" submit \" name= \" act \" value= \" login \" class= \" button \" >Connect</button></div>
</ form > \n " ;
$replyto = '<input type="hidden" name="replyto" value="' . htmlentities ( $_POST [ 'replyto' ]) . '"><input type="hidden" name="setcws" value="' . cb2hid ( 'setcws' ) . '"><input type="hidden" name="setments" value="' . cb2hid ( 'setments' ) . '"><input type="hidden" name="setvisib" value="' . cb2hid ( 'setvisib' ) . '"><input type="hidden" name="setlang" value="' . cb2hid ( 'setlang' ) . '">' ;
$visibility = '<input type="hidden" name="visib" value="' . $_POST [ 'visib' ] . '">' ;
$language = '<input type="hidden" name="lang" value="' . $_POST [ 'lang' ] . '">' ;
} else {
$auth = " <a name= \" connect \" ></a><h2>Connected :-)</h2> \n { $authmsgs } \n <form method= \" post \" id= \" authform \" name= \" authform \" action= \" { $formact } \" > \n " . oldpost2hid () . " <div class= \" normtext \" > { $sname } is connected to your { $myacc [ 'acct' ] } @ { $host } account.</div> \n <div><button type= \" submit \" id= \" logoutbutton \" name= \" act \" value= \" logout \" class= \" button \" >Disconnect</button></div> \n </form> \n " ;
$replyto = '<div class="inputdiv"><label for="replyto">URL of post to reply to</label><input type="text" id="replyto" name="replyto" class="inputx" placeholder="Leave blank to make a new post" value="' . htmlentities ( $_POST [ 'replyto' ]) . '" maxlength="' . MAXREPTOLEN . '"><input type="hidden" name="prevreplyto" value="' . htmlentities ( $_POST [ 'replyto' ]) . '"><div class="lastborder"><div class="trow"><input type="checkbox" name="setcws" id="setcws" class="tcell" value="1"' . $setcwsck . '><label for="setcws" class="cblab">Set “Content Warning” to this post’ s Content Warning (if any)</label></div><div class="trow"><input type="checkbox" name="setments" id="setments" class="tcell" value="1"' . $setmentsck . '><label for="setments" class="cblab">Set “Text to prepend” to this post’ s sender and mentions (except you)</label></div><div class="trow"><input type="checkbox" name="setvisib" id="setvisib" class="tcell" value="1"' . $setvisibck . '><label for="setvisib" class="cblab">Set “Split posts’ visibility” to this post’ s visibility</label></div><div class="trow"><input type="checkbox" name="setlang" id="setlang" class="tcell" value="1"' . $setlangck . '><label for="setlang" class="cblab">Set “Split posts’ language” to this post’ s language</label></div></div></div>' ;
2024-07-26 10:05:28 +02:00
$optsa = [ 'public' => 'First post public, subsequent posts unlisted' , 'unlisted' => 'Unlisted' , 'private' => 'Followers-only' , 'direct' => 'Direct' ];
2023-11-20 12:42:57 +01:00
$buff = '' ;
foreach ( $optsa as $key => $val ) {
if ( $key == $_POST [ 'visib' ]) {
$selected = ' selected' ;
$dispvisib = $val ;
} else {
$selected = '' ;
}
$buff .= " <option value= \" { $key } \" { $selected } > { $val } </option> \n " ;
}
$visibility = '<div class="inputdiv"><label for="visib">Split posts’ visibility</label><select class="input" id="visib" name="visib">' . $buff . '</select></div>' ;
// taken from 'preferences' -> 'other' on mastodon 4.1.2
$optsa = [[ 'aa' , 'Afar' , 'Afaraf' ],[ 'ab' , 'Abkhaz' , 'аҧсуа бызшәа' ],[ 'ae' , 'Avestan' , 'avesta' ],[ 'af' , 'Afrikaans' , 'Afrikaans' ],[ 'ak' , 'Akan' , 'Akan' ],[ 'am' , 'Amharic' , 'አማርኛ' ],[ 'an' , 'Aragonese' , 'aragonés' ],[ 'ar' , 'Arabic' , 'اللغة العربية' ],[ 'as' , 'Assamese' , 'অসমীয়া' ],[ 'av' , 'Avaric' , 'авар мацӀ' ],[ 'ay' , 'Aymara' , 'aymar aru' ],[ 'az' , 'Azerbaijani' , 'azərbaycan dili' ],[ 'ba' , 'Bashkir' , 'башҡорт теле' ],[ 'be' , 'Belarusian' , 'беларуская мова' ],[ 'bg' , 'Bulgarian' , 'български език' ],[ 'bh' , 'Bihari' , 'भोजपुरी' ],[ 'bi' , 'Bislama' , 'Bislama' ],[ 'bm' , 'Bambara' , 'bamanankan' ],[ 'bn' , 'Bengali' , 'বাংলা' ],[ 'bo' , 'Tibetan' , 'བོད་ཡིག' ],[ 'br' , 'Breton' , 'brezhoneg' ],[ 'bs' , 'Bosnian' , 'bosanski jezik' ],[ 'ca' , 'Catalan' , 'Català' ],[ 'ce' , 'Chechen' , 'нохчийн мотт' ],[ 'ch' , 'Chamorro' , 'Chamoru' ],[ 'co' , 'Corsican' , 'corsu' ],[ 'cr' , 'Cree' , 'ᓀᐦᐃᔭᐍᐏᐣ' ],[ 'cs' , 'Czech' , 'čeština' ],[ 'cu' , 'Old Church Slavonic' , 'ѩзыкъ словѣньскъ' ],[ 'cv' , 'Chuvash' , 'чӑваш чӗлхи' ],[ 'cy' , 'Welsh' , 'Cymraeg' ],[ 'da' , 'Danish' , 'dansk' ],[ 'de' , 'German' , 'Deutsch' ],[ 'dv' , 'Divehi' , 'Dhivehi' ],[ 'dz' , 'Dzongkha' , 'རྫོང་ཁ' ],[ 'ee' , 'Ewe' , 'Eʋ egbe' ],[ 'el' , 'Greek' , 'Ελληνικά' ],[ 'en' , 'English' , 'English' ],[ 'eo' , 'Esperanto' , 'Esperanto' ],[ 'es' , 'Spanish' , 'Español' ],[ 'et' , 'Estonian' , 'eesti' ],[ 'eu' , 'Basque' , 'euskara' ],[ 'fa' , 'Persian' , 'فارسی' ],[ 'ff' , 'Fula' , 'Fulfulde' ],[ 'fi' , 'Finnish' , 'suomi' ],[ 'fj' , 'Fijian' , 'Vakaviti' ],[ 'fo' , 'Faroese' , 'føroyskt' ],[ 'fr' , 'French' , 'Français' ],[ 'fy' , 'Western Frisian' , 'Frysk' ],[ 'ga' , 'Irish' , 'Gaeilge' ],[ 'gd' , 'Scottish Gaelic' , 'Gàidhlig' ],[ 'gl' , 'Galician' , 'galego' ],[ 'gu' , 'Gujarati' , 'ગુજરાતી' ],[ 'gv' , 'Manx' , 'Gaelg' ],[ 'ha' , 'Hausa' , 'هَوُسَ' ],[ 'he' , 'Hebrew' , 'עברית' ],[ 'hi' , 'Hindi' , 'हिन्दी' ],[ 'ho' , 'Hiri Motu' , 'Hiri Motu' ],[ 'hr' , 'Croatian' , 'Hrvatski' ],[ 'ht' , 'Haitian' , 'Kreyòl ayisyen' ],[ 'hu' , 'Hungarian' , 'magyar' ],[ 'hy' , 'Armenian' , 'Հայերեն' ],[ 'hz' , 'Herero' , 'Otjiherero' ],[ 'ia' , 'Interlingua' , 'Interlingua' ],[ 'id' , 'Indonesian' , 'Bahasa Indonesia' ],[ 'ie' , 'Interlingue' , 'Interlingue' ],[ 'ig' , 'Igbo' , 'Asụsụ Igbo' ],[ 'ii' , 'Nuosu' , 'ꆈꌠ꒿ Nuosuhxop' ],[ 'ik' , 'Inupiaq' , 'Iñupiaq' ],[ 'io' , 'Ido' , 'Ido' ],[ 'is' , 'Icelandic' , 'Íslenska' ],[ 'it' , 'Italian' , 'Italiano' ],[ 'iu' , 'Inuktitut' , 'ᐃᓄᒃᑎᑐᑦ' ],[ 'ja' , 'Japanese' , '日本語' ],[ 'jv' , 'Javanese' , 'basa Jawa' ],[ 'ka' , 'Georgian' , 'ქართული' ],[ 'kg' , 'Kongo' , 'Kikongo' ],[ 'ki' , 'Kikuyu' , 'Gĩkũyũ' ],[ 'kj' , 'Kwanyama' , 'Kuanyama' ],[ 'kk' , 'Kazakh' , 'қазақ тілі' ],[ 'kl' , 'Kalaallisut' , 'kalaallisut' ],[ 'km' , 'Khmer' , 'ខេមរភាសា' ],[ 'kn' , 'Kannada' , 'ಕನ್ನಡ' ],[ 'ko' , 'Korean' , '한국어' ],[ 'kr' , 'Kanuri' , 'Kanuri' ],[ 'ks' , 'Kashmiri' , 'कश्मीरी' ],[ 'ku' , 'Kurmanji (Kurdish)' , 'Kurmancî' ],[ 'kv' , 'Komi' , 'коми кыв' ],[ 'kw' , 'Cornish' , 'Kernewek' ],[ 'ky' , 'Kyrgyz' , 'Кыргызча' ],[ 'la' , 'Latin' , 'latine' ],[ 'lb' , 'Luxembourgish' , 'Lëtzebuergesch' ],[ 'lg' , 'Ganda' , 'Luganda' ],[ 'li' , 'Limburgish' , 'Limburgs' ],[ 'ln' , 'Lingala' , 'Lingála' ],[ 'lo' , 'Lao' , 'ລາວ' ],[ 'lt' , 'Lithuanian' , 'lietuvių kalba' ],[ 'lu' , 'Luba-Katanga' , 'Tshiluba' ],[ 'lv' , 'Latvian' , 'latviešu valoda' ],[ 'mg' , 'Malagasy' , 'fiteny malagasy' ],[ 'mh' , 'Marshallese' , 'Kajin M̧ajeļ' ],[ 'mi' , 'Māori' , 'te reo Māori' ],[ 'mk' , 'Macedonian' , 'македонски јазик' ],[ 'ml' , 'Malayalam' , 'മലയാളം' ],[ 'mn' , 'Mongolian' , 'Монгол хэл' ],[ 'mr' , 'Marathi' , 'मराठी' ],[ 'ms' , 'Malay' , 'Bahasa Melayu' ],[ 'mt' , 'Maltese' , 'Malti' ],[ 'my' , 'Burmese' , 'ဗမာစာ' ],[ 'na' , 'Nauru' , 'Ekakairũ Naoero' ],[ 'nb' , 'Norwegian Bokmål' , 'Norsk bokmål' ],[ 'nd' , 'Northern Ndebele' , 'isiNdebele' ],[ 'ne' , 'Nepali' , 'नेपाली' ],[ 'ng' , 'Ndonga' , 'Owambo' ],[ 'nl' , 'Dutch' , 'Nederlands' ],[ 'nn' , 'Norwegian Nynorsk' , 'Norsk Nynorsk' ],[ 'no' , 'Norwegian' , 'Norsk' ],[ 'nr' , 'Southern Ndebele' , 'isiNdebele' ],[ 'nv' , 'Navajo' , 'Diné bizaad' ],[ 'ny' , 'Chichewa' , 'chiCheŵa' ],[ 'oc' , 'Occitan' , 'occitan' ],[ 'oj' , 'Ojibwe' , 'ᐊᓂᔑᓈᐯᒧᐎᓐ' ],[ 'om' , 'Oromo' , 'Afaan Oromoo' ],[ 'or' , 'Oriya' , 'ଓଡ଼ିଆ' ],[ 'os' , '
$buff = '' ;
foreach ( $optsa as $val ) {
if ( $val [ 0 ] == $_POST [ 'lang' ]) {
$displang = $val [ 2 ] . ' (' . $val [ 1 ] . ')' ;
$selected = ' selected' ;
} else {
$selected = '' ;
}
$buff .= " <option value= \" { $val [ 0 ] } \" { $selected } > { $val [ 2 ] } ( { $val [ 1 ] } )</option> \n " ;
}
$language = " <div class= \" inputdiv \" ><label for= \" lang \" >Split posts’ language</label><select class= \" input \" id= \" lang \" name= \" lang \" > { $buff } </select></div> \n " ;
unset ( $buff , $optsa );
}
$auth .= " <div class= \" pseparator \" ></div> \n " ;
if ( $dodebug ) {
$debug = '<div class="debug">' . $debug . '</div>' ;
$svers .= '-' . rand ( 10000 , 999999 );
} else {
$debug = '' ;
}
( isset ( $_POST [ 'act' ]) && $_POST [ 'act' ] == 'split' ) ? $splitfh = '' : $splitfh = ' class="fullheight"' ;
header ( 'Content-Language: en' );
echo " <!DOCTYPE HTML>
< html lang = \ " en \" >
< head >
< title > { $sname } : a post splitter for Mastodon </ title >
< meta http - equiv = \ " Content-Type \" content= \" text/html; charset=utf-8 \" >
< meta name = \ " description \" content= \" A post splitter for Mastodon \" >
< meta name = \ " viewport \" content= \" width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no \" >
< meta property = \ " og:image \" content= \" imgs/ogimage.png \" >
< link rel = \ " icon \" type= \" image/png \" href= \" imgs/icon-16.png \" sizes= \" 16x16 \" >
< link rel = \ " icon \" type= \" image/png \" href= \" imgs/icon-32.png \" sizes= \" 32x32 \" >
< link rel = \ " icon \" type= \" image/png \" href= \" imgs/icon-192.png \" sizes= \" 192x192 \" >
< link rel = \ " icon \" type= \" image/png \" href= \" imgs/icon-512.png \" sizes= \" 512x512 \" >
< link rel = \ " apple-touch-icon-precomposed \" href= \" imgs/icon-180.png \" >
< link rel = \ " stylesheet \" type= \" text/css \" href= \" css/main.css?v= { $svers } \" >
2024-10-23 23:11:08 +02:00
< script language = \ " JavaScript \" src= \" { $jstldsfp } ?v= { $svers } \" ></script>
2023-11-20 12:42:57 +01:00
< script language = \ " JavaScript \" src= \" js/main.js?v= { $svers } \" ></script>
< script language = \ " JavaScript \" >
function swpdisp ( elem , defdisp , altdisp ) {
var eh = document . getElementById ( elem ), disp = window . getComputedStyle ( eh ) . getPropertyValue ( 'display' );
if ( disp == defdisp )
eh . style . display = altdisp ;
else
eh . style . display = defdisp ;
}
function updinfo () {
var avchars = document . getElementById ( 'avchars' ) . value , mincl = " .MINCL. " , precwavc = 0 , prelen = mastlength ( document . getElementById ( 'pre' ) . value ), cwlen = document . getElementById ( 'cw' ) . value . length , maxpostlen = " .MAXPOSTC. " , postlen = mastlength ( document . getElementById ( 'post' ) . value );
if ( Number . isNaN ( avchars ) || avchars - mincl < 0 )
precwavc = 0 ;
else
precwavc = avchars - mincl ;
if ( prelen > 0 ) prelen += 2 ;
postlen = postlen + cwlen + prelen ;
document . getElementById ( 'cwlen' ) . textContent = cwlen ;
document . getElementById ( 'cwavc' ) . textContent = precwavc ;
document . getElementById ( 'cwrmc' ) . textContent = precwavc - prelen - cwlen ;
document . getElementById ( 'prelen' ) . textContent = prelen ;
document . getElementById ( 'preavc' ) . textContent = precwavc ;
document . getElementById ( 'prermc' ) . textContent = precwavc - prelen - cwlen ;
document . getElementById ( 'postlen' ) . textContent = postlen ;
document . getElementById ( 'postleft' ) . textContent = maxpostlen - postlen ;
if ( prelen + cwlen <= precwavc ) {
document . getElementById ( 'cwlen' ) . style . color = 'white' ;
document . getElementById ( 'cwrmc' ) . style . color = 'white' ;
document . getElementById ( 'prelen' ) . style . color = 'white' ;
document . getElementById ( 'prermc' ) . style . color = 'white' ;
} else {
document . getElementById ( 'cwlen' ) . style . color = '#550000' ;
document . getElementById ( 'cwrmc' ) . style . color = '#550000' ;
document . getElementById ( 'prelen' ) . style . color = '#550000' ;
document . getElementById ( 'prermc' ) . style . color = '#550000' ;
}
if ( postlen <= maxpostlen ) {
document . getElementById ( 'postlen' ) . style . color = 'white' ;
document . getElementById ( 'postleft' ) . style . color = 'white' ;
} else {
document . getElementById ( 'postlen' ) . style . color = '#550000' ;
document . getElementById ( 'postleft' ) . style . color = '#550000' ;
}
}
var secstowait = 0 , postint = 'notset' , reptoid = '{$reptoid}' , postreq ;
function post ( postindex ) {
if ( postint != 'notset' ) {
clearInterval ( postint );
postint = 'notset' ;
}
var pstatus = document . getElementById ( 'pstatus' ), postscount = parseInt ( document . forms [ 'postform' ] . elements [ 'postscount' ] . value , 10 ), pperc = document . getElementById ( 'pperc' ), plog = document . getElementById ( 'plog' ), pbut = document . getElementById ( 'postbutton' ), form , msg , totres ;
if ( postindex == 0 )
plog . innerHTML = '' ;
msg = 'Posting split post ' + ( postindex + 1 ) + ' of ' + postscount + ' …' ;
pstatus . textContent = msg ;
plog . innerHTML += msg + '<br>' ;
form = new FormData ();
if ( postindex == 0 ) {
if ( reptoid != '' ) form . set ( 'in_reply_to_id' , reptoid );
} else {
form . set ( 'in_reply_to_id' , reptoid );
}
form . set ( 'language' , document . forms [ 'postform' ] . elements [ 'lang' ] . value );
if ( postindex > 0 && document . forms [ 'postform' ] . elements [ 'visib' ] . value == 'public' )
form . set ( 'visibility' , 'unlisted' );
else
form . set ( 'visibility' , document . forms [ 'postform' ] . elements [ 'visib' ] . value );
if ( document . forms [ 'postform' ] . elements [ 'cw' ] . value != '' )
form . set ( 'spoiler_text' , document . forms [ 'postform' ] . elements [ 'cw' ] . value );
form . set ( 'status' , document . getElementById ( 'post_' + postindex ) . value );
console . log ( 'postindex: ' + postindex );
console . log ( form );
postreq = new XMLHttpRequest ();
postreq . onloadend = ( e ) => {
console . log ( postreq . response );
//if (postindex==1) { postreq.response['ok']=false; postreq.response['error']='server exploded'; }// test err
if ( postreq . response === null ) {
console . log ( 'Error: response is null' );
msg = 'An error occurred while posting split post ' + ( postindex + 1 ) + ' of ' + postscount ;
if ( postreq . status != '' && postreq . statusText != '' )
msg += ' (server returned «' + postreq . status + ': ' + postreq . statusText + '»)' ;
pstatus . textContent = msg ;
plog . innerHTML += msg + '<br>' ;
document . forms [ 'postform' ] . elements [ 'postsoffset' ] . value = postindex ;
pbut . disabled = false ;
} else if ( ! postreq . response [ 'ok' ]) {
console . log ( 'Error: response is not ok' );
msg = 'An error occurred while posting split post ' + ( postindex + 1 ) + ' of ' + postscount + ': ' + postreq . response [ 'error' ];
pstatus . textContent = msg ;
plog . innerHTML += msg + '<br>' ;
document . forms [ 'postform' ] . elements [ 'postsoffset' ] . value = postindex ;
pbut . disabled = false ;
} else {
//console.log(e);
//console.log('rate limit remaining: '+postreq.response['remaining']+'; secstoreset: '+postreq.response['secstoreset']+'; id: '+postreq.response['id']+'.');
msg = 'Successfully posted split post ' + ( postindex + 1 ) + ' of ' + postscount + ' :-)' ;
pstatus . textContent = msg ;
plog . innerHTML += msg + '<br>' ;
pperc . style . width = 100 / postscount * ( postindex + 1 ) + '%' ;
reptoid = postreq . response [ 'id' ];
if ( postindex < postscount - 1 ) {
if ( postreq . response [ 'remaining' ] !== null && postreq . response [ 'secstoreset' ] !== null && postreq . response [ 'remaining' ] <= " .REQSTOPRESV. " ) {
secstowait = postreq . response [ 'secstoreset' ];
plog . innerHTML += 'Reached server’ s rate limit, waiting ' + ght ( secstowait ) + ' for next rate limit reset …<br>' ;
totres = setTimeout ( post , secstowait * 1000 , postindex + 1 );
postint = setInterval ( postwait , 500 , postindex + 1 , Date . now () / 1000 );
} else {
totres = setTimeout ( post , " .POSTPAUSE. " , postindex + 1 );
}
} else {
pbut . style . display = 'none' ;
}
}
return ;
};
postreq . responseType = 'json' ;
postreq . open ( 'POST' , 'post.php' );
postreq . send ( form );
}
function postwait ( postindex , start ) {
var remsecs = Math . ceil ( secstowait - ( Date . now () / 1000 - start ));
document . getElementById ( 'pstatus' ) . textContent = 'Reached server’ s rate limit, waiting ' + ght ( remsecs ) + ' for next rate limit reset …' ;
}
function postboot () {
document . getElementById ( 'postbutton' ) . disabled = true ;
document . getElementById ( 'pmonitor' ) . style . display = 'block' ;
post ( parseInt ( document . forms [ 'postform' ] . elements [ 'postsoffset' ] . value , 10 ));
}
function setpostbutton () {
var pb = document . getElementById ( 'postbutton' );
pb . type = 'button' ;
pb . addEventListener ( 'click' , postboot );
pb . textContent = 'Post' ;
}
var loggedin = " .booltostr( $loggedin ). " ;
function setpcb ( index ) {
if ( ! loggedin )
document . getElementById ( 'pcb_' + index ) . style . display = 'block' ;
}
function ght ( secs ) {
out = '' ;
// years
x = Math . floor ( secs / 31536000 );
if ( x > 0 )
( x == 1 ) ? out += x + ' year, ' : out += x + ' years, ' ;
secs = secs - x * 31536000 ;
// weeks
x = Math . floor ( secs / 604800 );
if ( x > 0 )
( x == 1 ) ? out += x + ' week, ' : out += x + ' weeks, ' ;
secs = secs - x * 604800 ;
// days
x = Math . floor ( secs / 86400 );
if ( x > 0 )
( x == 1 ) ? out += x + ' day, ' : out += x + ' days, ' ;
secs = secs - x * 86400 ;
// hours
x = Math . floor ( secs / 3600 );
if ( x > 0 )
( x == 1 ) ? out += x + ' hour, ' : out += x + ' hours, ' ;
secs = secs - x * 3600 ;
// minutes
x = Math . floor ( secs / 60 );
if ( x > 0 )
( x == 1 ) ? out += x + ' minute, ' : out += x + ' minutes, ' ;
secs = secs - x * 60 ;
// seconds
( secs == 1 ) ? out += secs + ' second' : out += secs + ' seconds' ;
return out ;
}
function ckf () {
var mincl = " .MINCL. " ,
maxpostc = " .MAXPOSTC. " ,
avchars = document . getElementById ( 'avchars' ) . value ,
cw = document . getElementById ( 'cw' ),
cwlen = cw . value . length ,
pre = document . getElementById ( 'pre' );
prelen = mastlength ( pre . value ),
postlen = mastlength ( document . getElementById ( 'post' ) . value ),
pmsg = document . getElementById ( 'pupmsg' ),
ptit = document . getElementById ( 'puptit' ),
maxcwprelen = avchars - mincl ,
ofelems = document . forms [ 'authform' ] . elements ,
msg = '' ,
msgs = [];
if ( cwlen + prelen > maxcwprelen ) msgs . push ( 'text of Content Warning + text to prepend is ' + ( cwlen + prelen ) + ' characters long, that is ' + ( cwlen + prelen - maxcwprelen ) + ' characters longer than its maximum allowed length (' + maxcwprelen + ' characters, that is ' + avchars + ' available characters minus ' + mincl + ' characters)' );
if ( postlen > maxpostc ) msgs . push ( 'post to split is ' + postlen + ' characters long, that is ' + ( postlen - maxpostc ) + ' characters longer than its maximum allowed length, ' + maxpostc );
var len = msgs . length , sep = ';' ;
if ( len > 0 ) {
ptit . textContent = 'Errors' ;
msg = '<ul>' ;
for ( i = 0 ; i < len ; i ++ ) {
if ( i == len - 1 ) sep = '.' ;
msg += '<li>' + msgs [ i ] + sep + '</li>' ;
}
pmsg . innerHTML = msg + '</ul>' ;
swpdisp ( 'popup' , 'none' , 'flex' );
return false ;
} else {
msgs = [];
if ( document . getElementById ( 'replyto' ) != null && document . getElementById ( 'replyto' ) . value . trim () != '' ) {
if ( document . getElementById ( 'setcws' ) . checked && cw . value != ofelems [ 'cw' ] . value )
msgs . push ( 'you have changed “Content Warning”, but it will be overwritten by the Content Warning detected in the post you are replying to (if present)' );
if ( document . getElementById ( 'setments' ) . checked && pre . value != ofelems [ 'pre' ] . value )
msgs . push ( 'you have changed “Text to prepend to each split post”, but it will be overwritten by the sender and mentions (except you) detected in the post you are replying to' );
if ( document . getElementById ( 'setvisib' ) . checked && document . getElementById ( 'visib' ) . value != ofelems [ 'visib' ] . value )
msgs . push ( 'you have changed “Split posts’ visibility”, but it will be set to the visibility of the post you are replying to' );
if ( document . getElementById ( 'setlang' ) . checked && document . getElementById ( 'lang' ) . value != ofelems [ 'lang' ] . value )
msgs . push ( 'you have changed “Split posts’ language”, but it will be set to the language of the post you are replying to' );
}
len = msgs . length ;
sep = ';' ;
if ( len > 0 ) {
ptit . textContent = 'Warnings' ;
msg = '<ul>' ;
for ( i = 0 ; i < len ; i ++ ) {
if ( i == len - 1 ) sep = '.' ;
msg += '<li>' + msgs [ i ] + sep + '</li>' ;
}
2024-01-09 19:55:16 +01:00
pmsg . innerHTML = msg + '</ul><p> </p><p class=\"firstp\">Do you want to continue?</p><p> </p><button class=\"halfbutton\" onclick=\"document.mainform.submit(true);\">Yes</button><button class=\"halfbutton\" onclick=\"swpdisp(\'popup\',\'flex\',\'none\');event.stopPropagation();\">No</button>' ;
2023-11-20 12:42:57 +01:00
swpdisp ( 'popup' , 'none' , 'flex' );
return false ;
} else {
return true ;
}
}
}
</ script >
</ head >
< body >
< div id = \ " notif \" title= \" Close \" onclick= \" this.style.display='none'; \" >Elo!</div>
< div id = \ " popup \" onclick= \" swpdisp('popup','flex','none'); \" >
< div id = \ " popupmsg \" >
< div id = \ " puptitle \" ><table class= \" tittab \" ><tr><td style= \" width:24px; \" ></td><td style= \" text-align:center; \" id= \" puptit \" >Uz!</td><td style= \" width:24px; \" ><img src= \" imgs/icon_close.png \" class= \" closeb \" onclick= \" swpdisp('popup','flex','none');event.stopPropagation(); \" ></td></tr></table></div>
< div id = \ " pupmsg \" >Elo!</div>
</ div >
</ div >
{ $debug }
< div id = \ " main \" >
{ $headmsgs }
< h1 > { $sname } : a post splitter for Mastodon </ h1 >
{ $intro }
< div class = \ " separator \" ></div>
{ $auth }
< div { $splitfh } >
< a name = \ " split \" ></a><h2>Split post</h2>
{ $splitmsgs }
< form method = \ " post \" id= \" mainform \" name= \" mainform \" action= \" { $formact } \" onsubmit= \" return ckf(); \" >
< input type = \ " hidden \" name= \" round \" value= \" " . $_POST [ 'round' ] . " \" >
< div class = \ " inputdiv \" ><label for= \" avchars \" >Available characters per post ( " . MINAC . " - " . MAXAC . " )</label><input type= \" number \" id= \" avchars \" name= \" avchars \" class= \" input \" placeholder= \" The number of characters per post available on your server \" value= \" { $_POST [ 'avchars' ] } \" min= \" " . MINAC . " \" max= \" " . MAXAC . " \" onkeyup= \" updinfo(); \" onchange= \" updinfo(); \" required></div>
{ $replyto }
< div class = \ " inputdiv \" ><label for= \" cw \" >Content Warning (applies to all split posts) (<span id= \" cwlen \" > { $cwlen } </span>/<span id= \" cwavc \" > { $maxcwprec } </span>: <span id= \" cwrmc \" > " . ( $maxcwprec - $cwprelen ) . " </span> left)</label><input type= \" text \" id= \" cw \" name= \" cw \" class= \" input \" placeholder= \" Leave blank for no Content Warning \" value= \" " . htmlentities ( $_POST [ 'cw' ]) . " \" maxlength= \" " . ( MAXAC - MINCL ) . " \" onkeyup= \" updinfo(); \" onchange= \" updinfo(); \" ></div>
< div class = \ " inputdiv \" ><label for= \" pre \" >Text to prepend to each split post, eg. the recipient(s) (<span id= \" prelen \" > { $prelen } </span>/<span id= \" preavc \" > { $maxcwprec } </span>: <span id= \" prermc \" > " . ( $maxcwprec - $cwprelen ) . " </span> left)</label><input type= \" text \" id= \" pre \" name= \" pre \" class= \" input \" placeholder= \" Leave blank to prepend nothing \" value= \" " . htmlentities ( $_POST [ 'pre' ]) . " \" maxlength= \" " . ( MAXAC - MINCL ) . " \" onkeyup= \" updinfo(); \" onchange= \" updinfo(); \" ></div>
{ $visibility }
{ $language }
< div class = \ " inputdiv \" ><label for= \" post \" >Post to split (<span id= \" postlen \" > { $postlen } </span>/ " . MAXPOSTC . " : <span id= \" postleft \" > " . ( MAXPOSTC - $postlen ) . " </span> left)</label><textarea placeholder= \" Write or paste your long post here \" id= \" post \" name= \" post \" class= \" input \" rows= \" 10 \" onkeyup= \" updinfo(); \" onchange= \" updinfo(); \" required> " . htmlentities ( $_POST [ 'post' ]) . " </textarea></div>
< script language = \ " JavaScript \" >
updinfo ();
</ script >
< div class = \ " inputdiv \" ><label for= \" cntpos \" >Split posts’ counter position</label>
< fieldset >
< div class = \ " trow \" ><input type= \" radio \" id= \" cntpos_before \" name= \" cntpos \" value= \" before \" class= \" tcell \" required { $rbsck [ 'cntpos_before' ] } ><label for= \" cntpos_before \" class= \" cblab \" >Before each split post’ s body</label></div>
< div class = \ " trow \" ><input type= \" radio \" id= \" cntpos_after \" name= \" cntpos \" value= \" after \" class= \" tcell \" required { $rbsck [ 'cntpos_after' ] } ><label for= \" cntpos_after \" class= \" cblab \" >After each split post’ s body</label></div>
</ fieldset >
</ div >
< div class = \ " inputdiv \" ><label for= \" addref \" >Add link to this page at last split post’ s end?</label>
< fieldset >
< div class = \ " trow \" ><input type= \" radio \" id= \" addref_no \" name= \" addref \" value= \" no \" class= \" tcell \" required { $rbsck [ 'addref_no' ] } ><label for= \" addref_no \" class= \" cblab \" >No</label></div>
< div class = \ " trow \" ><input type= \" radio \" id= \" addref_ifav \" name= \" addref \" value= \" ifav \" class= \" tcell \" required { $rbsck [ 'addref_ifav' ] } ><label for= \" addref_ifav \" class= \" cblab \" >If last split post has enough space left</label></div>
</ fieldset >
</ div >
< div class = \ " lastinputdiv \" ><button type= \" submit \" id= \" button \" name= \" act \" value= \" split \" class= \" button \" >Split</button></div> \n </form> \n </div> \n " ;
if ( $splitmsgs == '' ) {
if ( isset ( $_POST [ 'act' ]) && $_POST [ 'act' ] == 'split' && $_POST [ 'post' ] != '' ) {
$linklen = postlength ( $conf [ 'link' ]);
( $_POST [ 'pre' ] != '' ) ? $pre = $_POST [ 'pre' ] . " \n \n " : $pre = '' ;
$posts = splitpost ( $_POST [ 'post' ], $_POST [ 'avchars' ], $_POST [ 'cw' ], $pre , $cntbef );
$postscount = count ( $posts );
$errposts = [];
for ( $i = 0 ; $i < $postscount ; $i ++ )
if ( $posts [ $i ][ 'mastlen' ] > $_POST [ 'avchars' ]) $errposts [] = " <a href= \" #pa_ { $i } \" > { $i } </a> " ;
$epc = count ( $errposts );
if ( $epc > 0 ) {
if ( $epc == 1 )
echo " <p class= \" firstp \" >Sorry, the length of one split post (namely { $errposts [ 0 ] } ) exceeds { $_POST [ 'avchars' ] } characters. " ;
else
echo " <p class= \" firstp \" >Sorry, the length of { $epc } split posts (namely " . implode ( ', ' , $errposts ) . " ) exceeds { $_POST [ 'avchars' ] } characters. " ;
2024-07-14 21:53:11 +02:00
echo " Please report this bug <a href= \" https://git.lattuga.net/jones/verbose/issues \" >here</a>, possibly citing the original post text.</p> \n " ;
2023-11-20 12:42:57 +01:00
}
if ( $postscount > 1 && $aliif && $posts [ $postscount - 1 ][ 'mastlen' ] + $linklen <= $_POST [ 'avchars' ]) {
$posts [ $postscount - 1 ][ 'post' ] .= $conf [ 'link' ];
$posts [ $postscount - 1 ][ 'mastlen' ] += $linklen ;
}
}
if ( $postscount > 0 ) {
//if ($loggedin) $postmsgs.="<div class=\"normtext\">“Post all” button is at the bottom ;-)</div>\n";
echo " <div class= \" pseparator \" ></div> \n <div class= \" fullheight \" ><a name= \" splitresults \" ></a><h2>Split results</h2> \n { $postmsgs } <form method= \" post \" id= \" postform \" name= \" postform \" action= \" { $formact } \" > \n " ;
$info = 'Content Warning: ' ;
( $posts [ $postsoffset ][ 'cw' ] != '' ) ? $info .= htmlentities ( $_POST [ 'cw' ]) : $info .= '<span class="notset">not set</span>' ;
if ( $loggedin ) $info .= '<br>Visibility: ' . $dispvisib . '<br>Language: ' . htmlentities ( $displang );
( $loggedin ) ? $postdivclass = 'postdivnobut' : $postdivclass = 'postdiv' ;
for ( $i = $postsoffset ; $i < $postscount ; $i ++ ) {
$io = $i + 1 ;
( $posts [ $i ][ 'mastlen' ] > $_POST [ 'avchars' ]) ? $phclass = 'errposthead' : $phclass = 'posthead' ;
echo " <div class= \" { $phclass } \" ><a name= \" pa_ { $i } \" ></a>Post { $io } / { $postscount } (“Mastodon length”: { $posts [ $i ][ 'mastlen' ] } ; real length: " . ( mb_strlen ( $posts [ $i ][ 'post' ], 'UTF-8' ) + $cwlen ) . " )</div> \n <div class= \" outputdiv \" ><div class= \" outputnobb \" > { $info } </div></div> \n <div class= \" outputdiv \" ><div id= \" postdiv_ { $i } \" class= \" { $postdivclass } \" > " . nl2br ( htmlentities ( $posts [ $i ][ 'post' ])) . " </div><input type= \" hidden \" id= \" post_ { $i } \" name= \" post_ { $i } \" value= \" " . htmlentities ( $posts [ $i ][ 'post' ]) . " \" ><input type= \" hidden \" id= \" mastlen_ { $i } \" name= \" mastlen_ { $i } \" value= \" { $posts [ $i ][ 'mastlen' ] } \" ></div> \n <div class= \" outputdiv \" ><button type= \" button \" id= \" pcb_ { $i } \" class= \" copybutton \" onclick= \" copytext( { $i } ); \" >Copy post text</button><script language= \" JavaScript \" > \n setpcb( { $i } ); \n </script> \n </div> \n " ;
}
if ( $loggedin ) {
if ( ! isset ( $lspostid )) $lspostid = '' ;
echo " <div class= \" lastoutputdiv \" ><div id= \" pmonitor \" > \n <div id= \" pstatus \" ></div> \n <div id= \" ppercenv \" ><div id= \" pperc \" > </div></div> \n <div id= \" plog \" > </div> \n </div> \n <button type= \" submit \" id= \" postbutton \" name= \" act \" value= \" sendposts \" class= \" postbutton \" > { $pbtext } </button></div> \n " . oldpost2hid () . " <input type= \" hidden \" name= \" postscount \" value= \" { $postscount } \" > \n <input type= \" hidden \" name= \" postwaituntil \" value= \" { $postwaituntil } \" > \n <input type= \" hidden \" name= \" postsoffset \" value= \" { $postsoffset } \" > \n <input type= \" hidden \" name= \" lastsentpostid \" value= \" { $lspostid } \" > \n <script language= \" JavaScript \" > \n setpostbutton(); \n </script> \n " ;
}
echo " </form></div> \n " ;
} elseif ( $postmsgs != '' ) {
echo " <div class= \" separator \" ></div> \n { $postmsgs } " ;
}
}
if ( isset ( $conf [ 'footer' ]))
echo " <div id= \" almfooter \" > { $conf [ 'footer' ] } </div> \n " ;
echo " <div id= \" footer \" ><a href= \" " . SREPO . " \" > " . SNAME . " " . SVERS . " </a></div>
</ div >
</ body >
</ html > \n " ;
2024-08-27 21:17:07 +02:00
2023-11-20 12:42:57 +01:00
function preprint ( $var ) {
return '<pre>' . print_r ( $var , true ) . " </pre> \n " ;
}
function dieyoung ( $msg ) {
echo $msg ;
exit ( 1 );
}
function cb2hid ( $pkey ) {
if ( isset ( $_POST [ $pkey ]) && $_POST [ $pkey ] == '1' )
return '1' ;
else
return '0' ;
}
function oldpost2hid () {
return " <input type= \" hidden \" name= \" avchars \" value= \" { $_POST [ 'avchars' ] } \" > \n <input type= \" hidden \" name= \" cw \" value= \" " . htmlentities ( $_POST [ 'cw' ]) . " \" > \n <input type= \" hidden \" name= \" pre \" value= \" " . htmlentities ( $_POST [ 'pre' ]) . " \" > \n <input type= \" hidden \" name= \" post \" value= \" " . htmlentities ( $_POST [ 'post' ]) . " \" > \n <input type= \" hidden \" name= \" replyto \" value= \" " . htmlentities ( $_POST [ 'replyto' ]) . " \" > \n <input type= \" hidden \" name= \" setcws \" value= \" " . cb2hid ( 'setcws' ) . " \" > \n <input type= \" hidden \" name= \" setments \" value= \" " . cb2hid ( 'setments' ) . " \" > \n <input type= \" hidden \" name= \" setvisib \" value= \" " . cb2hid ( 'setvisib' ) . " \" > \n <input type= \" hidden \" name= \" setlang \" value= \" " . cb2hid ( 'setlang' ) . " \" > \n <input type= \" hidden \" name= \" visib \" value= \" { $_POST [ 'visib' ] } \" > \n <input type= \" hidden \" name= \" lang \" value= \" { $_POST [ 'lang' ] } \" > \n <input type= \" hidden \" name= \" cntpos \" value= \" { $_POST [ 'cntpos' ] } \" > \n <input type= \" hidden \" name= \" addref \" value= \" { $_POST [ 'addref' ] } \" > \n <input type= \" hidden \" name= \" round \" value= \" { $_POST [ 'round' ] } \" > \n " ;
}
?>