PageRenderTime 60ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/DEV/LIB/rw.encode.php

https://github.com/chrisbst35/LI_LEMONDE
PHP | 1380 lines | 918 code | 230 blank | 232 comment | 381 complexity | a1ac97ce470bd48a6a2b0591714bc11d MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. include_once($_SERVER['DOCUMENT_ROOT'] . '/../LIB/common.functions.php');
  3. // session
  4. include_once(URL_LIB . "/session.settings.php");
  5. // constants
  6. include_once(URL_LIB . "/constants.settings.php");
  7. include_once(URL_LIB . "/config.settings.php");
  8. /**
  9. * Enregistre l'erreur de génération d'url dans un fichier dédié si prod, affiche si vbx/dev/rec
  10. * String $message est le message d'erreur à enregistrer / afficher
  11. * String $target correspond au type d'url que l'on veut générer
  12. * Array $infos contient tout ce qui a été envoyé à la méthode to_nat
  13. */
  14. function error_rw_encode($message, $target, $infos = null) {
  15. global $_global;
  16. if ($_global['dev'] == 1 || $_global['pre_prod'] == 1) { // vbx, dev, rec
  17. $str_infos = '';
  18. if (is_array($infos)) {
  19. foreach ($infos as $param => $value)
  20. $str_infos .= ", {$param}=>'{$value}'";
  21. $str_infos = "\nAvailable informations : [" . substr($str_infos, 2) . ']';
  22. }
  23. $target = "<b>{$target}</b>";
  24. $message = "<b>{$message}</b>";
  25. $message .= " while generating url for target {$target} in file rw.encode.php {$str_infos}\n";
  26. // Afficher le message d'erreur
  27. echo '<p style="color:red; font-size:14px; padding:10px 0px">' . nl2br($message) . '</p>';
  28. // Afficher l'historique d'appel de la méthode
  29. echo '<p style="color:green; font-size:14px; padding:10px 0px">';
  30. debug_print_backtrace();
  31. echo '</p>';
  32. } else { // prod
  33. /*
  34. $str_infos = '';
  35. if (is_array($infos)) {
  36. foreach($infos as $param=>$value) $str_infos .= ", {$param}=>'{$value}'";
  37. $str_infos = "\nAvailable informations : [".substr($str_infos,2).']';
  38. }
  39. $message .= " while generating url for target `{$target}` in file rw.encode.php {$str_infos}\n";
  40. $destfile = realpath(dirname(__FILE__)).'/../DATA/'.date('m-Y').'-log_licom_rwencode.log';
  41. error_log('['.date('d-M-Y H:i:s').'] USER Warning: '.$message, 3, $destfile);
  42. */
  43. $filename = date("d-m-Y") . "_log_licom_rwencode";
  44. $pathname = "/data/apache/DATA/fr/log/" . $filename . ".log";
  45. $message .= "_______________________________________________________________________\n";
  46. $message .= "=> DATE TIME: " . $today = date("d/m/Y H:i:s") . "\n";
  47. $message .= "=> CONTEXT ENV: Site=" . $_global["site"] . " Lang=" . $_global["lang"] . " Target=" . $target . "\n";
  48. $message .= "=> PHP SELF: " . $_SERVER['PHP_SELF'] . "\n";
  49. $message .= "=> HTTP REFERER: " . $_SERVER["HTTP_REFERER"] . "\n";
  50. $message .= "=> SERVER ADDR: " . $_SERVER['SERVER_ADDR'] . "\n";
  51. $message .= "=> CLIENT ADDR: " . $_SERVER['REMOTE_ADDR'] . "\n";
  52. $message .= "=> SERVER NAME: " . $_SERVER['SERVER_NAME'] . "\n";
  53. $message .= "=> STR INFOS: " . $str_infos . "\n";
  54. $message .= "_______________________________________________________________________\n";
  55. $message .= "\n";
  56. }
  57. }
  58. /**
  59. *
  60. * @global type $_global
  61. * @global type $_tab_nom_page_trad
  62. * @global array $agency
  63. * @global array $agency
  64. * @param type $array
  65. * @param type $target
  66. * @param type $dns
  67. * @param type $toGDM
  68. * @return string
  69. */
  70. function to_nat($array, $target, $dns = '/', $toGDM = false) {
  71. global $_global;
  72. global $_tab_nom_page_trad;
  73. /*
  74. echo "<pre>[[";
  75. print_r($array);
  76. print_r($target);
  77. echo "]]</pre>";
  78. // die;
  79. *
  80. */
  81. $rw = "";
  82. if (isset($_REQUEST["grp_agency"]) == 1) {
  83. $str_univers = array(1 => "confier_vente",
  84. 2 => "confier_location",
  85. 8 => "confier_colocation");
  86. } else if ($target == 'ref_nat') {
  87. $str_univers = array(1 => "annonces-immobilier",
  88. 2 => "annonces-location",
  89. 8 => "annonces-colocation");
  90. } else {
  91. $str_univers = array(1 => "vente",
  92. 2 => "location",
  93. 8 => "colocation");
  94. }
  95. $order = array("update_date" => 1,
  96. "property_type" => 2,
  97. "price" => 3,
  98. "area" => 4,
  99. "nb_rooms" => 5);
  100. // Si $array n'est pas un tableau, c'est une url
  101. // Donc on récupère le query_string sous la forme d'un tableau
  102. if (!is_array($array)) {
  103. $parse_url = parse_url($array);
  104. parse_str($parse_url['query'], $array);
  105. }
  106. //$rw_data['uniqid'] = uniqid('rw_data_');
  107. $is_internal = isset($array['is_internal']);
  108. //////////////////////////////////////////////////////////////////
  109. if ($target == "recherche" ||
  110. $target == "recherche_agence_annonce" ||
  111. $target == "perim" ||
  112. $target == "recherche_agence" ||
  113. $target == "google") {
  114. // Définir les univers à utiliser
  115. if ($target == "recherche_agence") {
  116. $str_univers = array(
  117. 1 => "annonces-vente",
  118. 2 => "annonces-location",
  119. 8 => "annonces-colocation",
  120. 9 => "annonces-immobilier");
  121. } else if ($target == "recherche_agence_annonce") {
  122. $str_univers = array(
  123. 1 => "annonces-vente",
  124. 2 => "annonces-location",
  125. 8 => "annonces-colocation",
  126. 9 => "annonces-immobilier");
  127. } else if ($target == "google") {
  128. $str_univers = array(
  129. 1 => "gw_vente",
  130. 2 => "gw_location",
  131. 8 => "gw_colocation");
  132. } else {
  133. $str_univers = array(
  134. 1 => "vente-immobilier",
  135. 4 => "vente-immobilier", // viager
  136. 2 => "location-immobilier",
  137. 8 => "recherche-colocation");
  138. }
  139. if ($target == "recherche")
  140. $url_longue = true;
  141. else
  142. $url_longue = false;
  143. // Valeur de l'univers par defaut
  144. $rw_data["univ"] = ((isset($array["univers"]) && !empty($array["univers"])) ? $array["univers"] : $_global["univers"]);
  145. $rw_data["univers"] = $str_univers[$rw_data["univ"]];
  146. $default_locality = LABEL_DEFAULT_LOCALITY;
  147. $rw_data["price"] = "a";
  148. $rw_data["price_min"] = "0";
  149. $rw_data["price_max"] = "0";
  150. $rw_data["area"] = "a";
  151. $rw_data["area_min"] = "0";
  152. $rw_data["area_max"] = "0";
  153. $rw_data["surf_min"] = "0";
  154. $rw_data["surf_max"] = "0";
  155. $order_default = ($rw_data["univ"] == 2 ? "1" : "3"); // "update_date" si loc., "price" sinon
  156. //$order_default = 3;
  157. $rw_data["order"] = $order_default;
  158. $hi_order_default = ($rw_data["univ"] == 2 ? "1" : "0"); // "desc" si loc., "asc" sinon
  159. //$hi_order_default = 0;
  160. $rw_data["hi_order"] = $hi_order_default;
  161. $rw_data["an_visuel"] = "0";
  162. //var_dump($array); //die();
  163. // On a traité l'ancien format nb_room
  164. // => Ne pas refaire le test pour les trois nb_room (min et max)
  165. $nb_rooms_done = false;
  166. $url_seo_possible = true;
  167. /*
  168. echo "<hr>array = "; var_dump($array)."<br>url_seo_possible = "; var_dump($url_seo_possible); echo "<hr>";
  169. */
  170. foreach ($array as $key => $value) {
  171. switch ($key) {
  172. case "val_km":
  173. $rw_data["perim"] = $value;
  174. break;
  175. case "ck_property_type" :
  176. // - Si vous voulez utiliser un seul type de bien,
  177. // utilisez la fonction searchPropertyTypeIdOrig($id_orig)
  178. // - Si vous voulez utiliser la valeur par défaut (aucun filtre),
  179. // n'envoyez pas ck_property_type ou envoyez une valeur nulle
  180. if (!empty($value)) {
  181. $value_init = $value;
  182. // Si c'est un tableau (cf moteur de recherche)
  183. if (is_array($value)) {
  184. if (string_contains($value[0], ',')) {
  185. $array = explode(',', $value[0]);
  186. unset($value[0]);
  187. $value = array_merge($value, $array);
  188. sort($value);
  189. }
  190. if ($value[0] != '') {
  191. $str_property = str_repeat('0', 40); // 40 types de bien possibles (10 octets)
  192. $do_use_label2 = true; // utilise l'info 'label2' plutôt que 'label' si dispo (coloc)
  193. foreach ($value as $properties) {
  194. $value_property_type = getPropretyNameFromId($properties, $rw_data["univ"]);
  195. //echo "[".$properties."=>".$value_property_type."]";
  196. $rw_data["property_type"][] = $value_property_type;
  197. $values = explode(',', $properties);
  198. foreach ($values as $property) {
  199. $str_property[intval($property) - 1] = 1;
  200. }
  201. }
  202. }
  203. // Si un seul numéro est envoyé
  204. } else if (strlen($value) < 3) {
  205. $value = (int) $value;
  206. // rechercher tous les types du groupe contenant ce type
  207. $str_property = searchPropertyTypeIdOrig($value);
  208. // Si c'est uen chaine de binaire (40char)
  209. } else if (strlen($value) == 40) {
  210. $str_property = $value;
  211. // construire le tableau $rw_data["property_type"]
  212. $do_use_label2 = true; // utilise l'info 'label2' plutôt que 'label' si dispo (coloc)
  213. // echo "\n{VALUE:".print_r($value,true).";";
  214. for ($i = 0; $i < strlen($value); $i++) {
  215. if ($value[$i] == 0)
  216. continue;
  217. $properties = $value[$i];
  218. $value_property_type = getPropretyNameFromId($i + 1, $rw_data["univ"]);
  219. // echo "[".$properties."=>".$value_property_type."]<hr>";
  220. $rw_data["property_type"][] = $value_property_type;
  221. }
  222. // Sinon on utilise toute la chaine
  223. } else {
  224. $str_property = $value;
  225. }
  226. $rw_data["ck_property_type"] = $str_property;
  227. //echo "[str_property = $str_property]";
  228. // dédoublonne les éventuels "property_type"
  229. if (isset($rw_data["property_type"]) && !empty($rw_data["property_type"])) {
  230. $rw_data["property_type"] = array_unique($rw_data["property_type"]);
  231. }
  232. }
  233. break;
  234. case "univers" :
  235. $rw_data["univers"] = $str_univers[$value];
  236. break;
  237. case "loc_name" :
  238. $values = str_replace($default_locality, "###", $value);
  239. if (strpos($values, ",")) {
  240. $loc_names = explode(", ", $values);
  241. for ($i = 0; $i < count($loc_names);) {
  242. $locname = trim($loc_names[$i++]);
  243. $rw_data["loc_name" . $i] = $locname == "###" ? '' : $locname;
  244. // On rajoute _ apres la ville quand il n'y a pas de code postal
  245. //INES et SARA 02/09/08
  246. /* if (strpos($rw_data["loc_name".$i], "_") === false) $rw_data["loc_name".$i] .= "_"; */
  247. }
  248. } else {
  249. $rw_data["loc_name1"] = ($value == $default_locality ? '' : $value);
  250. /* if (strpos($rw_data["loc_name1"], "_") === false) $rw_data["loc_name1"] .= "_"; */
  251. }
  252. break;
  253. case "loc_key" :
  254. $rw_data["loc_key"] = $value;
  255. break;
  256. case "lockeys" :
  257. $rw_data["lockeys"] = $value;
  258. break;
  259. case "locnames" :
  260. $rw_data["locnames"] = $value;
  261. break;
  262. case "loc_name1" :
  263. $rw_data["loc_name1"] = $value == $default_locality ? '' : $value;
  264. /*
  265. if (strpos($rw_data["loc_name1"], "_") === false) $rw_data["loc_name1"] .= "_";
  266. */
  267. if (isset($_REQUEST['post_code']))
  268. $rw_data["loc_name1"] .= "-" . $_REQUEST['post_code'];
  269. break;
  270. case "loc_key1" :
  271. $rw_data["loc_key1"] = $value;
  272. break;
  273. case "loc_name2" :
  274. $rw_data["loc_name2"] = $value == $default_locality ? '' : $value;
  275. /*
  276. if (strpos($rw_data["loc_name2"], "_") === false) $rw_data["loc_name2"] .= "_";
  277. */
  278. break;
  279. case "loc_key2" :
  280. $rw_data["loc_key2"] = $value;
  281. break;
  282. case "loc_name3" :
  283. $rw_data["loc_name3"] = $value == $default_locality ? '' : $value;
  284. /*
  285. if (strpos($rw_data["loc_name3"], "_") === false) $rw_data["loc_name3"] .= "_";
  286. */
  287. break;
  288. case "loc_key3" :
  289. $rw_data["loc_key3"] = $value;
  290. break;
  291. case "loc_name4" :
  292. $rw_data["loc_name4"] = $value == $default_locality ? '' : $value;
  293. /*
  294. if (strpos($rw_data["loc_name4"], "_") === false) $rw_data["loc_name4"] .= "_";
  295. */
  296. break;
  297. case "loc_key4" :
  298. $rw_data["loc_key4"] = $value;
  299. break;
  300. case "agc_loc":
  301. $rw_data["agc_loc"] = $value;
  302. break;
  303. case "offset" :
  304. $rw_data["offset"] = empty($value) ? 1 : $value;
  305. break;
  306. case "price" :
  307. $rw_data["price"] = ($value != "" ? $value : "a");
  308. $url_longue = true;
  309. break;
  310. case "price_min" :
  311. case "price_max" :
  312. if (is_numeric($value) == false)
  313. $value = 0;
  314. // Si on a un prix de précisé, pas de redirection vers url seo
  315. else if ($value != '' && $value > 0)
  316. $url_seo_possible = false;
  317. else
  318. $value = 0;
  319. $rw_data[$key] = $value;
  320. $url_longue = true;
  321. break;
  322. case "area" :
  323. $rw_data["area"] = ($value != "" ? $value : "a");
  324. $url_longue = true;
  325. break;
  326. case "area_min" :
  327. case "area_max" :
  328. case "surf_min" :
  329. case "surf_max" :
  330. if (is_numeric($value) == false)
  331. $value = 0;
  332. // Si on a une surface de précisée, pas de redirection vers url seo
  333. else if ($value != '' && $value > 0)
  334. $url_seo_possible = false;
  335. else
  336. $value = 0;
  337. $rw_data[$key] = $value;
  338. $url_longue = true;
  339. break;
  340. case "nb_rooms" :
  341. case "nb_rooms_min" :
  342. case "nb_rooms_max" :
  343. if (!$nb_rooms_done) {
  344. $rw_data["ck_nb_rooms"] = convert_nb_rooms($array['nb_rooms'], $array['nb_rooms_min'], $array['nb_rooms_max']);
  345. $nb_rooms_done = true;
  346. $url_longue = true;
  347. }
  348. break;
  349. case 'ck_advanced':
  350. // Si vous voulez utiliser la valeur par défaut (aucun filtre),
  351. // n'envoyez pas ck_advanced ou envoyez une valeur nulle
  352. if (!empty($value) && ($value != '000000000000000000000000000000000000000000000000' || $_REQUEST['seven_days'] > 0 || $_REQUEST['only_old'] > 0)) {
  353. // Si c'est un tableau (cf moteur de recherche)
  354. if (is_array($value)) {
  355. if ($value[0] != '') {
  356. $str_adv = str_repeat('0', 48); // 48 criteres avancés possibles (9 octets)
  357. foreach ($value as $crit) {
  358. $str_adv[intval($crit)] = 1;
  359. }
  360. } else
  361. continue;
  362. // Si un seul nombre est envoyé
  363. } elseif (strlen($value) < 3) {
  364. $value = (int) $value;
  365. if ($value > 0) {
  366. $str_adv = str_repeat('0', 48); // 48 criteres avancés possibles (9 octets)
  367. $str_adv[$value - 1] = 1;
  368. } else
  369. continue;
  370. // Sinon on enregistre toute la chaine
  371. } else
  372. $str_adv = $value;
  373. // Prise en compte du param -7 jours
  374. if ($_REQUEST['seven_days']) {
  375. $str_adv[25] = 1;
  376. }
  377. // Prise en compte du param seulement dans l ancien
  378. if ($_REQUEST['only_old']) {
  379. $str_adv[26] = 1;
  380. }
  381. $rw_data['ck_advanced'] = $str_adv;
  382. $url_longue = true;
  383. $url_seo_possible = false;
  384. }
  385. break;
  386. case 'dpe':
  387. // Si vous voulez utiliser la valeur par défaut (aucun filtre),
  388. // n'envoyez pas dpe ou envoyez une valeur nulle
  389. if (!empty($value) && ($value != '00000000')) {
  390. // Si c'est un tableau (cf moteur de recherche)
  391. if (is_array($value)) {
  392. if ($value[0] != '') {
  393. $str_dpe = str_repeat('0', 8); // 8 catégories possibles (2 octets)
  394. foreach ($value as $dpe) {
  395. $str_dpe[intval($dpe)] = 1;
  396. }
  397. } else
  398. continue;
  399. // Si un seul numéro est envoyé
  400. } elseif (strlen($value) < 2) {
  401. $value = (int) $value;
  402. if ($value > 0) {
  403. $str_dpe[$value - 1] = 1;
  404. $str_dpe = str_repeat('0', 8); // 8 catégories possibles (2 octets)
  405. } else
  406. continue;
  407. // Sinon on enregistre toute la chaine
  408. } else
  409. $str_dpe = $value;
  410. if (strpos($str_dpe, '1'))
  411. $url_adv = true;
  412. $rw_data['dpe'] = $str_dpe;
  413. $url_longue = true;
  414. $url_seo_possible = false;
  415. }
  416. break;
  417. case "ck_nb_bedrooms" :
  418. // Si vous voulez utiliser la valeur par défaut (aucun filtre),
  419. // n'envoyez pas ck_nb_bedrooms ou envoyez une valeur nulle
  420. if (!empty($value) && ($value != '00000000')) {
  421. // Si c'est un tableau (cf moteur de recherche)
  422. if (is_array($value)) {
  423. if ($value[0] != '') {
  424. $str_nb_bedrooms = str_repeat('0', 8); // 8 nombre de chambres possibles (2 octets)
  425. foreach ($value as $nb_bedroom) {
  426. $str_nb_bedrooms[intval($nb_bedroom)] = 1;
  427. }
  428. } else
  429. continue;
  430. // Si un seul numéro est envoyé
  431. } elseif (strlen($value) < 2) {
  432. $value = (int) $value;
  433. if ($value > 0) {
  434. $str_nb_bedrooms[$value - 1] = 1;
  435. $str_nb_bedrooms = str_repeat('0', 8); // 8 nombre de chambres possibles (2 octets)
  436. } else
  437. continue;
  438. // Sinon on enregistre toute la chaine
  439. } else
  440. $str_nb_bedrooms = $value;
  441. $rw_data['ck_nb_bedrooms'] = $str_nb_bedrooms;
  442. $url_longue = true;
  443. $url_seo_possible = false;
  444. }
  445. break;
  446. case "ck_nb_rooms" :
  447. // Si vous voulez utiliser la valeur par défaut (aucun filtre),
  448. // n'envoyez pas ck_nb_rooms ou envoyez une valeur nulle
  449. if (!empty($value)) {
  450. // Si c'est un tableau (cf moteur de recherche)
  451. if (is_array($value)) {
  452. if ($value[0] != '') {
  453. $str_nb_rooms = str_repeat('0', 8); // 8 nombre de pieces possibles (2 octets)
  454. foreach ($value as $nb_room) {
  455. $str_nb_rooms[intval($nb_room)] = 1;
  456. }
  457. } else
  458. continue;
  459. // Si un seul numéro est envoyé
  460. } elseif (strlen($value) < 2) {
  461. $value = (int) $value;
  462. if ($value > 0) {
  463. $str_nb_rooms = str_repeat('0', 8); // 8 nombre de pieces possibles (2 octets)
  464. $str_nb_rooms[$value - 1] = 1;
  465. } else
  466. continue;
  467. // Sinon on enregistre toute la chaine
  468. } else
  469. $str_nb_rooms = $value;
  470. // Si un nombre de pièces est précisé
  471. if (($first = strpos($str_nb_rooms, '1')) !== false) {
  472. $first++;
  473. // Plusieurs nombres de pièces => Pas d'url SEO.
  474. if (strpos($str_nb_rooms, '1', $first) !== false) {
  475. $url_seo_possible = false;
  476. } else {
  477. $rw_data['nb_rooms'] = $first;
  478. }
  479. }
  480. $rw_data['ck_nb_rooms'] = $str_nb_rooms;
  481. $url_longue = true;
  482. }
  483. break;
  484. // Fraicheur des annonces (0 ou nombre+unité)
  485. case 'fresh':
  486. if (!empty($value)) {
  487. if (preg_match('`[1-9][0-9]*[hjsma]`', $value)) {
  488. $url_adv = true;
  489. $rw_data['fresh'] = $value;
  490. } else
  491. $rw_data['fresh'] = 0;
  492. $url_longue = true;
  493. $url_seo_possible = false;
  494. }
  495. break;
  496. case "order_pages" :
  497. $rw_data["order_pages"] = ($value != "" ? $value : "10");
  498. $url_longue = true;
  499. break;
  500. case "curr" :
  501. if ($value == "")
  502. $rw_data["curr"] = $_global["current_currency"];
  503. else
  504. $rw_data["curr"] = $value;
  505. $url_longue = true;
  506. break;
  507. case "an_visuel":
  508. $rw_data['an_visuel'] = ($value != "" ? $value : "0");
  509. $url_longue = true;
  510. break;
  511. case "use_map":
  512. $rw_data['use_map'] = ($value != "" ? $value : "0");
  513. $url_longue = true;
  514. break;
  515. case "hi_order":
  516. $rw_data["hi_order_param"] = $value;
  517. $value = (string) $value;
  518. if ($value != "") {
  519. $rw_data['hi_order'] = $value;
  520. if ($rw_data['hi_order'] != $hi_order_default) {
  521. $url_seo_possible = false;
  522. }
  523. } else {
  524. $rw_data['hi_order'] = $hi_order_default;
  525. }
  526. $url_longue = true;
  527. break;
  528. case "with_mmf" :
  529. // $rw_data["with_mmf"] = ($value != "" ? $value : "0");
  530. if ($value != "") {
  531. $rw_data['with_mmf'] = $value;
  532. $url_seo_possible = false;
  533. } else {
  534. $rw_data['with_mmf'] = 0;
  535. }
  536. $url_longue = true;
  537. break;
  538. case "order" :
  539. case "ordre" :
  540. $rw_data["order_param"] = $value;
  541. // Si c'est un chiffre
  542. if (preg_match('`[0-9]+`', $value))
  543. $value = (int) $value;
  544. else
  545. $value = $order[$value];
  546. if (empty($value)) {
  547. $value = $order_default;
  548. } else if ($value != $order_default) {
  549. $url_seo_possible = false;
  550. }
  551. $rw_data["order"] = $value;
  552. $url_longue = true;
  553. break;
  554. case "id_agence":
  555. $rw_data['id_agence'] = strtolower($value);
  556. break;
  557. case "xtor" :
  558. $rw_data["xtor"] = $value;
  559. break;
  560. }
  561. }
  562. //echo "<hr>rw_data = "; var_dump($rw_data)."<br>url_seo_possible = "; var_dump($url_seo_possible); echo "<hr>";
  563. // Mini-site agence (annonces d'une agence) --- Url sans recherche (basique)
  564. // EX: http://www.logic-immo.com/agence-immobiliere/lyon/annonces-immobilier-lyon_69280-0410e82a-b7ae-66cc-8f35-9dbb60302952.html
  565. if (($target == "recherche_agence_annonce") && (isset($array['no_search']) || !$url_longue)) {
  566. global $agency;
  567. $agency['offset'] = $rw_data['offset'];
  568. $rw = to_nat_agency($agency, $rw_data['univers'], '');
  569. // Ajout du order si nécessaire // && ($rw_data['order_param'] != 'price')
  570. if (!empty($rw_data['order_param']))
  571. $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'order=' . $rw_data['order_param'];
  572. // Ajout du hi_order si nécessaire // && ($rw_data['hi_order_param'] != '0')
  573. if ($rw_data['hi_order_param'] != '')
  574. $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'hi_order=' . $rw_data['hi_order_param'];
  575. // Ajout du an_visuel si nécessaire
  576. if (!empty($rw_data['an_visuel']) && ($rw_data['an_visuel'] != '0'))
  577. $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'an_visuel=' . $rw_data['an_visuel'];
  578. // Ajouter le xtor
  579. if (!empty($rw_data['xtor']))
  580. $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'xtor=' . $rw_data['xtor'];
  581. //echo "[rw = $rw]<br>";
  582. return $rw;
  583. }
  584. // Convertir la valeur en hexadecimal + Valeur par defaut
  585. if (empty($rw_data["ck_property_type"]))
  586. $rw_data["ck_property_type"] = '0000000000';
  587. else
  588. $rw_data["ck_property_type"] = stringToHexa($rw_data["ck_property_type"], 10);
  589. // Convertir la valeur en hexadecimal + Valeur par defaut
  590. if (empty($rw_data["ck_nb_rooms"]))
  591. $rw_data["ck_nb_rooms"] = '00';
  592. else
  593. $rw_data["ck_nb_rooms"] = stringToHexa($rw_data["ck_nb_rooms"], 2);
  594. //////////////////////////////////////////////////////////////////
  595. // Chercher les localités précisées avec un num
  596. $localities = array();
  597. for ($i = 0; $i < SEARCH_FIELDS_NUMBER;) {
  598. //echo "[loc_name".($i+1)."=".$rw_data['loc_name'.($i+1)]."]";
  599. if (!empty($rw_data['loc_name' . ++$i]))
  600. $localities[] = $rw_data['loc_name' . $i];
  601. }
  602. if (count($localities) == 0) {
  603. //echo "[locnames"."=".$rw_data['locnames']."]";
  604. //echo "[loc_name"."=".$rw_data['loc_name']."]";
  605. // Sinon on recherche d'autres paramètres
  606. if (!empty($rw_data["locnames"]))
  607. $localities = $rw_data["locnames"];
  608. elseif (!empty($rw_data['loc_name']))
  609. $localities = $rw_data['loc_name'];
  610. else { // Risque de provoquer une erreur, QUE FAIRE ??
  611. $localities = '';
  612. $url_seo_possible = false;
  613. error_rw_encode('No locality names given', $target, $rw_data);
  614. }
  615. }
  616. //////////////////////////////////////////////////////////////////
  617. // Chercher les clés de localité précisées avec un num
  618. $lockeys = array();
  619. for ($i = 0; $i < SEARCH_FIELDS_NUMBER;) {
  620. if (!empty($rw_data['loc_key' . ++$i]))
  621. $lockeys[] = $rw_data['loc_key' . $i];
  622. }
  623. if (count($lockeys) == 0) {
  624. // Sinon on recherche d'autres paramètres
  625. if (!empty($rw_data["lockeys"]))
  626. $lockeys = $rw_data["lockeys"];
  627. elseif (!empty($rw_data['loc_key']))
  628. $lockeys = $rw_data['loc_key'];
  629. else { // Risque de provoquer une erreur, QUE FAIRE ??
  630. $lockeys = '';
  631. $url_seo_possible = false;
  632. error_rw_encode('No locality keys given', $target, $rw_data);
  633. }
  634. } elseif (count($lockeys) > 1) {
  635. $url_seo_possible = false;
  636. }
  637. // Ne pas generer d'url courtes si plusieurs loc_keys
  638. if (string_contains($rw_data['lockeys'], ',') && string_contains($rw_data['lockeys'], '_')) {
  639. $url_seo_possible = false;
  640. }
  641. //echo "<pre>ck_property_type = "; print_r($_REQUEST['ck_property_type']); echo "</pre>";
  642. //echo "<pre>"; print_r($_REQUEST); echo "</pre>";
  643. //echo "<pre>"; print_r($rw_data); echo "</pre>";
  644. // Ne pas generer d'url courtes si "avec photos seulement" coché
  645. if ($_REQUEST['an_visuel'] == 1) {
  646. $url_seo_possible = false;
  647. }
  648. //echo "1. url_seo_possible=".($url_seo_possible?'oui':'non')."\n";
  649. // Ne pas generer d'url courtes pour : modèle 2 / location / terrain | viager
  650. if (
  651. ($rw_data['univ'] == 2) && is_array($rw_data['property_type']) &&
  652. (((in_array('Terrain', $rw_data['property_type']) || in_array('Viager', $rw_data['property_type']))) && $_global['univers'] != 8 ) &&
  653. ($rw_data['ck_nb_rooms'] == '00')
  654. ) {
  655. $url_seo_possible = false;
  656. }
  657. //echo "2. url_seo_possible=".($url_seo_possible?'oui':'non')."\n";
  658. // Ne pas generer d'url courtes pour : modèle 3 / vente / ferme | bureau | immeuble | parking | terrain | autre
  659. if (
  660. ($rw_data['univ'] == 1) && isset($rw_data['property_type']) && is_array($rw_data['property_type']) &&
  661. (in_array('Ferme', $rw_data['property_type']) || in_array('Bureau / Commerce', $rw_data['property_type']) ||
  662. in_array('Immeuble', $rw_data['property_type']) || in_array('Parking', $rw_data['property_type']) ||
  663. in_array('Terrain', $rw_data['property_type']) || in_array('Autre', $rw_data['property_type'])) &&
  664. ($rw_data['ck_nb_rooms'] != '00')
  665. ) {
  666. $url_seo_possible = false;
  667. }
  668. //echo "3. url_seo_possible=".($url_seo_possible?'oui':'non')."\n";
  669. // Ne pas generer d'url courtes pour : modèle 3 / location / ferme | bureau | immeuble | parking | terrain | viager | autre
  670. if (
  671. ($rw_data['univ'] == 2) && is_array($rw_data['property_type']) &&
  672. (in_array('Ferme', $rw_data['property_type']) || in_array('Bureau / Commerce', $rw_data['property_type']) ||
  673. in_array('Immeuble', $rw_data['property_type']) || in_array('Parking', $rw_data['property_type']) ||
  674. in_array('Terrain', $rw_data['property_type']) || in_array('Viager', $rw_data['property_type']) || in_array('Autre', $rw_data['property_type'])) &&
  675. ($rw_data['ck_nb_rooms'] != '00')
  676. ) {
  677. $url_seo_possible = false;
  678. }
  679. //var_dump($rw_data);
  680. //var_dump($rw_data['univ']);
  681. //var_dump($rw_data['property_type']);
  682. //echo "4. url_seo_possible=".($url_seo_possible?'oui':'non')."\n";
  683. // W.ASBAITI : Ne pas generer les URLS courtes pour les AEI
  684. if ($toGDM) {
  685. $url_seo_possible = false;
  686. }
  687. //echo "5. url_seo_possible=".($url_seo_possible?'oui':'non')."\n\n";
  688. //echo "<hr>rw_data = "; var_dump($rw_data); echo "<br>url_seo_possible = "; var_dump($url_seo_possible); echo "<hr>";
  689. //exit();
  690. //////////////////////////////////////////////////////////////////
  691. if ($target == 'recherche') {
  692. // Si des localités ont été trouvées
  693. if (is_array($localities))
  694. $localities = implode(',', $localities);
  695. // Si des clés de localité ont été trouvées
  696. if (is_array($lockeys))
  697. $lockeys = implode(',', $lockeys);
  698. /*
  699. * DESACTIVATION DES REDIRECTIONS VERS SEO
  700. * DEPUIS LE FORMULAIRE DE LA RECHERCHE AVANCEE
  701. * => EN ATTENTE DE LA NORMALISATION DES TEMPLATES SEO/CLASSIQUE !!
  702. */
  703. //print_r($rw_data);
  704. // Si on n'a pas fait une recherche avancée, et qu'on n'a qu'une seule localité,
  705. // on essaye de rediriger vers une url SEO
  706. if ($url_seo_possible && strpos($locnames, ',') === false) {
  707. if (isset($rw_data['property_type']) && count($rw_data['property_type']) == 1) {
  708. $rw_data['property_type'][0] = prepareToUrl($rw_data['property_type'][0]);
  709. if (isset($rw_data['nb_rooms'])) { // modèle 3
  710. $infos = array(
  711. 'is_internal' => 1,
  712. 'univers' => $rw_data['univ'],
  713. 'nb_rooms' => $rw_data["nb_rooms"],
  714. 'property_type' => prepareToUrl($rw_data['property_type'][0]),
  715. 'loc_name' => $localities,
  716. 'loc_key' => $lockeys,
  717. );
  718. if (isset($rw_data['offset']) && $rw_data['offset'] > 1)
  719. $infos['offset'] = $rw_data['offset'];
  720. if (isset($rw_data['post_code']))
  721. $infos['post_code'] = $rw_data['post_code'];
  722. $rw = to_nat($infos, 'bien_ville_piece');
  723. } else { // modèle 2
  724. $infos = array(
  725. 'is_internal' => 1,
  726. 'univers' => $rw_data['univ'],
  727. 'property_type' => prepareToUrl($rw_data['property_type'][0]),
  728. 'loc_name' => $localities,
  729. 'loc_key' => $lockeys,
  730. 'offset' => $rw_data['offset']
  731. );
  732. if (isset($rw_data['offset']) && $rw_data['offset'] > 1)
  733. $infos['offset'] = $rw_data['offset'];
  734. /* echo "\n\n\n\n";
  735. echo "rw_data = "; print_r($rw_data);
  736. echo "infos = "; print_r($infos);
  737. echo "url_seo_possible=".($url_seo_possible?'oui':'non');
  738. echo "\n\n\n\n"; */
  739. $rw = to_nat($infos, 'bien_ville_liste');
  740. }
  741. } elseif (((count($rw_data['property_type']) == 0) && ($rw_data["nb_rooms"] == 0)) || $_global['univers'] == 8) { // modèle 1
  742. $infos = array(
  743. 'is_internal' => 1,
  744. 'univers' => $rw_data['univ'],
  745. 'loc_name' => $localities,
  746. 'loc_key' => $lockeys,
  747. );
  748. if (isset($rw_data['offset']) && $rw_data['offset'] > 1)
  749. $infos['offset'] = $rw_data['offset'];
  750. $rw = to_nat($infos, 'ref_nat');
  751. }
  752. //var_dump($rw);
  753. if ($rw != '') {
  754. //echo "[rw = $rw]";
  755. return $rw;
  756. }
  757. // Continuer la génération d'une url de recherche avancée
  758. }
  759. $locnames = prepareToUrl($localities);
  760. // Convertir la valeur en hexadecimal + Valeur par defaut
  761. if (empty($rw_data["ck_nb_bedrooms"]))
  762. $rw_data["ck_nb_bedrooms"] = '00';
  763. else
  764. $rw_data["ck_nb_bedrooms"] = stringToHexa($rw_data["ck_nb_bedrooms"], 2);
  765. // Convertir la valeur en hexadecimal + Valeur par defaut
  766. if (empty($rw_data["ck_advanced"]))
  767. $rw_data["ck_advanced"] = '000000000000';
  768. else
  769. $rw_data["ck_advanced"] = stringToHexa($rw_data["ck_advanced"], 12);
  770. // Convertir la valeur en hexadecimal + Valeur par defaut
  771. if (empty($rw_data["dpe"]))
  772. $rw_data["dpe"] = '00';
  773. else
  774. $rw_data["dpe"] = stringToHexa($rw_data["dpe"], 2);
  775. if (empty($rw_data['fresh']))
  776. $rw_data['fresh'] = 0;
  777. if (empty($rw_data['offset']))
  778. $rw_data['offset'] = 1;
  779. // Début construction URL
  780. $url = $rw_data["univers"] . '-' . $locnames . ',' . $lockeys . '-';
  781. $url .= $rw_data["ck_property_type"] . '-';
  782. //*** DON'T FORGET TO APPLY THE ARRAY CHECK TO ALL PARAMETERS IN CASE OF MULTIBOX SEARCH REQUEST (Michel)
  783. $url .= $rw_data["price_min"] . ',' . $rw_data["price_max"] . '-';
  784. $url .= $rw_data["area_min"] . ',' . $rw_data["area_max"] . '-';
  785. $url .= $rw_data["surf_min"] . ',' . $rw_data["surf_max"] . '-';
  786. $url .= $rw_data["ck_nb_rooms"] . '-' . $rw_data["ck_nb_bedrooms"] . '-';
  787. $url .= $rw_data['ck_advanced'] . '-';
  788. $url .= $rw_data['dpe'] . '-' . $rw_data['fresh'] . '-';
  789. $url .= '0-'; // FREE (Champ libre, non utilisé pour l'instant)
  790. $url .= $rw_data['order'] . '-' . $rw_data['hi_order'] . '-'; // Tri
  791. $url .= $rw_data['an_visuel'] . '-'; // Photo ?
  792. $url .= $rw_data['offset']; // Numéro de page
  793. $url = strtolower($url) . '.html';
  794. // Ajouter le xtor
  795. if (!empty($rw_data["xtor"]))
  796. $url .= (strpos($url, '?') !== false ? '&' : '?') . 'xtor=' . $rw_data["xtor"];
  797. // Fin de la génération des urls de recherche avancées
  798. //die($url);
  799. return $url;
  800. }
  801. // Si des localités ont été trouvées
  802. if (is_array($localities))
  803. $localities = implode('-', $localities);
  804. $locnames = prepareToUrl($localities);
  805. // Si des clés de localité ont été trouvées
  806. if (is_array($lockeys))
  807. $lockeys = implode('-', $lockeys);
  808. $rw_url[] = $rw_data["univers"];
  809. $rw_url['locname'] = $locnames;
  810. $rw_url[] = $lockeys;
  811. // Ajouter le type de bien à l'url
  812. $rw_url[] = $rw_data["ck_property_type"];
  813. if ($target == "perim")
  814. $rw_url[] = $rw_data["perim"];
  815. //$rw_url[] = ($rw_data["offset"] ? $rw_data["offset"] : 0);
  816. //Modif pour faire commencer les paging à la page 1 ... C'est mieux non ?!
  817. $rw_url[] = empty($rw_data["offset"]) ? 1 : $rw_data["offset"];
  818. // Si c'est une url longue, on ajoute les paramètres de recherche
  819. if ($url_longue == true) {
  820. //*** DON'T FORGET TO APPLY THE ARRAY CHECK TO ALL PARAMETERS IN CASE OF MULTIBOX SEARCH REQUEST (Michel)
  821. $rw_url[] = (is_array($rw_data["price"]) ? implode("", $rw_data["price"]) : $rw_data["price"]);
  822. $rw_url[] = (is_array($rw_data["price_min"]) ? implode("", $rw_data["price_min"]) : $rw_data["price_min"]);
  823. $rw_url[] = (is_array($rw_data["price_max"]) ? implode("", $rw_data["price_max"]) : $rw_data["price_max"]);
  824. $rw_url[] = (is_array($rw_data["area"]) ? implode("", $rw_data["area"]) : $rw_data["area"]);
  825. $rw_url[] = (is_array($rw_data["area_min"]) ? implode("", $rw_data["area_min"]) : $rw_data["area_min"]);
  826. $rw_url[] = (is_array($rw_data["area_max"]) ? implode("", $rw_data["area_max"]) : $rw_data["area_max"]);
  827. $rw_url[] = $rw_data["ck_nb_rooms"];
  828. $rw_url[] = $rw_data['order'];
  829. $rw_url[] = $rw_data['an_visuel'];
  830. $rw_url[] = $rw_data['hi_order'];
  831. if ($rw_data['use_map'] != "")
  832. $rw_url[] = $rw_data['use_map'];
  833. }
  834. // Mini-site agence (annonces d'une agence) --- Url avec recherche (depuis formulaire à droite)
  835. // EX: http://www.logic-immo.com/agence-immobiliere/marcy-l-etoile/annonces-immobilier-marcy-l-etoile-36153_2-0000000000-1-a-0-0-a-0-0-00-3-0-0-0410e82a-b7ae-66cc-8f35-9dbb60302952.htm
  836. if ($target == "recherche_agence_annonce") {
  837. global $agency;
  838. if (!empty($rw_data["agc_loc"]))
  839. $locality = prepareToUrl($rw_data['agc_loc']);
  840. elseif (!empty($agency['town_agency']))
  841. $locality = prepareToUrl($agency['town_agency']);
  842. else
  843. $locality = prepareToUrl($locnames);
  844. if (empty($rw_url['locname']))
  845. $rw_url['locname'] = $locality;
  846. $rw = $dns . "agence-immobiliere/" . $locality . '/' . implode("-", $rw_url) . '-' . $rw_data['id_agence'] . ".htm";
  847. } else {
  848. // Par defaut on joint toutes les valeurs de $rw_url
  849. // Dans l'ordre où elles ont été ajoutées.
  850. $rw = $dns . implode("-", $rw_url) . ".htm";
  851. }
  852. } else {
  853. // Récupérer le type de transaction
  854. if ($array['type_transaction'] == 2 || (!isset($array['type_transaction']) && $array['univers']==2))
  855. $trans = 'location';
  856. else if ($array['type_transaction'] == 8 || (!isset($array['type_transaction']) && $array['univers']==8))
  857. $trans = 'colocation';
  858. else
  859. $trans = 'vente';
  860. if ($target == "detail") {
  861. if (empty($array["id"])) {
  862. // Enregistrer l'erreur de génération
  863. error_rw_encode('No announce identifier given', $target, $array);
  864. if (isset($array['req_internal']))
  865. return '';
  866. }
  867. $rw = 'detail-' . $trans . '-' . $array['id'] . ".htm";
  868. }else if ($target == "ref_nat") { // ie URLs courtes modèle 1
  869. $offset = empty($array["offset"]) || $array["offset"] < 2 ? '' : '-' . $array["offset"];
  870. if (empty($array["loc_name"]) || empty($array["loc_key"])) {
  871. // Enregistrer l'erreur de génération
  872. error_rw_encode('Invalid locality', $target, $array);
  873. if (isset($array['req_internal']))
  874. return '';
  875. }
  876. $locname = prepareToUrl($array["loc_name"]);
  877. $lockey = $array['loc_key'];
  878. if ($array['univers'] == 2) $univers = 'annonces-location';
  879. else if ($array['univers'] == 8) $univers = 'annonces-colocation';
  880. else $univers = 'annonces-immobilier';
  881. $rw = "{$univers}-{$locname}-{$lockey}{$offset}.html";
  882. }
  883. else if ($target == 'bien_ville_piece') { // ie URLs courtes modèle 3
  884. // => appartement-toulouse/vente-appartement-toulouse/appartement-3-pieces-toulouse-31000-393_99.html
  885. // => maison-villa-aix-en-provence/colocation-maison-villa-aix-en-provence/maison-villa-2-chambres-aix-en-provence-13100-36129_2.html
  886. // Renvoyer une 404 si une information est manquante
  887. if (empty($array['nb_rooms']) || empty($array['property_type']) || empty($array['loc_name']) || empty($array['loc_key'])) {
  888. // Enregistrer l'erreur de génération
  889. error_rw_encode('Missing variable', $target, $array);
  890. if (isset($array['req_internal']))
  891. return '';
  892. }
  893. // Renvoyer une 404 si le type n'est pas une chaine ou si on a plusieurs pieces/chambres
  894. if (is_numeric($array['property_type']) || strlen($array['nb_rooms']) > 1) {
  895. // Enregistrer l'erreur de génération
  896. error_rw_encode('Invalid value given', $target, $array);
  897. if (isset($array['req_internal']))
  898. return '';
  899. }
  900. if ($_global['univers'] == 8) {
  901. $wordPiece = 'chambre';
  902. } else { // 1 || 2
  903. $wordPiece = 'piece';
  904. }
  905. $strPieces = $array['nb_rooms'] . '-' . $wordPiece;
  906. if ($array['nb_rooms'] > 1)
  907. $strPieces .= 's';
  908. $lockey = $array['loc_key'];
  909. $locality = prepareToUrl($array['loc_name']);
  910. //echo "[locality=$locality , matches=$matches]";
  911. // Vérifier la localité
  912. if ($lockey == '100_1') {
  913. $locname = 'paris';
  914. $locality = 'paris-75';
  915. } else if (!preg_match('`^([a-z-]+(1er|2e|3e|4e|5e|6e|7e|8e|9e|10e|11e|12e|13e|14e|15e|16e|17e|18e|19e|20e)*|pyrenees-2000|tampon-17eme-km)-([0-9]+|2[a-b]|tous-codes-postaux)$`', $locality, $matches)) {
  916. // Enregistrer l'erreur de génération
  917. error_rw_encode('', $target, $array);
  918. if (isset($array['req_internal']))
  919. return '';
  920. $locname = $locality;
  921. } else
  922. $locname = $matches[1]; // Ville sans CP
  923. $propertyType = $array['property_type'];
  924. if ($array['offset'] > 1)
  925. $offset = '-' . $array['offset'];
  926. else
  927. $offset = '';
  928. // Remplacer appartement 1 pièce par studio pour vente/location
  929. if ((($_global['univers'] == 1) || ($_global['univers'] == 2)) && ($propertyType == 'appartement') && ($strPieces == '1-piece')) {
  930. $rw = "studio-{$locname}/{$str_univers[$_global['univers']]}-studio-{$locality}-{$lockey}$offset.html";
  931. } else {
  932. $rw = "{$propertyType}-{$locname}/{$str_univers[$_global['univers']]}-{$propertyType}-{$locname}/{$propertyType}-{$strPieces}-{$locality}-{$lockey}$offset.html";
  933. }
  934. } else if ($target == 'bien_ville_liste') { // ie URLs courtes modèle 2
  935. // => appartement-toulouse/vente-appartement-toulouse-31000-393_99.html
  936. // Renvoyer une 404 si une information est manquante
  937. if (empty($array['property_type']) || empty($array['loc_name']) || empty($array['loc_key'])) {
  938. // Enregistrer l'erreur de génération
  939. error_rw_encode('Missing variable', $target, $array);
  940. if (isset($array['req_internal']))
  941. return '';
  942. }
  943. // Renvoyer une 404 si le type n'est pas une chaine ou si on a plusieurs pieces
  944. if (is_numeric($array['property_type'])) {
  945. // Enregistrer l'erreur de génération
  946. error_rw_encode('Invalid value given', $target, $array);
  947. if (isset($array['req_internal']))
  948. return '';
  949. }
  950. $lockey = $array['loc_key'];
  951. $locality = prepareToUrl($array['loc_name']);
  952. //echo "[$locality]"; //exit;
  953. // Vérifier la localité
  954. if ($lockey == '100_1') {
  955. $locname = 'p…

Large files files are truncated, but you can click here to view the full file