/DEV/LIB/rw.encode.php
PHP | 1380 lines | 918 code | 230 blank | 232 comment | 381 complexity | a1ac97ce470bd48a6a2b0591714bc11d MD5 | raw file
- <?php
- include_once($_SERVER['DOCUMENT_ROOT'] . '/../LIB/common.functions.php');
- // session
- include_once(URL_LIB . "/session.settings.php");
- // constants
- include_once(URL_LIB . "/constants.settings.php");
- include_once(URL_LIB . "/config.settings.php");
- /**
- * Enregistre l'erreur de génération d'url dans un fichier dédié si prod, affiche si vbx/dev/rec
- * String $message est le message d'erreur à enregistrer / afficher
- * String $target correspond au type d'url que l'on veut générer
- * Array $infos contient tout ce qui a été envoyé à la méthode to_nat
- */
- function error_rw_encode($message, $target, $infos = null) {
- global $_global;
- if ($_global['dev'] == 1 || $_global['pre_prod'] == 1) { // vbx, dev, rec
- $str_infos = '';
- if (is_array($infos)) {
- foreach ($infos as $param => $value)
- $str_infos .= ", {$param}=>'{$value}'";
- $str_infos = "\nAvailable informations : [" . substr($str_infos, 2) . ']';
- }
- $target = "<b>{$target}</b>";
- $message = "<b>{$message}</b>";
- $message .= " while generating url for target {$target} in file rw.encode.php {$str_infos}\n";
- // Afficher le message d'erreur
- echo '<p style="color:red; font-size:14px; padding:10px 0px">' . nl2br($message) . '</p>';
- // Afficher l'historique d'appel de la méthode
- echo '<p style="color:green; font-size:14px; padding:10px 0px">';
- debug_print_backtrace();
- echo '</p>';
- } else { // prod
- /*
- $str_infos = '';
- if (is_array($infos)) {
- foreach($infos as $param=>$value) $str_infos .= ", {$param}=>'{$value}'";
- $str_infos = "\nAvailable informations : [".substr($str_infos,2).']';
- }
- $message .= " while generating url for target `{$target}` in file rw.encode.php {$str_infos}\n";
- $destfile = realpath(dirname(__FILE__)).'/../DATA/'.date('m-Y').'-log_licom_rwencode.log';
- error_log('['.date('d-M-Y H:i:s').'] USER Warning: '.$message, 3, $destfile);
- */
- $filename = date("d-m-Y") . "_log_licom_rwencode";
- $pathname = "/data/apache/DATA/fr/log/" . $filename . ".log";
- $message .= "_______________________________________________________________________\n";
- $message .= "=> DATE TIME: " . $today = date("d/m/Y H:i:s") . "\n";
- $message .= "=> CONTEXT ENV: Site=" . $_global["site"] . " Lang=" . $_global["lang"] . " Target=" . $target . "\n";
- $message .= "=> PHP SELF: " . $_SERVER['PHP_SELF'] . "\n";
- $message .= "=> HTTP REFERER: " . $_SERVER["HTTP_REFERER"] . "\n";
- $message .= "=> SERVER ADDR: " . $_SERVER['SERVER_ADDR'] . "\n";
- $message .= "=> CLIENT ADDR: " . $_SERVER['REMOTE_ADDR'] . "\n";
- $message .= "=> SERVER NAME: " . $_SERVER['SERVER_NAME'] . "\n";
- $message .= "=> STR INFOS: " . $str_infos . "\n";
- $message .= "_______________________________________________________________________\n";
- $message .= "\n";
- }
- }
- /**
- *
- * @global type $_global
- * @global type $_tab_nom_page_trad
- * @global array $agency
- * @global array $agency
- * @param type $array
- * @param type $target
- * @param type $dns
- * @param type $toGDM
- * @return string
- */
- function to_nat($array, $target, $dns = '/', $toGDM = false) {
- global $_global;
- global $_tab_nom_page_trad;
- /*
- echo "<pre>[[";
- print_r($array);
- print_r($target);
- echo "]]</pre>";
- // die;
- *
- */
- $rw = "";
- if (isset($_REQUEST["grp_agency"]) == 1) {
- $str_univers = array(1 => "confier_vente",
- 2 => "confier_location",
- 8 => "confier_colocation");
- } else if ($target == 'ref_nat') {
- $str_univers = array(1 => "annonces-immobilier",
- 2 => "annonces-location",
- 8 => "annonces-colocation");
- } else {
- $str_univers = array(1 => "vente",
- 2 => "location",
- 8 => "colocation");
- }
- $order = array("update_date" => 1,
- "property_type" => 2,
- "price" => 3,
- "area" => 4,
- "nb_rooms" => 5);
- // Si $array n'est pas un tableau, c'est une url
- // Donc on récupère le query_string sous la forme d'un tableau
- if (!is_array($array)) {
- $parse_url = parse_url($array);
- parse_str($parse_url['query'], $array);
- }
- //$rw_data['uniqid'] = uniqid('rw_data_');
- $is_internal = isset($array['is_internal']);
- //////////////////////////////////////////////////////////////////
- if ($target == "recherche" ||
- $target == "recherche_agence_annonce" ||
- $target == "perim" ||
- $target == "recherche_agence" ||
- $target == "google") {
- // Définir les univers à utiliser
- if ($target == "recherche_agence") {
- $str_univers = array(
- 1 => "annonces-vente",
- 2 => "annonces-location",
- 8 => "annonces-colocation",
- 9 => "annonces-immobilier");
- } else if ($target == "recherche_agence_annonce") {
- $str_univers = array(
- 1 => "annonces-vente",
- 2 => "annonces-location",
- 8 => "annonces-colocation",
- 9 => "annonces-immobilier");
- } else if ($target == "google") {
- $str_univers = array(
- 1 => "gw_vente",
- 2 => "gw_location",
- 8 => "gw_colocation");
- } else {
- $str_univers = array(
- 1 => "vente-immobilier",
- 4 => "vente-immobilier", // viager
- 2 => "location-immobilier",
- 8 => "recherche-colocation");
- }
- if ($target == "recherche")
- $url_longue = true;
- else
- $url_longue = false;
- // Valeur de l'univers par defaut
- $rw_data["univ"] = ((isset($array["univers"]) && !empty($array["univers"])) ? $array["univers"] : $_global["univers"]);
- $rw_data["univers"] = $str_univers[$rw_data["univ"]];
- $default_locality = LABEL_DEFAULT_LOCALITY;
- $rw_data["price"] = "a";
- $rw_data["price_min"] = "0";
- $rw_data["price_max"] = "0";
- $rw_data["area"] = "a";
- $rw_data["area_min"] = "0";
- $rw_data["area_max"] = "0";
- $rw_data["surf_min"] = "0";
- $rw_data["surf_max"] = "0";
- $order_default = ($rw_data["univ"] == 2 ? "1" : "3"); // "update_date" si loc., "price" sinon
- //$order_default = 3;
- $rw_data["order"] = $order_default;
- $hi_order_default = ($rw_data["univ"] == 2 ? "1" : "0"); // "desc" si loc., "asc" sinon
- //$hi_order_default = 0;
- $rw_data["hi_order"] = $hi_order_default;
- $rw_data["an_visuel"] = "0";
- //var_dump($array); //die();
- // On a traité l'ancien format nb_room
- // => Ne pas refaire le test pour les trois nb_room (min et max)
- $nb_rooms_done = false;
- $url_seo_possible = true;
- /*
- echo "<hr>array = "; var_dump($array)."<br>url_seo_possible = "; var_dump($url_seo_possible); echo "<hr>";
- */
- foreach ($array as $key => $value) {
- switch ($key) {
- case "val_km":
- $rw_data["perim"] = $value;
- break;
- case "ck_property_type" :
- // - Si vous voulez utiliser un seul type de bien,
- // utilisez la fonction searchPropertyTypeIdOrig($id_orig)
- // - Si vous voulez utiliser la valeur par défaut (aucun filtre),
- // n'envoyez pas ck_property_type ou envoyez une valeur nulle
- if (!empty($value)) {
- $value_init = $value;
- // Si c'est un tableau (cf moteur de recherche)
- if (is_array($value)) {
- if (string_contains($value[0], ',')) {
- $array = explode(',', $value[0]);
- unset($value[0]);
- $value = array_merge($value, $array);
- sort($value);
- }
- if ($value[0] != '') {
- $str_property = str_repeat('0', 40); // 40 types de bien possibles (10 octets)
- $do_use_label2 = true; // utilise l'info 'label2' plutôt que 'label' si dispo (coloc)
- foreach ($value as $properties) {
- $value_property_type = getPropretyNameFromId($properties, $rw_data["univ"]);
- //echo "[".$properties."=>".$value_property_type."]";
- $rw_data["property_type"][] = $value_property_type;
- $values = explode(',', $properties);
- foreach ($values as $property) {
- $str_property[intval($property) - 1] = 1;
- }
- }
- }
- // Si un seul numéro est envoyé
- } else if (strlen($value) < 3) {
- $value = (int) $value;
- // rechercher tous les types du groupe contenant ce type
- $str_property = searchPropertyTypeIdOrig($value);
- // Si c'est uen chaine de binaire (40char)
- } else if (strlen($value) == 40) {
- $str_property = $value;
- // construire le tableau $rw_data["property_type"]
- $do_use_label2 = true; // utilise l'info 'label2' plutôt que 'label' si dispo (coloc)
- // echo "\n{VALUE:".print_r($value,true).";";
- for ($i = 0; $i < strlen($value); $i++) {
- if ($value[$i] == 0)
- continue;
- $properties = $value[$i];
- $value_property_type = getPropretyNameFromId($i + 1, $rw_data["univ"]);
- // echo "[".$properties."=>".$value_property_type."]<hr>";
- $rw_data["property_type"][] = $value_property_type;
- }
- // Sinon on utilise toute la chaine
- } else {
- $str_property = $value;
- }
- $rw_data["ck_property_type"] = $str_property;
- //echo "[str_property = $str_property]";
- // dédoublonne les éventuels "property_type"
- if (isset($rw_data["property_type"]) && !empty($rw_data["property_type"])) {
- $rw_data["property_type"] = array_unique($rw_data["property_type"]);
- }
- }
- break;
- case "univers" :
- $rw_data["univers"] = $str_univers[$value];
- break;
- case "loc_name" :
- $values = str_replace($default_locality, "###", $value);
- if (strpos($values, ",")) {
- $loc_names = explode(", ", $values);
- for ($i = 0; $i < count($loc_names);) {
- $locname = trim($loc_names[$i++]);
- $rw_data["loc_name" . $i] = $locname == "###" ? '' : $locname;
- // On rajoute _ apres la ville quand il n'y a pas de code postal
- //INES et SARA 02/09/08
- /* if (strpos($rw_data["loc_name".$i], "_") === false) $rw_data["loc_name".$i] .= "_"; */
- }
- } else {
- $rw_data["loc_name1"] = ($value == $default_locality ? '' : $value);
- /* if (strpos($rw_data["loc_name1"], "_") === false) $rw_data["loc_name1"] .= "_"; */
- }
- break;
- case "loc_key" :
- $rw_data["loc_key"] = $value;
- break;
- case "lockeys" :
- $rw_data["lockeys"] = $value;
- break;
- case "locnames" :
- $rw_data["locnames"] = $value;
- break;
- case "loc_name1" :
- $rw_data["loc_name1"] = $value == $default_locality ? '' : $value;
- /*
- if (strpos($rw_data["loc_name1"], "_") === false) $rw_data["loc_name1"] .= "_";
- */
- if (isset($_REQUEST['post_code']))
- $rw_data["loc_name1"] .= "-" . $_REQUEST['post_code'];
- break;
- case "loc_key1" :
- $rw_data["loc_key1"] = $value;
- break;
- case "loc_name2" :
- $rw_data["loc_name2"] = $value == $default_locality ? '' : $value;
- /*
- if (strpos($rw_data["loc_name2"], "_") === false) $rw_data["loc_name2"] .= "_";
- */
- break;
- case "loc_key2" :
- $rw_data["loc_key2"] = $value;
- break;
- case "loc_name3" :
- $rw_data["loc_name3"] = $value == $default_locality ? '' : $value;
- /*
- if (strpos($rw_data["loc_name3"], "_") === false) $rw_data["loc_name3"] .= "_";
- */
- break;
- case "loc_key3" :
- $rw_data["loc_key3"] = $value;
- break;
- case "loc_name4" :
- $rw_data["loc_name4"] = $value == $default_locality ? '' : $value;
- /*
- if (strpos($rw_data["loc_name4"], "_") === false) $rw_data["loc_name4"] .= "_";
- */
- break;
- case "loc_key4" :
- $rw_data["loc_key4"] = $value;
- break;
- case "agc_loc":
- $rw_data["agc_loc"] = $value;
- break;
- case "offset" :
- $rw_data["offset"] = empty($value) ? 1 : $value;
- break;
- case "price" :
- $rw_data["price"] = ($value != "" ? $value : "a");
- $url_longue = true;
- break;
- case "price_min" :
- case "price_max" :
- if (is_numeric($value) == false)
- $value = 0;
- // Si on a un prix de précisé, pas de redirection vers url seo
- else if ($value != '' && $value > 0)
- $url_seo_possible = false;
- else
- $value = 0;
- $rw_data[$key] = $value;
- $url_longue = true;
- break;
- case "area" :
- $rw_data["area"] = ($value != "" ? $value : "a");
- $url_longue = true;
- break;
- case "area_min" :
- case "area_max" :
- case "surf_min" :
- case "surf_max" :
- if (is_numeric($value) == false)
- $value = 0;
- // Si on a une surface de précisée, pas de redirection vers url seo
- else if ($value != '' && $value > 0)
- $url_seo_possible = false;
- else
- $value = 0;
- $rw_data[$key] = $value;
- $url_longue = true;
- break;
- case "nb_rooms" :
- case "nb_rooms_min" :
- case "nb_rooms_max" :
- if (!$nb_rooms_done) {
- $rw_data["ck_nb_rooms"] = convert_nb_rooms($array['nb_rooms'], $array['nb_rooms_min'], $array['nb_rooms_max']);
- $nb_rooms_done = true;
- $url_longue = true;
- }
- break;
- case 'ck_advanced':
- // Si vous voulez utiliser la valeur par défaut (aucun filtre),
- // n'envoyez pas ck_advanced ou envoyez une valeur nulle
- if (!empty($value) && ($value != '000000000000000000000000000000000000000000000000' || $_REQUEST['seven_days'] > 0 || $_REQUEST['only_old'] > 0)) {
- // Si c'est un tableau (cf moteur de recherche)
- if (is_array($value)) {
- if ($value[0] != '') {
- $str_adv = str_repeat('0', 48); // 48 criteres avancés possibles (9 octets)
- foreach ($value as $crit) {
- $str_adv[intval($crit)] = 1;
- }
- } else
- continue;
- // Si un seul nombre est envoyé
- } elseif (strlen($value) < 3) {
- $value = (int) $value;
- if ($value > 0) {
- $str_adv = str_repeat('0', 48); // 48 criteres avancés possibles (9 octets)
- $str_adv[$value - 1] = 1;
- } else
- continue;
- // Sinon on enregistre toute la chaine
- } else
- $str_adv = $value;
- // Prise en compte du param -7 jours
- if ($_REQUEST['seven_days']) {
- $str_adv[25] = 1;
- }
- // Prise en compte du param seulement dans l ancien
- if ($_REQUEST['only_old']) {
- $str_adv[26] = 1;
- }
- $rw_data['ck_advanced'] = $str_adv;
- $url_longue = true;
- $url_seo_possible = false;
- }
- break;
- case 'dpe':
- // Si vous voulez utiliser la valeur par défaut (aucun filtre),
- // n'envoyez pas dpe ou envoyez une valeur nulle
- if (!empty($value) && ($value != '00000000')) {
- // Si c'est un tableau (cf moteur de recherche)
- if (is_array($value)) {
- if ($value[0] != '') {
- $str_dpe = str_repeat('0', 8); // 8 catégories possibles (2 octets)
- foreach ($value as $dpe) {
- $str_dpe[intval($dpe)] = 1;
- }
- } else
- continue;
- // Si un seul numéro est envoyé
- } elseif (strlen($value) < 2) {
- $value = (int) $value;
- if ($value > 0) {
- $str_dpe[$value - 1] = 1;
- $str_dpe = str_repeat('0', 8); // 8 catégories possibles (2 octets)
- } else
- continue;
- // Sinon on enregistre toute la chaine
- } else
- $str_dpe = $value;
- if (strpos($str_dpe, '1'))
- $url_adv = true;
- $rw_data['dpe'] = $str_dpe;
- $url_longue = true;
- $url_seo_possible = false;
- }
- break;
- case "ck_nb_bedrooms" :
- // Si vous voulez utiliser la valeur par défaut (aucun filtre),
- // n'envoyez pas ck_nb_bedrooms ou envoyez une valeur nulle
- if (!empty($value) && ($value != '00000000')) {
- // Si c'est un tableau (cf moteur de recherche)
- if (is_array($value)) {
- if ($value[0] != '') {
- $str_nb_bedrooms = str_repeat('0', 8); // 8 nombre de chambres possibles (2 octets)
- foreach ($value as $nb_bedroom) {
- $str_nb_bedrooms[intval($nb_bedroom)] = 1;
- }
- } else
- continue;
- // Si un seul numéro est envoyé
- } elseif (strlen($value) < 2) {
- $value = (int) $value;
- if ($value > 0) {
- $str_nb_bedrooms[$value - 1] = 1;
- $str_nb_bedrooms = str_repeat('0', 8); // 8 nombre de chambres possibles (2 octets)
- } else
- continue;
- // Sinon on enregistre toute la chaine
- } else
- $str_nb_bedrooms = $value;
- $rw_data['ck_nb_bedrooms'] = $str_nb_bedrooms;
- $url_longue = true;
- $url_seo_possible = false;
- }
- break;
- case "ck_nb_rooms" :
- // Si vous voulez utiliser la valeur par défaut (aucun filtre),
- // n'envoyez pas ck_nb_rooms ou envoyez une valeur nulle
- if (!empty($value)) {
- // Si c'est un tableau (cf moteur de recherche)
- if (is_array($value)) {
- if ($value[0] != '') {
- $str_nb_rooms = str_repeat('0', 8); // 8 nombre de pieces possibles (2 octets)
- foreach ($value as $nb_room) {
- $str_nb_rooms[intval($nb_room)] = 1;
- }
- } else
- continue;
- // Si un seul numéro est envoyé
- } elseif (strlen($value) < 2) {
- $value = (int) $value;
- if ($value > 0) {
- $str_nb_rooms = str_repeat('0', 8); // 8 nombre de pieces possibles (2 octets)
- $str_nb_rooms[$value - 1] = 1;
- } else
- continue;
- // Sinon on enregistre toute la chaine
- } else
- $str_nb_rooms = $value;
- // Si un nombre de pièces est précisé
- if (($first = strpos($str_nb_rooms, '1')) !== false) {
- $first++;
- // Plusieurs nombres de pièces => Pas d'url SEO.
- if (strpos($str_nb_rooms, '1', $first) !== false) {
- $url_seo_possible = false;
- } else {
- $rw_data['nb_rooms'] = $first;
- }
- }
- $rw_data['ck_nb_rooms'] = $str_nb_rooms;
- $url_longue = true;
- }
- break;
- // Fraicheur des annonces (0 ou nombre+unité)
- case 'fresh':
- if (!empty($value)) {
- if (preg_match('`[1-9][0-9]*[hjsma]`', $value)) {
- $url_adv = true;
- $rw_data['fresh'] = $value;
- } else
- $rw_data['fresh'] = 0;
- $url_longue = true;
- $url_seo_possible = false;
- }
- break;
- case "order_pages" :
- $rw_data["order_pages"] = ($value != "" ? $value : "10");
- $url_longue = true;
- break;
- case "curr" :
- if ($value == "")
- $rw_data["curr"] = $_global["current_currency"];
- else
- $rw_data["curr"] = $value;
- $url_longue = true;
- break;
- case "an_visuel":
- $rw_data['an_visuel'] = ($value != "" ? $value : "0");
- $url_longue = true;
- break;
- case "use_map":
- $rw_data['use_map'] = ($value != "" ? $value : "0");
- $url_longue = true;
- break;
- case "hi_order":
- $rw_data["hi_order_param"] = $value;
- $value = (string) $value;
- if ($value != "") {
- $rw_data['hi_order'] = $value;
- if ($rw_data['hi_order'] != $hi_order_default) {
- $url_seo_possible = false;
- }
- } else {
- $rw_data['hi_order'] = $hi_order_default;
- }
- $url_longue = true;
- break;
- case "with_mmf" :
- // $rw_data["with_mmf"] = ($value != "" ? $value : "0");
- if ($value != "") {
- $rw_data['with_mmf'] = $value;
- $url_seo_possible = false;
- } else {
- $rw_data['with_mmf'] = 0;
- }
- $url_longue = true;
- break;
- case "order" :
- case "ordre" :
- $rw_data["order_param"] = $value;
- // Si c'est un chiffre
- if (preg_match('`[0-9]+`', $value))
- $value = (int) $value;
- else
- $value = $order[$value];
- if (empty($value)) {
- $value = $order_default;
- } else if ($value != $order_default) {
- $url_seo_possible = false;
- }
- $rw_data["order"] = $value;
- $url_longue = true;
- break;
- case "id_agence":
- $rw_data['id_agence'] = strtolower($value);
- break;
- case "xtor" :
- $rw_data["xtor"] = $value;
- break;
- }
- }
- //echo "<hr>rw_data = "; var_dump($rw_data)."<br>url_seo_possible = "; var_dump($url_seo_possible); echo "<hr>";
- // Mini-site agence (annonces d'une agence) --- Url sans recherche (basique)
- // EX: http://www.logic-immo.com/agence-immobiliere/lyon/annonces-immobilier-lyon_69280-0410e82a-b7ae-66cc-8f35-9dbb60302952.html
- if (($target == "recherche_agence_annonce") && (isset($array['no_search']) || !$url_longue)) {
- global $agency;
- $agency['offset'] = $rw_data['offset'];
- $rw = to_nat_agency($agency, $rw_data['univers'], '');
- // Ajout du order si nécessaire // && ($rw_data['order_param'] != 'price')
- if (!empty($rw_data['order_param']))
- $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'order=' . $rw_data['order_param'];
- // Ajout du hi_order si nécessaire // && ($rw_data['hi_order_param'] != '0')
- if ($rw_data['hi_order_param'] != '')
- $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'hi_order=' . $rw_data['hi_order_param'];
- // Ajout du an_visuel si nécessaire
- if (!empty($rw_data['an_visuel']) && ($rw_data['an_visuel'] != '0'))
- $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'an_visuel=' . $rw_data['an_visuel'];
- // Ajouter le xtor
- if (!empty($rw_data['xtor']))
- $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'xtor=' . $rw_data['xtor'];
- //echo "[rw = $rw]<br>";
- return $rw;
- }
- // Convertir la valeur en hexadecimal + Valeur par defaut
- if (empty($rw_data["ck_property_type"]))
- $rw_data["ck_property_type"] = '0000000000';
- else
- $rw_data["ck_property_type"] = stringToHexa($rw_data["ck_property_type"], 10);
- // Convertir la valeur en hexadecimal + Valeur par defaut
- if (empty($rw_data["ck_nb_rooms"]))
- $rw_data["ck_nb_rooms"] = '00';
- else
- $rw_data["ck_nb_rooms"] = stringToHexa($rw_data["ck_nb_rooms"], 2);
- //////////////////////////////////////////////////////////////////
- // Chercher les localités précisées avec un num
- $localities = array();
- for ($i = 0; $i < SEARCH_FIELDS_NUMBER;) {
- //echo "[loc_name".($i+1)."=".$rw_data['loc_name'.($i+1)]."]";
- if (!empty($rw_data['loc_name' . ++$i]))
- $localities[] = $rw_data['loc_name' . $i];
- }
- if (count($localities) == 0) {
- //echo "[locnames"."=".$rw_data['locnames']."]";
- //echo "[loc_name"."=".$rw_data['loc_name']."]";
- // Sinon on recherche d'autres paramètres
- if (!empty($rw_data["locnames"]))
- $localities = $rw_data["locnames"];
- elseif (!empty($rw_data['loc_name']))
- $localities = $rw_data['loc_name'];
- else { // Risque de provoquer une erreur, QUE FAIRE ??
- $localities = '';
- $url_seo_possible = false;
- error_rw_encode('No locality names given', $target, $rw_data);
- }
- }
- //////////////////////////////////////////////////////////////////
- // Chercher les clés de localité précisées avec un num
- $lockeys = array();
- for ($i = 0; $i < SEARCH_FIELDS_NUMBER;) {
- if (!empty($rw_data['loc_key' . ++$i]))
- $lockeys[] = $rw_data['loc_key' . $i];
- }
- if (count($lockeys) == 0) {
- // Sinon on recherche d'autres paramètres
- if (!empty($rw_data["lockeys"]))
- $lockeys = $rw_data["lockeys"];
- elseif (!empty($rw_data['loc_key']))
- $lockeys = $rw_data['loc_key'];
- else { // Risque de provoquer une erreur, QUE FAIRE ??
- $lockeys = '';
- $url_seo_possible = false;
- error_rw_encode('No locality keys given', $target, $rw_data);
- }
- } elseif (count($lockeys) > 1) {
- $url_seo_possible = false;
- }
- // Ne pas generer d'url courtes si plusieurs loc_keys
- if (string_contains($rw_data['lockeys'], ',') && string_contains($rw_data['lockeys'], '_')) {
- $url_seo_possible = false;
- }
- //echo "<pre>ck_property_type = "; print_r($_REQUEST['ck_property_type']); echo "</pre>";
- //echo "<pre>"; print_r($_REQUEST); echo "</pre>";
- //echo "<pre>"; print_r($rw_data); echo "</pre>";
- // Ne pas generer d'url courtes si "avec photos seulement" coché
- if ($_REQUEST['an_visuel'] == 1) {
- $url_seo_possible = false;
- }
- //echo "1. url_seo_possible=".($url_seo_possible?'oui':'non')."\n";
- // Ne pas generer d'url courtes pour : modèle 2 / location / terrain | viager
- if (
- ($rw_data['univ'] == 2) && is_array($rw_data['property_type']) &&
- (((in_array('Terrain', $rw_data['property_type']) || in_array('Viager', $rw_data['property_type']))) && $_global['univers'] != 8 ) &&
- ($rw_data['ck_nb_rooms'] == '00')
- ) {
- $url_seo_possible = false;
- }
- //echo "2. url_seo_possible=".($url_seo_possible?'oui':'non')."\n";
- // Ne pas generer d'url courtes pour : modèle 3 / vente / ferme | bureau | immeuble | parking | terrain | autre
- if (
- ($rw_data['univ'] == 1) && isset($rw_data['property_type']) && is_array($rw_data['property_type']) &&
- (in_array('Ferme', $rw_data['property_type']) || in_array('Bureau / Commerce', $rw_data['property_type']) ||
- in_array('Immeuble', $rw_data['property_type']) || in_array('Parking', $rw_data['property_type']) ||
- in_array('Terrain', $rw_data['property_type']) || in_array('Autre', $rw_data['property_type'])) &&
- ($rw_data['ck_nb_rooms'] != '00')
- ) {
- $url_seo_possible = false;
- }
- //echo "3. url_seo_possible=".($url_seo_possible?'oui':'non')."\n";
- // Ne pas generer d'url courtes pour : modèle 3 / location / ferme | bureau | immeuble | parking | terrain | viager | autre
- if (
- ($rw_data['univ'] == 2) && is_array($rw_data['property_type']) &&
- (in_array('Ferme', $rw_data['property_type']) || in_array('Bureau / Commerce', $rw_data['property_type']) ||
- in_array('Immeuble', $rw_data['property_type']) || in_array('Parking', $rw_data['property_type']) ||
- in_array('Terrain', $rw_data['property_type']) || in_array('Viager', $rw_data['property_type']) || in_array('Autre', $rw_data['property_type'])) &&
- ($rw_data['ck_nb_rooms'] != '00')
- ) {
- $url_seo_possible = false;
- }
- //var_dump($rw_data);
- //var_dump($rw_data['univ']);
- //var_dump($rw_data['property_type']);
- //echo "4. url_seo_possible=".($url_seo_possible?'oui':'non')."\n";
- // W.ASBAITI : Ne pas generer les URLS courtes pour les AEI
- if ($toGDM) {
- $url_seo_possible = false;
- }
- //echo "5. url_seo_possible=".($url_seo_possible?'oui':'non')."\n\n";
- //echo "<hr>rw_data = "; var_dump($rw_data); echo "<br>url_seo_possible = "; var_dump($url_seo_possible); echo "<hr>";
- //exit();
- //////////////////////////////////////////////////////////////////
- if ($target == 'recherche') {
- // Si des localités ont été trouvées
- if (is_array($localities))
- $localities = implode(',', $localities);
- // Si des clés de localité ont été trouvées
- if (is_array($lockeys))
- $lockeys = implode(',', $lockeys);
- /*
- * DESACTIVATION DES REDIRECTIONS VERS SEO
- * DEPUIS LE FORMULAIRE DE LA RECHERCHE AVANCEE
- * => EN ATTENTE DE LA NORMALISATION DES TEMPLATES SEO/CLASSIQUE !!
- */
- //print_r($rw_data);
- // Si on n'a pas fait une recherche avancée, et qu'on n'a qu'une seule localité,
- // on essaye de rediriger vers une url SEO
- if ($url_seo_possible && strpos($locnames, ',') === false) {
- if (isset($rw_data['property_type']) && count($rw_data['property_type']) == 1) {
- $rw_data['property_type'][0] = prepareToUrl($rw_data['property_type'][0]);
- if (isset($rw_data['nb_rooms'])) { // modèle 3
- $infos = array(
- 'is_internal' => 1,
- 'univers' => $rw_data['univ'],
- 'nb_rooms' => $rw_data["nb_rooms"],
- 'property_type' => prepareToUrl($rw_data['property_type'][0]),
- 'loc_name' => $localities,
- 'loc_key' => $lockeys,
- );
- if (isset($rw_data['offset']) && $rw_data['offset'] > 1)
- $infos['offset'] = $rw_data['offset'];
- if (isset($rw_data['post_code']))
- $infos['post_code'] = $rw_data['post_code'];
- $rw = to_nat($infos, 'bien_ville_piece');
- } else { // modèle 2
- $infos = array(
- 'is_internal' => 1,
- 'univers' => $rw_data['univ'],
- 'property_type' => prepareToUrl($rw_data['property_type'][0]),
- 'loc_name' => $localities,
- 'loc_key' => $lockeys,
- 'offset' => $rw_data['offset']
- );
- if (isset($rw_data['offset']) && $rw_data['offset'] > 1)
- $infos['offset'] = $rw_data['offset'];
- /* echo "\n\n\n\n";
- echo "rw_data = "; print_r($rw_data);
- echo "infos = "; print_r($infos);
- echo "url_seo_possible=".($url_seo_possible?'oui':'non');
- echo "\n\n\n\n"; */
- $rw = to_nat($infos, 'bien_ville_liste');
- }
- } elseif (((count($rw_data['property_type']) == 0) && ($rw_data["nb_rooms"] == 0)) || $_global['univers'] == 8) { // modèle 1
- $infos = array(
- 'is_internal' => 1,
- 'univers' => $rw_data['univ'],
- 'loc_name' => $localities,
- 'loc_key' => $lockeys,
- );
- if (isset($rw_data['offset']) && $rw_data['offset'] > 1)
- $infos['offset'] = $rw_data['offset'];
- $rw = to_nat($infos, 'ref_nat');
- }
- //var_dump($rw);
- if ($rw != '') {
- //echo "[rw = $rw]";
- return $rw;
- }
- // Continuer la génération d'une url de recherche avancée
- }
- $locnames = prepareToUrl($localities);
- // Convertir la valeur en hexadecimal + Valeur par defaut
- if (empty($rw_data["ck_nb_bedrooms"]))
- $rw_data["ck_nb_bedrooms"] = '00';
- else
- $rw_data["ck_nb_bedrooms"] = stringToHexa($rw_data["ck_nb_bedrooms"], 2);
- // Convertir la valeur en hexadecimal + Valeur par defaut
- if (empty($rw_data["ck_advanced"]))
- $rw_data["ck_advanced"] = '000000000000';
- else
- $rw_data["ck_advanced"] = stringToHexa($rw_data["ck_advanced"], 12);
- // Convertir la valeur en hexadecimal + Valeur par defaut
- if (empty($rw_data["dpe"]))
- $rw_data["dpe"] = '00';
- else
- $rw_data["dpe"] = stringToHexa($rw_data["dpe"], 2);
- if (empty($rw_data['fresh']))
- $rw_data['fresh'] = 0;
- if (empty($rw_data['offset']))
- $rw_data['offset'] = 1;
- // Début construction URL
- $url = $rw_data["univers"] . '-' . $locnames . ',' . $lockeys . '-';
- $url .= $rw_data["ck_property_type"] . '-';
- //*** DON'T FORGET TO APPLY THE ARRAY CHECK TO ALL PARAMETERS IN CASE OF MULTIBOX SEARCH REQUEST (Michel)
- $url .= $rw_data["price_min"] . ',' . $rw_data["price_max"] . '-';
- $url .= $rw_data["area_min"] . ',' . $rw_data["area_max"] . '-';
- $url .= $rw_data["surf_min"] . ',' . $rw_data["surf_max"] . '-';
- $url .= $rw_data["ck_nb_rooms"] . '-' . $rw_data["ck_nb_bedrooms"] . '-';
- $url .= $rw_data['ck_advanced'] . '-';
- $url .= $rw_data['dpe'] . '-' . $rw_data['fresh'] . '-';
- $url .= '0-'; // FREE (Champ libre, non utilisé pour l'instant)
- $url .= $rw_data['order'] . '-' . $rw_data['hi_order'] . '-'; // Tri
- $url .= $rw_data['an_visuel'] . '-'; // Photo ?
- $url .= $rw_data['offset']; // Numéro de page
- $url = strtolower($url) . '.html';
- // Ajouter le xtor
- if (!empty($rw_data["xtor"]))
- $url .= (strpos($url, '?') !== false ? '&' : '?') . 'xtor=' . $rw_data["xtor"];
- // Fin de la génération des urls de recherche avancées
- //die($url);
- return $url;
- }
- // Si des localités ont été trouvées
- if (is_array($localities))
- $localities = implode('-', $localities);
- $locnames = prepareToUrl($localities);
- // Si des clés de localité ont été trouvées
- if (is_array($lockeys))
- $lockeys = implode('-', $lockeys);
- $rw_url[] = $rw_data["univers"];
- $rw_url['locname'] = $locnames;
- $rw_url[] = $lockeys;
- // Ajouter le type de bien à l'url
- $rw_url[] = $rw_data["ck_property_type"];
- if ($target == "perim")
- $rw_url[] = $rw_data["perim"];
- //$rw_url[] = ($rw_data["offset"] ? $rw_data["offset"] : 0);
- //Modif pour faire commencer les paging à la page 1 ... C'est mieux non ?!
- $rw_url[] = empty($rw_data["offset"]) ? 1 : $rw_data["offset"];
- // Si c'est une url longue, on ajoute les paramètres de recherche
- if ($url_longue == true) {
- //*** DON'T FORGET TO APPLY THE ARRAY CHECK TO ALL PARAMETERS IN CASE OF MULTIBOX SEARCH REQUEST (Michel)
- $rw_url[] = (is_array($rw_data["price"]) ? implode("", $rw_data["price"]) : $rw_data["price"]);
- $rw_url[] = (is_array($rw_data["price_min"]) ? implode("", $rw_data["price_min"]) : $rw_data["price_min"]);
- $rw_url[] = (is_array($rw_data["price_max"]) ? implode("", $rw_data["price_max"]) : $rw_data["price_max"]);
- $rw_url[] = (is_array($rw_data["area"]) ? implode("", $rw_data["area"]) : $rw_data["area"]);
- $rw_url[] = (is_array($rw_data["area_min"]) ? implode("", $rw_data["area_min"]) : $rw_data["area_min"]);
- $rw_url[] = (is_array($rw_data["area_max"]) ? implode("", $rw_data["area_max"]) : $rw_data["area_max"]);
- $rw_url[] = $rw_data["ck_nb_rooms"];
- $rw_url[] = $rw_data['order'];
- $rw_url[] = $rw_data['an_visuel'];
- $rw_url[] = $rw_data['hi_order'];
- if ($rw_data['use_map'] != "")
- $rw_url[] = $rw_data['use_map'];
- }
- // Mini-site agence (annonces d'une agence) --- Url avec recherche (depuis formulaire à droite)
- // 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
- if ($target == "recherche_agence_annonce") {
- global $agency;
- if (!empty($rw_data["agc_loc"]))
- $locality = prepareToUrl($rw_data['agc_loc']);
- elseif (!empty($agency['town_agency']))
- $locality = prepareToUrl($agency['town_agency']);
- else
- $locality = prepareToUrl($locnames);
- if (empty($rw_url['locname']))
- $rw_url['locname'] = $locality;
- $rw = $dns . "agence-immobiliere/" . $locality . '/' . implode("-", $rw_url) . '-' . $rw_data['id_agence'] . ".htm";
- } else {
- // Par defaut on joint toutes les valeurs de $rw_url
- // Dans l'ordre où elles ont été ajoutées.
- $rw = $dns . implode("-", $rw_url) . ".htm";
- }
- } else {
- // Récupérer le type de transaction
- if ($array['type_transaction'] == 2 || (!isset($array['type_transaction']) && $array['univers']==2))
- $trans = 'location';
- else if ($array['type_transaction'] == 8 || (!isset($array['type_transaction']) && $array['univers']==8))
- $trans = 'colocation';
- else
- $trans = 'vente';
- if ($target == "detail") {
- if (empty($array["id"])) {
- // Enregistrer l'erreur de génération
- error_rw_encode('No announce identifier given', $target, $array);
- if (isset($array['req_internal']))
- return '';
- }
- $rw = 'detail-' . $trans . '-' . $array['id'] . ".htm";
- }else if ($target == "ref_nat") { // ie URLs courtes modèle 1
- $offset = empty($array["offset"]) || $array["offset"] < 2 ? '' : '-' . $array["offset"];
- if (empty($array["loc_name"]) || empty($array["loc_key"])) {
- // Enregistrer l'erreur de génération
- error_rw_encode('Invalid locality', $target, $array);
- if (isset($array['req_internal']))
- return '';
- }
- $locname = prepareToUrl($array["loc_name"]);
- $lockey = $array['loc_key'];
- if ($array['univers'] == 2) $univers = 'annonces-location';
- else if ($array['univers'] == 8) $univers = 'annonces-colocation';
- else $univers = 'annonces-immobilier';
- $rw = "{$univers}-{$locname}-{$lockey}{$offset}.html";
- }
- else if ($target == 'bien_ville_piece') { // ie URLs courtes modèle 3
- // => appartement-toulouse/vente-appartement-toulouse/appartement-3-pieces-toulouse-31000-393_99.html
- // => maison-villa-aix-en-provence/colocation-maison-villa-aix-en-provence/maison-villa-2-chambres-aix-en-provence-13100-36129_2.html
- // Renvoyer une 404 si une information est manquante
- if (empty($array['nb_rooms']) || empty($array['property_type']) || empty($array['loc_name']) || empty($array['loc_key'])) {
- // Enregistrer l'erreur de génération
- error_rw_encode('Missing variable', $target, $array);
- if (isset($array['req_internal']))
- return '';
- }
- // Renvoyer une 404 si le type n'est pas une chaine ou si on a plusieurs pieces/chambres
- if (is_numeric($array['property_type']) || strlen($array['nb_rooms']) > 1) {
- // Enregistrer l'erreur de génération
- error_rw_encode('Invalid value given', $target, $array);
- if (isset($array['req_internal']))
- return '';
- }
- if ($_global['univers'] == 8) {
- $wordPiece = 'chambre';
- } else { // 1 || 2
- $wordPiece = 'piece';
- }
- $strPieces = $array['nb_rooms'] . '-' . $wordPiece;
- if ($array['nb_rooms'] > 1)
- $strPieces .= 's';
- $lockey = $array['loc_key'];
- $locality = prepareToUrl($array['loc_name']);
- //echo "[locality=$locality , matches=$matches]";
- // Vérifier la localité
- if ($lockey == '100_1') {
- $locname = 'paris';
- $locality = 'paris-75';
- } 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)) {
- // Enregistrer l'erreur de génération
- error_rw_encode('', $target, $array);
- if (isset($array['req_internal']))
- return '';
- $locname = $locality;
- } else
- $locname = $matches[1]; // Ville sans CP
- $propertyType = $array['property_type'];
- if ($array['offset'] > 1)
- $offset = '-' . $array['offset'];
- else
- $offset = '';
- // Remplacer appartement 1 pièce par studio pour vente/location
- if ((($_global['univers'] == 1) || ($_global['univers'] == 2)) && ($propertyType == 'appartement') && ($strPieces == '1-piece')) {
- $rw = "studio-{$locname}/{$str_univers[$_global['univers']]}-studio-{$locality}-{$lockey}$offset.html";
- } else {
- $rw = "{$propertyType}-{$locname}/{$str_univers[$_global['univers']]}-{$propertyType}-{$locname}/{$propertyType}-{$strPieces}-{$locality}-{$lockey}$offset.html";
- }
- } else if ($target == 'bien_ville_liste') { // ie URLs courtes modèle 2
- // => appartement-toulouse/vente-appartement-toulouse-31000-393_99.html
- // Renvoyer une 404 si une information est manquante
- if (empty($array['property_type']) || empty($array['loc_name']) || empty($array['loc_key'])) {
- // Enregistrer l'erreur de génération
- error_rw_encode('Missing variable', $target, $array);
- if (isset($array['req_internal']))
- return '';
- }
- // Renvoyer une 404 si le type n'est pas une chaine ou si on a plusieurs pieces
- if (is_numeric($array['property_type'])) {
- // Enregistrer l'erreur de génération
- error_rw_encode('Invalid value given', $target, $array);
- if (isset($array['req_internal']))
- return '';
- }
- $lockey = $array['loc_key'];
- $locality = prepareToUrl($array['loc_name']);
- //echo "[$locality]"; //exit;
- // Vérifier la localité
- if ($lockey == '100_1') {
- $locname = 'paris';
- $locality = 'paris-75';
- } 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)) {
- // Enregistrer l'erreur de génération
- error_rw_encode('Invalid locality given', $target, $array);
- if (isset($array['req_internal']))
- return '';
- $locname = $locality;
- } else {
- $locname = $matches[1]; // Ville sans CP
- }
- $propertyType = $array['property_type'];
- if ($array['offset'] > 1)
- $offset = '-' . $array['offset'];
- else
- $offset = '';
-
- if ($array['univers'] == 2) $univers = 'location';
- else if ($array['univers'] == 8) $univers = 'colocation';
- else $univers = 'vente';
- $rw = "{$propertyType}-{$locname}/{$univers}-{$propertyType}-{$locality}-{$lockey}$offset.html";
- }
- else if ($target == "confier_detail") {
- if (empty($array["id"])) {
- // Enregistrer l'erreur de génération
- error_rw_encode('No announce identifier given', $target, $array);
- return '';
- }
- $rw = 'detail_confier_' . $univers . '-' . $array['id'] . ".htm";
- } else if ($target == "recherche_agence") {
- $rw = "/agence-immobiliere-";
- $str_offset = "";
- $str_order = "";
- foreach ($array as $key => $value) {
- if ($key == "loc_key" || $key == "loc_key1") {
- $str_loc_key = $value;
- } else if ($key == "loc_name") {
- $str_agency = clean_agency($value);
- $str_city = $str_agency['ville'];
- $str_code_post = substr($str_agency['cp'], 0, 2);
- //vérifie si str_code est alphanumerique, auquel cas c'est un "TOUTE LOCATION"
- if (is_numeric($str_code_post)) {
- $glue = "-";
- $str_code_post = str_replace(" ", "%20", $str_agency['cp']);
- } else {
- $glue = "-";
- $str_code_post = str_replace(" ", "+", $str_agency['cp']);
- }
- } else if ($key == "order" && $value == "name") {
- $str_order = "-abc";
- } else if ($key == "offset") { // && $value != "")
- $str_offset = ($value == "" || $value == 0 || $value == 1 ? "" : "-" . $value);
- }
- }
- if ($str_code_post) {
- $rw .= $str_loc_key . "-" . $str_city . $glue . $str_code_post . $str_offset;
- } else {
- $rw .= $str_city . "-" . $str_loc_key . $str_order . $str_offset;
- }
- $rw .= ".php";
-
- }
- }
- if ($target == "recherche_agence") {
- $rw = "/agence-immobiliere-";
- $str_offset = "";
- $str_order = "";
- $glue = "-";
- foreach ($array as $key => $value) {
- if ($key == 'lockeys') {
- $str_loc_key = $value;
-
- } else if ($key == 'locnames') {
- $alocnames = explode(",", $value);
- ///var_dump($alocnames);exit();
- if (count($alocnames) > 1) {
- //Multilocalité
- $glue = ",";
- } else {
- $glue = "-";
- }
- $str_agency = clean_agency($value);
- $str_city = $str_agency['ville'];
- $str_code_post = substr($str_agency['cp'], 0, 2);
- //vérifie si str_code est alphanumerique, auquel cas c'est un "TOUTE LOCATION"
- if (is_numeric($str_code_post)) {
- $str_code_post = str_replace(" ", "%20", $str_agency['cp']);
- } else {
- $str_code_post = str_replace(" ", "+", $str_agency['cp']);
- }
- } else if ($key == "loc_key" || $key == "loc_key1") {
- $str_loc_key = $value;
- } else if ($key == "loc_name") {
- $str_agency = clean_agency($value);
- $str_city = $str_agency['ville'];
- $str_code_post = substr($str_agency['cp'], 0, 2);
- //vérifie si str_code est alphanumerique, auquel cas c'est un "TOUTE LOCATION"
- if (is_numeric($str_code_post)) {
- $str_code_post = str_replace(" ", "%20", $str_agency['cp']);
- } else {
- $str_code_post = str_replace(" ", "+", $str_agency['cp']);
- }
- } else if ($key == "order" && $value == "name") {
- $str_order = "-abc";
- } else if ($key == "offset") { // && $value != "")
- $str_offset = ($value == "" || $value == 0 || $value == 1 ? "" : "-" . $value);
- }
- }
- if ($str_code_post) {
- $rw .= $str_loc_key . $glue . $str_city . $glue . $str_code_post . $str_offset;
- } else {
- $rw .= $str_city . $glue . $str_loc_key . $str_order . $str_offset;
- }
- $rw .= ".php";
- }
- $rw = strtolower($rw);
- // Ajouter le xtor
- if (!empty($rw_data["xtor"]))
- $rw .= (strpos($rw, '?') !== false ? '&' : '?') . 'xtor=' . $rw_data["xtor"];
- //echo "[rw = $rw]";
- //echo "[rw = $rw]";
- //echo "[rw = $rw]";
- return $rw;
- }
- //
- function clean_agency($str) {
- $str = explode(" (", $str);
- $ville = prepareToUrl($str[0]);
- $cp = str_replace(")", "", $str[1]);
- $string['ville'] = $ville;
- $string['cp'] = $cp;
- return $string;
- }
- // Fonction utilisée pour la pagination classique (sans recherche)
- function to_nat_agency($agency, $univers = 'annonces-immobilier', $dns = '/') {
- /*
- echo "<hr><pre>";
- echo "[agency = ".print_r($agency, true)."]";
- echo "[univers = ".$univers."]";
- echo "[univers = ".$dns."]";
- echo "</pre><hr>";
- */
- $lzip = str_replace(' ', '', $agency['lzip']);
- $agency['town'] = str_replace('\\', '', $agency['town']);
- // Trouver le nom de la ville de manière gracieuse et le loc_id associé
- if (!empty($agency['town']) && ($agency['town'] != '-')) {
- $town_agency = $agency['town'];
- } else if (!empty($agency['town_agency']) && ($agency['town_agency'] != '-')) {
- $town_agency = $agency['town_agency'];
- } else if (!empty($agency['hierarchy'])) {
- $hierarchy = $agency['hierarchy'];
- if (!empty($hierarchy[2]['lct_name'])) {
- $town_agency = $hierarchy[2]['lct_name'];
- $lzip = $hierarchy[2]['lct_id'];
- } else if (!empty($hierarchy[1]['lct_name'])) {
- $town_agency = $hierarchy[1]['lct_name'];
- $lzip = $hierarchy[1]['lct_id'];
- } else {
- $town_agency = $hierarchy[0]['lct_name'];
- $lzip = $hierarchy[0]['lct_id'];
- }
- //
- if ((empty($town_agency) || ($town_agency == '-')) && !empty($hierarchy[2]['lct_id'])) {
- $sql = "
- SELECT lct_id, lct_parent_id, lct_level, lct_name, lct_name_fr, lct_post_code
- FROM TM_LOC_FR
- WHERE lct_id = '" . $hierarchy[2]['lct_id'] . "'
- ";
- //echo $sql;
- $res = pdoquery($sql);
- if (count($res) > 0) {
- $town_agency = $res[0]["lct_name_fr"];
- $lzip = $res[0]["lct_id"];
- }
- }
- // On retourne une chaine vide car de toute façon,
- // l'url générée sera invalide (pas de localité)
- } else {
- error_rw_encode('Could not find a valid locality', 'to_nat_agency', array('agency_infos' => $agency, 'univers' => $univers));
- return '';
- }
- $town_agency = prepareToUrl($town_agency, true);
- $rw = $dns . 'agence-immobiliere/' . $town_agency;
- $rw .= '/' . $univers . '-' . $town_agency . '_' . $lzip . "-" . strtolower($agency['id']);
- if (isset($agency['offset']) && $agency['offset'] > 1)
- $rw .= '-' . $agency['offset'];
- if (isset($agency['order']) && !empty($agency['order']))
- $rw .= '?order=' . $agency['order'];
- $rw .= ".html";
- if ($dns == '/') {
- $rw = to_url($rw);
- }
- //echo "[rw = $rw]";
- return $rw;
- }
- ?>