| Les deux révisions précédentesRévision précédente | |
| php:autoblog2 [2013-01-21 16:58] – mitsu | php:autoblog2 [2013-01-23 21:04] (Version actuelle) – mitsu |
|---|
| Licence: Domaine Public | Licence: Domaine Public |
| |
| [[https://www.ecirtam.net/zerobin/?cf6b82ad5427691f#3q0hO9TaJ8BCB/d7Iibjd2NMgpHaR95ONQrg8oKhHIY=|ToDo/idées]] | Le code est désormais sur Github: https://github.com/mitsukarenai/ferme-autoblog/ |
| | |
| <file php index.php> | |
| <?php | |
| | |
| /* modtime 2013-01-21 */ | |
| | |
| 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"); | |
| $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; | |
| } | |
| | |
| 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; | |
| } | |
| | |
| define('ROOT_DIR', __DIR__); | |
| 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 = escape($_GET['rssurl']); | |
| $siteurl = escape($_GET['siteurl']); | |
| $foldername = sha1($siteurl); | |
| if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(substr($siteurl, 0, -1)); }else{ $foldername2 = sha1($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é qui ré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> → <a target="_blank" href="'.$foldername.'">afficher l\'autoblog</a>');} | |
| } | |
| else | |
| {die("Impossible de créer le répertoire.");} | |
| | |
| } | |
| else | |
| { | |
| // checking procedure | |
| $rssurl = $_GET['rssurl']; | |
| $siteurl = get_link_from_feed($rssurl); | |
| $foldername = sha1($siteurl); | |
| if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(substr($siteurl, 0, -1)); }else{ $foldername2 = sha1($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">← 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">← 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">← adresse du flux</label><br> | |
| <input type="submit" value="Créer"></form></body></html>'; | |
| echo $form; die; | |
| } | |
| } | |
| | |
| | |
| if( !empty($_POST) ) { | |
| $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 = escape($_POST['rssurl']); | |
| if(!empty($_POST['siteurl'])) | |
| { | |
| // check done, writing out | |
| $siteurl = escape($_POST['siteurl']);$foldername = sha1($siteurl);$sitename = get_title_from_feed($rssurl); | |
| if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(substr($siteurl, 0, -1)); }else{ $foldername2 = sha1($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é qui ré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> → <a target="_blank" href="'.$foldername.'">afficher l\'autoblog</a>'; | |
| } | |
| else | |
| $error[] = "Impossible de créer le répertoire."; | |
| | |
| | |
| } | |
| else | |
| { | |
| // checking procedure | |
| $siteurl = get_link_from_feed($rssurl);$foldername = sha1($siteurl);$sitename = get_title_from_feed($rssurl); | |
| if(substr($siteurl, -1) == '/'){ $foldername2 = sha1(substr($siteurl, 0, -1)); }else{ $foldername2 = sha1($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">← titre du site (auto)</label><br> | |
| <input placeholder="Adresse du site" type="text" name="siteurl" id="siteurl" value="'.$siteurl.'"><label for="siteurl">← page d\'accueil (auto)</label><br> | |
| <input placeholder="Adresse du flux RSS/ATOM" type="text" name="rssurl" id="rssurl" value="'.$rssurl.'"><label for="rssurl">← adresse du flux</label><br> | |
| <input placeholder="Antibot: \'dix sept\' en chiffre" type="text" name="number" id="number" value="17"><label for="number">← 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;} | |
| 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;} | |
| .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="./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> | |
| → <a href="https://duckduckgo.com/?q=!g %22Voici une liste d'autoblogs hébergés%22">Rechercher</a><br><br> | |
| <b>Ajouter votre site</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 de votre 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 => <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="<?php echo serverUrl().$_SERVER["REQUEST_URI"]; ?>";var%20popup=window.open("","Add%20autoblog",'height=180,width=670');popup.document.writeln('<html><head></head><body><form%20action="'+autoblog_url+'"%20method="GET">');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=="alternate"){popup.document.writeln('<label%20for="feed_'+i+'"><input%20id="feed_'+i+'"%20type="radio"%20name="rssurl"%20value="'+links[i].href+'"/>'+links[i].title+"%20(%20"+links[i].href+"%20)</label><br/>");}}}popup.document.writeln("<input%20id='number'%20type='hidden'%20name='number'%20value='17'>");popup.document.writeln("<input%20type='hidden'%20name='via_button'%20value='1'>");popup.document.writeln("<br/><input%20type='submit'%20value='Vérifier'%20name='Ajouter'%20>");popup.document.writeln("</form></body></html>");})();">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.php?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><a href="http://wiki.suumitsu.eu/doku.php?id=php:autoblog2">index 2-dev</a> 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) | |
| <iframe width="1" height="1" frameborder="0" src="xsaf2.php"></iframe> | |
| </body> | |
| </html> | |
| | |
| </file> | |