diff --git a/bridges/LeBonCoinBridge.php b/bridges/LeBonCoinBridge.php index 19016cc6..72d21099 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); diff --git a/caches/FileCache.php b/caches/FileCache.php index f2e0dbb7..f2a3ea87 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) { diff --git a/lib/Cache.php b/lib/Cache.php index fa80bc04..a165148d 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';