get_source_params($source_id); if ($params["PARAMETERS"]) { $vars=unserialize($params["PARAMETERS"]); $params["PARAMETERS"]=$vars; } return $params; } function get_libelle($message) { if (substr($message,0,4)=="msg:") return $this->msg[substr($message,4)]; else return $message; } function source_get_property_form($source_id) { return ""; } function make_serialized_source_properties($source_id) { $this->sources[$source_id]["PARAMETERS"]=serialize(array()); } //Récupération des proriétés globales par défaut du connecteur (timeout, retry, repository, parameters) function fetch_default_global_values() { $this->timeout=5; $this->repository=2; $this->retry=3; $this->ttl=1800; $this->parameters=""; } //Formulaire des propriétés générales function get_property_form() { return ""; } function make_serialized_properties() { global $accesskey, $secretkey; //Mise en forme des paramètres à partir de variables globales (mettre le résultat dans $this->parameters) $keys = array(); $keys['accesskey']=$accesskey; $keys['secretkey']=$secretkey; $this->parameters = serialize($keys); } function enrichment_is_allow(){ return true; } function getEnrichmentHeader(){ global $lang; $header= array(); $header[]= ""; $header[]= ""; return $header; } function getTypeOfEnrichment($source_id){ $type['type'] = array( array( 'code' => "wiki", 'label' => $this->msg["wikipedia_label"] ), "bio" ); $type['source_id'] = $source_id; return $type; } function getEnrichment($notice_id,$source_id,$type="",$enrich_params=array()){ $enrichment= array(); //on renvoi ce qui est demandé... si on demande rien, on renvoi tout.. switch ($type){ case "bio" : $enrichment['bio']['content'] = $this->get_author_page($notice_id,$enrich_params); break; case "wiki" : default : $enrichment['wiki']['content'] = $this->noticeInfos($notice_id); break; } $enrichment['source_label']=$this->msg['wikipedia_enrichment_source']; return $enrichment; } function get_author_page($notice_id,$enrich_params){ global $lang; global $charset; if($enrich_params['label']!=""){ $author = $enrich_params['label']; }else{ //on va chercher l'auteur principal... $query = "select responsability_author from responsability where responsability_notice =".$notice_id." and responsability_type=0"; $result = mysql_query($query); if(mysql_num_rows($result)){ $author_id = mysql_result($result,0,0); $author_class = new auteur($author_id); $author = $author_class->isbd_entry; } } $curl = new Curl(); //on fait un premier appel pour regarder si on a quelque chose chez Wikipédia... $url = "http://".substr($lang,0,2).".wikipedia.org/w/api.php?format=json&action=opensearch&search=".rawurlencode($author)."&limit=20"; $json = $curl->get($url); $search = json_decode($json); if(count($search[1])==1 || $enrich_params['label']!=""){ $url = "http://".substr($lang,0,2).".wikipedia.org/w/api.php?format=json&action=query&titles=".rawurlencode($search[1][0])."&prop=revisions&rvprop=content&rvparse=1"; $json = $curl->get($url); $response = json_decode($json); $html_to_return=""; foreach($response->query->pages as $page){ foreach($page->revisions[0] as $rev){ $html_to_return .= utf8_decode($rev); } } $html_to_return = str_replace("href=\"/","target='_blank' href=\"http://".substr($lang,0,2).".wikipedia.org/",$html_to_return); @ini_set("zend.ze1_compatibility_mode", "0"); $dom = new domDocument(); $dom->loadHTML($html_to_return); $spans = $dom->getElementsByTagName("span"); for($i=0; $i<$spans->length ; $i++){ for($j=0 ; $j<$spans->item($i)->attributes->length ; $j++){ if($spans->item($i)->attributes->item($j)->name == "class" && $spans->item($i)->attributes->item($j)->nodeValue == "editsection"){ $spans->item($i)->parentNode->removeChild($spans->item($i)); } } } $html_to_return = $dom->saveHTML(); @ini_set("zend.ze1_compatibility_mode", "1"); }else if(count($search[1])>1){ //si plus d'un résultat on propose le choix... $html_to_return = "
".utf8_decode($search[1][$i])." | "; if($i%4 == 3){ $html_to_return.= " "; } } $html_to_return.= "