PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/spip/ecrire/exec/rechercher.php

https://github.com/eyeswebcrea/espace-couture-sittler.fr
PHP | 137 lines | 99 code | 22 blank | 16 comment | 16 complexity | bc868ea66ed2cdf564f08573f2f58654 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2011 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined('_ECRIRE_INC_VERSION')) return;
  12. include_spip('inc/actions');
  13. include_spip('inc/texte');
  14. // http://doc.spip.org/@exec_rechercher_dist
  15. function exec_rechercher_dist()
  16. {
  17. $id = intval(_request('id'));
  18. $exclus = intval(_request('exclus'));
  19. $rac = htmlentities(_request('rac'));
  20. $type = _request('type');
  21. $do = _request('do');
  22. if (preg_match('/^\w*$/', $do))
  23. $r = exec_rechercher_args($id, $type, $exclus, $rac, $do);
  24. else $r = '';
  25. ajax_retour($r);
  26. }
  27. // http://doc.spip.org/@exec_rechercher_args
  28. function exec_rechercher_args($id, $type, $exclus, $rac, $do)
  29. {
  30. if (!$do) $do = 'aff';
  31. $where = preg_split(",\s+,", $type);
  32. if ($where) {
  33. foreach ($where as $k => $v)
  34. $where[$k] = "'%" . substr(str_replace("%","\%", sql_quote($v)),1,-1) . "%'";
  35. $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
  36. $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
  37. $where_id = ("(id_rubrique = " . join(" AND id_rubrique = ", $where) . ")");
  38. } else {
  39. $where_titre = " 1=2";
  40. $where_desc = " 1=2";
  41. $where_id = " 1=2";
  42. }
  43. if ($exclus) {
  44. include_spip('inc/rubriques');
  45. $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
  46. } else $where_exclus = '';
  47. $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus");
  48. $points = $rub = array();
  49. while ($row = sql_fetch($res)) {
  50. $id_rubrique = $row["id_rubrique"];
  51. $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
  52. $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
  53. $points[$id_rubrique] = $points[$id_rubrique] + 3;
  54. }
  55. $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_titre$where_exclus");
  56. while ($row = sql_fetch($res)) {
  57. $id_rubrique = $row["id_rubrique"];
  58. $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
  59. $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
  60. if (isset($points[$id_rubrique]))
  61. $points[$id_rubrique] += 2;
  62. else $points[$id_rubrique] = 0;
  63. }
  64. $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus");
  65. while ($row = sql_fetch($res)) {
  66. $id_rubrique = $row["id_rubrique"];
  67. $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
  68. $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
  69. if (isset($points[$id_rubrique]))
  70. $points[$id_rubrique] += 1;
  71. else $points[$id_rubrique] = 0;
  72. }
  73. if ($points) {
  74. arsort($points);
  75. $style = " style='background-image: url(" . chemin_image('secteur-12.gif') . ")'";
  76. foreach($rub as $k => $v) {
  77. $rub[$k]['atts'] = ($v["id_parent"] ? $style : '')
  78. . " class='arial11 petite-rubrique'";
  79. }
  80. }
  81. return (proposer_item($points, $rub, $rac, $type, $do));
  82. }
  83. // Resultat de la recherche interactive demandee par la fonction JS
  84. // onkey_rechercher qui testera s'il comporte une seule balise au premier niveau
  85. // car cela qui indique qu'un seul resultat a ete trouve.
  86. // ==> attention a composer le message d'erreur avec au moins 2 balises
  87. // http://doc.spip.org/@proposer_item
  88. function proposer_item ($ids, $titles, $rac, $type, $do)
  89. {
  90. if (!$ids)
  91. return "<br /><br /><div style='padding: 5px; color: red;'><b>"
  92. .htmlentities($type)
  93. ."</b> : "._T('avis_aucun_resultat')."</div>";
  94. $ret = '';
  95. $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
  96. $onClick = "aff_selection(this.firstChild.title,'$rac". "_selection','$info', event)";
  97. $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
  98. foreach($ids as $id => $bof) {
  99. $titre = strtr(str_replace("'", "&#8217;", str_replace('"', "&#34;", textebrut($titles[$id]["titre"]))), "\n\r", " ");
  100. $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); "
  101. . $onClick
  102. . "\"\nondblclick=\""
  103. . $ondbClick
  104. . $onClick
  105. . " \"><div"
  106. . $titles[$id]["atts"]
  107. . " title='$id'>&nbsp; "
  108. . $titre
  109. . "</div></div>";
  110. }
  111. return $ret;
  112. }
  113. ?>