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