=') && extension_loaded('xsl')) {
require_once($include_path.'/xslt-php4-to-php5.inc.php');
}
class divercities extends oai {
const DIVERCITIES_URL_DEFAULT = "https://export.divercities.eu/oai";
const DIVERCITIES_AUTHENTICATION_URL_PATTERN_DEFAULT = "https://accounts.divercities.eu/users/auth/pmb?service=!!SERVICE!!&dest=!!DEST!!&bibid=!!STATION_ID!!&uid=!!UID!!&token=!!TOKEN!!";
const DIVERCITIES_METADATAPREFIX_DEFAULT = 'oai1dtouch_dc';
const DIVERCITIES_XSL_TRANSFORM_DEFAULT = 'oai1dtouch_dc.xsl';
const DIVERCITIES_XSL_TRANSFORM_FILE_DEFAULT = __DIR__.'/xslt/oai1dtouch_dc.xsl';
public function __construct($connector_path='') {
parent::__construct($connector_path);
$this->timeout = 30;
}
public function get_id() {
return "divercities";
}
public function get_messages($connector_path) {
global $lang;
$oai_file_name = '';
if (is_readable($connector_path."/../oai/messages/".$lang.".xml")) {
$oai_file_name=$connector_path."/../oai/messages/".$lang.".xml";
} else if (is_readable($connector_path."/../oai/messages/fr_FR.xml")) {
$oai_file_name=$connector_path."/../oai/messages/fr_FR.xml";
}
$file_name = '';
if (is_readable($connector_path."/messages/".$lang.".xml")) {
$file_name=$connector_path."/messages/".$lang.".xml";
} else if (is_readable($connector_path."/messages/fr_FR.xml")) {
$file_name=$connector_path."/messages/fr_FR.xml";
}
if ($oai_file_name) {
$xmllist = new XMLlist($oai_file_name);
$xmllist->analyser();
$this->msg=$xmllist->table;
}
if ($file_name) {
$xmllist=new XMLlist($file_name);
$xmllist->analyser();
$this->msg+=$xmllist->table;
}
}
public function source_get_property_form($source_id) {
global $base_path, $charset;
$url = '';
$clean_base_url = '';
$sets = [];
$formats = '';
$xsl_transform = [];
$del_deleted = 0;
$clean_html = '';
$divercities_authentication_url_pattern = '';
$divercities_authentication_source_id = 0;
$params = $this->unserialize_source_params($source_id);
if (!empty($params["PARAMETERS"])) {
foreach ($params["PARAMETERS"] as $key => $val) {
${$key} = $val;
}
}
if(!$source_id) {
$url = divercities::DIVERCITIES_URL_DEFAULT;
$formats = divercities::DIVERCITIES_METADATAPREFIX_DEFAULT;
$divercities_authentication_url_pattern = divercities::DIVERCITIES_AUTHENTICATION_URL_PATTERN_DEFAULT;
if (is_readable(divercities::DIVERCITIES_XSL_TRANSFORM_FILE_DEFAULT)) {
$xsl_transform = [
'name' => divercities::DIVERCITIES_XSL_TRANSFORM_DEFAULT,
'code' => file_get_contents(divercities::DIVERCITIES_XSL_TRANSFORM_FILE_DEFAULT),
];
}
}
$form = "
";
if (empty($url)) {
$form .= "
".$this->msg["rec_addr"]."
";
} else {
//Interrogation du serveur
$oai_p = new oai20($url, $charset, $params["TIMEOUT"]);
if ($oai_p->error) {
$form .= "
".sprintf($this->msg["error_contact_server"], $oai_p->error_message)."
";
} else {
$form .= "
".$oai_p->repositoryName."
";
if (!empty($oai_p->description)) {
$form .= "
".htmlentities($oai_p->description, ENT_QUOTES, $charset)."
";
}
$form .= "
".formatdate($oai_p->earliestDatestamp)."
".$oai_p->adminEmail."
".($oai_p->granularity=="YYYY-MM-DD" ? $this->msg["oai_one_day"] : $this->msg["oai_minute"])."
";
if ($oai_p->has_feature("SETS")) {
$form .= "
";
$elements = array();
foreach ($oai_p->sets as $code => $set) {
if (array_search($code, $sets) !== false) {
$elements[] = array('id' => $code, 'name' => $set['name'].($set['description'] ? " (".$set['description'].")" : ""));
}
}
$form .= "";
templates::init_completion_attributes(array(
array('name' => 'att_id_filter', 'value' => $source_id),
array('name' => 'source_url', 'value' => urlencode($url)),
array('name' => 'connector_path', 'value' => $this->get_id()),
array('name' => 'connector_name', 'value' => $this->get_id())
));
templates::init_selection_attributes(array(
array('name' => 'source_id', 'value' => $source_id),
array('name' => 'source_url', 'value' => urlencode($url)),
array('name' => 'connector_path', 'value' => $this->get_id()),
array('name' => 'connector_name', 'value' => $this->get_id())
));
$form .= oai::get_syncronised_sets_template($elements, 'source_form', 'sets', 'set_id', 'connectors', true);
$form .= "
";
}
$form .= "
";
$form .= "
";
if ($oai_p->deletedRecord == "persistent" || $oai_p->deletedRecord == "transient") {
$form .= "
";
}
}
}
$form.= "
".$authentication_sources_selector."
";
}
$form.= "
";
return $form;
}
protected function get_authentication_sources_selector($divercities_authentication_source_id) {
global $charset;
$sources = $this->get_authentication_sources();
if(empty($sources)) {
return '';
}
$selector = "
";
return $selector;
}
protected function get_authentication_sources() {
$connectors_out_list = new connecteurs_out();
$sources = [];
foreach($connectors_out_list->connectors as $connector_out) {
if($connector_out->path == 'divercities') {
foreach($connector_out->sources as $source) {
$sources[] = [
'id' => $source->id,
'name' => $source->name,
'station_id' => $source->config['station_id'],
'shared_key' => $source->config['shared_key'],
];
}
}
}
return $sources;
}
public function make_serialized_source_properties($source_id) {
global $url,$clean_base_url,$formats,$del_deleted,$del_xsl_transform,$clean_html;
global $divercities_authentication_url_pattern, $divercities_authentication_source_id;
$t["url"]=stripslashes($url);
$t["clean_base_url"]=$clean_base_url;
$t["sets"]=templates::get_values_completion_field_from_form('sets');
$t["formats"]=$formats;
$t["del_deleted"]=$del_deleted;
$t["clean_html"]=$clean_html;
switch (true) {
//Ajout fichier xslt
case ($_FILES["xslt_file"])&&(!$_FILES["xslt_file"]["error"]) :
$xslt_file_content = [
'name' => $_FILES["xslt_file"]["name"],
'code' => file_get_contents($_FILES["xslt_file"]["tmp_name"])
];
$t["xsl_transform"] = $xslt_file_content;
break;
//Suppression fichier xslt
case $del_xsl_transform :
$t["xsl_transform"] = '';
break;
//Création source
case (!$source_id && is_readable(divercities::DIVERCITIES_XSL_TRANSFORM_FILE_DEFAULT) ) :
$xslt_file_content = [
'name' => divercities::DIVERCITIES_XSL_TRANSFORM_DEFAULT,
'code' => file_get_contents(divercities::DIVERCITIES_XSL_TRANSFORM_FILE_DEFAULT),
];
$t["xsl_transform"] = $xslt_file_content;
break;
default :
$oldparams=$this->get_source_params($source_id);
if ($oldparams["PARAMETERS"]) {
//Anciens paramètres
$oldvars=unserialize($oldparams["PARAMETERS"]);
}
$t["xsl_transform"] = $oldvars["xsl_transform"];
break;
}
$t['divercities_authentication_url_pattern'] = stripslashes($divercities_authentication_url_pattern);
$t['divercities_authentication_source_id'] = intval($divercities_authentication_source_id);
$this->sources[$source_id]["PARAMETERS"]=serialize($t);
}
/**
*
* @param string $recid
* @param array $params
*
* @return string
*/
public static function get_resource_link($ref, $params=[]) {
if(empty($ref) || empty($params) || empty($params['source_id']) || empty($params['empr_id'])) {
return '';
}
$conn = new static();
$source_params = $conn->unserialize_source_params($params['source_id']);
$link = $source_params['PARAMETERS']['divercities_authentication_url_pattern'];
$station_id = '';
$shared_key = '';
$token = '';
$divercities_authentication_source_id = $source_params['PARAMETERS']['divercities_authentication_source_id'];
$divercities_authentication_source = $conn::get_authentication_source_by_id($divercities_authentication_source_id);
if(!empty($divercities_authentication_source['station_id']) && !empty($divercities_authentication_source['shared_key']) ) {
$station_id = $divercities_authentication_source['station_id'];
$shared_key = $divercities_authentication_source['shared_key'];
$token = md5($params['empr_id'].$shared_key.$station_id);
}
$data = $conn->get_ref($params['source_id'], $ref);
$service = '';
if(!empty($data[901]['a'][0]['value'])) {
$service = $data[901]['a'][0]['value'];
}
$dest = '';
if(!empty($data[902]['a'][0]['value'])) {
$dest = $data[902]['a'][0]['value'];
}
$link = str_replace('!!SERVICE!!', $service, $link);
$link = str_replace('!!DEST!!', $dest, $link);
$link = str_replace('!!STATION_ID!!', $station_id, $link);
$link = str_replace('!!UID!!', $params['empr_id'], $link);
$link = str_replace('!!TOKEN!!', $token, $link);
return $link;
}
/**
*
* @param string $url
* @param int $authentication_source_id
* @param int $empr_id
*
* @return string
*/
public static function get_link_with_authenfication($url, $authentication_source_id, $empr_id) {
if(empty($url) || empty($authentication_source_id) || empty($empr_id)) {
return '';
}
$station_id = '';
$shared_key = '';
$token = '';
$divercities_authentication_source = divercities::get_authentication_source_by_id($authentication_source_id);
if(!empty($divercities_authentication_source['station_id']) && !empty($divercities_authentication_source['shared_key']) ) {
$station_id = $divercities_authentication_source['station_id'];
$shared_key = $divercities_authentication_source['shared_key'];
$token = md5($empr_id.$shared_key.$station_id);
$url.= "&bibid={$station_id}&uid={$empr_id}&token={$token}";
}
return $url;
}
protected static function get_authentication_source_by_id($id) {
$source = [];
$id = intval($id);
$q = "SELECT connectors_out_source_config FROM `connectors_out_sources` where connectors_out_source_id=".$id;
$r = pmb_mysql_query($q);
if(pmb_mysql_num_rows($r)) {
$source = unserialize(pmb_mysql_result($r, 0, 0));
}
return $source;
}
}