[SPIP] ~maj v3.0.14-->v3.0.17
[ptitvelo/web/www.git] / www / plugins-dist / svp / inc / where_compatible_spip.php
1 <?php
2
3 /**
4 * Gestion des recherches de plugins par version ou branche
5 *
6 * @plugin SVP pour SPIP
7 * @license GPL
8 * @package SPIP\SVP\Recherche
9 **/
10
11 if (!defined("_ECRIRE_INC_VERSION")) return;
12
13 /**
14 * Construit le WHERE d'une requête SQL de selection des plugins ou paquets
15 * compatibles avec une version ou une branche de spip.
16 *
17 * Cette fonction est appelée par le critère {compatible_spip}
18 *
19 * @used-by svp_compter()
20 * @used-by critere_compatible_spip_dist()
21 *
22 * @param string $version
23 * Numéro de version de SPIP, tel que 2.0.8
24 * @param string $table
25 * Table d'application ou son alias SQL
26 * @param string $op
27 * Opérateur de comparaison, tel que '>' ou '='
28 * @return string
29 * Expression where de la requête SQL
30 */
31 function inc_where_compatible_spip($version='', $table, $op) {
32
33 // le critere s'applique a une VERSION (1.9.2, 2.0.8, ...)
34 if (count(explode('.', $version)) == 3) {
35 $min = 'SUBSTRING_INDEX(' . $table . '.compatibilite_spip, \';\', 1)';
36 $max = 'SUBSTRING_INDEX(' . $table . '.compatibilite_spip, \';\', -1)';
37
38 $where = 'CASE WHEN '.$min.' = \'\'
39 OR '.$min.' = \'[\'
40 THEN \'1.9.0\' <= \''.$version.'\'
41 ELSE TRIM(LEADING \'[\' FROM '.$min.') <= \''.$version.'\'
42 END
43 AND
44 CASE WHEN '.$max.' = \'\'
45 OR '.$max.' = \']\'
46 THEN \'99.99.99\' >= \''.$version.'\'
47 WHEN '.$max.' = \')\'
48 OR '.$max.' = \'[\'
49 THEN \'99.99.99\' > \''.$version.'\'
50 WHEN RIGHT('.$max.', 1) = \')\'
51 OR RIGHT('.$max.', 1) = \'[\'
52 THEN LEFT('.$max.', LENGTH('.$max.') - 1) > \''.$version.'\'
53 ELSE LEFT('.$max.', LENGTH('.$max.') - 1) >= \''.$version.'\'
54 END';
55 }
56 // le critere s'applique a une BRANCHE (1.9, 2.0, ...)
57 elseif (count(explode('.', $version)) == 2) {
58 $where = 'LOCATE(\''.$version.'\', '.$table.'.branches_spip) '.$op.' 0';
59 }
60 // le critere est vide ou mal specifie
61 else {
62 $where = '1=1';
63 }
64
65 return $where;
66 }
67 ?>