msg);
}
public function process($source_id, $pmb_user_id) {
global $base_path;
require_once ($base_path."/admin/connecteurs/out/oai/oai_out_protocol.class.php");
$source_object = $this->instantiate_source_class($source_id);
$oai_server = new oai_out_server($this->msg, $source_object);
$oai_server->process();
//Rien
return;
}
}
class oai_source extends connecteur_out_source {
public $repository_name="";
public $admin_email="";
public $included_sets=array();
public $repositoryIdentifier="";
public $chunk_size=100; //Nombre de résultats par requête
public $token_lifeduration=600; //Durée de vie en seconde des tokens
public $cache_complete_records=true;
public $cache_complete_records_seconds=86400; //Une journée
public $link_status_to_deletion=false;
public $linked_status_to_deletion=0;
public $allow_gzip_compression=true;
public $allowed_set_types=array(
1, //Set de paniers de notices
2 //Set multicritère de notices
);
public $allowed_admin_convert_paths=array();
public $baseURL="";
public $include_items=false; //Inclure les exemplaires
public $include_links = array('genere_lien'=>0);
public $deletion_management = 0;
public $deletion_management_transient_duration = 0;
public $use_items_update_date = 0;
public $oai_pmh_valid=false;
public function __construct($connector, $id, $msg) {
parent::__construct($connector, $id, $msg);
$this->repository_name = isset($this->config["repo_name"]) ? $this->config["repo_name"] : '';
$this->admin_email = isset($this->config["admin_email"]) ? $this->config["admin_email"] : '';
$this->included_sets = isset($this->config["included_sets"]) ? $this->config["included_sets"] : array();
$this->repositoryIdentifier = isset($this->config["repositoryIdentifier"]) ? $this->config["repositoryIdentifier"] : "";
$this->chunksize = isset($this->config["chunksize"]) ? $this->config["chunksize"] : 100;
$this->token_lifeduration = isset($this->config["token_lifeduration"]) ? $this->config["token_lifeduration"] : 600;
$this->cache_complete_records = isset($this->config["cache_complete_records"]) ? $this->config["cache_complete_records"] : true;
$this->cache_complete_records_seconds = isset($this->config["cache_complete_records_seconds"]) ? $this->config["cache_complete_records_seconds"] : true;
$this->link_status_to_deletion = isset($this->config["link_status_to_deletion"]) ? $this->config["link_status_to_deletion"] : false;
$this->linked_status_to_deletion = isset($this->config["linked_status_to_deletion"]) ? $this->config["linked_status_to_deletion"] : 0;
$this->allow_gzip_compression = isset($this->config["allow_gzip_compression"]) ? $this->config["allow_gzip_compression"] : true;
$this->allowed_admin_convert_paths = isset($this->config["allowed_admin_convert_paths"]) ? $this->config["allowed_admin_convert_paths"] : array();
$this->baseURL = isset($this->config["baseURL"]) ? $this->config["baseURL"] : array();
$this->include_items = isset($this->config["include_items"]) ? $this->config["include_items"] : false;
if (count($this->config['include_links'])) {
$this->include_links = $this->config['include_links'];
}
$this->deletion_management = $this->config['deletion_management'];
$this->deletion_management_transient_duration = $this->config['deletion_management_transient_duration'];
$this->use_items_update_date = $this->config['use_items_update_date'];
$this->oai_pmh_valid = isset($this->config["oai_pmh_valid"]) ? $this->config["oai_pmh_valid"] : false;
}
public function get_config_form() {
global $charset;
$result = parent::get_config_form();
//Repository Name
$result .= '
';
$result .= '
';
//Admin Email
$result .= '
';
$result .= '
';
//repositoryIdentifier
$result .= '
';
$result .= '
';
//baseURL
$disable_baseurl_fields = $this->id ? "" : "DISABLED";
$default_base_url = curPageBaseURL();
$default_base_url = substr($default_base_url, 0, strrpos($default_base_url, '/')+1);
$default_base_url .= 'ws/connector_out.php?source_id='.$this->id;
if (!$this->baseURL) {
$basee = $default_base_url;
}
else {
$basee = $this->baseURL;
}
$result .= '
';
if (!$this->id)
$result .= $this->msg['baseURL_sourceadd'].'
';
$result .= '';
if ($this->id)
$result .= '';
$result .= '
';
//Included sets
$included_sets = '';
$result .= '
';
$result .= $included_sets;
$result .= '
';
//Nombre de résultats par requete
$result .= '
';
$result .= '
';
//Nombre de résultats par requete
$result .= '
';
$result .= 'Dublin Core, PMB XML Unimarc
';
//Formats de conversion admin/convert autorisé
$admin_convert_catalog = external_services_converter_notices::get_export_possibilities();
$admin_convert_select = '';
$result .= '
';
$result .= $admin_convert_select;
$result .= '
';
//Validité OAI-PMH
$result .= 'oai_pmh_valid ? 'checked' : '').' name="oai_pmh_valid" type="checkbox" />'.'
';
$result .= '
';
//feuille XSLT personnalisée
$result .= "
";
//Token life duration
$result .= '
';
$result .= '
';
//Allow GZIP Compression
$result .= 'allow_gzip_compression ? 'checked' : '').' name="allow_gzip_compression" type="checkbox" />'.'
';
$result .= '
';
//Cache complete records
$result .= 'cache_complete_records ? 'checked' : '').' name="cache_complete_records" type="checkbox" />'.'
';
$result .= '
';
//Record cache duration (seconds)
$result .= '
';
$result .= 'cache_complete_records ? '' : 'disabled').' id="cache_complete_records_seconds" name="cache_complete_records_seconds" type="text" value="'.htmlentities($this->cache_complete_records_seconds,ENT_QUOTES, $charset).'" class="saisie-40em" />
';
//Link Status to deletion
$result .= 'link_status_to_deletion ? 'checked' : '').' name="link_status_to_deletion" type="checkbox" />'.'
';
$result .= '
';
//Linked Status to deletion
$notice_statut_select = '';
$result .= '
';
$result .= $notice_statut_select;
$result .= '
';
// Deletion management
$result .= '';
$result .= '
deletion_management == 0) ? 'checked' : '').'/>
';
$result .= '
deletion_management == 1) ? 'checked' : '').'/>
, ';
$result .= '
deletion_management != 1) ? 'disabled' : '').' type="text" id="deletion_management_transient_duration" value="'.htmlentities($this->deletion_management_transient_duration,ENT_QUOTES, $charset).'" name="deletion_management_transient_duration"/> ';
$result .= '
deletion_management == 2) ? 'checked' : '').'/>
';
$result .= '
';
// Update date
$result .= '
use_items_update_date ? 'checked' : '').' name="use_items_update_date" type="checkbox" />'.'';
$result .= '
';
//Include items
$result .= '
include_items ? 'checked=checked' : '').' name="include_items" type="checkbox" />'.'
';
$result .= '
';
//Include links
global $include_path, $class_path, $msg, $form_param,$include_links;
require_once($class_path.'/export_param.class.php');
$include_links = $this->include_links;
$e_param = new export_param(EXP_OAI_CONTEXT);
$result.= $e_param->check_default_param();
return $result;
}
public function update_config_from_form() {
parent::update_config_from_form();
global $repo_name, $admin_email, $included_sets, $repositoryIdentifier, $chunksize, $token_lifeduration, $cache_complete_records, $cache_complete_records_seconds, $link_status_to_deletion, $linked_status_to_deletion, $allow_gzip_compression, $baseURL, $include_items,$suppr_feuille_xslt;
global $deletion_management, $deletion_management_transient_duration, $use_items_update_date, $oai_pmh_valid;
//les trucs faciles
$this->config["repo_name"] = stripslashes($repo_name);
$this->config["admin_email"] = stripslashes($admin_email);
$this->config["repositoryIdentifier"] = stripslashes($repositoryIdentifier);
$this->config["chunksize"] = (int) $chunksize;
$this->config["token_lifeduration"] = (int) $token_lifeduration;
$this->config["cache_complete_records"] = isset($cache_complete_records);
$this->config["cache_complete_records_seconds"] = (int) $cache_complete_records_seconds;
$this->config["link_status_to_deletion"] = isset($link_status_to_deletion);
$this->config["linked_status_to_deletion"] = (int) $linked_status_to_deletion;
$this->config["allow_gzip_compression"] = isset($allow_gzip_compression);
$this->config["baseURL"] = stripslashes($baseURL);
$this->config["include_items"] = isset($include_items);
$this->config["deletion_management"] = $deletion_management;
$this->config["deletion_management_transient_duration"] = $deletion_management_transient_duration*1;
$this->config["use_items_update_date"] = isset($use_items_update_date);
$this->config["oai_pmh_valid"] = isset($oai_pmh_valid);
if(!$_FILES['feuille_xslt']['error']){
$this->config['feuille_xslt'] = file_get_contents($_FILES['feuille_xslt']['tmp_name']);
$this->config['feuille_xslt_name'] = $_FILES['feuille_xslt']['name'];
}
if($suppr_feuille_xslt){
$this->config['feuille_xslt'] = "";
$this->config['feuille_xslt_name'] = "";
}
$this->config['include_links']=array();
$this->config['include_links']['genere_lien'] = 0;
global $include_path, $class_path;
require_once($class_path.'/export_param.class.php');
$e_param = new export_param(EXP_GLOBAL_CONTEXT);
$this->config['include_links'] = $e_param->get_parametres(EXP_OAI_CONTEXT);
//Vérifions que le statut proposé existe bien
$sql = "SELECT COUNT(1) > 0 FROM notice_statut WHERE id_notice_statut = ".((int) $linked_status_to_deletion);
$status_exists = pmb_mysql_result(pmb_mysql_query($sql), 0, 0);
if (!$status_exists)
$this->config["linked_status_to_deletion"] = 0;
if (!$this->config["cache_complete_records_seconds"])
$this->config["cache_complete_records_seconds"] = 86400;
if (($this->config["deletion_management"] == 1) && !$this->config["deletion_management_transient_duration"])
$this->config["deletion_management"] = 0;
//et maintenant les sets
if (!is_array($included_sets))
$included_sets=array($included_sets);
array_walk($included_sets, function(&$a) {$a = intval($a);}); //Virons ce qui n'est pas entier
//Virons ce qui n'est pas un index de set de notice
$sql = "SELECT connector_out_set_id FROM connectors_out_sets WHERE connector_out_set_type IN (".implode(",",$this->allowed_set_types).") AND connector_out_set_id IN (".implode(",", $included_sets).')';
$res = pmb_mysql_query($sql);
$this->config["included_sets"] = array();
while($row=pmb_mysql_fetch_assoc($res)) {
$this->config["included_sets"][] = $row["connector_out_set_id"];
}
//Vérifions que les formats autorisés proposés existent bien
$allowed_paths=array();
$admin_convert_catalog = external_services_converter_notices::get_export_possibilities();
foreach ($admin_convert_catalog as $aconvert) {
$allowed_paths[] = $aconvert["path"];
}
global $allowed_admin_convert_paths;
if (!is_array($allowed_admin_convert_paths))
$allowed_admin_convert_paths = array($allowed_admin_convert_paths);
$this->config["allowed_admin_convert_paths"] = array();
foreach ($allowed_admin_convert_paths as $apath) {
if (!in_array($apath, $allowed_paths))
continue;
$this->config["allowed_admin_convert_paths"][] = $apath;
}
return;
}
/**
* Nettoie la table des enregistrements OAI supprimés
*/
static public function clean_out_oai_deleted_records() {
$sets_configs = array();
// On récupère les configurations des sources du connecteur oai
$query = "select connectors_out_source_config from connectors_out_sources where connectors_out_sources_connectornum = 3";
$result = pmb_mysql_query($query);
if ($result && pmb_mysql_num_rows($result)) {
while ($source = pmb_mysql_fetch_object($result)) {
$source_config = unserialize($source->connectors_out_source_config);
// On vérifie qu'on utilise la gestion de suppression et que l'on a des sets associés à la source
if (!$source_config['link_status_to_deletion'] && isset($source_config['included_sets'])) {
foreach ($source_config['included_sets'] as $set) {
if (!isset($sets_configs[$set])) {
$sets_configs[$set] = array(
'deletion_management' => $source_config['deletion_management'],
'deletion_management_transient_duration' => 0
);
} else if ($source_config['deletion_management'] > $sets_configs[$set]['deletion_management']) {
$sets_configs[$set]['deletion_management'] = $source_config['deletion_management'];
}
if (($sets_configs[$set]['deletion_management'] == 1) && ($source_config['deletion_management_transient_duration'] > $sets_configs[$set]['deletion_management_transient_duration'])) {
$sets_configs[$set]['deletion_management_transient_duration'] = $source_config['deletion_management_transient_duration'];
}
}
}
}
}
// On passe à la suppression !
foreach ($sets_configs as $set_id => $set) {
if ($set['deletion_management'] != 2) {
$query = "delete from connectors_out_oai_deleted_records where num_set = ".$set_id;
if ($set['deletion_management'] == 1) {
$query .= " and timestampdiff(second, deletion_date, now()) > ".$set['deletion_management_transient_duration'];
}
pmb_mysql_query($query);
}
}
}
}
?>