Réindentation du code pour une meilleur lecture.
This commit is contained in:
parent
9a3ea6f195
commit
653d007602
1 changed files with 94 additions and 85 deletions
179
xsaf2.php
179
xsaf2.php
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
/* modtime 2013-01-28 */
|
/* modtime 2013-01-30 */
|
||||||
|
|
||||||
define('DEBUG', true);
|
define('DEBUG', true);
|
||||||
|
|
||||||
|
@ -8,55 +8,53 @@ header('X-Robots-Tag: noindex'); /* more civilized method, but bots may not a
|
||||||
header('Content-type: text/plain');
|
header('Content-type: text/plain');
|
||||||
$expire = time() -7200 ; $lockfile = ".xsaflock"; /* defaut delay: 7200 (2 hours) */
|
$expire = time() -7200 ; $lockfile = ".xsaflock"; /* defaut delay: 7200 (2 hours) */
|
||||||
|
|
||||||
if (file_exists($lockfile))
|
if (file_exists($lockfile)) {
|
||||||
{
|
if (filemtime($lockfile) > $expire) {
|
||||||
if (filemtime($lockfile) > $expire)
|
echo "too early";
|
||||||
{ echo "too early"; die; }
|
die;
|
||||||
else
|
}else{
|
||||||
{ unlink($lockfile); file_put_contents($lockfile, ''); }
|
unlink($lockfile);
|
||||||
}
|
file_put_contents($lockfile, '');
|
||||||
else file_put_contents($lockfile, '');
|
}
|
||||||
|
}else{
|
||||||
|
file_put_contents($lockfile, '');
|
||||||
|
}
|
||||||
|
|
||||||
define('ROOT_DIR', __DIR__);
|
define('ROOT_DIR', __DIR__);
|
||||||
function escape($str)
|
function escape($str) {
|
||||||
{
|
|
||||||
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
|
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
|
||||||
}
|
}
|
||||||
function serverUrl()
|
|
||||||
{
|
function serverUrl() {
|
||||||
$https = (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS'])=='on')) || $_SERVER["SERVER_PORT"]=='443'; // HTTPS detection.
|
$https = (!empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS'])=='on')) || $_SERVER["SERVER_PORT"]=='443'; // HTTPS detection.
|
||||||
$serverport = ($_SERVER["SERVER_PORT"]=='80' || ($https && $_SERVER["SERVER_PORT"]=='443') ? '' : ':'.$_SERVER["SERVER_PORT"]);
|
$serverport = ($_SERVER["SERVER_PORT"]=='80' || ($https && $_SERVER["SERVER_PORT"]=='443') ? '' : ':'.$_SERVER["SERVER_PORT"]);
|
||||||
return 'http'.($https?'s':'').'://'.$_SERVER["SERVER_NAME"].$serverport;
|
return 'http'.($https?'s':'').'://'.$_SERVER["SERVER_NAME"].$serverport;
|
||||||
}
|
}
|
||||||
function NoProtocolSiteURL($url)
|
|
||||||
{
|
function NoProtocolSiteURL($url) {
|
||||||
$siteurlnoprototypes = array("http://", "https://");
|
$siteurlnoprototypes = array("http://", "https://");
|
||||||
$siteurlnoproto = str_replace($siteurlnoprototypes, "", $url);
|
$siteurlnoproto = str_replace($siteurlnoprototypes, "", $url);
|
||||||
return $siteurlnoproto;
|
return $siteurlnoproto;
|
||||||
}
|
}
|
||||||
function xsafimport($xsafremote, $iter)
|
|
||||||
{
|
function xsafimport($xsafremote, $iter) {
|
||||||
echo "\n*Traitement $xsafremote avec $iter créations max";
|
echo "\n*Traitement $xsafremote avec $iter créations max";
|
||||||
$json_import = file_get_contents($xsafremote);
|
$json_import = file_get_contents($xsafremote);
|
||||||
if(!empty($json_import)){
|
if(!empty($json_import)) {
|
||||||
$to_update=array();
|
$to_update=array();
|
||||||
foreach (json_decode($json_import) as $value) {
|
foreach (json_decode($json_import) as $value) {
|
||||||
$infos="";
|
$infos="";
|
||||||
if(count($value)==3 && !empty($value[0]) && !empty($value[1]) && !empty($value[2])){
|
if(count($value)==3 && !empty($value[0]) && !empty($value[1]) && !empty($value[2])) {
|
||||||
|
|
||||||
$sitename = $value[0];
|
$sitename = $value[0];
|
||||||
$siteurl = escape($value[1]);
|
$siteurl = escape($value[1]);
|
||||||
$rssurl = escape($value[2]);
|
$rssurl = escape($value[2]);
|
||||||
if(strpos($siteurl, 'twitter.com') !== FALSE or strpos($siteurl, 'identi.ca') !== FALSE or strpos($sitename, 'statusnet-') !== FALSE) {$social=TRUE;} else {$social=FALSE;}
|
if(strpos($siteurl, 'twitter.com') !== FALSE or strpos($siteurl, 'identi.ca') !== FALSE or strpos($sitename, 'statusnet-') !== FALSE) {$social=TRUE;} else {$social=FALSE;}
|
||||||
if($social==FALSE)
|
if($social==FALSE) {
|
||||||
{
|
|
||||||
$foldername = sha1(NoProtocolSiteURL($siteurl));
|
$foldername = sha1(NoProtocolSiteURL($siteurl));
|
||||||
if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');}
|
if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');}
|
||||||
}
|
} else{
|
||||||
else
|
|
||||||
{
|
|
||||||
$foldername = $sitename;$foldername2 = $sitename;
|
$foldername = $sitename;$foldername2 = $sitename;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sitedomain1 = preg_split('/\//', $siteurl, 0);
|
$sitedomain1 = preg_split('/\//', $siteurl, 0);
|
||||||
$sitedomain2=$sitedomain1[2];
|
$sitedomain2=$sitedomain1[2];
|
||||||
|
@ -67,88 +65,97 @@ echo "\n*Traitement $xsafremote avec $iter créations max";
|
||||||
if ( mkdir('./'. $foldername, 0755, false) ) {
|
if ( mkdir('./'. $foldername, 0755, false) ) {
|
||||||
$fp = fopen('./'. $foldername .'/index.php', 'w+');
|
$fp = fopen('./'. $foldername .'/index.php', 'w+');
|
||||||
|
|
||||||
$response = get_headers($rssurl, 1); // check for redirections
|
$response = get_headers($rssurl, 1); // check for redirections
|
||||||
if(!empty($response['Location']))
|
if(!empty($response['Location'])) {
|
||||||
{ $result="false"; }
|
$result="false";
|
||||||
else
|
}else{
|
||||||
{
|
$xml = simplexml_load_file($rssurl); // quick feed check
|
||||||
$xml = simplexml_load_file($rssurl); // quick feed check
|
if (isset($xml->entry)) { // ATOM feed.
|
||||||
if (isset($xml->entry)) // ATOM feed.
|
$result="true";
|
||||||
{$result="true";}
|
}elseif (isset($xml->item)) { // RSS 1.0 /RDF
|
||||||
elseif (isset($xml->item)) // RSS 1.0 /RDF
|
$result="true";
|
||||||
{$result="true";}
|
}elseif (isset($xml->channel->item)) { // RSS 2.0
|
||||||
elseif (isset($xml->channel->item)) // RSS 2.0
|
$result="true";
|
||||||
{$result="true";}
|
}else{
|
||||||
else
|
$result="false";
|
||||||
{$result="false";}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* autoblog */
|
/* autoblog */
|
||||||
if($social==FALSE and $result!=="false")
|
if($social==FALSE and $result!=="false") {
|
||||||
{ $iter--;
|
$iter--;
|
||||||
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/autoblog.php'; ?>") ){
|
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/autoblog.php'; ?>") ) {
|
||||||
$infos = "\nImpossible d'écrire le fichier index.php dans ".$foldername;
|
$infos = "\nImpossible d'écrire le fichier index.php dans ".$foldername;
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
}else{
|
}else{
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
$fp = fopen('./'. $foldername .'/vvb.ini', 'w+');
|
$fp = fopen('./'. $foldername .'/vvb.ini', 'w+');
|
||||||
if( !fwrite($fp, '[VroumVroumBlogConfig]
|
if( !fwrite($fp, '[VroumVroumBlogConfig]
|
||||||
SITE_TITLE="'. $sitename .'"
|
SITE_TITLE="'. $sitename .'"
|
||||||
SITE_DESCRIPTION="Ce site n\'est pas le site officiel de '. $sitename .'<br>C\'est un blog automatisé qui réplique les articles de <a href="'. $siteurl .'">'. $sitename .'</a>"
|
SITE_DESCRIPTION="Ce site n\'est pas le site officiel de '. $sitename .'<br>C\'est un blog automatisé qui réplique les articles de <a href="'. $siteurl .'">'. $sitename .'</a>"
|
||||||
SITE_URL="'. $siteurl .'"
|
SITE_URL="'. $siteurl .'"
|
||||||
FEED_URL="'. $rssurl .'"
|
FEED_URL="'. $rssurl .'"
|
||||||
DOWNLOAD_MEDIA_FROM='.$sitedomain) ){
|
DOWNLOAD_MEDIA_FROM='.$sitedomain) ){
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
$infos = "\nImpossible d'écrire le fichier vvb.ini dans ".$foldername;
|
$infos = "\nImpossible d'écrire le fichier vvb.ini dans ".$foldername;
|
||||||
}else{
|
}else{
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
$infos = "\n$iter/autoblog crée avec succès : $foldername";
|
$infos = "\n$iter/autoblog crée avec succès : $foldername";
|
||||||
$to_update[]=serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
|
$to_update[]=serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
/* automicroblog */
|
||||||
/* automicroblog */
|
else if($social!==FALSE and $result!=="false"){
|
||||||
else if($social!==FALSE and $result!=="false")
|
$iter--;
|
||||||
{ $iter--;
|
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/automicroblog.php'; ?>") ){
|
||||||
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/automicroblog.php'; ?>") ){
|
$infos = "\nImpossible d'écrire le fichier index.php dans ".$foldername;
|
||||||
$infos = "\nImpossible d'écrire le fichier index.php dans ".$foldername;
|
fclose($fp);
|
||||||
fclose($fp);
|
}else{
|
||||||
}else{
|
fclose($fp);
|
||||||
fclose($fp);
|
$fp = fopen('./'. $foldername .'/vvb.ini', 'w+');
|
||||||
$fp = fopen('./'. $foldername .'/vvb.ini', 'w+');
|
if( !fwrite($fp, '[VroumVroumBlogConfig]
|
||||||
if( !fwrite($fp, '[VroumVroumBlogConfig]
|
|
||||||
SITE_TITLE="'. $sitename .'"
|
SITE_TITLE="'. $sitename .'"
|
||||||
SITE_DESCRIPTION="AutoMicroblog automatisé de "
|
SITE_DESCRIPTION="AutoMicroblog automatisé de "
|
||||||
SITE_URL="'. $siteurl .'"
|
SITE_URL="'. $siteurl .'"
|
||||||
FEED_URL="'. $rssurl .'"') ){
|
FEED_URL="'. $rssurl .'"') ){
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
$infos = "\nImpossible d'écrire le fichier vvb.ini dans ".$foldername;
|
$infos = "\nImpossible d'écrire le fichier vvb.ini dans ".$foldername;
|
||||||
}else{
|
}else{
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
$infos = "\n$iter/automicroblog crée avec succès : $foldername";
|
$infos = "\n$iter/automicroblog crée avec succès : $foldername";
|
||||||
$to_update[]=serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
|
$to_update[]=serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$infos = "\n$rssurl -> flux invalide";
|
||||||
}
|
}
|
||||||
|
/* end of file writing */
|
||||||
} else { $infos = "\n$rssurl -> flux invalide"; }
|
|
||||||
/* end of file writing */
|
|
||||||
}else {
|
}else {
|
||||||
$infos = "\nImpossible de créer le répertoire ".$foldername;
|
$infos = "\nImpossible de créer le répertoire ".$foldername;
|
||||||
}
|
}
|
||||||
} else { /*$infos = "\nFin d'itération ou Le répertoire ".$foldername." existe déjà ($sitename;$siteurl;$rssurl)";*/ }
|
} else {
|
||||||
if(DEBUG){ echo $infos; }
|
/*$infos = "\nFin d'itération ou Le répertoire ".$foldername." existe déjà ($sitename;$siteurl;$rssurl)";*/
|
||||||
|
}
|
||||||
|
if(DEBUG){
|
||||||
|
echo $infos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*if(!empty($to_update)){
|
/*if(!empty($to_update)){
|
||||||
if(DEBUG){ echo "\nupdate of autoblogs ..."; }
|
if(DEBUG){
|
||||||
|
echo "\nupdate of autoblogs ...";
|
||||||
|
}
|
||||||
// because it's could be very long, we finish by updating new autoblogs
|
// because it's could be very long, we finish by updating new autoblogs
|
||||||
foreach ($to_update as $url) {
|
foreach ($to_update as $url) {
|
||||||
get_headers($url);
|
get_headers($url);
|
||||||
}
|
}
|
||||||
if(DEBUG){ echo "done\n\n"; }
|
if(DEBUG){
|
||||||
|
echo "done\n\n";
|
||||||
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
$iter=''; return;
|
$iter=''; return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And now, the XSAF links to be imported, with maximal import per run ! */
|
/* And now, the XSAF links to be imported, with maximal import per run ! */
|
||||||
|
@ -156,6 +163,8 @@ xsafimport('https://raw.github.com/mitsukarenai/xsaf-bootstrap/master/2.json', 2
|
||||||
//xsafimport('https://www.ecirtam.net/autoblogs/?export', 2);
|
//xsafimport('https://www.ecirtam.net/autoblogs/?export', 2);
|
||||||
//xsafimport('https://autoblog.suumitsu.eu/?export', 1);
|
//xsafimport('https://autoblog.suumitsu.eu/?export', 1);
|
||||||
|
|
||||||
if(DEBUG){ echo "\n\nXSAF import finished\n\n"; }
|
if(DEBUG) {
|
||||||
|
echo "\n\nXSAF import finished\n\n";
|
||||||
|
}
|
||||||
die;
|
die;
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue