fetch_global_properties();
//Affichage du formulaire en fonction de $this->parameters
if ($this->parameters) {
$keys = unserialize($this->parameters);
$login= $keys['login'];
$mdp=$keys['mdp'];
} else {
$login="";
$mdp="";
}
$r="
";
return $r;
}
public function make_serialized_properties() {
global $login, $mdp;
//Mise en forme des paramètres à partir de variables globales (mettre le résultat dans $this->parameters)
$keys = array();
$keys['login']=$login;
$keys['mdp']=$mdp;
$this->parameters = serialize($keys);
}
public function enrichment_is_allow(){
return true;
}
public function getEnrichmentHeader($source_id){
$header= array();
$header[]= "";
$header[]= "";
return $header;
}
public function getTypeOfEnrichment($notice_id,$source_id){
$type = array();
$type['type'] = array(
"citation",
"critique"
);
$type['source_id'] = $source_id;
return $type;
}
public function getEnrichment($notice_id,$source_id,$type="",$enrich_params=array(),$page=1){
$enrichment= array();
$this->noticeToEnrich = $notice_id;
$this->enrichPage = $page;
//on renvoi ce qui est demandé... si on demande rien, on renvoi tout..
$rqt="select code from notices where notice_id = '$notice_id'";
$res=pmb_mysql_query($rqt);
if(pmb_mysql_num_rows($res)){
$code = pmb_mysql_result($res,0,0);
$code = preg_replace('/-|\.| /', '', $code);
}
$this->typeOfEnrichment = $type;
switch ($this->typeOfEnrichment){
case "citation" :
$enrichment['citation']['content'] = $this->getInfos(2,$code);
break;
case "critique" :
$enrichment['critique']['content'] = $this->getInfos(1,$code);
break;
default :
$enrichment['citation']['content'] = $this->getInfos(2,$code);
$enrichment['critique']['content'] = $this->getInfos(1,$code);
break;
}
$enrichment['source_label']=$this->msg['babelio_enrichment_source'];
return $enrichment;
}
public function getInfos($type,$isbn){
if(!$isbn) return "";
$return = "";
$t = time();
$url = "http://www.babelio.info/sxml/$isbn&type=$type&page=".$this->enrichPage."&auth=".$this->getHash($t)."×tamp=$t";
$curl = new Curl();
$xmlToParse = $curl->get($url);
$xmlToParse = utf8_decode($xmlToParse);
$xmlToParse=$this->cp1252Toiso88591($xmlToParse);
$xmlToParse = str_replace("utf-8","iso-8859-1",$xmlToParse);
$xml = _parser_text_no_function_($xmlToParse,"URLSET");
$return = $this->formatEnrichmentResult($xml);
$return.= $this->getEnrichmentPagin($xml['SOMMAIRE'][0]);
return $return;
}
public function getHash($t){
$keys = unserialize($this->parameters);
return md5($keys['login'].md5($keys['mdp'])."PMB".$t);
}
public function getEnrichmentPagin($sommaire){
global $msg;
$current = $sommaire['PAGE'][0]['value'];
$nb_page = ceil($sommaire['NB_RESULTATS'][0]['value']/$sommaire['RESULTATS_PAR_PAGE'][0]['value']);
$ret = "";
if($current > 1) $ret .= "";
else $ret .= "";
$ret .=" ".$current."/$nb_page ";
if($current < $nb_page) $ret .= "noticeToEnrich."\",\"".$this->typeOfEnrichment."\",\"".$current."\",\"next\");'/>";
else $ret .= "";
return "".$ret."
";
}
public function formatEnrichmentResult($xml){
$result = "";
foreach($xml['URL'] as $url){
$d = explode("T",$url['DT'][0]['value']);
$date = formatdate($d[0]);
$result.="
".
$this->msg['babelio_enrichment_publish_date']." ".$date;
if($this->typeOfEnrichment == 'critique') $result.= " ".$this->stars(isset($url['NOTE'][0]['value']) ? $url['NOTE'][0]['value'] : 0) ;
$result.="
";
foreach($url['SNIPPET'] as $content){
$result.= $content['value'];
}
$result.="
".$this->msg['babelio_enrichment_see_more']."
";
}
return $result;
}
// Gestion des étoiles pour les notes
public function stars($note) {
$etoiles_moyenne="";
$cpt_star = 5;
for ($i = 1; $i <= $cpt_star; $i++) {
if($note >= $i) $etoiles_moyenne.="";
else $etoiles_moyenne.="";
}
return $etoiles_moyenne;
} // fin stars()
public function cp1252Toiso88591($str){
$cp1252_map = array(
"\x80" => "EUR", /* EURO SIGN */
"\x82" => "\xab", /* SINGLE LOW-9 QUOTATION MARK */
"\x83" => "\x66", /* LATIN SMALL LETTER F WITH HOOK */
"\x84" => "\xab", /* DOUBLE LOW-9 QUOTATION MARK */
"\x85" => "...", /* HORIZONTAL ELLIPSIS */
"\x86" => "?", /* DAGGER */
"\x87" => "?", /* DOUBLE DAGGER */
"\x88" => "?", /* MODIFIER LETTER CIRCUMFLEX ACCENT */
"\x89" => "?", /* PER MILLE SIGN */
"\x8a" => "S", /* LATIN CAPITAL LETTER S WITH CARON */
"\x8b" => "\x3c", /* SINGLE LEFT-POINTING ANGLE QUOTATION */
"\x8c" => "OE", /* LATIN CAPITAL LIGATURE OE */
"\x8e" => "Z", /* LATIN CAPITAL LETTER Z WITH CARON */
"\x91" => "\x27", /* LEFT SINGLE QUOTATION MARK */
"\x92" => "\x27", /* RIGHT SINGLE QUOTATION MARK */
"\x93" => "\x22", /* LEFT DOUBLE QUOTATION MARK */
"\x94" => "\x22", /* RIGHT DOUBLE QUOTATION MARK */
"\x95" => "\b7", /* BULLET */
"\x96" => "\x20", /* EN DASH */
"\x97" => "\x20\x20", /* EM DASH */
"\x98" => "\x7e", /* SMALL TILDE */
"\x99" => "?", /* TRADE MARK SIGN */
"\x9a" => "S", /* LATIN SMALL LETTER S WITH CARON */
"\x9b" => "\x3e;", /* SINGLE RIGHT-POINTING ANGLE QUOTATION*/
"\x9c" => "oe", /* LATIN SMALL LIGATURE OE */
"\x9e" => "Z", /* LATIN SMALL LETTER Z WITH CARON */
"\x9f" => "Y" /* LATIN CAPITAL LETTER Y WITH DIAERESIS*/
);
return strtr($str, $cp1252_map);
}
}
?>