Mise à jour de l'import xsaf
modified: xsaf3.php
This commit is contained in:
parent
9f42a07a85
commit
968f1d6a6f
1 changed files with 77 additions and 62 deletions
|
@ -2,6 +2,8 @@
|
||||||
/* modtime 2013-02-04 */
|
/* modtime 2013-02-04 */
|
||||||
|
|
||||||
define('DEBUG', true);
|
define('DEBUG', true);
|
||||||
|
define('XSAF_VERSION', 3);
|
||||||
|
define('AUTOBLOG_FILE_NAME', 'autoblog-0.3.php');
|
||||||
|
|
||||||
header("HTTP/1.0 403 Forbidden"); /* Uncivilized method to prevent bot indexing, huh :) */
|
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('X-Robots-Tag: noindex'); /* more civilized method, but bots may not all take into account */
|
||||||
|
@ -46,83 +48,96 @@ function xsafimport($xsafremote, $max_exec_time) {
|
||||||
$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, true) as $value) {
|
$json_import = json_decode($json_import, true);
|
||||||
$infos="";
|
|
||||||
if(count($value)==3 && !empty($value['SITE_TYPE']) && !empty($value['SITE_TITLE']) && !empty($value['SITE_URL']) && !empty($value['FEED_URL'])) {
|
|
||||||
$sitetype = $value['SITE_TYPE'];
|
|
||||||
$sitename = $value['SITE_TITLE'];
|
|
||||||
$siteurl = escape($value['SITE_URL']);
|
|
||||||
$rssurl = escape($value['FEED_URL']);
|
|
||||||
|
|
||||||
$foldername = $sitename;$foldername2 = $sitename;
|
if(!isset($json_import['meta']) || !isset($json_import['meta']['xsaf-version']) || $json_import['meta']['xsaf-version'] != XSAF_VERSION){
|
||||||
|
if(DEBUG){
|
||||||
|
echo "\nxsaf-version différentes !";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!empty($json_import['autoblogs'])) {
|
||||||
|
foreach ($json_import['autoblogs'] as $value) {
|
||||||
|
$infos="";
|
||||||
|
if(count($value)==4 && !empty($value['SITE_TYPE']) && !empty($value['SITE_TITLE']) && !empty($value['SITE_URL']) && !empty($value['FEED_URL'])) {
|
||||||
|
$sitetype = $value['SITE_TYPE'];
|
||||||
|
$sitename = $value['SITE_TITLE'];
|
||||||
|
$siteurl = escape($value['SITE_URL']);
|
||||||
|
$rssurl = escape($value['FEED_URL']);
|
||||||
|
|
||||||
if(!file_exists($foldername) && !file_exists($foldername2)) {
|
$foldername = $sitename;$foldername2 = $sitename;
|
||||||
if ( mkdir('./'. $foldername, 0755, false) ) {
|
|
||||||
$fp = fopen('./'. $foldername .'/index.php', 'w+');
|
|
||||||
|
|
||||||
$response = get_headers($rssurl, 1); // check for redirections
|
if(!file_exists($foldername) && !file_exists($foldername2)) {
|
||||||
if(!empty($response['Location'])) {
|
if ( mkdir('./'. $foldername, 0755, false) ) {
|
||||||
$result="false";
|
$fp = fopen('./'. $foldername .'/index.php', 'w+');
|
||||||
}else{
|
|
||||||
$xml = simplexml_load_file($rssurl); // quick feed check
|
|
||||||
|
|
||||||
if($xml === FALSE){
|
$response = get_headers($rssurl, 1); // check for redirections
|
||||||
|
if(!empty($response['Location'])) {
|
||||||
$result="false";
|
$result="false";
|
||||||
}elseif (isset($xml->entry)) { // ATOM feed.
|
|
||||||
$result="true";
|
|
||||||
}elseif (isset($xml->item)) { // RSS 1.0 /RDF
|
|
||||||
$result="true";
|
|
||||||
}elseif (isset($xml->channel->item)) { // RSS 2.0
|
|
||||||
$result="true";
|
|
||||||
}else{
|
}else{
|
||||||
$result="false";
|
$xml = simplexml_load_file($rssurl); // quick feed check
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* autoblog */
|
if($xml === FALSE){
|
||||||
if($result!=="false") {
|
$result="false";
|
||||||
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/autoblog.php'; ?>") ) {
|
}elseif (isset($xml->entry)) { // ATOM feed.
|
||||||
$infos = "\nImpossible d'écrire le fichier index.php dans ".$foldername;
|
$result="true";
|
||||||
fclose($fp);
|
}elseif (isset($xml->item)) { // RSS 1.0 /RDF
|
||||||
}else{
|
$result="true";
|
||||||
fclose($fp);
|
}elseif (isset($xml->channel->item)) { // RSS 2.0
|
||||||
$fp = fopen('./'. $foldername .'/vvb.ini', 'w+');
|
$result="true";
|
||||||
if( !fwrite($fp, '[VroumVroumBlogConfig]
|
}else{
|
||||||
|
$result="false";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* autoblog */
|
||||||
|
if($result!=="false") {
|
||||||
|
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/".AUTOBLOG_FILE_NAME."'; ?>") ) {
|
||||||
|
$infos = "\nImpossible d'écrire le fichier index.php dans ".$foldername;
|
||||||
|
fclose($fp);
|
||||||
|
}else{
|
||||||
|
fclose($fp);
|
||||||
|
$fp = fopen('./'. $foldername .'/vvb.ini', 'w+');
|
||||||
|
if( !fwrite($fp, '[VroumVroumBlogConfig]
|
||||||
SITE_TYPE="'. $sitetype .'"
|
SITE_TYPE="'. $sitetype .'"
|
||||||
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 .'"') ){
|
||||||
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);
|
||||||
/* ============================================================================================================================================================================== */
|
/* ============================================================================================================================================================================== */
|
||||||
/* récupération de la DB distante */ $remote_db=str_replace("?export", $foldername."/articles.db", $xsafremote); copy($remote_db, './'. $foldername .'/articles.db');
|
/* récupération de la DB distante */ $remote_db=str_replace("?export", $foldername."/articles.db", $xsafremote); copy($remote_db, './'. $foldername .'/articles.db');
|
||||||
/* ============================================================================================================================================================================== */
|
/* ============================================================================================================================================================================== */
|
||||||
$infos = "\nautoblog crée avec succès : $foldername";
|
|
||||||
$to_update[]=serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
|
//TODO : tester si articles.db est une DB valide
|
||||||
|
|
||||||
|
$infos = "\nautoblog crée avec succès : $foldername";
|
||||||
|
$to_update[]=serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$infos = "\n$rssurl -> flux invalide";
|
||||||
}
|
}
|
||||||
} else {
|
/* end of file writing */
|
||||||
$infos = "\n$rssurl -> flux invalide";
|
}else {
|
||||||
|
$infos = "\nImpossible de créer le répertoire ".$foldername;
|
||||||
}
|
}
|
||||||
/* end of file writing */
|
} else {
|
||||||
}else {
|
/*$infos = "\nFin d'itération ou Le répertoire ".$foldername." existe déjà ($sitename;$siteurl;$rssurl)";*/
|
||||||
$infos = "\nImpossible de créer le répertoire ".$foldername;
|
}
|
||||||
|
if(DEBUG){
|
||||||
|
echo $infos;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
/*$infos = "\nFin d'itération ou Le répertoire ".$foldername." existe déjà ($sitename;$siteurl;$rssurl)";*/
|
echo "\n time : ".(time() - $max_exec_time);
|
||||||
}
|
if(time() >= $max_exec_time){
|
||||||
if(DEBUG){
|
break;
|
||||||
echo $infos;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "\n time : ".(time() - $max_exec_time);
|
|
||||||
if(time() >= $max_exec_time){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*if(!empty($to_update)){
|
/*if(!empty($to_update)){
|
||||||
if(DEBUG){
|
if(DEBUG){
|
||||||
echo "\nupdate of autoblogs ...";
|
echo "\nupdate of autoblogs ...";
|
||||||
|
@ -140,7 +155,7 @@ FEED_URL="'. $rssurl .'"') ){
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And now, the XSAF links to be imported, with maximal execusion time for import in second ! */
|
/* 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://raw.github.com/mitsukarenai/xsaf-bootstrap/master/3.json', 5);
|
||||||
//xsafimport('https://www.ecirtam.net/autoblogs/?export', 5);
|
//xsafimport('https://www.ecirtam.net/autoblogs/?export', 5);
|
||||||
//xsafimport('https://autoblog.suumitsu.eu/?export', 5);
|
//xsafimport('https://autoblog.suumitsu.eu/?export', 5);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue