where_compatible_spip.php 1.8 KB

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