1 - ordonner un tableau en fonction de la longueur des chaines qui le composent
function order($a,$b){
return strlen($b)-strlen($a);
}
usort($mots,'order');
function order($a,$b){
return strlen($b)-strlen($a);
}
usort($mots,'order');
def locale_load(self,lang):
locale_file='sys/locales/'+lang+".locale"
if not os.path.isfile(locale_file):
self.locale={}
return
locale={}
locale_str=file_get_contents(locale_file)
locale_str=re.findall('\"(?P<eng>.*?)\"=\"(?P<trad>.*?)\"',locale_str)
for key,val in enumerate(locale_str):
locale[locale_str[key][0]]=locale_str[key][1]
self.locale=locale
# syntaxe du fichier locale
#"Title"="Titre",
#"Author"="Auteur",
#"Language"="Langue",
def trad(self,term):
if not term in self.locale:
return term
return self.locale[term]
def no_accents(string):
replacements=[
(u"é","e"),
(u"ê","e"),
(u"è","e"),
(u"ë","e"),
(u"ô","o"),
(u"ó","o"),
(u"ù","u"),
(u"ú","u"),
(u"û","u"),
(u"ü","u"),
(u"î","i"),
(u"ï","i"),
(u"í","i"),
(u"â","a"),
(u"à","a"),
(u"á","a"),
(u"ä","a"),
(u"ñ","n")
]
for a, b in replacements:
string = string.replace(a, b)
return string
function getSelected() {
if(window.getSelection) { return window.getSelection(); }
else if(document.getSelection) { return document.getSelection(); }
else {
var selection = document.selection && document.selection.createRange();
if(selection.text) { return selection.text; }
return false;
}
return false;
}
function deep_strip_tags($var){
if (is_string($var)){return strip_tags($var);}
if (is_array($var)){return array_map('deep_strip_tags',$var);}
return $var;
}
function strip_almost_all_tags($chaine){
// ajouter le strip attributes
// à la barbare
$secure='#on(click|dblclick|blur|change|dragdrop|focus|keydown|keyup|keypress|mouseover|mouseout|load|unload|keydown)=#i';
$keep=array('<img ','<a ', '<em', '<br>','<br/>','</a', '</em', '<br />','<p ', '</p','<div ', '</div','<span ', '</span', '<li', '</li', '<ul', '</ul');
$temp_repl=array('[img ','[a ','[em','[br]','[br/]','[/a','[/em','[br /]','[p ','[/p','[div ','[/div','[span ','[/span','[li','[/li','[ul','[/ul');
$chaine=str_ireplace($keep,$temp_repl,$chaine);
$chaine=strip_tags($chaine);
$chaine=preg_replace($secure, 'on$1=', $chaine);
return str_ireplace($temp_repl,$keep,$chaine);
}
<?php
#
#
# Parsedown
# http://parsedown.org
#
# (c) Emanuil Rusev
# http://erusev.com
#
#This version is not the original: it's a class to function conversion by Bronco (http:www.warriordudimanche.net)
#Thanks a lot to Emanuil Rusev for this script ! It saved me lots of time ! ;-)
global $escape_sequence_map;
function parse($text)
{
# removes UTF-8 BOM and marker characters
$text = preg_replace('{^\xEF\xBB\xBF|\x1A}', '', $text);
# removes \r characters
$text = str_replace("\r\n", "\n", $text);
$text = str_replace("\r", "\n", $text);
# replaces tabs with spaces
$text = str_replace("\t", ' ', $text);
# encodes escape sequences
if (strpos($text, '\\') !== FALSE)
{
$escape_sequences = array('\\\\', '\`', '\*', '\_', '\{', '\}', '\[', '\]', '\(', '\)', '\>', '\#', '\+', '\-', '\.', '\!');
foreach ($escape_sequences as $index => $escape_sequence)
{
if (strpos($text, $escape_sequence) !== FALSE)
{
$code = "\x1A".'\\'.$index.';';
$text = str_replace($escape_sequence, $code, $text);
$escape_sequence_map[$code] = $escape_sequence;
}
}
}
# ~
$text = preg_replace('/\n\s*\n/', "\n\n", $text);
$text = trim($text, "\n");
$lines = explode("\n", $text);
$text = parse_block_elements($lines);
# decodes escape sequences
if (!empty($escape_sequence_map)){
foreach ($escape_sequence_map as $code => $escape_sequence)
{
$text = str_replace($code, $escape_sequence[1], $text);
}
}
$text = rtrim($text, "\n");
return $text;
}
function parse_block_elements(array $lines, $context = '')
{
$elements = array();
$element = array('type' => '',);
foreach ($lines as $line)
{
# markup (open)
if ($element['type'] === 'markup' and ! isset($element['closed']))
{
if (preg_match('{<'.$element['subtype'].'>$}', $line)) # opening tag
{
$element['depth']++;
}
if (preg_match('{</'.$element['subtype'].'>$}', $line)) # closing tag
{
$element['depth'] > 0
? $element['depth']--
: $element['closed'] = true;
}
$element['text'] .= "\n".$line;
continue;
}
# *
if ($line === '')
{
$element['interrupted'] = true;
continue;
}
# blockquote (existing)
if ($element['type'] === 'blockquote' and ! isset($element['interrupted']))
{
$line = preg_replace('/^[ ]*>[ ]?/', '', $line);
$element['lines'] []= $line;
continue;
}
# list (existing)
if ($element['type'] === 'li')
{
if (preg_match('/^([ ]{0,3})(\d+[.]|[*+-])[ ](.*)/', $line, $matches))
{
if ($element['indentation'] !== $matches[1])
{
$element['lines'] []= $line;
}
else
{
unset($element['last']);
$elements []= $element;
$element = array(
'type' => 'li',
'indentation' => $matches[1],
'last' => true,
'lines' => array(
preg_replace('/^[ ]{0,4}/', '', $matches[3]),
),
);
}
continue;
}
if (isset($element['interrupted']))
{
if ($line[0] === ' ')
{
$element['lines'] []= '';
$line = preg_replace('/^[ ]{0,4}/', '', $line);
$element['lines'] []= $line;
continue;
}
}
else
{
$line = preg_replace('/^[ ]{0,4}/', '', $line);
$element['lines'] []= $line;
continue;
}
}
# paragraph
if ($line[0] >= 'a' or $line[0] >= 'A' and $line[0] <= 'Z')
{
goto paragraph;
}
# code block
if ($line[0] === ' ' and preg_match('/^[ ]{4}(.*)/', $line, $matches))
{
if (trim($line) === ''){continue;}
if ($element['type'] === 'code')
{
if (isset($element['interrupted']))
{
$element['text'] .= "\n";
unset ($element['interrupted']);
}
$element['text'] .= "\n".$matches[1];
}
else
{
$elements []= $element;
$element = array(
'type' => 'code',
'text' => $matches[1],
);
}
continue;
}
# setext heading (---)
if ($line[0] === '-' and $element['type'] === 'p' and ! isset($element['interrupted']) and preg_match('/^[-]+[ ]*$/', $line))
{
$element['type'] = 'h.';
$element['level'] = 2;
continue;
}
# atx heading (#)
if ($line[0] === '#' and preg_match('/^(#{1,6})[ ]*(.+?)[ ]*#*$/', $line, $matches))
{
$elements []= $element;
$level = strlen($matches[1]);
$element = array(
'type' => 'h.',
'text' => $matches[2],
'level' => $level,
);
continue;
}
# setext heading (===)
if ($line[0] === '=' and $element['type'] === 'p' and ! isset($element['interrupted']) and preg_match('/^[=]+[ ]*$/', $line))
{
$element['type'] = 'h.';
$element['level'] = 1;
continue;
}
$deindented_line = $line[0] !== ' ' ? $line : ltrim($line);
if ($deindented_line === ''){continue;}
# reference
if ($deindented_line[0] === '[' and preg_match('/^\[(.+?)\]:[ ]*([^ ]+)/', $deindented_line, $matches))
{
$label = strtolower($matches[1]);
$url = trim($matches[2], '<>');
$reference_map[$label] = $url;
continue;
}
# blockquote
if ($deindented_line[0] === '>' and preg_match('/^>[ ]?(.*)/', $deindented_line, $matches))
{
if ($element['type'] === 'blockquote')
{
if (isset($element['interrupted']))
{
$element['lines'] []= '';
unset($element['interrupted']);
}
$element['lines'] []= $matches[1];
}
else
{
$elements []= $element;
$element = array(
'type' => 'blockquote',
'lines' => array(
$matches[1],
),
);
}
continue;
}
# markup
if ($deindented_line[0] === '<')
{
# self-closing tag
if (preg_match('{^<.+?/>$}', $deindented_line))
{
$elements []= $element;
$element = array(
'type' => '',
'text' => $deindented_line,
);
continue;
}
# opening tag
if (preg_match('{^<(\w+)(?:[ ].*?)?>}', $deindented_line, $matches))
{
$elements []= $element;
$element = array(
'type' => 'markup',
'subtype' => strtolower($matches[1]),
'text' => $deindented_line,
'depth' => 0,
);
preg_match('{</'.$matches[1].'>\s*$}', $deindented_line) and $element['closed'] = true;
continue;
}
}
# horizontal rule
if (preg_match('/^([-*_])([ ]{0,2}\1){2,}[ ]*$/', $deindented_line))
{
$elements []= $element;
$element = array('type' => 'hr',);
continue;
}
# list item
if (preg_match('/^([ ]*)(\d+[.]|[*+-])[ ](.*)/', $line, $matches))
{
$elements []= $element;
$element = array(
'type' => 'li',
'ordered' => isset($matches[2][1]),
'indentation' => $matches[1],
'last' => true,
'lines' => array(
preg_replace('/^[ ]{0,4}/', '', $matches[3]),
),
);
continue;
}
paragraph:
if ($element['type'] === 'p')
{
if (isset($element['interrupted']))
{
$elements []= $element;
$element['text'] = $line;
unset($element['interrupted']);
}
else {$element['text'] .= "\n".$line;}
}
else
{
$elements []= $element;
$element = array(
'type' => 'p',
'text' => $line,
);
}
}
$elements []= $element;
array_shift($elements);
$markup = '';
foreach ($elements as $index => $element)
{
switch ($element['type'])
{
case 'p':
$text = parse_span_elements($element['text']);
$text = preg_replace('/[ ]{2}\n/', '<br />'."\n", $text);
if ($context === 'li' and $index === 0)
{
if (isset($element['interrupted'])) { $markup .= "\n".'<p>'.$text.'</p>'."\n";}
else {$markup .= $text;}
}
else{$markup .= '<p>'.$text.'</p>'."\n";}
break;
case 'blockquote':
$text =parse_block_elements($element['lines']);
$markup .= '<blockquote>'."\n".$text.'</blockquote>'."\n";
break;
case 'code':
$text = htmlentities($element['text'], ENT_NOQUOTES);
strpos($text, "\x1A\\") !== FALSE and $text = strtr($text, $escape_sequence_map);
$markup .= '<pre><code>'.$text.'</code></pre>'."\n";
break;
case 'h.':
$text = parse_span_elements($element['text']);
$markup .= '<h'.$element['level'].'>'.$text.'</h'.$element['level'].'>'."\n";
break;
case 'hr':
$markup .= '<hr />'."\n";
break;
case 'li':
if (isset($element['ordered'])) # first
{
$list_type = $element['ordered'] ? 'ol' : 'ul';
$markup .= '<'.$list_type.'>'."\n";
}
if (isset($element['interrupted']) and ! isset($element['last']))
{
$element['lines'] []= '';
}
$text = parse_block_elements($element['lines'], 'li');
$markup .= '<li>'.$text.'</li>'."\n";
isset($element['last']) and $markup .= '</'.$list_type.'>'."\n";
break;
default:
$markup .= $element['text']."\n";
}
}
return $markup;
}
function parse_span_elements($text)
{
$map = array();
$index = 0;
# code span
if (strpos($text, '`') !== FALSE and preg_match_all('/`(.+?)`/', $text, $matches, PREG_SET_ORDER))
{
foreach ($matches as $matches)
{
$element_text = $matches[1];
$element_text = htmlentities($element_text, ENT_NOQUOTES);
# decodes escape sequences
$escape_sequence_map
and strpos($element_text, "\x1A") !== FALSE
and $element_text = strtr($element_text, $escape_sequence_map);
# composes element
$element = '<code>'.$element_text.'</code>';
# encodes element
$code = "\x1A".'$'.$index;
$text = str_replace($matches[0], $code, $text);
$map[$code] = $element;
$index ++;
}
}
# inline link or image
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
{
foreach ($matches as $matches)
{
$url = $matches[4];
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url);
if ($matches[1]) # image
{
$element = '<img alt="'.$matches[3].'" src="'.$url.'">';
}
else
{
$element_text =parse_span_elements($matches[3]);
$element = '<a href="'.$url.'">'.$element_text.'</a>';
}
$code = "\x1A".'$'.$index;
$text = str_replace($matches[0], $code, $text);
$map[$code] = $element;
$index ++;
}
}
# reference link or image
if (strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
{
foreach ($matches as $matches)
{
$link_definition = isset($matches[3]) && $matches[3]
? $matches[3]
: $matches[2]; # implicit
$link_definition = strtolower($link_definition);
if (isset($reference_map[$link_definition]))
{
$url = $reference_map[$link_definition];
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url);
if ($matches[1]) # image
{
$element = '<img alt="'.$matches[2].'" src="'.$url.'">';
}
else # anchor
{
$element_text = parse_span_elements($matches[2]);
$element = '<a href="'.$url.'">'.$element_text.'</a>';
}
$code = "\x1A".'$'.$index;
$text = str_replace($matches[0], $code, $text);
$map[$code] = $element;
$index ++;
}
}
}
# automatic link
if (strpos($text, '<') !== FALSE and preg_match_all('/<((https?|ftp|dict):[^\^\s]+?)>/i', $text, $matches, PREG_SET_ORDER))
{
foreach ($matches as $matches)
{
$url = $matches[1];
strpos($url, '&') !== FALSE and $url = preg_replace('/&(?!#?\w+;)/', '&', $url);
$element = '<a href=":href">:text</a>';
$element = str_replace(':text', $url, $element);
$element = str_replace(':href', $url, $element);
$code = "\x1A".'$'.$index;
$text = str_replace($matches[0], $code, $text);
$map[$code] = $element;
$index ++;
}
}
strpos($text, '&') !== FALSE and $text = preg_replace('/&(?!#?\w+;)/', '&', $text);
strpos($text, '<') !== FALSE and $text = preg_replace('/<(?!\/?\w.*?>)/', '<', $text);
if (strpos($text, '_') !== FALSE)
{
$text = preg_replace('/__(?=\S)(.+?)(?<=\S)__(?!_)/s', '<strong>$1</strong>', $text);
$text = preg_replace('/_(?=\S)(.+?)(?<=\S)_/s', '<em>$1</em>', $text);
}
if (strpos($text, '*') !== FALSE)
{
$text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*(?!\*)/s', '<strong>$1</strong>', $text);
$text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*/s', '<em>$1</em>', $text);
}
$text = strtr($text, $map);
return $text;
}
?>
<?php
# search2feed
# @author: bronco@warriordudimanche.net / warriordudimanche.net
# @version 0.1
# @license free and opensource
# @use: search2feed.php?q=your+query+here
function Random_referer(){
return array_rand(array(
'http://oudanstoncul.com.free.fr/',
'http://googlearretedenousfliquer.fr/',
'http://stopspyingme.fr/',
'http://spyyourassfuckinggoogle.fr/',
'http://dontfuckinglookatme.fr/',
'http://matemonculgoogle.fr/',
'http://auxarmescitoyens.fr/',
'http://jetlametsavecdugravier.con/',
'http://lesdeuxpiedsdanstagueule.fr/',
'http://moncoudedanstabouche.con/',
'http://monpieddanston.uk/',
'http://bienfaitpourvosgueul.es/',
'http://pandanstesdents.fr/',
'http://tupuessouslesbras.fr/',
'http://mangetescrottesdenez.fr/',
'http://jtepourristesstats.fr/',
'http://ontecompissevigoureusement.com/',
'http://lepoingleveetlemajeuraussi.com/',
));
}
function return_UTF8($var){
$utf8=str_replace("\xef\xbb\xbf\xA0", '',utf8_encode($var));// SANS BOM !!!!
if (strpos($var,"\xA0")){return $utf8;}
if (strpos($utf8,'Ã')){return $var;}else {return $utf8;}
}
function file_curl_contents($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Charset: UTF-8'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
if (!ini_get("safe_mode") && !ini_get('open_basedir') ) {curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);}
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_REFERER, random_referer());// notez le referer "custom"
$data = curl_exec($ch);
$response_headers = curl_getinfo($ch);
// Google seems to be sending ISO encoded page + htmlentities, why??
if($response_headers['content_type'] == 'text/html; charset=ISO-8859-1') $data = html_entity_decode(iconv('ISO-8859-1', 'UTF-8//TRANSLIT', $data));
# $data = curl_exec($ch);
curl_close($ch);
return return_utf8($data);
}
function parse_query($query,$title='Search2feed',$nb, $link='http://warriordudimanche.net',$lang='fr',$safesearch='&safe=off'){
$REGEX_WEB='#(?<=<h3 class="r"><a href="/url\?q=)([^&]+).*?>(.*?)</a>.*?(?<=<span class="st">)(.*?)(?=</span>)#';
$REGEX_PAGES='#&start=([0-9]+)|&start=([0-9]+)#';
$lang=strip_tags($lang);
$URL='https://www.google.com/search?hl='.$lang.$safesearch.'&id=hp&q=';
$page=file_curl_contents($URL.str_replace(' ','+',urlencode($query)).'&num='.$nb);
if (!$page){return false;}
preg_match_all($REGEX_WEB, $page, $r);
preg_match_all($REGEX_PAGES,$page,$p);
$p=count($p[2]);
$content=array();
foreach ($r[1] as $key=>$val){
$content[$key]['description']=strip_tags($r[3][$key]);
$content[$key]['link']=strip_tags($r[1][$key]);
$content[$key]['title']=strip_tags($r[2][$key]);
$content[$key]['guid']=strip_tags($r[1][$key]).'#1';
$content[$key]['pubDate']=@date('r');
}
$rss=array(
'infos'=>array(
'type'=>'rss',
'description'=>strip_tags($query),
'title'=>$title,
'link'=>$link,
),
'items'=>$content
);
return $rss;
}
function array2feed($array=null){
if (!$array){return false;}
if (empty($array['infos']['type'])){$array['infos']['type']='rss';}else{$array['infos']['type']=strtolower($array['infos']['type']);}
if (empty($array['infos']['description'])){$array['infos']['description']='';}
$r="\n";$t="\t";
$tpl=array('rss'=>array(),'atom'=>array());
$tpl['rss']['header']='<?xml version="1.0" encoding="utf-8" ?>'.$r.'<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'.$r.$t.'<channel>'.$r;
$tpl['atom']['header']='<feed xmlns="http://www.w3.org/2005/Atom">'.$r;
$tpl['rss']['footer']=$t.'</channel></rss>'.$r;
$tpl['atom']['footer']='</feed>'.$r;
$tpl['rss']['content-type']='Content-Type: application/rss+xml';
$tpl['atom']['content-type']='Content-Type: application/atom+xml;charset=utf-8';
header($tpl[$array['infos']['type']]['content-type']);
$feed=$tpl[$array['infos']['type']]['header'];
//create the feed's info content
foreach($array['infos'] as $key=>$value){
if ($array['infos']['type']=='atom'){ // ATOM
if ($key=='link'){$feed.=$t.$t.'<link href="'.$value.'" rel="self" type="application/atom+xml"/>'.$r;}
elseif ($key=='author'){$feed.=$t.$t.'<author><name>'.$value.'</name></author>'.$r;}
elseif ($key=='licence'){$feed.=$t.$t.'<'.$key.' href="'.$value.'" rel="license"/>'.$r;} // in atom feed, licence is the link to the licence type
elseif ($key!='version'&&$key!='type'){$feed.=$t.$t.'<'.$key.'>'.$value.'</'.$key.'>'.$r;}
}else{ // RSS
if ($key!='version'&&$key!='type'){$feed.=$t.$t.'<'.$key.'>'.$value.'</'.$key.'>'.$r;}
}
}
//then the items content
foreach ($array['items'] as $item){
if ($array['infos']['type']=='atom'){ $feed.=$t.$t.$t.'<entry>'.$r;}else{$feed.=$t.$t.$t.'<item>'.$r;}
foreach($item as $key=>$value){
if ($array['infos']['type']=='atom'){ // ATOM
if ($key=='link'){$feed.=$t.$t.$t.$t.'<link href="'.$value.'" rel="alternate" type="text/html"/>'.$r;}
elseif ($key=='content'){$feed.=$t.$t.$t.$t.'<content type="text">'.htmlspecialchars($value).'</content>'.$r;}
else{$feed.=$t.$t.$t.$t.'<'.$key.'>'.$value.'</'.$key.'>'.$r;}
}else{ // RSS
if ($key=='date'||$key=='pubDate'||$key=='title'||$key=='link'){$feed.=$t.$t.$t.$t.'<'.$key.'>'.htmlspecialchars($value).'</'.$key.'>'.$r;}
elseif($key=='guid'){ $feed.=$t.$t.$t.$t.'<guid isPermaLink="false">'.$value.'</guid>'.$r;}
else{$feed.=$t.$t.$t.$t.'<'.$key.'><![CDATA['.$value.']]></'.$key.'>'.$r;}
}
}
if ($array['infos']['type']=='atom'){ $feed.=$t.$t.$t.'</entry>'.$r;}else{$feed.=$t.$t.$t.'</item>'.$r;}
}
$feed.=$tpl[$array['infos']['type']]['footer'];
return $feed;
}
// récupération des parametres get
if (isset($_GET['q'])){$query=strip_tags($_GET['q']);}else{exit('pas de query');}
if (isset($_GET['title'])){$title=strip_tags($_GET['title']);}else{$title='GoogolSearch for '.$query;}
if (isset($_GET['nb'])){$nb=strip_tags($_GET['nb']);}else{$nb=20;}
echo array2feed(parse_query($query,$title,$nb));
?>
function secure($var,$level=0){
// $level=0 > returns text only (no html or script), 1 > text + html (no script), 2 > all content secured with entities
if (is_array($var)){foreach ($var as $index=>$v){$var[$index]=secure($v,$level);}}
else if (is_string($var)){
if ($level==0){$var=strip_tags($var);}
else if ($level==1){$var=preg_replace('#on[a-z]+ ?= ?["\'].*?["\'](?=[ />])|</?script>|javascript:#i','',$var);}
else {$var=htmlspecialchars($var);}
}
return $var;
}
function return_UTF8($chaine){
$utf8=str_replace("\xef\xbb\xbf", '',utf8_encode($chaine));// SANS BOM !!!!
if (strpos($utf8,'Ã')){return $chaine;}else {return $utf8;}// bon, là, on peut sans AUCUN doute mieux faire ^^
}
# Feed2array
# @author: bronco@warriordudimanche.net
# @version 0.2
# @license free and opensource
# @inspired by http://milletmaxime.net/syndexport/
# @use: $items=feed2array('http://sebsauvage.net/links/index.php?do=rss');
function feed2array($feed,$load=true){
if ($load){if (!$feed_content=file_get_contents($feed)){return false;}}else{$feed_content=$feed;}
$flux=array('infos'=>array(),'items'=>array());
if(preg_match('~<rss(.*)</rss>~si', $feed_content)){$type='RSS';}//RSS ?
elseif(preg_match('~<feed(.*)</feed>~si', $feed_content)){$type='ATOM';}//ATOM ?
else return false;//if the feed isn't rss or atom
$feed_content=utf8_encode($feed_content);
$flux['infos']['type']=$type;
if($feed_obj = new SimpleXMLElement($feed_content, LIBXML_NOCDATA))
{
$flux['infos']['version']=$feed_obj->attributes()->version;
if (!empty($feed_obj->attributes()->version)){ $flux['infos']['version']=(string)$feed_obj->attributes()->version;}
if (!empty($feed_obj->channel->title)){ $flux['infos']['title']=(string)$feed_obj->channel->title;}
if (!empty($feed_obj->channel->subtitle)){ $flux['infos']['subtitle']=(string)$feed_obj->channel->subtitle;}
if (!empty($feed_obj->channel->link)){ $flux['infos']['link']=(string)$feed_obj->channel->link;}
if (!empty($feed_obj->channel->description)){ $flux['infos']['description']=(string)$feed_obj->channel->description;}
if (!empty($feed_obj->channel->language)){ $flux['infos']['language']=(string)$feed_obj->channel->language;}
if (!empty($feed_obj->channel->copyright)){ $flux['infos']['copyright']=(string)$feed_obj->channel->copyright;}
if (!empty($feed_obj->title)){ $flux['infos']['title']=(string)$feed_obj->title;}
if (!empty($feed_obj->subtitle)){ $flux['infos']['subtitle']=(string)$feed_obj->subtitle;}
if (!empty($feed_obj->link)){ $flux['infos']['link']=(string)$feed_obj->link;}
if (!empty($feed_obj->description)){ $flux['infos']['description']=(string)$feed_obj->description;}
if (!empty($feed_obj->language)){ $flux['infos']['language']=(string)$feed_obj->language;}
if (!empty($feed_obj->copyright)){ $flux['infos']['copyright']=(string)$feed_obj->copyright;}
if (!empty($feed_obj->channel->item)){ $items=$feed_obj->channel->item;}
if (!empty($feed_obj->entry)){ $items=$feed_obj->entry;}
if (empty($items)){return false;}
//aff($feed_obj);
foreach ($items as $item){
$c=count($flux['items']);
if(!empty($item->title)){ $flux['items'][$c]['title'] = (string)$item->title;}
if(!empty($item->logo)){ $flux['items'][$c]['titleImage'] = (string)$item->logo;}
if(!empty($item->icon)){ $flux['items'][$c]['icon'] = (string)$item->icon;}
if(!empty($item->subtitle)){ $flux['items'][$c]['description'] = (string)$item->subtitle;}
if(!empty($item->link['href'])){ $flux['items'][$c]['link'] = (string)$item->link['href'];}
if(!empty($item->language)){ $flux['items'][$c]['language'] = (string)$item->language;}
if(!empty($item->author->name)){ $flux['items'][$c]['author'] = (string)$item->author->name;}
if(!empty($item->author->email)){ $flux['items'][$c]['email'] = (string)$item->author->email;}
if(!empty($item->updated)){ $flux['items'][$c]['last'] = (string)$item->updated;}
if(!empty($item->rights)){ $flux['items'][$c]['copyright'] = (string)$item->rights;}
if(!empty($item->generator)){ $flux['items'][$c]['generator'] = (string)$item->generator;}
if(!empty($item->guid)){ $flux['items'][$c]['guid'] = (string)$item->guid;}
if(!empty($item->pubDate)){ $flux['items'][$c]['pubDate'] = (string)$item->pubDate;}
if(!empty($item->description)){ $flux['items'][$c]['description'] = (string)$item->description;}
if(!empty($item->summary)){ $flux['items'][$c]['description'] = (string)$item->summary;}
if(!empty($item->published)){ $flux['items'][$c]['date'] = (string)$item->published;}
if(!empty($item->update)){ $flux['items'][$c]['update'] = (string)$item->update;}
if(!empty($item->link)){ $flux['items'][$c]['link'] = (string)$item->link;}
if(!empty($item->content)){ $flux['items'][$c]['description'] = (string)$item->content;}
}
}else return false;
return $flux;
}
# Array2feed
# @author: bronco@warriordudimanche.net
# @version 0.1
# @license free and opensource
# @inspired by http://milletmaxime.net/syndexport/
# @use: $items=feed2array('http://sebsauvage.net/links/index.php?do=rss');
# @doc:
# the array must have an index 'infos' and another called 'items'
#info key
# for rss type feed, infos must have at least the 'title', 'description', 'guid' keys
# for atom type feed, infos must have at least the 'title', 'id', 'subtitle', 'link' keys
# items key => array
# for rss type feed, each item must have the 'title', 'description', 'pubDate' and 'link' keys
# for atom type feed, info must have the 'title', 'id', 'updated, 'link' & 'content' keys
function array2feed($array=null){
if (!$array){return false;}
if (empty($array['infos']['type'])){$array['infos']['type']='rss';}else{$array['infos']['type']=strtolower($array['infos']['type']);}
if (empty($array['infos']['description'])){$array['infos']['description']='';}
$r="n";$t="t";
$tpl=array('rss'=>array(),'atom'=>array());
$tpl['rss']['header']='<?xml version="1.0" encoding="utf-8" ?>'.$r.'<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">'.$r.$t.'<channel>'.$r;
$tpl['atom']['header']='<feed xmlns="http://www.w3.org/2005/Atom">'.$r;
$tpl['rss']['footer']=$t.'</channel></rss>'.$r;
$tpl['atom']['footer']='</feed>'.$r;
$tpl['rss']['content-type']='Content-Type: application/rss+xml';
$tpl['atom']['content-type']='Content-Type: application/atom+xml;charset=utf-8';
header($tpl[$array['infos']['type']]['content-type']);
$feed=$tpl[$array['infos']['type']]['header'];
//create the feed's info content
foreach($array['infos'] as $key=>$value){
if ($array['infos']['type']=='atom'){ // ATOM
if ($key=='link'){$feed.=$t.$t.'<link href="'.$value.'" rel="self" type="application/atom+xml"/>'.$r;}
elseif ($key=='author'){$feed.=$t.$t.'<author><name>'.$value.'</name></author>'.$r;}
elseif ($key=='licence'){$feed.=$t.$t.'<'.$key.' href="'.$value.'" rel="license"/>'.$r;} // in atom feed, licence is the link to the licence type
elseif ($key!='version'&&$key!='type'){$feed.=$t.$t.'<'.$key.'>'.$value.'</'.$key.'>'.$r;}
}else{ // RSS
if ($key!='version'&&$key!='type'){$feed.=$t.$t.'<'.$key.'>'.$value.'</'.$key.'>'.$r;}
}
}
//then the items content
foreach ($array['items'] as $item){
if ($array['infos']['type']=='atom'){ $feed.=$t.$t.$t.'<entry>'.$r;}else{$feed.=$t.$t.$t.'<item>'.$r;}
foreach($item as $key=>$value){
if ($array['infos']['type']=='atom'){ // ATOM
if ($key=='link'){$feed.=$t.$t.$t.$t.'<link href="'.$value.'" rel="alternate" type="text/html"/>'.$r;}
elseif ($key=='content'){$feed.=$t.$t.$t.$t.'<content type="text">'.htmlspecialchars($value).'</content>'.$r;}
else{$feed.=$t.$t.$t.$t.'<'.$key.'>'.$value.'</'.$key.'>'.$r;}
}else{ // RSS
if ($key=='date'||$key=='pubDate'||$key=='title'||$key=='link'){$feed.=$t.$t.$t.$t.'<'.$key.'>'.htmlspecialchars($value).'</'.$key.'>'.$r;}
elseif($key=='guid'){ $feed.=$t.$t.$t.$t.'<guid isPermaLink="false">'.$value.'</guid>'.$r;}
else{$feed.=$t.$t.$t.$t.'<'.$key.'><![CDATA['.$value.']]></'.$key.'>'.$r;}
}
}
if ($array['infos']['type']=='atom'){ $feed.=$t.$t.$t.'</entry>'.$r;}else{$feed.=$t.$t.$t.'</item>'.$r;}
}
$feed.=$tpl[$array['infos']['type']]['footer'];
return $feed;
}
$array=array(
'infos'=>array(
'type'=>'rss',
'description'=>'Ceci est le test ultime de la mort',
'title'=>'test de création de flux rss',
'link'=>'http://www.warriordudimanche.net',
),
'items'=>array(
0=>array(
'description'=>'Ceci est le premier item du flux',
'title'=>'item 1 : le titre',
'link'=>'http://www.warriordudimanche.net',
'guid'=>'http://www.warriordudimanche.net#1',
'pubDate'=>@date('r'),// Be carefull, the rss pubDate format is specific ! RFC 2822 (see http://www.faqs.org/rfcs/rfc2822.html)
),
1=>array(
'description'=>'Ceci est le second item du flux',
'title'=>'item 2 : le retour',
'link'=>'http://www.warriordudimanche.net',
'guid'=>'http://www.warriordudimanche.net#2',
'pubDate'=>@date('r'),
),
2=>array(
'description'=>'Ceci est le troisième item du flux',
'title'=>'item 3 : la revanche',
'link'=>'http://www.warriordudimanche.net',
'guid'=>'http://www.warriordudimanche.net#3',
'pubDate'=>@date('r'),
),
)
);
echo array2feed($array);
function detectUTF8($string)
{
return preg_match('%(?:
[xC2-xDF][x80-xBF] # non-overlong 2-byte
|xE0[xA0-xBF][x80-xBF] # excluding overlongs
|[xE1-xECxEExEF][x80-xBF]{2} # straight 3-byte
|xED[x80-x9F][x80-xBF] # excluding surrogates
|xF0[x90-xBF][x80-xBF]{2} # planes 1-3
|[xF1-xF3][x80-xBF]{3} # planes 4-15
|xF4[x80-x8F][x80-xBF]{2} # plane 16
)+%xs',
$string);
}
function stripAccents($string){
$a=explode(' ','à á â ã ä ç è é ê ë ì í î ï ñ ò ó ô õ ö ù ú û ü ý ÿ À Á Â Ã Ä Ç È É Ê Ë Ì Í Î Ï Ñ Ò Ó Ô Õ Ö Ù Ú Û Ü Ý');
$b=explode(' ','a a a a a c e e e e i i i i n o o o o o u u u u y y A A A A A C E E E E I I I I N O O O O O U U U U Y');
return str_replace($a,$b,$string);
}
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
function myTruncate($string, $limit, $break=".", $pad="...") {
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit)
return $string;
// is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $string;
}
/***** Example ****/
$short_string=myTruncate($long_string, 100, ' ');
function makeClickableLinks($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'<a href="1">1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'1<a href="http://2">2</a>', $text);
$text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',
'<a href="mailto:1">1</a>', $text);
return $text;
}
// display source code
$lines = file('http://google.com/');
foreach ($lines as $line_num => $line) {
// loop thru each line and prepend line numbers
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>n";
}