[add] Ajout de la description du site (balise meta description)

This commit is contained in:
Knah Tsaeb 2013-04-09 15:50:00 +02:00
parent d9b23add41
commit cd936fdf9c
6 changed files with 107 additions and 44 deletions

View file

@ -145,6 +145,7 @@ class VroumVroum_Config
public $site_type = '';
public $site_title = '';
public $site_description = '';
public $site_meta_description = '';
public $site_url = '';
public $feed_url = '';
public $articles_per_page = 10;
@ -651,7 +652,7 @@ if (!$search && !empty($_SERVER['QUERY_STRING']) && !is_numeric($_SERVER['QUERY_
$css=' * { margin: 0; padding: 0; }
body { font-family:sans-serif; background-color: #efefef; padding: 1%; color: #333; }
img { max-width: 100%; height: auto; }
a { text-decoration: none; color: #000;font-weight:bold; }
a { text-decoration: none; color: #000;font-weight:bold; }
.header a { text-decoration: none; color: #000;font-weight:bold; }
.header { text-align:center; padding: 30px 3%; max-width:70em;margin:0 auto; }
.article .title { margin-bottom: 1em; }
@ -726,9 +727,10 @@ echo '
<hr>
<h1><a href="./">'.escape($config->site_title).'</a></h1>';
if (!empty($config->site_description))
if (!empty($config->site_description)){
echo '<p>'.$config->site_description.'<br><a href="../../">&lArr; retour index</a></p>';
}
echo '<p class="pagination">'.$config->site_meta_description.'<br></p>';
echo '
<form method="get" action="'.escape(LOCAL_URL).'" class="searchForm">
<div>

View file

@ -46,12 +46,12 @@ $head_title = "";
/* And now, the XSAF links to be imported, with maximal execusion time for import in second !
You should add only trusted sources. */
$autoblog_farm = array(
'https://raw.github.com/mitsukarenai/xsaf-bootstrap/master/3.json' /*,
'https://raw.github.com/mitsukarenai/xsaf-bootstrap/master/3.json' ,
'https://www.ecirtam.net/autoblogs/?export',
'https://autoblog.suumitsu.eu/?export', */
'http://autoblog.suumitsu.eu/?export'
);
// personnal option
$myOptions['enableThumbShot'] = false;
$myOptions['enableThumbShot'] = true;
$myOptions['externalThumbSdhot'] = '';
?>

View file

@ -54,7 +54,24 @@ function escape($str) {
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false);
}
function createAutoblog($type, $sitename, $siteurl, $rssurl, $error = array()) {
function getSiteDesc($url){
$allMeta = get_meta_tags($url);
if(!empty($allMeta['description'])){
return $allMeta['description'];
} else {
return 'Pas de description trouvé';
}
}
function shortSiteDesc($desc, $length = 145){
$charset = 'UTF-8';
if(mb_strlen($desc, $charset) > $length) {
$desc = mb_substr($desc, 0, $length, $charset) . '...';
}
return $desc;
}
function createAutoblog($type, $sitename, $siteurl, $rssurl, $siteDesc, $error = array()) {
if( $type == 'generic' || empty( $type )) {
$var = updateType( $siteurl );
$type = $var['type'];
@ -63,23 +80,22 @@ function createAutoblog($type, $sitename, $siteurl, $rssurl, $error = array()) {
$sitename = ucfirst($var['name']) . ' - ' . $sitename;
}
}
if(folderExists($siteurl)) {
$error[] = 'Erreur : l\'autoblog '. $sitename .' existe déjà.';
if(folderExists($siteurl)) {
$error[] = 'Erreur : l\'autoblog '. $sitename .' existe déjà.';
return $error;
}
$foldername = AUTOBLOGS_FOLDER . urlToFolderSlash($siteurl);
$foldername = AUTOBLOGS_FOLDER . urlToFolderSlash($siteurl);
if ( mkdir($foldername, 0755, false) ) {
/**
/**
* RSS
**/
require_once('class_rssfeed.php');
$rss = new AutoblogRSS(RSS_FILE);
$rss->addNewAutoblog($sitename, $foldername, $siteurl, $rssurl);
$fp = fopen($foldername .'/index.php', 'w+');
if( !fwrite($fp, "<?php require_once '../autoblog.php'; ?>") )
$error[] = "Impossible d'écrire le fichier index.php";
@ -90,6 +106,7 @@ function createAutoblog($type, $sitename, $siteurl, $rssurl, $error = array()) {
SITE_TYPE="'. $type .'"
SITE_TITLE="'. $sitename .'"
SITE_DESCRIPTION="Site original : <a href=\''. $siteurl .'\'>'. $sitename .'</a>"
SITE_META_DESCRIPTION="'.$siteDesc.'"
SITE_URL="'. $siteurl .'"
FEED_URL="'. $rssurl .'"
ARTICLES_PER_PAGE="'. getArticlesPerPage( $type ) .'"
@ -144,7 +161,7 @@ function updateType($siteurl) {
elseif ( strpos( $siteurl, 'identi.ca') !== FALSE ) {
return array('type' => 'identica', 'name' => 'identica');
}
elseif( strpos( $siteurl, 'shaarli' ) !== FALSE ) {
elseif( strpos( $siteurl, 'shaarli' ) !== FALSE ) {
return array('type' => 'shaarli', 'name' => 'shaarli');
}
else
@ -158,6 +175,24 @@ function debug($data)
echo '</pre>';
}
/**
* Améliore la sortie print
*
* @author Tatane http://www.tatane.info/index.php/print_rn
* @author http://www.blog.cactuscrew.com/77-print_rn.html
* @param $data (array) tableau à examiner
* @param $name (string) nom a affiché
* @return false affiche les clef valeur du tableau $data
*/
function n_print($data, $name = '') {
$aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>';
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '</fieldset><br />';
}
function __($str)
{
switch ($str)

View file

@ -115,8 +115,9 @@ function create_from_opml($opml) {
$sitename = escape( $outline['title'] );
$siteurl = escape($outline['htmlUrl']);
$sitetype = escape($outline['text']); if ( $sitetype == 'generic' or $sitetype == 'microblog' or $sitetype == 'shaarli') { } else { $sitetype = 'generic'; }
$siteDesc = getSiteDesc(escape($siteurl));
$error = array_merge( $error, createAutoblog( $sitetype, $sitename, $siteurl, $rssurl, $error ) );
$error = array_merge( $error, createAutoblog( $sitetype, $sitename, $siteurl, $rssurl, $siteDesc, $error ) );
if( empty ( $error ))
$success[] = '<iframe width="1" height="1" frameborder="0" src="'. urlToFolderSlash( $siteurl ) .'/index.php"></iframe>Autoblog "'. $sitename .'" crée avec succès. &rarr; <a target="_blank" href="'. urlToFolderSlash( $siteurl ) .'">afficher l\'autoblog</a>.';
@ -426,8 +427,9 @@ if(!empty($_GET['via_button']) && $_GET['number'] === '17' && ALLOW_NEW_AUTOBLOG
$sitename = escape($_GET['sitename']);
$sitetype = updateType($siteurl); // Disabled input doesn't send POST data
$sitetype = $sitetype['type'];
$siteDesc = getSiteDesc(escape($_GET['siteDesc']));
$error = array_merge( $error, createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $error));
$error = array_merge( $error, createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $siteDesc, $error));
if( empty($error)) {
$form .= '<iframe width="1" height="1" frameborder="0" src="'. urlToFolderSlash($siteurl) .'/index.php"></iframe>';
$form .= '<p><span style="color:darkgreen">Autoblog <a href="'. urlToFolderSlash($siteurl) .'">'. $sitename .'</a> ajouté avec succès.</span><br>';
@ -453,14 +455,16 @@ if(!empty($_GET['via_button']) && $_GET['number'] === '17' && ALLOW_NEW_AUTOBLOG
$sitename = get_title_from_datafeed($datafeed);
$sitetype = updateType($siteurl);
$sitetype = $sitetype['type'];
$siteDesc = getSiteDesc(escape($siteurl));
$form .= '<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 style="width:30em;" type="text" name="sitetype" id="sitetype" value="'.$sitetype.'" disabled><label for="sitetype">&larr; type de site</label><br>
<input style="width:450px;" type="text" name="sitename" id="sitename" value="'.$sitename.'"><label for="sitename">&larr; titre du site (auto)</label><br>
<input style="width:450px;" 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:450px;" placeholder="Adresse du flux RSS/ATOM" type="text" name="rssurl" id="rssurl" value="'.$rssurl.'"><label for="rssurl">&larr; adresse du flux</label><br>
<input style="width:450px;" type="text" name="sitetype" id="sitetype" value="'.$sitetype.'" disabled><label for="sitetype">&larr; type de site</label><br>
<textarea style="width:450px;height:8em;" type="text" name="siteDesc" id="siteDesc">'.escape($siteDesc).'</textarea><label for="siteDesc">&larr; description de site</label><br>
<input type="submit" value="Créer"></form>';
}
else {
@ -533,7 +537,7 @@ if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']) && ALLOW_
}
}
if( empty($error) ) {
$error = array_merge( $error, createAutoblog($sitetype, ucfirst($socialinstance) .' - '. $socialaccount, $siteurl, $rssurl, $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="'. urlToFolderSlash( $siteurl ) .'/index.php"></iframe><b style="color:darkgreen">'.ucfirst($socialinstance) .' - '. $socialaccount.' <a href="'.urlToFolderSlash( $siteurl ).'">ajouté avec succès</a>.</b>';
}
@ -562,8 +566,9 @@ if( !empty($_POST['generic']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_L
$siteurl = escape($_POST['siteurl']);
$sitename = get_title_from_feed($rssurl);
$siteDesc = escape($_POST['siteDesc']);
$error = array_merge( $error, createAutoblog('generic', $sitename, $siteurl, $rssurl, $error));
$error = array_merge( $error, createAutoblog('generic', $sitename, $siteurl, $rssurl, $siteDesc, $error));
if( empty($error))
$success[] = '<iframe width="1" height="1" frameborder="0" src="'. 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>';
@ -578,12 +583,14 @@ if( !empty($_POST['generic']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_L
$sitetype = 'generic';
$siteurl = get_link_from_datafeed($datafeed);
$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 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>
<input placeholder="Adresse du flux RSS/ATOM" type="text" name="rssurl" id="rssurl" value="'.$rssurl.'"><label for="rssurl">&larr; adresse du flux</label><br>
<textarea style="width:450px;height:8em;" type="text" name="siteDesc" id="siteDesc">'.escape($siteDesc).'</textarea><label for="siteDesc">&larr; description de site</label><br>
<input placeholder=""Type de site" type="text" name="sitetype" id="sitetype" value="'.$sitetype.'" '.( $datafeed === false?'':'disabled').'><label for="sitetype">&larr; type de site</label><br>
<input placeholder="Antibot: '. escape($_POST['antibot']) .' en chiffre" type="text" name="number" value="'. escape($_POST['number']) .'"><label for="number">&larr; antibot</label><br>
<input type="hidden" name="antibot" value="'. escape($_POST['antibot']) .'" /><input type="submit" value="Créer"></form>';
@ -873,10 +880,12 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
$autoblogs_display .= '<div class="vignette">
<div class="title"><a title="'.escape($autoblog->site_title).'" href="'.$key.'/"><img width="15" height="15" alt="" src="./?check='.$key.'"> '.escape($autoblog->site_title).'</a></div>';
if($myOptions['enableThumbShot'] === true){
if(file_exists(ROOT_DIR . '/' . $unit . '/thumbshot.png')){
$autoblogs_display .= '<div class="thumbshot"><img src="'.ROOT_DIR . '/' . $unit . '/thumbshot.png" title="Thumbshot de '.escape($autoblog->site_title).'"/></div>';
if(file_exists(ROOT_DIR . '/' . $key . '/thumbshot.png')){
$autoblogs_display .= '<div class="thumbshot"><img src="'.ROOT_DIR . '/' . $key . '/thumbshot.png" title="Thumbshot de '.escape($autoblog->site_title).'"/></div>
<div class="siteDesc">'.shortSiteDesc(escape($autoblog->site_meta_description)).'</div>';
} elseif(!empty($myOptions['externalThumbSdhot'])) {
$autoblogs_display .= '<div class="thumbshot"><img src="'.$myOptions['externalThumbSdhot'].rawurlencode(escape($autoblog->site_url)).'" title="Thumbshot de '.escape($autoblog->site_title).'"/></div>';
$autoblogs_display .= '<div class="thumbshot"><img src="'.$myOptions['externalThumbSdhot'].rawurlencode(escape($autoblog->site_url)).'" title="Thumbshot de '.escape($autoblog->site_title).'"/></div>
<div class="siteDesc">'.shortSiteDesc(escape($autoblog->site_meta_description)).'</div>';
}
}
$autoblogs_display .= '<div class="source">config <sup><a href="'.$key.'/vvb.ini">ini</a> '.$opml_link.'</sup> | '.escape($autoblog->site_type).' source: <a href="'.escape($autoblog->site_url).'">'.escape($autoblog->site_url).'</a></div>

View file

@ -17,6 +17,10 @@ h1 {
margin: 1.2em 0.3em;
}
input, textarea {
width: 450px;
}
#vignette {
text-align: center;
}
@ -40,6 +44,14 @@ h1 {
float: left;
}
.siteDesc {
padding : 0.15em;
max-height: 160px;
overflow:hidden;
text-align:center;
word-wrap: break-word;
}
.source {
text-align: left;
clear:both;

View file

@ -5,27 +5,27 @@ 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', 5);
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 ;
$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__);
@ -57,7 +57,7 @@ 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
/* détection de ferme autoblog */
$json_import = file_get_contents($xsafremote);
if(!empty($json_import)) {
@ -73,14 +73,19 @@ function xsafimport($xsafremote, $max_exec_time) {
$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']);
@ -90,14 +95,14 @@ function xsafimport($xsafremote, $max_exec_time) {
/* 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 = (!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);
$errors = createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $siteDesc);
foreach( $errors AS $value) {
if( DEBUG )
echo '<p>'. $value .'</p>';
@ -110,9 +115,9 @@ function xsafimport($xsafremote, $max_exec_time) {
/* ============================================================================================================================================================================== */
/* 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_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 ) {
@ -141,19 +146,19 @@ function xsafimport($xsafremote, $max_exec_time) {
if(time() >= $max_exec_time) {
if( DEBUG )
echo "<p>Time out !</p>";
break;
break;
}
}
}
}
else {
if( DEBUG )
echo "Format JSON incorrect.";
return false;
}
}
return;
return;
}
if( DEBUG ) echo '<html><body>';
if( ALLOW_NEW_AUTOBLOGS and ALLOW_NEW_AUTOBLOGS_BY_XSAF && !empty($autoblog_farm) ) {
foreach( $autoblog_farm AS $value ) {