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="
".$url."
";
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;
}
public 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);
}
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['type'] = array(
"bio",
array(
"code" => "similar_artists",
"label" => "Artistes Similaires"
),
array(
"code" => "pictures",
"label" => "Photos"
)
);
$type['source_id'] = $source_id;
return $type;
}
public 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;
}
public 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 = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
$infos['title'] = pmb_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 = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
$author_id = pmb_mysql_result($result,0,0);
$author = new auteur($author_id);
//$infos['author'] = $author->display;
$infos['author'] = ($author->rejete!= ""? $author->rejete." ":"").$author->name;
}
return $infos;
}
public 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'];
}
}
public 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;
}
public 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;
}
public 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());
}
public 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;
}
}
?>