array(__CLASS__, 'sanitize'))
);
}
/**
* Sanitize the submitted settings.
*
* @param array $input Raw submitted values.
* @return array
*/
public static function sanitize($input)
{
$input = is_array($input) ? $input : array();
$current = of_sso_get_settings();
$output = array();
$textKeys = array('platform', 'client_id', 'default_role');
foreach ($textKeys as $key) {
$output[$key] = isset($input[$key]) ? sanitize_text_field($input[$key]) : '';
}
$urlKeys = array('base_url', 'redirect_uri', 'redirect_after_login');
foreach ($urlKeys as $key) {
$output[$key] = isset($input[$key]) ? esc_url_raw(trim($input[$key])) : '';
}
// Paths are kept as-is apart from trimming: they point outside the web root on purpose.
$pathKeys = array('cert_dir', 'auth_cert', 'auth_key', 'sign_cert', 'sign_key', 'ca_cert', 'server_sign_cert');
foreach ($pathKeys as $key) {
$output[$key] = isset($input[$key]) ? trim(wp_strip_all_tags($input[$key])) : '';
}
// 0 means "no report": members then keep the technical name built from their identifier.
$output['profile_report_id'] = isset($input['profile_report_id']) ? absint($input['profile_report_id']) : 0;
$boolKeys = array('send_x_ssl_cert', 'auto_create', 'show_login_button', 'debug');
foreach ($boolKeys as $key) {
$output[$key] = empty($input[$key]) ? 0 : 1;
}
// An empty secret field means "keep the stored value", so a secret is never wiped by accident.
foreach (array('client_secret', 'key_passphrase') as $key) {
$submitted = isset($input[$key]) ? trim($input[$key]) : '';
$output[$key] = ($submitted === '') ? $current[$key] : $submitted;
}
if (empty($output['base_url'])) {
$output['base_url'] = 'https://openflyers.com';
}
return $output;
}
/**
* Render the settings page.
*
* @return void
*/
public static function renderPage()
{
if (!current_user_can('manage_options')) {
return;
}
$settings = of_sso_get_settings();
$verdict = self::handleConnectionTest();
?>
Configuration de l\'API) :', 'openflyers-sso'); ?>
'unknown', 'detail' => __('Jeton de securite invalide, merci de recharger la page.', 'openflyers-sso'));
}
$client = of_sso_get_client();
if (!$client) {
return array('status' => 'unknown', 'detail' => __('Renseignez au moins le code plateforme et le client_id.', 'openflyers-sso'));
}
return $client->testConnection(of_sso_get_redirect_uri());
}
/**
* Render the connection test button and the verdict of the last run.
*
* @param array|null $verdict Verdict returned by handleConnectionTest().
* @return void
*/
private static function renderConnectionTest($verdict)
{
if (is_array($verdict)) {
// Every status but 'ok' names the exact link in the chain that refused the call.
$messages = array(
'ok' => array('success', __('Connexion a OpenFlyers reussie. Le certificat TLS, la signature et les identifiants du client sont acceptes : un membre peut se connecter.', 'openflyers-sso')),
'network' => array('error', __('Le serveur OpenFlyers n\'a pas pu etre contacte. Verifiez que l\'hebergeur autorise les connexions sortantes avec un certificat client, et que la cle privee est lisible par PHP.', 'openflyers-sso')),
'server_ca' => array('error', __('Le certificat du serveur OpenFlyers n\'a pas pu etre verifie avec le fichier ca.crt fourni. Ce fichier sert a valider le serveur, pas votre client : s\'il ne convient pas, retirez ca.crt du dossier des certificats pour utiliser le magasin d\'autorites du systeme.', 'openflyers-sso')),
'tls' => array('error', __('Le certificat TLS a ete refuse. Il ne correspond pas a celui enregistre dans OpenFlyers. Si les fichiers sont les bons, votre hebergeur termine sans doute le TLS sur un proxy : activez l\'option X-SSL-CERT.', 'openflyers-sso')),
'signature' => array('error', __('La signature HTTP a ete refusee. Verifiez la cle de signature, et surtout que l\'horloge du serveur est a l\'heure (NTP).', 'openflyers-sso')),
'client' => array('error', __('Le client_id ou la passphrase sont incorrects.', 'openflyers-sso')),
'grant_type' => array('error', __('Ce client n\'est pas declare avec le type d\'autorisation authorization_code dans OpenFlyers.', 'openflyers-sso')),
'unknown' => array('warning', __('Reponse inattendue d\'OpenFlyers.', 'openflyers-sso')),
);
$status = isset($messages[$verdict['status']]) ? $verdict['status'] : 'unknown';
list($noticeType, $text) = $messages[$status];
printf(
'
',
esc_attr($key),
esc_html($label),
esc_attr(OF_SSO_OPTION),
empty($value)
? esc_html__('Non renseigne.', 'openflyers-sso')
: esc_html__('Deja enregistre. Laisser vide pour conserver la valeur actuelle.', 'openflyers-sso')
);
}
/**
* Render a checkbox row.
*
* @param string $key Setting key.
* @param string $label Field label.
* @param int $value Current value.
* @param string $description Help text.
* @return void
*/
private static function checkboxRow($key, $label, $value, $description)
{
printf(
'
%2$s
'
. '
%5$s
',
esc_attr($key),
esc_html($label),
esc_attr(OF_SSO_OPTION),
checked(1, (int) $value, false),
esc_html($description)
);
}
/**
* Render the role selector.
*
* @param string $key Setting key.
* @param string $label Field label.
* @param string $value Current value.
* @return void
*/
private static function roleRow($key, $label, $value)
{
printf(
'
';
}
/**
* Display the OpenFlyers identifier on the user profile screen.
*
* @param WP_User $user User being edited.
* @return void
*/
public static function renderUserField($user)
{
if (!current_user_can('edit_users') and get_current_user_id() !== $user->ID) {
return;
}
$value = get_user_meta($user->ID, OF_SSO_USER_META, true);
$editable = current_user_can('edit_users');
?>