@@ -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 | } |
@@ -10,110 +10,110 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) { |
| 17 | - $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 18 | - $racine = basename(_DIR_PLUGINS); |
|
| 19 | - $init_dir = $current_dir = ''; |
|
| 20 | - // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 21 | - // des qu'un path est deja note deplie on s'arrete |
|
| 22 | - $deplie = [$racine => true]; |
|
| 23 | - $fast_liste_plugins_actifs = []; |
|
| 24 | - foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 25 | - $chemin_plug = chemin_plug($racine, $plug); |
|
| 26 | - $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 27 | - $dir = dirname($chemin_plug); |
|
| 28 | - $maxiter = 100; |
|
| 29 | - while (strlen($dir) && !isset($deplie[$dir]) && $dir !== $racine && $maxiter-- > 0) { |
|
| 30 | - $deplie[$dir] = true; |
|
| 31 | - $dir = dirname($dir); |
|
| 32 | - } |
|
| 33 | - } |
|
| 17 | + $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 18 | + $racine = basename(_DIR_PLUGINS); |
|
| 19 | + $init_dir = $current_dir = ''; |
|
| 20 | + // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 21 | + // des qu'un path est deja note deplie on s'arrete |
|
| 22 | + $deplie = [$racine => true]; |
|
| 23 | + $fast_liste_plugins_actifs = []; |
|
| 24 | + foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 25 | + $chemin_plug = chemin_plug($racine, $plug); |
|
| 26 | + $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 27 | + $dir = dirname($chemin_plug); |
|
| 28 | + $maxiter = 100; |
|
| 29 | + while (strlen($dir) && !isset($deplie[$dir]) && $dir !== $racine && $maxiter-- > 0) { |
|
| 30 | + $deplie[$dir] = true; |
|
| 31 | + $dir = dirname($dir); |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - // index repertoires --> plugin |
|
| 36 | - $dir_index = []; |
|
| 37 | - foreach ($liste_plugins as $key => $plug) { |
|
| 38 | - $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 39 | - $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 40 | - } |
|
| 35 | + // index repertoires --> plugin |
|
| 36 | + $dir_index = []; |
|
| 37 | + foreach ($liste_plugins as $key => $plug) { |
|
| 38 | + $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 39 | + $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $visible = @isset($deplie[$current_dir]); |
|
| 43 | - $maxiter = 1000; |
|
| 42 | + $visible = @isset($deplie[$current_dir]); |
|
| 43 | + $maxiter = 1000; |
|
| 44 | 44 | |
| 45 | - $res = ''; |
|
| 46 | - while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) { |
|
| 47 | - // le rep suivant |
|
| 48 | - $dir = dirname(reset($liste_plugins)); |
|
| 49 | - if ($dir != $current_dir) { |
|
| 50 | - $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 51 | - } |
|
| 45 | + $res = ''; |
|
| 46 | + while ((is_countable($liste_plugins) ? count($liste_plugins) : 0) && $maxiter--) { |
|
| 47 | + // le rep suivant |
|
| 48 | + $dir = dirname(reset($liste_plugins)); |
|
| 49 | + if ($dir != $current_dir) { |
|
| 50 | + $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // d'abord tous les plugins du rep courant |
|
| 54 | - if (isset($dir_index[$current_dir])) { |
|
| 55 | - foreach ($dir_index[$current_dir] as $key) { |
|
| 56 | - $plug = $liste_plugins[$key]; |
|
| 57 | - $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 58 | - $id = substr(md5($plug), 0, 16); |
|
| 59 | - $res .= $ligne_plug( |
|
| 60 | - $url_page, |
|
| 61 | - str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), |
|
| 62 | - $actif, |
|
| 63 | - 'menu-entree' |
|
| 64 | - ) . "\n"; |
|
| 65 | - unset($liste_plugins[$key]); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 53 | + // d'abord tous les plugins du rep courant |
|
| 54 | + if (isset($dir_index[$current_dir])) { |
|
| 55 | + foreach ($dir_index[$current_dir] as $key) { |
|
| 56 | + $plug = $liste_plugins[$key]; |
|
| 57 | + $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 58 | + $id = substr(md5($plug), 0, 16); |
|
| 59 | + $res .= $ligne_plug( |
|
| 60 | + $url_page, |
|
| 61 | + str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), |
|
| 62 | + $actif, |
|
| 63 | + 'menu-entree' |
|
| 64 | + ) . "\n"; |
|
| 65 | + unset($liste_plugins[$key]); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 70 | 70 | |
| 71 | - return "<ul class='menu-liste plugins'>" |
|
| 72 | - . $res |
|
| 73 | - . '</ul>'; |
|
| 71 | + return "<ul class='menu-liste plugins'>" |
|
| 72 | + . $res |
|
| 73 | + . '</ul>'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | // vraiment n'importe quoi la gestion des chemins des plugins |
| 78 | 78 | // une fonction pour aider... |
| 79 | 79 | function chemin_plug($racine, $plug) { |
| 80 | - return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 80 | + return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | function tree_open_close_dir(&$current, $target, $deplie = []) { |
| 84 | - if ($current == $target) { |
|
| 85 | - return ''; |
|
| 86 | - } |
|
| 87 | - $tcur = explode('/', $current); |
|
| 88 | - $ttarg = explode('/', $target); |
|
| 89 | - $tcom = []; |
|
| 90 | - $output = ''; |
|
| 91 | - // la partie commune |
|
| 92 | - while (reset($tcur) === reset($ttarg)) { |
|
| 93 | - $tcom[] = array_shift($tcur); |
|
| 94 | - array_shift($ttarg); |
|
| 95 | - } |
|
| 96 | - // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | - while ($close = array_pop($tcur)) { |
|
| 98 | - $output .= "</ul>\n"; |
|
| 99 | - $output .= fin_block(); |
|
| 100 | - $output .= "</li>\n"; |
|
| 101 | - } |
|
| 102 | - $chemin = ''; |
|
| 103 | - if ($tcom !== []) { |
|
| 104 | - $chemin .= implode('/', $tcom) . '/'; |
|
| 105 | - } |
|
| 106 | - // ouvrir les repertoires jusqu'a la cible |
|
| 107 | - while ($open = array_shift($ttarg)) { |
|
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . '/'; |
|
| 110 | - $output .= '<li>'; |
|
| 111 | - $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | - $output .= debut_block_depliable($visible); |
|
| 84 | + if ($current == $target) { |
|
| 85 | + return ''; |
|
| 86 | + } |
|
| 87 | + $tcur = explode('/', $current); |
|
| 88 | + $ttarg = explode('/', $target); |
|
| 89 | + $tcom = []; |
|
| 90 | + $output = ''; |
|
| 91 | + // la partie commune |
|
| 92 | + while (reset($tcur) === reset($ttarg)) { |
|
| 93 | + $tcom[] = array_shift($tcur); |
|
| 94 | + array_shift($ttarg); |
|
| 95 | + } |
|
| 96 | + // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | + while ($close = array_pop($tcur)) { |
|
| 98 | + $output .= "</ul>\n"; |
|
| 99 | + $output .= fin_block(); |
|
| 100 | + $output .= "</li>\n"; |
|
| 101 | + } |
|
| 102 | + $chemin = ''; |
|
| 103 | + if ($tcom !== []) { |
|
| 104 | + $chemin .= implode('/', $tcom) . '/'; |
|
| 105 | + } |
|
| 106 | + // ouvrir les repertoires jusqu'a la cible |
|
| 107 | + while ($open = array_shift($ttarg)) { |
|
| 108 | + $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | + $chemin .= $open . '/'; |
|
| 110 | + $output .= '<li>'; |
|
| 111 | + $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | + $output .= debut_block_depliable($visible); |
|
| 113 | 113 | |
| 114 | - $output .= "<ul>\n"; |
|
| 115 | - } |
|
| 116 | - $current = $target; |
|
| 114 | + $output .= "<ul>\n"; |
|
| 115 | + } |
|
| 116 | + $current = $target; |
|
| 117 | 117 | |
| 118 | - return $output; |
|
| 118 | + return $output; |
|
| 119 | 119 | } |
@@ -58,10 +58,10 @@ discard block |
||
| 58 | 58 | $id = substr(md5($plug), 0, 16); |
| 59 | 59 | $res .= $ligne_plug( |
| 60 | 60 | $url_page, |
| 61 | - str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), |
|
| 61 | + str_replace(_DIR_PLUGINS, '', _DIR_RACINE.$plug), |
|
| 62 | 62 | $actif, |
| 63 | 63 | 'menu-entree' |
| 64 | - ) . "\n"; |
|
| 64 | + )."\n"; |
|
| 65 | 65 | unset($liste_plugins[$key]); |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | $chemin = ''; |
| 103 | 103 | if ($tcom !== []) { |
| 104 | - $chemin .= implode('/', $tcom) . '/'; |
|
| 104 | + $chemin .= implode('/', $tcom).'/'; |
|
| 105 | 105 | } |
| 106 | 106 | // ouvrir les repertoires jusqu'a la cible |
| 107 | 107 | while ($open = array_shift($ttarg)) { |
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . '/'; |
|
| 108 | + $visible = @isset($deplie[$chemin.$open]); |
|
| 109 | + $chemin .= $open.'/'; |
|
| 110 | 110 | $output .= '<li>'; |
| 111 | 111 | $output .= bouton_block_depliable($chemin, $visible); |
| 112 | 112 | $output .= debut_block_depliable($visible); |
@@ -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); |
@@ -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 | /** |
@@ -53,92 +53,92 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | function plugins_installer_dist($plug, $action, $dir_type = '_DIR_PLUGINS') { |
| 55 | 55 | |
| 56 | - // Charger les informations du XML du plugin et vérification de l'existence d'une installation |
|
| 57 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 58 | - $infos = $get_infos($plug, false, constant($dir_type)); |
|
| 59 | - if (!isset($infos['install']) || !$infos['install']) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // Passer en chemin absolu si possible, c'est plus efficace |
|
| 64 | - $dir = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 65 | - if (!defined($dir)) { |
|
| 66 | - $dir = $dir_type; |
|
| 67 | - } |
|
| 68 | - $dir = constant($dir); |
|
| 69 | - foreach ($infos['install'] as $file) { |
|
| 70 | - $file = $dir . $plug . '/' . trim($file); |
|
| 71 | - if (file_exists($file)) { |
|
| 72 | - include_once($file); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // Détermination de la table meta et du nom de la meta plugin |
|
| 77 | - $table = 'meta'; |
|
| 78 | - if (isset($infos['meta']) && $infos['meta'] !== 'meta') { |
|
| 79 | - $table = $infos['meta']; |
|
| 80 | - // S'assurer que les metas de la table spécifique sont bien accessibles dans la globale |
|
| 81 | - lire_metas($table); |
|
| 82 | - } |
|
| 83 | - $nom_meta = $infos['prefix'] . '_base_version'; |
|
| 84 | - |
|
| 85 | - // Détermination de la fonction à appeler et de ses arguments |
|
| 86 | - $f = $infos['prefix'] . '_install'; |
|
| 87 | - if (!function_exists($f)) { |
|
| 88 | - $f = isset($infos['schema']) ? 'spip_plugin_install' : ''; |
|
| 89 | - $arg = $infos; |
|
| 90 | - // On passe la table et la meta pour éviter de les recalculer dans la fonction appelée |
|
| 91 | - $arg['meta'] = $table; |
|
| 92 | - $arg['nom_meta'] = $nom_meta; |
|
| 93 | - } else { |
|
| 94 | - // Ancienne méthode d'installation - TODO à supprimer à terme |
|
| 95 | - // stupide: info deja dans le nom |
|
| 96 | - $arg = $infos['prefix']; |
|
| 97 | - } |
|
| 98 | - $version = $infos['schema'] ?? ''; |
|
| 99 | - |
|
| 100 | - if (!$f) { |
|
| 101 | - // installation sans operation particuliere |
|
| 102 | - $infos['install_test'] = [true, '']; |
|
| 103 | - return $infos; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Tester si l'action demandée est nécessaire ou pas. |
|
| 107 | - $test = $f('test', $arg, $version); |
|
| 108 | - if ($action == 'uninstall') { |
|
| 109 | - $test = !$test; |
|
| 110 | - } |
|
| 111 | - // Si deja fait, on ne fait rien et on ne dit rien |
|
| 112 | - if ($test) { |
|
| 113 | - return true; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - // Si install et que l'on a la meta d'installation, c'est un upgrade. On le consigne dans $infos |
|
| 117 | - // pour renvoyer le bon message en retour de la fonction. |
|
| 118 | - if ($action == 'install' && !empty($GLOBALS[$table][$nom_meta])) { |
|
| 119 | - $infos['upgrade'] = true; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // executer l'installation ou l'inverse |
|
| 123 | - // et renvoyer la trace (mais il faudrait passer en AJAX plutot) |
|
| 124 | - ob_start(); |
|
| 125 | - $f($action, $arg, $version); |
|
| 126 | - $aff = ob_get_contents(); |
|
| 127 | - ob_end_clean(); |
|
| 128 | - |
|
| 129 | - // vider le cache des descriptions de tables a chaque (de)installation |
|
| 130 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 131 | - $trouver_table(''); |
|
| 132 | - $infos['install_test'] = [$f('test', $arg, $version), $aff]; |
|
| 133 | - |
|
| 134 | - // Si la table meta n'est pas spip_meta et qu'on est dans la première installation du plugin |
|
| 135 | - // on force la création du fichier cache à la date du moment. |
|
| 136 | - // On relit les metas de la table pour être sur que la globale soit à jour pour touch_meta. |
|
| 137 | - if ($table !== 'meta' && $action == 'install' && empty($infos['upgrade'])) { |
|
| 138 | - touch_meta(false, $table); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $infos; |
|
| 56 | + // Charger les informations du XML du plugin et vérification de l'existence d'une installation |
|
| 57 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 58 | + $infos = $get_infos($plug, false, constant($dir_type)); |
|
| 59 | + if (!isset($infos['install']) || !$infos['install']) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // Passer en chemin absolu si possible, c'est plus efficace |
|
| 64 | + $dir = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 65 | + if (!defined($dir)) { |
|
| 66 | + $dir = $dir_type; |
|
| 67 | + } |
|
| 68 | + $dir = constant($dir); |
|
| 69 | + foreach ($infos['install'] as $file) { |
|
| 70 | + $file = $dir . $plug . '/' . trim($file); |
|
| 71 | + if (file_exists($file)) { |
|
| 72 | + include_once($file); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // Détermination de la table meta et du nom de la meta plugin |
|
| 77 | + $table = 'meta'; |
|
| 78 | + if (isset($infos['meta']) && $infos['meta'] !== 'meta') { |
|
| 79 | + $table = $infos['meta']; |
|
| 80 | + // S'assurer que les metas de la table spécifique sont bien accessibles dans la globale |
|
| 81 | + lire_metas($table); |
|
| 82 | + } |
|
| 83 | + $nom_meta = $infos['prefix'] . '_base_version'; |
|
| 84 | + |
|
| 85 | + // Détermination de la fonction à appeler et de ses arguments |
|
| 86 | + $f = $infos['prefix'] . '_install'; |
|
| 87 | + if (!function_exists($f)) { |
|
| 88 | + $f = isset($infos['schema']) ? 'spip_plugin_install' : ''; |
|
| 89 | + $arg = $infos; |
|
| 90 | + // On passe la table et la meta pour éviter de les recalculer dans la fonction appelée |
|
| 91 | + $arg['meta'] = $table; |
|
| 92 | + $arg['nom_meta'] = $nom_meta; |
|
| 93 | + } else { |
|
| 94 | + // Ancienne méthode d'installation - TODO à supprimer à terme |
|
| 95 | + // stupide: info deja dans le nom |
|
| 96 | + $arg = $infos['prefix']; |
|
| 97 | + } |
|
| 98 | + $version = $infos['schema'] ?? ''; |
|
| 99 | + |
|
| 100 | + if (!$f) { |
|
| 101 | + // installation sans operation particuliere |
|
| 102 | + $infos['install_test'] = [true, '']; |
|
| 103 | + return $infos; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Tester si l'action demandée est nécessaire ou pas. |
|
| 107 | + $test = $f('test', $arg, $version); |
|
| 108 | + if ($action == 'uninstall') { |
|
| 109 | + $test = !$test; |
|
| 110 | + } |
|
| 111 | + // Si deja fait, on ne fait rien et on ne dit rien |
|
| 112 | + if ($test) { |
|
| 113 | + return true; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + // Si install et que l'on a la meta d'installation, c'est un upgrade. On le consigne dans $infos |
|
| 117 | + // pour renvoyer le bon message en retour de la fonction. |
|
| 118 | + if ($action == 'install' && !empty($GLOBALS[$table][$nom_meta])) { |
|
| 119 | + $infos['upgrade'] = true; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // executer l'installation ou l'inverse |
|
| 123 | + // et renvoyer la trace (mais il faudrait passer en AJAX plutot) |
|
| 124 | + ob_start(); |
|
| 125 | + $f($action, $arg, $version); |
|
| 126 | + $aff = ob_get_contents(); |
|
| 127 | + ob_end_clean(); |
|
| 128 | + |
|
| 129 | + // vider le cache des descriptions de tables a chaque (de)installation |
|
| 130 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 131 | + $trouver_table(''); |
|
| 132 | + $infos['install_test'] = [$f('test', $arg, $version), $aff]; |
|
| 133 | + |
|
| 134 | + // Si la table meta n'est pas spip_meta et qu'on est dans la première installation du plugin |
|
| 135 | + // on force la création du fichier cache à la date du moment. |
|
| 136 | + // On relit les metas de la table pour être sur que la globale soit à jour pour touch_meta. |
|
| 137 | + if ($table !== 'meta' && $action == 'install' && empty($infos['upgrade'])) { |
|
| 138 | + touch_meta(false, $table); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $infos; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -154,24 +154,24 @@ discard block |
||
| 154 | 154 | * @return bool|void |
| 155 | 155 | */ |
| 156 | 156 | function spip_plugin_install($action, $infos, $version_cible) { |
| 157 | - $nom_meta = $infos['nom_meta']; |
|
| 158 | - $table = $infos['meta']; |
|
| 159 | - switch ($action) { |
|
| 160 | - case 'test': |
|
| 161 | - return (isset($GLOBALS[$table]) |
|
| 162 | - && isset($GLOBALS[$table][$nom_meta]) |
|
| 163 | - && spip_version_compare($GLOBALS[$table][$nom_meta], $version_cible, '>=')); |
|
| 164 | - case 'install': |
|
| 165 | - if (function_exists($upgrade = $infos['prefix'] . '_upgrade')) { |
|
| 166 | - $upgrade($nom_meta, $version_cible, $table); |
|
| 167 | - } |
|
| 168 | - break; |
|
| 169 | - case 'uninstall': |
|
| 170 | - if (function_exists($vider_tables = $infos['prefix'] . '_vider_tables')) { |
|
| 171 | - $vider_tables($nom_meta, $table); |
|
| 172 | - } |
|
| 173 | - break; |
|
| 174 | - } |
|
| 157 | + $nom_meta = $infos['nom_meta']; |
|
| 158 | + $table = $infos['meta']; |
|
| 159 | + switch ($action) { |
|
| 160 | + case 'test': |
|
| 161 | + return (isset($GLOBALS[$table]) |
|
| 162 | + && isset($GLOBALS[$table][$nom_meta]) |
|
| 163 | + && spip_version_compare($GLOBALS[$table][$nom_meta], $version_cible, '>=')); |
|
| 164 | + case 'install': |
|
| 165 | + if (function_exists($upgrade = $infos['prefix'] . '_upgrade')) { |
|
| 166 | + $upgrade($nom_meta, $version_cible, $table); |
|
| 167 | + } |
|
| 168 | + break; |
|
| 169 | + case 'uninstall': |
|
| 170 | + if (function_exists($vider_tables = $infos['prefix'] . '_vider_tables')) { |
|
| 171 | + $vider_tables($nom_meta, $table); |
|
| 172 | + } |
|
| 173 | + break; |
|
| 174 | + } |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -190,29 +190,29 @@ discard block |
||
| 190 | 190 | * @return array Tableau des plugins actifs |
| 191 | 191 | **/ |
| 192 | 192 | function liste_plugin_actifs() { |
| 193 | - $liste = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 194 | - if (!$liste) { |
|
| 195 | - return []; |
|
| 196 | - } |
|
| 197 | - if (!is_array($liste = unserialize($liste))) { |
|
| 198 | - // compatibilite pre 1.9.2, mettre a jour la meta |
|
| 199 | - spip_log("MAJ meta plugin vieille version : $liste", 'plugin'); |
|
| 200 | - $new = true; |
|
| 201 | - [, $liste] = liste_plugin_valides(explode(',', $liste)); |
|
| 202 | - } else { |
|
| 203 | - $new = false; |
|
| 204 | - // compat au moment d'une migration depuis version anterieure |
|
| 205 | - // si pas de dir_type, alors c'est _DIR_PLUGINS |
|
| 206 | - foreach ($liste as $prefix => $infos) { |
|
| 207 | - if (!isset($infos['dir_type'])) { |
|
| 208 | - $liste[$prefix]['dir_type'] = '_DIR_PLUGINS'; |
|
| 209 | - $new = true; |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - if ($new) { |
|
| 214 | - ecrire_meta('plugin', serialize($liste)); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $liste; |
|
| 193 | + $liste = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 194 | + if (!$liste) { |
|
| 195 | + return []; |
|
| 196 | + } |
|
| 197 | + if (!is_array($liste = unserialize($liste))) { |
|
| 198 | + // compatibilite pre 1.9.2, mettre a jour la meta |
|
| 199 | + spip_log("MAJ meta plugin vieille version : $liste", 'plugin'); |
|
| 200 | + $new = true; |
|
| 201 | + [, $liste] = liste_plugin_valides(explode(',', $liste)); |
|
| 202 | + } else { |
|
| 203 | + $new = false; |
|
| 204 | + // compat au moment d'une migration depuis version anterieure |
|
| 205 | + // si pas de dir_type, alors c'est _DIR_PLUGINS |
|
| 206 | + foreach ($liste as $prefix => $infos) { |
|
| 207 | + if (!isset($infos['dir_type'])) { |
|
| 208 | + $liste[$prefix]['dir_type'] = '_DIR_PLUGINS'; |
|
| 209 | + $new = true; |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + if ($new) { |
|
| 214 | + ecrire_meta('plugin', serialize($liste)); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return $liste; |
|
| 218 | 218 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | $dir = constant($dir); |
| 69 | 69 | foreach ($infos['install'] as $file) { |
| 70 | - $file = $dir . $plug . '/' . trim($file); |
|
| 70 | + $file = $dir.$plug.'/'.trim($file); |
|
| 71 | 71 | if (file_exists($file)) { |
| 72 | 72 | include_once($file); |
| 73 | 73 | } |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | // S'assurer que les metas de la table spécifique sont bien accessibles dans la globale |
| 81 | 81 | lire_metas($table); |
| 82 | 82 | } |
| 83 | - $nom_meta = $infos['prefix'] . '_base_version'; |
|
| 83 | + $nom_meta = $infos['prefix'].'_base_version'; |
|
| 84 | 84 | |
| 85 | 85 | // Détermination de la fonction à appeler et de ses arguments |
| 86 | - $f = $infos['prefix'] . '_install'; |
|
| 86 | + $f = $infos['prefix'].'_install'; |
|
| 87 | 87 | if (!function_exists($f)) { |
| 88 | 88 | $f = isset($infos['schema']) ? 'spip_plugin_install' : ''; |
| 89 | 89 | $arg = $infos; |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | && isset($GLOBALS[$table][$nom_meta]) |
| 163 | 163 | && spip_version_compare($GLOBALS[$table][$nom_meta], $version_cible, '>=')); |
| 164 | 164 | case 'install': |
| 165 | - if (function_exists($upgrade = $infos['prefix'] . '_upgrade')) { |
|
| 165 | + if (function_exists($upgrade = $infos['prefix'].'_upgrade')) { |
|
| 166 | 166 | $upgrade($nom_meta, $version_cible, $table); |
| 167 | 167 | } |
| 168 | 168 | break; |
| 169 | 169 | case 'uninstall': |
| 170 | - if (function_exists($vider_tables = $infos['prefix'] . '_vider_tables')) { |
|
| 170 | + if (function_exists($vider_tables = $infos['prefix'].'_vider_tables')) { |
|
| 171 | 171 | $vider_tables($nom_meta, $table); |
| 172 | 172 | } |
| 173 | 173 | break; |
@@ -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(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(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($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($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 | } |
@@ -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); |