Merge pull request #197 from teromene/new-attribute-system

Re-encode datas before saving
This commit is contained in:
Mitsu 2016-01-19 13:44:14 +01:00
commit 2458e369c4
3 changed files with 24 additions and 1 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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';