Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
la descritpion d'un compte mastodon peut etre fourni par une fonction…
Browse files Browse the repository at this point in the history
… inc_mastodon_oauth_user_token_dist() surchargeable
  • Loading branch information
Cerdic committed Jul 28, 2018
1 parent fe5c8a1 commit 4c37ad5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
32 changes: 25 additions & 7 deletions inc/mastodon.php
Expand Up @@ -100,20 +100,38 @@ function mastodon_oauth_register_user($domain, $code, $redirect_authorize) {
* @return array|bool
*/
function mastodon_oauth_user_token($user_name = '') {
static $user_tokens = array();

if (isset($user_tokens[$user_name])) {
return $user_tokens[$user_name];
}

if (!function_exists('lire_config')) {
include_spip('inc/config');
}

// si pas de user_name fourni on utilise le compte par defaut
if (!$user_name) {
$user_name = lire_config('mastodon/default_account');
$account = $user_name;
if (!$account) {
if (!$account = lire_config('mastodon/default_account')) {
spip_log("mastodon_oauth_user_token : aucun user_name par defaut dans mastodon/default_account","mastodon"._LOG_ERREUR);
return $user_tokens[$user_name] = false;
}
}
if (!$user_name
or !$token = lire_config('mastodon/accounts/' . $user_name)) {
spip_log("mastodon_oauth_user_token : user_name $user_name inconnu","mastodon"._LOG_ERREUR);
return false;

// si on l'a en config c'est tout bon
if ($token = lire_config('mastodon/accounts/' . $account)) {
return $user_tokens[$user_name] = $user_tokens[$account] = array($account, $token);
}

// sinon on regarde si on a une fonction connue pour recuperer le token de cet user
if ($mastodon_oauth_user_token = charger_fonction('mastodon_oauth_user_token', 'inc', true)) {
return $user_tokens[$user_name] = $user_tokens[$account] = $mastodon_oauth_user_token($account);
}

return array($user_name, $token);
// c'est un echec
spip_log("mastodon_oauth_user_token : aucun account $user_name ($account) connu","mastodon"._LOG_ERREUR);
return $user_tokens[$user_name] = $user_tokens[$account] = false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion paquet.xml
@@ -1,7 +1,7 @@
<paquet
prefix="mastodon"
categorie="communication"
version="1.5.6"
version="1.6.0"
etat="test"
compatibilite="[3.0.0;3.2.*]"
schema="1.0.0"
Expand Down

0 comments on commit 4c37ad5

Please sign in to comment.