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 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']; 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_META_DESCRIPTION="'.$siteDesc.'" 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 'shaarli': return 20; case 'youtube': return 10; default: return 5; } } function getInterval( $type ) { switch( $type ) { case 'microblog': return 300; case 'twitter': return 300; case 'shaarli': return 1800; default: return 3600; } } function getTimeout( $type ) { switch( $type ) { default: return 30; } } function updateType($siteurl) { if( strpos($siteurl, 'twitter.com') !== FALSE ) { return array('type' => 'twitter', 'name' => 'twitter'); } elseif( strpos( $siteurl, 'shaarli' ) !== FALSE ) { return array('type' => 'shaarli', 'name' => 'shaarli'); } elseif( strpos( $siteurl, 'youtube.com' ) !== FALSE ) { return array('type' => 'youtube', 'name' => ''); } else return array('type' => 'generic', 'name' => ''); } function debug($data) { echo '
'; var_dump($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 '