public function getPage() { $Curl = new \Lib\Net\Curl(); $Curl->url = $this->url; $result = $Curl->exec(); return $result; }
public function store() { $blog = I('get.b', 'wordsnquotes'); $ImgPage = M('img_page'); $s = I('get.s'); $p = $ImgPage->where(array('name' => $blog))->max('page'); if (!$p) { $page_info['name'] = $blog; $page_info['page'] = 1; $page_info['time'] = time(); $ImgPage->add($page_info); } else { $page_info['page'] = $p + 1; $page_info['time'] = time(); $ImgPage->where(array('name' => $blog))->save($page_info); } $p = $p ? $p + 1 : 1; if ($s) { $p = $s + $p; } $start = ($p - 1) * 20; $api = 'fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4'; $url = 'http://api.tumblr.com/v2/blog/' . $blog . '.tumblr.com/posts/photo?offset=' . $start . '&api_key=' . $api . '&limit=20'; $Curl = new \Lib\Net\Curl(); $Curl->url = $url; $result = $Curl->exec(); $result = json_decode($result, true); $total = $result['response']['total_posts']; if (!$result['response']['posts']) { exit; } foreach ($result['response']['posts'] as $key => $value) { $data['slug'] = $value['slug']; $data['time'] = $value['timestamp']; $data['summary'] = $value['summary']; $data['blog'] = $blog; $data['photos'] = json_encode($value['photos']); $map['slug'] = $value['slug']; $map['time'] = $value['timestamp']; $map['blog'] = $blog; $Img = M('img'); $count = $Img->where($map)->count(); if (!$count) { $Img->add($data); } else { $page_info['page'] = 1; $page_info['time'] = time(); $ImgPage->where(array('name' => $blog))->save($page_info); } } }