PageRenderTime 69ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/DEV/LIB/common.functions.php

https://github.com/chrisbst35/LI_LEMONDE
PHP | 7552 lines | 4863 code | 1106 blank | 1583 comment | 1286 complexity | 3fb67c2dde3df8b70cd34cfe9e5886d9 MD5 | raw file

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

  1. <?php
  2. $test = include('/data/apache/CONF_URL/conf.php');
  3. if (!$test)
  4. require('/data/apache/CONF_URL/prod.conf.php');
  5. //bandeaux personnalisables
  6. //include(realpath(dirname(__FILE__) . "/../DATA/bandeaux/libelles_bandeaux.php"));
  7. global $_global;
  8. //##############################################################################
  9. //# Définition des constantes fonctionnelles
  10. // Répertoire dans lequel les fichiers generes par les scripts des crons sont enregistres
  11. define('URL_DATA', '/data/apache/DATA/');
  12. // Appel depuis un script => Pas de DOCUMENT_ROOT !!!
  13. //$display = rtrim($_SERVER['DOCUMENT_ROOT'],'/');
  14. $display = realpath(dirname(__FILE__) . '/../DISPLAY');
  15. $root = dirname($display);
  16. // Gérer les document root de Orange (et autres), qui ont DISPLAY
  17. // directement à la racine !!
  18. if (substr($root, -4) == '/DEV')
  19. $root = dirname($root);
  20. define('ROOT_PATH', $root); // ex: /data/apache/www/www.logic-immo.com
  21. define('DISPLAY_PATH', $display); // ex: /data/apache/www/www.logic-immo.com/DEV/DISPLAY
  22. // Répertoire dans lequel les librairies (fonctions, classes) sont enregistrees
  23. $current_lib_dir = dirname(__FILE__);
  24. // PB : Si la constante a déjà été définie dans une autre page !!
  25. if (defined('URL_LIB')) {
  26. // Simuler une erreur fatale pour qu'on recoive un mail en cas de problème
  27. error_log("FATAL ERROR - La constante URL_LIB a deja ete definie ! (VALEUR:" . URL_LIB . ")");
  28. // Enregistrer le backtrace dans le fichier de log
  29. ob_start() or exit();
  30. debug_print_backtrace();
  31. $content = ob_get_contents();
  32. error_log($content);
  33. ob_end_clean();
  34. } else {
  35. define('URL_LIB', $current_lib_dir); // ex: /data/apache/www/www.logic-immo.com/DEV/LIB
  36. }
  37. //##############################################################################
  38. //# Chargement de la configuration par environnement
  39. // Récupérer le chemin du fichier de conf
  40. $conf_file = ROOT_PATH . '/CONF/conf.php';
  41. $test = include($conf_file);
  42. // Gestion en cas de configuration introuvable
  43. if (!$test) {
  44. // Utiliser la configuration de production
  45. $test = include(ROOT_PATH . '/CONF/prodA.conf.php');
  46. if (!$test) {
  47. // Simuler une erreur fatale pour qu'on recoive un mail en cas de problème
  48. error_log("FATAL ERROR - Le fichier de configuration `{$conf_file}` n\'a pas ete trouve. (DOCUMENT_ROOT:{$_SERVER['DOCUMENT_ROOT']})");
  49. // Enregistrer le backtrace dans le fichier de log
  50. ob_start() or exit();
  51. debug_print_backtrace();
  52. $content = ob_get_contents();
  53. error_log($content);
  54. ob_end_clean();
  55. // Ne pas plus faire de traitement avec des constantes manquantes !
  56. exit();
  57. }
  58. }
  59. //##############################################################################
  60. //# Inclure les librairies relatives à MMF
  61. include_once(URL_LIB . '/mmf.constants.php');
  62. include_once(URL_LIB . '/mmf.functions.php');
  63. //##############################################################################
  64. //##
  65. //## direct_hit($ip) -- returns true if url hits a frontal server
  66. //## add_parameters($url, $site = "", $lang = "", $univers = "") -- returns an url along with the environment parameters
  67. //## add_parameter($url, $parameter, $value) -- returns an url along with a parameter and value
  68. //## del_parameter($url, $parameter) -- returns an url without a parameter
  69. //## get_all_summary_cz($data) -- returns an array of human readable values, translated from search criteria (CZ)
  70. //## get_all_summary($data,$showIfAllChecked) -- returns an array of human readable values, translated from search criteria
  71. //## get_adv_summary($data,$extended,$showIfAllChecked) -- return an array of human readable values from advanced criterias
  72. //## get_summary($data, $parameters, $item, $label_all, $label_unit) -- turns a search criterion to a human readable value
  73. //## get_property_type_label($id) -- returns property type label depending on the code
  74. //## n_f($value) -- number_format shortcut
  75. //## currency_format($value, $from, $to, $add_currency_name = true) -- currency conversion
  76. //## sosex($input, $partial = false) -- Function so sex, par le so sexy oxman, da crazy man !
  77. //## str_limit($value, $limit) -- returns a truncated string
  78. //## remove_returns($value) -- returns a clean string
  79. //## resize_image($img, $max_width, $max_height) -- returns html height and width properties, determining the size of an image to fit required width and height
  80. //## spacer($height, $width) -- returns html code for a spacer
  81. //## set_html_title($value) -- returns html alt and title
  82. //##
  83. //## get_ad_data($page, $value, $has_premium = 0, $url = "", $idx = -1) -- returns ad and agency data
  84. //## get_ag_data($page, $value) -- returns agency data
  85. //## get_pub_data($value, $key) -- returns pub data
  86. //## get_mmf_type($label) -- returns mmf type index
  87. //##
  88. //## format_phone($value, $country = "FR") -- returns formatted number
  89. //## get_parameter_index($name, $value) -- returns parameter index
  90. //## is_guid($value) -- returns true if value is a guid
  91. //## back_to_list($page) -- returns "back to list" url
  92. //## build_search_url($page, $parameters) -- returns a search url
  93. //## from_page($previous_url, $page) -- returns true if page comes from Mars
  94. //## is_external() -- returns true if is external
  95. //## is_ref_page($page) -- returns true if is a ref page
  96. //## get_zip_code($data, $mode) -- returns szip / lzip
  97. //## writeLockFile($sLockFileName, $sLockFileDescription) --
  98. //## getLockFile($sLockFileName) --
  99. //## checkLockFile($sLockFileName) -- xx
  100. //## removeLockFile($sLockFileName) --
  101. //## truncate($chaine, $length = 50) -- Tronque un texte (mais pas les mots !) si trop long et rajoute des points de suspension
  102. //## loc2xiti($k1,$n1,$k2,$n2) --
  103. //## format_footer_link($str) --
  104. //## generateMd5MaintenanceString($iOperationCode, $sPreSharedKey) --
  105. //## checkSha1MaintenanceString($sPreSharedKey, $iOperationCode, $aOperationArray, $sKeyString) --
  106. //## redirection($url) -- Gere la presence des headers
  107. //## verif_cookie_prehome -- Gestion de la revisite Belge (modifiable pour les autres Pays)
  108. //## pub_relais_neuf_cookie($val_relais) -- Verification les nombres de refresh
  109. //## Verif_Url_BE() -- verifier la syntax de l'URL pour le site BE
  110. //## Get_Lockey_By_Name_Level($name, $level=1, $site="xx", $lang="xx") -- Retrouve le Loc_key en fonction d'un name et d'un level
  111. //## Get_Trad_Locname ($lockey, $lang) -- Retrouve la traduction d'un nom de Locname en fonction d'un LCT_ID et d'une Langue
  112. //## TextNoAccent($string) -- Supprime les accents d'une chaine
  113. //## => Déprécié : Regarder la fonction prepareToUrl($string)
  114. //##
  115. //## check_detail_exist -- Vérifie si il existe des détail spécifique sur une annonce
  116. //## create_block_nosearch($title)
  117. //## no_magic_quote() -- pour eviter les injection S-K-UL
  118. //## uc_strtoupper_fr($chaine) -- Amélioration du strtoupper de PHP pour gérer les accents
  119. //##
  120. //## getLocalityLabel($search_parameters,$num) -- Renvoyer la localite selon le level ("tous codes" ...)
  121. //## stringToHexa($string,$size) -- Convertir la chaine de 0 et 1 en hexa
  122. //## hexaToString($string,$size) -- Convertir la chaine hexa en 0 et 1
  123. //##
  124. //## searchPropertyTypeIdOrig($id_orig,$get_group) -- Récupérer le groupe ou la chaine de 40bits (par défaut)
  125. //## searchPropertyTypeIdOrigAdv($id_orig,$get_group) -- Récupérer le groupe ou la chaine de 40bits (par défaut)
  126. //## => Utilise les nouveaux groupes (plus nombreux et quasi unitaires)
  127. //##
  128. //##############################################################################
  129. //
  130. //
  131. // 20080820-XI $ad["default_sector"] should not be displayed if $ad["default_town"]==$ad["default_sector"]
  132. // 20090401-1-XI, Retrieving xxx_locality_2_agency field (mantis 5342)
  133. // 20090407-1-XI, Setting agc loc of ads to 0 if id_presto='CMM-PT-BDL-EXPRESSO'
  134. // 20090410-1-XI, Retrieving xxx_tel2_agency
  135. // 20090610-1-XI, NOT Setting agc loc of ads to 0 if id_presto='CMM-PT-BDL-EXPRESSO', mantis 5865
  136. //
  137. //##############################################################################
  138. function open_file(&$filepath, $requestType = '', $mode = 'a', $backupFolder = TRAPPED_WRITE_ERROR) {
  139. // Enregistrer la statistique dans le csv
  140. $fp = @fopen($filepath, 'a');
  141. if ($fp === false) {
  142. error_log('FATAL ERROR - Could not open file `' . $filepath . '` to save "' . $requestType . '" request !');
  143. // Utiliser le dossier de secours pour ne pas perdre les demandes
  144. $filepath = $backupFolder . $requestType . '/' . basename($filepath);
  145. // Enregistrer la statistique dans le csv
  146. $fp = @fopen($filepath, 'a');
  147. if ($fp === false) {
  148. error_log('FATAL ERROR - Could not open file `' . $filepath . '` to save "' . $requestType . '" request !');
  149. }
  150. }
  151. return $fp;
  152. }
  153. /**
  154. * Returns true if url hits a frontal server
  155. *
  156. * @param unknown_type $ip
  157. * @return unknown
  158. */
  159. function direct_hit($ip) {
  160. global $_prodServers;
  161. return in_array($ip, $_prodServers);
  162. }
  163. /**
  164. * Returns an url along with the environment parameters
  165. *
  166. * @param unknown_type $url
  167. * @param unknown_type $site
  168. * @param unknown_type $lang
  169. * @param unknown_type $univers
  170. * @return unknown
  171. */
  172. function add_parameters($url, $site = "", $lang = "", $univers = "") {
  173. global $_global;
  174. // default values
  175. $site = ($site == "" ? $_global["site"] : $site);
  176. $lang = ($lang == "" ? $_global["lang"] : $lang);
  177. $univers = ($univers == "" ? $_global["univers"] : $univers);
  178. // sets url parameters into an array
  179. $tmp = explode("?", $url);
  180. parse_str($tmp[1], $url_parameters);
  181. // adds site parameter
  182. if (!array_key_exists("site", $url_parameters)) {
  183. $add_parameters["site"] = $site;
  184. } else {
  185. $url_parameters["site"] = $site;
  186. }
  187. // adds universe parameter
  188. if (!array_key_exists("univers", $url_parameters)) {
  189. $add_parameters["univers"] = $univers;
  190. } else {
  191. $url_parameters["univers"] = $univers;
  192. }
  193. // adds language parameter
  194. if (!array_key_exists("lang", $url_parameters)) {
  195. $add_parameters["lang"] = $lang;
  196. } else {
  197. $url_parameters["lang"] = $lang;
  198. }
  199. // merges parameters
  200. if (is_array($add_parameters)) {
  201. $url_parameters = array_merge($add_parameters, $url_parameters);
  202. }
  203. // concatenates
  204. $url = $tmp[0] . "?" . http_build_query($url_parameters);
  205. switch ($_global["site"]) {
  206. case "be":
  207. if (strpos($url, "http:") === false) {
  208. $url = "/" . $lang . "/" . $url;
  209. $url = str_replace("//", "/", $url);
  210. }
  211. break;
  212. default:
  213. break;
  214. }
  215. // returns
  216. return $url;
  217. }
  218. /**
  219. * Returns an url along with a parameter and value
  220. *
  221. * @param unknown_type $url
  222. * @param unknown_type $parameter
  223. * @param unknown_type $value
  224. * @return unknown
  225. */
  226. function add_parameter($url, $parameter, $value) {
  227. // sets url parameters into an array
  228. $tmp = explode("?", $url);
  229. parse_str($tmp[1], $url_parameters);
  230. if (!array_key_exists($parameter, $url_parameters)) {
  231. $url_parameters[$parameter] = $value;
  232. // concatenates
  233. $url = $tmp[0] . "?" . http_build_query($url_parameters);
  234. }
  235. // returns
  236. return $url;
  237. }
  238. /**
  239. * Returns an url without a parameter
  240. *
  241. * @param unknown_type $url
  242. * @param unknown_type $parameter
  243. * @return unknown
  244. */
  245. function del_parameter($url, $parameter) {
  246. // sets url parameters into an array
  247. $tmp = explode("?", $url);
  248. parse_str($tmp[1], $url_parameters);
  249. if (array_key_exists($parameter, $url_parameters)) {
  250. unset($url_parameters[$parameter]);
  251. // concatenates
  252. $url = $tmp[0] . "?" . http_build_query($url_parameters);
  253. }
  254. // returns
  255. return $url;
  256. }
  257. /**
  258. * Returns an array of human readable values, translated from search criteria
  259. *
  260. * @param Array $data
  261. * @param Boolean $showIfAllChecked List all values (1,2,...) if all checked ?
  262. * @param Boolean $useAdvancedGroups Utiliser les groupes de types de bien avancés (plus nombreux)
  263. * @return unknown
  264. */
  265. function get_all_summary($data, $showIfAllChecked = true, $useAdvancedGroups = false) {
  266. global $_global;
  267. // summary table
  268. $summary = array();
  269. // vacances
  270. if ($_global["univers"] == 13) {
  271. // globals
  272. global $_LI_BEDROOMS;
  273. global $_LI_PEOPLE;
  274. // load values
  275. $parameters = array();
  276. $parameters["nb_bedrooms"] = $_LI_BEDROOMS;
  277. $parameters["nb_people"] = $_LI_PEOPLE;
  278. // univers
  279. $summary["univers"] = LABEL_COMMON_UNIVERSE_13;
  280. // localisation
  281. $summary["loc_name"] = $data["loc_name"];
  282. // property types
  283. if ($data["property_type"] == "" || $data["property_type"][0] == -1 || count($data["property_type"]) == 8) {
  284. $summary["property_type"] = LABEL_ALL_PROPERTY_TYPE;
  285. } else {
  286. for ($i = 0; $i < count($data["property_type"]); $i++) {
  287. $data["property_type"][$i] = constant("LABEL_COMMON_PROPERTY_" . $data["property_type"][$i]);
  288. }
  289. $summary["property_type"] = implode(", ", $data["property_type"]);
  290. }
  291. // bedrooms
  292. $summary["nb_bedrooms"] = get_summary($data, $parameters["nb_bedrooms"], "nb_bedrooms", LABEL_ALL_BEDROOMS, LABEL_COMMON_BEDROOMS_UNIT);
  293. // people
  294. $summary["nb_people"] = get_summary($data, $parameters["nb_people"], "nb_people", LABEL_ALL_PEOPLE, LABEL_COMMON_PEOPLE_UNIT);
  295. } else {
  296. // globals
  297. global $_LI_PRICERANGE;
  298. global $_LI_ADSURFACE;
  299. global $_LI_ROOMS;
  300. // load values
  301. $parameters = array();
  302. $parameters["area"] = $_LI_ADSURFACE;
  303. $parameters["price"] = $_LI_PRICERANGE;
  304. $parameters["nb_rooms"] = $_LI_ROOMS;
  305. // univers
  306. if ($data["univers"] == 2) { // location
  307. $summary["univers"] = LABEL_COMMON_UNIVERSE_2;
  308. } else if ($data["univers"] == 8) { // colocation
  309. $summary["univers"] = LABEL_COMMON_UNIVERSE_8;
  310. } else { // vente
  311. $summary["univers"] = LABEL_COMMON_UNIVERSE_1;
  312. }
  313. $loc_names = array();
  314. if (isset($data['is_from_cookie'])) {
  315. for ($i = 1; $i < 4; $i++) {
  316. if (isset($data['loc_name' . $i]) && ($locname = $data['loc_name' . $i]) != '' && $locname != LABEL_DEFAULT_LOCALITY) {
  317. $loc_names[] = ucwords2(strtolower($data['loc_name1']));
  318. }
  319. $locname = implode(', ', $loc_names);
  320. }
  321. } else {
  322. // localisation
  323. $loc_name = getLocalityLabel($data, 0);
  324. if ($loc_name != LABEL_DEFAULT_LOCALITY)
  325. $loc_names[] = ucwords2(strtolower($loc_name));
  326. $loc_name = getLocalityLabel($data, 1);
  327. if ($loc_name != LABEL_DEFAULT_LOCALITY)
  328. $loc_names[] = ucwords2(strtolower($loc_name));
  329. $loc_name = getLocalityLabel($data, 2);
  330. if ($loc_name != LABEL_DEFAULT_LOCALITY)
  331. $loc_names[] = ucwords2(strtolower($loc_name));
  332. if ($loc_names == array()) {
  333. $locname = ucwords2(strtolower($data["loc_name"]));
  334. // Ajouter manuellement les parentheses autour des codes postaux
  335. // En veillant à ne pas les doubler si déjà présentes
  336. $locname = preg_replace('`\(?([0-9]{3,})\)?`', '($1)', $locname);
  337. }
  338. else
  339. $locname = implode(', ', $loc_names);
  340. // Remplacer les -+_ par un espace
  341. $locname = strtr($locname, array('-' => ' ', '+' => ' ', '_' => ' '));
  342. // Mettre la chaine tous codes postaux entre parentheses
  343. $locname = str_ireplace('TOUS CODES POSTAUX', '(Tous codes postaux)', $locname);
  344. // Séparer les parentheses avec une virgule
  345. $locname = str_replace(') ', '), ', $locname);
  346. // Ajouter les apostrophes devant les L et le D
  347. $locname = preg_replace('`\b(L|D) `i', '$1\'', $locname);
  348. }
  349. // Ajout la valeur de localité
  350. if ($locname != '')
  351. $summary["loc_name"] = $locname;
  352. // property types
  353. if (isset($data["ck_property_type"])) {
  354. $property_type = $data['ck_property_type'];
  355. // Si champ vide, ou aucun coché
  356. if (empty($property_type) || strpos($property_type, '1') === false) {
  357. $summary["property_type"] = LABEL_ALL_PROPERTY_TYPE;
  358. // Sinon on liste tous les types de biens
  359. } elseif (SUMMARY_LIST_PROPERTY_TYPES) {
  360. $size = strlen($property_type);
  361. $str_property_type = '';
  362. /*
  363. for($i=0; $i<$size; $i++) {
  364. if( $property_type[$i]=='1' ) $str_property_type .= ', '.constant("LABEL_COMMON_PROPERTY_ID_".($i+1));
  365. }
  366. */
  367. $pos = -1;
  368. while (($pos = strpos($string, '1', $pos + 1)) !== false) {
  369. $str_property_type .= ', ' . constant("LABEL_COMMON_PROPERTY_ID_" . ($pos + 1));
  370. }
  371. $summary["property_type"] = substr($str_property_type, 2);
  372. // Sinon on liste les groupes de biens
  373. } else {
  374. if ($useAdvancedGroups) {
  375. global $_ADVANCED_SEARCH_TYPES, $_MASK_REALESTATETYPES_ALL_CHECKED;
  376. $checkedLabels = getCheckedFields($_ADVANCED_SEARCH_TYPES, $property_type, $_MASK_REALESTATETYPES_ALL_CHECKED, true);
  377. } else {
  378. global $_LI_REALESTATEGROUPS, $_MASK_REALESTATETYPES_ALL_CHECKED;
  379. $checkedLabels = getCheckedFields($_LI_REALESTATEGROUPS, $property_type, $_MASK_REALESTATETYPES_ALL_CHECKED, true);
  380. }
  381. // Si ce n'est pas un tableau ou qu'il est vide, c'est "Tous types de bien"
  382. if (!is_array($checkedLabels) || $checkedLabels == array())
  383. $summary["property_type"] = LABEL_ALL_PROPERTY_TYPE;
  384. else
  385. $summary["property_type"] = implode(', ', $checkedLabels);
  386. }
  387. }
  388. else {
  389. global $_LI_REALESTATETYPES;
  390. if ($data["property_type"] == "" || $data["property_type"][0] == -1 || count($data["property_type"]) == count($_LI_REALESTATETYPES)) {
  391. $summary["property_type"] = LABEL_ALL_PROPERTY_TYPE;
  392. } else {
  393. for ($i = 0; $i < count($data["property_type"]); $i++) {
  394. $data["property_type"][$i] = $_LI_REALESTATETYPES[$data["property_type"][$i]];
  395. }
  396. $summary["property_type"] = implode(", ", $data["property_type"]);
  397. }
  398. }
  399. // surface
  400. $summary["area"] = get_summary($data, $parameters["area"], "area", LABEL_ALL_AREA, LABEL_COMMON_AREA_UNIT);
  401. // price
  402. $summary["price"] = get_summary($data, $parameters["price"], "price", LABEL_ALL_BUDGET, LABEL_COMMON_PRICE_UNIT);
  403. // rooms
  404. // NB: pour la coloc., le nombre de pièces est en fait le nombre de chambres !
  405. if (isset($data['ck_nb_rooms'])) {
  406. global $_MASK_NB_ROOMS_ALL_CHECKED;
  407. $nb_rooms = $data['ck_nb_rooms'];
  408. // Convertir le tableau en chaine
  409. if (is_array($nb_rooms)) {
  410. $str_nb_rooms = str_repeat('0', 8); // 8 nombre de pieces possibles (2 octets)
  411. foreach ($nb_rooms as $nb_room) {
  412. $str_nb_rooms[intval($nb_room)] = 1;
  413. }
  414. $nb_rooms = $str_nb_rooms;
  415. }
  416. // Si champ vide, ou aucun coché ou tous cochés
  417. $all_checked = matchMask($nb_rooms, $_MASK_NB_ROOMS_ALL_CHECKED);
  418. if (empty($nb_rooms) || strpos($nb_rooms, '1') === false || $all_checked) {
  419. if ($showIfAllChecked)
  420. $summary["nb_rooms"] = ($data["univers"] == 8 ? LABEL_ALL_BEDROOMS : LABEL_ALL_ROOMS);
  421. }
  422. else {
  423. // Gérer le cas où seul le premier est coché (singulier)
  424. if (strpos($nb_rooms, '1', 1) === false && strpos($nb_rooms, '1') === 0) {
  425. $summary["nb_rooms"] = $_LI_ROOMS[0];
  426. } else {
  427. $limit = count($_LI_ROOMS) - 1;
  428. $str_nb_rooms = '';
  429. for ($i = 0; $i < $limit; $i++) {
  430. if ($nb_rooms[$i] == '1')
  431. $str_nb_rooms .= ', ' . ($i + 1);
  432. }
  433. // Ajouter le 'Et plus' sur le dernier si coché
  434. if ($nb_rooms[$i] == '1') {
  435. //$str_nb_rooms .= ', '.($i+1).' ';
  436. //$summary["nb_rooms"] = substr($str_nb_rooms,2).' '.LABEL_COMMON_ROOMS_UNIT.' '.LABEL_AND_MORE;
  437. if ($str_nb_rooms == '')
  438. $summary["nb_rooms"] = $_LI_ROOMS[$i];
  439. else
  440. $summary["nb_rooms"] = substr($str_nb_rooms, 2) . ', ' . $_LI_ROOMS[$i];
  441. }
  442. else {
  443. $summary["nb_rooms"] = substr($str_nb_rooms, 2) . ' ' . ($data["univers"] == 8 ? LABEL_COMMON_BEDROOMS_UNITS : LABEL_COMMON_ROOMS_UNITS);
  444. }
  445. }
  446. }
  447. } else {
  448. $summary["nb_rooms"] = get_summary($data, $parameters["nb_rooms"], "nb_rooms", ($data["univers"] == 8 ? LABEL_ALL_BEDROOMS : LABEL_ALL_ROOMS), ($data["univers"] == 8 ? LABEL_COMMON_BEDROOMS_UNITS : LABEL_COMMON_ROOMS_UNITS));
  449. }
  450. // bedrooms
  451. if (isset($data['ck_nb_bedrooms'])) {
  452. global $_MASK_NB_BEDROOMS_ALL_CHECKED, $_LI_BEDROOMS;
  453. $nb_bedrooms = $data['ck_nb_bedrooms'];
  454. // Convertir le tableau en chaine
  455. if (is_array($nb_bedrooms)) {
  456. $str_nb_bedrooms = str_repeat('0', 8); // 8 nombre de pieces possibles (2 octets)
  457. foreach ($nb_bedrooms as $nb_bedroom) {
  458. $str_nb_bedrooms[intval($nb_bedroom)] = 1;
  459. }
  460. $nb_bedrooms = $str_nb_bedrooms;
  461. }
  462. // Si champ vide, ou aucun coché ou tous cochés
  463. $all_checked = matchMask($nb_bedrooms, $_MASK_NB_BEDROOMS_ALL_CHECKED);
  464. if (empty($nb_bedrooms) || strpos($nb_bedrooms, '1') === false || $all_checked) {
  465. if ($showIfAllChecked)
  466. $summary["nb_bedrooms"] = 'Tous nb de chambres';
  467. }
  468. else {
  469. // Gérer le cas où seul le premier est coché (singulier)
  470. if (strpos($nb_bedrooms, '1', 1) === false && strpos($nb_bedrooms, '1') === 0) {
  471. $summary["nb_bedrooms"] = $_LI_BEDROOMS[0];
  472. } else {
  473. $limit = count($_LI_BEDROOMS) - 1;
  474. $str_nb_bedrooms = '';
  475. for ($i = 0; $i < $limit; $i++) {
  476. if ($nb_bedrooms[$i] == '1')
  477. $str_nb_bedrooms .= ', ' . ($i + 1);
  478. }
  479. // Ajouter le 'Et plus' sur le dernier si coché
  480. if ($nb_bedrooms[$i] == '1') {
  481. if ($str_nb_bedrooms == '')
  482. $summary["nb_bedrooms"] = $_LI_BEDROOMS[$i];
  483. else
  484. $summary["nb_bedrooms"] = substr($str_nb_bedrooms, 2) . ', ' . $_LI_BEDROOMS[$i];
  485. }
  486. else {
  487. $summary["nb_bedrooms"] = substr($str_nb_bedrooms, 2) . ' chambres';
  488. }
  489. }
  490. }
  491. }
  492. }
  493. return $summary;
  494. }
  495. /**
  496. * Convertit chaque critère par une valeur lisible par l'internaute
  497. * @param Array $data Tableau indexé des valeurs sélectionnées par l'internaute
  498. * @param Boolean $extended Afficher les "ou" entre parentheses [ex: chauffage (gaz,fioul) ]
  499. * @param Boolean $showIfAllChecked
  500. * @return Array Tableau indexé contenant uniquement les valeurs converties
  501. */
  502. function get_adv_summary($data, $extended = false, $showIfAllChecked = true) {
  503. global $_ADVANCED_SEARCH_CAT;
  504. $summary = array();
  505. // Critères avancés du bien (equipement, chauffage, fiche technique, etc.)
  506. if (isset($data['ck_advanced']) && strpos($data['ck_advanced'], '1') !== false) {
  507. $advanced = $data['ck_advanced'];
  508. // Récupérer la liste des critères sans les catégories
  509. // => Plus simple à interroger
  510. $advanced_search = array();
  511. foreach ($_ADVANCED_SEARCH_CAT as $SUB_CAT) {
  512. $advanced_search += $SUB_CAT;
  513. }
  514. $str_advanced = '';
  515. $length = strlen($advanced);
  516. if ($extended) {
  517. global $_MASK_ADV_OR;
  518. foreach ($_MASK_ADV_OR as $label => $mask_or) {
  519. $mask_value = $advanced & $mask_or;
  520. // Ajouter la clause OU
  521. if ($mask_value > 0) {
  522. // Equivalent d'un NON + compléter avec des 1 pour le ET ci-dessous
  523. $remove_mask = str_pad(strtr($mask_value, '01', '10'), $length, 1);
  524. // Effacer les critères de chauffage du masque principal
  525. $advanced = $advanced & $remove_mask;
  526. $pos = -1;
  527. $tmp_str_advanced = '';
  528. while (($pos = strpos($mask_value, '1', $pos + 1)) !== false) {
  529. $tmp_str_advanced .= ', ' . $advanced_search[$pos];
  530. }
  531. $tmp_str_advanced = substr($tmp_str_advanced, 2);
  532. $str_advanced .= ", $label ($tmp_str_advanced)";
  533. }
  534. }
  535. }
  536. $pos = -1;
  537. while (($pos = strpos($advanced, '1', $pos + 1)) !== false) {
  538. $str_advanced .= ', ' . $advanced_search[$pos];
  539. }
  540. $summary["advanced"] = substr($str_advanced, 2);
  541. }
  542. /*
  543. * *************************************************************************
  544. * TRAITEMENTS A ACTIVER SI UTILISES
  545. * (Surface du terrain, DPE, Fraicheur des annonces)
  546. * *************************************************************************
  547. *
  548. // Surface du terrain min / max
  549. $surf_min = isset($data['surf_min']) ? (int)$data['surf_min'] : 0;
  550. $surf_max = isset($data['surf_max']) ? (int)$data['surf_max'] : 0;
  551. if($surf_max>0) {
  552. $summary['surf'] = "Terrain entre {$surf_min} et {$surf_max} m²";
  553. } elseif($surf_min>0) {
  554. $summary['surf'] = "Terrain de plus de {$surf_min} m²";
  555. }
  556. // Consommation énergétique
  557. if(isset($data['dpe']) && strpos($data['dpe'],'1')!==false) {
  558. $ref_dpe = 'ABCDEFGH';
  559. $result = '';
  560. for($i=0, $max=strlen($data['dpe']); $i<$max; $i++) {
  561. if($data['dpe'][$i]==1) $result .= ', '.$ref_dpe[$i];
  562. }
  563. $summary['dpe'] = 'Energie '.substr($result,2);
  564. }
  565. // Fraicheur des annonces
  566. if(isset($data['fresh']) && ($fresh = (int)$data['fresh'])!==0) {
  567. switch(substr($data['fresh'],-1)) {
  568. case 'h': $unit = $fresh==1 ? 'heure' : 'heures'; break;
  569. case 'j': $unit = $fresh==1 ? 'jour' : 'jours'; break;
  570. case 's': $unit = $fresh==1 ? 'semaine' : 'semaines'; break;
  571. case 'm': $unit = 'mois'; break;
  572. case 'a': $unit = $fresh==1 ? 'an' : 'ans'; break;
  573. }
  574. if(isset($unit)) {
  575. $summary['fresh'] = "Annonces de moins de {$fresh} {$unit}";
  576. }
  577. }
  578. */
  579. return $summary;
  580. }
  581. /**
  582. * Turns a search criterion to a human readable value
  583. *
  584. * @param unknown_type $data
  585. * @param unknown_type $parameters
  586. * @param unknown_type $item
  587. * @param unknown_type $label_all
  588. * @param unknown_type $label_unit
  589. * @return unknown
  590. */
  591. function get_summary($data, $parameters, $item, $label_all, $label_unit) {
  592. // patch
  593. if ($data[$item] == -1) {
  594. $data[$item] = "";
  595. }
  596. // rooms
  597. if (in_array($item, array("nb_rooms", "nb_bedrooms", "nb_people"))) {
  598. if ($data[$item] == "" && $data[$item . "_min"] == "" && $data[$item . "_max"] == "") {
  599. $summary = $label_all;
  600. } else {
  601. if ($data[$item] != "") {
  602. $summary = $parameters[$data[$item]];
  603. } else {
  604. if ($data[$item . "_min"] != "" && $data[$item . "_max"] != "") {
  605. $summary = LABEL_FROM . " " . $data[$item . "_min"] . " " . LABEL_TO . " " . $data[$item . "_max"] . " " . $label_unit;
  606. } elseif ($data[$item . "_min"] != "" && $data[$item . "_max"] == "") {
  607. $summary = LABEL_MORE_THAN . " " . $data[$item . "_min"] . " " . $label_unit;
  608. } else {
  609. $summary = LABEL_LESS_THAN . " " . $data[$item . "_max"] . " " . $label_unit;
  610. }
  611. }
  612. }
  613. }
  614. // price, surface
  615. else {
  616. if (!is_numeric($data[$item . "_min"]))
  617. $data[$item . "_min"] = '';
  618. if (!is_numeric($data[$item . "_max"]))
  619. $data[$item . "_max"] = '';
  620. if ($data[$item] == "" && $data[$item . "_min"] == "" && $data[$item . "_max"] == "") {
  621. $summary = $label_all;
  622. } else {
  623. if ($data[$item] != "") {
  624. $value = $parameters[$data[$item]];
  625. if ($value["from"] == 0) {
  626. $summary = LABEL_LESS_THAN . " " . $value["to"] . " " . $label_unit;
  627. } elseif ($value["to"] == 999999999) {
  628. $summary = LABEL_MORE_THAN . " " . $value["from"] . " " . $label_unit;
  629. } else {
  630. $summary = LABEL_FROM . " " . $value["from"] . " " . LABEL_TO . " " . $value["to"] . " " . $label_unit;
  631. }
  632. } else {
  633. if ($data[$item . "_min"] != "" && $data[$item . "_max"] != "") {
  634. $summary = LABEL_FROM . " " . n_f($data[$item . "_min"]) . " " . LABEL_TO . " " . n_f($data[$item . "_max"]) . " " . $label_unit;
  635. } elseif ($data[$item . "_min"] != "" && $data[$item . "_max"] == "") {
  636. $summary = LABEL_MORE_THAN . " " . n_f($data[$item . "_min"]) . " " . $label_unit;
  637. } else {
  638. $summary = LABEL_LESS_THAN . " " . n_f($data[$item . "_max"]) . " " . $label_unit;
  639. }
  640. }
  641. }
  642. }
  643. return $summary;
  644. }
  645. /**
  646. * Returns property type label depending on the code
  647. *
  648. * @param unknown_type $id
  649. * @return unknown
  650. */
  651. function get_property_type_label($id) {
  652. global $_LI_REALESTATETYPES;
  653. foreach ($_LI_REALESTATETYPES as $property_type) {
  654. if ($property_type["value"] == $id) {
  655. return $property_type["label"];
  656. }
  657. }
  658. }
  659. /**
  660. * number_format shortcut
  661. *
  662. * @param unknown_type $value
  663. * @return unknown
  664. */
  665. function n_f($value) {
  666. return number_format($value, 0, "", " ");
  667. }
  668. /**
  669. * Currency conversion
  670. *
  671. * @param unknown_type $value
  672. * @param unknown_type $from
  673. * @param unknown_type $to
  674. * @param unknown_type $add_currency_name
  675. * @return unknown
  676. */
  677. function currency_format($value, $from, $to, $add_currency_name = true) {
  678. global $_global;
  679. global $_rates;
  680. if ($_rates[$from][$to] > 0) {
  681. $price = n_f($value * $_rates[$from][$to]);
  682. if ($add_currency_name) {
  683. switch ($_global["current_currency"]) {
  684. case "CZK" :
  685. $price = $price . " " . LABEL_COMMON_PRICE_UNIT_CZ;
  686. break;
  687. case "EUR" :
  688. $price = $price . " " . LABEL_COMMON_PRICE_UNIT;
  689. break;
  690. case "CHF" :
  691. $price = $price . " " . LABEL_COMMON_PRICE_UNIT_CH;
  692. break;
  693. default :
  694. $price = $price . " " . LABEL_COMMON_PRICE_UNIT;
  695. break;
  696. }
  697. }
  698. return $price;
  699. }
  700. }
  701. /**
  702. * Function so sex, par le so sexy oxman, da crazy man !
  703. *
  704. * @param unknown_type $input
  705. * @param unknown_type $partial
  706. * @return unknown
  707. */
  708. function sosex($input, $partial = false) {
  709. // Partial mode, the word isn't complete, typically when you're doing an ajax completion
  710. $input = str_replace('è', 'ai', $input);
  711. $input = str_replace('ê', 'ai', $input);
  712. $input = str_replace('é', 'ai', $input);
  713. $input = strtoupper($input);
  714. // START - Nettoiement de la recherche, suppressions de tous les caracteres parasites
  715. $input = preg_replace('/(.)\\1{1,}/', '\\1', $input); // 1. Suppression des lettres en doubles (exemple: pelle, femme)
  716. $input = preg_replace('/[-,\/;.\']/', ' ', $input); // 2. Sérateur de mot : , / ; . -
  717. $input = preg_replace('/(?=\b)[^ ](?=\b)/', '', $input); // 28. Suppression des caractères isolées (résultant d'un D', L', etc)
  718. $input = ' ' . $input . ' ';
  719. $input = preg_replace('/(?=\b)ST(?=\b)/', 'SAINT', $input); // 3. Attention avant la 4
  720. $input = preg_replace('/(?=\b)[LD]ES(?=\b)/', '', $input); // 4. Suppression des dérminants (exemple: nos, mes, du, les, la)
  721. $input = preg_replace('/(?=\b)SUR(?=\b)/', '', $input); // 4. Suppression des dérminants (exemple: nos, mes, du, les, la)
  722. $input = preg_replace('/(?=\b)SOUS(?=\b)/', '', $input); // 4. Suppression des dérminants (exemple: nos, mes, du, les, la)
  723. $input = preg_replace('/(?=\b)L[EA](?=\b)/', '', $input); // 4. Suppression des dérminants (exemple: nos, mes, du, les, la)
  724. $input = preg_replace('/(?=\b)D[EU](?=\b)/', '', $input); // 4. Suppression des dérminants (exemple: nos, mes, du, les, la)
  725. $input = preg_replace('/(?=\b)E[TN](?=\b)/', '', $input); // 4. Suppression des dérminants (exemple: nos, mes, du, les, la)
  726. $input = str_replace('ET', 'AIT', $input); // 25. Son : AI (exemple: jouet, essai), avant la regle de suppressions des lettres muettes (n°20)
  727. $input = preg_replace('/ES(?!\b)/', 'AIS', $input); // 26. Son : AI (exemple: jouet, essai, mais pas lourdes), avant la regle de suppressions des lettres muettes (n°20)
  728. $input = preg_replace('/[AE][NM](?![AEIOUY])/', 'AN', $input); // 5. Son : AN (exemple: femme, enfant), avant lettres muettes
  729. $input = preg_replace('/OM(?![AEIOUY])/', 'ON', $input); // 14. Son : ON (exemple: pantalom, pomtom), avant lettres muettes
  730. $input = preg_replace('/(?<![CSP]|\b)H/', '\\1', $input); // 6. Son muet H si il n'y a ni C,S,P devant (hyè, mammouth, pharaon), avant lettres muettes
  731. $input = preg_replace('/P[HF]/', 'F', $input); // 19. Son : F (exemple: PF ou PH donne le son F), avant lettres muettes
  732. $input = str_replace('Y', 'I', $input); // 29. Son : I, avant lettres muettes
  733. $input = preg_replace('/X(?=\b)/', '', $input); // 30. Son : X muet à la fin de mot
  734. if (!$partial) {
  735. $input = preg_replace('/(?!E)T(?![AEIOUYR$])/', '', $input); // 13. Son muet T si en fin de mot, où suivis d'une consonne, pas muet si c'est suivit d'un R : TRIMARAN, pas muet si précédé d'un E, car fait le son AI
  736. $input = preg_replace('/(?<![AEIOUY]|\b)[GLSXP](?![AEIOUY])/', '', $input); // 20. Son muet G ou, H ou L etc.. si en fin de mot, où suivis d'une consonne, et précédé d'une consonne
  737. $input = preg_replace('/E(?=\b)/', '', $input); // 20. Son muet E etc.. si en fin de mot, où suivis d'une voyelle, et précédé d'une voyelle
  738. $input = preg_replace('/ES(?=\b)/', '', $input); // 27. Son ES en fin de mot muet
  739. }
  740. // END
  741. $input = str_replace('EU', 'E', $input); // 25. Son : E, après la regle de suppressions des lettres muettes (n°20)
  742. $input = preg_replace('/E?AU/', 'O', $input); // 7. Son O : veau, pot, l'horizon
  743. $input = str_replace('SH', 'CH', $input); // 9. Son : CH
  744. $input = preg_replace('/C[CK]/', 'K', $input); // 18. Son : K (exemple: CC ou CK donne le son K)
  745. $input = str_replace('QU', 'K', $input); // 10. Son : K (exemple: quand, bouquet, plaque)
  746. $input = str_replace('KS', 'X', $input); // 28. Son : X (exemple: luksiol)
  747. $input = preg_replace('/C(?=[UAO]|\b)/', 'K', $input); // 16. Son : K (exemple: cutalion, carole, mais pas celine, ciboulette, candiac)
  748. $input = preg_replace('/C(?=[IEY])/', 'S', $input); // 17. Son : S (exemple: celine, ciboulette, cy..., mais pas cutalion, carole)
  749. $input = preg_replace('/G(?=[IEYL]|\b)/', 'J', $input); // 24. Son : J (exemple: gille, vregille, mais pas vrigne, zigliara)
  750. $input = str_replace('Z', 'S', $input); // 15. Son : Z S
  751. $input = preg_replace("/(.)\\1{1,}/", "\\1", $input); // 12. Suppression des lettres en doubles cré aprètransformation (tout àa fin)
  752. return trim($input);
  753. }
  754. /**
  755. * Replace only the first occurence of a string
  756. *
  757. * @param unknown_type $needle
  758. * @param unknown_type $replace
  759. * @param unknown_type $haystack
  760. * @return unknown
  761. */
  762. function str_replace_once($needle, $replace, $haystack) {
  763. // Looks for the first occurence of $needle in $haystack
  764. // and replaces it with $replace.
  765. $pos = strpos($haystack, $needle);
  766. if ($pos === false) {
  767. // Nothing found
  768. return $haystack;
  769. }
  770. return substr_replace($haystack, $replace, $pos, strlen($needle));
  771. }
  772. /**
  773. * Returns a truncated string
  774. *
  775. * @param unknown_type $value
  776. * @param unknown_type $limit
  777. * @return unknown
  778. */
  779. function str_limit($value, $limit) {
  780. if (strlen($value) == 0) {
  781. return "";
  782. } else {
  783. if (strlen($value) <= $limit) {
  784. return $value;
  785. } else {
  786. $tmp = explode(" ", $value);
  787. if (count($tmp) > 0) {
  788. $valV = $valVold = "";
  789. foreach ($tmp as $v) {
  790. if (strlen($valV) > $limit) {
  791. $value = substr($valVold, 0, -1) . "...";
  792. break;
  793. }
  794. else
  795. $valVold = $valV;
  796. $valV .= $v . " ";
  797. }
  798. }
  799. return $value;
  800. }
  801. }
  802. }
  803. /**
  804. * Returns html city name with arrondissement correctly written in french
  805. * ex: Marseille 1er => Marseille 1<sup>er</sup>, Paris 2e => Paris 2<sup>ème</sup>
  806. *
  807. * @param unknown_type $cityname_arrond
  808. * @return unknown
  809. */
  810. function cityname_arrond($cityname_arrond, $short_form = false) {
  811. $str_cityname_arrond = "";
  812. $arr_cityname_arrond = explode(" ", $cityname_arrond);
  813. $str_cityname = $arr_cityname_arrond[0];
  814. $str_arrond = $arr_cityname_arrond[1];
  815. if (strpos($str_arrond, "er") !== FALSE) {
  816. $str_cityname_arrond = $str_cityname . " " . str_replace("er", "<sup>er</sup>", $str_arrond);
  817. } else if (strpos($str_arrond, "e") !== FALSE) {
  818. if ($short_form) {
  819. $str_cityname_arrond = $str_cityname . " " . str_replace("e", "<sup>è</sup>", $str_arrond);
  820. } else {
  821. $str_cityname_arrond = $str_cityname . " " . str_replace("e", "<sup>ème</sup>", $str_arrond);
  822. }
  823. }
  824. return $str_cityname_arrond;
  825. }
  826. /**
  827. * Returns html city name without arrondissement at the end, if present
  828. * ex: Marseille 1er => Marseille, Paris 2e => Paris, Cannes => Cannes
  829. *
  830. * @param unknown_type $cityname_arrond
  831. * @return unknown
  832. */
  833. function cityname_without_arrond($cityname_arrond) {
  834. $str_cityname_arrond = $cityname_arrond;
  835. $str_cityname_arrond = preg_replace('/(\w+) (\d+)er/i', '${1}', $str_cityname_arrond);
  836. $str_cityname_arrond = preg_replace('/(\w+) (\d+)e/i', '${1}', $str_cityname_arrond);
  837. return $str_cityname_arrond;
  838. }
  839. /**
  840. * Returns true if the lct_id is the one of the arrondissement of a city (Paris, Lyon, Marseille)
  841. * ex: 36102 => true (Marseille 2è), 33109 => false (Toulon)
  842. *
  843. * @param int $lct_id
  844. * @return bool
  845. */
  846. function is_lct_id_arrond_of_city($lct_id) {
  847. if (!isset($lct_id) || empty($lct_id)) {
  848. return array(false, "");
  849. }
  850. $lct_ids_arrronds_paris = array(23599, 23601, 23602, 23603, 23604, 23605, 23606, 23607, 23609, 23589, 23590, 23591, 23592, 23593, 23594, 23595, 23596, 23597, 23598, 23600);
  851. if (in_array($lct_id, $lct_ids_arrronds_paris)) {
  852. return array(true, "paris");
  853. }
  854. $lct_ids_arrronds_marseille = array(36102, 36104, 36105, 36106, 36107, 36108, 36109, 36110, 36111, 36112, 36113, 36114, 36115, 36116, 36117, 36118);
  855. if (in_array($lct_id, $lct_ids_arrronds_marseille)) {
  856. return array(true, "marseille");
  857. }
  858. $lct_ids_arrronds_lyon = array(36119, 36120, 36121, 36122, 36123, 36124, 36125, 36126, 36127);
  859. if (in_array($lct_id, $lct_ids_arrronds_lyon)) {
  860. return array(true, "lyon");
  861. }
  862. return array(false, "");
  863. }
  864. /**
  865. * Returns true if the loc_key is the one of city with arrondissements (Paris, Lyon, Marseille)
  866. * ex: 421_99 => true (Marseille), 33109_2 => false (Toulon)
  867. *
  868. * @param int $lct_id
  869. * @return bool
  870. */
  871. function is_loc_key_city_with_arronds($loc_key) {
  872. if (!isset($loc_key) || empty($loc_key)) {
  873. return array(false, "");
  874. }
  875. $loc_key_paris = '100_1';
  876. if ($loc_key == $loc_key_paris) {
  877. return array(true, "paris");
  878. }
  879. $loc_key_marseille = '421_99';
  880. if ($loc_key == $loc_key_marseille) {
  881. return array(true, "marseille");
  882. }
  883. $loc_key_lyon = '422_99';
  884. if ($loc_key == $loc_key_lyon) {
  885. return array(true, "lyon");
  886. }
  887. return array(false, "");
  888. }
  889. /**
  890. * Returns a clean string
  891. *
  892. * @param unknown_type $value
  893. * @return unknown
  894. */
  895. function remove_returns($value) {
  896. $value = str_replace("\r\n", "", $value);
  897. $value = str_replace("\n\r", "", $value);
  898. $value = str_replace("\n", "", $value);
  899. $value = str_replace("\r", "", $value);
  900. return $value;
  901. }
  902. /**
  903. * Returns a "clean" html, without css MS Office classes
  904. *
  905. * @param unknown_type $value
  906. * @return unknown
  907. */
  908. function strip_mso_css_class($value) {
  909. $value = str_replace(" class=\"MsoPlainText\"", "", $value);
  910. return $value;
  911. }
  912. /**
  913. * Returns in a html string li tags par a dot char
  914. *
  915. * @param unknown_type $value
  916. * @return unknown
  917. */
  918. function replace_li_tag_dot_char($value) {
  919. $value = str_replace("<li>", "&#149;&nbsp;&nbsp;", $value);
  920. $value = str_replace("</li>", "<br>", $value);
  921. $value = str_replace("<ul>", "", $value);
  922. $value = str_replace("</ul>", "", $value);
  923. return $value;
  924. }
  925. /**
  926. * Returns html height and width properties, determining the size of an image to fit required width and height
  927. *
  928. * @param unknown_type $img
  929. * @param unknown_type $max_width
  930. * @param unknown_type $max_height
  931. * @return unknown
  932. */
  933. function resize_image($img, $max_width, $max_height) {
  934. $img_details = @getimagesize($img);
  935. $img_width = $img_details[0];
  936. $img_height = $img_details[1];
  937. if ($img_width == "" || $img_height == "") {
  938. return "";
  939. }
  940. $img_wratio = round($img_height / $img_width, 2);
  941. $img_hratio = round($img_width / $img_height, 2);
  942. if ($img_width > $max_width || $img_height > $max_height) {
  943. if ($img_width > $img_height) {
  944. $img_width = $max_width;
  945. $img_height = $img_width * $img_wratio;
  946. if ($img_height > $max_height) {
  947. $img_height = $max_height;
  948. $img_width = $img_height * $img_hratio;
  949. }
  950. } else {
  951. $img_height = $max_height;
  952. $img_width = $img_height * $img_hratio;
  953. if ($img_width > $max_width) {
  954. $img_width = $max_width;
  955. $img_height = $img_width * $img_wratio;
  956. }
  957. }
  958. }
  959. return "width=\"" . $img_width . "\" height=\"" . $img_height . "\"";
  960. }
  961. /**
  962. * Returns html code for a spacer
  963. *
  964. * @param unknown_type $height
  965. * @param unknown_type $width
  966. * @return unknown
  967. */
  968. function spacer($height, $width) {
  969. return "<img src=\"" . get_urlmmf('/spacer.gif') . "\" height=\"" . $height . "\" width=\"" . $width . "\" />";
  970. }
  971. /**
  972. * Returns html alt and title
  973. *
  974. * @param unknown_type $value
  975. * @return unknown
  976. */
  977. function set_html_title($value) {
  978. return "alt=\"" . $value . "\" title=\"" . $value . "\"";
  979. }
  980. /**
  981. * Returns ad and agency data
  982. *
  983. * @param unknown_type $page
  984. * @param unknown_type $value
  985. * @param unknown_type $has_premium
  986. * @param unknown_type $url
  987. * @param Integer $idx
  988. * @param Boolean $is_exclusive Annonce à afficher en haut de la page des annonces
  989. * @return unknown
  990. */
  991. function get_ad_data($page, $value, $has_premium = 0, $url = "", $idx = -1, $is_exclusive = false) {
  992. global $_global;
  993. global $_LI_REALESTATETYPES;
  994. global $_REF_ROOMS;
  995. global $_LI_BANDEAU_PERSO_FR;
  996. $prefix_table = '';
  997. if ( 9 != $_global['univers'] ) {
  998. $prefix_table = $_global["table_prefix"] . '_';
  999. }
  1000. // arrays
  1001. $ad = array();
  1002. $ag = array();
  1003. //echo '<pre>'; var_dump($value); echo '</pre>';
  1004. $ad["idx"] = $idx;
  1005. $ad["id"] = $value["id_annonce"];
  1006. $ad["univers"] = $value["univers"];
  1007. $ad["reference"] = $value[$prefix_table . "reference"];
  1008. $ad["num_mandat"] = $value[$prefix_table . "num_mandat"];
  1009. // ad premium
  1010. $ad["premium"] = $value[$prefix_table . "is_premium"];
  1011. // ad features
  1012. $ad["type_transaction"] = $value[$prefix_table . "type_transaction"];
  1013. $ad["id_bien"] = $value["id_bien"];
  1014. $ad["id_bien_programme"] = $value["id_bien_programme"];
  1015. $ad["prg_title"] = $value["prg_title"];
  1016. $ad["property_type_id"] = $value[$prefix_table . "property_type_id"];
  1017. $ad["property_type_id_orig"] = $value[$prefix_table . "property_type_id_orig"];
  1018. $ad["property_type"] = html_entity_decode($value[$prefix_table . "property_type"], ENT_QUOTES, "UTF-8");
  1019. if ($ad["type_transaction"] == "4")
  1020. $ad["property_type"] .= LABEL_AD_LIFE_ANNUITY;
  1021. $ad["agency_rent_fees"] = $value["rnt_agency_rent_fees"];
  1022. $ad["rnt_property_charges"] = $value["rnt_property_charges"];
  1023. $ad["guarantee_deposit"] = $value[$prefix_table . "guarantee_deposit"];
  1024. //ad currency
  1025. $ad["currency"] = $value[$prefix_table . "currency"];
  1026. //SUSPENSION DES CHARGES
  1027. $ad["real_price"] = $value[$prefix_table . "price"];
  1028. $ad["price"] = ($ad["real_price"] >= AD_PRICE_LIMIT ? $ad["real_price"] : n_f($ad["real_price"]));
  1029. if ($ad["property_type"] == "") {
  1030. $ad["property_type"] = ($ad["property_type_id_orig"] != "" ? constant("LABEL_COMMON_PROPERTY_ID_" . $ad["property_type_id_orig"]) : "");
  1031. }
  1032. $ad["area"] = $value[$prefix_table . "area"];
  1033. $ad["price"] = ($ad["real_price"] >= AD_PRICE_LIMIT ? $ad["real_price"] : n_f($ad["real_price"]));
  1034. $ad["nb_rooms"] = $value[$prefix_table . "nb_rooms"];
  1035. // Advanced : dependances, chauffage, amenagement, confort
  1036. $ad["advanced_set"] = $value[$prefix_table . 'advanced_set'];
  1037. // First online date
  1038. $ad["first_online_date"] = $value[$prefix_table . 'first_online_date'];
  1039. //Colocation
  1040. if ($_global["univers"] == 8) {
  1041. $ad["nb_bedrooms"] = $value["rnt_nb_bedrooms"];
  1042. }
  1043. $ad["default_text"] = str_replace("[[n]]", " ", $value[$prefix_table . "default_text"]);
  1044. if ($_global["self"] == "resultats_refnat.php") {
  1045. $ad["default_intro"] = strtolower(strip_tags(str_limit($ad["default_text"], 90)));
  1046. } else {
  1047. $ad["default_intro"] = preg_replace('`(\<[a-zA-Z]*)\.\.\.$`', '', str_limit($ad["default_text"], 200));
  1048. }
  1049. // vacances
  1050. if ($_global["univers"] == 13) {
  1051. $ad["nb_bedrooms"] = $value["rnt_nb_bedrooms"];
  1052. $ad["nb_people"] = $value["rnt_nb_people"];
  1053. if ($value["rnt_site_agency"] != "") {
  1054. if (substr($value["rnt_site_agency"], 0, 7) != "http://") {
  1055. $value["rnt_site_agency"] = "http://" . $value["rnt_site_agency"];
  1056. }
  1057. $ad["partner_url"] = $value["rnt_site_agency"];
  1058. }
  1059. $ad["external"] = ($value["id_presto"] == "CMM-PT-VACANCES" ? true : false);
  1060. }
  1061. if ($_global["univers"] == 13) {
  1062. $ad["features"] = $ad["property_type"] . ($ad["area"] > 0 ? " - " . $ad["area"] . " " . LABEL_COMMON_AREA_UNIT . " " . LABEL_RESULTS_ABOUT : "") . ($ad["nb_bedrooms"] > 0 ? " - " . $ad["nb_bedrooms"] . " " . LABEL_COMMON_BEDROOMS_UNIT : "");
  1063. } else {
  1064. if ($ad["nb_rooms"] == 1) {
  1065. $s_piece = LABEL_COMMON_ROOM_UNIT;
  1066. } else {
  1067. $s_piece = LABEL_COMMON_ROOMS_UNITS;
  1068. }
  1069. if ($_global["self"] == "resultats_refnat.php") {
  1070. $ad["features"] = ($ad["area"] > 0 ? $ad["area"] . " " . LABEL_COMMON_AREA_UNIT . " " . LABEL_RESULTS_ABOUT : "") . ($ad["area"] > 0 && $ad["nb_rooms"] > 0 ? " - " : "") . ($ad["nb_rooms"] > 0 ? $ad["nb_rooms"] . " " . $s_piece : "");
  1071. } else {
  1072. $ad["features"] = $ad["property_type"] . ($ad["area"] > 0 ? " - " . $ad["area"] . " " . LABEL_COMMON_AREA_UNIT . " " . LABEL_RESULTS_ABOUT : "") . ($ad["nb_rooms"] > 0 ? " - " . $ad["nb_rooms"] . " " . $s_piece : "");
  1073. }
  1074. /** Suppression du label "OU PLUS" Mathieu 25/01
  1075. if ($ad["nb_rooms"] == 6) {
  1076. $ad["features"] .= " " . LABEL_COMMON_OR_MORE;
  1077. }
  1078. *
  1079. */
  1080. }
  1081. $ad

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