parameters= array(); $this->parameters['nb_max_elements'] = $cms_module_common_datasource_rss_limit+0; return parent::save_form(); } public function get_form(){ $form = parent::get_form(); $form.= "
"; return $form; } /* * Récupération des données de la source... */ public function get_datas(){ //on commence par récupérer l'identifiant retourné par le sélecteur... if($this->parameters['selector'] != ""){ for($i=0 ; $iselectors) ; $i++){ if($this->selectors[$i]['name'] == $this->parameters['selector']){ $selector = new $this->parameters['selector']($this->selectors[$i]['id']); break; } } @ini_set("zend.ze1_compatibility_mode", "0"); $information = array(); $loaded=false; $aCurl = new Curl(); $aCurl->timeout=2; $url = $selector->get_value(); if(is_array($url)){ $url = $url[0]; } $content = $aCurl->get($url); $flux=$content->body; if($flux && $content->headers['Status-Code'] == 200){ $rss = new domDocument(); $loaded=$rss->loadXML($flux); } if($loaded){ //les infos sur le flux... //Flux RSS if ($rss->getElementsByTagName("channel")->length > 0) { $channel = $rss->getElementsByTagName("channel")->item(0); $elements = array( 'title', 'description', 'generator', 'link' ); $informations = $this->get_informations($channel,$elements,1); //on va lire les infos des items... $informations['items'] =array(); $items = $rss->getElementsByTagName("item"); $elements = array( 'title', 'description', 'link', 'guid', 'date', 'creator', 'subject', 'format', 'language', ); for($i=0 ; $i<$items->length ; $i++){ if($this->parameters['nb_max_elements']==0 || $i < $this->parameters['nb_max_elements']){ $informations['items'][]=$this->get_informations($items->item($i),$elements,false); } } //Flux ATOM } elseif($rss->getElementsByTagName("feed")->length > 0) { $feed = $rss->getElementsByTagName("feed")->item(0); $atom_elements = array( 'title', 'subtitle', 'link', 'updated', 'author', 'id', ); $informations = $this->get_atom_informations($feed,$atom_elements,1); //on va lire les infos des entries... $informations['items'] =array(); $entries = $rss->getElementsByTagName("entry"); $atom_elements = array( 'title', 'link', 'id', 'author', 'issued', 'modified', 'published', 'content', ); for($i=0 ; $i<$entries->length ; $i++){ if($this->parameters['nb_max_elements']==0 || $i < $this->parameters['nb_max_elements']){ $informations['items'][]=$this->get_atom_informations($entries->item($i),$atom_elements,false); } } } } @ini_set("zend.ze1_compatibility_mode", "1"); return $informations; } return false; } protected function get_informations($node,$elements,$first_only=false){ global $charset; $informations = array(); foreach($elements as $element){ $items = $node->getElementsByTagName($element); if($items->length == 1 || $first_only){ $informations[$element] = $this->charset_normalize($items->item(0)->nodeValue,"utf-8"); }else{ for($i=0 ; $i<$items->length ; $i++){ $informations[$element][] = $this->charset_normalize($items->item($i)->nodeValue,"utf-8"); } } } return $informations; } protected function get_atom_informations($node,$atom_elements,$first_only=false){ global $charset; $informations = array(); foreach($atom_elements as $atom_element){ $items = $node->getElementsByTagName($atom_element); switch ($atom_element) { case "published" : $element = "date"; break; case "author" : $element = "creator"; break; case "content" : $element = "description"; break; default: $element = $atom_element; break; } if($items->length == 1 || $first_only){ if ($element == "link") { $informations[$element] = $this->charset_normalize($items->item(0)->getAttribute('href'),"utf-8"); } else { $informations[$element] = $this->charset_normalize($items->item(0)->nodeValue,"utf-8"); } }else{ if ($element == "link") { for($i=0 ; $i<$items->length ; $i++){ $informations[$element][] = $this->charset_normalize($items->item(0)->getAttribute('href'),"utf-8"); } } else { for($i=0 ; $i<$items->length ; $i++){ $informations[$element][] = $this->charset_normalize($items->item($i)->nodeValue,"utf-8"); } } } } return $informations; } public function get_format_data_structure(){ return array( array( 'var' => "title", 'desc' => $this->msg['cms_module_common_datasource_rss_title_desc'] ), array( 'var' => "description", 'desc' => $this->msg['cms_module_common_datasource_rss_description_desc'] ), array( 'var' => "generator", 'desc' => $this->msg['cms_module_common_datasource_rss_generator_desc'] ), array( 'var' => "link", 'desc' => $this->msg['cms_module_common_datasource_rss_link_desc'] ), array( 'var' => "items", 'desc' => $this->msg['cms_module_common_datasource_rss_items_desc'], 'children' => array( array( 'var' => "items[i].title", "desc" => $this->msg['cms_module_common_datasource_rss_item_title_desc'] ), array( 'var' => "items[i].description", "desc" => $this->msg['cms_module_common_datasource_rss_item_description_desc'] ), array( 'var' => "items[i].link", "desc" => $this->msg['cms_module_common_datasource_rss_item_link_desc'] ), array( 'var' => "items[i].guid", "desc" => $this->msg['cms_module_common_datasource_rss_item_guid_desc'] ), array( 'var' => "items[i].date", "desc" => $this->msg['cms_module_common_datasource_rss_item_date_desc'] ), array( 'var' => "items[i].creator", "desc" => $this->msg['cms_module_common_datasource_rss_item_creator_desc'] ), array( 'var' => "items[i].subject", "desc" => $this->msg['cms_module_common_datasource_rss_item_subject_desc'] ), array( 'var' => "items[i].format", "desc" => $this->msg['cms_module_common_datasource_rss_item_format_desc'] ), array( 'var' => "items[i].language", "desc" => $this->msg['cms_module_common_datasource_rss_item_language_desc'] ) ) ), ); } }