SebSauvage et Bohwaz.'); /** * Functions **/ function NoProtocolSiteURL($url) { $protocols = array("http://", "https://"); $siteurlnoproto = str_replace($protocols, "", $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 DetectRedirect($url) { if(parse_url($url, PHP_URL_HOST)==FALSE) { throw new Exception('Not a URL: '. escape ($url) ); } try { $response = get_headers($url, 1); } catch (Exception $e) { throw new Exception('RSS URL unreachable: '. escape($url) ); } if(!empty($response['Location'])) { try { $response2 = get_headers($response['Location'], 1); } catch (Exception $e) { throw new Exception('RSS URL unreachable: '. escape($url) ); } if(!empty($response2['Location'])) { throw new Exception('Too much redirection: '. escape ($url) ); } else { return $response['Location']; } } else { return $url; } } function urlHash($rssurl) { return sha1(NoProtocolSiteURL($rssurl)); } function urlToFolder($siteurl, $rssurl) { return AUTOBLOGS_FOLDER . substr(preg_replace("/[^a-z0-9]/", '', strtolower(NoProtocolSiteURL($siteurl))), 0, FOLDER_MAX_LENGTH) .'_'. urlHash($rssurl) .'/'; } function folderExists($siteurl, $rssurl) { return file_exists(urlToFolder($siteurl, $rssurl)); } function escape($str) { return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false); } function createAutoblog($type, $sitename, $siteurl, $rssurl) { if( $type == 'generic' || empty( $type )) { $var = updateType( $siteurl ); $type = $var['type']; if( !empty( $var['name']) ) { if( !stripos($siteurl, $var['name'] === false) ) $sitename = ucfirst($var['name']) . ' - ' . $sitename; } } if(folderExists($siteurl, $rssurl)) { throw new Exception('Erreur : l\'autoblog '. $sitename .' existe déjà.'); } $foldername = urlToFolder($siteurl, $rssurl); if ( mkdir($foldername, 0755, false) ) { $fp = fopen($foldername .'/index.php', 'w+'); if( !fwrite($fp, "") ) throw new Exception('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 : '. $sitename .'" SITE_URL="'. $siteurl .'" FEED_URL="'. $rssurl .'" ARTICLES_PER_PAGE="'. getArticlesPerPage( $type ) .'" UPDATE_INTERVAL="'. getInterval( $type ) .'" UPDATE_TIMEOUT="'. getTimeout( $type ) .'"') ) throw new Exception('Impossible d\'écrire le fichier vvb.ini'); fclose($fp); } else throw new Exception('Impossible de créer le répertoire.'); updateXML('new_autoblog_added', 'new', $foldername, $sitename, $siteurl, $rssurl); } function getArticlesPerPage( $type ) { switch( $type ) { case 'microblog': return 20; case 'twitter': return 20; case 'identica': return 20; case 'shaarli': return 20; default: return 5; } } function getInterval( $type ) { switch( $type ) { case 'microblog': return 300; case 'twitter': return 300; case 'identica': return 300; case 'shaarli': return 1800; default: return 3600; } } function getTimeout( $type ) { switch( $type ) { case 'microblog': return 30; case 'twitter': return 30; case 'identica': return 30; case 'shaarli': return 30; default: return 30; } } function updateType($siteurl) { if( strpos($siteurl, 'twitter.com') !== FALSE ) { return array('type' => 'twitter', 'name' => 'twitter'); } elseif ( strpos( $siteurl, 'identi.ca') !== FALSE ) { return array('type' => 'identica', 'name' => 'identica'); } elseif( strpos( $siteurl, 'shaarli' ) !== FALSE ) { return array('type' => 'shaarli', 'name' => 'shaarli'); } else return array('type' => 'generic', 'name' => ''); } function debug($data) { echo '
';
	var_dump($data);
	echo '
'; } 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 '%d results for %s': return '%d résultats pour la recherche %s'; 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 'ATOM Feed': return 'Flux ATOM'; 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; case 'Media export': return 'Export fichiers media'; default: 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.')
Autoblog: '.$autoblog_title.'
Site: '. $autoblog_sourceurl .'
RSS: '.$autoblog_sourcefeed.''; case 'moved': return 'Autoblog "'.$autoblog_title.'": site distant redirigé (code '.$response_code.')
Autoblog: '.$autoblog_title.'
Site: '. $autoblog_sourceurl .'
RSS: '.$autoblog_sourcefeed.''; case 'not_found': return 'Autoblog "'.$autoblog_title.'": site distant introuvable (code '.$response_code.')
Autoblog: '.$autoblog_title.'
Site: '. $autoblog_sourceurl .'
RSS: '.$autoblog_sourcefeed.''; case 'remote_error': return 'Autoblog "'.$autoblog_title.'": site distant a problème serveur (code '.$response_code.')
Autoblog: '.$autoblog_title.'
Site: '. $autoblog_sourceurl .'
RSS: '.$autoblog_sourcefeed.''; case 'available': return 'Autoblog "'.$autoblog_title.'": site distant à nouveau opérationnel (code '.$response_code.')
Autoblog: '.$autoblog_title.'
Site: '. $autoblog_sourceurl .'
RSS: '.$autoblog_sourcefeed.''; case 'new_autoblog_added': return 'Autoblog "'.$autoblog_title.'" ajouté (code '.$response_code.')
Autoblog: '.$autoblog_title.'
Site: '. $autoblog_sourceurl .'
RSS: '.$autoblog_sourcefeed.''; } } function displayXML() { header('Content-type: application/rss+xml; charset=utf-8'); echo ' '.serverUrl(true).''; echo 'Projet Autoblog'. ((strlen(HEAD_TITLE)>0) ? ' | '. HEAD_TITLE : '').''.serverUrl(true),"Projet Autoblog - RSS : Ajouts et changements de disponibilité.".''; 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).$item['autoblog_url']; $date = date("r", $item['timestamp']); print << {$item['autoblog_title']} {$link} {$item['timestamp']} admin@{$_SERVER['SERVER_NAME']} {$date} EOT; } } echo ''; } ?>