Wikini

ActionRssgp

PagePrincipale :: DerniersChangements :: DerniersCommentaires :: ParametresUtilisateur :: Vous êtes ec2-18-223-43-142.us-east-2.compute.amazonaws.com

Avertissement: cette action est en cours de développement et ne fait pas partie de la distribution officielle de wikini.

un projet d'application autonome a été déposé sur gna! : https://gna.org/projects/poieticagg/
Bien joué !
(bon moi je galère avec le SSH ...) a+ -- YannLeGuennec

Cette action permet de visualiser des items de fils RSS sous forme de carrés de couleurs associés à des mots-clé.


Développement:



Fichiers liés à cette action:



Bugs:



<?php
/*
Affichage visuel de carrés de couleurs correpondants à des analyses de fils RSS
Inspiré du Générateur Poïétique  (http://poietic-generator.net/) -- Olivier Auber
Copyright ©  04/2005 Yann Le Guennec --  Olivier Auber
Copyleft : cette oeuvre est libre, vous pouvez la redistribuer et/ou la modifier selon les termes de la Licence Art Libre.
Vous trouverez un exemplaire de cette Licence sur le site Copyleft Attitude http://www.artlibre.org/ ainsi que sur d'autres sites.

Action rssgp pour Wikini:  v.0.0.3

développement:
voir: http://poietic-generator.net/wikini/wakka.php?wiki=RssGP
url : http://www.x-arn.org/w3/ActionRssgp
dev : http://www.wikini.net/wakka.php?wiki=ActionRssgp

utilise wz_tooltip.js
http://www.walterzorn.com/tooltip/tooltip_e.htm

parametres:
- size: nombre de colonnes et lignes du carré global : il y a un fil RSS par ligne, le nombre de fils devrait donc être inférieur ou égal à size. Les fils supplémentaires ne sont pas traités.
- aff: affichage 100% ou taille fixe en pixel 
- limit : nombre d'item max par fil (vaut size par défaut)
- assoc: associations couleur|mot-clé séparés par des points virgules les couleurs prédéfinies sont: rouge, vert, bleu, jaune, fushia, cyan. On peut aussi utiliser des triplets rgb sous la forme r,g,b (valeurs numériques entre 0 et 255 séparées par des virgules). les associations sont traitées dans l'ordre, donc un item qui condiendra 2 mots-clés différents prendra la couleur du dernier mot trouvé dans la liste.
- rss: liste de fils RSS séparés par des points virgules
- refresh: temps de rafraichissement automatique en minutes
- field: permet de limiter la recherche sur un champ ("author","title","description")

usage (exemple): 
Attention, il peut y avoir des espaces après les points-virgules, mais pas de retour ligne.

{{rssgp refresh="60" size="7" aff="100%"  assoc="bleu|ducamp;rouge|auber;jaune|guennec;fushia|bourguet;cyan|vodjdani;vert|constitution"
rss="http://www.wikini.net/wakka.php?wiki=DerniersChangementsRSS/xml; 
http://poietic-generator.net/wikini/wakka.php?wiki=DerniersChangementsRSS/xml;  http://wiki.crao.net/index.php/%C9ditionsR%E9centes?format=rss; http://www.emacswiki.org/cw/rss; http://www.usemod.com/cgi-bin/mb.pl?action=rss&days=1"}}
*/

//mettre ici le chemin vers le fichier wz_tooltip.js sur votre serveur
define('WSTOOLTIP','http://www.example.net/../../wz_tooltip.js');

