-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport-rpps.php
More file actions
148 lines (123 loc) · 3.96 KB
/
import-rpps.php
File metadata and controls
148 lines (123 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* Plugin Name: Import RPPS
* Plugin URI: https://www.answeb.net
* Description: Plugin WordPress pour maintenir à jour une liste de numéros RPPS (Répertoire Partagé des Professionnels de Santé)
* Version: 1.0.0
* Author: Answeb
* Author URI: https://www.answeb.net
* Text Domain: import-rpps
* Domain Path: /languages
* Requires at least: 6.8.1
* Requires PHP: 8.0
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'IMPORT_RPPS_VERSION', '1.0.0' );
define( 'IMPORT_RPPS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'IMPORT_RPPS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'IMPORT_RPPS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
if ( file_exists( IMPORT_RPPS_PLUGIN_DIR . 'vendor/autoload.php' ) ) {
require_once IMPORT_RPPS_PLUGIN_DIR . 'vendor/autoload.php';
} else {
wp_die( __( 'Les dépendances Composer ne sont pas installées. Veuillez exécuter "composer install" dans le répertoire du plugin.',
'import-rpps' ) );
}
use ImportRpps\Admin;
use ImportRpps\Database;
use ImportRpps\Scheduler;
class ImportRppsPlugin {
private static $instance = null;
private $database;
private $admin;
private $scheduler;
public static function getInstance() {
if ( self::$instance === null ) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {
add_action( 'plugins_loaded', array( $this, 'init' ) );
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
}
public function init() {
if ( ! $this->checkRequirements() ) {
return;
}
$this->database = new Database();
$this->admin = new Admin();
$this->scheduler = new Scheduler();
load_plugin_textdomain( 'import-rpps', false, dirname( IMPORT_RPPS_PLUGIN_BASENAME ) . '/languages' );
}
public function activate() {
if ( ! $this->checkRequirements() ) {
deactivate_plugins( IMPORT_RPPS_PLUGIN_BASENAME );
wp_die( __( 'Ce plugin nécessite WordPress 6.8.1 ou supérieur et PHP 8.0 ou supérieur.', 'import-rpps' ) );
}
$database = new Database();
$database->createTable();
if ( ! wp_next_scheduled( 'import_rpps_cron_hook' ) ) {
wp_schedule_event( time(), 'weekly', 'import_rpps_cron_hook' );
}
}
public function deactivate() {
wp_clear_scheduled_hook( 'import_rpps_cron_hook' );
}
private function checkRequirements() {
global $wp_version;
$compliant = true;
if ( version_compare( $wp_version, '6.8.1', '<' ) ) {
add_action( 'admin_notices', function () {
echo '<div class="error"><p>' . __( 'Le plugin Import RPPS nécessite WordPress 6.8.1 ou supérieur.',
'import-rpps' ) . '</p></div>';
} );
$compliant = false;
}
if ( version_compare( PHP_VERSION, '8.0', '<' ) ) {
add_action( 'admin_notices', function () {
echo '<div class="error"><p>' . __( 'Le plugin Import RPPS nécessite PHP 8.0 ou supérieur.',
'import-rpps' ) . '</p></div>';
} );
$compliant = false;
}
if ( ! class_exists( 'ZipArchive' ) ) {
add_action( 'admin_notices', function () {
echo '<div class="error"><p>' . __( 'Le plugin Import RPPS nécessite l\'extension PHP ZipArchive.',
'import-rpps' ) . '</p></div>';
} );
$compliant = false;
}
return $compliant;
}
public function getDatabase() {
return $this->database;
}
public function getAdmin() {
return $this->admin;
}
public function getScheduler() {
return $this->scheduler;
}
}
function importRpps() {
return ImportRppsPlugin::getInstance();
}
/**
* Fonction globale pour valider un numéro RPPS
*
* @param string $rpps_number Le numéro RPPS à valider
* @return bool True si le numéro est valide, false sinon
*/
function import_rpps_validate_number($rpps_number) {
$plugin = importRpps();
if (!$plugin || !$plugin->getDatabase()) {
return false;
}
return $plugin->getDatabase()->validateRppsNumber($rpps_number);
}
importRpps();