forked from blallo/rss-bridge
Merge pull request #197 from teromene/new-attribute-system
Re-encode datas before saving
This commit is contained in:
commit
2458e369c4
3 changed files with 24 additions and 1 deletions
|
@ -134,7 +134,7 @@ class LeBonCoinBridge extends BridgeAbstract{
|
||||||
public function collectData(array $param){
|
public function collectData(array $param){
|
||||||
|
|
||||||
$html = '';
|
$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);
|
$html = file_get_html($link) or $this->returnError('Could not request LeBonCoin.', 404);
|
||||||
|
|
||||||
$list = $html->find('.list-lbc', 0);
|
$list = $html->find('.list-lbc', 0);
|
||||||
|
|
|
@ -24,6 +24,9 @@ class FileCache extends CacheAbstract{
|
||||||
public function saveData($datas){
|
public function saveData($datas){
|
||||||
$this->isPrepareCache();
|
$this->isPrepareCache();
|
||||||
|
|
||||||
|
//Re-encode datas to UTF-8
|
||||||
|
$datas = Cache::utf8_encode_deep($datas);
|
||||||
|
|
||||||
$writeStream = file_put_contents($this->getCacheFile(), json_encode($datas));
|
$writeStream = file_put_contents($this->getCacheFile(), json_encode($datas));
|
||||||
|
|
||||||
if(!$writeStream) {
|
if(!$writeStream) {
|
||||||
|
|
|
@ -70,6 +70,26 @@ class Cache{
|
||||||
return preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameCache);
|
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() {
|
static public function purge() {
|
||||||
$cacheTimeLimit = time() - 60*60*24 ;
|
$cacheTimeLimit = time() - 60*60*24 ;
|
||||||
$cachePath = 'cache';
|
$cachePath = 'cache';
|
||||||
|
|
Loading…
Reference in a new issue