Merge branch 'master' into myAutoBlog

Conflicts:
	.gitignore
	docs/docs.txt
	functions.php
	index.php
	xsaf3.php
This commit is contained in:
Knah Tsaeb 2013-04-30 12:04:03 +02:00
commit 3e3861ee87
28 changed files with 390 additions and 2832 deletions

15
.gitignore vendored Normal file → Executable file
View file

@ -1,8 +1,9 @@
0.3/config.php
0.3/.versionlock
0.3/.xsaflock
0.3/resources/rss.xml
config.php
.versionlock
.xsaflock
resources/rss.xml
resources/rss.json
.project
!0.3/resources/user.css
0.3/autoblogs/*
!0.3/autoblogs/autoblog.php
resources/user.css
autoblogs/*
!autoblogs/autoblog.php

View file

@ -1,20 +0,0 @@
Projet Autoblog serie 0.1
==============
- version VroumVroumBlog 0.1.32
Auteur: Sebastien Sauvage
Licence: Domaine Public
- À propos du Projet Autoblog
lire: http://sebsauvage.net/streisand.me/fr/
- Contraintes techniques
voir: http://sebsauvage.net/streisand.me/fr/tech.html
- Instructions
Personnalisez vvb.ini. Envoyez index.php et vvb.ini sur votre site web, dans le répertoire de votre choix. Terminé !

View file

@ -1,403 +0,0 @@
<?php
/* VroumVroumBlog 0.1.32
This blog automatically publishes articles from an external RSS 2.0, RSS 1.0/RDF or ATOM feed.
For more information, see: http://sebsauvage.net/steisand.me/
This program is public domain. COPY COPY COPY !
*/
// ==================================================================================================
// Settings:
error_reporting(0); // Fail silentely.
if (!get_cfg_var('safe_mode')) { set_time_limit(240); } // More time to download (images, source feed)
date_default_timezone_set('Europe/Paris');
if (version_compare(PHP_VERSION, '5.2.0') >= 0) { libxml_disable_entity_loader(true); }
$CONFIG=parse_ini_file('vvb.ini') or die('Missing or bad config file vvb.ini'); // Read config file.
$CONFIG['ARTICLES_PER_PAGE']=10;
$CONFIG['DOWNLOAD_MEDIA_TYPES']=array('jpeg','jpg','gif','png','pdf','txt','odt'); // Media types which will be downloaded.
$CONFIG['MEDIA_TO_DOWNLOAD']=array(); // List of media to download in background.
// ==================================================================================================
/* Callback for the preg_replace_callback() function in remapImageUrls() which remaps URLs to point to local cache.
(src=... and href=...) */
function remap_callback($matches)
{
global $CONFIG;
$attr = $matches[1]; $url = $matches[2]; $srchost=parse_url($url,PHP_URL_HOST);
if (!mediaAuthorized($url)) { return $attr.'="'.$url.'"'; } // Not authorized: do not remap URL.
if (!file_exists('media/'.sanitize($url)) ) { $CONFIG['MEDIA_TO_DOWNLOAD'][] = $url; } // If media not present in the cache, add URL to list of media to download in background.
return $attr.'="?m='.$url.'"'; // Return remapped URL.
}
/* Remaps image URL to point to local cache (src= and href=)
eg. src="http://toto.com/..." --> src="?m=http://toto.com/..."
*/
function remapImageUrls($html)
{
return preg_replace_callback("@(src|href)=[\"\'](.+?)[\"\']@i",'remap_callback',$html);
}
/* updateFeed(): Update articles database from a RSS2.0 feed.
Articles deleted from the feed are not deleted from the database.
You can force the refresh by passing ?force_the_refresh in URL.
*/
function updateFeed()
{
global $CONFIG;
// Only update feed if last check was > 60 minutes
// but you can force it with force_the_refresh in GET parameters.
if (@filemtime('store')>time()-(3600) && !isset($_GET['force_the_refresh'])) { return; }
// Read database from disk
$feed_items=(file_exists('store') ? unserialize(file_get_contents('store')) : array() );
// Read the feed and update the database.
$xml = simplexml_load_file($CONFIG['FEED_URL']);
if (isset($xml->entry)) // ATOM feed.
{
foreach ($xml->entry as $item)
{
$pubDate=$item->published; if (!$pubDate) { $pubDate=$item->updated; }
$i=array('title'=>strval($item->title),'link'=>strval($item->link['href']),'guid'=>strval($item->id),'pubDate'=>strval($pubDate),
'description'=>'','content'=>remapImageUrls(strval($item->content)));
$i['dateiso'] = date('Ymd_His', strtotime($i['pubDate']));
$feed_items[$i['dateiso']] = $i;
}
}
elseif (isset($xml->item)) // RSS 1.0 /RDF
{
foreach ($xml->item as $item)
{
$guid =$item->attributes('http://www.w3.org/1999/02/22-rdf-syntax-ns#')->about;
$date =$item->children('http://purl.org/dc/elements/1.1/')->date;
$content = $item->children('http://purl.org/rss/1.0/modules/content/');
$i=array('title'=>strval($item->title),'link'=>strval($item->link),'guid'=>strval($guid),'pubDate'=>strval($date),
'description'=>strval($item->description),'content'=>remapImageUrls(strval($content)));
$i['dateiso'] = date('Ymd_His', strtotime($i['pubDate']));
$feed_items[$i['dateiso']] = $i;
}
}
elseif (isset($xml->channel->item)) // RSS 2.0
{
foreach ($xml->channel->item as $item)
{
$content = strval($item->children('http://purl.org/rss/1.0/modules/content/')); // Get <content:encoded>
if (!$content) { $content = strval($item->description); } // Some feeds put content in the description.
$pubDate = $item->pubDate;
if (!$pubDate) { $pubDate=$item->children('http://purl.org/dc/elements/1.1/')->date; } // To read the <dc:date> tag content.
$i=array('title'=>strval($item->title),'link'=>strval($item->link),'guid'=>strval($item->guid),'pubDate'=>strval($pubDate),
'description'=>strval($item->description),'content'=>remapImageUrls($content));
$i['dateiso'] = date('Ymd_His', strtotime($i['pubDate']));
$feed_items[$i['dateiso']] = $i;
}
}
krsort($feed_items); // Sort array, latest articles first.
file_put_contents('store', serialize($feed_items)); // Write database to disk
}
/* feed(): Returns the feed as an associative array (latest articles first).
Key is timestamp in compact iso format (eg. '20110628_073208')
Value is an associative array (title,link,content,pubDate...)
*/
function feed()
{
$data=file_get_contents('store');
if ($data===FALSE) { $feed_items=array(); } else { $feed_items = unserialize($data); }
return $feed_items;
}
/* Remove accents (é-->e) */
function replace_accents($str) {
$str = htmlentities($str, ENT_COMPAT, "UTF-8");
$str = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',$str);
return html_entity_decode($str);
}
// Sanitize strings for use in filename or URLs
function sanitize($name)
{
$fname=replace_accents($name);
$replace="_";
$pattern="/([[:alnum:]_\.-]*)/"; // The autorized characters.
$fname=str_replace(str_split(preg_replace($pattern,$replace,$fname)),$replace,$fname);
return $fname;
}
// Tells if a string start with a substring or not.
function startsWith($haystack,$needle,$case=true) {
if($case){return (strcmp(substr($haystack, 0, strlen($needle)),$needle)===0);}
return (strcasecmp(substr($haystack, 0, strlen($needle)),$needle)===0);
}
// Tells if a string ends with a substring or not.
function endsWith($haystack,$needle,$case=true) {
if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
}
/* Returns the CSS stylesheet to include in HTML document */
function css()
{
return <<<HTML
<style type="text/css">
<!--
body { font-family:"Trebuchet MS",Verdana,Arial,Helvetica,sans-serif; font-size:10pt; background-color: #3E4B50; }
img { max-width: 100%;height: auto; }
h1 { margin: 0 0 0 0; font-size:24pt; text-shadow: 2px 2px 2px #000; /* FF3.5+, Opera 9+, Saf1+, Chrome */ }
.pagetitle
{
padding: 10 30 10 30;
color:#eee;
margin-left:10%;
margin-right:10%;
border-bottom: 1px solid #aaa;
background-color: #6A6A6A;
background-image: -webkit-gradient(linear, left top, left bottom, from(#6A6A6A), to(#303030)); /* Saf4+, Chrome */
background-image: -webkit-linear-gradient(top, #6A6A6A, #303030); /* Chrome 10+, Saf5.1+ */
background-image: -moz-linear-gradient(top, #6A6A6A, #303030); /* FF3.6 */
background-image: -ms-linear-gradient(top, #6A6A6A, #303030); /* IE10 */
background-image: -o-linear-gradient(top, #6A6A6A, #303030); /* Opera 11.10+ */
background-image: linear-gradient(top, #6A6A6A, #303030);
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#6A6A6A', EndColorStr='#303030'); /* IE6-IE9 */
}
.pagetitle a:link { color:#bbb; text-decoration:none;}
.pagetitle a:visited { color:#bbb; text-decoration:none;}
.pagetitle a:hover { color:#FFFFC9; text-decoration:none;}
.pagetitle a:active { color:#bbb; text-decoration:none;}
h2 { font-size:22pt; margin:0 0 0 0; color:#666; text-shadow: 1px 1px 1px #fff; /* FF3.5+, Opera 9+, Saf1+, Chrome */ }
h2 a:link { color:#666; text-decoration:none;}
h2 a:visited { color:#666; text-decoration:none;}
h2 a:hover { color:#403976; text-decoration:none;}
h2 a:active { color:#666; text-decoration:none;}
.datearticle { font-size: 8pt; color:#666; }
.pagination
{
margin-left:10%;
margin-right:10%;
padding: 5 10 5 10;
background-color: #6A6A6A;
background-image: -webkit-gradient(linear, left top, left bottom, from(#6A6A6A), to(#303030)); /* Saf4+, Chrome */
background-image: -webkit-linear-gradient(top, #6A6A6A, #303030); /* Chrome 10+, Saf5.1+ */
background-image: -moz-linear-gradient(top, #6A6A6A, #303030); /* FF3.6 */
background-image: -ms-linear-gradient(top, #6A6A6A, #303030); /* IE10 */
background-image: -o-linear-gradient(top, #6A6A6A, #303030); /* Opera 11.10+ */
background-image: linear-gradient(top, #6A6A6A, #303030);
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#6A6A6A', EndColorStr='#303030'); /* IE6-IE9 */
}
.pagination a:link { color:#ccc; text-decoration:none;}
.pagination a:visited { color:#ccc; text-decoration:none;}
.pagination a:hover { color:#FFFFC9; text-decoration:none;}
.pagination a:active { color:#ccc; text-decoration:none;}
.anciens { float:left; }
.recents { float:right; }
.article
{
margin-left:10%;
margin-right:10%;
padding:10 15 10 15;
background-color: #cccccc;
background-image: -webkit-gradient(linear, left top, left bottom, from(#cccccc), to(#ffffff)); /* Saf4+, Chrome */
background-image: -webkit-linear-gradient(top, #cccccc, #ffffff); /* Chrome 10+, Saf5.1+ */
background-image: -moz-linear-gradient(top, #cccccc, #ffffff); /* FF3.6 */
background-image: -ms-linear-gradient(top, #cccccc, #ffffff); /* IE10 */
background-image: -o-linear-gradient(top, #cccccc, #ffffff); /* Opera 11.10+ */
background-image: linear-gradient(top, #cccccc, #ffffff);
filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#cccccc', EndColorStr='#ffffff'); /* IE6-IE9 */
border-bottom: 1px solid #888;
}
.search { float:right; }
.search input { border:1px solid black; color:#666; }
.powered { width:100%; text-align:center; font-size:8pt; color:#aaaaaa; }
.powered a:link { color:#cccccc; text-decoration:none;}
.powered a:visited { color:#cccccc; text-decoration:none;}
.powered a:hover { color:#FFFFC9; text-decoration:none;}
.powered a:active { color:#aaaaaa; text-decoration:none;}
.sourcelink a { color:#666; text-decoration:none; }
.sourcelink a:hover { color:#403976; text-decoration:none; }
@media handheld
{
html, body { font: 12px sans-serif; background: #fff; padding: 3px; color: #000; margin: 0; }
img { max-width: 100%;height: auto; }
.pagetitle { padding: 7 7 7 7; margin-left:0; margin-right:0; }
.article { background-color: #eee; margin-left:0; margin-right:0; border-bottom: 3px solid #888; }
.pagination { margin-left:0; margin-right:0;}
h1 { font-size:16pt; margin-bottom:10px;}
h2 { font-size:14pt; line-height:120%; }
ul { padding-left:10px; }
blockquote{margin-left:12px; margin-right:3px; }
pre { width:100%; overflow:auto; }
}
-->
</style>
HTML;
}
/* Render a single article
$article : the article itself (associative array with title,pubDate,content,dateiso keys.)
*/
function renderArticle($article)
{
echo '<div class="article">';
echo '<div class="articletitle"><h2><a href="?'.$article['dateiso'].'_'.sanitize($article['title']).'">'.$article['title'].'</a></h2><div class="datearticle">'.$article['pubDate'];
if ($article['link']!='') { echo ' - <span class="sourcelink">(<a href="'.$article['link'].'">source</a>)</span>'; }
echo '</div></div><div class="articlecontent">'.$article['content'].'</div>';
echo '<br style="clear:both;"></div>';
}
function rssHeaderLink() { return '<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="?feed">'; }
function searchForm() { return '<div class="search"><form method="GET"><input type="text" name="s"><input type="submit" value="search"></form></div>'; }
function powered() { return '<div class="powered">Powered by <a href="http://sebsauvage.net/streisand.me/">VroumVroumBlog</a> 0.1.32 - <a href="?feed">RSS Feed</a><br>Download <a href="vvb.ini">config</a> <a href="store">articles</a></div>'; }
function canonical_metatag($url) { return '<link rel="canonical" href="'.$url.'" />'; }
/* Show a single article
$articleid = article identifier (eg.'20110629_010334')
*/
function showArticle($articleid)
{
global $CONFIG;
header('Content-Type: text/html; charset=utf-8');
$feed=feed();if (!array_key_exists($articleid,$feed)) { die('Article not found.'); }
$a=$feed[$articleid];
echo '<html><head><title>'.$a['title'].' - '.$CONFIG['SITE_TITLE'].'</title>'.canonical_metatag($a['link']).css().rssHeaderLink().'</head><body>';
echo '<div class="pagetitle"><h1>'.$CONFIG['SITE_TITLE'].'</h1>'.$CONFIG['SITE_DESCRIPTION'].searchForm().'</div>';
renderArticle($a);
echo '<div class="pagination"><table width="100%"><tr><td><a href="?page1">See all articles</a></td></tr></table></div>'.powered().'</body></html>';
}
/* Show a list of articles, starting at a specific page.
$page = start page. First page is page 1.
*/
function showArticles($page)
{
global $CONFIG;
header('Content-Type: text/html; charset=utf-8');
$feed=feed();
$keys=array_keys($feed);
echo '<html><head><title>'.$CONFIG['SITE_TITLE'].'</title>'.canonical_metatag($CONFIG['SITE_URL']).css().rssHeaderLink().'</head><body>';
echo '<div class="pagetitle"><h1>'.$CONFIG['SITE_TITLE'].'</h1>'.$CONFIG['SITE_DESCRIPTION'].searchForm().'</div>';
$i = ($page-1)*$CONFIG['ARTICLES_PER_PAGE']; // Start index.
$end = $i+$CONFIG['ARTICLES_PER_PAGE'];
while ($i<$end && $i<count($keys))
{
renderArticle($feed[$keys[$i]]);
$i++;
}
echo '<div class="pagination"><table width="100%"><tr><td>';
if ($i!=count($keys)) { echo '<div class="anciens"><a href="?page'.($page+1).'">&lt; Older</a></div>'; }
echo '</td><td>';
if ($page>1) { echo '<div class="recents"><a href="?page'.($page-1).'">Newer &gt;</a></div>'; }
echo '</td></tr></table></div>'.powered().'</body></html>';
}
/* Search for text in articles content and title.
$textpage = text to search.
*/
function search($text)
{
global $CONFIG;
header('Content-Type: text/html; charset=utf-8');
$txt = urldecode($text);
echo '<html><head><title>'.$CONFIG['SITE_TITLE'].'</title>'.css().rssHeaderLink().'</head><body>';
echo '<div class="pagetitle"><h1>'.$CONFIG['SITE_TITLE'].'</h1>'.$CONFIG['SITE_DESCRIPTION'].searchForm().'</div>';
echo '<div class="pagetitle">Search for <span style="font-weight:bold;color:#FFFFC9;">'.htmlspecialchars($txt).'</span> :</div>';
$feed=feed();
foreach($feed as $article)
{
if (stripos($article['content'],$txt) || stripos($article['title'],$txt)) { renderArticle($article); }
}
echo '<div class="pagination"><table width="100%"><tr><td><a href="?page1">See all articles</a></td></tr></table></div>'.powered().'</body></html>';
}
/* Tells if a media URL should be downloaded or not.
Input: $url = absolute URL of a media (jpeg,pdf...)
Output: true= can download. false= should not download (wrong host, wrong file extension) */
function mediaAuthorized($url)
{
global $CONFIG;
$goodhost=false; $srchost=parse_url($url,PHP_URL_HOST);
foreach( explode(',',$CONFIG['DOWNLOAD_MEDIA_FROM']) as $host) // Does the URL point to an authorized host ?
{ if ($srchost==$host) { $goodhost=true; } }
if (!$goodhost) { return false; } // Wrong host.
$ext = pathinfo($url, PATHINFO_EXTENSION); // Get file extension (eg.'png','gif'...)
if (!in_array(strtolower($ext),$CONFIG['DOWNLOAD_MEDIA_TYPES'])) { return false; } // Not in authorized file extensions.
return true;
}
// Returns the MIME type corresponding to a file extension.
// (I do not trust mime_content_type() because of some dodgy hosting providers with ill-configured magic.mime file.)
function mime_type($filename)
{
$MIME_TYPES=array('.jpg'=>'image/jpeg','.jpeg'=>'image/jpeg','.png'=>'image/png','.gif'=>'image/gif',
'.txt'=>'text/plain','.odt'=>'application/vnd.oasis.opendocument.text');
foreach($MIME_TYPES as $extension=>$mime_type) { if (endswith($filename,$extension,false)) { return $mime_type; } }
return 'application/octet-stream'; // For an unkown extension.
}
// Returns a media from the local cache (and download it if not available).
function showMedia($imgurl)
{
if (!mediaAuthorized($imgurl)) { header('HTTP/1.1 404 Not Found'); return; }
downloadMedia($imgurl); // Will only download if necessary.
$filename = 'media/'.sanitize($imgurl);
header('Content-Type: '.mime_type($filename));
readfile($filename);
}
// Download a media to local cache (if necessary)
function downloadMedia($imgurl)
{
$filename = 'media/'.sanitize($imgurl);
if (!file_exists($filename) ) // Only download image if not present
{
if (!is_dir('media')) { mkdir('media',0705); file_put_contents('media/index.html',' '); }
file_put_contents($filename, file_get_contents($imgurl,NULL, NULL, 0, 4000000)); // We download at most 4 Mb from source.
}
}
/* Output the whole feed in RSS 2.0 format with article content (BIG!) */
function outputFeed()
{
global $CONFIG;
header('Content-Type: application/xhtml+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">';
echo '<channel><title>'.htmlspecialchars($CONFIG['SITE_TITLE']).'</title><link>'.htmlspecialchars($CONFIG['SITE_URL']).'</link>';
echo '<description></description><language></language><copyright>'.htmlspecialchars($CONFIG['SITE_URL']).'</copyright>'."\n\n";
$feed=feed();
foreach($feed as $a)
{
echo '<item><title>'.$a['title'].'</title><guid>'.$a['guid'].'</guid><link>http://'.$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"].'?'.$a['dateiso'].'_'.sanitize($a['title']).'</link><pubDate>'.$a['pubDate'].'</pubDate>';
echo '<description><![CDATA['.$a['description'].']]></description><content:encoded><![CDATA['.$a['content'].']]></content:encoded></item>'."\n\n";
}
echo '</channel></rss>';
}
// ==================================================================================================
// Update feed if necessary. (you can force refresh with ?force_the_refresh in URL)
updateFeed();
// Handle media download requests (eg. http://myserver.com/?m=http___anotherserver.net_images_myimage.jpg)
if (startswith($_SERVER["QUERY_STRING"],'m=')) { showMedia(substr($_SERVER["QUERY_STRING"],2)); }
// Handle single article URI (eg. http://myserver.com/?20110506_224455-chit-chat)
elseif (preg_match('/^(\d{8}_\d{6})/',$_SERVER["QUERY_STRING"],$matches)) { showArticle($matches[1]); }
// Handle page URI (eg. http://myserver.com/?page5)
elseif (preg_match('/^page(\d+)/',$_SERVER["QUERY_STRING"],$matches)) { showArticles($matches[1]); }
// Handle RSS 2.0 feed request (http://myserver.com/?feed)
elseif (startswith($_SERVER["QUERY_STRING"],'feed')) { outputFeed(); }
// Handle search request (eg. http://myserver.com/?s=tuto4pc)
elseif (startswith($_SERVER["QUERY_STRING"],'s=')) { search(substr($_SERVER["QUERY_STRING"],2)); }
// Nothing ? Then render page1.
else { showArticles(1); }
// Force flush, rendered page is fully sent to browser.
ob_end_flush();
flush();
// Now we've finised rendering the page and sending to the user,
// it's time for some background tasks: Are there media to download ?
foreach($CONFIG['MEDIA_TO_DOWNLOAD'] as $url) { downloadMedia($url); }
exit;
?>

View file

@ -1,6 +0,0 @@
[VroumVroumBlogConfig]
SITE_TITLE="Autoblog de Sebsauvage"
SITE_DESCRIPTION="Ce site n'est pas le site officiel de Sebsauvage<br>C'est un blog automatis&eacute; qui r&eacute;plique les articles de <a href="http://sebsauvage.net/rhaa/">sebsauvage.net</a>"
SITE_URL=http://sebsauvage.net/rhaa/
FEED_URL=http://sebsauvage.net/rhaa/rss_fulltext.php
DOWNLOAD_MEDIA_FROM=sebsauvage.net

View file

@ -1,24 +0,0 @@
Projet Autoblog serie 0.2
==============
- version VroumVroumBlog 0.2.11
Auteurs: BohwaZ (VVB) & Arthur Hoaro, Mitsukarenai, Oros (index ferme d'autoblogs)
Licence: Domaine Public
- À propos du Projet Autoblog
lire: http://sebsauvage.net/streisand.me/fr/
- Présentation et Instructions pour VVB 0.2 (par BohwaZ)
voir: http://blogs.kd2.org/bohwaz/?2011/07/14/369-auto-blog-vroumvroumblog-et-effet-streisand
- Présentation et Instructions pour la ferme d'autoblogs (par Arthur Hoaro)
voir: http://wiki.hoa.ro/doku.php?id=web%3Aferme-autoblog
- Améliorations pour la ferme d'autoblogs et XSAF (par Mitsukarenai et Oros)
voir: https://www.suumitsu.eu/2012/08/autoblogs-petites-ameliorations/

View file

@ -1,897 +0,0 @@
<?php
/*
VroumVroumBlog 0.2.11
This blog automatically publishes articles from an external RSS 2.0 or ATOM feed.
Installation:
- copy this script (index.php) to a directory on your webserver.
- optionnaly copy the database ('articles.db'). Otherwise, it will be created automatically.
- tweak setting in vvb.ini
Requirement for the source RSS feed:
- Source feed MUST be a valid RSS 2.0, RDF 1.0 or ATOM 1.0 feed.
- Source feed MUST be valid UTF-8
- Source feed MUST contain article body
- Only media from the hosts declared in DOWNLOAD_MEDIA_FROM= in vbb.ini will be downloaded.
This program is public domain. COPY COPY COPY !
*/
if (!version_compare(phpversion(), '5.3.0', '>='))
die("This software requires PHP version 5.3.0 at least, yours is ".phpversion());
if (!class_exists('SQLite3'))
die("This software requires the SQLite3 PHP extension, and it can't be found on this system!");
libxml_disable_entity_loader(true);
// Config and data file locations
if (file_exists(__DIR__ . '/config.php'))
{
require_once __DIR__ . '/config.php';
}
if (!defined('ROOT_DIR'))
define('ROOT_DIR', __DIR__);
if (!defined('CONFIG_FILE')) define('CONFIG_FILE', ROOT_DIR . '/vvb.ini');
if (!defined('ARTICLES_DB_FILE')) define('ARTICLES_DB_FILE', ROOT_DIR . '/articles.db');
if (!defined('LOCAL_DB_FILE')) define('LOCAL_DB_FILE', ROOT_DIR . '/local.db');
if (!defined('MEDIA_DIR')) define('MEDIA_DIR', ROOT_DIR . '/media');
if (!defined('LOCAL_URL'))
{
// Automagic URL discover
$path = substr(ROOT_DIR, strlen($_SERVER['DOCUMENT_ROOT']));
$path = (!empty($path[0]) && $path[0] != '/') ? '/' . $path : $path;
$path = (substr($path, -1) != '/') ? $path . '/' : $path;
define('LOCAL_URL', 'http' . (!empty($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $path);
}
if (!defined('LOCAL_URI'))
{
// filename
define('LOCAL_URI', (basename($_SERVER['SCRIPT_FILENAME']) == 'index.php' ? '' : basename($_SERVER['SCRIPT_FILENAME'])) . '?');
}
if (!function_exists('__'))
{
// Translation?
function __($str)
{
if ($str == '_date_format')
return '%A %e %B %Y at %H:%M';
else
return $str;
}
}
// ERROR MANAGEMENT
class VroumVroum_User_Exception extends Exception {}
class VroumVroum_Feed_Exception extends Exception
{
static public function getXMLErrorsAsString($errors)
{
$out = array();
foreach ($errors as $error)
{
$return = $xml[$error->line - 1] . "\n";
$return .= str_repeat('-', $error->column) . "^\n";
switch ($error->level) {
case LIBXML_ERR_WARNING:
$return .= "Warning ".$error->code.": ";
break;
case LIBXML_ERR_ERROR:
$return .= "Error ".$error->code.": ";
break;
case LIBXML_ERR_FATAL:
$return .= "Fatal Error ".$error->code.": ";
break;
}
$return .= trim($error->message) .
"\n Line: ".$error->line .
"\n Column: ".$error->column;
if ($error->file) {
$return .= "\n File: ".$error->file;
}
$out[] = $return;
}
return $out;
}
}
error_reporting(E_ALL);
function exception_error_handler($errno, $errstr, $errfile, $errline )
{
// For @ ignored errors
if (error_reporting() === 0) return;
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
function exception_handler($e)
{
if ($e instanceOf VroumVroum_User_Exception)
{
echo '<h3>'.$e->getMessage().'</h3>';
exit;
}
$error = "Error happened !\n\n".
$e->getCode()." - ".$e->getMessage()."\n\nIn: ".
$e->getFile() . ":" . $e->getLine()."\n\n";
if (!empty($_SERVER['HTTP_HOST']))
$error .= 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\n\n";
$error .= $e->getTraceAsString();
//$error .= print_r($_SERVER, true);
echo $error;
exit;
}
set_error_handler("exception_error_handler");
set_exception_handler("exception_handler");
// CONFIGURATION
class VroumVroum_Config
{
public $site_title = '';
public $site_description = '';
public $site_url = '';
public $feed_url = '';
public $download_media_from = null;
public $download_media_types = 'jpg,jpeg,png,gif,pdf';
public $articles_per_page = 10;
public $update_interval = 3600;
public $update_timeout = 10;
public function __construct()
{
if (!file_exists(CONFIG_FILE))
throw new VroumVroum_User_Exception("Missing configuration file '".basename(CONFIG_FILE)."'.");
$ini = parse_ini_file(CONFIG_FILE);
foreach ($ini as $key=>$value)
{
$key = strtolower($key);
if (!property_exists($this, $key))
continue; // Unknown config
if (is_string($this->$key) || is_null($this->$key))
$this->$key = trim((string) $value);
elseif (is_int($this->$key))
$this->$key = (int) $value;
elseif (is_bool($this->$key))
$this->$key = (bool) $value;
}
// Check that all required values are filled
$check = array('site_title', 'site_url', 'feed_url', 'update_timeout', 'update_interval', 'articles_per_page');
foreach ($check as $c)
{
if (!trim($this->$c))
throw new VroumVroum_User_Exception("Missing or empty configuration value '".$c."' which is required!");
}
// Default value
if (is_null($this->download_media_from))
{
$this->download_media_from = preg_replace('!^https?://([^/]+).*$!', '\\1', $this->site_url);
}
}
public function __set($key, $value)
{
return;
}
}
// BLOG
class VroumVroum_Blog
{
const VERSION = '0.2.11';
protected $articles = null;
protected $local = null;
public $config = null;
static public function removeHTML($str)
{
$str = strip_tags($str);
$str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
return $str;
}
static public function toURI($str)
{
$uri = self::removeHTML(trim($str));
$uri = substr($uri, 0, 70);
$uri = preg_replace('/[^\w\d()\p{L}]+/u', '-', $uri);
$uri = preg_replace('/-{2,}/', '-', $uri);
$uri = preg_replace('/^-|-$/', '', $uri);
return $uri;
}
public function __construct()
{
$this->config = new VroumVroum_Config;
$create_articles_db = file_exists(ARTICLES_DB_FILE) ? false : true;
$create_local_db = file_exists(LOCAL_DB_FILE) ? false : true;
$this->articles = new SQLite3(ARTICLES_DB_FILE);
$this->local = new SQLite3(LOCAL_DB_FILE);
if ($create_articles_db)
{
$this->articles->exec('
CREATE TABLE articles (
id INTEGER PRIMARY KEY,
feed_id TEXT,
title TEXT,
uri TEXT,
url TEXT,
date INT,
content TEXT
);
CREATE UNIQUE INDEX feed_id ON articles (feed_id);
CREATE INDEX date ON articles (date);
');
}
if ($create_local_db)
{
$this->local->exec('
CREATE VIRTUAL TABLE search USING fts3 (
id INT PRIMARY KEY,
title TEXT,
content TEXT
);
CREATE TABLE update_log (
date INT PRIMARY KEY,
success INT,
log TEXT
);');
}
$this->local->createFunction('countintegers', array($this, 'sql_countintegers'));
}
public function getLocalURL($in)
{
return LOCAL_URL . LOCAL_URI . (is_array($in) ? $in['uri'] : $in);
}
protected function log_update($success, $log = '')
{
$this->local->exec('INSERT INTO update_log (date, success, log) VALUES (\''.time().'\', \''.(int)(bool)$success.'\',
\''.$this->articles->escapeString($log).'\');');
// Delete old log
$this->local->exec('DELETE FROM update_log WHERE date > (SELECT date FROM update_log ORDER BY date DESC LIMIT 100,1);');
return true;
}
public function insertOrUpdateArticle($feed_id, $title, $url, $date, $content)
{
$exists = $this->articles->querySingle('SELECT date, id, title, content FROM articles WHERE feed_id = \''.$this->articles->escapeString($feed_id).'\';', true);
if (empty($exists))
{
$uri = self::toURI($title);
if ($this->articles->querySingle('SELECT 1 FROM articles WHERE uri = \''.$this->articles->escapeString($uri).'\';'))
{
$uri = date('Y-m-d-') . $uri;
}
if (!empty($this->config->download_media_from) && !empty($this->config->download_media_types))
$content = $this->mirrorMediasForArticle($content, $url);
$this->articles->exec('INSERT INTO articles (id, feed_id, title, uri, url, date, content) VALUES (NULL,
\''.$this->articles->escapeString($feed_id).'\', \''.$this->articles->escapeString($title).'\',
\''.$this->articles->escapeString($uri).'\', \''.$this->articles->escapeString($url).'\',
\''.(int)$date.'\', \''.$this->articles->escapeString($content).'\');');
$id = $this->articles->lastInsertRowId();
$title = self::removeHTML($title);
$content = self::removeHTML($content);
$this->local->exec('INSERT INTO search (id, title, content) VALUES (\''.(int)$id.'\',
\''.$this->local->escapeString($title).'\', \''.$this->local->escapeString($content).'\');');
}
else
{
// Doesn't need update
if ($date == $exists['date'] && $content == $exists['content'] && $title == $exists['title'])
{
return false;
}
$id = $exists['id'];
if ($content != $exists['content'] && !empty($this->config->download_media_from) && !empty($this->config->download_media_types))
$content = $this->mirrorMediasForArticle($content, $url);
$this->articles->exec('UPDATE articles SET title=\''.$this->articles->escapeString($title).'\',
url=\''.$this->articles->escapeString($url).'\', content=\''.$this->articles->escapeString($content).'\',
date=\''.(int)$date.'\' WHERE id = \''.(int)$id.'\';');
$title = self::removeHTML($title);
$content = self::removeHTML($content);
$this->local->exec('UPDATE search SET title=\''.$this->local->escapeString($title).'\',
content=\''.$this->local->escapeString($content).'\' WHERE id = \''.(int)$id.'\';');
}
return $id;
}
public function mustUpdate()
{
if (isset($_GET['update']))
return true;
$last_update = $this->local->querySingle('SELECT date FROM update_log ORDER BY date DESC LIMIT 1;');
if (!empty($last_update) && (int) $last_update > (time() - $this->config->update_interval))
return false;
return true;
}
protected function _getStreamContext()
{
return stream_context_create(
array(
'http' => array(
'method' => 'GET',
'timeout' => $this->config->update_timeout,
'header' => "User-Agent: Opera/9.80 (X11; Linux i686; U; fr) Presto/2.2.15 Version/10.10\r\n",
)
)
);
}
public function update()
{
if (!$this->mustUpdate())
return false;
try {
$body = file_get_contents($this->config->feed_url, false, $this->_getStreamContext());
}
catch (ErrorException $e)
{
$this->log_update(false, $e->getMessage() . "\n\n" . (!empty($http_response_header) ? implode("\n", $http_response_header) : ''));
throw new VroumVroum_Feed_Exception("Can't retrieve feed: ".$e->getMessage());
}
libxml_use_internal_errors(true);
$xml = @simplexml_load_string($body);
if (!$xml)
{
$errors = VroumVroum_Feed_Exception::getXMLErrorsAsString(libxml_get_errors());
$this->log_update(false, implode("\n", $errors) . "\n\n" . $body);
throw new VroumVroum_Feed_Exception("Feed is invalid - XML error: ".implode(" - ", $errors));
}
$updated = 0;
$this->local->exec('BEGIN TRANSACTION;');
$this->articles->exec('BEGIN TRANSACTION;');
if (isset($xml->entry)) // ATOM feed
{
foreach ($xml->entry as $item)
{
$date = isset($item->published) ? (string) $item->published : (string) $item->updated;
$guid = !empty($item->id) ? (string)$item->id : (string)$item->link['href'];
$id = $this->insertOrUpdateArticle($guid, (string)$item->title,
(string)$item->link['href'], strtotime($date), (string)$item->content);
if ($id !== false)
$updated++;
}
}
elseif (isset($xml->item)) // RSS 1.0 /RDF
{
foreach ($xml->item as $item)
{
$guid = (string) $item->attributes('http://www.w3.org/1999/02/22-rdf-syntax-ns#')->about ?: (string)$item->link;
$date = (string) $item->children('http://purl.org/dc/elements/1.1/')->date;
$id = $this->insertOrUpdateArticle($guid, (string)$item->title, (string)$item->link,
strtotime($date), (string) $item->children('http://purl.org/rss/1.0/modules/content/'));
if ($id !== false)
$updated++;
}
}
elseif (isset($xml->channel->item)) // RSS 2.0
{
foreach ($xml->channel->item as $item)
{
$content = (string) $item->children('http://purl.org/rss/1.0/modules/content/');
$guid = !empty($item->guid) ? (string) $item->guid : (string) $item->link;
if (empty($content) && !empty($item->description))
$content = (string) $item->description;
$id = $this->insertOrUpdateArticle($guid, (string)$item->title, (string)$item->link,
strtotime((string) $item->pubDate), $content);
if ($id !== false)
$updated++;
}
}
else
{
throw new VroumVroum_Feed_Exception("Unknown feed type?!");
}
$this->log_update(true, $updated . " elements updated");
$this->articles->exec('END TRANSACTION;');
$this->local->exec('END TRANSACTION;');
return $updated;
}
public function listArticlesByPage($page = 1)
{
$nb = $this->config->articles_per_page;
$begin = ($page - 1) * $nb;
$res = $this->articles->query('SELECT * FROM articles ORDER BY date DESC LIMIT '.(int)$begin.','.(int)$nb.';');
$out = array();
while ($row = $res->fetchArray(SQLITE3_ASSOC))
{
$out[] = $row;
}
return $out;
}
public function listLastArticles()
{
return array_merge($this->listArticlesByPage(1), $this->listArticlesByPage(2));
}
public function countArticles()
{
return $this->articles->querySingle('SELECT COUNT(*) FROM articles;');
}
public function getArticleFromURI($uri)
{
return $this->articles->querySingle('SELECT * FROM articles WHERE uri = \''.$this->articles->escapeString($uri).'\';', true);
}
public function sql_countintegers($in)
{
return substr_count($in, ' ');
}
public function searchArticles($query)
{
$res = $this->local->query('SELECT id, title, snippet(search, "<b>", "</b>", "...", -1, -40) AS snippet
FROM search
WHERE search MATCH \''.$this->local->escapeString($query).'\'
ORDER BY countintegers(offsets(search)) DESC
LIMIT 0,100;');
$out = array();
while ($row = $res->fetchArray(SQLITE3_ASSOC))
{
$row['url'] = $this->getLocalURL($this->articles->querySingle('SELECT uri FROM articles WHERE id = \''.(int)$row['id'].'\';'));
$out[] = $row;
}
return $out;
}
public function mirrorMediasForArticle($content, $url)
{
if (!file_exists(MEDIA_DIR))
{
mkdir(MEDIA_DIR);
}
$extensions = explode(',', preg_quote($this->config->download_media_types, '!'));
$extensions = implode('|', $extensions);
$hosts = explode(',', preg_quote($this->config->download_media_from, '!'));
$hosts = implode('|', $hosts);
$hosts = str_replace('\\*', '.*', $hosts);
$schemes = array('http', 'https');
$from = parse_url($url);
$from['path'] = preg_replace('![^/]*$!', '', $from['path']);
preg_match_all('!(src|href)\s*=\s*[\'"]?([^"\'<>\s]+\.(?:'.$extensions.'))[\'"]?!i', $content, $match, PREG_SET_ORDER);
foreach ($match as $m)
{
$url = parse_url($m[2]);
if (empty($url['scheme']))
$url['scheme'] = $from['scheme'];
if (empty($url['host']))
$url['host'] = $from['host'];
if (!in_array(strtolower($url['scheme']), $schemes))
continue;
if (!preg_match('!^(?:'.$hosts.')$!i', $url['host']))
continue;
if ($url['path'][0] != '/')
$url['path'] = $from['path'] . $url['path'];
$filename = basename($url['path']);
$url = $url['scheme'] . '://' . $url['host'] . $url['path'];
$filename = substr(sha1($url), -8) . '.' . substr(preg_replace('![^\w\d_.-]!', '', $filename), -64);
$copied = false;
if (!file_exists(MEDIA_DIR . '/' . $filename))
{
try {
$copied = $this->_copy($url, MEDIA_DIR . '/' . $filename);
}
catch (ErrorException $e)
{
// Ignore copy errors
}
}
if ($copied)
{
$content = str_replace($m[0], $m[1] . '="media/'.$filename.'" data-original-source="'.$url.'"', $content);
}
else
{
$content = str_replace($m[0], $m[1] . '="'.$url.'"', $content);
}
}
return $content;
}
/* copy() is buggy with http streams and safe_mode enabled (which is bad), so here's a workaround */
protected function _copy($from, $to)
{
$in = fopen($from, 'r', false, $this->_getStreamContext());
$out = fopen($to, 'w', false);
$size = stream_copy_to_stream($in, $out);
fclose($in);
fclose($out);
return $size;
}
}
// DISPLAY AND CONTROLLERS
$vvb = new VroumVroum_Blog;
$config = $vvb->config;
if (isset($_GET['feed'])) // FEED
{
header('Content-Type: application/xhtml+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>'.escape($config->site_title).'</title>
<link>'.escape($config->site_url).'</link>
<description>'.escape(html_entity_decode(strip_tags($config->site_description), ENT_COMPAT, 'UTF-8')).'</description>
<language></language>
<copyright></copyright>';
foreach($vvb->listLastArticles() as $art)
{
echo '
<item>
<title>'.escape($art['title']).'</title>
<guid>'.escape($art['feed_id']).'</guid>
<link>'.$vvb->getLocalURL($art).'</link>
<pubDate>'.date(DATE_RSS, $art['date']).'</pubDate>
<description>
<![CDATA['.escape_content($art['content']).']]>
</description>
<content:encoded>
<![CDATA['.escape_content($art['content']).']]>
</content:encoded>
</item>';
}
echo '
</channel>
</rss>';
exit;
}
if (isset($_GET['update']))
{
$_SERVER['QUERY_STRING'] = '';
}
// CONTROLLERS
$search = !empty($_GET['q']) ? trim($_GET['q']) : '';
$article = null;
if (!$search && !empty($_SERVER['QUERY_STRING']) && !is_numeric($_SERVER['QUERY_STRING']))
{
$uri = rawurldecode($_SERVER['QUERY_STRING']);
$article = $vvb->getArticleFromURI($uri);
if (!$article)
{
header('HTTP/1.1 404 Not Found', true, 404);
}
}
// HTML HEADER
echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>'.escape($config->site_title).'</title>
<link rel="canonical" href="'.escape($config->site_url).'" />
<link rel="alternate" type="application/rss+xml" title="'.__('RSS Feed').'" href="?feed" />
<style type="text/css" media="screen,projection">
'.get_css().'
</style>
</head>
<body>
<div class="header">
<h1><a href="'.escape(LOCAL_URL).'">'.escape($config->site_title).'</a></h1>';
if (!empty($config->site_description))
echo '<p>'.$config->site_description.'</p>';
echo '
<form method="get" action="'.escape(LOCAL_URL).'" class="searchForm">
<div>
<input type="text" name="q" value="'.escape($search).'" />
<input type="submit" value="'.__('Search').'" />
</div>
</form>
</div>
';
if ($vvb->mustUpdate())
{
echo '
<div class="article">
<div class="title">
<h2>'.__('Update').'</h2>
</div>
<div class="content" id="update">
'.__('Updating database... Please wait.').'
</div>
</div>';
}
if (!empty($search))
{
$results = $vvb->searchArticles($search);
$text = sprintf(__('<b>%d</b> results for <i>%s</i>'), count($results), escape($search));
echo '
<div class="article">
<div class="title">
<h2>'.__('Search').'</h2>
<h4>'.$text.'</h4>
</div>
</div>';
foreach ($results as $art)
{
echo '
<div class="article result">
<h3><a href="'.escape($art['url']).'">'.escape($art['title']).'</a></h3>
<p>'.$art['snippet'].'</p>
</div>';
}
}
elseif (!is_null($article))
{
if (!$article)
{
echo '
<div class="article">
<div class="title">
<h2>'.__('Not Found').'</h2>
'.(!empty($uri) ? '<p><tt>'.escape($vvb->getLocalURL($uri)) . '</tt></p>' : '').'
<h4>'.__('Article not found.').'</h4>
</div>
</div>';
}
else
{
display_article($article);
}
}
else
{
if (!empty($_SERVER['QUERY_STRING']) && is_numeric($_SERVER['QUERY_STRING']))
$page = (int) $_SERVER['QUERY_STRING'];
else
$page = 1;
$list = $vvb->listArticlesByPage($page);
foreach ($list as $article)
{
display_article($article);
}
$max = $vvb->countArticles();
if ($max > $config->articles_per_page)
{
echo '<div class="pagination">';
if ($page > 1)
echo '<a href="'.$vvb->getLocalURL($page - 1).'">&larr; '.__('Newer').'</a> ';
$last = ceil($max / $config->articles_per_page);
for ($i = 1; $i <= $last; $i++)
{
echo '<a href="'.$vvb->getLocalURL($i).'">'.($i == $page ? '<b>'.$i.'</b>' : $i).'</a> ';
}
if ($page < $last)
echo '<a href="'.$vvb->getLocalURL($page + 1).'">'.__('Older').' &rarr;</a> ';
echo '</div>';
}
}
echo '
<div class="footer">
<p>Powered by VroumVroumBlog '.VroumVroum_Blog::VERSION.' - <a href="?feed">'.__('RSS Feed').'</a></p>
<p>'.__('Download:').' <a href="'.LOCAL_URL.basename(CONFIG_FILE).'">'.__('configuration').'</a>
- <a href="'.LOCAL_URL.basename(ARTICLES_DB_FILE).'">'.__('articles').'</a></p>
</div>';
if ($vvb->mustUpdate())
{
try {
ob_end_flush();
flush();
}
catch (Exception $e)
{
// Silent, not critical
}
try {
$updated = $vvb->update();
}
catch (VroumVroum_Feed_Exception $e)
{
echo '
<div id="error">
'.escape($e->getMessage()).'
</div>';
$updated = 0;
}
if ($updated > 0)
{
echo '
<script type="text/javascript">
window.onload = function () {
document.getElementById("update").innerHTML = "'.__('Update complete!').' <a href=\\"#reload\\" onclick=\\"window.location.reload();\\">'.__('Click here to reload this webpage.').'</a>";
};
</script>';
}
else
{
echo '
<script type="text/javascript">
window.onload = function () {
document.body.removeChild(document.getElementById("update").parentNode);
};
</script>';
}
}
echo '
</body>
</html>';
// Escaping HTML strings
function escape($str)
{
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
}
function escape_content($str)
{
$str = preg_replace('!<\s*(style|script|link)!', '&lt;\\1', $str);
$str = str_replace('="media/', '="'.LOCAL_URL.'media/', $str);
return $str;
}
// ARTICLE HTML CODE
function display_article($article)
{
global $vvb, $config;
echo '
<div class="article">
<div class="title">
<h2><a href="'.$vvb->getLocalURL($article).'">'.escape($article['title']).'</a></h2>
<h4>'.strftime(__('_date_format'), $article['date']).'</h4>
</div>
<div class="content">'.escape_content($article['content']).'</div>
<p class="source">'.__('Source:').' <a href="'.escape($article['url']).'">'.escape($article['url']).'</a></p>
<br style="clear: both;" />
</div>';
}
function get_css()
{
return '
* { margin: 0; padding: 0; }
body { font-family:"Trebuchet MS",Verdana,Arial,Helvetica,sans-serif; background-color: #3E4B50; padding: 1%; color: #000; }
img { max-width: 100%; height: auto; }
.header h1 { text-shadow: 2px 2px 2px #000; }
.header h1 a { text-decoration: none; color: #eee; }
.header { padding: 1% 3%; color: #eee; margin: 0 10%; border-bottom: 1px solid #aaa; background: #6A6A6A; }
.header p a { color: #bbb; }
.header p a:hover { color:#FFFFC9; text-decoration:none;}
.article .title h2 { margin: 0; color:#666; text-shadow: 1px 1px 1px #fff; }
.article .title h2 a { color:#666; text-decoration:none; }
.article .title h2 a:hover { color:#403976; }
.pagination { margin: 0 10%; padding: 1% 2%; background: #6A6A6A; }
.pagination b { font-size: 1.2em; color: #ffffc9; }
.pagination a { color:#ccc; margin: 0 0.5em; }
.pagination a:hover { color:#FFFFC9; }
.article { margin: 0 10%; padding: 1% 2%; background: #ccc; border-bottom: 1px solid #888; }
.article h4 { font-weight: normal; font-size: small; color: #666; }
.article .title { margin-bottom: 1em; }
.article .source { font-size: 0.8em; color: #666; }
.article .source a { color: #666; }
.searchForm { float:right; background: #6a6a6a; border: 1px solid #aaa; border-top: none; padding: 0 0.3em 0.3em; margin-top: 1.3%; }
.searchForm input { padding: 0.2em; border: 1px solid #999; background: #eee; color: #000; }
.footer { text-align:center; font-size: small; color:#aaa; clear: both; }
.footer a { color:#ccc; }
.footer a:hover { color:#FFFFC9; }
.content ul, .content ol { margin-left: 2em; }
.content h1, .content h2, .content h3, .content h4, .content h5, .content h6,
.content ul, .content ol, .content p, .content object, .content div, .content blockquote,
.content dl, .content pre { margin-bottom: 0.8em; }
.content pre, .content blockquote { background: #ddd; border: 1px solid #999; padding: 0.2em; max-width: 100%; overflow: auto; }
.content h1 { font-size: 1.5em; }
.content h2 { font-size: 1.4em; }
.result h3 a { color: darkblue; text-decoration: none; text-shadow: 1px 1px 1px #fff; }
#error { position: fixed; top: 0; left: 0; right: 0; padding: 1%; background: #fff; border-bottom: 2px solid red; color: darkred; }';
}
?>

View file

@ -1,54 +0,0 @@
<?php
if(!defined('ROOT_DIR'))
{
define('ROOT_DIR', dirname($_SERVER['SCRIPT_FILENAME']));
}
define('LOCAL_URI', '');
date_default_timezone_set('Europe/Paris');
setlocale(LC_TIME, 'fr_FR.UTF-8', 'fr_FR', 'fr');
function __($str)
{
switch ($str)
{
case 'Search':
return 'Recherche';
case 'Update':
return 'Mise à jour';
case 'Updating database... Please wait.':
return 'Mise à jour de la base de données, veuillez patienter...';
case '<b>%d</b> results for <i>%s</i>':
return '<b>%d</b> résultats pour la recherche <i>%s</i>';
case 'Not Found':
return 'Introuvable';
case 'Article not found.':
return 'Cet article n\'a pas été trouvé.';
case 'Older':
return 'Plus anciens';
case 'Newer':
return 'Plus récents';
case 'RSS Feed':
return 'Flux RSS';
case 'Update complete!':
return 'Mise à jour terminée !';
case 'Click here to reload this webpage.':
return 'Cliquez ici pour recharger cette page.';
case 'Source:':
return 'Source :';
case '_date_format':
return '%A %e %B %Y à %H:%M';
case 'configuration':
case 'articles':
return $str;
}
}
// Logo à utiliser
$logo="./icon-logo.svg";
// Marquez ici votre propre message qui apparaîtra en bas de page.
// exemple :
// $HTML_footer="<br/><a href='http://datalove.me/'>Love data</a><br/>Data is essential<br/>Data must flow<br/>Data must be used<br/>Data is neither good nor bad<br/>There is no illegal data<br/>Data is free<br/>Data can not be owned<br/>No man, machine or system shall interrupt the flow of data<br/>Locking data is a crime against datanity";
$HTML_footer="";
?>

View file

@ -1 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="300" height="200"><defs id="defs4" /><g transform="translate(0,-852.36218)" id="layer1"><rect width="259.5" height="82.395004" x="20.25" y="911.16467" id="rect3030" style="fill:#f2f2f2;fill-opacity:1;stroke:#000000;stroke-width:0.72559333;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" /><text x="149.10121" y="936.99072" id="text3032" xml:space="preserve" style="font-size:31.44740295px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"><tspan x="149.10121" y="936.99072" id="tspan3040" style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;fill:#000000;stroke:none;font-family:Arial;-inkscape-font-specification:Arial Bold">Never surrender</tspan><tspan x="149.10121" y="982.74823" id="tspan3044" style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;fill:#000000;stroke:none;font-family:Arial;-inkscape-font-specification:Arial Bold">to <tspan id="tspan3046" style="font-size:38px">censorship</tspan></tspan></text></g></svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -1,462 +0,0 @@
<?php
/* modtime 2013-01-23 */
define('ROOT_DIR', __DIR__);
if(file_exists("config.php")){
include "config.php";
}
function get_title_from_feed($url)
{
// get site title from feed
$data = file_get_contents("$url");
if($data === false) { die('url inaccessible'); }
$dom = new DOMDocument;
$dom->loadXML($data) or die('xml malformé');
$title = $dom->getElementsByTagName('title');
return $title->item(0)->nodeValue;
}
function get_link_from_feed($url)
{
// get site link from feed
$data = file_get_contents("$url");
$xml = simplexml_load_string($data); // quick feed check
if (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
{$result="false";}
if($result == "false") { die('le flux n\'a pas une syntaxe valide'); }
$check = substr($data, 0, 5);
if($check !== '<?xml') { die('n\'est pas un flux valide'); }
$xml = new SimpleXmlElement($data);
$channel['link'] = $xml->channel->link;
if($channel['link'] === NULL)
{
$dom = new DOMDocument;
$dom->loadXML($data) or die('xml malformé');
$link = $dom->getElementsByTagName('uri');
return $link->item(0)->nodeValue;
}
else
{
return $channel['link'];
}
}
function serverUrl()
{
$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;
}
function NoProtocolSiteURL($url)
{
$siteurlnoprototypes = array("http://", "https://");
$siteurlnoproto = str_replace($siteurlnoprototypes, "", $url);
return $siteurlnoproto;
}
function DetectRedirect($url)
{
$response = get_headers($url, 1);
if(!empty($response['Location']))
{
$response2 = get_headers($response['Location'], 1);
if(!empty($response2['Location']))
{die('too much redirection');}
else { return $response['Location']; }
}
else
{
return $url;
}
}
if (isset($_GET['check']))
{
$randomtime=rand(86400, 259200); /* intervalle de mise à jour: de 1 à 3 jours (pour éviter que le statut de tous les autoblogs soit rafraichi en bloc et bouffe le CPU) */
$expire=time() -$randomtime ;
/* SVG minimalistes */
$svg_vert='<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="15" height="15"><g><rect width="15" height="15" x="0" y="0" style="fill:#00ff00;stroke:#008000"/></g><text style="font-size:10px;font-weight:bold;text-anchor:middle;font-family:Arial"><tspan x="7" y="11">OK</tspan></text></svg>';
$svg_jaune='<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="15" height="15"><g><rect width="15" height="15" x="0" y="0" style="fill:#ffff00;stroke:#ffcc00"/></g><text style="font-size:10px;font-weight:bold;text-anchor:middle;font-family:Arial"><tspan x="7" y="11">mv</tspan></text></svg>';
$svg_rouge='<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="15" height="15"><g><rect width="15" height="15" x="0" y="0" style="fill:#ff0000;stroke:#800000"/></g><text style="font-size:10px;font-weight:bold;text-anchor:middle;font-family:Arial"><tspan x="7" y="11">err</tspan></text></svg>';
$svg_twitter='<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="15" height="15"><path d="m 11.679889,7.6290431 a 4.1668792,3.7091539 0 1 1 -8.3337586,0 4.1668792,3.7091539 0 1 1 8.3337586,0 z" style="fill:none;stroke:#3aaae1;stroke-width:4;stroke-miterlimit:4" /></svg>';
$svg_identica='<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="15" height="15"><path d="m 11.679889,7.6290431 a 4.1668792,3.7091539 0 1 1 -8.3337586,0 4.1668792,3.7091539 0 1 1 8.3337586,0 z" style="fill:none;stroke:#a00000;stroke-width:4;stroke-miterlimit:4" /></svg>';
$svg_statusnet='<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="15" height="15"><path d="m 11.679889,7.6290431 a 4.1668792,3.7091539 0 1 1 -8.3337586,0 4.1668792,3.7091539 0 1 1 8.3337586,0 z" style="fill:none;stroke:#ff6a00;stroke-width:4;stroke-miterlimit:4" /></svg>';
if(strpos($_GET['check'], 'twitter') !== FALSE) { header('Content-type: image/svg+xml');die($svg_twitter); }
if(strpos($_GET['check'], 'identica') !== FALSE) { header('Content-type: image/svg+xml');die($svg_identica); }
if(strpos($_GET['check'], 'statusnet') !== FALSE) { header('Content-type: image/svg+xml');die($svg_statusnet); }
$errorlog="./".$_GET['check']."/error.log";
if(file_exists($errorlog) && filemtime($errorlog) < $expire) { unlink($errorlog); } /* errorlog périmé ? Suppression. */
if(file_exists($errorlog)) /* errorlog existe encore ? se contenter de lire sa taille pour avoir le statut */
{
header('Content-type: image/svg+xml');
if(filesize($errorlog) == "0") {die($svg_vert);}
else if(filesize($errorlog) == "1") {die($svg_jaune);}
else {die($svg_rouge);}
}
else /* ..sinon, lancer la procédure de contrôle */
{
$ini = parse_ini_file("./".$_GET['check']."/vvb.ini") or die;
header('Content-type: image/svg+xml');
$headers = get_headers("$ini[FEED_URL]");
if(empty($headers)) { file_put_contents($errorlog, '..'); die($svg_rouge); } /* le flux est indisponible (typiquement: erreur DNS ou possible censure) - à vérifier */
$code=explode(" ", $headers[0]);
if($code[1] == "200") { file_put_contents($errorlog, ''); die($svg_vert);} /* code retour 200: flux disponible */
else {file_put_contents($errorlog, '.'); die($svg_jaune);} /* autre code retour: un truc a changé (redirection, changement de CMS, .. bref vvb.ini doit être corrigé) */
}
}
if (isset($_GET['export']))
// autoblog exporting
{
header('Content-Type: application/json');
$directory = "./";
$subdirs = glob($directory . "*");
foreach($subdirs as $unit)
{
if(is_dir($unit))
{
$unit=substr($unit, 2);
$ini = parse_ini_file($unit.'/vvb.ini');
$config = new stdClass;
foreach ($ini as $key=>$value)
{
$key = strtolower($key);
$config->$key = $value;
}
unset($ini);
$title=$config->site_title;
$url=$config->site_url;
$feed=$config->feed_url;
$reponse[$unit] = array("$title", "$url", "$feed");
}
}
echo json_encode($reponse);
die;
}
if (isset($_GET['feedexport']))
// autoblog exporting -feed only
{
header('Content-Type: application/json');
$directory = "./";
$reponse="";
$subdirs = glob($directory . "*");
foreach($subdirs as $unit)
{
if(is_dir($unit))
{
$unit=substr($unit, 2);
$ini = parse_ini_file($unit.'/vvb.ini');
$config = new stdClass;
foreach ($ini as $key=>$value)
{
$key = strtolower($key);
$config->$key = $value;
}
unset($ini);
$feed=$config->feed_url;
$reponse=$reponse.";$feed";
}
}
$reponse=substr($reponse, 1);
echo json_encode(explode(';', $reponse));
die;
}
if (isset($_GET['sitemap']))
// url-list sitemap
{
header('Content-Type: text/plain');
$directory = "./";
$subdirs = glob($directory . "*");
foreach($subdirs as $unit)
{
if(is_dir($unit))
{
$unit=substr($unit, 2);
$proto=$_SERVER['HTTPS']?"https://":"http://";
echo $proto.$_SERVER['SERVER_NAME'].substr($_SERVER['PHP_SELF'], 0, -9)."$unit/"."\n";
}
}
die;
}
function escape($str)
{
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
}
$form = '<form method="POST"><input placeholder="Adresse du flux RSS/ATOM" type="text" name="rssurl" id="rssurl"><br>
<input placeholder="Antibot: \'dix sept\' en chiffre" type="text" name="number" id="number"><br><input type="submit" value="Vérifier"></form>';
if(!empty($_GET['via_button']) && !empty($_GET['rssurl']) && $_GET['number'] === '17')
{
if(isset($_GET['add']) && $_GET['add'] === '1' && !empty($_GET['siteurl']) && !empty($_GET['sitename']))
{
$rssurl = DetectRedirect(escape($_GET['rssurl']));
$siteurl = escape($_GET['siteurl']);
$foldername = sha1(NoProtocolSiteURL($siteurl));
if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');}
$sitename = escape($_GET['sitename']);
$sitedomain1 = preg_split('/\//', $siteurl, 0);
$sitedomain2=$sitedomain1[2];
$sitedomain3=explode(".", $sitedomain2);
$sitedomain3=array_reverse($sitedomain3);
$sitedomain = $sitedomain3[1].'.'.$sitedomain3[0];
if(file_exists($foldername) || file_exists($foldername2)) { die('Erreur: l\'autoblog <a target="_blank" href="./'.$foldername.'/">existe déjà</a>.'); }
if ( mkdir('./'. $foldername, 0755, false) ) {
$fp = fopen('./'. $foldername .'/index.php', 'w+');
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/autoblog.php'; ?>") )
{die("Impossible d'écrire le fichier index.php");}
fclose($fp);
$fp = fopen('./'. $foldername .'/vvb.ini', 'w+');
if( !fwrite($fp, '[VroumVroumBlogConfig]
SITE_TITLE="'. $sitename .'"
SITE_DESCRIPTION="Ce site n\'est pas le site officiel de '. $sitename .'<br>C\'est un blog automatis&eacute; qui r&eacute;plique les articles de <a href="'. $siteurl .'">'. $sitename .'</a>"
SITE_URL="'. $siteurl .'"
FEED_URL="'. $rssurl .'"
DOWNLOAD_MEDIA_FROM='.$sitedomain) )
{die("Impossible d'écrire le fichier vvb.ini");}
fclose($fp);
{die('<iframe width="1" height="1" frameborder="0" src="'.$foldername.'"></iframe><b style="color:darkgreen">autoblog crée avec succès.</b> &rarr; <a target="_blank" href="'.$foldername.'">afficher l\'autoblog</a>');}
}
else
{die("Impossible de créer le répertoire.");}
}
else
{
// checking procedure
$rssurl = DetectRedirect($_GET['rssurl']);
$siteurl = get_link_from_feed($rssurl);
$foldername = sha1(NoProtocolSiteURL($siteurl));
if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');}
$sitename = get_title_from_feed($rssurl);
$sitedomain1 = preg_split('/\//', $siteurl, 0);$sitedomain2=$sitedomain1[2];$sitedomain3=explode(".", $sitedomain2);$sitedomain3=array_reverse($sitedomain3);$sitedomain = $sitedomain3[1].'.'.$sitedomain3[0];
if(file_exists($foldername) || file_exists($foldername2)) { die('Erreur: l\'autoblog <a href="./'.$foldername.'/">existe déjà</a>.'); }
$form = '<html><head></head><body><span style="color:blue">Merci de vérifier les informations suivantes, corrigez si nécessaire.</span><br>
<form method="GET">
<input type="hidden" name="via_button" value="1"><input type="hidden" name="add" value="1"><input type="hidden" name="number" value="17">
<input style="width:30em;" type="text" name="sitename" id="sitename" value="'.$sitename.'"><label for="sitename">&larr; titre du site (auto)</label><br>
<input style="width:30em;" placeholder="Adresse du site" type="text" name="siteurl" id="siteurl" value="'.$siteurl.'"><label for="siteurl">&larr; page d\'accueil (auto)</label><br>
<input style="width:30em;" placeholder="Adresse du flux RSS/ATOM" type="text" name="rssurl" id="rssurl" value="'.$rssurl.'"><label for="rssurl">&larr; adresse du flux</label><br>
<input type="submit" value="Créer"></form></body></html>';
echo $form; die;
}
}
if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']))
{
$socialaccount = strtolower(escape($_POST['socialaccount']));
if(escape($_POST['socialinstance']) === 'twitter') { $socialinstance = 'twitter'; }
if(escape($_POST['socialinstance']) === 'identica') { $socialinstance = 'identica'; }
if(escape($_POST['socialinstance']) === 'statusnet') { $socialinstance = 'statusnet'; }
$folder = "$socialinstance-$socialaccount";if(file_exists($folder)) { die('Erreur: l\'autoblog <a href="./'.$folder.'/">existe déjà</a>.'); }
if($socialinstance === 'twitter') { $siteurl = "http://twitter.com/$socialaccount"; $rssurl = "http://api.twitter.com.nyud.net/1/statuses/user_timeline.rss?screen_name=$socialaccount"; }
if($socialinstance === 'identica') { $siteurl = "http://identi.ca/$socialaccount"; $rssurl = "http://identi.ca.nyud.net/api/statuses/user_timeline/$socialaccount.rss"; }
if($socialinstance === 'statusnet' && !empty($_POST['socialurl'])) { $siteurl = "http://".escape($_POST['socialurl'])."/$socialaccount"; $rssurl = "http://".escape($_POST['socialurl'])."/api/statuses/user_timeline/$socialaccount.rss"; }
$headers = get_headers($rssurl, 1);
if (strpos($headers[0], '200') == FALSE) {$error[] = "Flux inaccessible (compte inexistant ?)";} else { }
if( empty($error) ) {
if( !preg_match('#\.\.|/#', $folder) ) {
if ( mkdir('./'. $folder, 0755, false) ) {
$fp = fopen('./'. $folder .'/index.php', 'w+');
if( !fwrite($fp, "<?php require_once dirname(__DIR__).'/automicroblog.php'; ?>") )
$error[] = "Impossible d'écrire le fichier index.php";
fclose($fp);
$fp = fopen('./'. $folder .'/vvb.ini', 'w+');
if( !fwrite($fp, '[VroumVroumBlogConfig]
SITE_TITLE="'.$socialinstance.'-'.$socialaccount.'"
SITE_DESCRIPTION="AutoMicroblog automatis&eacute; de "
SITE_URL='. $siteurl .'
FEED_URL="'. $rssurl .'"') )
$error[] = "Impossible d'écrire le fichier vvb.ini";
fclose($fp);
$error[] = '<iframe width="1" height="1" frameborder="0" src="'.$folder.'"></iframe><b style="color:darkgreen">AutoMicroblog <a href="'.$folder.'">ajouté avec succès</a>.</b>';
}
else
$error[] = "Impossible de créer le répertoire.";
}
else
$error[] = "Nom de site invalide.";
}
}
if( !empty($_POST) && empty($_POST['socialinstance']) ) {
$error = array();
if(empty($_POST['rssurl']))
{$error[] = "Veuillez entrer l'adresse du flux.";}
if(empty($_POST['number']))
{$error[] = "Le chiffre. Écrivez le chiffre.";}
if($_POST['number'] !== '17')
{$error[] = "C'est pas le bon chiffre.";}
if(empty($error))
{
$rssurl = DetectRedirect(escape($_POST['rssurl']));
if(!empty($_POST['siteurl']))
{
// check done, writing out
$siteurl = escape($_POST['siteurl']);
$foldername = sha1(NoProtocolSiteURL($siteurl));$sitename = get_title_from_feed($rssurl);
if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');}
$sitedomain1 = preg_split('/\//', $siteurl, 0);$sitedomain2=$sitedomain1[2];$sitedomain3=explode(".", $sitedomain2);$sitedomain3=array_reverse($sitedomain3);$sitedomain = $sitedomain3[1].'.'.$sitedomain3[0];
if(file_exists($foldername) || file_exists($foldername2)) { die('Erreur: l\'autoblog <a href="./'.$foldername.'/">existe déjà</a>.'); }
if ( mkdir('./'. $foldername, 0755, false) ) {
$fp = fopen('./'. $foldername .'/index.php', 'w+');
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/autoblog.php'; ?>") )
$error[] = "Impossible d'écrire le fichier index.php";
fclose($fp);
$fp = fopen('./'. $foldername .'/vvb.ini', 'w+');
if( !fwrite($fp, '[VroumVroumBlogConfig]
SITE_TITLE="'. $sitename .'"
SITE_DESCRIPTION="Ce site n\'est pas le site officiel de '. $sitename .'<br>C\'est un blog automatis&eacute; qui r&eacute;plique les articles de <a href="'. $siteurl .'">'. $sitename .'</a>"
SITE_URL="'. $siteurl .'"
FEED_URL="'. $rssurl .'"
DOWNLOAD_MEDIA_FROM='.$sitedomain) )
$error[] = "Impossible d'écrire le fichier vvb.ini";
fclose($fp);
$error[] = '<iframe width="1" height="1" frameborder="0" src="'.$foldername.'"></iframe><b style="color:darkgreen">autoblog crée avec succès.</b> &rarr; <a target="_blank" href="'.$foldername.'">afficher l\'autoblog</a>';
}
else
$error[] = "Impossible de créer le répertoire.";
}
else
{
// checking procedure
$rssurl = DetectRedirect($rssurl);
$siteurl = get_link_from_feed($rssurl);
$foldername = sha1(NoProtocolSiteURL($siteurl));
$sitename = get_title_from_feed($rssurl);
if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');}
$sitedomain1 = preg_split('/\//', $siteurl, 0);$sitedomain2=$sitedomain1[2];$sitedomain3=explode(".", $sitedomain2);$sitedomain3=array_reverse($sitedomain3);$sitedomain = $sitedomain3[1].'.'.$sitedomain3[0];
if(file_exists($foldername) || file_exists($foldername2)) { die('Erreur: l\'autoblog <a href="./'.$foldername.'/">existe déjà</a>.'); }
$form = '<span style="color:blue">Merci de vérifier les informations suivantes, corrigez si nécessaire.</span><br>
<form method="POST"><input style="color:black" type="text" id="sitename" value="'.$sitename.'" disabled><label for="sitename">&larr; titre du site (auto)</label><br>
<input placeholder="Adresse du site" type="text" name="siteurl" id="siteurl" value="'.$siteurl.'"><label for="siteurl">&larr; page d\'accueil (auto)</label><br>
<input placeholder="Adresse du flux RSS/ATOM" type="text" name="rssurl" id="rssurl" value="'.$rssurl.'"><label for="rssurl">&larr; adresse du flux</label><br>
<input placeholder="Antibot: \'dix sept\' en chiffre" type="text" name="number" id="number" value="17"><label for="number">&larr; antibot</label><br><input type="submit" value="Créer"></form>';
}
}
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Le Projet Autoblog</title>
<style type="text/css">
body {background-color:#efefef;text-align:center;color:#333;font-family:sans-serif}
a {color:black;text-decoration:none;font-weight:bold;}
a:hover {color:darkred;}
h1 { text-align:center;font-size:40pt;text-shadow: #ccc 0px 5px 5px; }
h2 { text-align:center;font-size: 16pt;margin:0 0 1em 0;font-style:italic;text-shadow: #ccc 0px 5px 5px; }
.pbloc {background-color:white;padding: 12px 10px 12px 10px;border:1px solid #aaa;max-width:70em;margin:1em auto;text-align:justify;box-shadow:0px 5px 7px #aaa;}
input {width:30em;}
input[type="radio"] { width:1em; }
input#socialaccount, input#socialurl, input#socialsub {width:12em;}
.vignette { width:20em;height:2em;float:left;margin:0; padding:20px;background-color:#eee;border: 1px solid #888;}
.vignette:hover { background-color:#fff;}
.vignette .title { font-size: 14pt;text-shadow: #ccc 0px 5px 5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.vignette .title a:hover { color:darkred; text-decoration:none;}
.vignette .source { font-size:x-small;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.vignette .source a:hover { color:darkred; text-decoration:none;}
.clear {clear:both;text-align:right;font-size:small;}
#logo {float: right;}
.bouton{background: -moz-linear-gradient(center top , #EDEDED 5%, #DFDFDF 100%) repeat scroll 0 0 #EDEDED;border: 1px none;padding: 10px;border: 1px solid #7777777;border-radius: 8px 8px 8px 8px;box-shadow: 0 1px 0 0 #FFFFFF inset;display: inline-block;}
</style>
</head>
<body>
<h1>LE PROJET AUTOBLOG</h1>
<div class="pbloc">
<img id="logo" src="<?php if(isset($logo)) { echo $logo; }else{ echo './icon-logo.svg'; } ?>" alt="">
<b>Note</b><br>
Voici une liste d'autoblogs hébergés sur <i><?php echo $_SERVER['SERVER_NAME']; ?></i> (<a href="http://sebsauvage.net/streisand.me/fr/">plus d'infos sur le projet</a>).<br><br>
<b>Autres fermes</b><br>
&rarr; <a href="https://duckduckgo.com/?q=!g%20%22Voici%20une%20liste%20d'autoblogs%20hébergés%22">Rechercher</a><br><br>
<b>Ajouter un compte social</b><br><br>
<form method="POST">
<input class="text" placeholder="identifiant compte" type="text" name="socialaccount" id="socialaccount"><br>
<input type="radio" name="socialinstance" value="twitter">Twitter<br>
<input type="radio" name="socialinstance" value="identica">Identica<br>
<input type="radio" name="socialinstance" value="statusnet"><input placeholder="statusnet.personnel.com" type="text" name="socialurl" id="socialurl"><br>
<input id="socialsub" type="submit" value="Créer">
</form><br>
<b>Ajouter un site web</b><br>
<?php
if( !empty( $error )) {
echo '<p>Erreur(s) :</p><ul>';
foreach ( $error AS $value ) {
echo '<li>'. $value .'</li>';
}
echo '</ul>';
}
?>
Si vous souhaitez que <i><?php echo $_SERVER['SERVER_NAME']; ?></i> héberge un autoblog d'un site,<br/>remplissez le formulaire suivant:<br><br>
<?php echo $form; ?>
<br>Pour ajouter facillement un autoblog, glissez ce bouton dans votre barre de marque-pages =&gt; <a class="bouton" onclick="alert('Glissez ce lien dans votre barre de marque-pages ou clic-droit puis choisiez d\'ajouter ce lien aux marque-pages.');return false;" href="javascript:(function(){var%20autoblog_url=&quot;<?php echo serverUrl().$_SERVER["REQUEST_URI"]; ?>&quot;;var%20popup=window.open(&quot;&quot;,&quot;Add%20autoblog&quot;,'height=180,width=670');popup.document.writeln('<html><head></head><body><form%20action=&quot;'+autoblog_url+'&quot;%20method=&quot;GET&quot;>');popup.document.write('Url%20feed%20%20:%20<br/>');var%20feed_links=new%20Array();var%20links=document.getElementsByTagName('link');if(links.length>0){for(var%20i=0;i<links.length;i++){if(links[i].rel==&quot;alternate&quot;){popup.document.writeln('<label%20for=&quot;feed_'+i+'&quot;><input%20id=&quot;feed_'+i+'&quot;%20type=&quot;radio&quot;%20name=&quot;rssurl&quot;%20value=&quot;'+links[i].href+'&quot;/>'+links[i].title+&quot;%20(%20&quot;+links[i].href+&quot;%20)</label><br/>&quot;);}}}popup.document.writeln(&quot;<input%20id='number'%20type='hidden'%20name='number'%20value='17'>&quot;);popup.document.writeln(&quot;<input%20type='hidden'%20name='via_button'%20value='1'>&quot;);popup.document.writeln(&quot;<br/><input%20type='submit'%20value='Vérifier'%20name='Ajouter'%20>&quot;);popup.document.writeln(&quot;</form></body></html>&quot;);})();">Projet Autoblog</a>
</div>
<div class="pbloc">
<h2>Autoblogs hébergés</h2>
<div class="clear"><a href="?export">export<sup> JSON</sup></a></div>
<?php
$directory = "./";
$subdirs = glob($directory . "*");
$autoblogs = array();
foreach($subdirs as $unit)
{
if(is_dir($unit))
{
$ini = parse_ini_file(ROOT_DIR . '/' . $unit . '/vvb.ini');
if($ini)
{
$config = new stdClass;
$unit=substr($unit, 2);
foreach ($ini as $key=>$value)
{
$key = strtolower($key);
$config->$key = $value;
}
$autoblogs[$unit] = '
<div class="vignette">
<div class="title"><a title="'.escape($config->site_title).'" href="'.$unit.'/"><img width="15" height="15" alt="" src="./?check='.$unit.'"> '.escape($config->site_title).'</a></div>
<div class="source"><a href="'.$unit.'/vvb.ini">config</a> | source: <a href="'.escape($config->site_url).'">'.escape($config->site_url).'</a></div>
</div>';
unset($ini);
}
}
}
if(!empty($autoblogs)){
sort($autoblogs, SORT_STRING);
foreach ($autoblogs as $autoblog) {
echo $autoblog;
}
}
?>
<div class="clear"></div>
<?php echo "<br/>".count($autoblogs)." autoblogs d'hébergés"; ?>
</div>
Autoblogs propulsés par <a href="http://autoblog.kd2.org/source.txt">VroumVroumBlog 0.2.10</a> [SQLite] (Domaine Public)<br>index2 inspiré par <a href="http://wiki.hoa.ro/doku.php?id=web%3Aferme-autoblog">Arthur</a> et développé par <a href="https://www.suumitsu.eu/">Mitsu</a> et <a href="https://www.ecirtam.net/">Oros</a> (Domaine Public)
<br/><a href='https://github.com/mitsukarenai/ferme-autoblog'>Code source du projet</a>
<?php if(isset($HTML_footer)){ echo "<br/>".$HTML_footer; } ?>
<iframe width="1" height="1" style="display:none" src="xsaf2.php"></iframe>
</body>
</html>

View file

@ -1,179 +0,0 @@
<?php
/* modtime 2013-01-30 */
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) */
if (file_exists($lockfile)) {
if (filemtime($lockfile) > $expire) {
echo "too early";
die;
}else{
unlink($lockfile);
file_put_contents($lockfile, '');
}
}else{
file_put_contents($lockfile, '');
}
define('ROOT_DIR', __DIR__);
function escape($str) {
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
}
function serverUrl() {
$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;
}
function NoProtocolSiteURL($url) {
$siteurlnoprototypes = array("http://", "https://");
$siteurlnoproto = str_replace($siteurlnoprototypes, "", $url);
return $siteurlnoproto;
}
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
$json_import = file_get_contents($xsafremote);
if(!empty($json_import)) {
$to_update=array();
foreach (json_decode($json_import) as $value) {
$infos="";
if(count($value)==3 && !empty($value[0]) && !empty($value[1]) && !empty($value[2])) {
$sitename = $value[0];
$siteurl = escape($value[1]);
$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($social==FALSE) {
$foldername = sha1(NoProtocolSiteURL($siteurl));
if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(NoProtocolSiteURL(substr($siteurl, 0, -1))); }else{ $foldername2 = sha1(NoProtocolSiteURL($siteurl).'/');}
} else{
$foldername = $sitename;$foldername2 = $sitename;
}
$sitedomain1 = preg_split('/\//', $siteurl, 0);
$sitedomain2=$sitedomain1[2];
$sitedomain3=explode(".", $sitedomain2);
$sitedomain3=array_reverse($sitedomain3);
$sitedomain = $sitedomain3[1].'.'.$sitedomain3[0];
if(!file_exists($foldername) && !file_exists($foldername2)) {
if ( mkdir('./'. $foldername, 0755, false) ) {
$fp = fopen('./'. $foldername .'/index.php', 'w+');
$response = get_headers($rssurl, 1); // check for redirections
if(!empty($response['Location'])) {
$result="false";
}else{
$xml = simplexml_load_file($rssurl); // quick feed check
if($xml === 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{
$result="false";
}
}
/* autoblog */
if($social==FALSE and $result!=="false") {
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/autoblog.php'; ?>") ) {
$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_TITLE="'. $sitename .'"
SITE_DESCRIPTION="Ce site n\'est pas le site officiel de '. $sitename .'<br>C\'est un blog automatis&eacute; qui r&eacute;plique les articles de <a href="'. $siteurl .'">'. $sitename .'</a>"
SITE_URL="'. $siteurl .'"
FEED_URL="'. $rssurl .'"
DOWNLOAD_MEDIA_FROM='.$sitedomain) ){
fclose($fp);
$infos = "\nImpossible d'écrire le fichier vvb.ini dans ".$foldername;
}else{
fclose($fp);
$infos = "\nautoblog crée avec succès : $foldername";
$to_update[]=serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
}
}
}
/* automicroblog */
else if($social!==FALSE and $result!=="false"){
if( !fwrite($fp, "<?php require_once dirname(__DIR__) . '/automicroblog.php'; ?>") ){
$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_TITLE="'. $sitename .'"
SITE_DESCRIPTION="AutoMicroblog automatis&eacute; de "
SITE_URL="'. $siteurl .'"
FEED_URL="'. $rssurl .'"') ){
fclose($fp);
$infos = "\nImpossible d'écrire le fichier vvb.ini dans ".$foldername;
}else{
fclose($fp);
$infos = "\nautomicroblog 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";
}
/* end of file writing */
}else {
$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)";*/
}
if(DEBUG){
echo $infos;
}
}
echo "\n time : ".(time() - $max_exec_time);
if(time() >= $max_exec_time){
break;
}
}
/*if(!empty($to_update)){
if(DEBUG){
echo "\nupdate of autoblogs ...";
}
// because it's could be very long, we finish by updating new autoblogs
foreach ($to_update as $url) {
get_headers($url);
}
if(DEBUG){
echo "done\n\n";
}
}*/
}
return;
}
/* 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);
if(DEBUG) {
echo "\n\nXSAF import finished\n\n";
}
die;
?>

View file

@ -1,138 +0,0 @@
<?php
$dir="./";
$liste_blog = scandir($dir);
unset($liste_blog[0]);
unset($liste_blog[1]);
foreach($liste_blog as $blog) {
if(is_dir($dir.$blog) && is_file($dir.$blog."/vvb.ini")) {
$articles = new SQLite3($dir.$blog."/articles.db");
$articles->exec('
CREATE TABLE update_log (
date INT PRIMARY KEY,
success INT,
log TEXT
);
');
$vals=array();
$ini = parse_ini_file($dir.$blog."/vvb.ini");
if(is_dir(urlToFolderWithTrailingSlash( $ini['SITE_URL'] )) || is_dir(urlToFolder( $ini['SITE_URL'] )))
continue;
$foldername = urlToFolderWithTrailingSlash($ini['SITE_URL']);
mkdir( $dir . $foldername );
mkdir( $dir . $foldername . '/media');
recursiveMove( $dir . $blog . '/media', $dir . $foldername .'/media' );
copy($dir . $blog . '/index.php', $dir . $foldername .'/index.php');
copy($dir . $blog . '/articles.db', $dir . $foldername .'/articles.db');
deleteDir($dir . $blog );
if( strpos($ini['SITE_TITLE'], 'Autoblog de') !== false ) {
$ini['SITE_TITLE'] = preg_replace('#^Autoblog de (.*)$#', '$1', $ini['SITE_TITLE']);
}
switch(substr($ini['SITE_TITLE'], 0, 7)) {
case 'twitter':
case 'statusn':
case 'identic':
$ini['SITE_TYPE']="microblog";
$ini['ARTICLES_PER_PAGE'] = "20";
$ini['UPDATE_INTERVAL'] = "300";
$ini['UPDATE_TIMEOUT'] = "30";
break;
default:
$ini['SITE_TYPE']="generic";
$ini['ARTICLES_PER_PAGE'] = "5";
$ini['UPDATE_INTERVAL'] = "3600";
$ini['UPDATE_TIMEOUT'] = "30";
break;
}
$fp = fopen($dir.$foldername."/vvb.ini", 'w+');
fwrite($fp, <<<EOF
[VroumVroumBlogConfig]
SITE_TYPE="{$ini['SITE_TYPE']}"
SITE_TITLE="{$ini['SITE_TITLE']}"
SITE_DESCRIPTION="source: <a href='{$ini['SITE_URL']}'>{$ini['SITE_TITLE']}</a>"
SITE_URL="{$ini['SITE_URL']}"
FEED_URL="{$ini['FEED_URL']}"
ARTICLES_PER_PAGE="{$ini['ARTICLES_PER_PAGE']}"
UPDATE_INTERVAL="{$ini['UPDATE_INTERVAL']}"
UPDATE_TIMEOUT="{$ini['UPDATE_TIMEOUT']}"
EOF
);
fclose($fp);
}
}
echo "\nend ".date("d/m/Y H:i:s")."\n\n";
function NoProtocolSiteURL($url) {
$siteurlnoprototypes = array("http://", "https://");
$siteurlnoproto = str_replace($siteurlnoprototypes, "", $url);
// Remove the / at the end of string
if ( $siteurlnoproto[strlen($siteurlnoproto) - 1] == '/' )
$siteurlnoproto = substr($siteurlnoproto, 0, -1);
// Remove index.php/html at the end of string
if( strpos($url, 'index.php') || strpos($url, 'index.html') ) {
$siteurlnoproto = preg_replace('#(.*)/index\.(html|php)$#', '$1', $siteurlnoproto);
}
return $siteurlnoproto;
}
function urlToFolderWithTrailingSlash($url) {
return sha1(NoProtocolSiteURL($url).'/');
}
function urlToFolder($url) {
return sha1(NoProtocolSiteURL($url));
}
/* http://stackoverflow.com/questions/2082138/move-all-files-in-a-folder-to-another */
function recursiveMove($source, $dest) {
// Get array of all source files
$files = scandir($source);
$delete = array();
if(substr($source, strlen($source) - 1, 1) != '/')
$source .= '/';
if(substr($dest, strlen($dest) - 1, 1) != '/')
$dest .= '/';
// Cycle through all source files
foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
// If we copied this successfully, mark it for deletion
if (copy($source.$file, $dest.$file)) {
$delete[] = $source.$file;
}
}
// Delete all successfully-copied files
foreach ($delete as $file) {
unlink($file);
}
}
/* http://stackoverflow.com/questions/3349753/delete-directory-with-files-in-it */
function deleteDir($dirPath) {
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
?>

View file

@ -1,18 +0,0 @@
Projet Autoblog serie 0.3
==============
- version VroumVroumBlog 0.3.0 BETA
Auteurs: Mitsu (https://www.suumitsu.eu/), Oros (https://www.ecirtam.net/) et Arthur Hoaro (http://hoa.ro)
Licence: Domaine Public
- À propos du Projet Autoblog
lire: http://sebsauvage.net/streisand.me/fr/
Instructions
- uploader les fichiers sur un serveur avec PHP 5.3+
- ..c'est tout. Hackez le code pour apprendre comment ça marche et comment le personnaliser :)

View file

@ -1,277 +0,0 @@
<?php
/**
* class_rssfeed.php uses:
* RSSFeed: This class has methods for making a RSS 2.0 feed.
* RSSMerger: This class has the ability to merge different RSS feeds and sort them after the date the feed items were posted.
* @author David Laurell <david.laurell@gmail.com>
*
* + 03/2013
* Few changes, AutoblogRSS and FileRSSFeed
* @author Arthur Hoaro <http://hoa.ro>
*/
class RSSFeed {
protected $xml;
/**
* Construct a RSS feed
*/
public function __construct() {
$template = <<<END
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
</channel>
</rss>
END;
$this->xml = new SimpleXMLElement($template);
}
/**
* Set RSS Feed headers
* @param $title the title of the feed
* @param $link link to the website where you can find the RSS feed
* @param $description a description of the RSS feed
* @param $rsslink the link to this RSS feed
*/
public function setHeaders($title, $link, $description, $rsslink) {
$atomlink = $this->xml->channel->addChild("atom:link","","http://www.w3.org/2005/Atom");
$atomlink->addAttribute("href",$rsslink);
$atomlink->addAttribute("rel","self");
$atomlink->addAttribute("type","application/rss+xml");
$this->xml->channel->title = $title;
$this->xml->channel->link = $link;
$this->xml->channel->description = $description;
}
/**
* Set the language of the RSS feed
* @param $lang the language of the RSS feed
*/
public function setLanguage($lang) {
$this->xml->channel->addChild("language",$lang);
}
/**
* Adds a picture to the RSS feed
* @param $url URL to the image
* @param $title The image title. Usually same as the RSS feed's title
* @param $link Where the image should link to. Usually same as the RSS feed's link
*/
public function setImage($url, $title, $link) {
$image = $this->xml->channel->addChild("image");
$image->url = $url;
$image->title = $title;
$image->link = $link;
}
/**
* Add a item to the RSS feed
* @param $title The title of the RSS feed
* @param $link Link to the item's url
* @param $description The description of the item
* @param $author The author who wrote this item
* @param $guid Unique ID for this post
* @param $timestamp Unix timestamp for making a date
*/
public function addItem($title, $link, $description, $author, $guid, $timestamp) {
$item = $this->xml->channel->addChild("item");
$item->title = $title;
$item->description = $description;
$item->link = $link;
$item->guid = $guid;
if( isset($guid['isPermaLink']))
$item->guid['isPermaLink'] = $guid['isPermaLink'];
if( !empty( $author) )
$item->author = $author;
$item->pubDate = date(DATE_RSS,intval($timestamp));
}
/**
* Displays the RSS feed
*/
public function displayXML() {
header('Content-type: application/rss+xml; charset=utf-8');
echo $this->xml->asXML();
exit;
}
public function getXML() {
return $this->xml;
}
}
class RSSMerger {
private $feeds = array();
/**
* Constructs a RSSmerger object
*/
function __construct() {
}
/**
* Populates the feeds array from the given url which is a rss feed
* @param $url
*/
function add($xml) {
foreach($xml->channel->item as $item) {
$item->sitetitle = $xml->channel->title;
$item->sitelink = $xml->channel->link;
preg_match("/^[A-Za-z]{3}, ([0-9]{2}) ([A-Za-z]{3}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) ([\+|\-]?[0-9]{4})$/", $item->pubDate, $match);
$item->time = time($match[4]+($match[6]/100),$match[5],$match[6],date("m",strtotime($match[2])),$match[1],$match[3]);
$this->feeds[] = $item;
}
}
/**
* Comparing function for sorting the feeds
* @param $value1
* @param $value2
*/
function feeds_cmp($value1,$value2) {
if(intval($value1->time) == intval($value2->time))
return 0;
return (intval($value1->time) < intval($value2->time)) ? +1 : -1;
}
/**
* Sorts the feeds array using the Compare function feeds_cmp
*/
function sort() {
usort($this->feeds,Array("RssMerger","feeds_cmp"));
}
/**
* This function return the feed items.
* @param $limit how many feed items that should be returned
* @return the feeds array
*/
function getFeeds($limit) {
return array_slice($this->feeds,0,$limit);
}
}
class FileRSSFeed extends RSSFeed {
protected $filename;
public function __construct($filename) {
parent::__construct();
$this->filename = $filename;
$this->load();
}
public function load() {
if ( file_exists( $this->filename )) {
$this->xml = simplexml_load_file($this->filename);
}
}
public function create($title, $link, $description, $rsslink) {
parent::setHeaders($title, $link, $description, $rsslink);
$this->write();
}
public function addItem($title, $link, $description, $author, $guid, $timestamp) {
parent::addItem($title, $link, $description, $author, $guid, $timestamp);
$this->write();
}
private function write() {
if ( file_exists( $this->filename )) {
unlink($this->filename);
}
$outputXML = new RSSFeed();
foreach($this->xml->channel->item as $f) {
$item = $outputXML->addItem($f->title,$f->link,$f->description,$f->author,$f->guid, strtotime($f->pubDate));
}
$merger = new RssMerger();
$merger->add($outputXML->getXML());
$merger->sort();
unset($this->xml->channel->item);
foreach($merger->getFeeds(20) as $f) {
parent::addItem($f->title,$f->link,$f->description,$f->author,$f->guid,$f->time);
}
file_put_contents( $this->filename, $this->xml->asXML(), LOCK_EX );
}
}
class AutoblogRSS extends FileRSSFeed {
public function __construct($filename) {
parent::__construct($filename);
}
public function addUnavailable($title, $folder, $siteurl, $rssurl) {
$path = pathinfo( $_SERVER['PHP_SELF'] );
$autobHref = 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'.
$_SERVER["SERVER_NAME"].':'.$_SERVER["SERVER_PORT"]. $path['dirname'].'/'.$folder;
parent::addItem( 'L\'autoblog "'. $title.'" est indisponible', $autobHref,
'Autoblog: <a href="'. $autobHref .'">'.$title.'</a><br>
Site: <a href="'. $siteurl .'">'. $siteurl .'</a><br>
RSS: <a href="'.$rssurl.'">'.$rssurl.'</a><br>
Folder: '. $folder ,
'admin@'.$_SERVER['SERVER_NAME'],
$autobHref,
time()
);
}
public function addAvailable($title, $folder, $siteurl, $rssurl) {
$path = pathinfo( $_SERVER['PHP_SELF'] );
$autobHref = 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'.
$_SERVER["SERVER_NAME"].':'.$_SERVER["SERVER_PORT"]. $path['dirname'].'/'.$folder;
parent::addItem( 'L\'autoblog "'. $title.'" est de nouveau disponible', $autobHref,
'Autoblog : <a href="'. $autobHref .'">'.$title.'</a><br>
Site: <a href="'. $siteurl .'">'. $siteurl .'</a><br>
RSS: <a href="'.$rssurl.'">'.$rssurl.'</a><br>
Folder: '. $folder ,
'admin@'.$_SERVER['SERVER_NAME'],
$autobHref,
time()
);
}
public function addCodeChanged($title, $folder, $siteurl, $rssurl, $code) {
$path = pathinfo( $_SERVER['PHP_SELF'] );
$autobHref = 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'.
$_SERVER["SERVER_NAME"].':'.$_SERVER["SERVER_PORT"]. $path['dirname'].'/'.$folder;
parent::addItem( 'L\'autoblog "'. $title.'" a renvoyé un code imprévu', $autobHref,
'Code: '. $code .'<br>
Autoblog : <a href="'. $autobHref .'">'.$title.'</a><br>
Site: <a href="'. $siteurl .'">'. $siteurl .'</a><br>
RSS: <a href="'.$rssurl.'">'.$rssurl.'</a><br>
Folder: '. $folder ,
'admin@'.$_SERVER['SERVER_NAME'],
$autobHref,
time()
);
}
public function addNewAutoblog($title, $folder, $siteurl, $rssurl) {
$path = pathinfo( $_SERVER['PHP_SELF'] );
$autobHref = 'http'.(!empty($_SERVER['HTTPS'])?'s':'').'://'.
$_SERVER["SERVER_NAME"].':'.$_SERVER["SERVER_PORT"]. $path['dirname'].'/'.$folder;
parent::addItem( 'L\'autoblog "'. $title.'" a été ajouté à la ferme', $autobHref,
'Autoblog : <a href="'. $autobHref .'">'.$title.'</a><br>
Site: <a href="'. $siteurl .'">'. $siteurl .'</a><br>
RSS: <a href="'.$rssurl.'">'.$rssurl.'</a><br>
Folder: '. $folder ,
'admin@'.$_SERVER['SERVER_NAME'],
$autobHref,
time()
);
}
}
?>

View file

@ -1,63 +0,0 @@
body {
padding: 0.3em;
}
h1 {
font-size: 2.2em;
margin: 0.5em;
}
#logo {
height: 145px;
}
.pbloc, .button, .vignette, .thumbshot img {
border-radius: 0.2em;
}
.pbloc {
max-width: 100%;
padding: 0.4em;
margin: 1.2em 0.3em;
}
input, textarea {
width: 450px;
}
#vignette {
text-align: center;
}
.vignette {
text-align: justify;
width: 31%;
margin: 0.3em;
display: inline-block;
float: none;
padding: 0.2em;
height: auto;
}
.thumbshot {
}
.thumbshot img {
width: 200px;
height: 160px;
float: left;
}
.siteDesc {
padding : 0.15em;
max-height: 160px;
overflow:hidden;
text-align:center;
word-wrap: break-word;
}
.source {
text-align: left;
clear:both;
padding : 0.3em;
}

View file

@ -1 +0,0 @@
0.3.0-DEV Build 0

View file

@ -1,174 +0,0 @@
<?php
define('DEBUG', false);
define('XSAF_VERSION', 3);
define('AUTOBLOG_FILE_NAME', 'autoblog.php');
define('ALLOW_REMOTE_DB_DL', false);
define('ALLOW_REMOTE_MEDIA_DL', false);
define('EXEC_TIME', 20);
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() -3600 ;
$lockfile = ".xsaflock"; /* defaut delay: 7200 (2 hours) */
if (file_exists($lockfile) && filemtime($lockfile) > $expire) {
echo "too early";
die;
}
else {
if( file_exists($lockfile) )
unlink($lockfile);
if( file_put_contents($lockfile, date(DATE_RFC822)) ===FALSE) {
echo "Merci d'ajouter des droits d'écriture sur le dossier.";
die;
}
}
define('ROOT_DIR', __DIR__);
if(file_exists("functions.php")){
include "functions.php";
}else{
echo "functions.php not found !";
die;
}
if(file_exists("config.php")){
include "config.php";
}else{
echo "config.php not found !";
die;
}
function serverUrl() {
$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;
}
libxml_use_internal_errors(true);
// $max_exec_time = temps max d'exécution en seconde
function xsafimport($xsafremote, $max_exec_time) {
if( DEBUG )
echo "\n*Traitement $xsafremote en maximum $max_exec_time secondes";
$max_exec_time+=time()-1; // -1 car l'import prend environ 1 seconde
/* détection de ferme autoblog */
$json_import = file_get_contents($xsafremote);
if(!empty($json_import)) {
$to_update=array();
$json_import = json_decode($json_import, true);
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;
}
$get_remote_db = ($json_import['meta']['xsaf-db_transfer'] == "true") ? true : false;
$get_remote_media = ($json_import['meta']['xsaf-media_transfer'] == "true") ? true : false;
if(!empty($json_import['autoblogs'])) {
foreach ($json_import['autoblogs'] as $value) {
if(count($value)==4 && !empty($value['SITE_TYPE']) && !empty($value['SITE_TITLE']) && !empty($value['SITE_URL']) && !empty($value['FEED_URL'])) {
$sitetype = escape($value['SITE_TYPE']);
$sitename = escape($value['SITE_TITLE']);
$siteurl = escape($value['SITE_URL']);
if(empty($value['SITE_META_DESCRIPTION'])){
$siteDesc = getSiteDesc(escape($value['SITE_URL']));
} else {
$siteDesc = escape($value['SITE_META_DESCRIPTION']);
}
// Do not use DetectRedirect because it's slow and it has been used when the feed was added
//$rssurl = DetectRedirect(escape($value['FEED_URL']));
$rssurl = escape($value['FEED_URL']);
}
/* TOO SLOW
$xml = simplexml_load_file($rssurl); // quick feed check
// ATOM feed && RSS 1.0 /RDF && RSS 2.0
$result = (!isset($xml->entry) && !isset($xml->item) && !isset($xml->channel->item)) ? false : true; */
$result = true;
/* autoblog */
if( $result === true ) {
$foldername = urlToFolderSlash($siteurl);
$errors = createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $siteDesc);
foreach( $errors AS $value) {
if( DEBUG )
echo '<p>'. $value .'</p>';
}
if( empty($errors) && DEBUG ) {
echo '<p>autoblog '. $sitename .' crée avec succès (DL DB : '. var_dump($get_remote_db) .' - DL media : '. var_dump($get_remote_media) .') : '. $foldername .'</p>';
if( !ALLOW_REMOTE_DB_DL && !ALLOW_REMOTE_MEDIA_DL )
echo '<iframe width="1" height="1" frameborder="0" src="'. $foldername .'/index.php"></iframe>';
}
/* ============================================================================================================================================================================== */
/* récupération de la DB distante */
if($get_remote_db == true && ALLOW_REMOTE_DB_DL ) {
$remote_db = str_replace("?export", $foldername."/articles.db", $xsafremote);
copy($remote_db, './'. $foldername .'/articles.db');
}
if($get_remote_media == true && ALLOW_REMOTE_MEDIA_DL ) {
$remote_media=str_replace("?export", $foldername."/?media", $xsafremote);
$json_media_import = file_get_contents($remote_media);
if(!empty($json_media_import))
{
mkdir('./'.$foldername.'/media/');
$json_media_import = json_decode($json_media_import, true);
$media_path=$json_media_import['url'];
if(!empty($json_media_import['files'])) {
foreach ($json_media_import['files'] as $value) {
copy($media_path.$value, './'.$foldername.'/media/'.$value);
}
}
}
}
/* ============================================================================================================================================================================== */
//TODO : tester si articles.db est une DB valide
//$to_update[] = serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
}
if( DEBUG )
echo '<p>time : '.($max_exec_time - time()) .'</p>';
if(time() >= $max_exec_time) {
if( DEBUG )
echo "<p>Time out !</p>";
break;
}
}
}
else {
if( DEBUG )
echo "Format JSON incorrect.";
return false;
}
}
return;
}
if( DEBUG ) echo '<html><body>';
if( ALLOW_NEW_AUTOBLOGS and ALLOW_NEW_AUTOBLOGS_BY_XSAF && !empty($friends_autoblog_farm) ) {
foreach( $friends_autoblog_farm AS $value ) {
if( !empty($value) )
xsafimport($value, EXEC_TIME);
}
if(DEBUG) echo "<p>XSAF import finished</p>";
}
elseif( DEBUG )
echo "<p>XSAF désactivé. Positionnez les variables ALLOW_NEW_AUTOBLOGS et ALLOW_NEW_AUTOBLOGS_BY_XSAF à TRUE dans le fichier config.php pour l'activer.</p>";
if( DEBUG ) echo '</body></html>';
?>

31
README.md Normal file → Executable file
View file

@ -1,10 +1,31 @@
Projet-Autoblog
Projet Autoblog
===============
Création, gestion et échange de blogs automatiques contre la censure (à propos: http://sebsauvage.net/streisand.me/fr/ )
Création, gestion et échange de blogs automatiques contre la censure (à propos: http://sebsauvage.net/streisand.me/fr/ ).
- serie 0.1 par Sebsauvage
Serie 0.3 par [Mitsu](https://github.com/mitsukarenai/), [Oros](https://github.com/Oros42), [Arthur Hoaro](https://github.com/ArthurHoaro).
- serie 0.2 par BohwaZ, Arthur Hoaro, Mitsu, Oros
Nouveautés majeures
===================
- serie 0.3 par Mitsu, Oros, Arthur Hoaro
- "ferme" d'autoblogs avec ajout facile par différents formulaires (générique, microblogging, OPML, marque-pages)
- échange de références entre fermes avec XSAF (Cross-Site Autoblog Farming)
- vérification du statut des sites distants, et flux de suivi des changements
- export facile des références, articles et médias
- contrôle de version et alerte de mise à jour
- apparence de l'autoblog selon son type
- CSS utilisateur personnalisable
- hébergement de documents spécifiques
Branches :
===================
- [master](https://github.com/mitsukarenai/Projet-Autoblog/tree/master/) _(développement)_ : Autoblog Project serie 0.3 par Mitsu, Oros, Arthur Hoaro
- [legacy-0.2](https://github.com/mitsukarenai/Projet-Autoblog/tree/legacy-0.2) : version VroumVroumBlog 0.2.11 par BohwaZ (VVB) & Arthur Hoaro, Mitsukarenai, Oros (index ferme d'autoblogs)
- [legacy-0.1](https://github.com/mitsukarenai/Projet-Autoblog/tree/legacy-0.1) : version VroumVroumBlog 0.1.32 par Sebastien Sauvage
- [legacy-0.2to0.3](https://github.com/mitsukarenai/Projet-Autoblog/tree/legacy-0.2to0.3) : script de migration 0.2 to 0.3 par Oros et Arthur Hoaro
Pré-requis techniques
=====================
- serveur web avec PHP 5.3 et son support SQLite

View file

@ -499,11 +499,11 @@ class VroumVroum_Blog
$from['path'] = '';
}
preg_match_all('!(src|href)\s*=\s*[\'"]?([^"\'<>\s]+\.(?:'.$extensions.'))[\'"]?!i', $content, $match, PREG_SET_ORDER);
preg_match_all('!(src|href)\s*=\s*[\'"]?([^"\'<>\s]+\.(?:'.$extensions.')[\'"])[\'"]?!i', $content, $match, PREG_SET_ORDER);
foreach ($match as $m)
{
$url = parse_url($m[2]);
$url = parse_url(substr($m[2], 0, -1));
if (empty($url['scheme']))
$url['scheme'] = $from['scheme'];

View file

@ -18,7 +18,7 @@ define( 'ALLOW_CHECK_UPDATE', TRUE );
/**
* If you set ALLOW_NEW_AUTOBLOGS to FALSE, the following options do not matter.
**/
define( 'ALLOW_NEW_AUTOBLOGS', FALSE );
define( 'ALLOW_NEW_AUTOBLOGS', false );
// define( 'ALLOW_NEW_AUTOBLOGS_BY_LINKS', TRUE );
// define( 'ALLOW_NEW_AUTOBLOGS_BY_SOCIAL', TRUE );
// define( 'ALLOW_NEW_AUTOBLOGS_BY_BUTTON', TRUE );
@ -42,5 +42,5 @@ $friends_autoblog_farm = array(
);
$myOptions['enableThumbShot'] = true;
$myOptions['externalThumbSdhot'] = 'http://soshot.local/?key=a2b860fcd656&&s=m&url=';
$myOptions['externalThumbSdhot'] = 'http://soshot.knah-tsaeb.org/?key=3400affe9919&s=m&url=';
?>

4
docs/docs.txt Normal file
View file

@ -0,0 +1,4 @@
You can manually add files in the /docs/ directory, such as PDF, docs, images, etc.
You can also add subfolders in /docs/ for website mirroring. Be sure that your subfolder contains a file named index.html.
Delete this file to hide the 'Autres documents' block in your autoblogs homepage.

View file

@ -12,7 +12,7 @@ define('LOCAL_URI', '');
if (!defined('AUTOBLOGS_FOLDER')) define('AUTOBLOGS_FOLDER', './autoblogs/');
if (!defined('DOC_FOLDER')) define('DOC_FOLDER', './docs/');
if (!defined('RESOURCES_FOLDER')) define('RESOURCES_FOLDER', './resources/');
if (!defined('RSS_FILE')) define('RSS_FILE', RESOURCES_FOLDER.'rss.xml');
if (!defined('FOLDER_MAX_LENGTH')) define('FOLDER_MAX_LENGTH', 80);
date_default_timezone_set('Europe/Paris');
setlocale(LC_TIME, 'fr_FR.UTF-8', 'fr_FR', 'fr');
@ -35,7 +35,9 @@ if( !defined('LOGO')) define( 'LOGO', 'icon-logo.svg' );
if( !defined('HEAD_TITLE')) define( 'HEAD_TITLE', '');
if( !defined('FOOTER')) define( 'FOOTER', 'D\'après les premières versions de <a href="http://sebsauvage.net">SebSauvage</a> et <a href="http://bohwaz.net/">Bohwaz</a>.');
// Functions
/**
* Functions
**/
function NoProtocolSiteURL($url) {
$protocols = array("http://", "https://");
$siteurlnoproto = str_replace($protocols, "", $url);
@ -56,15 +58,17 @@ function NoProtocolSiteURL($url) {
function DetectRedirect($url)
{
if(parse_url($url, PHP_URL_HOST)==FALSE) {
//die('Not a URL');
throw new Exception('Not a URL: '. escape ($url) );
}
$response = get_headers($url, 1);
try { $response = get_headers($url, 1); }
catch (Exception $e) { throw new Exception('RSS URL unreachable: '. escape($url) ); }
if(!empty($response['Location'])) {
$response2 = get_headers($response['Location'], 1);
try { $response2 = get_headers($response['Location'], 1); }
catch (Exception $e) { throw new Exception('RSS URL unreachable: '. escape($url) ); }
if(!empty($response2['Location'])) {
//die('too much redirection');
throw new Exception('too much redirection: '. escape ($url) );
throw new Exception('Too much redirection: '. escape ($url) );
}
else { return $response['Location']; }
}
@ -73,16 +77,16 @@ function DetectRedirect($url)
}
}
function urlToFolder($url) {
return sha1(NoProtocolSiteURL($url));
function urlHash($rssurl) {
return sha1(NoProtocolSiteURL($rssurl));
}
function urlToFolderSlash($url) {
return sha1(NoProtocolSiteURL($url).'/');
function urlToFolder($siteurl, $rssurl) {
return AUTOBLOGS_FOLDER . substr(preg_replace("/[^a-z0-9]/", '', strtolower(NoProtocolSiteURL($siteurl))), 0, FOLDER_MAX_LENGTH) .'_'. urlHash($rssurl) .'/';
}
function folderExists($url) {
return file_exists(AUTOBLOGS_FOLDER . urlToFolder($url)) || file_exists(AUTOBLOGS_FOLDER . urlToFolderSlash($url));
function folderExists($siteurl, $rssurl) {
return file_exists(urlToFolder($siteurl, $rssurl));
}
function escape($str) {
@ -116,29 +120,18 @@ function createAutoblog($type, $sitename, $siteurl, $rssurl, $siteDesc, $error =
}
}
if(folderExists($siteurl)) {
$error[] = 'Erreur : l\'autoblog '. $sitename .' existe déjà.';
return $error;
if(folderExists($siteurl, $rssurl)) {
throw new Exception('Erreur : l\'autoblog '. $sitename .' existe déjà.');
}
$foldername = AUTOBLOGS_FOLDER . urlToFolderSlash($siteurl);
$foldername = urlToFolder($siteurl, $rssurl);
if ( mkdir($foldername, 0755, false) ) {
/**
* RSS
**/
try {
require_once('class_rssfeed.php');
$rss = new AutoblogRSS(RSS_FILE);
$rss->addNewAutoblog($sitename, $foldername, $siteurl, $rssurl);
}
catch (Exception $e) {
;
}
$fp = fopen($foldername .'/index.php', 'w+');
if( !fwrite($fp, "<?php require_once '../autoblog.php'; ?>") )
$error[] = "Impossible d'écrire le fichier index.php";
throw new Exception('Impossible d\'écrire le fichier index.php');
fclose($fp);
$fp = fopen($foldername .'/vvb.ini', 'w+');
@ -152,13 +145,13 @@ FEED_URL="'. $rssurl .'"
ARTICLES_PER_PAGE="'. getArticlesPerPage( $type ) .'"
UPDATE_INTERVAL="'. getInterval( $type ) .'"
UPDATE_TIMEOUT="'. getTimeout( $type ) .'"') )
$error[] = "Impossible d'écrire le fichier vvb.ini";
throw new Exception('Impossible d\'écrire le fichier vvb.ini');
fclose($fp);
}
else
$error[] = "Impossible de créer le répertoire.";
throw new Exception('Impossible de créer le répertoire.');
return $error;
updateXML('new_autoblog_added', 'new', $foldername, $sitename, $siteurl, $rssurl);
}
function getArticlesPerPage( $type ) {
@ -272,4 +265,69 @@ function __($str)
return $str;
}
}
function updateXML($status, $response_code, $autoblog_url, $autoblog_title, $autoblog_sourceurl, $autoblog_sourcefeed)
{
$json = json_decode(file_get_contents(RESOURCES_FOLDER.'rss.json'), true);
$json[] = array(
'timestamp'=>time(),
'autoblog_url'=>$autoblog_url,
'autoblog_title'=>$autoblog_title,
'autoblog_sourceurl'=>$autoblog_sourceurl,
'autoblog_sourcefeed'=>$autoblog_sourcefeed,
'status'=>$status,
'response_code'=>$response_code
);
if(file_put_contents(RESOURCES_FOLDER.'rss.json', json_encode($json), LOCK_EX) === FALSE)
{ return FALSE; }
else { return TRUE; }
}
function displayXMLstatus($status, $response_code, $autoblog_url, $autoblog_title, $autoblog_sourceurl, $autoblog_sourcefeed) {
switch ($status)
{
case 'unavailable':
return 'Autoblog "'.$autoblog_title.'": site distant inaccessible (code '.$response_code.')<br>Autoblog: <a href="'. serverUrl(false).AUTOBLOGS_FOLDER.$autoblog_url.'">'.$autoblog_title.'</a><br>Site: <a href="'. $autoblog_sourceurl .'">'. $autoblog_sourceurl .'</a><br>RSS: <a href="'.$autoblog_sourcefeed.'">'.$autoblog_sourcefeed.'</a>';
case 'moved':
return 'Autoblog "'.$autoblog_title.'": site distant redirigé (code '.$response_code.')<br>Autoblog: <a href="'. serverUrl(false).AUTOBLOGS_FOLDER.$autoblog_url.'">'.$autoblog_title.'</a><br>Site: <a href="'. $autoblog_sourceurl .'">'. $autoblog_sourceurl .'</a><br>RSS: <a href="'.$autoblog_sourcefeed.'">'.$autoblog_sourcefeed.'</a>';
case 'not_found':
return 'Autoblog "'.$autoblog_title.'": site distant introuvable (code '.$response_code.')<br>Autoblog: <a href="'. serverUrl(false).AUTOBLOGS_FOLDER.$autoblog_url.'">'.$autoblog_title.'</a><br>Site: <a href="'. $autoblog_sourceurl .'">'. $autoblog_sourceurl .'</a><br>RSS: <a href="'.$autoblog_sourcefeed.'">'.$autoblog_sourcefeed.'</a>';
case 'remote_error':
return 'Autoblog "'.$autoblog_title.'": site distant a problème serveur (code '.$response_code.')<br>Autoblog: <a href="'. serverUrl(false).AUTOBLOGS_FOLDER.$autoblog_url.'">'.$autoblog_title.'</a><br>Site: <a href="'. $autoblog_sourceurl .'">'. $autoblog_sourceurl .'</a><br>RSS: <a href="'.$autoblog_sourcefeed.'">'.$autoblog_sourcefeed.'</a>';
case 'available':
return 'Autoblog "'.$autoblog_title.'": site distant à nouveau opérationnel (code '.$response_code.')<br>Autoblog: <a href="'. serverUrl(false).AUTOBLOGS_FOLDER.$autoblog_url.'">'.$autoblog_title.'</a><br>Site: <a href="'. $autoblog_sourceurl .'">'. $autoblog_sourceurl .'</a><br>RSS: <a href="'.$autoblog_sourcefeed.'">'.$autoblog_sourcefeed.'</a>';
case 'new_autoblog_added':
return 'Autoblog "'.$autoblog_title.'" ajouté (code '.$response_code.')<br>Autoblog: <a href="'. serverUrl(false).AUTOBLOGS_FOLDER.$autoblog_url.'">'.$autoblog_title.'</a><br>Site: <a href="'. $autoblog_sourceurl .'">'. $autoblog_sourceurl .'</a><br>RSS: <a href="'.$autoblog_sourcefeed.'">'.$autoblog_sourcefeed.'</a>';
}
}
function displayXML() {
header('Content-type: application/rss+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><link>'.serverUrl(true).'</link>';
echo '<atom:link href="'.serverUrl(false) . '/?rss" rel="self" type="application/rss+xml"/><title>Projet Autoblog'. ((strlen(HEAD_TITLE)>0) ? ' | '. HEAD_TITLE : '').'</title><description>'.serverUrl(true),"Projet Autoblog - RSS : Ajouts et changements de disponibilité.".'</description>';
if(file_exists(RESOURCES_FOLDER.'rss.json'))
{
$json = json_decode(file_get_contents(RESOURCES_FOLDER.'rss.json'), true);
rsort($json);
foreach ($json as $item)
{
$description = displayXMLstatus($item['status'],$item['response_code'],$item['autoblog_url'],$item['autoblog_title'],$item['autoblog_sourceurl'],$item['autoblog_sourcefeed']);
$link = serverUrl(true).AUTOBLOGS_FOLDER.$item['autoblog_url'];
$date = date("r", $item['timestamp']);
print <<<EOT
<item>
<title>{$item['autoblog_title']}</title>
<description><![CDATA[{$description}]]></description>
<link>{$link}</link>
<guid isPermaLink="false">{$item['timestamp']}</guid>
<author>admin@{$_SERVER['SERVER_NAME']}</author>
<pubDate>{$date}</pubDate>
</item>
EOT;
}
}
echo '</channel></rss>';
}
?>

View file

@ -105,21 +105,31 @@ function check_antibot($number, $text_number) {
function create_from_opml($opml) {
global $error, $success;
$cpt = 0;
foreach( $opml->body->outline as $outline ) {
if ( !empty( $outline['title'] ) && !empty( $outline['text'] ) && !empty( $outline['xmlUrl']) && !empty( $outline['htmlUrl'] )) {
try {
$rssurl = DetectRedirect(escape( $outline['xmlUrl']));
$sitename = escape( $outline['title'] );
$siteurl = escape($outline['htmlUrl']);
$sitetype = escape($outline['text']); if ( $sitetype == 'generic' or $sitetype == 'microblog' or $sitetype == 'shaarli') { } else { $sitetype = 'generic'; }
// Lighten process by checking folderExists first
// A CHANGER SELON ISSUE #20
if(folderExists($siteurl))
throw new Exception('Erreur : l\'autoblog '. $sitename .' existe déjà.');
$sitetype = escape($outline['text']);
if ( $sitetype != 'microblog' && $sitetype != 'shaarli' && $sitetype != 'twitter' && $sitetype != 'identica' )
$sitetype = 'generic';
$siteDesc = getSiteDesc(escape($siteurl));
$rssurl = DetectRedirect(escape($outline['xmlUrl']));
$error = array_merge( $error, createAutoblog( $sitetype, $sitename, $siteurl, $rssurl, $siteDesc, $error ) );
createAutoblog( $sitetype, $sitename, $siteurl, $rssurl, $siteDesc, $error );
if( empty ( $error ))
$success[] = '<iframe width="1" height="1" frameborder="0" src="'. AUTOBLOGS_FOLDER . urlToFolderSlash( $siteurl ) .'/index.php"></iframe>Autoblog "'. $sitename .'" crée avec succès. &rarr; <a target="_blank" href="'. urlToFolderSlash( $siteurl ) .'">afficher l\'autoblog</a>.';
$message = 'Autoblog "'. $sitename .'" crée avec succès. &rarr; <a target="_blank" href="'. urlToFolder( $siteurl, $rssurl ) .'">afficher l\'autoblog</a>.';
// Do not print iframe on big import (=> heavy and useless)
if( ++$cpt < 10 )
$message .= '<iframe width="1" height="1" frameborder="0" src="'. urlToFolder( $siteurl, $rssurl ) .'/index.php"></iframe>';
$success[] = $message;
}
catch (Exception $e) {
$error[] = $e->getMessage();
@ -133,7 +143,7 @@ function create_from_opml($opml) {
**/
function versionCheck() {
$versionfile = 'version';
$lastestUrl = 'https://raw.github.com/mitsukarenai/Projet-Autoblog/master/0.3/version';
$lastestUrl = 'https://raw.github.com/mitsukarenai/Projet-Autoblog/master/version';
$expire = time() - 84600 ; // 23h30 en secondes
$lockfile = '.versionlock';
@ -161,16 +171,14 @@ function versionCheck() {
/**
* RSS Feed
*
**/
if( !file_exists(RSS_FILE)) {
require_once('class_rssfeed.php');
$rss = new AutoblogRSS(RSS_FILE);
$rss->create('Projet Autoblog'. ((strlen(HEAD_TITLE)>0) ? ' | '. HEAD_TITLE : ''), serverUrl(true),"Projet Autoblog - RSS : Ajouts et changements de disponibilité.", serverUrl(true) . RSS_FILE);
if( !file_exists(RESOURCES_FOLDER.'rss.json')) {
file_put_contents(RESOURCES_FOLDER.'rss.json', '', LOCK_EX);
}
if (isset($_GET['rss'])) {
require_once('class_rssfeed.php');
$rss = new AutoblogRSS(RSS_FILE);
$rss->displayXML();
displayXML();
die;
}
@ -215,9 +223,7 @@ if (isset($_GET['check']))
/* le flux est indisponible (typiquement: erreur DNS ou possible censure) - à vérifier */
if(empty($headers) || $headers === FALSE ) {
if( $oldvalue !== null && $oldvalue != '..' ) {
require_once('class_rssfeed.php');
$rss = new AutoblogRSS(RSS_FILE);
$rss->addUnavailable($ini['SITE_TITLE'], escape($_GET['check']), $ini['SITE_URL'], $ini['FEED_URL']);
updateXML('unavailable', 'nxdomain', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']);
}
file_put_contents($errorlog, '..');
die($svg_rouge);
@ -226,9 +232,7 @@ if (isset($_GET['check']))
/* code retour 200: flux disponible */
if($code[1] == "200") {
if( $oldvalue !== null && $oldvalue != '' ) {
require_once('class_rssfeed.php');
$rss = new AutoblogRSS(RSS_FILE);
$rss->addAvailable($ini['SITE_TITLE'], escape($_GET['check']), $ini['SITE_URL'], $ini['FEED_URL']);
updateXML('available', '200', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']);
}
file_put_contents($errorlog, '');
die($svg_vert);
@ -236,9 +240,7 @@ if (isset($_GET['check']))
/* autre code retour: un truc a changé (redirection, changement de CMS, .. bref vvb.ini doit être corrigé) */
else {
if( $oldvalue !== null && $oldvalue != '.' ) {
require_once('class_rssfeed.php');
$rss = new AutoblogRSS(RSS_FILE);
$rss->addCodeChanged($ini['SITE_TITLE'], escape($_GET['check']), $ini['SITE_URL'], $ini['FEED_URL'], $code[1]);
updateXML('moved', '3xx', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']);
}
file_put_contents($errorlog, '.');
die($svg_jaune);
@ -344,7 +346,6 @@ if (isset($_GET['exportopml'])) // OPML
/**
* Site map
* NEW AUTOBLOG FOLDER - Need update
**/
if (isset($_GET['sitemap']))
{
@ -428,10 +429,10 @@ if(!empty($_GET['via_button']) && $_GET['number'] === '17' && ALLOW_NEW_AUTOBLOG
$sitetype = $sitetype['type'];
$siteDesc = getSiteDesc(escape($_GET['siteDesc']));
$error = array_merge( $error, createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $siteDesc, $error));
createAutoblog( $sitetype, $sitename, $siteurl, $rssurl, $siteDesc, $error);
if( empty($error)) {
$form .= '<iframe width="1" height="1" frameborder="0" src="'. AUTOBLOGS_FOLDER . urlToFolderSlash($siteurl) .'/index.php"></iframe>';
$form .= '<p><span style="color:darkgreen">Autoblog <a href="'. AUTOBLOGS_FOLDER . urlToFolderSlash($siteurl) .'">'. $sitename .'</a> ajouté avec succès.</span><br>';
$form .= '<iframe width="1" height="1" frameborder="0" src="'. urlToFolder( $siteurl, $rssurl ) .'/index.php"></iframe>';
$form .= '<p><span style="color:darkgreen">Autoblog <a href="'. urlToFolder( $siteurl, $rssurl ) .'">'. $sitename .'</a> ajouté avec succès.</span><br>';
}
else {
$form .= '<ul>';
@ -482,26 +483,28 @@ if(!empty($_GET['via_button']) && $_GET['number'] === '17' && ALLOW_NEW_AUTOBLOG
/**
* ADD BY SOCIAL / SHAARLI
**/
if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_SOCIAL)
{
if( !empty($_POST['number']) && !empty($_POST['antibot']) && check_antibot($_POST['number'], $_POST['antibot']) ) {
if( !empty($_POST['socialinstance']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_SOCIAL)
{;
$socialinstance = strtolower(escape($_POST['socialinstance']));
$socialaccount = (!empty($_POST['socialaccount'])) ? strtolower(escape($_POST['socialaccount'])) : false;
if( $socialaccount === false && $socialinstance !== 'shaarli')
$error[] = 'Le compte social doit être renseigné.';
$socialaccount = strtolower(escape($_POST['socialaccount']));
$socialinstance = strtolower(escape($_POST['socialinstance']));
if( !empty($_POST['number']) && !empty($_POST['antibot']) && check_antibot($_POST['number'], $_POST['antibot']) && empty($error)) {
if($socialinstance === 'twitter') {
if( API_TWITTER !== FALSE ) {
$sitetype = 'twitter';
$siteurl = "http://twitter.com/$socialaccount";
$siteurl = 'http://twitter.com/'. $socialaccount;
$rssurl = API_TWITTER.$socialaccount;
}
else
$error[] = "Twitter veut mettre à mort son API ouverte. Du coup on peut plus faire ça comme ça.";
$error[] = 'Vous devez définir une API Twitter -> RSS dans votre fichier de configuration (see <a href="https://github.com/mitsukarenai/twitterbridge">TwitterBridge</a>).';
}
elseif($socialinstance === 'identica') {
$sitetype = 'identica';
$siteurl = "http://identi.ca/$socialaccount";
$rssurl = "http://identi.ca/api/statuses/user_timeline/$socialaccount.rss";
$siteurl = 'http://identi.ca/'.$socialaccount;
$rssurl = 'http://identi.ca/api/statuses/user_timeline/'.$socialaccount.'.rss';
}
elseif($socialinstance === 'statusnet' && !empty($_POST['statusneturl'])) {
$sitetype = 'microblog';
@ -527,18 +530,25 @@ if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']) && ALLOW_
$socialaccount = get_title_from_feed($rssurl);
}
if( empty($error) ) {
// Twitterbridge do NOT allow this user yet => No check
if( $sitetype != 'twitter' ) {
$headers = get_headers($rssurl, 1);
if (strpos($headers[0], '200') == FALSE) {
$error[] = "Flux inaccessible (compte inexistant ?)";
try {
// TwitterBridge user will be allowed after Autoblog creation
// TODO: Twitter user does not exist ?
// TODO: get remote like http://wwz.suumitsu.eu/twitter/whitelist.json, decode, check if is in array, return error or continue
if($sitetype != 'twitter') {
$headers = get_headers($rssurl, 1);
if (strpos($headers[0], '200') === FALSE)
throw new Exception('Flux inaccessible (compte inexistant ?)');
}
createAutoblog($sitetype, ucfirst($socialinstance) .' - '. $socialaccount, $siteurl, $rssurl);
$success[] = '<iframe width="1" height="1" frameborder="0" src="'. urlToFolder( $siteurl, $rssurl ) .'/index.php"></iframe>
<b style="color:darkgreen">'.ucfirst($socialinstance) .' - '. $socialaccount.' <a href="'. urlToFolder( $siteurl, $rssurl ) .'">ajouté avec succès</a>.</b>';
}
if( empty($error) ) {
$error = array_merge( $error, createAutoblog($sitetype, ucfirst($socialinstance) .' - '. $socialaccount, $siteurl, $rssurl,$siteDesc, $error));
if( empty($error))
$success[] = '<iframe width="1" height="1" frameborder="0" src="'. AUTOBLOGS_FOLDER . urlToFolderSlash( $siteurl ) .'/index.php"></iframe><b style="color:darkgreen">'.ucfirst($socialinstance) .' - '. $socialaccount.' <a href="'.urlToFolderSlash( $siteurl ).'">ajouté avec succès</a>.</b>';
catch (Exception $e) {
echo $error[] = $e->getMessage();
}
}
}
@ -567,10 +577,10 @@ if( !empty($_POST['generic']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_L
$sitename = get_title_from_feed($rssurl);
$siteDesc = escape($_POST['siteDesc']);
$error = array_merge( $error, createAutoblog('generic', $sitename, $siteurl, $rssurl, $siteDesc, $error));
createAutoblog('generic', $sitename, $siteurl, $rssurl, $siteDesc, $error);
if( empty($error))
$success[] = '<iframe width="1" height="1" frameborder="0" src="'. AUTOBLOGS_FOLDER . urlToFolderSlash( $siteurl ) .'/index.php"></iframe><b style="color:darkgreen">Autoblog '. $sitename .' crée avec succès.</b> &rarr; <a target="_blank" href="'. AUTOBLOGS_FOLDER . urlToFolderSlash( $siteurl ) .'">afficher l\'autoblog</a>';
$success[] = '<iframe width="1" height="1" frameborder="0" src="'. urlToFolder( $siteurl, $rssurl ) .'/index.php"></iframe>
<b style="color:darkgreen">Autoblog '. $sitename .' crée avec succès.</b> &rarr; <a target="_blank" href="'. urlToFolder( $siteurl, $rssurl ) .'">afficher l\'autoblog</a>';
}
else {
// checking procedure
@ -584,7 +594,7 @@ if( !empty($_POST['generic']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_L
$sitename = get_title_from_datafeed($datafeed);
$siteDesc = getSiteDesc(escape($siteurl));
$form = '<span style="color:blue">Merci de vérifier les informations suivantes, corrigez si nécessaire.</span><br>
$form = '<span style="color:blue">Merci de vérifier les informations suivantes, corrigez si nécessaire. Tous les champs doivent être renseignés.</span><br>
<form method="POST"><input type="hidden" name="generic" value="1" />
<input style="color:black" type="text" id="sitename" value="'.$sitename.'" '.( $datafeed === false?'':'disabled').'><label for="sitename">&larr; titre du site (auto)</label><br>
<input placeholder="Adresse du site" type="text" name="siteurl" id="siteurl" value="'.$siteurl.'"><label for="siteurl">&larr; page d\'accueil (auto)</label><br>
@ -658,7 +668,7 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
<head>
<meta charset="utf-8">
<title>Projet Autoblog<?php if(strlen(HEAD_TITLE)>0) echo " | " . HEAD_TITLE; ?></title>
<link rel="alternate" type="application/rss+xml" title="RSS" href="<?php echo serverUrl(true) . RSS_FILE;?>" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="<?php echo serverUrl(false) . '/?rss';?>" />
<link href="<?php echo RESOURCES_FOLDER; ?>autoblog.css" rel="stylesheet" type="text/css">
<?php
if(file_exists(RESOURCES_FOLDER .'user.css')){
@ -673,10 +683,10 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
</a></h1>
<div class="pbloc">
<?php
if (defined('LOGO'))
echo '<img id="logo" src="'. RESOURCES_FOLDER . LOGO .'" alt="">';
?>
<?php
if (defined('LOGO'))
echo '<img id="logo" src="'. RESOURCES_FOLDER . LOGO .'" alt="">';
?>
<h2>Présentation</h2>
<p>
@ -689,6 +699,11 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
Voici une liste d'autoblogs hébergés sur <i><?php echo $_SERVER['SERVER_NAME']; ?></i>
(<a href="http://sebsauvage.net/streisand.me/fr/">plus d'infos sur le projet</a>).
</p>
<p>
<b>Autres fermes</b>
&rarr; <a href="https://duckduckgo.com/?q=!g%20%22Voici%20une%20liste%20d'autoblogs%20hébergés%22">Rechercher</a>
</p>
</div>
<?php if( $update_available ) { ?>
@ -770,7 +785,7 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
<h3>Ajouter un Shaarli</h3>
<form method="POST">
<input type="hidden" name="socialaccount" value="shaarli">
<input type="hidden" name="socialinstance" value="shaarli">
<input placeholder="shaarli.personnel.com" type="text" name="shaarliurl" id="shaarliurl"><br>
<input placeholder="Antibot : Ecrivez '<?php echo $antibot; ?>' en chiffres" type="text" name="number" class="smallinput"><br>
<input type="hidden" name="antibot" value="<?php echo $antibot; ?>" />
@ -844,10 +859,6 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
<div class="pbloc">
<h2>Autoblogs hébergés <a href="?rss" title="RSS des changements"><img src="<?php echo RESOURCES_FOLDER; ?>rss.png" alt="rss"/></a></h2>
<p>
<b>Autres fermes</b>
&rarr; <a href="https://duckduckgo.com/?q=!g%20%22Voici%20une%20liste%20d'autoblogs%20hébergés%22">Rechercher</a>
</p>
<div class="clear"><a href="?sitemap">sitemap</a> | <a href="?export">export<sup> JSON</sup></a> | <a href="?exportopml">export<sup> OPML</sup></a></div>
<div id="contentVignette">
@ -859,6 +870,7 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
if(is_dir($unit))
{
if( !file_exists(ROOT_DIR . '/' . $unit . '/.disabled')) {
if( file_exists(ROOT_DIR . '/' . $unit . '/vvb.ini')) {
$ini = parse_ini_file(ROOT_DIR . '/' . $unit . '/vvb.ini');
if($ini)
{
@ -872,6 +884,7 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
$autoblogs[$unit] = $config;
unset($ini);
}
}
}
}
}
@ -910,15 +923,15 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
<script type="text/javascript">
<?php if( !empty($_POST['generic']) && !empty($_POST['siteurl']) || empty($_POST['generic']) )
echo "document.getElementById('add_generic').style.display = 'none';"; ?>
document.getElementById('add_social').style.display = 'none';
document.getElementById('add_shaarli').style.display = 'none';
document.getElementById('add_opmlfile').style.display = 'none';
document.getElementById('add_bookmark').style.display = 'none';
document.getElementById('add_opmllink').style.display = 'none';
document.getElementById('button_list').style.display = 'block';
if(document.getElementById('add_social') != null) { document.getElementById('add_social').style.display = 'none'; }
if(document.getElementById('add_shaarli') != null) { document.getElementById('add_shaarli').style.display = 'none'; }
if(document.getElementById('add_opmlfile') != null) { document.getElementById('add_opmlfile').style.display = 'none'; }
if(document.getElementById('add_bookmark') != null) { document.getElementById('add_bookmark').style.display = 'none'; }
if(document.getElementById('add_opmllink') != null) { document.getElementById('add_opmllink').style.display = 'none'; }
if(document.getElementById('button_list') != null) { document.getElementById('button_list').style.display = 'block'; }
function show_form(str){
document.getElementById('add_'+str).style.display = (document.getElementById('add_'+str).style.display != 'block' ? 'block' : 'none' );
document.getElementById('button_'+str).className = (document.getElementById('button_'+str).className != 'buttonactive' ? 'buttonactive' : 'button' );
document.getElementById('button_'+str).className = (document.getElementById('button_'+str).className != 'buttonactive' ? 'buttonactive' : 'button' );
}
</script>

View file

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View file

Before

Width:  |  Height:  |  Size: 691 B

After

Width:  |  Height:  |  Size: 691 B

1
version Executable file
View file

@ -0,0 +1 @@
0.3.0-DEV Build 1

177
xsaf3.php Executable file
View file

@ -0,0 +1,177 @@
<?php
define('DEBUG', false);
define('XSAF_VERSION', 3);
define('AUTOBLOG_FILE_NAME', 'autoblog.php');
define('ALLOW_REMOTE_DB_DL', false);
define('ALLOW_REMOTE_MEDIA_DL', false);
define('EXEC_TIME', 20);
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) */
if (file_exists($lockfile) && filemtime($lockfile) > $expire) {
echo "too early";
die;
}
else {
if( file_exists($lockfile) )
unlink($lockfile);
if( file_put_contents($lockfile, date(DATE_RFC822)) ===FALSE) {
echo "Merci d'ajouter des droits d'écriture sur le dossier.";
die;
}
}
define('ROOT_DIR', __DIR__);
if(file_exists("functions.php")){
include "functions.php";
}else{
echo "functions.php not found !";
die;
}
if(file_exists("config.php")){
include "config.php";
}else{
echo "config.php not found !";
die;
}
function serverUrl() {
$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;
}
libxml_use_internal_errors(true);
// $max_exec_time = temps max d'exécution en seconde
function xsafimport($xsafremote, $max_exec_time) {
if( DEBUG )
echo "\n*Traitement $xsafremote en maximum $max_exec_time secondes";
$max_exec_time+=time()-1; // -1 car l'import prend environ 1 seconde
/* détection de ferme autoblog */
$json_import = file_get_contents($xsafremote);
if(!empty($json_import)) {
$to_update=array();
$json_import = json_decode($json_import, true);
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;
}
$get_remote_db = ($json_import['meta']['xsaf-db_transfer'] == "true") ? true : false;
$get_remote_media = ($json_import['meta']['xsaf-media_transfer'] == "true") ? true : false;
if(!empty($json_import['autoblogs'])) {
foreach ($json_import['autoblogs'] as $value) {
if(count($value)==4 && !empty($value['SITE_TYPE']) && !empty($value['SITE_TITLE']) && !empty($value['SITE_URL']) && !empty($value['FEED_URL'])) {
$sitetype = escape($value['SITE_TYPE']);
$sitename = escape($value['SITE_TITLE']);
$siteurl = escape($value['SITE_URL']);
if(empty($value['SITE_META_DESCRIPTION'])){
$siteDesc = getSiteDesc(escape($value['SITE_URL']));
} else {
$siteDesc = escape($value['SITE_META_DESCRIPTION']);
}
// Do not use DetectRedirect because it's slow and it has been used when the feed was added
//$rssurl = DetectRedirect(escape($value['FEED_URL']));
$rssurl = escape($value['FEED_URL']);
}
/* TOO SLOW
$xml = simplexml_load_file($rssurl); // quick feed check
// ATOM feed && RSS 1.0 /RDF && RSS 2.0
$result = (!isset($xml->entry) && !isset($xml->item) && !isset($xml->channel->item)) ? false : true; */
$result = true;
/* autoblog */
if( $result === true ) {
$foldername = urlToFolder($sitename, $rssurl);
try {
createAutoblog($sitetype, $sitename, $siteurl, $rssurl,$siteDesc);
if( DEBUG ) {
echo '<p>autoblog '. $sitename .' crée avec succès (DL DB : '. var_dump($get_remote_db) .' - DL media : '. var_dump($get_remote_media) .') : '. $foldername .'</p>';
if( !ALLOW_REMOTE_DB_DL && !ALLOW_REMOTE_MEDIA_DL )
echo '<iframe width="1" height="1" frameborder="0" src="'. urlToFolder( $siteurl, $rssurl ) .'/index.php"></iframe>';
}
/* ============================================================================================================================================================================== */
/* récupération de la DB distante */
if($get_remote_db == true && ALLOW_REMOTE_DB_DL ) {
$remote_db = str_replace("?export", $foldername."/articles.db", $xsafremote);
copy($remote_db, './'. $foldername .'/articles.db');
}
if($get_remote_media == true && ALLOW_REMOTE_MEDIA_DL ) {
$remote_media=str_replace("?export", $foldername."/?media", $xsafremote);
$json_media_import = file_get_contents($remote_media);
if(!empty($json_media_import))
{
mkdir('./'.$foldername.'/media/');
$json_media_import = json_decode($json_media_import, true);
$media_path=$json_media_import['url'];
if(!empty($json_media_import['files'])) {
foreach ($json_media_import['files'] as $value) {
copy($media_path.$value, './'.$foldername.'/media/'.$value);
}
}
}
}
/* ============================================================================================================================================================================== */
//TODO : tester si articles.db est une DB valide
//$to_update[] = serverUrl().preg_replace("/(.*)\/(.*)$/i","$1/".$foldername , $_SERVER['SCRIPT_NAME']); // url of the new autoblog
}
catch (Exception $e) {
if( DEBUG )
echo $e->getMessage();
}
}
if( DEBUG )
echo '<p>time : '.($max_exec_time - time()) .'</p>';
if(time() >= $max_exec_time) {
if( DEBUG )
echo "<p>Time out !</p>";
break;
}
}
}
else {
if( DEBUG )
echo "Format JSON incorrect.";
return false;
}
}
return;
}
if( DEBUG ) echo '<html><body>';
if( ALLOW_NEW_AUTOBLOGS and ALLOW_NEW_AUTOBLOGS_BY_XSAF && !empty($friends_autoblog_farm) ) {
foreach( $friends_autoblog_farm AS $value ) {
if( !empty($value) )
xsafimport($value, EXEC_TIME);
}
if(DEBUG) echo "<p>XSAF import finished</p>";
}
elseif( DEBUG )
echo "<p>XSAF désactivé. Positionnez les variables ALLOW_NEW_AUTOBLOGS et ALLOW_NEW_AUTOBLOGS_BY_XSAF à TRUE dans le fichier config.php pour l'activer.</p>";
if( DEBUG ) echo '</body></html>';
?>