2013-01-22 22:48:58 +01:00
< ? php
2013-01-30 21:40:34 +01:00
/* modtime 2013-01-30 */
2013-01-22 22:48:58 +01:00
define ( 'DEBUG' , true );
header ( " HTTP/1.0 403 Forbidden " ); /* Uncivilized method to prevent bot indexing, huh :) */
header ( 'X-Robots-Tag: noindex' ); /* more civilized method, but bots may not all take into account */
header ( 'Content-type: text/plain' );
$expire = time () - 7200 ; $lockfile = " .xsaflock " ; /* defaut delay: 7200 (2 hours) */
2013-01-30 21:40:34 +01:00
if ( file_exists ( $lockfile )) {
if ( filemtime ( $lockfile ) > $expire ) {
echo " too early " ;
die ;
} else {
unlink ( $lockfile );
file_put_contents ( $lockfile , '' );
}
} else {
file_put_contents ( $lockfile , '' );
}
2013-01-22 22:48:58 +01:00
define ( 'ROOT_DIR' , __DIR__ );
2013-01-30 21:40:34 +01:00
function escape ( $str ) {
2013-01-22 22:48:58 +01:00
return htmlspecialchars ( $str , ENT_COMPAT , 'UTF-8' , false );
}
2013-01-30 21:40:34 +01:00
function serverUrl () {
2013-01-22 22:48:58 +01:00
$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 " ]);
return 'http' . ( $https ? 's' : '' ) . '://' . $_SERVER [ " SERVER_NAME " ] . $serverport ;
}
2013-01-30 21:40:34 +01:00
function NoProtocolSiteURL ( $url ) {
2013-01-23 20:11:49 +01:00
$siteurlnoprototypes = array ( " http:// " , " https:// " );
$siteurlnoproto = str_replace ( $siteurlnoprototypes , " " , $url );
return $siteurlnoproto ;
}
2013-01-30 21:40:34 +01:00
2013-01-30 22:28:19 +01:00
libxml_use_internal_errors ( true );
// $max_exec_time = temps max d'exécution en seconde
function xsafimport ( $xsafremote , $max_exec_time ) {
echo " \n *Traitement $xsafremote en maximum $max_exec_time secondes " ;
$max_exec_time += time () - 1 ; // -1 car l'import prend environ 1 seconde
2013-01-28 12:29:45 +01:00
$json_import = file_get_contents ( $xsafremote );
2013-01-30 21:40:34 +01:00
if ( ! empty ( $json_import )) {
2013-01-22 22:48:58 +01:00
$to_update = array ();
foreach ( json_decode ( $json_import ) as $value ) {
$infos = " " ;
2013-01-30 21:40:34 +01:00
if ( count ( $value ) == 3 && ! empty ( $value [ 0 ]) && ! empty ( $value [ 1 ]) && ! empty ( $value [ 2 ])) {
2013-01-23 23:15:16 +01:00
$sitename = $value [ 0 ];
$siteurl = escape ( $value [ 1 ]);
2013-01-22 22:48:58 +01:00
$rssurl = escape ( $value [ 2 ]);
2013-01-30 21:40:34 +01:00
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 ) {
2013-01-23 23:15:16 +01:00
$foldername = sha1 ( NoProtocolSiteURL ( $siteurl ));
if ( substr ( $siteurl , - 1 ) == '/' ){ $foldername2 = sha1 ( NoProtocolSiteURL ( substr ( $siteurl , 0 , - 1 ))); } else { $foldername2 = sha1 ( NoProtocolSiteURL ( $siteurl ) . '/' );}
2013-01-30 21:40:34 +01:00
} else {
2013-01-23 23:15:16 +01:00
$foldername = $sitename ; $foldername2 = $sitename ;
2013-01-30 21:40:34 +01:00
}
2013-01-22 22:48:58 +01:00
$sitedomain1 = preg_split ( '/\//' , $siteurl , 0 );
$sitedomain2 = $sitedomain1 [ 2 ];
$sitedomain3 = explode ( " . " , $sitedomain2 );
$sitedomain3 = array_reverse ( $sitedomain3 );
$sitedomain = $sitedomain3 [ 1 ] . '.' . $sitedomain3 [ 0 ];
2013-01-30 22:28:19 +01:00
if ( ! file_exists ( $foldername ) && ! file_exists ( $foldername2 )) {
2013-01-22 22:48:58 +01:00
if ( mkdir ( './' . $foldername , 0755 , false ) ) {
$fp = fopen ( './' . $foldername . '/index.php' , 'w+' );
2013-01-23 23:15:16 +01:00
2013-01-30 21:40:34 +01:00
$response = get_headers ( $rssurl , 1 ); // check for redirections
if ( ! empty ( $response [ 'Location' ])) {
$result = " false " ;
} else {
$xml = simplexml_load_file ( $rssurl ); // quick feed check
2013-01-30 22:28:19 +01:00
if ( $xml === FALSE ){
$result = " false " ;
} elseif ( isset ( $xml -> entry )) { // ATOM feed.
2013-01-30 21:40:34 +01:00
$result = " true " ;
} elseif ( isset ( $xml -> item )) { // RSS 1.0 /RDF
$result = " true " ;
} elseif ( isset ( $xml -> channel -> item )) { // RSS 2.0
$result = " true " ;
} else {
$result = " false " ;
}
}
2013-01-24 11:20:23 +01:00
2013-01-30 21:40:34 +01:00
/* autoblog */
if ( $social == FALSE and $result !== " false " ) {
if ( ! fwrite ( $fp , " <?php require_once dirname(__DIR__) . '/autoblog.php'; ?> " ) ) {
$infos = " \n Impossible d'écrire le fichier index.php dans " . $foldername ;
fclose ( $fp );
} else {
fclose ( $fp );
$fp = fopen ( './' . $foldername . '/vvb.ini' , 'w+' );
if ( ! fwrite ( $fp , ' [ VroumVroumBlogConfig ]
2013-01-22 22:48:58 +01:00
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_URL = " '. $siteurl .' "
FEED_URL = " '. $rssurl .' "
DOWNLOAD_MEDIA_FROM = ' . $sitedomain ) ){
2013-01-30 21:40:34 +01:00
fclose ( $fp );
$infos = " \n Impossible d'écrire le fichier vvb.ini dans " . $foldername ;
} else {
fclose ( $fp );
2013-01-30 22:28:19 +01:00
$infos = " \n autoblog crée avec succès : $foldername " ;
2013-01-30 21:40:34 +01:00
$to_update [] = serverUrl () . preg_replace ( " /(.*) \ /(.*) $ /i " , " $ 1/ " . $foldername , $_SERVER [ 'SCRIPT_NAME' ]); // url of the new autoblog
}
2013-01-22 22:48:58 +01:00
}
}
2013-01-30 21:40:34 +01:00
/* automicroblog */
else if ( $social !== FALSE and $result !== " false " ){
if ( ! fwrite ( $fp , " <?php require_once dirname(__DIR__) . '/automicroblog.php'; ?> " ) ){
$infos = " \n Impossible d'écrire le fichier index.php dans " . $foldername ;
fclose ( $fp );
} else {
fclose ( $fp );
$fp = fopen ( './' . $foldername . '/vvb.ini' , 'w+' );
if ( ! fwrite ( $fp , ' [ VroumVroumBlogConfig ]
2013-01-23 23:15:16 +01:00
SITE_TITLE = " '. $sitename .' "
SITE_DESCRIPTION = " AutoMicroblog automatisé de "
SITE_URL = " '. $siteurl .' "
FEED_URL = " '. $rssurl .' " ' ) ){
2013-01-30 21:40:34 +01:00
fclose ( $fp );
$infos = " \n Impossible d'écrire le fichier vvb.ini dans " . $foldername ;
} else {
fclose ( $fp );
2013-01-30 22:28:19 +01:00
$infos = " \n automicroblog crée avec succès : $foldername " ;
2013-01-30 21:40:34 +01:00
$to_update [] = serverUrl () . preg_replace ( " /(.*) \ /(.*) $ /i " , " $ 1/ " . $foldername , $_SERVER [ 'SCRIPT_NAME' ]); // url of the new autoblog
}
2013-01-23 23:15:16 +01:00
}
2013-01-30 21:40:34 +01:00
} else {
$infos = " \n $rssurl -> flux invalide " ;
2013-01-23 23:15:16 +01:00
}
2013-01-30 21:40:34 +01:00
/* end of file writing */
2013-01-22 22:48:58 +01:00
} else {
2013-01-28 12:29:45 +01:00
$infos = " \n Impossible de créer le répertoire " . $foldername ;
2013-01-22 22:48:58 +01:00
}
2013-01-30 21:40:34 +01:00
} else {
/*$infos = "\nFin d'itération ou Le répertoire ".$foldername." existe déjà ($sitename;$siteurl;$rssurl)";*/
}
if ( DEBUG ){
echo $infos ;
}
2013-01-22 22:48:58 +01:00
}
2013-01-30 22:28:19 +01:00
echo " \n time : " . ( time () - $max_exec_time );
if ( time () >= $max_exec_time ){
break ;
}
2013-01-22 22:48:58 +01:00
}
2013-01-28 12:29:45 +01:00
/* if ( ! empty ( $to_update )){
2013-01-30 21:40:34 +01:00
if ( DEBUG ){
echo " \n update of autoblogs ... " ;
}
2013-01-22 22:48:58 +01:00
// because it's could be very long, we finish by updating new autoblogs
foreach ( $to_update as $url ) {
2013-01-28 12:29:45 +01:00
get_headers ( $url );
2013-01-22 22:48:58 +01:00
}
2013-01-30 21:40:34 +01:00
if ( DEBUG ){
echo " done \n \n " ;
}
2013-01-28 12:29:45 +01:00
} */
2013-01-22 22:48:58 +01:00
}
2013-01-30 22:28:19 +01:00
return ;
2013-01-22 22:48:58 +01:00
}
2013-01-30 22:28:19 +01:00
/* And now, the XSAF links to be imported, with maximal execusion time for import in second ! */
xsafimport ( 'https://raw.github.com/mitsukarenai/xsaf-bootstrap/master/2.json' , 5 );
//xsafimport('https://www.ecirtam.net/autoblogs/?export', 5);
//xsafimport('https://autoblog.suumitsu.eu/?export', 5);
2013-01-24 11:20:23 +01:00
2013-01-30 21:40:34 +01:00
if ( DEBUG ) {
echo " \n \n XSAF import finished \n \n " ;
}
2013-01-28 12:29:45 +01:00
die ;
2013-01-22 22:48:58 +01:00
?>