2013-02-18 19:42:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function NoProtocolSiteURL($url) {
|
2013-02-23 20:18:22 +01:00
|
|
|
$protocols = array("http://", "https://");
|
|
|
|
$siteurlnoproto = str_replace($protocols, "", $url);
|
|
|
|
|
2013-02-18 19:42:10 +01:00
|
|
|
// Remove the / at the end of string
|
|
|
|
if ( $siteurlnoproto[strlen($siteurlnoproto) - 1] == '/' )
|
|
|
|
$siteurlnoproto = substr($siteurlnoproto, 0, -1);
|
2013-02-23 20:18:22 +01:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2013-02-18 19:42:10 +01:00
|
|
|
return $siteurlnoproto;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function DetectRedirect($url)
|
|
|
|
{
|
2013-03-04 21:40:43 +01:00
|
|
|
if(parse_url($url, PHP_URL_HOST)==FALSE) {
|
2013-03-10 14:48:29 +01:00
|
|
|
//die('Not a URL');
|
|
|
|
return array( 'error' => 'Not a URL: '. escape ($url) );
|
2013-03-04 21:40:43 +01:00
|
|
|
}
|
2013-02-18 19:42:10 +01:00
|
|
|
$response = get_headers($url, 1);
|
|
|
|
if(!empty($response['Location'])) {
|
|
|
|
$response2 = get_headers($response['Location'], 1);
|
|
|
|
if(!empty($response2['Location'])) {
|
2013-03-10 14:48:29 +01:00
|
|
|
//die('too much redirection');
|
|
|
|
return array( 'error' => 'too much redirection: '. escape ($url) );
|
2013-02-18 19:42:10 +01:00
|
|
|
}
|
|
|
|
else { return $response['Location']; }
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function urlToFolder($url) {
|
|
|
|
return sha1(NoProtocolSiteURL($url));
|
|
|
|
}
|
|
|
|
|
2013-02-23 20:18:22 +01:00
|
|
|
function urlToFolderSlash($url) {
|
2013-02-20 20:14:12 +01:00
|
|
|
return sha1(NoProtocolSiteURL($url).'/');
|
|
|
|
}
|
|
|
|
|
2013-02-23 20:18:22 +01:00
|
|
|
function folderExists($url) {
|
|
|
|
return file_exists(urlToFolder($url)) || file_exists(urlToFolderSlash($url));
|
|
|
|
}
|
|
|
|
|
2013-02-18 19:42:10 +01:00
|
|
|
function escape($str) {
|
|
|
|
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createAutoblog($type, $sitename, $siteurl, $rssurl, $error = array()) {
|
2013-02-19 12:20:13 +01:00
|
|
|
if( $type == 'generic' || empty( $type )) {
|
2013-02-18 19:42:10 +01:00
|
|
|
$var = updateType( $siteurl );
|
|
|
|
$type = $var['type'];
|
2013-03-01 12:14:46 +01:00
|
|
|
if( !empty( $var['name']) ) {
|
|
|
|
if( !stripos($siteurl, $var['name'] === false) )
|
|
|
|
$sitename = ucfirst($var['name']) . ' - ' . $sitename;
|
|
|
|
}
|
2013-02-18 19:42:10 +01:00
|
|
|
}
|
|
|
|
|
2013-02-23 20:18:22 +01:00
|
|
|
if(folderExists($siteurl)) {
|
2013-02-27 12:04:05 +01:00
|
|
|
$error[] = 'Erreur : l\'autoblog '. $sitename .' existe déjà.';
|
2013-02-18 19:42:10 +01:00
|
|
|
return $error;
|
|
|
|
}
|
2013-02-20 20:14:12 +01:00
|
|
|
|
2013-02-23 20:18:22 +01:00
|
|
|
$foldername = urlToFolderSlash($siteurl);
|
2013-02-18 19:42:10 +01:00
|
|
|
|
|
|
|
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_TYPE="'. $type .'"
|
|
|
|
SITE_TITLE="'. $sitename .'"
|
|
|
|
SITE_DESCRIPTION="Site original : <a href=\''. $siteurl .'\'>'. $sitename .'</a>"
|
|
|
|
SITE_URL="'. $siteurl .'"
|
|
|
|
FEED_URL="'. $rssurl .'"
|
2013-02-23 15:27:29 +01:00
|
|
|
ARTICLES_PER_PAGE="'. getArticlesPerPage( $type ) .'"
|
2013-02-18 19:42:10 +01:00
|
|
|
UPDATE_INTERVAL="'. getInterval( $type ) .'"
|
2013-02-23 15:27:29 +01:00
|
|
|
UPDATE_TIMEOUT="'. getTimeout( $type ) .'"') )
|
2013-02-18 19:42:10 +01:00
|
|
|
$error[] = "Impossible d'écrire le fichier vvb.ini";
|
|
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$error[] = "Impossible de créer le répertoire.";
|
|
|
|
|
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
|
2013-02-23 15:27:29 +01:00
|
|
|
function getArticlesPerPage( $type ) {
|
|
|
|
switch( $type ) {
|
|
|
|
case 'microblog':
|
|
|
|
return 20;
|
|
|
|
case 'shaarli':
|
|
|
|
return 20;
|
|
|
|
default:
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 19:42:10 +01:00
|
|
|
function getInterval( $type ) {
|
|
|
|
switch( $type ) {
|
|
|
|
case 'microblog':
|
|
|
|
return 300;
|
|
|
|
case 'shaarli':
|
|
|
|
return 1800;
|
|
|
|
default:
|
|
|
|
return 3600;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-23 15:27:29 +01:00
|
|
|
function getTimeout( $type ) {
|
|
|
|
switch( $type ) {
|
|
|
|
case 'microblog':
|
|
|
|
return 30;
|
|
|
|
case 'shaarli':
|
|
|
|
return 30;
|
|
|
|
default:
|
|
|
|
return 30;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-18 19:42:10 +01:00
|
|
|
function updateType($siteurl) {
|
|
|
|
if( strpos($siteurl, 'twitter.com') !== FALSE ) {
|
|
|
|
return array('type' => 'microblog', 'name' => 'twitter');
|
|
|
|
}
|
|
|
|
elseif ( strpos( $siteurl, 'identi.ca') !== FALSE ) {
|
|
|
|
return array('type' => 'microblog', 'name' => 'identica');
|
|
|
|
}
|
|
|
|
elseif( strpos( $siteurl, 'shaarli' ) !== FALSE ) {
|
|
|
|
return array('type' => 'shaarli', 'name' => 'shaarli');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return array('type' => 'generic', 'name' => '');
|
|
|
|
}
|
2013-02-23 20:18:22 +01:00
|
|
|
|
|
|
|
function debug($data)
|
|
|
|
{
|
2013-03-12 18:17:16 +01:00
|
|
|
echo '<pre>';
|
|
|
|
var_dump($data);
|
|
|
|
echo '</pre>';
|
2013-02-23 20:18:22 +01:00
|
|
|
}
|
2013-02-20 20:14:12 +01:00
|
|
|
?>
|