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) {
global $charset;
global $pmb_url_base;
global $token;
$params=$this->get_source_params($source_id);
if ($params["PARAMETERS"]) {
//Affichage du formulaire avec $params["PARAMETERS"]
$vars=unserialize($params["PARAMETERS"]);
foreach ($vars as $key=>$val) {
global $$key;
$$key=$val;
}
}
if($source_id!=0){
$url = $pmb_url_base."admin.php?categ=connecteurs&sub=in&act=add_source&id=15&source_id=".$source_id;
}else{
$url = $this->msg['lastfm_no_source'];
}
$form="
".$this->msg["lastfm_callback_url"]."
".$url."
".$this->msg["lastfm_token"]."
";
if($token != ""){
$form.="
".$this->msg['lastfm_ws_allow_in_progress']."
";
}else if($token_saved!=""){
$form.="
".$this->msg['lastfm_ws_allowed']."
";
}else if($api_key != ""){
$form.="
".$this->msg['lastfm_link_allow_ws']." ";
}else{
$form.="
".$this->msg['lastfm_allow_need_api_key']." ";
}
$form.="
";
return $form;
}
function make_serialized_source_properties($source_id) {
global $api_key,$secret_key,$token_saved;
$t=array();
$t["api_key"]=$api_key;
$t["secret_key"]=$secret_key;
$t["token_saved"]=$token_saved;
$this->sources[$source_id]["PARAMETERS"]=serialize($t);
}
//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();
$this->parameters = serialize($keys);
}
function enrichment_is_allow(){
return true;
}
function getEnrichmentHeader(){
$header= array();
$header[]= "";
$header[]= "";
return $header;
}
function getTypeOfEnrichment($source_id){
$type['type'] = array(
"bio",
array(
"code" => "similar_artists",
"label" => "Artistes Similaires"
),
array(
"code" => "pictures",
"label" => "Photos"
)
);
$type['source_id'] = $source_id;
return $type;
}
function getEnrichment($notice_id,$source_id,$type="",$params=array(),$page=1){
$enrichment= array();
$this->enrichPage = $page;
$this->noticeToEnrich = $notice_id;
$this->typeOfEnrichment = $type;
//on renvoi ce qui est demandé... si on demande rien, on renvoi tout..
switch ($type){
case "bio" :
$enrichment['bio']['content'] = $this->get_artist_biography($source_id);
break;
case "events" :
$enrichment['events']['content'] = $this->get_artist_events($source_id);
break;
case "similar_artists" :
$enrichment['similar_artists']['content'] = $this->get_similar_artists($source_id);
break;
case "pictures" :
$enrichment['pictures']['content'] = $this->get_pictures($source_id);
break;
}
$enrichment['source_label']=$this->msg['lastfm_enrichment_source'];
return $enrichment;
}
function get_notice_infos(){
$infos = array();
//on va chercher le titre de la notice...
$query = "select tit1 from notices where notice_id = ".$this->noticeToEnrich;
$result = mysql_query($query);
if(mysql_num_rows($result)){
$infos['title'] = mysql_result($result,0,0);
}
//on va chercher l'auteur principal...
$query = "select responsability_author from responsability where responsability_notice =".$this->noticeToEnrich." and responsability_type=0";
$result = mysql_query($query);
if(mysql_num_rows($result)){
$author_id = mysql_result($result,0,0);
$author = new auteur($author_id);
$infos['author'] = $author->isbd_entry;
}
return $infos;
}
function get_artist_biography($source_id){
$this->init_ws($source_id);
$bio = $this->api->get_artist_biography();
// highlight_string(print_r($bio,true));
if ($bio['content'] != ""){
return utf8_decode(nl2br($bio['content']));
}else{
return $this->msg['lastfm_no_informations'];
}
}
function get_similar_artists($source_id){
$this->init_ws($source_id);
$similar = $this->api->get_similar_artists();
// highlight_string(print_r($similar,true));
$html = "
";
return $html;
}
function get_pictures($source_id){
global $charset;
$this->init_ws($source_id);
$pictures = $this->api->get_pictures($this->enrichPage);
if($pictures['total']>0){
$html = "
";
for($i=0 ; $i";
}
$html.= "
";
if($i%4 == 3){
$html.="
";
}
}
$html .= "
";
$html.=$this->get_pagin_form($pictures);
}else{
$html = $this->msg['lastfm_no_informations'];
}
return $html;
}
function init_ws($source_id){
$params=$this->get_source_params($source_id);
if ($params["PARAMETERS"]) {
//Affichage du formulaire avec $params["PARAMETERS"]
$vars=unserialize($params["PARAMETERS"]);
foreach ($vars as $key=>$val) {
global $$key;
$$key=$val;
}
}
$authVars['apiKey'] = $api_key;
$authVars['secret'] = $secret_key;
$authVars['token'] = $token_saved;
$this->api = new lastfm_api($authVars);
$this->api->set_notice_infos($this->get_notice_infos());
}
function get_pagin_form($infos){
$current = $infos['page'];
$ret = "";
if($current>0){
$nb_page = ceil($infos['total']/20);
if($current > 1) $ret .= " ";
else $ret .= " ";
$ret .=" ".$current."/$nb_page ";
if($current < $nb_page) $ret .= " ";
else $ret .= " ";
$ret = "
$ret ";
}
return $ret;
}
}
?>