[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_type = '';
public $site_title = ''; public $site_title = '';
public $site_description = ''; public $site_description = '';
public $site_meta_description = '';
public $site_url = ''; public $site_url = '';
public $feed_url = ''; public $feed_url = '';
public $articles_per_page = 10; public $articles_per_page = 10;
@ -726,9 +727,10 @@ echo '
<hr> <hr>
<h1><a href="./">'.escape($config->site_title).'</a></h1>'; <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>'.$config->site_description.'<br><a href="../../">&lArr; retour index</a></p>';
}
echo '<p class="pagination">'.$config->site_meta_description.'<br></p>';
echo ' echo '
<form method="get" action="'.escape(LOCAL_URL).'" class="searchForm"> <form method="get" action="'.escape(LOCAL_URL).'" class="searchForm">
<div> <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 ! /* And now, the XSAF links to be imported, with maximal execusion time for import in second !
You should add only trusted sources. */ You should add only trusted sources. */
$autoblog_farm = array( $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://www.ecirtam.net/autoblogs/?export',
'https://autoblog.suumitsu.eu/?export', */ 'http://autoblog.suumitsu.eu/?export'
); );
// personnal option // personnal option
$myOptions['enableThumbShot'] = false; $myOptions['enableThumbShot'] = true;
$myOptions['externalThumbSdhot'] = ''; $myOptions['externalThumbSdhot'] = '';
?> ?>

View file

