@@ -11,193 +11,193 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Sql extends AbstractIterateur implements Iterator |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Ressource sql. |
|
| 16 | - * |
|
| 17 | - * @var bool|object |
|
| 18 | - */ |
|
| 19 | - protected $sqlresult = false; |
|
| 14 | + /** |
|
| 15 | + * Ressource sql. |
|
| 16 | + * |
|
| 17 | + * @var bool|object |
|
| 18 | + */ |
|
| 19 | + protected $sqlresult = false; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * row sql courante. |
|
| 23 | - * |
|
| 24 | - * @var null|array |
|
| 25 | - */ |
|
| 26 | - protected $row; |
|
| 21 | + /** |
|
| 22 | + * row sql courante. |
|
| 23 | + * |
|
| 24 | + * @var null|array |
|
| 25 | + */ |
|
| 26 | + protected $row; |
|
| 27 | 27 | |
| 28 | - protected bool $firstseek = false; |
|
| 28 | + protected bool $firstseek = false; |
|
| 29 | 29 | |
| 30 | - protected int $pos = -1; |
|
| 30 | + protected int $pos = -1; |
|
| 31 | 31 | |
| 32 | - /* |
|
| 32 | + /* |
|
| 33 | 33 | * array command: les commandes d'initialisation |
| 34 | 34 | * array info: les infos sur le squelette |
| 35 | 35 | */ |
| 36 | - public function __construct(array $command, array $info = []) { |
|
| 37 | - $this->type = 'SQL'; |
|
| 38 | - parent::__construct($command, $info); |
|
| 39 | - |
|
| 40 | - $this->select(); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Rembobiner. |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public function rewind(): void { |
|
| 49 | - if ($this->pos > 0) { |
|
| 50 | - $this->seek(0); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Verifier l'etat de l'iterateur. |
|
| 56 | - */ |
|
| 57 | - public function valid(): bool { |
|
| 58 | - if ($this->err) { |
|
| 59 | - return false; |
|
| 60 | - } |
|
| 61 | - if (!$this->firstseek) { |
|
| 62 | - $this->next(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return is_array($this->row); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Valeurs sur la position courante. |
|
| 70 | - * |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - #[\ReturnTypeWillChange] |
|
| 74 | - public function current() { |
|
| 75 | - return $this->row; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - #[\ReturnTypeWillChange] |
|
| 79 | - public function key() { |
|
| 80 | - return $this->pos; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Sauter a une position absolue. |
|
| 85 | - * |
|
| 86 | - * @param int $n |
|
| 87 | - * @param null|string $continue |
|
| 88 | - * |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function seek($n = 0, $continue = null) { |
|
| 92 | - if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 93 | - // SQLite ne sait pas seek(), il faut relancer la query |
|
| 94 | - // si la position courante est apres la position visee |
|
| 95 | - // il faut relancer la requete |
|
| 96 | - if ($this->pos > $n) { |
|
| 97 | - $this->free(); |
|
| 98 | - $this->select(); |
|
| 99 | - $this->valid(); |
|
| 100 | - } |
|
| 101 | - // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 102 | - // (sera fait en cas d'echec de cette fonction) |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 106 | - $this->pos = min($n, $this->count()); |
|
| 107 | - |
|
| 108 | - return true; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Avancer d'un cran. |
|
| 113 | - */ |
|
| 114 | - public function next(): void { |
|
| 115 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 116 | - ++$this->pos; |
|
| 117 | - $this->firstseek |= true; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Avancer et retourner les donnees pour le nouvel element. |
|
| 122 | - * |
|
| 123 | - * @return null|array|bool |
|
| 124 | - */ |
|
| 125 | - public function fetch() { |
|
| 126 | - if ($this->valid()) { |
|
| 127 | - $r = $this->current(); |
|
| 128 | - $this->next(); |
|
| 129 | - } else { |
|
| 130 | - $r = false; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - return $r; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * liberer les ressources. |
|
| 138 | - * |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - public function free() { |
|
| 142 | - if (!$this->sqlresult) { |
|
| 143 | - return true; |
|
| 144 | - } |
|
| 145 | - $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 146 | - $this->sqlresult = null; |
|
| 147 | - |
|
| 148 | - return $a; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Compter le nombre de resultats. |
|
| 153 | - * |
|
| 154 | - * @return int |
|
| 155 | - */ |
|
| 156 | - public function count() { |
|
| 157 | - if (is_null($this->total)) { |
|
| 158 | - if (!$this->sqlresult) { |
|
| 159 | - $this->total = 0; |
|
| 160 | - } else { |
|
| 161 | - // cas count(*) |
|
| 162 | - if (in_array('count(*)', $this->command['select'])) { |
|
| 163 | - $this->valid(); |
|
| 164 | - $s = $this->current(); |
|
| 165 | - $this->total = $s['count(*)']; |
|
| 166 | - } else { |
|
| 167 | - $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return $this->total; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * selectionner les donnees, ie faire la requete SQL. |
|
| 177 | - */ |
|
| 178 | - protected function select() { |
|
| 179 | - $this->row = null; |
|
| 180 | - $v = &$this->command; |
|
| 181 | - $this->sqlresult = calculer_select( |
|
| 182 | - $v['select'], |
|
| 183 | - $v['from'], |
|
| 184 | - $v['type'], |
|
| 185 | - $v['where'], |
|
| 186 | - $v['join'], |
|
| 187 | - $v['groupby'], |
|
| 188 | - $v['orderby'], |
|
| 189 | - $v['limit'], |
|
| 190 | - $v['having'], |
|
| 191 | - $v['table'], |
|
| 192 | - $v['id'], |
|
| 193 | - $v['connect'], |
|
| 194 | - $this->info |
|
| 195 | - ); |
|
| 196 | - $this->err = !$this->sqlresult; |
|
| 197 | - $this->firstseek = false; |
|
| 198 | - $this->pos = -1; |
|
| 199 | - |
|
| 200 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 201 | - //$this->total = $this->count(); |
|
| 202 | - } |
|
| 36 | + public function __construct(array $command, array $info = []) { |
|
| 37 | + $this->type = 'SQL'; |
|
| 38 | + parent::__construct($command, $info); |
|
| 39 | + |
|
| 40 | + $this->select(); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Rembobiner. |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public function rewind(): void { |
|
| 49 | + if ($this->pos > 0) { |
|
| 50 | + $this->seek(0); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Verifier l'etat de l'iterateur. |
|
| 56 | + */ |
|
| 57 | + public function valid(): bool { |
|
| 58 | + if ($this->err) { |
|
| 59 | + return false; |
|
| 60 | + } |
|
| 61 | + if (!$this->firstseek) { |
|
| 62 | + $this->next(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return is_array($this->row); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Valeurs sur la position courante. |
|
| 70 | + * |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + #[\ReturnTypeWillChange] |
|
| 74 | + public function current() { |
|
| 75 | + return $this->row; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + #[\ReturnTypeWillChange] |
|
| 79 | + public function key() { |
|
| 80 | + return $this->pos; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Sauter a une position absolue. |
|
| 85 | + * |
|
| 86 | + * @param int $n |
|
| 87 | + * @param null|string $continue |
|
| 88 | + * |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function seek($n = 0, $continue = null) { |
|
| 92 | + if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 93 | + // SQLite ne sait pas seek(), il faut relancer la query |
|
| 94 | + // si la position courante est apres la position visee |
|
| 95 | + // il faut relancer la requete |
|
| 96 | + if ($this->pos > $n) { |
|
| 97 | + $this->free(); |
|
| 98 | + $this->select(); |
|
| 99 | + $this->valid(); |
|
| 100 | + } |
|
| 101 | + // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 102 | + // (sera fait en cas d'echec de cette fonction) |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 106 | + $this->pos = min($n, $this->count()); |
|
| 107 | + |
|
| 108 | + return true; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Avancer d'un cran. |
|
| 113 | + */ |
|
| 114 | + public function next(): void { |
|
| 115 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 116 | + ++$this->pos; |
|
| 117 | + $this->firstseek |= true; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Avancer et retourner les donnees pour le nouvel element. |
|
| 122 | + * |
|
| 123 | + * @return null|array|bool |
|
| 124 | + */ |
|
| 125 | + public function fetch() { |
|
| 126 | + if ($this->valid()) { |
|
| 127 | + $r = $this->current(); |
|
| 128 | + $this->next(); |
|
| 129 | + } else { |
|
| 130 | + $r = false; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + return $r; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * liberer les ressources. |
|
| 138 | + * |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + public function free() { |
|
| 142 | + if (!$this->sqlresult) { |
|
| 143 | + return true; |
|
| 144 | + } |
|
| 145 | + $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 146 | + $this->sqlresult = null; |
|
| 147 | + |
|
| 148 | + return $a; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Compter le nombre de resultats. |
|
| 153 | + * |
|
| 154 | + * @return int |
|
| 155 | + */ |
|
| 156 | + public function count() { |
|
| 157 | + if (is_null($this->total)) { |
|
| 158 | + if (!$this->sqlresult) { |
|
| 159 | + $this->total = 0; |
|
| 160 | + } else { |
|
| 161 | + // cas count(*) |
|
| 162 | + if (in_array('count(*)', $this->command['select'])) { |
|
| 163 | + $this->valid(); |
|
| 164 | + $s = $this->current(); |
|
| 165 | + $this->total = $s['count(*)']; |
|
| 166 | + } else { |
|
| 167 | + $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return $this->total; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * selectionner les donnees, ie faire la requete SQL. |
|
| 177 | + */ |
|
| 178 | + protected function select() { |
|
| 179 | + $this->row = null; |
|
| 180 | + $v = &$this->command; |
|
| 181 | + $this->sqlresult = calculer_select( |
|
| 182 | + $v['select'], |
|
| 183 | + $v['from'], |
|
| 184 | + $v['type'], |
|
| 185 | + $v['where'], |
|
| 186 | + $v['join'], |
|
| 187 | + $v['groupby'], |
|
| 188 | + $v['orderby'], |
|
| 189 | + $v['limit'], |
|
| 190 | + $v['having'], |
|
| 191 | + $v['table'], |
|
| 192 | + $v['id'], |
|
| 193 | + $v['connect'], |
|
| 194 | + $this->info |
|
| 195 | + ); |
|
| 196 | + $this->err = !$this->sqlresult; |
|
| 197 | + $this->firstseek = false; |
|
| 198 | + $this->pos = -1; |
|
| 199 | + |
|
| 200 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 201 | + //$this->total = $this->count(); |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -18,76 +18,76 @@ |
||
| 18 | 18 | * @link https://www.php.net/manual/fr/book.sodium.php |
| 19 | 19 | */ |
| 20 | 20 | class Chiffrement { |
| 21 | - /** Chiffre un message en utilisant une clé ou un mot de passe */ |
|
| 22 | - public static function chiffrer( |
|
| 23 | - string $message, |
|
| 24 | - #[\SensitiveParameter] |
|
| 25 | - string $key |
|
| 26 | - ): ?string { |
|
| 27 | - // create a random salt for key derivation |
|
| 28 | - $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 29 | - $key = self::deriveKeyFromPassword($key, $salt); |
|
| 30 | - $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 31 | - $padded_message = sodium_pad($message, 16); |
|
| 32 | - $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
|
| 33 | - $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 34 | - sodium_memzero($key); |
|
| 35 | - sodium_memzero($nonce); |
|
| 36 | - sodium_memzero($salt); |
|
| 37 | - #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG); |
|
| 38 | - return $encoded; |
|
| 39 | - } |
|
| 21 | + /** Chiffre un message en utilisant une clé ou un mot de passe */ |
|
| 22 | + public static function chiffrer( |
|
| 23 | + string $message, |
|
| 24 | + #[\SensitiveParameter] |
|
| 25 | + string $key |
|
| 26 | + ): ?string { |
|
| 27 | + // create a random salt for key derivation |
|
| 28 | + $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 29 | + $key = self::deriveKeyFromPassword($key, $salt); |
|
| 30 | + $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 31 | + $padded_message = sodium_pad($message, 16); |
|
| 32 | + $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
|
| 33 | + $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 34 | + sodium_memzero($key); |
|
| 35 | + sodium_memzero($nonce); |
|
| 36 | + sodium_memzero($salt); |
|
| 37 | + #spip_log("chiffrer($message)=$encoded", 'chiffrer' . _LOG_DEBUG); |
|
| 38 | + return $encoded; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** Déchiffre un message en utilisant une clé ou un mot de passe */ |
|
| 42 | - public static function dechiffrer( |
|
| 43 | - string $encoded, |
|
| 44 | - #[\SensitiveParameter] |
|
| 45 | - string $key |
|
| 46 | - ): ?string { |
|
| 47 | - $decoded = base64_decode($encoded); |
|
| 48 | - $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 49 | - $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 50 | - $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | - $key = self::deriveKeyFromPassword($key, $salt); |
|
| 52 | - $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
|
| 53 | - sodium_memzero($key); |
|
| 54 | - sodium_memzero($nonce); |
|
| 55 | - sodium_memzero($salt); |
|
| 56 | - if ($padded_message === false) { |
|
| 57 | - spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 58 | - return null; |
|
| 59 | - } |
|
| 60 | - return sodium_unpad($padded_message, 16); |
|
| 61 | - } |
|
| 41 | + /** Déchiffre un message en utilisant une clé ou un mot de passe */ |
|
| 42 | + public static function dechiffrer( |
|
| 43 | + string $encoded, |
|
| 44 | + #[\SensitiveParameter] |
|
| 45 | + string $key |
|
| 46 | + ): ?string { |
|
| 47 | + $decoded = base64_decode($encoded); |
|
| 48 | + $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
|
| 49 | + $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 50 | + $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | + $key = self::deriveKeyFromPassword($key, $salt); |
|
| 52 | + $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
|
| 53 | + sodium_memzero($key); |
|
| 54 | + sodium_memzero($nonce); |
|
| 55 | + sodium_memzero($salt); |
|
| 56 | + if ($padded_message === false) { |
|
| 57 | + spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 58 | + return null; |
|
| 59 | + } |
|
| 60 | + return sodium_unpad($padded_message, 16); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** Génère une clé de la taille attendue pour le chiffrement */ |
|
| 64 | - public static function keygen(): string { |
|
| 65 | - return sodium_crypto_secretbox_keygen(); |
|
| 66 | - } |
|
| 63 | + /** Génère une clé de la taille attendue pour le chiffrement */ |
|
| 64 | + public static function keygen(): string { |
|
| 65 | + return sodium_crypto_secretbox_keygen(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Retourne une clé de la taille attendue pour le chiffrement |
|
| 70 | - * |
|
| 71 | - * Notamment si on utilise un mot de passe comme clé, il faut le hacher |
|
| 72 | - * pour servir de clé à la taille correspondante. |
|
| 73 | - */ |
|
| 74 | - private static function deriveKeyFromPassword( |
|
| 75 | - #[\SensitiveParameter] |
|
| 76 | - string $password, |
|
| 77 | - string $salt |
|
| 78 | - ): string { |
|
| 79 | - if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 80 | - return $password; |
|
| 81 | - } |
|
| 82 | - $key = sodium_crypto_pwhash( |
|
| 83 | - \SODIUM_CRYPTO_SECRETBOX_KEYBYTES, |
|
| 84 | - $password, |
|
| 85 | - $salt, |
|
| 86 | - \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, |
|
| 87 | - \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE |
|
| 88 | - ); |
|
| 89 | - sodium_memzero($password); |
|
| 68 | + /** |
|
| 69 | + * Retourne une clé de la taille attendue pour le chiffrement |
|
| 70 | + * |
|
| 71 | + * Notamment si on utilise un mot de passe comme clé, il faut le hacher |
|
| 72 | + * pour servir de clé à la taille correspondante. |
|
| 73 | + */ |
|
| 74 | + private static function deriveKeyFromPassword( |
|
| 75 | + #[\SensitiveParameter] |
|
| 76 | + string $password, |
|
| 77 | + string $salt |
|
| 78 | + ): string { |
|
| 79 | + if (strlen($password) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 80 | + return $password; |
|
| 81 | + } |
|
| 82 | + $key = sodium_crypto_pwhash( |
|
| 83 | + \SODIUM_CRYPTO_SECRETBOX_KEYBYTES, |
|
| 84 | + $password, |
|
| 85 | + $salt, |
|
| 86 | + \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, |
|
| 87 | + \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE |
|
| 88 | + ); |
|
| 89 | + sodium_memzero($password); |
|
| 90 | 90 | |
| 91 | - return $key; |
|
| 92 | - } |
|
| 91 | + return $key; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $nonce = random_bytes(\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
| 31 | 31 | $padded_message = sodium_pad($message, 16); |
| 32 | 32 | $encrypted = sodium_crypto_secretbox($padded_message, $nonce, $key); |
| 33 | - $encoded = base64_encode($salt . $nonce . $encrypted); |
|
| 33 | + $encoded = base64_encode($salt.$nonce.$encrypted); |
|
| 34 | 34 | sodium_memzero($key); |
| 35 | 35 | sodium_memzero($nonce); |
| 36 | 36 | sodium_memzero($salt); |
@@ -47,14 +47,14 @@ discard block |
||
| 47 | 47 | $decoded = base64_decode($encoded); |
| 48 | 48 | $salt = substr($decoded, 0, \SODIUM_CRYPTO_PWHASH_SALTBYTES); |
| 49 | 49 | $nonce = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES, \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
| 50 | - $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES + \SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 50 | + $encrypted = substr($decoded, \SODIUM_CRYPTO_PWHASH_SALTBYTES +\SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
|
| 51 | 51 | $key = self::deriveKeyFromPassword($key, $salt); |
| 52 | 52 | $padded_message = sodium_crypto_secretbox_open($encrypted, $nonce, $key); |
| 53 | 53 | sodium_memzero($key); |
| 54 | 54 | sodium_memzero($nonce); |
| 55 | 55 | sodium_memzero($salt); |
| 56 | 56 | if ($padded_message === false) { |
| 57 | - spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer' . _LOG_DEBUG); |
|
| 57 | + spip_log("dechiffrer() chiffre corrompu `$encoded`", 'chiffrer'._LOG_DEBUG); |
|
| 58 | 58 | return null; |
| 59 | 59 | } |
| 60 | 60 | return sodium_unpad($padded_message, 16); |
@@ -13,169 +13,169 @@ |
||
| 13 | 13 | |
| 14 | 14 | /** Gestion des clés d’authentification / chiffrement de SPIP */ |
| 15 | 15 | final class SpipCles { |
| 16 | - private static array $instances = []; |
|
| 17 | - |
|
| 18 | - private string $file = _DIR_ETC . 'cles.php'; |
|
| 19 | - private Cles $cles; |
|
| 20 | - |
|
| 21 | - public static function instance(string $file = ''): self { |
|
| 22 | - if (empty(self::$instances[$file])) { |
|
| 23 | - self::$instances[$file] = new self($file); |
|
| 24 | - } |
|
| 25 | - return self::$instances[$file]; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Retourne le secret du site (shorthand) |
|
| 30 | - * @uses self::getSecretSite() |
|
| 31 | - */ |
|
| 32 | - public static function secret_du_site(): ?string { |
|
| 33 | - return (self::instance())->getSecretSite(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - private function __construct(string $file = '') { |
|
| 37 | - if ($file) { |
|
| 38 | - $this->file = $file; |
|
| 39 | - } |
|
| 40 | - $this->cles = new Cles($this->read()); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Renvoyer le secret du site |
|
| 45 | - * |
|
| 46 | - * Le secret du site doit rester aussi secret que possible, et est eternel |
|
| 47 | - * On ne doit pas l'exporter |
|
| 48 | - * |
|
| 49 | - * Le secret est partagé entre une clé disque et une clé bdd |
|
| 50 | - * |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function getSecretSite(bool $autoInit = true): ?string { |
|
| 54 | - $key = $this->getKey('secret_du_site', $autoInit); |
|
| 55 | - $meta = $this->getMetaKey('secret_du_site', $autoInit); |
|
| 56 | - // conserve la même longeur. |
|
| 57 | - return $key ^ $meta; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** Renvoyer le secret des authentifications */ |
|
| 61 | - public function getSecretAuth(bool $autoInit = false): ?string { |
|
| 62 | - return $this->getKey('secret_des_auth', $autoInit); |
|
| 63 | - } |
|
| 64 | - public function save(): bool { |
|
| 65 | - return ecrire_fichier_securise($this->file, $this->cles->toJson()); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur) |
|
| 70 | - * |
|
| 71 | - * @param string $withKey Clé de chiffrage de la sauvegarde |
|
| 72 | - * @return string Contenu de la sauvegarde chiffrée générée |
|
| 73 | - */ |
|
| 74 | - public function backup( |
|
| 75 | - #[\SensitiveParameter] |
|
| 76 | - string $withKey |
|
| 77 | - ): string { |
|
| 78 | - if (count($this->cles)) { |
|
| 79 | - return Chiffrement::chiffrer($this->cles->toJson(), $withKey); |
|
| 80 | - } |
|
| 81 | - return ''; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles |
|
| 86 | - * (si la sauvegarde est bien valide) |
|
| 87 | - */ |
|
| 88 | - public function restore( |
|
| 89 | - /** Sauvegarde chiffrée (générée par backup()) */ |
|
| 90 | - string $backup, |
|
| 91 | - #[\SensitiveParameter] |
|
| 92 | - string $password_clair, |
|
| 93 | - #[\SensitiveParameter] |
|
| 94 | - string $password_hash, |
|
| 95 | - int $id_auteur |
|
| 96 | - ): bool { |
|
| 97 | - if (empty($backup)) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair); |
|
| 102 | - $json = json_decode($sauvegarde, true); |
|
| 103 | - if (!$json) { |
|
| 104 | - return false; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // cela semble une sauvegarde valide |
|
| 108 | - $cles_potentielles = array_map('base64_decode', $json); |
|
| 109 | - |
|
| 110 | - // il faut faire une double verif sur secret_des_auth |
|
| 111 | - // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde |
|
| 112 | - // et par extension tous les passwords |
|
| 113 | - if ( |
|
| 114 | - !empty($cles_potentielles['secret_des_auth']) |
|
| 115 | - && !Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth']) |
|
| 116 | - ) { |
|
| 117 | - spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 118 | - unset($cles_potentielles['secret_des_auth']); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // on merge les cles pour recuperer les cles manquantes |
|
| 122 | - $restauration = false; |
|
| 123 | - foreach ($cles_potentielles as $name => $key) { |
|
| 124 | - if (!$this->cles->has($name)) { |
|
| 125 | - $this->cles->set($name, $key); |
|
| 126 | - spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 127 | - $restauration = true; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - return $restauration; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - private function getKey(string $name, bool $autoInit): ?string { |
|
| 134 | - if ($this->cles->has($name)) { |
|
| 135 | - return $this->cles->get($name); |
|
| 136 | - } |
|
| 137 | - if ($autoInit) { |
|
| 138 | - $this->cles->generate($name); |
|
| 139 | - // si l'ecriture de fichier a bien marche on peut utiliser la cle |
|
| 140 | - if ($this->save()) { |
|
| 141 | - return $this->cles->get($name); |
|
| 142 | - } |
|
| 143 | - // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
|
| 144 | - spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 145 | - $this->cles->delete($name); |
|
| 146 | - } |
|
| 147 | - return null; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - private function getMetaKey(string $name, bool $autoInit = true): ?string { |
|
| 151 | - if (!isset($GLOBALS['meta'][$name])) { |
|
| 152 | - include_spip('base/abstract_sql'); |
|
| 153 | - $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 154 | - } |
|
| 155 | - $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
|
| 156 | - if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 157 | - return $key; |
|
| 158 | - } |
|
| 159 | - if (!$autoInit) { |
|
| 160 | - return null; |
|
| 161 | - } |
|
| 162 | - $key = Chiffrement::keygen(); |
|
| 163 | - ecrire_meta($name, base64_encode($key), 'non'); |
|
| 164 | - lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 165 | - |
|
| 166 | - return $key; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - private function read(): array { |
|
| 170 | - $json = null; |
|
| 171 | - lire_fichier_securise($this->file, $json); |
|
| 172 | - if ( |
|
| 173 | - $json |
|
| 174 | - && ($json = \json_decode($json, true)) |
|
| 175 | - && is_array($json) |
|
| 176 | - ) { |
|
| 177 | - return array_map('base64_decode', $json); |
|
| 178 | - } |
|
| 179 | - return []; |
|
| 180 | - } |
|
| 16 | + private static array $instances = []; |
|
| 17 | + |
|
| 18 | + private string $file = _DIR_ETC . 'cles.php'; |
|
| 19 | + private Cles $cles; |
|
| 20 | + |
|
| 21 | + public static function instance(string $file = ''): self { |
|
| 22 | + if (empty(self::$instances[$file])) { |
|
| 23 | + self::$instances[$file] = new self($file); |
|
| 24 | + } |
|
| 25 | + return self::$instances[$file]; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Retourne le secret du site (shorthand) |
|
| 30 | + * @uses self::getSecretSite() |
|
| 31 | + */ |
|
| 32 | + public static function secret_du_site(): ?string { |
|
| 33 | + return (self::instance())->getSecretSite(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + private function __construct(string $file = '') { |
|
| 37 | + if ($file) { |
|
| 38 | + $this->file = $file; |
|
| 39 | + } |
|
| 40 | + $this->cles = new Cles($this->read()); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Renvoyer le secret du site |
|
| 45 | + * |
|
| 46 | + * Le secret du site doit rester aussi secret que possible, et est eternel |
|
| 47 | + * On ne doit pas l'exporter |
|
| 48 | + * |
|
| 49 | + * Le secret est partagé entre une clé disque et une clé bdd |
|
| 50 | + * |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function getSecretSite(bool $autoInit = true): ?string { |
|
| 54 | + $key = $this->getKey('secret_du_site', $autoInit); |
|
| 55 | + $meta = $this->getMetaKey('secret_du_site', $autoInit); |
|
| 56 | + // conserve la même longeur. |
|
| 57 | + return $key ^ $meta; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** Renvoyer le secret des authentifications */ |
|
| 61 | + public function getSecretAuth(bool $autoInit = false): ?string { |
|
| 62 | + return $this->getKey('secret_des_auth', $autoInit); |
|
| 63 | + } |
|
| 64 | + public function save(): bool { |
|
| 65 | + return ecrire_fichier_securise($this->file, $this->cles->toJson()); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur) |
|
| 70 | + * |
|
| 71 | + * @param string $withKey Clé de chiffrage de la sauvegarde |
|
| 72 | + * @return string Contenu de la sauvegarde chiffrée générée |
|
| 73 | + */ |
|
| 74 | + public function backup( |
|
| 75 | + #[\SensitiveParameter] |
|
| 76 | + string $withKey |
|
| 77 | + ): string { |
|
| 78 | + if (count($this->cles)) { |
|
| 79 | + return Chiffrement::chiffrer($this->cles->toJson(), $withKey); |
|
| 80 | + } |
|
| 81 | + return ''; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles |
|
| 86 | + * (si la sauvegarde est bien valide) |
|
| 87 | + */ |
|
| 88 | + public function restore( |
|
| 89 | + /** Sauvegarde chiffrée (générée par backup()) */ |
|
| 90 | + string $backup, |
|
| 91 | + #[\SensitiveParameter] |
|
| 92 | + string $password_clair, |
|
| 93 | + #[\SensitiveParameter] |
|
| 94 | + string $password_hash, |
|
| 95 | + int $id_auteur |
|
| 96 | + ): bool { |
|
| 97 | + if (empty($backup)) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair); |
|
| 102 | + $json = json_decode($sauvegarde, true); |
|
| 103 | + if (!$json) { |
|
| 104 | + return false; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // cela semble une sauvegarde valide |
|
| 108 | + $cles_potentielles = array_map('base64_decode', $json); |
|
| 109 | + |
|
| 110 | + // il faut faire une double verif sur secret_des_auth |
|
| 111 | + // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde |
|
| 112 | + // et par extension tous les passwords |
|
| 113 | + if ( |
|
| 114 | + !empty($cles_potentielles['secret_des_auth']) |
|
| 115 | + && !Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth']) |
|
| 116 | + ) { |
|
| 117 | + spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 118 | + unset($cles_potentielles['secret_des_auth']); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // on merge les cles pour recuperer les cles manquantes |
|
| 122 | + $restauration = false; |
|
| 123 | + foreach ($cles_potentielles as $name => $key) { |
|
| 124 | + if (!$this->cles->has($name)) { |
|
| 125 | + $this->cles->set($name, $key); |
|
| 126 | + spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 127 | + $restauration = true; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + return $restauration; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + private function getKey(string $name, bool $autoInit): ?string { |
|
| 134 | + if ($this->cles->has($name)) { |
|
| 135 | + return $this->cles->get($name); |
|
| 136 | + } |
|
| 137 | + if ($autoInit) { |
|
| 138 | + $this->cles->generate($name); |
|
| 139 | + // si l'ecriture de fichier a bien marche on peut utiliser la cle |
|
| 140 | + if ($this->save()) { |
|
| 141 | + return $this->cles->get($name); |
|
| 142 | + } |
|
| 143 | + // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
|
| 144 | + spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 145 | + $this->cles->delete($name); |
|
| 146 | + } |
|
| 147 | + return null; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + private function getMetaKey(string $name, bool $autoInit = true): ?string { |
|
| 151 | + if (!isset($GLOBALS['meta'][$name])) { |
|
| 152 | + include_spip('base/abstract_sql'); |
|
| 153 | + $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 154 | + } |
|
| 155 | + $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
|
| 156 | + if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 157 | + return $key; |
|
| 158 | + } |
|
| 159 | + if (!$autoInit) { |
|
| 160 | + return null; |
|
| 161 | + } |
|
| 162 | + $key = Chiffrement::keygen(); |
|
| 163 | + ecrire_meta($name, base64_encode($key), 'non'); |
|
| 164 | + lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 165 | + |
|
| 166 | + return $key; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + private function read(): array { |
|
| 170 | + $json = null; |
|
| 171 | + lire_fichier_securise($this->file, $json); |
|
| 172 | + if ( |
|
| 173 | + $json |
|
| 174 | + && ($json = \json_decode($json, true)) |
|
| 175 | + && is_array($json) |
|
| 176 | + ) { |
|
| 177 | + return array_map('base64_decode', $json); |
|
| 178 | + } |
|
| 179 | + return []; |
|
| 180 | + } |
|
| 181 | 181 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | final class SpipCles { |
| 16 | 16 | private static array $instances = []; |
| 17 | 17 | |
| 18 | - private string $file = _DIR_ETC . 'cles.php'; |
|
| 18 | + private string $file = _DIR_ETC.'cles.php'; |
|
| 19 | 19 | private Cles $cles; |
| 20 | 20 | |
| 21 | 21 | public static function instance(string $file = ''): self { |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | !empty($cles_potentielles['secret_des_auth']) |
| 115 | 115 | && !Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth']) |
| 116 | 116 | ) { |
| 117 | - spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 117 | + spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 118 | 118 | unset($cles_potentielles['secret_des_auth']); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | foreach ($cles_potentielles as $name => $key) { |
| 124 | 124 | if (!$this->cles->has($name)) { |
| 125 | 125 | $this->cles->set($name, $key); |
| 126 | - spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 126 | + spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 127 | 127 | $restauration = true; |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | return $this->cles->get($name); |
| 142 | 142 | } |
| 143 | 143 | // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
| 144 | - spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 144 | + spip_log('Echec ecriture du fichier cle '.$this->file." ; impossible de generer une cle $name", 'chiffrer'._LOG_ERREUR); |
|
| 145 | 145 | $this->cles->delete($name); |
| 146 | 146 | } |
| 147 | 147 | return null; |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | private function getMetaKey(string $name, bool $autoInit = true): ?string { |
| 151 | 151 | if (!isset($GLOBALS['meta'][$name])) { |
| 152 | 152 | include_spip('base/abstract_sql'); |
| 153 | - $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 153 | + $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = '.sql_quote($name, '', 'string')); |
|
| 154 | 154 | } |
| 155 | 155 | $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
| 156 | 156 | if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
@@ -7,32 +7,32 @@ |
||
| 7 | 7 | * privée ou dans un de ses sous menus |
| 8 | 8 | */ |
| 9 | 9 | class Bouton { |
| 10 | - /** Sous-barre de boutons / onglets */ |
|
| 11 | - public array $sousmenu = []; |
|
| 10 | + /** Sous-barre de boutons / onglets */ |
|
| 11 | + public array $sousmenu = []; |
|
| 12 | 12 | |
| 13 | - /** Position dans le menu */ |
|
| 14 | - public int $position = 0; |
|
| 13 | + /** Position dans le menu */ |
|
| 14 | + public int $position = 0; |
|
| 15 | 15 | |
| 16 | - /** Entrée favorite (sa position dans les favoris) ? */ |
|
| 17 | - public int $favori = 0; |
|
| 16 | + /** Entrée favorite (sa position dans les favoris) ? */ |
|
| 17 | + public int $favori = 0; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Définit un bouton |
|
| 22 | - */ |
|
| 23 | - public function __construct( |
|
| 24 | - /** L'icone à mettre dans le bouton */ |
|
| 25 | - public string $icone, |
|
| 26 | - /** Le nom de l'entrée d'i18n associé */ |
|
| 27 | - public string $libelle, |
|
| 28 | - /** L'URL de la page (null => ?exec=nom) */ |
|
| 29 | - public ?string $url = null, |
|
| 30 | - /** Arguments supplémentaires de l'URL */ |
|
| 31 | - public string|array|null $urlArg = null, |
|
| 32 | - /** URL du javascript */ |
|
| 33 | - public ?string $url2 = null, |
|
| 34 | - /** Pour ouvrir une fenêtre à part */ |
|
| 35 | - public ?string $target = null |
|
| 36 | - ) { |
|
| 37 | - } |
|
| 20 | + /** |
|
| 21 | + * Définit un bouton |
|
| 22 | + */ |
|
| 23 | + public function __construct( |
|
| 24 | + /** L'icone à mettre dans le bouton */ |
|
| 25 | + public string $icone, |
|
| 26 | + /** Le nom de l'entrée d'i18n associé */ |
|
| 27 | + public string $libelle, |
|
| 28 | + /** L'URL de la page (null => ?exec=nom) */ |
|
| 29 | + public ?string $url = null, |
|
| 30 | + /** Arguments supplémentaires de l'URL */ |
|
| 31 | + public string|array|null $urlArg = null, |
|
| 32 | + /** URL du javascript */ |
|
| 33 | + public ?string $url2 = null, |
|
| 34 | + /** Pour ouvrir une fenêtre à part */ |
|
| 35 | + public ?string $target = null |
|
| 36 | + ) { |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | /** L'URL de la page (null => ?exec=nom) */ |
| 29 | 29 | public ?string $url = null, |
| 30 | 30 | /** Arguments supplémentaires de l'URL */ |
| 31 | - public string|array|null $urlArg = null, |
|
| 31 | + public string | array | null $urlArg = null, |
|
| 32 | 32 | /** URL du javascript */ |
| 33 | 33 | public ?string $url2 = null, |
| 34 | 34 | /** Pour ouvrir une fenêtre à part */ |
@@ -7,21 +7,21 @@ |
||
| 7 | 7 | * @internal |
| 8 | 8 | */ |
| 9 | 9 | class Collection implements \Stringable { |
| 10 | - private array $vars = []; |
|
| 10 | + private array $vars = []; |
|
| 11 | 11 | |
| 12 | - public function add(string $var, string $value) { |
|
| 13 | - $this->vars[$var] = $value; |
|
| 14 | - } |
|
| 12 | + public function add(string $var, string $value) { |
|
| 13 | + $this->vars[$var] = $value; |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - public function getString(): string { |
|
| 17 | - $string = ''; |
|
| 18 | - foreach ($this->vars as $key => $value) { |
|
| 19 | - $string .= "$key: $value;\n"; |
|
| 20 | - } |
|
| 21 | - return $string; |
|
| 22 | - } |
|
| 16 | + public function getString(): string { |
|
| 17 | + $string = ''; |
|
| 18 | + foreach ($this->vars as $key => $value) { |
|
| 19 | + $string .= "$key: $value;\n"; |
|
| 20 | + } |
|
| 21 | + return $string; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function __toString(): string { |
|
| 25 | - return $this->getString(); |
|
| 26 | - } |
|
| 24 | + public function __toString(): string { |
|
| 25 | + return $this->getString(); |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -32,110 +32,110 @@ discard block |
||
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | 34 | function plugins_get_infos_dist($plug = false, $reload = false, $dir = _DIR_PLUGINS, $clean_old = false) { |
| 35 | - $contenu = null; |
|
| 36 | - $res = null; |
|
| 37 | - static $cache = ''; |
|
| 38 | - static $filecache = ''; |
|
| 39 | - |
|
| 40 | - if ($cache === '') { |
|
| 41 | - $filecache = _DIR_TMP . 'plugin_xml_cache.gz'; |
|
| 42 | - if (is_file($filecache)) { |
|
| 43 | - lire_fichier($filecache, $contenu); |
|
| 44 | - $cache = unserialize($contenu); |
|
| 45 | - } |
|
| 46 | - if (!is_array($cache)) { |
|
| 47 | - $cache = []; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - if (defined('_VAR_MODE') && _VAR_MODE == 'recalcul') { |
|
| 52 | - $reload = true; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - if ($plug === false) { |
|
| 56 | - ecrire_fichier($filecache, serialize($cache)); |
|
| 57 | - |
|
| 58 | - return $cache; |
|
| 59 | - } elseif (is_string($plug)) { |
|
| 60 | - $res = plugins_get_infos_un($plug, $reload, $dir, $cache); |
|
| 61 | - } elseif (is_array($plug)) { |
|
| 62 | - $res = false; |
|
| 63 | - if (!$reload) { |
|
| 64 | - $reload = -1; |
|
| 65 | - } |
|
| 66 | - foreach ($plug as $nom) { |
|
| 67 | - $res |= plugins_get_infos_un($nom, $reload, $dir, $cache); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // Nettoyer le cache des vieux plugins qui ne sont plus la |
|
| 71 | - if ($clean_old && isset($cache[$dir]) && (is_countable($cache[$dir]) ? count($cache[$dir]) : 0)) { |
|
| 72 | - foreach (array_keys($cache[$dir]) as $p) { |
|
| 73 | - if (!in_array($p, $plug)) { |
|
| 74 | - unset($cache[$dir][$p]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - if ($res) { |
|
| 80 | - ecrire_fichier($filecache, serialize($cache)); |
|
| 81 | - } |
|
| 82 | - if (!isset($cache[$dir])) { |
|
| 83 | - return []; |
|
| 84 | - } |
|
| 85 | - if (is_string($plug)) { |
|
| 86 | - return $cache[$dir][$plug] ?? []; |
|
| 87 | - } else { |
|
| 88 | - return $cache[$dir]; |
|
| 89 | - } |
|
| 35 | + $contenu = null; |
|
| 36 | + $res = null; |
|
| 37 | + static $cache = ''; |
|
| 38 | + static $filecache = ''; |
|
| 39 | + |
|
| 40 | + if ($cache === '') { |
|
| 41 | + $filecache = _DIR_TMP . 'plugin_xml_cache.gz'; |
|
| 42 | + if (is_file($filecache)) { |
|
| 43 | + lire_fichier($filecache, $contenu); |
|
| 44 | + $cache = unserialize($contenu); |
|
| 45 | + } |
|
| 46 | + if (!is_array($cache)) { |
|
| 47 | + $cache = []; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + if (defined('_VAR_MODE') && _VAR_MODE == 'recalcul') { |
|
| 52 | + $reload = true; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + if ($plug === false) { |
|
| 56 | + ecrire_fichier($filecache, serialize($cache)); |
|
| 57 | + |
|
| 58 | + return $cache; |
|
| 59 | + } elseif (is_string($plug)) { |
|
| 60 | + $res = plugins_get_infos_un($plug, $reload, $dir, $cache); |
|
| 61 | + } elseif (is_array($plug)) { |
|
| 62 | + $res = false; |
|
| 63 | + if (!$reload) { |
|
| 64 | + $reload = -1; |
|
| 65 | + } |
|
| 66 | + foreach ($plug as $nom) { |
|
| 67 | + $res |= plugins_get_infos_un($nom, $reload, $dir, $cache); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // Nettoyer le cache des vieux plugins qui ne sont plus la |
|
| 71 | + if ($clean_old && isset($cache[$dir]) && (is_countable($cache[$dir]) ? count($cache[$dir]) : 0)) { |
|
| 72 | + foreach (array_keys($cache[$dir]) as $p) { |
|
| 73 | + if (!in_array($p, $plug)) { |
|
| 74 | + unset($cache[$dir][$p]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + if ($res) { |
|
| 80 | + ecrire_fichier($filecache, serialize($cache)); |
|
| 81 | + } |
|
| 82 | + if (!isset($cache[$dir])) { |
|
| 83 | + return []; |
|
| 84 | + } |
|
| 85 | + if (is_string($plug)) { |
|
| 86 | + return $cache[$dir][$plug] ?? []; |
|
| 87 | + } else { |
|
| 88 | + return $cache[$dir]; |
|
| 89 | + } |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | 93 | function plugins_get_infos_un($plug, $reload, $dir, &$cache) { |
| 94 | - if (!is_readable($file = "$dir$plug/paquet.xml")) { |
|
| 95 | - return false; |
|
| 96 | - } |
|
| 97 | - $time = (int) @filemtime($file); |
|
| 98 | - if ($time < 0) { |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - $md5 = md5_file($file); |
|
| 102 | - |
|
| 103 | - $pcache = $cache[$dir][$plug] ?? ['filemtime' => 0, 'md5_file' => '']; |
|
| 104 | - |
|
| 105 | - // si le cache est valide |
|
| 106 | - if ( |
|
| 107 | - (int) $reload <= 0 |
|
| 108 | - && $time > 0 |
|
| 109 | - && $time <= $pcache['filemtime'] |
|
| 110 | - && $md5 == $pcache['md5_file'] |
|
| 111 | - ) { |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // si on arrive pas a lire le fichier, se contenter du cache |
|
| 116 | - if (!($texte = spip_file_get_contents($file))) { |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $f = charger_fonction('infos_paquet', 'plugins'); |
|
| 121 | - $ret = $f($texte, $plug, $dir); |
|
| 122 | - $ret['filemtime'] = $time; |
|
| 123 | - $ret['md5_file'] = $md5; |
|
| 124 | - // Si on lit le paquet.xml de SPIP, on rajoute un procure php afin que les plugins puissent |
|
| 125 | - // utiliser un necessite php. SPIP procure donc la version php courante du serveur. |
|
| 126 | - // chaque librairie php est aussi procurée, par exemple 'php:curl'. |
|
| 127 | - if (isset($ret['prefix']) && $ret['prefix'] == 'spip') { |
|
| 128 | - $ret['procure']['php'] = ['nom' => 'php', 'version' => phpversion()]; |
|
| 129 | - foreach (get_loaded_extensions() as $ext) { |
|
| 130 | - $ret['procure']['php:' . $ext] = ['nom' => 'php:' . $ext, 'version' => phpversion($ext)]; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - $diff = ($ret != $pcache); |
|
| 134 | - |
|
| 135 | - if ($diff) { |
|
| 136 | - $cache[$dir][$plug] = $ret; |
|
| 94 | + if (!is_readable($file = "$dir$plug/paquet.xml")) { |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | + $time = (int) @filemtime($file); |
|
| 98 | + if ($time < 0) { |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + $md5 = md5_file($file); |
|
| 102 | + |
|
| 103 | + $pcache = $cache[$dir][$plug] ?? ['filemtime' => 0, 'md5_file' => '']; |
|
| 104 | + |
|
| 105 | + // si le cache est valide |
|
| 106 | + if ( |
|
| 107 | + (int) $reload <= 0 |
|
| 108 | + && $time > 0 |
|
| 109 | + && $time <= $pcache['filemtime'] |
|
| 110 | + && $md5 == $pcache['md5_file'] |
|
| 111 | + ) { |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // si on arrive pas a lire le fichier, se contenter du cache |
|
| 116 | + if (!($texte = spip_file_get_contents($file))) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $f = charger_fonction('infos_paquet', 'plugins'); |
|
| 121 | + $ret = $f($texte, $plug, $dir); |
|
| 122 | + $ret['filemtime'] = $time; |
|
| 123 | + $ret['md5_file'] = $md5; |
|
| 124 | + // Si on lit le paquet.xml de SPIP, on rajoute un procure php afin que les plugins puissent |
|
| 125 | + // utiliser un necessite php. SPIP procure donc la version php courante du serveur. |
|
| 126 | + // chaque librairie php est aussi procurée, par exemple 'php:curl'. |
|
| 127 | + if (isset($ret['prefix']) && $ret['prefix'] == 'spip') { |
|
| 128 | + $ret['procure']['php'] = ['nom' => 'php', 'version' => phpversion()]; |
|
| 129 | + foreach (get_loaded_extensions() as $ext) { |
|
| 130 | + $ret['procure']['php:' . $ext] = ['nom' => 'php:' . $ext, 'version' => phpversion($ext)]; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + $diff = ($ret != $pcache); |
|
| 134 | + |
|
| 135 | + if ($diff) { |
|
| 136 | + $cache[$dir][$plug] = $ret; |
|
| 137 | 137 | # echo count($cache[$dir]), $dir,$plug, " $reloadc<br>"; |
| 138 | - } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return $diff; |
|
| 140 | + return $diff; |
|
| 141 | 141 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | static $filecache = ''; |
| 39 | 39 | |
| 40 | 40 | if ($cache === '') { |
| 41 | - $filecache = _DIR_TMP . 'plugin_xml_cache.gz'; |
|
| 41 | + $filecache = _DIR_TMP.'plugin_xml_cache.gz'; |
|
| 42 | 42 | if (is_file($filecache)) { |
| 43 | 43 | lire_fichier($filecache, $contenu); |
| 44 | 44 | $cache = unserialize($contenu); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | if (isset($ret['prefix']) && $ret['prefix'] == 'spip') { |
| 128 | 128 | $ret['procure']['php'] = ['nom' => 'php', 'version' => phpversion()]; |
| 129 | 129 | foreach (get_loaded_extensions() as $ext) { |
| 130 | - $ret['procure']['php:' . $ext] = ['nom' => 'php:' . $ext, 'version' => phpversion($ext)]; |
|
| 130 | + $ret['procure']['php:'.$ext] = ['nom' => 'php:'.$ext, 'version' => phpversion($ext)]; |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | $diff = ($ret != $pcache); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | asort($liste_plugins); |
| 64 | 64 | $exposed = urldecode(_request('plugin') ?? ''); |
| 65 | 65 | |
| 66 | - $block_par_lettre = false;//count($liste_plugins)>10; |
|
| 66 | + $block_par_lettre = false; //count($liste_plugins)>10; |
|
| 67 | 67 | $fast_liste_plugins_actifs = []; |
| 68 | 68 | $fast_liste_plugins_checked = []; |
| 69 | 69 | if (is_array($liste_plugins_actifs)) { |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | $actif = isset($fast_liste_plugins_actifs[$plug]); |
| 89 | 89 | $checked = isset($fast_liste_plugins_checked[$plug]); |
| 90 | 90 | $block_actif |= $actif; |
| 91 | - $expose = ($exposed && ($exposed == $plug || $exposed === $dir_plugins . $plug || $exposed === substr( |
|
| 91 | + $expose = ($exposed && ($exposed == $plug || $exposed === $dir_plugins.$plug || $exposed === substr( |
|
| 92 | 92 | $dir_plugins, |
| 93 | 93 | strlen(_DIR_RACINE) |
| 94 | - ) . $plug)); |
|
| 95 | - $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, 'item', $dir_plugins) . "\n"; |
|
| 94 | + ).$plug)); |
|
| 95 | + $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, 'item', $dir_plugins)."\n"; |
|
| 96 | 96 | } |
| 97 | 97 | $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
| 98 | 98 | $class = basename($dir_plugins); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | include_spip('inc/charsets'); |
| 16 | 16 | |
@@ -26,90 +26,90 @@ discard block |
||
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | 28 | function plugins_afficher_liste_dist( |
| 29 | - $url_page, |
|
| 30 | - $liste_plugins, |
|
| 31 | - $liste_plugins_checked, |
|
| 32 | - $liste_plugins_actifs, |
|
| 33 | - $dir_plugins = _DIR_PLUGINS, |
|
| 34 | - $afficher_un = 'afficher_plugin' |
|
| 29 | + $url_page, |
|
| 30 | + $liste_plugins, |
|
| 31 | + $liste_plugins_checked, |
|
| 32 | + $liste_plugins_actifs, |
|
| 33 | + $dir_plugins = _DIR_PLUGINS, |
|
| 34 | + $afficher_un = 'afficher_plugin' |
|
| 35 | 35 | ) { |
| 36 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 37 | - $ligne_plug = charger_fonction($afficher_un, 'plugins'); |
|
| 36 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 37 | + $ligne_plug = charger_fonction($afficher_un, 'plugins'); |
|
| 38 | 38 | |
| 39 | - $all_infos = $get_infos($liste_plugins, false, $dir_plugins); |
|
| 39 | + $all_infos = $get_infos($liste_plugins, false, $dir_plugins); |
|
| 40 | 40 | |
| 41 | - $all_infos = pipeline( |
|
| 42 | - 'filtrer_liste_plugins', |
|
| 43 | - [ |
|
| 44 | - 'args' => [ |
|
| 45 | - 'liste_plugins' => $liste_plugins, |
|
| 46 | - 'liste_plugins_checked' => $liste_plugins_checked, |
|
| 47 | - 'liste_plugins_actifs' => $liste_plugins_actifs, |
|
| 48 | - 'dir_plugins' => $dir_plugins |
|
| 49 | - ], |
|
| 50 | - 'data' => $all_infos |
|
| 51 | - ] |
|
| 52 | - ); |
|
| 41 | + $all_infos = pipeline( |
|
| 42 | + 'filtrer_liste_plugins', |
|
| 43 | + [ |
|
| 44 | + 'args' => [ |
|
| 45 | + 'liste_plugins' => $liste_plugins, |
|
| 46 | + 'liste_plugins_checked' => $liste_plugins_checked, |
|
| 47 | + 'liste_plugins_actifs' => $liste_plugins_actifs, |
|
| 48 | + 'dir_plugins' => $dir_plugins |
|
| 49 | + ], |
|
| 50 | + 'data' => $all_infos |
|
| 51 | + ] |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | - $liste_plugins = array_flip($liste_plugins); |
|
| 55 | - foreach (array_keys($liste_plugins) as $chemin) { |
|
| 56 | - // des plugins ont pu etre enleves de la liste par le pipeline. On en tient compte. |
|
| 57 | - if (isset($all_infos[$chemin])) { |
|
| 58 | - $liste_plugins[$chemin] = strtoupper(trim((string) typo(translitteration(unicode2charset(html2unicode($all_infos[$chemin]['nom'])))))); |
|
| 59 | - } else { |
|
| 60 | - unset($liste_plugins[$chemin]); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - asort($liste_plugins); |
|
| 64 | - $exposed = urldecode(_request('plugin') ?? ''); |
|
| 54 | + $liste_plugins = array_flip($liste_plugins); |
|
| 55 | + foreach (array_keys($liste_plugins) as $chemin) { |
|
| 56 | + // des plugins ont pu etre enleves de la liste par le pipeline. On en tient compte. |
|
| 57 | + if (isset($all_infos[$chemin])) { |
|
| 58 | + $liste_plugins[$chemin] = strtoupper(trim((string) typo(translitteration(unicode2charset(html2unicode($all_infos[$chemin]['nom'])))))); |
|
| 59 | + } else { |
|
| 60 | + unset($liste_plugins[$chemin]); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + asort($liste_plugins); |
|
| 64 | + $exposed = urldecode(_request('plugin') ?? ''); |
|
| 65 | 65 | |
| 66 | - $block_par_lettre = false;//count($liste_plugins)>10; |
|
| 67 | - $fast_liste_plugins_actifs = []; |
|
| 68 | - $fast_liste_plugins_checked = []; |
|
| 69 | - if (is_array($liste_plugins_actifs)) { |
|
| 70 | - $fast_liste_plugins_actifs = array_flip($liste_plugins_actifs); |
|
| 71 | - } |
|
| 72 | - if (is_array($liste_plugins_checked)) { |
|
| 73 | - $fast_liste_plugins_checked = array_flip($liste_plugins_checked); |
|
| 74 | - } |
|
| 66 | + $block_par_lettre = false;//count($liste_plugins)>10; |
|
| 67 | + $fast_liste_plugins_actifs = []; |
|
| 68 | + $fast_liste_plugins_checked = []; |
|
| 69 | + if (is_array($liste_plugins_actifs)) { |
|
| 70 | + $fast_liste_plugins_actifs = array_flip($liste_plugins_actifs); |
|
| 71 | + } |
|
| 72 | + if (is_array($liste_plugins_checked)) { |
|
| 73 | + $fast_liste_plugins_checked = array_flip($liste_plugins_checked); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $res = ''; |
|
| 77 | - $block = ''; |
|
| 78 | - $initiale = ''; |
|
| 79 | - $block_actif = false; |
|
| 80 | - foreach ($liste_plugins as $plug => $nom) { |
|
| 81 | - if (($i = substr($nom, 0, 1)) !== $initiale) { |
|
| 82 | - $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
|
| 83 | - $initiale = $i; |
|
| 84 | - $block = ''; |
|
| 85 | - $block_actif = false; |
|
| 86 | - } |
|
| 87 | - // le rep suivant |
|
| 88 | - $actif = isset($fast_liste_plugins_actifs[$plug]); |
|
| 89 | - $checked = isset($fast_liste_plugins_checked[$plug]); |
|
| 90 | - $block_actif |= $actif; |
|
| 91 | - $expose = ($exposed && ($exposed == $plug || $exposed === $dir_plugins . $plug || $exposed === substr( |
|
| 92 | - $dir_plugins, |
|
| 93 | - strlen(_DIR_RACINE) |
|
| 94 | - ) . $plug)); |
|
| 95 | - $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, 'item', $dir_plugins) . "\n"; |
|
| 96 | - } |
|
| 97 | - $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
|
| 98 | - $class = basename($dir_plugins); |
|
| 76 | + $res = ''; |
|
| 77 | + $block = ''; |
|
| 78 | + $initiale = ''; |
|
| 79 | + $block_actif = false; |
|
| 80 | + foreach ($liste_plugins as $plug => $nom) { |
|
| 81 | + if (($i = substr($nom, 0, 1)) !== $initiale) { |
|
| 82 | + $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
|
| 83 | + $initiale = $i; |
|
| 84 | + $block = ''; |
|
| 85 | + $block_actif = false; |
|
| 86 | + } |
|
| 87 | + // le rep suivant |
|
| 88 | + $actif = isset($fast_liste_plugins_actifs[$plug]); |
|
| 89 | + $checked = isset($fast_liste_plugins_checked[$plug]); |
|
| 90 | + $block_actif |= $actif; |
|
| 91 | + $expose = ($exposed && ($exposed == $plug || $exposed === $dir_plugins . $plug || $exposed === substr( |
|
| 92 | + $dir_plugins, |
|
| 93 | + strlen(_DIR_RACINE) |
|
| 94 | + ) . $plug)); |
|
| 95 | + $block .= $ligne_plug($url_page, $plug, $checked, $actif, $expose, 'item', $dir_plugins) . "\n"; |
|
| 96 | + } |
|
| 97 | + $res .= $block_par_lettre ? affiche_block_initiale($initiale, $block, $block_actif) : $block; |
|
| 98 | + $class = basename($dir_plugins); |
|
| 99 | 99 | |
| 100 | - return $res ? "<ul class='liste-items plugins $class'>$res</ul>" : ''; |
|
| 100 | + return $res ? "<ul class='liste-items plugins $class'>$res</ul>" : ''; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | function affiche_block_initiale($initiale, $block, $block_actif) { |
| 105 | - if (strlen((string) $block)) { |
|
| 106 | - return "<li class='item'>" |
|
| 107 | - . bouton_block_depliable($initiale, (bool) $block_actif) |
|
| 108 | - . debut_block_depliable($block_actif) |
|
| 109 | - . "<ul>$block</ul>" |
|
| 110 | - . fin_block() |
|
| 111 | - . '</li>'; |
|
| 112 | - } |
|
| 105 | + if (strlen((string) $block)) { |
|
| 106 | + return "<li class='item'>" |
|
| 107 | + . bouton_block_depliable($initiale, (bool) $block_actif) |
|
| 108 | + . debut_block_depliable($block_actif) |
|
| 109 | + . "<ul>$block</ul>" |
|
| 110 | + . fin_block() |
|
| 111 | + . '</li>'; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return ''; |
|
| 114 | + return ''; |
|
| 115 | 115 | } |
@@ -10,59 +10,59 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | include_spip('inc/charsets'); |
| 16 | 16 | include_spip('inc/texte'); |
| 17 | 17 | include_spip('plugins/afficher_plugin'); |
| 18 | 18 | |
| 19 | 19 | function plugins_afficher_nom_plugin_dist( |
| 20 | - $url_page, |
|
| 21 | - $plug_file, |
|
| 22 | - $checked, |
|
| 23 | - $actif, |
|
| 24 | - $expose = false, |
|
| 25 | - $class_li = 'item', |
|
| 26 | - $dir_plugins = _DIR_PLUGINS |
|
| 20 | + $url_page, |
|
| 21 | + $plug_file, |
|
| 22 | + $checked, |
|
| 23 | + $actif, |
|
| 24 | + $expose = false, |
|
| 25 | + $class_li = 'item', |
|
| 26 | + $dir_plugins = _DIR_PLUGINS |
|
| 27 | 27 | ) { |
| 28 | - static $id_input = 0; |
|
| 29 | - static $versions = []; |
|
| 28 | + static $id_input = 0; |
|
| 29 | + static $versions = []; |
|
| 30 | 30 | |
| 31 | - $erreur = false; |
|
| 32 | - $s = ''; |
|
| 31 | + $erreur = false; |
|
| 32 | + $s = ''; |
|
| 33 | 33 | |
| 34 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 35 | - $info = $get_infos($plug_file, false, $dir_plugins); |
|
| 34 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 35 | + $info = $get_infos($plug_file, false, $dir_plugins); |
|
| 36 | 36 | |
| 37 | - // numerotons les occurences d'un meme prefix |
|
| 38 | - $versions[$info['prefix']] = isset($versions[$info['prefix']]) ? $versions[$info['prefix']] + 1 : ''; |
|
| 39 | - $id = $info['prefix'] . $versions[$info['prefix']]; |
|
| 37 | + // numerotons les occurences d'un meme prefix |
|
| 38 | + $versions[$info['prefix']] = isset($versions[$info['prefix']]) ? $versions[$info['prefix']] + 1 : ''; |
|
| 39 | + $id = $info['prefix'] . $versions[$info['prefix']]; |
|
| 40 | 40 | |
| 41 | - $class = $class_li; |
|
| 42 | - $class .= $actif ? ' actif' : ''; |
|
| 43 | - $class .= $expose ? ' on' : ''; |
|
| 44 | - $erreur = isset($info['erreur']); |
|
| 45 | - if ($erreur) { |
|
| 46 | - $class .= ' error'; |
|
| 47 | - } |
|
| 48 | - $s .= "<li id='$id' class='$class'>"; |
|
| 41 | + $class = $class_li; |
|
| 42 | + $class .= $actif ? ' actif' : ''; |
|
| 43 | + $class .= $expose ? ' on' : ''; |
|
| 44 | + $erreur = isset($info['erreur']); |
|
| 45 | + if ($erreur) { |
|
| 46 | + $class .= ' error'; |
|
| 47 | + } |
|
| 48 | + $s .= "<li id='$id' class='$class'>"; |
|
| 49 | 49 | |
| 50 | - // Cartouche Resume |
|
| 51 | - $s .= "<div class='resume'>"; |
|
| 50 | + // Cartouche Resume |
|
| 51 | + $s .= "<div class='resume'>"; |
|
| 52 | 52 | |
| 53 | - $prefix = $info['prefix']; |
|
| 54 | - $dir = "$dir_plugins$plug_file/lang/$prefix"; |
|
| 55 | - $desc = plugin_propre($info['description'], $dir); |
|
| 56 | - $url_stat = parametre_url($url_page, 'plugin', $dir_plugins . $plug_file); |
|
| 53 | + $prefix = $info['prefix']; |
|
| 54 | + $dir = "$dir_plugins$plug_file/lang/$prefix"; |
|
| 55 | + $desc = plugin_propre($info['description'], $dir); |
|
| 56 | + $url_stat = parametre_url($url_page, 'plugin', $dir_plugins . $plug_file); |
|
| 57 | 57 | |
| 58 | - $s .= "<strong class='nom'>" . typo($info['nom']) . '</strong>'; |
|
| 59 | - $s .= " <span class='version'>" . $info['version'] . '</span>'; |
|
| 60 | - $s .= " <span class='etat'> - " . plugin_etat_en_clair($info['etat']) . '</span>'; |
|
| 61 | - $s .= '</div>'; |
|
| 58 | + $s .= "<strong class='nom'>" . typo($info['nom']) . '</strong>'; |
|
| 59 | + $s .= " <span class='version'>" . $info['version'] . '</span>'; |
|
| 60 | + $s .= " <span class='etat'> - " . plugin_etat_en_clair($info['etat']) . '</span>'; |
|
| 61 | + $s .= '</div>'; |
|
| 62 | 62 | |
| 63 | - if ($erreur) { |
|
| 64 | - $s .= "<div class='erreur'>" . implode('<br >', $info['erreur']) . '</div>'; |
|
| 65 | - } |
|
| 63 | + if ($erreur) { |
|
| 64 | + $s .= "<div class='erreur'>" . implode('<br >', $info['erreur']) . '</div>'; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - return $s . '</li>'; |
|
| 67 | + return $s . '</li>'; |
|
| 68 | 68 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | // numerotons les occurences d'un meme prefix |
| 38 | 38 | $versions[$info['prefix']] = isset($versions[$info['prefix']]) ? $versions[$info['prefix']] + 1 : ''; |
| 39 | - $id = $info['prefix'] . $versions[$info['prefix']]; |
|
| 39 | + $id = $info['prefix'].$versions[$info['prefix']]; |
|
| 40 | 40 | |
| 41 | 41 | $class = $class_li; |
| 42 | 42 | $class .= $actif ? ' actif' : ''; |
@@ -53,16 +53,16 @@ discard block |
||
| 53 | 53 | $prefix = $info['prefix']; |
| 54 | 54 | $dir = "$dir_plugins$plug_file/lang/$prefix"; |
| 55 | 55 | $desc = plugin_propre($info['description'], $dir); |
| 56 | - $url_stat = parametre_url($url_page, 'plugin', $dir_plugins . $plug_file); |
|
| 56 | + $url_stat = parametre_url($url_page, 'plugin', $dir_plugins.$plug_file); |
|
| 57 | 57 | |
| 58 | - $s .= "<strong class='nom'>" . typo($info['nom']) . '</strong>'; |
|
| 59 | - $s .= " <span class='version'>" . $info['version'] . '</span>'; |
|
| 60 | - $s .= " <span class='etat'> - " . plugin_etat_en_clair($info['etat']) . '</span>'; |
|
| 58 | + $s .= "<strong class='nom'>".typo($info['nom']).'</strong>'; |
|
| 59 | + $s .= " <span class='version'>".$info['version'].'</span>'; |
|
| 60 | + $s .= " <span class='etat'> - ".plugin_etat_en_clair($info['etat']).'</span>'; |
|
| 61 | 61 | $s .= '</div>'; |
| 62 | 62 | |
| 63 | 63 | if ($erreur) { |
| 64 | - $s .= "<div class='erreur'>" . implode('<br >', $info['erreur']) . '</div>'; |
|
| 64 | + $s .= "<div class='erreur'>".implode('<br >', $info['erreur']).'</div>'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - return $s . '</li>'; |
|
| 67 | + return $s.'</li>'; |
|
| 68 | 68 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -27,24 +27,24 @@ discard block |
||
| 27 | 27 | * Environnement du formulaire |
| 28 | 28 | **/ |
| 29 | 29 | function formulaires_configurer_reducteur_charger_dist() { |
| 30 | - $valeurs = []; |
|
| 31 | - foreach ( |
|
| 32 | - [ |
|
| 33 | - 'image_process', |
|
| 34 | - 'formats_graphiques', |
|
| 35 | - 'creer_preview', |
|
| 36 | - 'taille_preview', |
|
| 37 | - ] as $m |
|
| 38 | - ) { |
|
| 39 | - $valeurs[$m] = $GLOBALS['meta'][$m] ?? null; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $valeurs['taille_preview'] = (int) $valeurs['taille_preview']; |
|
| 43 | - if ($valeurs['taille_preview'] < 10) { |
|
| 44 | - $valeurs['taille_preview'] = 120; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - return $valeurs; |
|
| 30 | + $valeurs = []; |
|
| 31 | + foreach ( |
|
| 32 | + [ |
|
| 33 | + 'image_process', |
|
| 34 | + 'formats_graphiques', |
|
| 35 | + 'creer_preview', |
|
| 36 | + 'taille_preview', |
|
| 37 | + ] as $m |
|
| 38 | + ) { |
|
| 39 | + $valeurs[$m] = $GLOBALS['meta'][$m] ?? null; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $valeurs['taille_preview'] = (int) $valeurs['taille_preview']; |
|
| 43 | + if ($valeurs['taille_preview'] < 10) { |
|
| 44 | + $valeurs['taille_preview'] = 120; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + return $valeurs; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | |
@@ -55,52 +55,52 @@ discard block |
||
| 55 | 55 | * Retours des traitements |
| 56 | 56 | **/ |
| 57 | 57 | function formulaires_configurer_reducteur_traiter_dist() { |
| 58 | - $res = ['editable' => true]; |
|
| 59 | - |
|
| 60 | - if (is_array($image_process = _request('image_process_'))) { |
|
| 61 | - $image_process = array_keys($image_process); |
|
| 62 | - $image_process = reset($image_process); |
|
| 63 | - |
|
| 64 | - // application du choix de vignette |
|
| 65 | - if ($image_process) { |
|
| 66 | - // mettre a jour les formats graphiques lisibles |
|
| 67 | - switch ($image_process) { |
|
| 68 | - case 'gd2': |
|
| 69 | - $formats_graphiques = $GLOBALS['meta']['gd_formats_read']; |
|
| 70 | - break; |
|
| 71 | - case 'netpbm': |
|
| 72 | - $formats_graphiques = $GLOBALS['meta']['netpbm_formats']; |
|
| 73 | - break; |
|
| 74 | - case 'convert': |
|
| 75 | - case 'imagick': |
|
| 76 | - $formats_graphiques = 'gif,jpg,png,webp'; |
|
| 77 | - break; |
|
| 78 | - default: #debug |
|
| 79 | - $formats_graphiques = ''; |
|
| 80 | - $image_process = 'non'; |
|
| 81 | - break; |
|
| 82 | - } |
|
| 83 | - ecrire_meta('formats_graphiques', $formats_graphiques, 'non'); |
|
| 84 | - ecrire_meta('image_process', $image_process, 'non'); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - foreach ( |
|
| 89 | - [ |
|
| 90 | - 'creer_preview' |
|
| 91 | - ] as $m |
|
| 92 | - ) { |
|
| 93 | - if (!is_null($v = _request($m))) { |
|
| 94 | - ecrire_meta($m, $v == 'oui' ? 'oui' : 'non'); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - if (!is_null($v = _request('taille_preview'))) { |
|
| 98 | - ecrire_meta('taille_preview', (int) $v); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $res['message_ok'] = _T('config_info_enregistree'); |
|
| 102 | - |
|
| 103 | - return $res; |
|
| 58 | + $res = ['editable' => true]; |
|
| 59 | + |
|
| 60 | + if (is_array($image_process = _request('image_process_'))) { |
|
| 61 | + $image_process = array_keys($image_process); |
|
| 62 | + $image_process = reset($image_process); |
|
| 63 | + |
|
| 64 | + // application du choix de vignette |
|
| 65 | + if ($image_process) { |
|
| 66 | + // mettre a jour les formats graphiques lisibles |
|
| 67 | + switch ($image_process) { |
|
| 68 | + case 'gd2': |
|
| 69 | + $formats_graphiques = $GLOBALS['meta']['gd_formats_read']; |
|
| 70 | + break; |
|
| 71 | + case 'netpbm': |
|
| 72 | + $formats_graphiques = $GLOBALS['meta']['netpbm_formats']; |
|
| 73 | + break; |
|
| 74 | + case 'convert': |
|
| 75 | + case 'imagick': |
|
| 76 | + $formats_graphiques = 'gif,jpg,png,webp'; |
|
| 77 | + break; |
|
| 78 | + default: #debug |
|
| 79 | + $formats_graphiques = ''; |
|
| 80 | + $image_process = 'non'; |
|
| 81 | + break; |
|
| 82 | + } |
|
| 83 | + ecrire_meta('formats_graphiques', $formats_graphiques, 'non'); |
|
| 84 | + ecrire_meta('image_process', $image_process, 'non'); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + foreach ( |
|
| 89 | + [ |
|
| 90 | + 'creer_preview' |
|
| 91 | + ] as $m |
|
| 92 | + ) { |
|
| 93 | + if (!is_null($v = _request($m))) { |
|
| 94 | + ecrire_meta($m, $v == 'oui' ? 'oui' : 'non'); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + if (!is_null($v = _request('taille_preview'))) { |
|
| 98 | + ecrire_meta('taille_preview', (int) $v); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $res['message_ok'] = _T('config_info_enregistree'); |
|
| 102 | + |
|
| 103 | + return $res; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -113,17 +113,17 @@ discard block |
||
| 113 | 113 | * URL d'action pour tester la librairie graphique en créant une vignette |
| 114 | 114 | **/ |
| 115 | 115 | function url_vignette_choix(string $process): string { |
| 116 | - $ok = match ($process) { |
|
| 117 | - 'gd2' => function_exists('ImageCreateTrueColor'), |
|
| 118 | - 'netpbm' => !(defined('_PNMSCALE_COMMAND') && _PNMSCALE_COMMAND == ''), |
|
| 119 | - 'imagick' => method_exists(\Imagick::class, 'readImage'), |
|
| 120 | - 'convert' => !(defined('_CONVERT_COMMAND') && _CONVERT_COMMAND == ''), |
|
| 121 | - default => false, |
|
| 122 | - }; |
|
| 123 | - |
|
| 124 | - if (!$ok) { |
|
| 125 | - return ''; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return generer_url_action('tester', "arg=$process&time=" . time()); |
|
| 116 | + $ok = match ($process) { |
|
| 117 | + 'gd2' => function_exists('ImageCreateTrueColor'), |
|
| 118 | + 'netpbm' => !(defined('_PNMSCALE_COMMAND') && _PNMSCALE_COMMAND == ''), |
|
| 119 | + 'imagick' => method_exists(\Imagick::class, 'readImage'), |
|
| 120 | + 'convert' => !(defined('_CONVERT_COMMAND') && _CONVERT_COMMAND == ''), |
|
| 121 | + default => false, |
|
| 122 | + }; |
|
| 123 | + |
|
| 124 | + if (!$ok) { |
|
| 125 | + return ''; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return generer_url_action('tester', "arg=$process&time=" . time()); |
|
| 129 | 129 | } |
@@ -125,5 +125,5 @@ |
||
| 125 | 125 | return ''; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - return generer_url_action('tester', "arg=$process&time=" . time()); |
|
| 128 | + return generer_url_action('tester', "arg=$process&time=".time()); |
|
| 129 | 129 | } |