From cd936fdf9c93d5b4cc722deb28cb2b51b691068c Mon Sep 17 00:00:00 2001 From: Knah Tsaeb Date: Tue, 9 Apr 2013 15:50:00 +0200 Subject: [PATCH] [add] Ajout de la description du site (balise meta description) --- 0.3/autoblogs/autoblog.php | 8 +++--- 0.3/config.php | 6 ++--- 0.3/functions.php | 55 +++++++++++++++++++++++++++++++------- 0.3/index.php | 31 +++++++++++++-------- 0.3/resources/user.css | 12 +++++++++ 0.3/xsaf3.php | 39 +++++++++++++++------------ 6 files changed, 107 insertions(+), 44 deletions(-) diff --git a/0.3/autoblogs/autoblog.php b/0.3/autoblogs/autoblog.php index 38a68f5..ddcecd0 100644 --- a/0.3/autoblogs/autoblog.php +++ b/0.3/autoblogs/autoblog.php @@ -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 '

'.escape($config->site_title).'

'; -if (!empty($config->site_description)) +if (!empty($config->site_description)){ echo '

'.$config->site_description.'
⇐ retour index

'; - +} + echo '

'.$config->site_meta_description.'

'; echo '
diff --git a/0.3/config.php b/0.3/config.php index 9a71640..8d10a51 100755 --- a/0.3/config.php +++ b/0.3/config.php @@ -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'] = ''; ?> diff --git a/0.3/functions.php b/0.3/functions.php index bffc786..83605d8 100755 --- a/0.3/functions.php +++ b/0.3/functions.php @@ -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, "") ) $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 : '. $sitename .'" +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 ''; } +/** + * 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 '

', $name, '

'; + echo '
'; + echo '', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], ''; + echo '
', htmlentities(print_r($data, 1)), '
'; + echo '

'; + } + function __($str) { switch ($str) diff --git a/0.3/index.php b/0.3/index.php index 6705077..6364c70 100755 --- a/0.3/index.php +++ b/0.3/index.php @@ -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[] = 'Autoblog "'. $sitename .'" crée avec succès. → afficher l\'autoblog.'; @@ -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 .= ''; $form .= '

Autoblog '. $sitename .' ajouté avec succès.
'; @@ -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 .= 'Merci de vérifier les informations suivantes, corrigez si nécessaire.
-
-
-
-
+
+
+
+
+

'; } 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[] = ''.ucfirst($socialinstance) .' - '. $socialaccount.' ajouté avec succès.'; } @@ -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[] = 'Autoblog '. $sitename .' crée avec succès.afficher l\'autoblog'; @@ -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 = 'Merci de vérifier les informations suivantes, corrigez si nécessaire.



+


'; @@ -873,10 +880,12 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY $autoblogs_display .= '
'; if($myOptions['enableThumbShot'] === true){ - if(file_exists(ROOT_DIR . '/' . $unit . '/thumbshot.png')){ - $autoblogs_display .= '
'; + if(file_exists(ROOT_DIR . '/' . $key . '/thumbshot.png')){ + $autoblogs_display .= '
+
'.shortSiteDesc(escape($autoblog->site_meta_description)).'
'; } elseif(!empty($myOptions['externalThumbSdhot'])) { - $autoblogs_display .= '
'; + $autoblogs_display .= '
+
'.shortSiteDesc(escape($autoblog->site_meta_description)).'
'; } } $autoblogs_display .= '
config ini '.$opml_link.' | '.escape($autoblog->site_type).' source: '.escape($autoblog->site_url).'
diff --git a/0.3/resources/user.css b/0.3/resources/user.css index 4ca9edd..148f17f 100644 --- a/0.3/resources/user.css +++ b/0.3/resources/user.css @@ -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; diff --git a/0.3/xsaf3.php b/0.3/xsaf3.php index b62ce5e..d5ac2e1 100755 --- a/0.3/xsaf3.php +++ b/0.3/xsaf3.php @@ -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 '

'. $value .'

'; @@ -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 "

Time out !

"; - break; + break; } } - } + } else { if( DEBUG ) echo "Format JSON incorrect."; return false; } } - return; + return; } - + if( DEBUG ) echo ''; if( ALLOW_NEW_AUTOBLOGS and ALLOW_NEW_AUTOBLOGS_BY_XSAF && !empty($autoblog_farm) ) { foreach( $autoblog_farm AS $value ) {