function cache_control() { $f_xml = new File($this->set_cache_filename('xml')); $f_img = new File($this->set_cache_filename('img'), true); $live = $expire = $this->expire * 3600; $live++; // AMAZON_NO_IMAGE - $this->items['Height'] = 91; $this->items['Width'] = 69; // キャッシュが存在している場合 if ($f_xml->has() && $f_xml->isReadable()) { // 経過秒数 $live = time() - $f_xml->time(); } // 一度キャッシュを作成した場合、取得できない場合は継続利用されることになる if ($expire >= $live) { $xml = $f_xml->get(true); // read cache file. if (empty($xml)) { $this->items['image'] = ''; $this->items['Height'] = 91; $this->items['Width'] = 69; return false; } $this->obj_xml = simplexml_load_string($xml); $this->asin = $this->obj_xml->Items->Item->ASIN; list($URL, $Height, $Width) = $this->get_image_size(); if ($f_img->has()) { $this->items['image'] = $f_img->filename; $this->items['Height'] = $Height; $this->items['Width'] = $Width; } else { $this->items['image'] = ''; $this->items['Height'] = 91; $this->items['Width'] = 69; } return true; } // 直接読む場合 $url = $this->ecs_url(); $xml = $this->fetch_xml($url); if (!empty($this->items['Error'])) { $this->items['image'] = ''; $this->items['Height'] = 91; $this->items['Width'] = 69; return false; } // ページが読めた場合 $f_xml->set($xml); // write xml file. list($URL, $Height, $Width) = $this->get_image_size(); if (empty($URL)) { $this->items['image'] = ''; $this->items['Height'] = 91; $this->items['Width'] = 69; return true; } $img = $this->fetch_img((string) $URL); if (!empty($img)) { $f_img->set($img); // Fileクラスの画像書き込みがちゃんと動かない・・・。 //self::file_write($f_img->filename, $img); // write img file. } $this->items['image'] = $f_img->filename; $this->items['Height'] = $Height; $this->items['Width'] = $Width; return true; }
/** * ファイルをセットする */ public function set($content, $keeptimestamp = false) { $fileinfo = new File($this->path); $this->status['count'][$this->age]++; $this->update = true; return $fileinfo->set($content, $keeptimestamp); }