Set("popular"); $envato->Set_Category($atts["category"]); $envato->Display_Items(); } /** * Get featured envato files * * @param $atts - Attributes in the shortcode * @param $content - Content in shortcode can be null */ function paulund_envato_features_function( $atts, $content = null ){ $envato = new Paulund_Envato($atts); $envato->Set("features"); $envato->Set_Category($atts["category"]); $envato->Display_Items(); } /** * Get new envato files * * @param $atts - Attributes in the shortcode * @param $content - Content in shortcode can be null */ function paulund_envato_new_files_function( $atts, $content = null ){ $envato = new Paulund_Envato($atts); $envato->Set("new-files"); $envato->Display_Items(); } /** * Get new envato files for user * * @param $atts - Attributes in the shortcode * @param $content - Content in shortcode can be null */ function paulund_envato_new_files_from_user_function( $atts, $content = null ){ $envato = new Paulund_Envato($atts); $envato->Set("new-files-from-user"); $envato->Display_Items(); } /** * Get random new envato files * * @param $atts - Attributes in the shortcode * @param $content - Content in shortcode can be null */ function paulund_envato_random_new_files_function( $atts, $content = null ){ $envato = new Paulund_Envato($atts); $envato->Set("random-new-files"); $envato->Display_Items(); } /** * Get specific envato file item * * @param $atts - Attributes in the shortcode * @param $content - Content in shortcode can be null */ function paulund_envato_item_function ( $atts, $content = null ){ $envato = new Paulund_Envato($atts); $envato->Set("item"); $envato->Display_Items(); } /** * Get envato files for specific user * * @param $atts - Attributes in the shortcode * @param $content - Content in shortcode can be null */ function paulund_envato_user_function( $atts, $content = null ){ $envato = new Paulund_Envato($atts); $envato->Set("user"); $envato->Display_Items(); } /** * The class wrapper for envato API */ class Paulund_Envato{ /** * Shortcode attributes */ private $atts = FALSE; /** * The API URL */ private $url = FALSE; /** * All items */ private $items = FALSE; /** * Set debug mode */ private $debug = FALSE; /** * Constructor for wrapper class * * @param $atts - Shortcode attributes */ public function __construct( $atts ){ // Set default attributes $this->atts = shortcode_atts(array( 'marketplace' => '', 'set' => '', 'category' => '', 'limit' => '', 'id' => '', 'user' => '', 'search' => '', 'ref' => 'paulund', 'buttontext' => 'Buy Now', 'displaytitle' => 'true', 'displayimage' => 'true', 'displaysales' => '', 'displayrating' => '', 'displaycost' => 'true', 'displaytags' => '', 'displaycategory' => '', 'displaynumberfiles'=> '', 'displaybutton' => 'true', 'debug' => 'false'), $atts); // If debug mode is on set class field to true if($this->atts["debug"] == 'true'){ $this->debug = TRUE; } } /** * Defines which set of files we want * * @param $set - Set of files */ public function Set( $set ){ $this->atts["set"] = $set; } /** * Defines which category we want from set of files * Used on searches such as popular which return popular last week, popular last 3 months and popular authors * * @param $category - Defines category */ public function Set_Category( $category ){ $this->atts["category"] = $category; } /** * Works out the URL to call by the attributes sent */ private function Set_Url( $format = ".json"){ $url = "http://marketplace.envato.com/api/edge/"; if( $this->atts["set"] != "" ){ $url .= $this->atts["set"]; } if( $this->atts["marketplace"] != "" ){ $url .= ":".$this->atts["marketplace"]; } if( $this->atts["id"] != "" ){ $url .= ":".$this->atts["id"]; } $url .= $format; $this->url = $url; } /** * The main method for the class which will set the url, get the items, parse the items and display each items */ public function Display_Items(){ // Set the URL $this->Set_Url(); // Display debug messages if($this->debug){ echo 'Start Display Items'; echo '
';
			print_r($this->atts);
			echo '
'; } // Extract the variables from array extract($this->atts); // Make sure that at least one of these are set if( $id == '' && $marketplace == '' && $set == ''){ return; } // Get the items $this->Get_Items(); // Parse the correct category $this->Parse_Category(); // Displays each item $this->Display_Each_Item(); } /** * Uses the Wordpress remote get function to return the json items */ public function Get_Items(){ // Get items as json $json = wp_remote_get( $this->url ); // Display debug messages if($this->debug){ echo 'Get Items'; echo 'URL - '.$this->url; echo '
';
			print_r($json);
			echo '
'; } // Set the items variable with the body of the json $this->items = json_decode($json["body"], true); } /** * Parse the items to get exactly the data we want */ private function Parse_Category(){ // Display debug messages if($this->debug){ echo 'Parse Category'; echo '
';
			print_r($this->atts);
			print_r($parsed_items);
			echo '
'; } // Set the items $items = $this->items; // Get the set of items we want if($this->atts["set"] != ""){ $parsed_items = $items[$this->atts["set"]]; } // Get the category of items we want if($this->atts["category"] != ""){ $parsed_items = $parsed_items[$this->atts["category"]]; } // Limit the items to the amount we want back if($this->atts["limit"] != ""){ $parsed_items = array_slice($parsed_items, 0, $this->atts["limit"]); } // Display the parsed items if($this->debug){ echo 'End Parse Category Display Items'; echo '
';
			print_r($parsed_items);
			echo '
'; } // Set the items variable to the new parsed items $this->items = $parsed_items; } /** * Loop through all of the items to display each item */ private function Display_Each_Item(){ // Display the debug messages if($this->debug){ echo 'Display Each Items'; echo '
';
			print_r($this->items);
			echo '
'; } // Set the attributes variable $atts = $this->atts; // Make sure that the items are inside an array if(!is_array($this->items[0])){ $this->items = array($this->items); } // Loop through all items to display on the page foreach($this->items as $item){ $url = $item["url"]."?ref=".$atts["ref"]; ?>

<?php echo $item[" />

Total Sales:

Rating: out of 5

Price: $

Tags:

Category:

Number Of Files: