set_default_enrichment_template(); } public function get_id() { return "toutapprendre"; } //Est-ce un entrepot ? public function is_repository() { return 1; } public function source_get_property_form($source_id) { global $charset; $params=$this->get_source_params($source_id); if ($params["PARAMETERS"]) { //Affichage du formulaire avec $params["PARAMETERS"] $vars=unserialize($params["PARAMETERS"]); } //URL if (!isset($vars['url'])) $vars['url'] = ""; $form="
"; // Champ perso de notice à utiliser $form .= "
"; // Template de l'enrichissement $form .= "
"; $form .="
"; return $form; } public function make_serialized_source_properties($source_id) { global $url, $cp_field, $enrichment_template; $t = array(); $t["url"]=stripslashes($url); $t["cp_field"] = $cp_field; $t['enrichment_template'] = ($enrichment_template ? $enrichment_template : addslashes($this->default_enrichment_template)); $this->sources[$source_id]["PARAMETERS"]=serialize($t); } //Récupération des proriétés globales par défaut du connecteur (timeout, retry, repository, parameters) public function fetch_default_global_values() { parent::fetch_default_global_values(); $this->timeout=40; $this->repository=1; } //Formulaire des propriétés générales public function get_property_form() { global $charset; $this->fetch_global_properties(); //Affichage du formulaire en fonction de $this->parameters if ($this->parameters) { $keys = unserialize($this->parameters); $establishmentid= $keys['establishmentid']; $privatekey=$keys['privatekey']; } else { $establishmentid=""; $privatekey=""; } $r="
"; return $r; } public function make_serialized_properties() { global $establishmentid, $privatekey; $keys = array( 'establishmentid' => $establishmentid, 'privatekey' => $privatekey ); $this->parameters=serialize($keys); } public function progress($query,$token) { $callback_progress=$this->callback_progress; if ($token["completeListSize"]) { $percent=($this->current_set/$this->total_sets)+(($token["cursor"]/$token["completeListSize"])/$this->total_sets); $nlu=$this->n_recu; $ntotal="inconnu"; //$nlu=$token["cursor"]; //$ntotal=$token["completeListSize"]; } else { $percent=($this->current_set/$this->total_sets); $nlu=$this->n_recu; $ntotal="inconnu"; } call_user_func($callback_progress,$percent,$nlu,$ntotal); } public function cancel_maj($source_id) { return true; } public function break_maj($source_id) { return true; } public function maj_entrepot($source_id,$callback_progress="",$recover=false,$recover_env="") { global $base_path,$charset; $this->n_recu=0; $this->callback_progress=$callback_progress; $params=$this->get_source_params($source_id); $this->fetch_global_properties(); if ($params["PARAMETERS"]) { //Affichage du formulaire avec $params["PARAMETERS"] $vars=unserialize($params["PARAMETERS"]); foreach ($vars as $key=>$val) { global ${$key}; ${$key}=$val; } } if (!isset($url)) { $this->error_message = $this->msg["toutapprendre_unconfigured"]; $this->error = 1; return; } //Recherche de la dernière date... $requete="select unix_timestamp(max(date_import)) from entrepot_source_".$source_id." where 1;"; $resultat=pmb_mysql_query($requete); if (pmb_mysql_num_rows($resultat)) { $last_date=pmb_mysql_result($resultat,0,0); if ($last_date) { $last_date+=3600*24; } } $ch = curl_init(); $addr=$url; // configuration des options CURL curl_setopt($ch, CURLOPT_URL, $addr); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); configurer_proxy_curl($ch,$addr); $xml=curl_exec($ch); if($charset=='utf-8') $xml = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]'. '|[\x00-\x7F][\x80-\xBF]+'. '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*'. '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})'. '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/', '?', $xml ); $this->dom = new DomDocument(); $this->dom->encoding = $charset; if(!@$this->dom->loadXML($xml)) return 0; $cours = $this->dom->getElementsByTagName('cours'); foreach($cours as $cour){ $data_notice=array(); if($cour->childNodes->length) { foreach($cour->childNodes as $i) { if ($i->nodeName == "lecons") { $ind = 0; foreach ($i->childNodes as $lecon) { if ($lecon->nodeName != "#text") { foreach ($lecon->childNodes as $propLecon) { if ($propLecon->nodeName != "#text") { if($charset!='utf-8') $val= utf8_decode($propLecon->nodeValue); else $val=$propLecon->nodeValue; $data_notice[$i->nodeName][$ind][$propLecon->nodeName] = $val; } } $ind++; } } } else if ($i->nodeName != "#text") { if($charset!='utf-8') $val= utf8_decode($i->nodeValue); else $val=$i->nodeValue; $data_notice[$i->nodeName] =$val; } } } $this->rec_record($this->notice_2_uni($data_notice),$source_id); } curl_close($ch); return $this->n_recu; } public function notice_2_uni($nt) { global $dbh; global $cp_field; $unimarc=array(); $unimarc["001"][0]=$nt["pk"]; $unimarc["200"][0]["a"][0]=$nt["titre"]; //Editeur if ($nt["editeur"]) $unimarc["210"][0]["c"][0]=$nt["editeur"]; //Résumé if ($nt["description"]) $unimarc["330"][0]["a"][0]=$nt["description"]; // Link demo if(count($nt["demo"])) $unimarc["856"][0]["u"][0]=urldecode($nt["demo"]); // Keywords if ($nt["categorie"]) $unimarc["610"][0]["a"][0]=$nt["categorie"]; // vignette if ($nt["thumbnail"]) $unimarc["896"][0]["a"][0]=$nt["thumbnail"]; // collation if ($nt["dureeCours"]) $unimarc["215"][0]["a"][0]=$nt["dureeCours"]; // source $unimarc["801"][0]["a"][0]="FR"; $unimarc["801"][0]["b"][0]="ToutApprendre"; // champ perso if ($cp_field) { $query = "select name from notices_custom where idchamp = ".$cp_field; $result = pmb_mysql_query($query, $dbh); if ($row = pmb_mysql_fetch_object($result)) { $unimarc["900"][0]["a"][0] = $nt["pk"]; $unimarc["900"][0]["n"][0] = $row->name; } } // leçons foreach ($nt["lecons"] as $indice => $lecon){ $unimarc["917"][$indice]["a"][0] = $lecon["pkLecon"]; $unimarc["917"][$indice]["b"][0] = $lecon["titreLecon"]; } return $unimarc; } public function rec_record($record,$source_id) { global $charset,$base_path,$url,$search_index; $date_import=date("Y-m-d H:i:s",time()); //Recherche du 001 $ref=$record["001"][0]; //Mise à jour if ($ref) { //Si conservation des anciennes notices, on regarde si elle existe if (!$this->del_old) { $ref_exists = $this->has_ref($source_id, $ref); if($ref_exists) return 1; } //Si pas de conservation des anciennes notices, on supprime if ($this->del_old) { $this->delete_from_entrepot($source_id, $ref); $this->delete_from_external_count($source_id, $ref); } //Si pas de conservation ou reférence inexistante if (($this->del_old)||((!$this->del_old)&&(!$ref_exists))) { //Insertion de l'entête $n_header["rs"]="*"; $n_header["ru"]="*"; $n_header["el"]="1"; $n_header["bl"]="m"; $n_header["hl"]="0"; $n_header["dt"]=$this->types[$search_index[$url][0]]; if (!$n_header["dt"]) $n_header["dt"]="a"; $n_header["001"]=$record["001"][0]; //Récupération d'un ID $recid = $this->insert_into_external_count($source_id, $ref); foreach($n_header as $hc=>$code) { $this->insert_header_into_entrepot($source_id, $ref, $date_import, $hc, $code, $recid); } $field_order=0; foreach ($record as $field=>$val) { for ($i=0; $i$vals) { for ($j=0; $jinsert_content_into_entrepot($source_id, $ref, $date_import, $field, $sfield, $field_order, $j, $vals[$j], $recid); } } } else { //if ($charset!="utf-8") $vals[$i]=utf8_decode($vals[$i]); $this->insert_content_into_entrepot($source_id, $ref, $date_import, $field, '', $field_order, 0, $val[$i], $recid); } $field_order++; } } $this->rec_isbd_record($source_id, $ref, $recid); $this->n_recu++; } } } public function enrichment_is_allow(){ return true; } public function getTypeOfEnrichment($source_id){ $type['type'] = array( array( "code" => "toutapprendre", "label" => $this->msg['toutapprendre_toutapprendre'] ) ); $type['source_id'] = $source_id; return $type; } public function getEnrichment($notice_id,$source_id,$type="",$enrich_params=array()){ $enrichment= array(); return $enrichment; } public function getEnrichmentHeader(){ $header= array(); return $header; } /** * Définit le template par défaut de l'enrichissement */ private function set_default_enrichment_template() { $this->default_enrichment_template = "{* Template par défaut *}
{* titre *} {% if lessons.title %}

{{ lessons.title }}

{% endif %} {* catégorie *} {% if lessons.category %}

{{ lessons.category }}

{% endif %} {* éditeur *} {% if lessons.publisher %}

Par {{ lessons.publisher }}

{% endif %} {* durée *} {% if lessons.duration %}

Durée : {{ lessons.duration }}

{% endif %} {* démonstration *} {% if lessons.demo %}

{{ 'Démonstration' | links_to lessons.demo }}

{% endif %} {* leçons *} {% if lessons.base_url %} {% for lesson in lessons.lessons %} {% if loop.first %} Leçons : {% endif %} {% endfor %} {% else %} {% for lesson in lessons.lessons %} {% if loop.first %} Leçons : (Veuillez vous connecter pour y accéder en ligne)
    {% endif %}
  • {{ lesson.title }}
  • {% if loop.last %}
{% endif %} {% endfor %} {% endif %}
"; } }// class end