Class 
RssReader {
    
    var 
$xml_file// url du fil RSS
    
var $host// nom de domaine du fil
    
var $xml_parser;
    var 
$data;
    var 
$fp;
    var 
$store;
    var 
$cur_tag
    var 
$cur_data
    var 
$cur_item
    var 
$color//couleur de l'item
    
var $lgd// mot clé associé à l'item
    
var $keywords//tableau d'associations couleurs/motsclés
    
    
var $html//resultat HTML
    
    
var $size;
    var 
$img_size;
    
    var 
$limit_item_feed//nombre de colonnes = nombre d'items par feed
    
var $limit_item_total//nombre total de cases, items

    
var $count_item_feed// compteur d'items affichés par feed
    
var $count_item_total// compteur total
    
var $tableau_couleur//associations noms de couleurs / couleurs rgb
    
    
var $aff// affichage 100% ou taille fixe
    
var $limit//nombre d'item max par feed
    
var $field//champ de recherche exclusif
    
    
function rssreader() {
        
$this->store FALSE;
        
$this->cur_item = array("title"=>"""link"=>"""description"=>"""date"=>"""author"=>"");
        
$this->html "";
        
$this->count_item_feed 0;
        
$this->count_item_total 0;
        
$this->tableau_couleur = array("bleu"=>"0,0,255""rouge"=>"255,0,0""vert"=>"0,225,0""jaune"=>"255,255,0""fushia"=>"255,0,255""cyan"=>"0,255,255");
        
$this->field "";
        return 
$this;
    }
    
    
//nombre de colonnes / lignes du carré global
    
function setSize($size) {
        
$this->size $size;
        
// le nombre total d'items est limité au nombre de cases du carré global donné par size
        
$this->limit_item_total $this->size $this->size
    }
    
    function 
getSize() {
        return 
$this->size;
    }
    
    
//taille du carré global pour affichage
    
function setAff($aff) {
        if(
$aff == "100%") {
            
$this->aff $aff;
            
$this->img_size floor(100/$this->size)."%"//setSize() doit être appelé avant
        
} else if (preg_match("'^[0-9]{1,3}$'"$aff)) {
            
$this->aff ceil($aff)."px";
            
$this->img_size floor($this->aff/$this->size)."px";
        } 
    }
    
    
//nombre limite d'item par feed
    
function setLimit($l) {
        if(
preg_match("'^[0-9]{1,3}$'"$l)) {
            
$this->limit_item_feed $l;
        } else {
            
$this->limit_item_feed $this->size;
        }
    }
    
    function 
setField($f) {
        
$this->field htmlentities($f);
    }
    
    function 
setKeywords($kw) {
        
//kw sous la forme 
        //bleu|ducamp;rouge|auber;jaune|guennec;fushia|bourguet;cyan|vodjdani;vert|constitution"
        //assoc de couleurs
        // on créé le tableau d'associations
        
$tab explode(";"$kw);
        foreach(
$tab as $t) {
            
$a explode("|"$t);
            
$col trim($a[0]); 
            
$k trim($a[1]); 
            
//couleur prédéfinie
            
if(isset($this->tableau_couleur[$col])) {
                
$this->keywords[$k] = $this->tableau_couleur[$col];
            
//couleur rgb sous la forme r,g,b    
            
} else if(preg_match("'^[0-9]{1,3},[0-9]{1,3},[0-9]{1,3}$'"$col)) {
                
$this->keywords[$k] = $col;
            
//couleur par défaut    
            
} else {
                
$this->keywords[$k] = "0,0,0";
            }
        }
        
//return $this;
    
}
    
    function 
getKeywords() {
        
$this->legende "";
        while(list(
$k,$v) = each($this->keywords)) {
            
$this->legende .= "<span style=\"color:rgb($v)\">$k</span> ";
        }
        
reset($this->keywords);
        return 
$this->legende;
    }
    
    function 
getColor() {
        
    }
    
    function 
startElement($parser$name$attribs) {
        if(
$name == "ITEM") {
            
$this->store TRUE;
        }
        
$this->cur_tag $name;
        
$this->cur_data "";
    }

    function 
endElement($parser$name) {
        if(
$name == "ITEM") {
            
$this->count_item_feed++;
            
//couleur par défaut de l'item
            
$this->color "background-color:rgb(210,210,210)";
            if(
is_array($this->keywords)) {
                
$this->lgd "";
                while( list(
$k$v) = each($this->keywords) ) {
                    
                    if( 
$this->field == "author" && eregi($k$this->cur_item['author']) || 
                     
$this->field == "title" && eregi($k$this->cur_item['title']) || 
                     
$this->field == "description" && eregi($k$this->cur_item['description']) 
                     ) {
                            
$this->color "background-color:rgb($v)";
                            
$this->lgd $k;
                        
                    } else if (
$this->field == ""){
                    
                    
                        if(
eregi($k$this->cur_item['title']) || eregi($k$this->cur_item['author']) || eregi($k$this->cur_item['description']) ) {
                        
                            
$this->color "background-color:rgb($v)";
                            
$this->lgd $k;
                        }
                        
                    }    
                }
                
reset($this->keywords);
            } else {
                echo 
"<!-- debug:: not an array -->\n";
            }
            
            
/*
            
            */
            
            
if( $this->count_item_total<$this->limit_item_total && $this->count_item_feed<=$this->limit_item_feed ) {
                    
                    
$ptitle $this->host;
                    if(
$this->lgd != "") { 
                        
$ptitle .= "  (mot-cl&eacute;: $this->lgd) "//<span style=\"background-color:".$this->color."\">&nbsp;</span> 
                    
}
                    
$txt "<b>" addslashes(htmlentities($this->cur_item['title'])) . " </b>---  " addslashes(htmlentities($this->cur_item['author'])) . " (" htmlentities($this->cur_item['date']) . ")   " addslashes(htmlentities($this->cur_item['description']));
                    
$txt ereg_replace("\("""$txt);
                    
$txt ereg_replace("\)"""$txt);
                    
$txt preg_replace("'([\r\n])+'"""$txt);  
                    
$this->html .= "<a href=\"".$this->cur_item['link']."\" title=\"$txt\" onmouseover=\"this.T_TITLE='$ptitle';this.T_BGCOLOR='#E6FFFB';this.T_OFFSETX=20;this.T_OFFSETY=20;this.T_STICKY=1;return escape('$txt')\"><img style=\"width:".$this->img_size.";height:".$this->img_size.";border:none;".$this->color."\" src=\"http://www.x-arn.org/0.gif\" alt=\"\"></a>"//
                    
                    
$this->count_item_total++;
                    
                } else {
                    
//echo "debug::$this->count_item_total<=$this->limit_item_total && $this->count_item_feed<=$this->limit_item_feed<br>";
                
}

                
$this->cur_item['title'] = ''
                
$this->cur_item['link'] = ''
                
$this->cur_item['description'] = ''
                
$this->cur_item['date'] = ''
                
$this->cur_item['author'] = ''
                
$this->storeFALSE
            }
        }

        function 
characterData ($parser$data) {
            if(
$this->store == TRUE) {
                if(
$this->cur_tag == "TITLE") {
                    
$this->cur_item['title'] .= rtrim($data);
                }
                else if(
$this->cur_tag == "LINK") {
                    
$this->cur_item['link'] .= rtrim($data);
                }
                else if(
$this->cur_tag == "DESCRIPTION") {
                    
$this->cur_item['description'] .=  rtrim($data);
                }
                else if(
$this->cur_tag == "DC:DATE") {
                    
$this->cur_item['date'] .=  $data;
                }
                else if(
$this->cur_tag == "DC:CONTRIBUTOR") {
                    
$this->cur_item['author'] .=  $data;
                }
            }
        }



        function 
parseRss($xml_file) {
            
$this->xml_file trim($xml_file);
            
$u parse_url($this->xml_file);
            
$this->host $u['host'];
            
$this->html "";
            
            if (
$this->count_item_total $this->limit_item_total) {
            
                if(
$this->fp fopen($this->xml_file"r")) {
                
//$this->html .= "<a href=\"".$this->xml_file."\">RSS</a><br />";
                
$this->xml_parser xml_parser_create();
                
xml_set_object($this->xml_parser$this);
                
xml_set_element_handler($this->xml_parser,"startElement""endElement");
                
xml_set_character_data_handler($this->xml_parser"characterData");
                while (
$this->data fread($this->fp4096)) {
                    
//if($encoding == "utf-8") {
                     //   $data = utf8_decode($data);
                    //}
                    
xml_parse($this->xml_parser$this->data);
                    
//echo "debug:<b>$this->count_item_feed </b><br>";
                
}
                
fclose($this->fp);
                
//echo "<h3>".xml_error_string(xml_get_error_code($this->xml_parser))."</h3>";
                
xml_parser_free ($this->xml_parser);
                
$this->count_item_feed 0;
                
                
                } else {
                    
$this->html "<!-- feed $this->xml_file not available -->\n";
                }
            } else {
                
$this->html "<!-- feed $this->xml_file outside limit  $this->limit_item_total -->\n";
            }
            return 
$this->html;
        }


}
    
    
    
//if(!$encoding =  $this->GetParameter("encoding")) {
//    $encoding = "iso-8859-1";
//}
?>

<?php
if(!$rss =  $this->GetParameter("rss")) {
    echo 
"veuillez spécifier des adresses de fil RSS avec le paramètre rss";
} else {
    
$gp = new RssReader();
    
    
$gp->setKeywords($this->GetParameter("assoc"));
    
    if(!
$s =  $this->GetParameter("size")) {     // nombre de carré/item par ligne
        
$s 10;
    }
    
$gp->setSize($s);  
    
    if(!
$a =  $this->GetParameter("aff")) {      // taille d'affichage du carré global
        
$a 200;
    }
    
$gp->setAff($a);  
    
    if(!
$l =  $this->GetParameter("limit")) {    // nombre d'item max par feed
        
$l $gp->getSize();
    }
    
$gp->setLimit($l);
    
    if(
$field =  $this->GetParameter("field")) { // champ de recherche exclusif
        
$gp->setField($field);
    }
    
    echo 
"<div style=\"width:".$gp->aff.";height:".$gp->aff.";background-color:#000000\">";
    
    
$x explode(";"$rss);
    foreach(
$x as $xf) {
        echo 
$gp->parseRss($xf);
    }
    
    echo 
"</div>";
}


//delai de rafraichissement en minutes
if(!$refresh $this->GetParameter("refresh")) {
    
$refresh 60000*5;//5 minutes
} else {
    
$refresh 60000 $this->GetParameter("refresh");
}
echo 
"<script language=\"javascript\" type=\"text/javascript\">setTimeout('this.location.reload()', $refresh);</script>";
echo 
"<script language=\"JavaScript\" type=\"text/javascript\" src=\"".WSTOOLTIP."\"></script>";
?>

Il n'y a pas de commentaire sur cette page. [Afficher commentaires/formulaire]