/ Published in: PHP
URL: http://dtbaker.com.au/random-bits/basic-usage-of-the-envato-api-plus-curl-.html
Script used to access the Envato API, and get extra details using Curl.
This script will only work on PHP5 on a Linux hosting account (with safe mode / openbasedir disabled). Will need slight adjustment if trying to run it otherwise.
You are welcome to use or modify this script, feel free to share your implementation of it.
Expand |
Embed | Plain Text
$envato = new envato(); $files = $envato->get_user_items('dtbaker','codecanyon'); $x=1; echo '<ul>'; foreach($files as $file){ if($x++>9)break; echo '<li>'; echo '</a>'; echo '</li>'; } echo '</ul>'; class envato{ private $_temp_folder; private $_ch; public function __construct(){ } $this->_ch = curl_init(); curl_setopt($this->_ch, CURLOPT_HEADER, false); curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($this->_ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($this->_ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); } $data = false; if(!$force){ // check if the cache item exists. $filename = $this->_temp_folder.$cache_id; } } } if(!$data){ // no cache item found, so we grab it via curl. curl_setopt($this->_ch, CURLOPT_URL, $url); curl_setopt($this->_ch,CURLOPT_POST,true); curl_setopt($this->_ch,CURLOPT_POSTFIELDS,$post_data); }else{ curl_setopt($this->_ch,CURLOPT_POST,false); } $data = curl_exec($this->_ch); } if(!$force){ // save cache item. file_put_contents($filename,$data); } if($clean)$data = $this->_clean($data); return $data; } public function get_item($item_id){ $url = "http://themeforest.net/item/daves_api/$item_id"; $data = $this->grab_url($url); $return['large_thumb'] = $matches[1]; } $return['content'] = $text[1]; } } // we also have to get the theme screenshot thumbnails $url = "http://themeforest.net/theme_previews/$item_id-daves_api"; //print_r($matches); foreach($matches[2] as $thumbnail){ } } } return $return; } public function get_user_items($user,$marketplace='themeforest'){ $url = "http://marketplace.envato.com/api/v2/new-files-from-user:$user,$marketplace.json"; $data = $this->grab_url($url); $json_data = json_decode($data, true); $files = $json_data['new-files-from-user']; // sort files? meh. return $files; } } /** private functions **/ private function posterize($post){ $postv = ''; foreach($post as $key=>$val){ $postv .= $key .'='.$val.'&'; } return $postv; } private function _clean($data){ } }
You need to login to post a comment.