@ -54,7 +54,24 @@ function escape($str) {
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8', false); 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 )) { if( $type == 'generic' || empty( $type )) {
$var = updateType( $siteurl ); $var = updateType( $siteurl );
$type = $var['type']; $type = $var['type'];
@ -70,7 +87,6 @@ function createAutoblog($type, $sitename, $siteurl, $rssurl, $error = array()) {
} }
$foldername = AUTOBLOGS_FOLDER . urlToFolderSlash($siteurl); $foldername = AUTOBLOGS_FOLDER . urlToFolderSlash($siteurl);
if ( mkdir($foldername, 0755, false) ) { if ( mkdir($foldername, 0755, false) ) {
/** /**
@ -90,6 +106,7 @@ function createAutoblog($type, $sitename, $siteurl, $rssurl, $error = array()) {
SITE_TYPE="'. $type .'" SITE_TYPE="'. $type .'"
SITE_TITLE="'. $sitename .'" SITE_TITLE="'. $sitename .'"
SITE_DESCRIPTION="Site original : <a href=\''. $siteurl .'\'>'. $sitename .'</a>" SITE_DESCRIPTION="Site original : <a href=\''. $siteurl .'\'>'. $sitename .'</a>"
SITE_META_DESCRIPTION="'.$siteDesc.'"
SITE_URL="'. $siteurl .'" SITE_URL="'. $siteurl .'"
FEED_URL="'. $rssurl .'" FEED_URL="'. $rssurl .'"
ARTICLES_PER_PAGE="'. getArticlesPerPage( $type ) .'" ARTICLES_PER_PAGE="'. getArticlesPerPage( $type ) .'"
@ -158,6 +175,24 @@ function debug($data)
echo '</pre>'; 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) function __($str)
{ {
switch ($str) switch ($str)

View file

@ -115,8 +115,9 @@ function create_from_opml($opml) {
$sitename = escape( $outline['title'] ); $sitename = escape( $outline['title'] );
$siteurl = escape($outline['htmlUrl']); $siteurl = escape($outline['htmlUrl']);
$sitetype = escape($outline['text']); if ( $sitetype == 'generic' or $sitetype == 'microblog' or $sitetype == 'shaarli') { } else { $sitetype = 'generic'; } $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 )) 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>.'; $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']); $sitename = escape($_GET['sitename']);
$sitetype = updateType($siteurl); // Disabled input doesn't send POST data $sitetype = updateType($siteurl); // Disabled input doesn't send POST data
$sitetype = $sitetype['type']; $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)) { if( empty($error)) {
$form .= '<iframe width="1" height="1" frameborder="0" src="'. urlToFolderSlash($siteurl) .'/index.php"></iframe>'; $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>'; $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); $sitename = get_title_from_datafeed($datafeed);
$sitetype = updateType($siteurl); $sitetype = updateType($siteurl);
$sitetype = $sitetype['type']; $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 .= '<span style="color:blue">Merci de vérifier les informations suivantes, corrigez si nécessaire.</span><br>
<form method="GET"> <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 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:450px;" 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: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: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: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: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="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>'; <input type="submit" value="Créer"></form>';
} }
else { else {
@ -533,7 +537,7 @@ if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']) && ALLOW_
} }
} }
if( empty($error) ) { 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)) 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>'; $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']); $siteurl = escape($_POST['siteurl']);
$sitename = get_title_from_feed($rssurl); $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)) 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>'; $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'; $sitetype = 'generic';
$siteurl = get_link_from_datafeed($datafeed); $siteurl = get_link_from_datafeed($datafeed);
$sitename = get_title_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 = '<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" /> <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 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 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="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=""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 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>'; <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"> $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>'; <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($myOptions['enableThumbShot'] === true){
if(file_exists(ROOT_DIR . '/' . $unit . '/thumbshot.png')){ if(file_exists(ROOT_DIR . '/' . $key . '/thumbshot.png')){
$autoblogs_display .= '<div class="thumbshot"><img src="'.ROOT_DIR . '/' . $unit . '/thumbshot.png" title="Thumbshot de '.escape($autoblog->site_title).'"/></div>'; $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'])) { } 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> $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; margin: 1.2em 0.3em;
} }
input, textarea {
width: 450px;
}
#vignette { #vignette {
text-align: center; text-align: center;
} }
@ -40,6 +44,14 @@ h1 {
float: left; float: left;
} }
.siteDesc {
padding : 0.15em;
max-height: 160px;
overflow:hidden;
text-align:center;
word-wrap: break-word;
}
.source { .source {
text-align: left; text-align: left;
clear:both; clear:both;

View file

@ -5,13 +5,13 @@ define('XSAF_VERSION', 3);
define('AUTOBLOG_FILE_NAME', 'autoblog.php'); define('AUTOBLOG_FILE_NAME', 'autoblog.php');
define('ALLOW_REMOTE_DB_DL', false); define('ALLOW_REMOTE_DB_DL', false);
define('ALLOW_REMOTE_MEDIA_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("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('X-Robots-Tag: noindex'); /* more civilized method, but bots may not all take into account */
//header('Content-type: text/plain'); //header('Content-type: text/plain');
$expire = time() -7200 ; $expire = time() -3600 ;
$lockfile = ".xsaflock"; /* defaut delay: 7200 (2 hours) */ $lockfile = ".xsaflock"; /* defaut delay: 7200 (2 hours) */
if (file_exists($lockfile) && filemtime($lockfile) > $expire) { if (file_exists($lockfile) && filemtime($lockfile) > $expire) {
@ -81,6 +81,11 @@ function xsafimport($xsafremote, $max_exec_time) {
$sitetype = escape($value['SITE_TYPE']); $sitetype = escape($value['SITE_TYPE']);
$sitename = escape($value['SITE_TITLE']); $sitename = escape($value['SITE_TITLE']);
$siteurl = escape($value['SITE_URL']); $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 // 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 = DetectRedirect(escape($value['FEED_URL']));
$rssurl = escape($value['FEED_URL']); $rssurl = escape($value['FEED_URL']);
@ -97,7 +102,7 @@ function xsafimport($xsafremote, $max_exec_time) {
if( $result === true ) { if( $result === true ) {
$foldername = urlToFolderSlash($siteurl); $foldername = urlToFolderSlash($siteurl);
$errors = createAutoblog($sitetype, $sitename, $siteurl, $rssurl); $errors = createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $siteDesc);
foreach( $errors AS $value) { foreach( $errors AS $value) {
if( DEBUG ) if( DEBUG )
echo '<p>'. $value .'</p>'; echo '<p>'. $value .'</p>';