api_key = $api_key; // allow the user to pass the API key upon instantiation } /** * Attach your API key. * * @param string $api_key Can be accessed on the marketplaces via My Account * -> My Settings -> API Key */ public function set_api_key($api_key) { $this->api_key = $api_key; } /** * Retrieve the value of your API KEY, if needed. * * @return string The requested API Key. */ public function get_api_key() { if (!isset($this->api_key)) return 'No API Key is set.'; return $this->api_key; } /** * Sets the cache directory for all API calls. * * @param string $cache_dir */ public function set_cache_dir($cache_dir) { $this->cache_dir = $cache_dir; } /** * Retrieve the value of your cache directory, if needed. * * @return string The requested cache directory. */ public function get_cache_dir() { return $this->cache_dir; } /** * Available sets => 'vitals', 'earnings-and-sales-by-month', 'statement', 'recent-sales', 'account', 'verify-purchase', 'download-purchase' * */ public function private_user_data($user_name, $set, $purchase_code = null) { if (!isset($this->api_key)) exit('You have not set an api key yet. $class->set_api_key(key)'); if (!isset($set)) return 'Missing parameters'; $url = "http://marketplace.envato.com/api/edge/$user_name/$this->api_key/$set"; if (!is_null($purchase_code)) $url .= ":$purchase_code"; $url .= '.json'; $result = $this->fetch($url); if (isset($result->error)) return 'Username, API Key, or purchase code is invalid.'; return $result->$set; } /** * Can be used to verify if a person did in fact purchase your item. * * @param $user_name Author's username. * @param $purchase_code - The buyer's purchase code. See Downloads page for * receipt. * @return object|bool If purchased, returns an object containing the details. */ public function verify_purchase($user_name, $purchase_code) { $validity = $this->private_user_data($user_name, 'verify-purchase', $purchase_code); return isset($validity->buyer) ? $validity : false; } /** * Can be used to retrieve the download URL for a purchased item. * * @param $user_name Purchaser's username. * @param $purchase_code - The item purchase code. See Downloads page for * receipt. * @return string If purchased, returns a string containing the download URL. */ public function download_purchase($user_name, $purchase_code) { $download_url = $this->private_user_data($user_name, 'download-purchase', $purchase_code); return isset($download_url->download_url) ? $download_url->download_url : false; } /** * Helper method to retrieve the balance on your account. * * @param string $user_name The username attached to your API KEY. * @return string The balance in your account. */ public function balance($user_name) { $vitals = $this->private_user_data($user_name, 'vitals'); return $vitals->balance; } /** * Retrieve details for your most recent sales. * * @param string $user_name The username attached to your API KEY. * @param int $limit The number of sales to return. * @return array A list of your recent sales. */ public function recent_sales($user_name, $limit = null) { $sales = $this->private_user_data($user_name, 'recent-sales'); return $this->apply_limit($sales, $limit); } /** * Retrieve your account information -- balance, location, name, etc. * * @param string $user_name The username attached to your API KEY. * @return array A list of account information for the user. */ public function account_information($user_name) { return $this->private_user_data($user_name, 'account'); } /** * Grab quick monthly stats - number of sales, income, etc. * * @param string $user_name The username attached to your API KEY. * @param int $limit The number of months to return. * @return array A list of sales figures, ordered by month. */ public function earnings_by_month($user_name, $limit = null) { $earnings = $this->private_user_data($user_name, 'earnings-and-sales-by-month'); return $this->apply_limit($earnings, $limit); } /** * Generic method, to be used in combination with the marketplace API docs. * * @param string $user_name The user name of the seller to track. * @return array The returned data wrapped in an array. */ public function public_user_data($user_name) { $url = preg_replace('/set/i', 'user:' . $user_name, $this->public_url); return $this->fetch($url, 'user'); } /** * Returns the featured item, author, and free file for a given marketplace. * * @param string $marketplace_name The desired marketplace name. * @return array The featured file, free file, and featured author for the * given site. */ public function featured($marketplace_name = 'themeforest') { $url = preg_replace('/set/i', 'features:' . $marketplace_name, $this->public_url); return $this->fetch($url, 'features'); } /** * Retrieve the details for a specific marketplace item. * * @param string $item_id The id of the item you need information for. * @return object Details for the given item. */ public function item_details($item_id) { $url = preg_replace('/set/i', 'item:' . $item_id, $this->public_url); return $this->fetch($url, 'item'); } /** * Returns new files from a specific marketplaces and category. * * @param string $marketplace_name The desired marketplace name. * @param string $category The name of the category you'd like to search. * @param int $limit The number of files to return. * @return array A list of ALL recent files. */ public function new_files($marketplace_name = 'themeforest', $category = 'wordpress', $limit = null) { $url = preg_replace('/set/i', 'new-files:' . $marketplace_name . ',' . $category, $this->public_url); $results = $this->fetch($url, 'new-files'); if ($results) { return $this->apply_limit($results, $limit); } } /** * Similar to new_files, but focuses on a specific author's files. * * @param string $user_name The desired username. * @param string $marketplace_name The desired marketplace name. * @param int $limit The number of files to return. * @return array A list of recently added files by one user. */ public function new_files_from_user($user_name, $marketplace_name = 'themeforest', $limit = null) { $cache_path = "$this->cache_dir/$user_name-$marketplace_name-new_files"; $url = preg_replace('/set/i', 'new-files-from-user:' . $user_name . ',' . $marketplace_name, $this->public_url); return $this->apply_limit($this->fetch($url, 'new-files-from-user'), $limit); } /** * Helper function which automatically echos out a list of thumbnails * + links. Use new_files_from_user for more control. * * @param string $user_name The username of the account you want to display * thumbnails from. * @param string $marketplace_name The desired marketplace name. * @param int $limit The number of thumbnails to display. * @return string Helper function immediately echos out thumbnails. * Careful... */ public function display_thumbs($user_name, $marketplace_name, $limit = null) { $results = $this->new_files_from_user($user_name, $marketplace_name, $limit); echo "
";
print_r($data);
echo "";
}
public function configExists() {
if (file_exists(__DIR__ . '/../dbconfig.php')) {
return true;
} else {
return false;
}
}
}