Files
thalim-plugin-hal-importer/thalim-hal-importer.php

109 lines
3.4 KiB
PHP

<?php
/**
* Plugin Name: THALIM HAL Importer
* Plugin URI: https://thalim.fr
* Description: Import publications from HAL for the THALIM lab (structure_s:THALIM)
* Version: 2.0.0
* Author: THALIM Dev
* Author URI: https://thalim.fr
* License: GPL v2 or later
* Text Domain: thalim-hal-importer
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Plugin constants
define('THALIM_HAL_VERSION', '2.0.0');
define('THALIM_HAL_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('THALIM_HAL_PLUGIN_URL', plugin_dir_url(__FILE__));
// HAL API configuration
define('THALIM_HAL_API_BASE', 'https://api.archives-ouvertes.fr/search/');
define('THALIM_HAL_STRUCT_ID', 254015); // THALIM lab structure ID
define('THALIM_HAL_DOC_TYPES', ['ART', 'COUV', 'OUV', 'COMM', 'ISSUE', 'PROCEEDINGS', 'THESE', 'HDR', 'SON', 'VIDEO', 'NOTICE', 'BLOG', 'TRAD', 'REPORT', 'UNDEFINED', 'POSTER', 'OTHER']);
/**
* Main plugin class - minimal bootstrap
*/
class Thalim_HAL_Importer {
private static $instance = null;
public static function get_instance() {
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
$this->load_dependencies();
$this->init_hooks();
}
private function load_dependencies() {
require_once THALIM_HAL_PLUGIN_DIR . 'includes/class-hal-api.php';
// Traits must be loaded before the class that `use`s them.
require_once THALIM_HAL_PLUGIN_DIR . 'includes/trait-admin-page-config.php';
require_once THALIM_HAL_PLUGIN_DIR . 'includes/trait-admin-page-csv-legacy.php';
require_once THALIM_HAL_PLUGIN_DIR . 'includes/class-admin-page.php';
require_once THALIM_HAL_PLUGIN_DIR . 'includes/class-pods-storage.php';
require_once THALIM_HAL_PLUGIN_DIR . 'includes/class-importer.php';
}
private function init_hooks() {
add_action('admin_menu', [$this, 'add_admin_menu']);
}
public function add_admin_menu() {
// Admins/editors : page sous Outils (UI complète : filtres tous auteurs, debug, etc.)
if (current_user_can('edit_others_posts')) {
add_management_page(
'HAL Import',
'HAL Import',
'edit_others_posts',
'thalim-hal-importer',
[$this, 'render_admin_page']
);
return;
}
// Contributeurs : menu top-level dédié (Outils est masqué pour eux par le thème).
// La classe rend une UI réduite scopée sur leur idHAL en interne.
if (current_user_can('edit_posts')) {
add_menu_page(
'Importer depuis HAL',
'Importer depuis HAL',
'edit_posts',
'thalim-hal-import-mine',
[$this, 'render_admin_page'],
'dashicons-download',
26
);
}
}
public function render_admin_page() {
$admin_page = new Thalim_HAL_Admin_Page();
$admin_page->render();
}
}
// Activation hook
register_activation_hook(__FILE__, function() {
add_option('thalim_hal_version', THALIM_HAL_VERSION);
});
// Deactivation hook
register_deactivation_hook(__FILE__, function() {
delete_transient('thalim_hal_preview_data');
});
// Initialize plugin
add_action('plugins_loaded', function() {
Thalim_HAL_Importer::get_instance();
});