From 379c89045b81443b0c69501e23bc480aacbb88e6 Mon Sep 17 00:00:00 2001 From: Teromene Date: Tue, 19 Jan 2016 12:15:16 +0000 Subject: [PATCH 1/3] Quoted the "r" and "k" in the parameters --- bridges/LeBonCoinBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/LeBonCoinBridge.php b/bridges/LeBonCoinBridge.php index 19016cc..72d2109 100755 --- a/bridges/LeBonCoinBridge.php +++ b/bridges/LeBonCoinBridge.php @@ -134,7 +134,7 @@ class LeBonCoinBridge extends BridgeAbstract{ public function collectData(array $param){ $html = ''; - $link = 'http://www.leboncoin.fr/annonces/offres/' . $param[r] . '/?f=a&th=1&q=' . $param[k]; + $link = 'http://www.leboncoin.fr/annonces/offres/' . $param['r'] . '/?f=a&th=1&q=' . $param['k']; $html = file_get_html($link) or $this->returnError('Could not request LeBonCoin.', 404); $list = $html->find('.list-lbc', 0); From 5f01b7fe7dbc4cf2f05365e8f00e27e2817f1725 Mon Sep 17 00:00:00 2001 From: Teromene Date: Tue, 19 Jan 2016 12:17:27 +0000 Subject: [PATCH 2/3] Added a function to re-encode everything to UTF-8 --- lib/Cache.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/Cache.php b/lib/Cache.php index fa80bc0..a165148 100644 --- a/lib/Cache.php +++ b/lib/Cache.php @@ -70,6 +70,26 @@ class Cache{ return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameCache); } + + static public function utf8_encode_deep(&$input) { + if (is_string($input)) { + $input = utf8_encode($input); + } else if (is_array($input)) { + foreach ($input as &$value) { + Cache::utf8_encode_deep($value); + } + + unset($value); + } else if (is_object($input)) { + $vars = array_keys(get_object_vars($input)); + + foreach ($vars as $var) { + Cache::utf8_encode_deep($input->$var); + } + } + } + + static public function purge() { $cacheTimeLimit = time() - 60*60*24 ; $cachePath = 'cache'; From 259e5ef9defeb8bb00270172a441890997573398 Mon Sep 17 00:00:00 2001 From: Teromene Date: Tue, 19 Jan 2016 12:18:54 +0000 Subject: [PATCH 3/3] Casting to UTF-8 before converting to JSON. --- caches/FileCache.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/caches/FileCache.php b/caches/FileCache.php index f2e0dbb..f2a3ea8 100644 --- a/caches/FileCache.php +++ b/caches/FileCache.php @@ -24,6 +24,9 @@ class FileCache extends CacheAbstract{ public function saveData($datas){ $this->isPrepareCache(); + //Re-encode datas to UTF-8 + $datas = Cache::utf8_encode_deep($datas); + $writeStream = file_put_contents($this->getCacheFile(), json_encode($datas)); if(!$writeStream) {