• 1.
    <?php
  • 2.
     
  • 3.
        /*
  • 4.
         *
  • 5.
         *	Envato API Wrapper Class
  • 6.
         *	
  • 7.
         *	@Author : Roland Groza
  • 8.
         *	@Description :
  • 9.
         *
  • 10.
         *	@Features : [
  • 11.
         *         
  • 12.
         *  ]
  • 13.
         *
  • 14.
         *	@Category : PHP Class
  • 15.
         *	@Copyright : Copyright 2013 Roland Groza [ http://rolandgroza.me ]
  • 16.
         *	@Version : 2.0
  • 17.
         *	@Created : January 2013
  • 18.
         *
  • 19.
         */
  • 20.
        
  • 21.
        namespace Envato {
  • 22.
     
  • 23.
            /*
  • 24.
             *  Curl Trait
  • 25.
            */
  • 26.
     
  • 27.
            trait Curl {
  • 28.
     
  • 29.
     
  • 30.
                /*
  • 31.
                 *  Set Global Trait Variables
  • 32.
                 *
  • 33.
                 *  @variables : [
  • 34.
                 *      
  • 35.
                 *      #certificate [ Protected ] ~ set the path to the Envato SSL Certificate, used in order to verify the curl request
  • 36.
                 *      #verify_cert [ Protected ] ~ if true, the connection will be secured ( the certificate is required ) otherwise the connection will opened without verification
  • 37.
                 *  ]
  • 38.
                */        
  • 39.
     
  • 40.
                protected $certificate = "/certificate/";
  • 41.
                protected $verify_cert = false;
  • 42.
     
  • 43.
     
  • 44.
                /*
  • 45.
                 *  Curl GET Method
  • 46.
                 *
  • 47.
                 *  @arguments : [
  • 48.
                 *      
  • 49.
                 *      #url ~ the url is required, based on it the necessary data is grabbed
  • 50.
                 *  ]
  • 51.
                 *  @returns : [ data fetched from the url ]
  • 52.
                */
  • 53.
     
  • 54.
                public function curl_get($url) {
  • 55.
     
  • 56.
                    if(empty($url)) {
  • 57.
                        return false;
  • 58.
                    };
  • 59.
     
  • 60.
                    $channel = curl_init($url);
  • 61.
     
  • 62.
                    curl_setopt($channel, CURLOPT_RETURNTRANSFER, 1);
  • 63.
     
  • 64.
                    $this->curl_verify_cert($channel);
  • 65.
                   
  • 66.
                    curl_setopt($channel, CURLOPT_CUSTOMREQUEST, "GET");
  • 67.
     
  • 68.
                    $result = curl_exec($channel);
  • 69.
     
  • 70.
                    if(curl_errno($channel)) {
  • 71.
                        return $result = 0;
  • 72.
                    };
  • 73.
     
  • 74.
                    curl_close($channel);
  • 75.
     
  • 76.
                    return $result;
  • 77.
                }
  • 78.
                
  • 79.
     
  • 80.
                /*
  • 81.
                 *  Curl Verify Certification
  • 82.
                 *
  • 83.
                 *  @arguments : [
  • 84.
                 *      
  • 85.
                 *      #curl ~ the curl request
  • 86.
                 *  ]
  • 87.
                 *  @returns : [ an option for curl to verify or not the connection ]
  • 88.
                */
  • 89.
     
  • 90.
                public function curl_verify_cert($curl) {
  • 91.
     
  • 92.
                    $files = [];
  • 93.
                    $certificate_url = "";
  • 94.
     
  • 95.
                    if ($this->verify_cert) {
  • 96.
     
  • 97.
                        $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . $this->certificate), RecursiveIteratorIterator::SELF_FIRST);
  • 98.
     
  • 99.
                        foreach ($iterator as $key => $value) {
  • 100.
                            array_push($files, $value->__toString());
  • 101.
                        };
  • 102.
                        unset($value);   
  • 103.
     
  • 104.
     
  • 105.
                        if (is_array($files) && !empty($files) && count($files) === 1) {
  • 106.
                            $certificate_url = $files[0];
  • 107.
                        } else {
  • 108.
                            return json_encode("[ Verify Certificate [ Failed ] | Certificate Missing ]", JSON_FORCE_OBJECT);
  • 109.
                        };
  • 110.
     
  • 111.
                        if (preg_match("/\\\\/", $certificate_url)) {
  • 112.
                            $certificate_url = preg_replace("/\\\\/", "/", $certificate_url);
  • 113.
                        };
  • 114.
     
  • 115.
                        return curl_setopt_array($curl, [ CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CAINFO => $certificate_url ]);
  • 116.
     
  • 117.
                    } else {
  • 118.
                        return curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  • 119.
                    };
  • 120.
                }
  • 121.
            }
  • 122.
     
  • 123.
     
  • 124.
            /*
  • 125.
             *  Fetch Trait
  • 126.
             *
  • 127.
            */
  • 128.
     
  • 129.
            trait Fetch {
  • 130.
     
  • 131.
     
  • 132.
                /*
  • 133.
                 * Use Curl Methods
  • 134.
                */
  • 135.
     
  • 136.
                use Curl {
  • 137.
                    curl_get as protected;
  • 138.
                }
  • 139.
     
  • 140.
     
  • 141.
                /*
  • 142.
                 *  Fetch Method | Fetch Data / Return Decoded JSON
  • 143.
                 *
  • 144.
                 *  @arguments : [
  • 145.
                 *      
  • 146.
                 *      #url ~ the url is required, based on it the necessary data is grabbed
  • 147.
                 *  ]
  • 148.
                 *  @returns : [ returns decoded data ]
  • 149.
                */
  • 150.
     
  • 151.
                public function fetch($url, $set = null) {
  • 152.
     
  • 153.
                    $_action = [];
  • 154.
                    $_result = [];
  • 155.
     
  • 156.
                    switch (empty($url)) {
  • 157.
                        case false:
  • 158.
                            
  • 159.
                            switch (is_null($set)) {
  • 160.
                                case false:
  • 161.
                                    
  • 162.
                                    $_action = json_decode($this->curl_get($url));
  • 163.
     
  • 164.
                                    if ( is_array($_action) || is_object($_action) && array_key_exists("error", $_action) ) {
  • 165.
                                        $_result = [
  • 166.
                                            "Error" => true,
  • 167.
                                            "Description" => ( is_array($_action) ) ? $_action["error"] : $_action->error 
  • 168.
                                        ];
  • 169.
                                    } else {
  • 170.
                                        $_result = $_action->$set;
  • 171.
                                    };
  • 172.
     
  • 173.
                                    break;
  • 174.
                                case true:
  • 175.
                                default:
  • 176.
                                    $_result = json_decode($this->curl_get($url));
  • 177.
                                    break;
  • 178.
                            };
  • 179.
     
  • 180.
                            break;
  • 181.
                        case true:
  • 182.
                            $_result = "Fetch Data [ Failed ] | Provide URL";
  • 183.
                            break;
  • 184.
                        default:
  • 185.
                            break;
  • 186.
                    };
  • 187.
     
  • 188.
                    return $_result;
  • 189.
                }
  • 190.
            }
  • 191.
     
  • 192.
     
  • 193.
            /*
  • 194.
             *  Utils Trait | Small PHP Utility
  • 195.
            */
  • 196.
     
  • 197.
            trait Utils {
  • 198.
     
  • 199.
     
  • 200.
                /*
  • 201.
                 * Use Fetch Methods
  • 202.
                */
  • 203.
     
  • 204.
                use Fetch {
  • 205.
                    fetch as protected;
  • 206.
                }
  • 207.
     
  • 208.
     
  • 209.
                /*
  • 210.
                 *  Remove Array Duplicate Values
  • 211.
                 *
  • 212.
                 *  @arguments : [
  • 213.
                 *      
  • 214.
                 *      #array ~ the array to run the function against
  • 215.
                 *      #flags ~ the type of array values, can be Regular, Numeric, String or Locale
  • 216.
                 *  ]
  • 217.
                 *  @returns : [ returns the sorted array ]
  • 218.
                */
  • 219.
     
  • 220.
                public function array_unique_values($array, $flags) {
  • 221.
     
  • 222.
                    $f_array = [];
  • 223.
                    $parsed = [];
  • 224.
     
  • 225.
                    $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
  • 226.
     
  • 227.
                    foreach ($iterator as $key => $value) {
  • 228.
                        array_push($parsed, $value);
  • 229.
                    };
  • 230.
                    unset($value);
  • 231.
     
  • 232.
                    switch (gettype($flags)) {
  • 233.
                        case 'string':
  • 234.
                            
  • 235.
                            switch (strtolower($flags)) {
  • 236.
                                case 'regular':
  • 237.
                                    return array_unique($parsed, SORT_REGULAR);
  • 238.
                                case 'numeric':
  • 239.
                                    return array_unique($parsed, SORT_NUMERIC);
  • 240.
                                case 'string':
  • 241.
                                    return array_unique($parsed, SORT_STRING);
  • 242.
                                case 'locale':
  • 243.
                                    return array_unique($parsed, SORT_LOCALE_STRING);
  • 244.
                                default:
  • 245.
                                    return $this->json_encode_as_object("Array Unique Values [ Flag : ". $flags ." Inexistent]");
  • 246.
                            };
  • 247.
     
  • 248.
                            break;
  • 249.
                        case 'array':
  • 250.
     
  • 251.
                            foreach ($flags as $key => $flag) {
  • 252.
                                
  • 253.
                                switch (strtolower($flag)) {
  • 254.
                                    case 'regular':
  • 255.
                                        array_push($f_array, SORT_REGULAR);
  • 256.
                                        break;
  • 257.
                                    case 'numeric':
  • 258.
                                        array_push($f_array, SORT_NUMERIC);
  • 259.
                                        break;
  • 260.
                                    case 'string':
  • 261.
                                        array_push($f_array, SORT_STRING);
  • 262.
                                        break;
  • 263.
                                    case 'locale':
  • 264.
                                        array_push($f_array, SORT_LOCALE_STRING);
  • 265.
                                        break;
  • 266.
                                    default:
  • 267.
                                        return $this->json_encode_as_object("Array Unique Values [ Flag : ". $flags ." Inexistent]");
  • 268.
                                };
  • 269.
     
  • 270.
                            };
  • 271.
                            unset($flag);
  • 272.
     
  • 273.
                            return array_unique($parsed, $f_array);
  • 274.
                        default:
  • 275.
                            break;
  • 276.
                    };
  • 277.
                }
  • 278.
     
  • 279.
     
  • 280.
                /*
  • 281.
                 *  Remove Array Duplicates | Recursivelly | Multidimensional Arrays
  • 282.
                 *
  • 283.
                 *  @arguments : [
  • 284.
                 *      
  • 285.
                 *      #array ~ the array to run the function against
  • 286.
                 *  ]
  • 287.
                 *  @returns : [ returns the sorted array ]
  • 288.
                */
  • 289.
     
  • 290.
                public function array_unique_multidimensional($array) {
  • 291.
     
  • 292.
                    $result = array_map("unserialize", array_unique(array_map("serialize", $array)));
  • 293.
     
  • 294.
                    foreach ($result as $key => $value) {
  • 295.
                        
  • 296.
                        if ( is_array($value) ) {
  • 297.
                            $result[$key] = $this->array_unique_multidimensional($value);
  • 298.
                        };
  • 299.
     
  • 300.
                    };
  • 301.
                    unset($value);
  • 302.
     
  • 303.
                    return $result;
  • 304.
                }
  • 305.
     
  • 306.
                /*
  • 307.
                 *  Encode Array to JSON | Force Conversion
  • 308.
                 *
  • 309.
                 *  @arguments : [
  • 310.
                 *      
  • 311.
                 *      #array ~ the array to run the conversion against
  • 312.
                 *  ]
  • 313.
                 *  @returns : [ returns encoded json ]
  • 314.
                */
  • 315.
     
  • 316.
                public function json_encode_as_object($array) {
  • 317.
                    return json_encode($array, JSON_FORCE_OBJECT);
  • 318.
                }
  • 319.
     
  • 320.
     
  • 321.
                /*
  • 322.
                 *  Strip Spaces
  • 323.
                 *
  • 324.
                 *  @arguments : [
  • 325.
                 *      
  • 326.
                 *      #string ~ a string which will be stripped of all spaces between characters
  • 327.
                 *  ]
  • 328.
                 *  @returns : [ returns a string stripped of spaces ]
  • 329.
                */
  • 330.
     
  • 331.
                public function strip_spaces($string) {
  • 332.
                    return trim(preg_replace( '/\s+/', '', $string ));
  • 333.
                }
  • 334.
     
  • 335.
     
  • 336.
                /*
  • 337.
                 *  Get Function Arguments
  • 338.
                 *
  • 339.
                 *  @arguments : [
  • 340.
                 *      
  • 341.
                 *      ~ accepts as many arguments as you want, the arguments can be strings or arrays of strings, the strings if containing white spaces (space, tab, new line, etc) and commas will also be read as arguments
  • 342.
                 *  ]
  • 343.
                 *  @returns : [ an array of unique arguments ]
  • 344.
                */
  • 345.
     
  • 346.
                public function filter_arguments_recursive($arguments, $arguments_count) {
  • 347.
     
  • 348.
                    $iterator = [];
  • 349.
                    $args = [];
  • 350.
                    $args_count = [];
  • 351.
                    $temporary = [];
  • 352.
     
  • 353.
                    switch ($arguments_count) {
  • 354.
                        case 0:
  • 355.
                            exit("[ Get Function Arguments | Argument Missing ]");
  • 356.
                        case 1:
  • 357.
                        default:
  • 358.
                            
  • 359.
                            $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($arguments));
  • 360.
     
  • 361.
                            foreach ($iterator as $key => $value) {
  • 362.
                                array_push($args, $value);
  • 363.
                            };
  • 364.
                            unset($value);
  • 365.
     
  • 366.
                            $args_count = count($args);
  • 367.
     
  • 368.
                            foreach ($args as $key => $arg) {
  • 369.
                                array_push($temporary, preg_split("/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|" . "[\s,]*'([^']+)'[\s,]*|" . "[\s,]+/", $arg, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE));
  • 370.
     
  • 371.
                                if ($args_count - 1 === $key) {
  • 372.
                                    $args = [];
  • 373.
                                    array_push($args, $this->array_unique_values($temporary, "String"));
  • 374.
                                };
  • 375.
                            };
  • 376.
                            unset($arg);
  • 377.
     
  • 378.
                            return array_map('array_values', $args)[0];
  • 379.
                    };
  • 380.
                }
  • 381.
            }
  • 382.
     
  • 383.
     
  • 384.
     
  • 385.
            interface IEnvato {
  • 386.
     
  • 387.
                public function set_api_key($api_key);
  • 388.
                public function get_api_key();
  • 389.
                public function get_user_vitals();
  • 390.
                public function get_earnings_and_sales_by_month();
  • 391.
                public function get_statement();
  • 392.
                public function get_recent_sales();
  • 393.
                public function get_account_info();
  • 394.
                public function verify_purchase();
  • 395.
                public function download_purchase();
  • 396.
                public function get_blog_posts();
  • 397.
                public function get_active_threads();
  • 398.
                public function get_number_of_files();
  • 399.
                public function get_popular_files();
  • 400.
                public function get_releases();
  • 401.
                public function get_thread_status();
  • 402.
                public function get_collection();
  • 403.
                public function get_featured_items();
  • 404.
                public function get_new_files_from_market();
  • 405.
                public function get_new_files_from_user();
  • 406.
                public function get_random_new_files();
  • 407.
                public function get_total_users();
  • 408.
                public function get_item_details();
  • 409.
                public function get_item_prices();
  • 410.
                public function get_search_results($expression, $marketplace, $category);
  • 411.
                public function get_user_info();
  • 412.
                public function get_user_items_by_site();
  • 413.
            }
  • 414.
     
  • 415.
     
  • 416.
            /*
  • 417.
             *  Envato Class | Envato API Wrapper Class
  • 418.
            */
  • 419.
     
  • 420.
            class EnvatoAPIWrapper implements IEnvato {
  • 421.
     
  • 422.
     
  • 423.
                /*
  • 424.
                 * Use Fetch Methods
  • 425.
                */
  • 426.
     
  • 427.
                use Utils {
  • 428.
                    fetch as protected;
  • 429.
                }
  • 430.
     
  • 431.
     
  • 432.
                /*
  • 433.
                 *  Set Global Class Variables
  • 434.
                 *
  • 435.
                 *  @variables : [
  • 436.
                 *      
  • 437.
                 *      #api_key [ Protected ] ~ set API key necessary for fetching private user data
  • 438.
                 *      #public_url [ Protected ] ~ set API public URL from which all data is fetched
  • 439.
                 *      #methods [ Protected ] ~ set all the methods available in the API
  • 440.
                 *  ]
  • 441.
                */
  • 442.
     
  • 443.
           	    protected $api_key;
  • 444.
                protected $public_url = "http://marketplace.envato.com/api/v3/set.json";
  • 445.
     
  • 446.
                protected $methods = [
  • 447.
     
  • 448.
                    "Public" => ["blog-posts", "active-threads", "number-of-files", "popular", "releases", "thread-status", "collection", "features", "new-files", "new-files-from-user", "random-new-files", "total-users", "item", "item-prices", "search", "user", "user-items-by-site"],
  • 449.
     
  • 450.
                    "Private" => ["vitals", "earnings-and-sales-by-month", "statement", "recent-sales", "account", 'verify-purchase', "download-purchase"]
  • 451.
                ];
  • 452.
     
  • 453.
     
  • 454.
                /*
  • 455.
                 *  Class Constructor
  • 456.
                 *
  • 457.
                 *  @arguments : [
  • 458.
                 *      
  • 459.
                 *      #api_key ~ API key necessary for fetching private user data 
  • 460.
                 *  ]
  • 461.
                 *  @returns : [ sets API key necessary for fetching private user data ]
  • 462.
                */
  • 463.
     
  • 464.
                public function __construct($api_key = null) {
  • 465.
                    
  • 466.
                    if(isset($api_key) ) {
  • 467.
                        $this->api_key = $api_key;
  • 468.
                    };
  • 469.
                }
  • 470.
     
  • 471.
     
  • 472.
                /*
  • 473.
                 *  Set API Key
  • 474.
                 *
  • 475.
                 *  @arguments : [
  • 476.
                 *      
  • 477.
                 *      #api_key ~ API key necessary for fetching private user data 
  • 478.
                 *  ]
  • 479.
                 *  @returns : [ sets API key necessary for fetching private user data ]
  • 480.
                */
  • 481.
     
  • 482.
                public function set_api_key($api_key) {
  • 483.
                    return $this->api_key = $api_key;
  • 484.
                }
  • 485.
     
  • 486.
     
  • 487.
                /*
  • 488.
                 *  Get API Key
  • 489.
                 *
  • 490.
                 *  @arguments : [
  • 491.
                 *      
  • 492.
                 *  ]
  • 493.
                 *  @returns : [ returns API key necessary for fetching private user data or asks for an API key]
  • 494.
                */
  • 495.
     
  • 496.
                public function get_api_key() {
  • 497.
     
  • 498.
                    if(isset($this->api_key) ) {
  • 499.
                        return $this->json_encode_as_object([
  • 500.
                            "API" => $this->api_key
  • 501.
                        ]);
  • 502.
                    } else {
  • 503.
                        return $this->json_encode_as_object("[ API [ Missing ] | Set API ]");
  • 504.
                    };
  • 505.
                }
  • 506.
     
  • 507.
     
  • 508.
                /*
  • 509.
                 *  Get Private User Data
  • 510.
                 *
  • 511.
                 *  @arguments : [
  • 512.
                 *      
  • 513.
                 *      #username ~ the username based upon the data is fetched
  • 514.
                 *      #set ~ the type of data that is required to be fetched
  • 515.
                 *      #purchase_code ~ used to check if a buyer purchased an item, not required if the method isn't verifying purchase or download purchase
  • 516.
                 *  ]
  • 517.
                 *  @returns : [ returns fetched data ]
  • 518.
                */
  • 519.
     
  • 520.
                private function get_private_user_data($username, $set, $purchase_code = null) {
  • 521.
     
  • 522.
                    if(!isset($this->api_key)) {
  • 523.
                        return $this->json_encode_as_object("[ API [ Missing ] | Set API ]");
  • 524.
                    };
  • 525.
     
  • 526.
                    if(!isset($set)) {
  • 527.
                        return $this->json_encode_as_object("[ User Data [ Private ] | Set : ". $set ." [ Undefined ] ]");
  • 528.
                    };
  • 529.
     
  • 530.
                    $url = preg_replace('/set/i', $username . "/" . $this->api_key . "/" . $set, $this->public_url);
  • 531.
     
  • 532.
                    if(!is_null($purchase_code)) {
  • 533.
                        $url = preg_replace('/'. $set . '/i', $set . ":$purchase_code", $url);
  • 534.
                    };
  • 535.
     
  • 536.
                    return $this->fetch($url, $set);
  • 537.
                }
  • 538.
     
  • 539.
     
  • 540.
                /*
  • 541.
                 *  Get User Vitals
  • 542.
                 *
  • 543.
                 *  @arguments : [
  • 544.
                 *      
  • 545.
                 *      #username ~ the username based upon the data is fetched
  • 546.
                 *  ]
  • 547.
                 *  @returns : [ returns user vitals ( balance and username ) ]
  • 548.
                */
  • 549.
     
  • 550.
                public function get_user_vitals() {
  • 551.
     
  • 552.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 553.
                    $set = $this->methods["Private"][0];
  • 554.
     
  • 555.
                    return $this->json_encode_as_object([
  • 556.
                        "User" => [
  • 557.
                            "Vitals" => $this->get_private_user_data($arguments[0], $set)
  • 558.
                        ]
  • 559.
                    ]);
  • 560.
                }
  • 561.
     
  • 562.
     
  • 563.
                /*
  • 564.
                 *  Get Earnings & Sales
  • 565.
                 *
  • 566.
                 *  @arguments : [
  • 567.
                 *      
  • 568.
                 *      #username ~ the username based upon the data is fetched
  • 569.
                 *  ]
  • 570.
                 *  @returns : [ returns user earnings and sales by month ]
  • 571.
                */
  • 572.
     
  • 573.
                public function get_earnings_and_sales_by_month() {
  • 574.
     
  • 575.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 576.
                    $set = $this->methods["Private"][1];
  • 577.
     
  • 578.
                    return $this->json_encode_as_object([
  • 579.
                        "User" => [
  • 580.
                            "Transactions" => $this->get_private_user_data($arguments[0], $set)
  • 581.
                        ]
  • 582.
                    ]);
  • 583.
                }
  • 584.
     
  • 585.
     
  • 586.
                /*
  • 587.
                 *  Get Statement
  • 588.
                 *
  • 589.
                 *  @arguments : [
  • 590.
                 *      
  • 591.
                 *      #username ~ the username based upon the data is fetched
  • 592.
                 *  ]
  • 593.
                 *  @returns : [ returns user statement ]
  • 594.
                */
  • 595.
     
  • 596.
                public function get_statement() {
  • 597.
     
  • 598.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 599.
                    $set = $this->methods["Private"][2];
  • 600.
     
  • 601.
                    return $this->json_encode_as_object([
  • 602.
                        "User" => [
  • 603.
                            "Statement" => $this->get_private_user_data($arguments[0], $set)
  • 604.
                        ]
  • 605.
                    ]);
  • 606.
                }
  • 607.
     
  • 608.
     
  • 609.
                /*
  • 610.
                 *  Get Recent Sales
  • 611.
                 *
  • 612.
                 *  @arguments : [
  • 613.
                 *      
  • 614.
                 *      #username ~ the username based upon the data is fetched
  • 615.
                 *  ]
  • 616.
                 *  @returns : [ returns user's recent sales ]
  • 617.
                */
  • 618.
     
  • 619.
                public function get_recent_sales() {
  • 620.
     
  • 621.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 622.
                    $set = $this->methods["Private"][3];
  • 623.
     
  • 624.
                    return $this->json_encode_as_object([
  • 625.
                        "User" => [
  • 626.
                            "Sales" => $this->get_private_user_data($arguments[0], $set)
  • 627.
                        ]
  • 628.
                    ]);
  • 629.
                }
  • 630.
     
  • 631.
     
  • 632.
                /*
  • 633.
                 *  Get Account Information
  • 634.
                 *
  • 635.
                 *  @arguments : [
  • 636.
                 *      
  • 637.
                 *      #username ~ the username based upon the data is fetched
  • 638.
                 *  ]
  • 639.
                 *  @returns : [ returns user account information ]
  • 640.
                */
  • 641.
     
  • 642.
                public function get_account_info() {
  • 643.
     
  • 644.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 645.
                    $set = $this->methods["Private"][4];
  • 646.
                
  • 647.
                    return $this->json_encode_as_object([
  • 648.
                        "User" => [
  • 649.
                            "Information" => $this->get_private_user_data($arguments[0], $set)
  • 650.
                        ]
  • 651.
                    ]);
  • 652.
                }
  • 653.
     
  • 654.
     
  • 655.
                /*
  • 656.
                 *  Verify Purchase | Requires User's Purchase Code / Own API Key / Own Username
  • 657.
                 *
  • 658.
                 *  @arguments : [
  • 659.
                 *      
  • 660.
                 *      #username ~ the username based upon the data is fetched
  • 661.
                 *      #purchase_code ~ used to check if a buyer purchased an item
  • 662.
                 *  ]
  • 663.
                 *  @returns : [
  • 664.
                 *
  • 665.
                 *      {
  • 666.
                 *          Item {
  • 667.
                 *              Verified : {
  • 668.
                 *                  "buyer" : "buyer_id_here",
  • 669.
                 *                  "created_at" : "Wed Dec 01 05:00:47 +1100 2010",
  • 670.
                 *                  "licence" : "Regular Licence",
  • 671.
                 *                  "item_name" : "Your Item Name Here",
  • 672.
                 *                  "item_id" : "116430"
  • 673.
                 *              }
  • 674.
                 *          }
  • 675.
                 *      }
  • 676.
                 *      {
  • 677.
                 *          Item {
  • 678.
                 *              Verified : false
  • 679.
                 *          }
  • 680.
                 *      }
  • 681.
                 *  ]
  • 682.
                */
  • 683.
     
  • 684.
                public function verify_purchase() {
  • 685.
     
  • 686.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 687.
                    $verified = [];
  • 688.
                    $set = $this->methods["Private"][5];
  • 689.
     
  • 690.
                    if(empty($arguments[1])) {
  • 691.
                       return "[ Download Purchase [ Failed ] | Set Purchase Code ]";
  • 692.
                    };
  • 693.
     
  • 694.
                    $validity = $this->get_private_user_data($arguments[0], $set, $arguments[1]);
  • 695.
                    
  • 696.
                    if (is_array($validity) || is_object($validity) && array_key_exists("item_id", $validity)) {
  • 697.
                        $verified = $validity;
  • 698.
                    } else {
  • 699.
                        $verified = false;
  • 700.
                    };
  • 701.
     
  • 702.
                    return $this->json_encode_as_object([
  • 703.
                        "Item" => [
  • 704.
                            "Verified" => $verified
  • 705.
                        ]
  • 706.
                    ]);
  • 707.
                }
  • 708.
     
  • 709.
     
  • 710.
                /*
  • 711.
                 *  Download Purchase | Requires User's Purchase Code / User's API Key / User's Username
  • 712.
                 *
  • 713.
                 *  @arguments : [
  • 714.
                 *      
  • 715.
                 *      #username ~ the username based upon the data is fetched
  • 716.
                 *      #purchase_code ~ used to check if a buyer purchased an item
  • 717.
                 *  ]
  • 718.
                 *  @returns : [
  • 719.
                 *      
  • 720.
                 *      {
  • 721.
                 *          Item {
  • 722.
                 *              Download : {
  • 723.
                 *                  "download_url": "http://s3.amazonaws.com/marketplace-downloads.envato.com/files/123456/blablabla.zip?AWSAccessKeyId=blablabla\u0026Expires=123456789\u0026Signature=foobarfoobar\u0026response-content-disposition=attachment;%20filename=blablabla.zip"
  • 724.
                 *              }
  • 725.
                 *          }
  • 726.
                 *      }
  • 727.
                 *      {
  • 728.
                 *          Item {
  • 729.
                 *              Download : false
  • 730.
                 *          }
  • 731.
                 *      }
  • 732.
                 *  ]
  • 733.
                */
  • 734.
     
  • 735.
                public function download_purchase() {
  • 736.
     
  • 737.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 738.
                    $download = [];
  • 739.
                    $set = $this->methods["Private"][6];
  • 740.
     
  • 741.
                    if(empty($arguments[1])) {
  • 742.
                       return "[ Download Purchase [ Failed ] | Set Purchase Code [ 1 +  Required ] ]";
  • 743.
                    };
  • 744.
     
  • 745.
                    $validity = $this->get_private_user_data($arguments[0], $set, $arguments[1]);
  • 746.
     
  • 747.
                    if (is_array($validity) || is_object($validity) && array_key_exists("download_url", $validity)) {
  • 748.
                        $download = $validity;
  • 749.
                    } else {
  • 750.
                        $download = false;
  • 751.
                    };
  • 752.
     
  • 753.
                    return $this->json_encode_as_object([
  • 754.
                        "Item" => [
  • 755.
                            "Download" => $download
  • 756.
                        ]
  • 757.
                    ]);
  • 758.
                }
  • 759.
     
  • 760.
                
  • 761.
                /*
  • 762.
                 *  Get Blog Posts
  • 763.
                 *
  • 764.
                 *  @arguments : [
  • 765.
                 *      
  • 766.
                 *      #marketplace ~ the marketplace ( or marketplaces ) based upon the data is fetched
  • 767.
                 *  ]
  • 768.
                 *  @returns : [ returns the marketplace's blog posts ]
  • 769.
                */
  • 770.
     
  • 771.
                public function get_blog_posts() {
  • 772.
     
  • 773.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 774.
                    $blog_posts = [];
  • 775.
                    $set = $this->methods["Public"][0];
  • 776.
                    $public_url = $this->public_url;
  • 777.
     
  • 778.
                    foreach ($arguments as $key => $argument) {
  • 779.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 780.
                        array_push($blog_posts, $this->fetch($url, $set));
  • 781.
                    };
  • 782.
                    unset($argument);
  • 783.
     
  • 784.
                    return $this->json_encode_as_object([
  • 785.
                        "Blog" => [
  • 786.
                            "Posts" => ( count($arguments) === 1 ) ? $blog_posts[0] : $blog_posts
  • 787.
                        ]
  • 788.
                    ]);
  • 789.
                }
  • 790.
     
  • 791.
     
  • 792.
                /*
  • 793.
                 *  Get Blog Active Threads
  • 794.
                 *
  • 795.
                 *  @arguments : [
  • 796.
                 *      
  • 797.
                 *      #marketplace ~ the marketplace ( or marketplaces ) based upon the data is fetched
  • 798.
                 *  ]
  • 799.
                 *  @returns : [ returns the marketplace's blog active threads ]
  • 800.
                */
  • 801.
     
  • 802.
                public function get_active_threads() {
  • 803.
     
  • 804.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 805.
                    $blog_threads = [];
  • 806.
                    $set = $this->methods["Public"][1];
  • 807.
                    $public_url = $this->public_url;
  • 808.
     
  • 809.
                    foreach ($arguments as $key => $argument) {
  • 810.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 811.
                        array_push($blog_threads, $this->fetch($url, $set));
  • 812.
                    };
  • 813.
                    unset($argument);
  • 814.
     
  • 815.
                    return $this->json_encode_as_object([
  • 816.
                        "Blog" => [
  • 817.
                            "ActiveThreads" => ( count($arguments) === 1 ) ? $blog_threads[0] : $blog_threads
  • 818.
                        ]
  • 819.
                    ]);
  • 820.
                }
  • 821.
     
  • 822.
     
  • 823.
                /*
  • 824.
                 *  Get Marketplace File Count
  • 825.
                 *
  • 826.
                 *  @arguments : [
  • 827.
                 *      
  • 828.
                 *      #marketplace ~ the marketplace ( or marketplaces ) based upon the data is fetched
  • 829.
                 *  ]
  • 830.
                 *  @returns : [ returns the marketplace's total file count ]
  • 831.
                */
  • 832.
     
  • 833.
                public function get_number_of_files() {
  • 834.
     
  • 835.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 836.
                    $files = [];
  • 837.
                    $set = $this->methods["Public"][2];
  • 838.
                    $public_url = $this->public_url;
  • 839.
     
  • 840.
                    foreach ($arguments as $key => $argument) {
  • 841.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 842.
                        $files[$argument] = $this->fetch($url, $set);
  • 843.
                    };
  • 844.
                    unset($argument);
  • 845.
     
  • 846.
                    return $this->json_encode_as_object([
  • 847.
                        "Items" => [
  • 848.
                            "Marketplaces" => $files
  • 849.
                        ]
  • 850.
                    ]);
  • 851.
                }
  • 852.
     
  • 853.
     
  • 854.
                /*
  • 855.
                 *  Get Marketplace Popular Files
  • 856.
                 *
  • 857.
                 *  @arguments : [
  • 858.
                 *      
  • 859.
                 *      #marketplace ~ the marketplace based upon the data is fetched
  • 860.
                 *  ]
  • 861.
                 *  @returns : [ returns the marketplace's most popular files ]
  • 862.
                */
  • 863.
     
  • 864.
                public function get_popular_files() {
  • 865.
     
  • 866.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 867.
                    $files = [];
  • 868.
                    $set = $this->methods["Public"][3];
  • 869.
                    $public_url = $this->public_url;
  • 870.
     
  • 871.
                    foreach ($arguments as $key => $argument) {
  • 872.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 873.
                        array_push($files, $this->fetch($url, $set));
  • 874.
                    };
  • 875.
                    unset($argument);
  • 876.
     
  • 877.
                    return $this->json_encode_as_object([
  • 878.
                        "Items" => [
  • 879.
                            "Popular" => ( count($arguments) === 1 ) ? $files[0] : $files
  • 880.
                        ]
  • 881.
                    ]);
  • 882.
                }
  • 883.
     
  • 884.
     
  • 885.
                /*
  • 886.
                 *  Get API Releases
  • 887.
                 *
  • 888.
                 *  @arguments : [
  • 889.
                 *      
  • 890.
                 *  ]
  • 891.
                 *  @returns : [ returns the api releases ]
  • 892.
                */
  • 893.
     
  • 894.
                public function get_releases() {
  • 895.
     
  • 896.
                    $set = $this->methods["Public"][4];
  • 897.
                    $public_url = $this->public_url;
  • 898.
     
  • 899.
                    $url = preg_replace('/set/i', $set, $public_url);
  • 900.
                    $releases = $this->fetch($url, $set);
  • 901.
     
  • 902.
                    return $this->json_encode_as_object([
  • 903.
                        "API" => [
  • 904.
                            "Releases" => $releases
  • 905.
                        ]
  • 906.
                    ]);
  • 907.
                }
  • 908.
     
  • 909.
     
  • 910.
                /*
  • 911.
                 *  Get Thread Status
  • 912.
                 *
  • 913.
                 *  @arguments : [
  • 914.
                 *      
  • 915.
                 *      #thread ~ the thread id ( or ids ) based upon the status is fetched
  • 916.
                 *  ]
  • 917.
                 *  @returns : [ returns the thread status ]
  • 918.
                */
  • 919.
     
  • 920.
                public function get_thread_status() {
  • 921.
     
  • 922.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 923.
                    $threads = [];
  • 924.
                    $set = $this->methods["Public"][5];
  • 925.
                    $public_url = $this->public_url;
  • 926.
     
  • 927.
                    foreach ($arguments as $key => $argument) {
  • 928.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 929.
                        array_push($threads, $this->fetch($url, $set));
  • 930.
                    };
  • 931.
                    unset($argument);
  • 932.
     
  • 933.
                    return $this->json_encode_as_object([
  • 934.
                        "Blog" => [
  • 935.
                            "Threads" => ( count($arguments) === 1 ) ? $threads[0] : $threads
  • 936.
                        ]
  • 937.
                    ]);
  • 938.
                }
  • 939.
     
  • 940.
     
  • 941.
                /*
  • 942.
                 *  Get Collection
  • 943.
                 *
  • 944.
                 *  @arguments : [
  • 945.
                 *      
  • 946.
                 *      #collection ~ the collection id ( or ids ) based upon the collection data is fetched
  • 947.
                 *  ]
  • 948.
                 *  @returns : [ returns the collection data ]
  • 949.
                */
  • 950.
     
  • 951.
                public function get_collection() {
  • 952.
     
  • 953.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 954.
                    $collections = [];
  • 955.
                    $set = $this->methods["Public"][6];
  • 956.
                    $public_url = $this->public_url;
  • 957.
     
  • 958.
                    foreach ($arguments as $key => $argument) {
  • 959.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 960.
                        $collections[$argument] = $this->fetch($url, $set); 
  • 961.
                    };
  • 962.
                    unset($argument);
  • 963.
     
  • 964.
                    return $this->json_encode_as_object([
  • 965.
                        "Items" => [
  • 966.
                            "Collections" => $collections
  • 967.
                        ]
  • 968.
                    ]);
  • 969.
                }
  • 970.
     
  • 971.
     
  • 972.
                /*
  • 973.
                 *  Get Featured Items
  • 974.
                 *
  • 975.
                 *  @arguments : [
  • 976.
                 *      
  • 977.
                 *      #marketplace ~ the marketplace ( or marketplaces ) based upon the data is fetched
  • 978.
                 *  ]
  • 979.
                 *  @returns : [ returns the featured items of the selected marketplace ]
  • 980.
                */
  • 981.
     
  • 982.
                public function get_featured_items() {
  • 983.
     
  • 984.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 985.
                    $featured = [];
  • 986.
                    $set = $this->methods["Public"][7];
  • 987.
                    $public_url = $this->public_url;
  • 988.
     
  • 989.
                    foreach ($arguments as $key => $argument) {
  • 990.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 991.
                        $featured[$argument] = $this->fetch($url, $set); 
  • 992.
                    };
  • 993.
                    unset($argument);
  • 994.
     
  • 995.
                    return $this->json_encode_as_object([
  • 996.
                        "Items" => [
  • 997.
                            "Featured" => $featured
  • 998.
                        ]
  • 999.
                    ]);
  • 1000.
                }
  • 1001.
     
  • 1002.
     
  • 1003.
                /*
  • 1004.
                 *  Get Marketplace New Files
  • 1005.
                 *
  • 1006.
                 *  @arguments : [
  • 1007.
                 *      
  • 1008.
                 *      #marketplace ~ the marketplace based upon the data is fetched
  • 1009.
                 *      #category ~ the category ( or categories ) based upon the data is fetched from the marketplace
  • 1010.
                 *  ]
  • 1011.
                 *  @returns : [ returns the new items of the selected marketplace and category ]
  • 1012.
                */
  • 1013.
     
  • 1014.
     
  • 1015.
                public function get_new_files_from_market() {
  • 1016.
     
  • 1017.
                    $filtered_arguments = [];
  • 1018.
                    $arguments = func_get_args();
  • 1019.
                    $args_count = func_num_args();
  • 1020.
                    $first_argument_index = [];
  • 1021.
                    $second_argument_index = [];
  • 1022.
                    $files = [];
  • 1023.
                    $files = [];
  • 1024.
                    $set = $this->methods["Public"][8];
  • 1025.
                    $public_url = $this->public_url;
  • 1026.
     
  • 1027.
                    switch ($args_count) {
  • 1028.
                        case 0:
  • 1029.
                            return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Insufficient ][ 2 Required ] ]");
  • 1030.
                        case 1:
  • 1031.
     
  • 1032.
                            $first_argument_index = $arguments[0];
  • 1033.
     
  • 1034.
                            switch (gettype($first_argument_index)) {
  • 1035.
                                case 'string':
  • 1036.
                                    
  • 1037.
                                    $filtered_arguments = $this->filter_arguments_recursive($arguments, $args_count);
  • 1038.
     
  • 1039.
                                    switch (count($filtered_arguments)) {
  • 1040.
                                        case 0:
  • 1041.
                                        case 1:
  • 1042.
                                            return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Insufficient ][ 2 Required ] ]");
  • 1043.
                                        case 2:
  • 1044.
     
  • 1045.
                                            $url = preg_replace('/set/i', $set . ":" . $filtered_arguments[0] . "," . $filtered_arguments[1], $public_url);
  • 1046.
     
  • 1047.
                                            array_push($files, [
  • 1048.
                                                "Marketplace" => $filtered_arguments[0],
  • 1049.
                                                "Categories" => [
  • 1050.
                                                    $filtered_arguments[1] => $this->fetch($url, $set)
  • 1051.
                                                ]
  • 1052.
                                            ]);
  • 1053.
                                            
  • 1054.
                                            break;
  • 1055.
                                        default:
  • 1056.
                                            return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Exceeded ][ 2 Required ] ]");
  • 1057.
                                    };
  • 1058.
     
  • 1059.
                                    break;
  • 1060.
                                case 'array':
  • 1061.
                                    
  • 1062.
                                    switch (count($first_argument_index)) {
  • 1063.
                                        case 0:
  • 1064.
                                            return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Insufficient ][ 2 Required ] ]");
  • 1065.
                                        case 1:
  • 1066.
     
  • 1067.
                                            $filtered_arguments = $this->filter_arguments_recursive($arguments, $args_count);
  • 1068.
     
  • 1069.
                                            switch (count($filtered_arguments)) {
  • 1070.
                                                case 0:
  • 1071.
                                                case 1:
  • 1072.
                                                    return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Insufficient ][ 2 Required ] ]");
  • 1073.
                                                case 2:
  • 1074.
     
  • 1075.
                                                    $url = preg_replace('/set/i', $set . ":" . $filtered_arguments[0] . "," . $filtered_arguments[1], $public_url);
  • 1076.
     
  • 1077.
                                                    array_push($files, [
  • 1078.
                                                        "Marketplace" => $filtered_arguments[0],
  • 1079.
                                                        "Categories" => [
  • 1080.
                                                            $filtered_arguments[1] => $this->fetch($url, $set)
  • 1081.
                                                        ]
  • 1082.
                                                    ]);
  • 1083.
     
  • 1084.
                                                    break;
  • 1085.
                                                default:
  • 1086.
                                                    return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Exceeded ][ 2 Required ] ]");
  • 1087.
                                            };
  • 1088.
     
  • 1089.
                                            break;
  • 1090.
                                        case 2:
  • 1091.
     
  • 1092.
                                            switch (gettype($first_argument_index[0])) {
  • 1093.
                                                case 'string':
  • 1094.
                                                    
  • 1095.
                                                    switch (gettype($first_argument_index[1])) {
  • 1096.
                                                        case 'string':
  • 1097.
                                                            
  • 1098.
                                                            $filtered_arguments = $this->filter_arguments_recursive([ $first_argument_index[1] ], 1);
  • 1099.
     
  • 1100.
                                                            switch (count($filtered_arguments)) {
  • 1101.
                                                                case 0:
  • 1102.
                                                                    return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Category ][ Missing ][ 1 + Required ] ]");
  • 1103.
                                                                case 1:
  • 1104.
     
  • 1105.
                                                                    $url = preg_replace('/set/i', $set . ":" . $first_argument_index[0] . "," . $filtered_arguments[0], $public_url);
  • 1106.
     
  • 1107.
                                                                    array_push($files, [
  • 1108.
                                                                        "Marketplace" => $first_argument_index[0],
  • 1109.
                                                                        "Categories" => [
  • 1110.
                                                                            $filtered_arguments[0] => $this->fetch($url, $set)
  • 1111.
                                                                        ]
  • 1112.
                                                                    ]);
  • 1113.
     
  • 1114.
                                                                    break;
  • 1115.
                                                                default:
  • 1116.
                                                                    
  • 1117.
                                                                    $results = [];
  • 1118.
     
  • 1119.
                                                                    foreach ($filtered_arguments as $key => $argument) {
  • 1120.
                                                                        $url = preg_replace('/set/i', $set . ":" . $first_argument_index[0] . "," . $argument, $public_url);
  • 1121.
                                                                        array_push($results, [ $argument => $this->fetch($url, $set) ] );
  • 1122.
                                                                    };
  • 1123.
                                                                    unset($argument);
  • 1124.
                                                                    
  • 1125.
                                                                    array_push($files, [
  • 1126.
                                                                        "Marketplace" => $first_argument_index[0],
  • 1127.
                                                                        "Categories" => $results
  • 1128.
                                                                    ]);
  • 1129.
     
  • 1130.
                                                                    break;
  • 1131.
                                                            };
  • 1132.
     
  • 1133.
                                                            break;
  • 1134.
                                                        case 'array':
  • 1135.
                                                            
  • 1136.
                                                            $results = [];
  • 1137.
                                                            
  • 1138.
                                                            foreach ($first_argument_index[1] as $key => $argument) {
  • 1139.
                                                                $url = preg_replace('/set/i', $set . ":" . $first_argument_index[0] . "," . $argument, $public_url);
  • 1140.
                                                                $results[$argument] = $this->fetch($url, $set);
  • 1141.
                                                            };
  • 1142.
                                                            unset($argument);
  • 1143.
                                                            
  • 1144.
                                                            array_push($files, [
  • 1145.
                                                                "Marketplace" => $first_argument_index[0],
  • 1146.
                                                                "Categories" => $results
  • 1147.
                                                            ]);
  • 1148.
     
  • 1149.
                                                            break;
  • 1150.
                                                        default:
  • 1151.
                                                            return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]");
  • 1152.
                                                    };
  • 1153.
     
  • 1154.
                                                    break;
  • 1155.
                                                default:
  • 1156.
                                                    return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]");
  • 1157.
                                            };
  • 1158.
     
  • 1159.
                                            break;
  • 1160.
                                        default:
  • 1161.
                                            return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Exceeded ][ 2 Required ] ]");
  • 1162.
                                    };
  • 1163.
     
  • 1164.
                                    break;
  • 1165.
                                default:
  • 1166.
                                    return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]");
  • 1167.
                            };
  • 1168.
     
  • 1169.
                            break;
  • 1170.
                        case 2:
  • 1171.
                            
  • 1172.
                            $first_argument_index = $arguments[0];
  • 1173.
                            $second_argument_index = $arguments[1];
  • 1174.
     
  • 1175.
                            switch (gettype($first_argument_index)) {
  • 1176.
                                case 'string':
  • 1177.
                                    
  • 1178.
                                    switch (gettype($second_argument_index)) {
  • 1179.
                                        case 'string':
  • 1180.
                                            
  • 1181.
                                            $filtered_arguments = $this->filter_arguments_recursive([ $second_argument_index ], 1);
  • 1182.
     
  • 1183.
                                            switch (count($filtered_arguments)) {
  • 1184.
                                                case 0:
  • 1185.
                                                    return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Category ][ Missing ][ 1 + Required ] ]");
  • 1186.
                                                case 1:
  • 1187.
     
  • 1188.
                                                    $url = preg_replace('/set/i', $set . ":" . $first_argument_index . "," . $filtered_arguments[0], $public_url);
  • 1189.
                                                    
  • 1190.
                                                    array_push($files, [
  • 1191.
                                                        "Marketplace" => $first_argument_index,
  • 1192.
                                                        "Categories" => [
  • 1193.
                                                            $filtered_arguments[0] => $this->fetch($url, $set)
  • 1194.
                                                        ]
  • 1195.
                                                    ]);
  • 1196.
     
  • 1197.
                                                    break;
  • 1198.
                                                default:
  • 1199.
                                                    
  • 1200.
                                                    $results = [];
  • 1201.
     
  • 1202.
                                                    foreach ($filtered_arguments as $key => $argument) {
  • 1203.
                                                        $url = preg_replace('/set/i', $set . ":" . $first_argument_index . "," . $argument, $public_url);
  • 1204.
                                                        array_push($results, [ $argument => $this->fetch($url, $set) ] );
  • 1205.
                                                    };
  • 1206.
                                                    unset($argument);
  • 1207.
                                                    
  • 1208.
                                                    array_push($files, [
  • 1209.
                                                        "Marketplace" => $first_argument_index,
  • 1210.
                                                        "Categories" => $results
  • 1211.
                                                    ]);
  • 1212.
     
  • 1213.
                                                    break;
  • 1214.
                                            };
  • 1215.
     
  • 1216.
                                            break;
  • 1217.
                                        case 'array':
  • 1218.
                                            
  • 1219.
                                            $results = [];
  • 1220.
     
  • 1221.
                                            foreach ($second_argument_index as $key => $argument) {
  • 1222.
                                                $url = preg_replace('/set/i', $set . ":" . $first_argument_index . "," . $argument, $public_url);
  • 1223.
                                                $results[$argument] = [ $argument => $this->fetch($url, $set) ];
  • 1224.
                                            };
  • 1225.
                                            unset($argument);
  • 1226.
                                            
  • 1227.
                                            array_push($files, [
  • 1228.
                                                "Marketplace" => $first_argument_index,
  • 1229.
                                                "Categories" => $results
  • 1230.
                                            ]);
  • 1231.
     
  • 1232.
                                            break;
  • 1233.
                                        default:
  • 1234.
                                            return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]");
  • 1235.
                                    };
  • 1236.
     
  • 1237.
                                    break;
  • 1238.
                                case 'array':
  • 1239.
                                    
  • 1240.
                                    if (is_array($second_argument_index)) {
  • 1241.
     
  • 1242.
                                        foreach ($arguments as $key => $argument) {
  • 1243.
                                            $results = json_decode($this->get_new_files_from_market($argument), true);
  • 1244.
                                            array_push($files, $results["Items"]["New"]["Marketplaces"][0]);
  • 1245.
                                        };
  • 1246.
                                        unset($argument);
  • 1247.
     
  • 1248.
                                    };
  • 1249.
     
  • 1250.
                                    break;
  • 1251.
                                default:
  • 1252.
                                    return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]");
  • 1253.
                            };
  • 1254.
     
  • 1255.
                            break;
  • 1256.
                        default:
  • 1257.
     
  • 1258.
                            $types = [];
  • 1259.
     
  • 1260.
                            foreach ($arguments as $key => $argument) {
  • 1261.
                                
  • 1262.
                                if (is_array($argument)) {
  • 1263.
                                    array_push($types, true);
  • 1264.
                                };
  • 1265.
     
  • 1266.
                            };
  • 1267.
     
  • 1268.
                            if (count($arguments) === count($types)) {
  • 1269.
     
  • 1270.
                                foreach ($arguments as $key => $argument) {
  • 1271.
                                    $results = json_decode($this->get_new_files_from_market($argument), true);
  • 1272.
                                    array_push($files, $results["Items"]["New"]["Marketplaces"][0]);
  • 1273.
                                };
  • 1274.
                                unset($argument);
  • 1275.
     
  • 1276.
                            } else {
  • 1277.
                                return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Exceeded ][ 2 Required ] ]");
  • 1278.
                            }
  • 1279.
     
  • 1280.
                            break;
  • 1281.
                    };
  • 1282.
     
  • 1283.
                    return $this->json_encode_as_object($this->array_unique_multidimensional([
  • 1284.
                        "Items" => [
  • 1285.
                            "New" => [
  • 1286.
                                "Marketplaces" => $files
  • 1287.
                            ]
  • 1288.
                        ]
  • 1289.
                    ]));
  • 1290.
                }
  • 1291.
     
  • 1292.
               
  • 1293.
                /*
  • 1294.
                 *  Get Marketplace User's New Files
  • 1295.
                 *
  • 1296.
                 *  @arguments : [
  • 1297.
                 *      
  • 1298.
                 *      #user ~ the user based upon the data is fetched
  • 1299.
                 *      #marketplace ~ the marketplace based upon the data is fetched from the user
  • 1300.
                 *  ]
  • 1301.
                 *  @returns : [ returns the user's new files of the selected marketplace ]
  • 1302.
                */
  • 1303.
     
  • 1304.
                public function get_new_files_from_user($marketplace = null, $user = null) {
  • 1305.
     
  • 1306.
                    $args = func_num_args();
  • 1307.
     
  • 1308.
                    if($args === 1) {
  • 1309.
                        $user = $marketplace;
  • 1310.
                    }
  • 1311.
     
  • 1312.
                    $url = preg_replace('/set/i', $this->methods["Public"][9] . ":" . $user . "," . $this->default_marketplace, $this->public_url);
  • 1313.
     
  • 1314.
                    if(empty($user)) {
  • 1315.
                       return "[ User | Set User ]";
  • 1316.
                    }
  • 1317.
     
  • 1318.
                    return $this->fetch($url);
  • 1319.
                }
  • 1320.
     
  • 1321.
     
  • 1322.
                /*
  • 1323.
                 *  Get Marketplace Random New Files
  • 1324.
                 *
  • 1325.
                 *  @arguments : [
  • 1326.
                 *      
  • 1327.
                 *      #marketplace ~ the marketplace based upon the data is fetched
  • 1328.
                 *  ]
  • 1329.
                 *  @returns : [ returns the marketplace random new files of the selected marketplace ]
  • 1330.
                */
  • 1331.
     
  • 1332.
                public function get_random_new_files() {
  • 1333.
     
  • 1334.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 1335.
                    $random = [];
  • 1336.
                    $set = $this->methods["Public"][10];
  • 1337.
                    $public_url = $this->public_url;
  • 1338.
     
  • 1339.
                    foreach ($arguments as $key => $argument) {
  • 1340.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 1341.
                        $random[$argument] = $this->fetch($url, $set);
  • 1342.
                    };
  • 1343.
                    unset($argument);
  • 1344.
     
  • 1345.
                    return $this->json_encode_as_object([
  • 1346.
                        "Items" => [
  • 1347.
                            "Random" => $random
  • 1348.
                        ]
  • 1349.
                    ]);
  • 1350.
                }
  • 1351.
     
  • 1352.
     
  • 1353.
                /*
  • 1354.
                 *  Get Marketplace Total Users
  • 1355.
                 *
  • 1356.
                 *  @arguments : [
  • 1357.
                 *      
  • 1358.
                 *  ]
  • 1359.
                 *  @returns : [ returns the marketplace's total of users ]
  • 1360.
                */
  • 1361.
     
  • 1362.
                public function get_total_users() {
  • 1363.
     
  • 1364.
                    $set = $this->methods["Public"][11];
  • 1365.
                    $public_url = $this->public_url;
  • 1366.
     
  • 1367.
                    $url = preg_replace('/set/i', $set, $public_url);
  • 1368.
     
  • 1369.
                    return $this->json_encode_as_object([
  • 1370.
                        "Users" => [
  • 1371.
                            "Total" => $this->fetch($url, $set)
  • 1372.
                        ]
  • 1373.
                    ]);
  • 1374.
                }
  • 1375.
     
  • 1376.
     
  • 1377.
                /*
  • 1378.
                 *  Get Item Information
  • 1379.
                 *
  • 1380.
                 *  @arguments : [
  • 1381.
                 *      
  • 1382.
                 *      #item ~ the item id ( or ids ) based upon the data is fetched
  • 1383.
                 *  ]
  • 1384.
                 *  @returns : [ returns the item information ]
  • 1385.
                */
  • 1386.
     
  • 1387.
                public function get_item_details() {
  • 1388.
     
  • 1389.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 1390.
                    $information = [];
  • 1391.
                    $set = $this->methods["Public"][12];
  • 1392.
                    $public_url = $this->public_url;
  • 1393.
     
  • 1394.
                    foreach ($arguments as $key => $argument) {
  • 1395.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 1396.
                        $information[$argument] = $this->fetch($url, $set);
  • 1397.
                    };
  • 1398.
                    unset($argument);
  • 1399.
     
  • 1400.
                    return $this->json_encode_as_object([
  • 1401.
                        "Items" => [
  • 1402.
                            "Information" => $information
  • 1403.
                        ]
  • 1404.
                    ]);
  • 1405.
                }
  • 1406.
     
  • 1407.
     
  • 1408.
                /*
  • 1409.
                 *  Get Item Price
  • 1410.
                 *
  • 1411.
                 *  @arguments : [
  • 1412.
                 *      
  • 1413.
                 *      #item ~ the item id ( or ids ) based upon the data is fetched
  • 1414.
                 *  ]
  • 1415.
                 *  @returns : [ returns the item price ]
  • 1416.
                */
  • 1417.
     
  • 1418.
                public function get_item_prices() {
  • 1419.
     
  • 1420.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 1421.
                    $prices = [];
  • 1422.
                    $set = $this->methods["Public"][13];
  • 1423.
                    $public_url = $this->public_url;
  • 1424.
     
  • 1425.
                    foreach ($arguments as $key => $argument) {
  • 1426.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 1427.
                        $prices[$argument] = $this->fetch($url, $set);
  • 1428.
                    };
  • 1429.
                    unset($argument);
  • 1430.
     
  • 1431.
                    return $this->json_encode_as_object([
  • 1432.
                        "Items" => [
  • 1433.
                            "Prices" => $prices
  • 1434.
                        ]
  • 1435.
                    ]);
  • 1436.
                }
  • 1437.
     
  • 1438.
     
  • 1439.
                /*
  • 1440.
                 *  Get Search Results
  • 1441.
                 *
  • 1442.
                 *  @arguments : [
  • 1443.
                 *      
  • 1444.
                 *      #expression ~ the expression based upon the search is done, required argument
  • 1445.
                 *      #marketplace ~ the marketplace, provided as a filter, it isn't a required argument
  • 1446.
                 *      #category ~ the category, provided as a filter, it isn't a required argument ( you can additionally pass subcategory and other hierarchy categories )
  • 1447.
                 *  ]
  • 1448.
                 *  @returns : [ returns search results from all marketplaces or by market and or category, limited to the first 50 ]
  • 1449.
                */
  • 1450.
     
  • 1451.
                public function get_search_results($expression, $marketplace = null, $category = null) {
  • 1452.
     
  • 1453.
                    $search = [];
  • 1454.
                    $set = $this->methods["Public"][14];
  • 1455.
                    $public_url = $this->public_url;
  • 1456.
                    $regex = "/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|" . "[\s,]*'([^']+)'[\s,]*|" . "[\s,]+/";
  • 1457.
     
  • 1458.
                    if (empty($expression)) {
  • 1459.
                        return json_encode("[ Search Items [ Failed ][ Expression Required ] ]");
  • 1460.
                    } else {
  • 1461.
                        $expression = preg_replace($regex, "|", $expression);
  • 1462.
                    }
  • 1463.
     
  • 1464.
                    if (!is_null($category)) {
  • 1465.
                        $category = preg_replace($regex, "%2f", $category);
  • 1466.
                    }
  • 1467.
     
  • 1468.
                    $url = preg_replace('/set/i', $set . ":" . ( ( is_null($marketplace) ) ? '' : $marketplace ) . ',' .  ( ( is_null($category) ) ? '' : $category ) . ',' . $expression, $public_url );
  • 1469.
     
  • 1470.
                    $search = $this->fetch($url, $set);
  • 1471.
     
  • 1472.
                    return $this->json_encode_as_object([
  • 1473.
                        "Items" => [
  • 1474.
                            "Search" => $search
  • 1475.
                        ]
  • 1476.
                    ]);
  • 1477.
                }
  • 1478.
     
  • 1479.
     
  • 1480.
                /*
  • 1481.
                 *  Get User Info
  • 1482.
                 *
  • 1483.
                 *  @arguments : [
  • 1484.
                 *      
  • 1485.
                 *      #user ~ the user id ( or ids ) based upon the data is fetched
  • 1486.
                 *  ]
  • 1487.
                 *  @returns : [ returns the user info ]
  • 1488.
                */
  • 1489.
     
  • 1490.
                public function get_user_info() {
  • 1491.
     
  • 1492.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 1493.
                    $users = [];
  • 1494.
                    $set = $this->methods["Public"][15];
  • 1495.
                    $public_url = $this->public_url;
  • 1496.
     
  • 1497.
                    foreach ($arguments as $key => $argument) {
  • 1498.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 1499.
                        $users[$argument] = [
  • 1500.
                            "Information" => $this->fetch($url, $set)
  • 1501.
                        ]; 
  • 1502.
                    };
  • 1503.
                    unset($argument);
  • 1504.
     
  • 1505.
                    return $this->json_encode_as_object([
  • 1506.
                        "Users" => $users
  • 1507.
                    ]);
  • 1508.
                }
  • 1509.
     
  • 1510.
     
  • 1511.
                /*
  • 1512.
                 *  Get User Items Count
  • 1513.
                 *
  • 1514.
                 *  @arguments : [
  • 1515.
                 *      
  • 1516.
                 *      #user ~ the user id ( or ids ) based upon the data is fetched
  • 1517.
                 *  ]
  • 1518.
                 *  @returns : [ returns the user items count by site ]
  • 1519.
                */
  • 1520.
     
  • 1521.
                public function get_user_items_by_site() {
  • 1522.
     
  • 1523.
                    $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args());
  • 1524.
                    $users = [];
  • 1525.
                    $set = $this->methods["Public"][16];
  • 1526.
                    $public_url = $this->public_url;
  • 1527.
     
  • 1528.
                    foreach ($arguments as $key => $argument) {
  • 1529.
                        $url = preg_replace('/set/i', $set . ":" . $argument, $public_url);
  • 1530.
                        $users[$argument] = [
  • 1531.
                            "Items" => $this->fetch($url, $set)
  • 1532.
                        ]; 
  • 1533.
                    };
  • 1534.
                    unset($argument);
  • 1535.
     
  • 1536.
                    return $this->json_encode_as_object([
  • 1537.
                        "Users" => $users
  • 1538.
                    ]);
  • 1539.
                }
  • 1540.
     
  • 1541.
            }
  • 1542.
        }
  • 1543.
    ?>
<?php /* * * Envato API Wrapper Class * * @Author : Roland Groza * @Description : * * @Features : [ * * ] * * @Category : PHP Class * @Copyright : Copyright 2013 Roland Groza [ http://rolandgroza.me ] * @Version : 2.0 * @Created : January 2013 * */ namespace Envato { /* * Curl Trait */ trait Curl { /* * Set Global Trait Variables * * @variables : [ * * #certificate [ Protected ] ~ set the path to the Envato SSL Certificate, used in order to verify the curl request * #verify_cert [ Protected ] ~ if true, the connection will be secured ( the certificate is required ) otherwise the connection will opened without verification * ] */ protected $certificate = "/certificate/"; protected $verify_cert = false; /* * Curl GET Method * * @arguments : [ * * #url ~ the url is required, based on it the necessary data is grabbed * ] * @returns : [ data fetched from the url ] */ public function curl_get($url) { if(empty($url)) { return false; }; $channel = curl_init($url); curl_setopt($channel, CURLOPT_RETURNTRANSFER, 1); $this->curl_verify_cert($channel); curl_setopt($channel, CURLOPT_CUSTOMREQUEST, "GET"); $result = curl_exec($channel); if(curl_errno($channel)) { return $result = 0; }; curl_close($channel); return $result; } /* * Curl Verify Certification * * @arguments : [ * * #curl ~ the curl request * ] * @returns : [ an option for curl to verify or not the connection ] */ public function curl_verify_cert($curl) { $files = []; $certificate_url = ""; if ($this->verify_cert) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . $this->certificate), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $key => $value) { array_push($files, $value->__toString()); }; unset($value); if (is_array($files) && !empty($files) && count($files) === 1) { $certificate_url = $files[0]; } else { return json_encode("[ Verify Certificate [ Failed ] | Certificate Missing ]", JSON_FORCE_OBJECT); }; if (preg_match("/\\\\/", $certificate_url)) { $certificate_url = preg_replace("/\\\\/", "/", $certificate_url); }; return curl_setopt_array($curl, [ CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CAINFO => $certificate_url ]); } else { return curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); }; } } /* * Fetch Trait * */ trait Fetch { /* * Use Curl Methods */ use Curl { curl_get as protected; } /* * Fetch Method | Fetch Data / Return Decoded JSON * * @arguments : [ * * #url ~ the url is required, based on it the necessary data is grabbed * ] * @returns : [ returns decoded data ] */ public function fetch($url, $set = null) { $_action = []; $_result = []; switch (empty($url)) { case false: switch (is_null($set)) { case false: $_action = json_decode($this->curl_get($url)); if ( is_array($_action) || is_object($_action) && array_key_exists("error", $_action) ) { $_result = [ "Error" => true, "Description" => ( is_array($_action) ) ? $_action["error"] : $_action->error ]; } else { $_result = $_action->$set; }; break; case true: default: $_result = json_decode($this->curl_get($url)); break; }; break; case true: $_result = "Fetch Data [ Failed ] | Provide URL"; break; default: break; }; return $_result; } } /* * Utils Trait | Small PHP Utility */ trait Utils { /* * Use Fetch Methods */ use Fetch { fetch as protected; } /* * Remove Array Duplicate Values * * @arguments : [ * * #array ~ the array to run the function against * #flags ~ the type of array values, can be Regular, Numeric, String or Locale * ] * @returns : [ returns the sorted array ] */ public function array_unique_values($array, $flags) { $f_array = []; $parsed = []; $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array)); foreach ($iterator as $key => $value) { array_push($parsed, $value); }; unset($value); switch (gettype($flags)) { case 'string': switch (strtolower($flags)) { case 'regular': return array_unique($parsed, SORT_REGULAR); case 'numeric': return array_unique($parsed, SORT_NUMERIC); case 'string': return array_unique($parsed, SORT_STRING); case 'locale': return array_unique($parsed, SORT_LOCALE_STRING); default: return $this->json_encode_as_object("Array Unique Values [ Flag : ". $flags ." Inexistent]"); }; break; case 'array': foreach ($flags as $key => $flag) { switch (strtolower($flag)) { case 'regular': array_push($f_array, SORT_REGULAR); break; case 'numeric': array_push($f_array, SORT_NUMERIC); break; case 'string': array_push($f_array, SORT_STRING); break; case 'locale': array_push($f_array, SORT_LOCALE_STRING); break; default: return $this->json_encode_as_object("Array Unique Values [ Flag : ". $flags ." Inexistent]"); }; }; unset($flag); return array_unique($parsed, $f_array); default: break; }; } /* * Remove Array Duplicates | Recursivelly | Multidimensional Arrays * * @arguments : [ * * #array ~ the array to run the function against * ] * @returns : [ returns the sorted array ] */ public function array_unique_multidimensional($array) { $result = array_map("unserialize", array_unique(array_map("serialize", $array))); foreach ($result as $key => $value) { if ( is_array($value) ) { $result[$key] = $this->array_unique_multidimensional($value); }; }; unset($value); return $result; } /* * Encode Array to JSON | Force Conversion * * @arguments : [ * * #array ~ the array to run the conversion against * ] * @returns : [ returns encoded json ] */ public function json_encode_as_object($array) { return json_encode($array, JSON_FORCE_OBJECT); } /* * Strip Spaces * * @arguments : [ * * #string ~ a string which will be stripped of all spaces between characters * ] * @returns : [ returns a string stripped of spaces ] */ public function strip_spaces($string) { return trim(preg_replace( '/\s+/', '', $string )); } /* * Get Function Arguments * * @arguments : [ * * ~ accepts as many arguments as you want, the arguments can be strings or arrays of strings, the strings if containing white spaces (space, tab, new line, etc) and commas will also be read as arguments * ] * @returns : [ an array of unique arguments ] */ public function filter_arguments_recursive($arguments, $arguments_count) { $iterator = []; $args = []; $args_count = []; $temporary = []; switch ($arguments_count) { case 0: exit("[ Get Function Arguments | Argument Missing ]"); case 1: default: $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($arguments)); foreach ($iterator as $key => $value) { array_push($args, $value); }; unset($value); $args_count = count($args); foreach ($args as $key => $arg) { array_push($temporary, preg_split("/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|" . "[\s,]*'([^']+)'[\s,]*|" . "[\s,]+/", $arg, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)); if ($args_count - 1 === $key) { $args = []; array_push($args, $this->array_unique_values($temporary, "String")); }; }; unset($arg); return array_map('array_values', $args)[0]; }; } } interface IEnvato { public function set_api_key($api_key); public function get_api_key(); public function get_user_vitals(); public function get_earnings_and_sales_by_month(); public function get_statement(); public function get_recent_sales(); public function get_account_info(); public function verify_purchase(); public function download_purchase(); public function get_blog_posts(); public function get_active_threads(); public function get_number_of_files(); public function get_popular_files(); public function get_releases(); public function get_thread_status(); public function get_collection(); public function get_featured_items(); public function get_new_files_from_market(); public function get_new_files_from_user(); public function get_random_new_files(); public function get_total_users(); public function get_item_details(); public function get_item_prices(); public function get_search_results($expression, $marketplace, $category); public function get_user_info(); public function get_user_items_by_site(); } /* * Envato Class | Envato API Wrapper Class */ class EnvatoAPIWrapper implements IEnvato { /* * Use Fetch Methods */ use Utils { fetch as protected; } /* * Set Global Class Variables * * @variables : [ * * #api_key [ Protected ] ~ set API key necessary for fetching private user data * #public_url [ Protected ] ~ set API public URL from which all data is fetched * #methods [ Protected ] ~ set all the methods available in the API * ] */ protected $api_key; protected $public_url = "http://marketplace.envato.com/api/v3/set.json"; protected $methods = [ "Public" => ["blog-posts", "active-threads", "number-of-files", "popular", "releases", "thread-status", "collection", "features", "new-files", "new-files-from-user", "random-new-files", "total-users", "item", "item-prices", "search", "user", "user-items-by-site"], "Private" => ["vitals", "earnings-and-sales-by-month", "statement", "recent-sales", "account", 'verify-purchase', "download-purchase"] ]; /* * Class Constructor * * @arguments : [ * * #api_key ~ API key necessary for fetching private user data * ] * @returns : [ sets API key necessary for fetching private user data ] */ public function __construct($api_key = null) { if(isset($api_key) ) { $this->api_key = $api_key; }; } /* * Set API Key * * @arguments : [ * * #api_key ~ API key necessary for fetching private user data * ] * @returns : [ sets API key necessary for fetching private user data ] */ public function set_api_key($api_key) { return $this->api_key = $api_key; } /* * Get API Key * * @arguments : [ * * ] * @returns : [ returns API key necessary for fetching private user data or asks for an API key] */ public function get_api_key() { if(isset($this->api_key) ) { return $this->json_encode_as_object([ "API" => $this->api_key ]); } else { return $this->json_encode_as_object("[ API [ Missing ] | Set API ]"); }; } /* * Get Private User Data * * @arguments : [ * * #username ~ the username based upon the data is fetched * #set ~ the type of data that is required to be fetched * #purchase_code ~ used to check if a buyer purchased an item, not required if the method isn't verifying purchase or download purchase * ] * @returns : [ returns fetched data ] */ private function get_private_user_data($username, $set, $purchase_code = null) { if(!isset($this->api_key)) { return $this->json_encode_as_object("[ API [ Missing ] | Set API ]"); }; if(!isset($set)) { return $this->json_encode_as_object("[ User Data [ Private ] | Set : ". $set ." [ Undefined ] ]"); }; $url = preg_replace('/set/i', $username . "/" . $this->api_key . "/" . $set, $this->public_url); if(!is_null($purchase_code)) { $url = preg_replace('/'. $set . '/i', $set . ":$purchase_code", $url); }; return $this->fetch($url, $set); } /* * Get User Vitals * * @arguments : [ * * #username ~ the username based upon the data is fetched * ] * @returns : [ returns user vitals ( balance and username ) ] */ public function get_user_vitals() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $set = $this->methods["Private"][0]; return $this->json_encode_as_object([ "User" => [ "Vitals" => $this->get_private_user_data($arguments[0], $set) ] ]); } /* * Get Earnings & Sales * * @arguments : [ * * #username ~ the username based upon the data is fetched * ] * @returns : [ returns user earnings and sales by month ] */ public function get_earnings_and_sales_by_month() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $set = $this->methods["Private"][1]; return $this->json_encode_as_object([ "User" => [ "Transactions" => $this->get_private_user_data($arguments[0], $set) ] ]); } /* * Get Statement * * @arguments : [ * * #username ~ the username based upon the data is fetched * ] * @returns : [ returns user statement ] */ public function get_statement() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $set = $this->methods["Private"][2]; return $this->json_encode_as_object([ "User" => [ "Statement" => $this->get_private_user_data($arguments[0], $set) ] ]); } /* * Get Recent Sales * * @arguments : [ * * #username ~ the username based upon the data is fetched * ] * @returns : [ returns user's recent sales ] */ public function get_recent_sales() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $set = $this->methods["Private"][3]; return $this->json_encode_as_object([ "User" => [ "Sales" => $this->get_private_user_data($arguments[0], $set) ] ]); } /* * Get Account Information * * @arguments : [ * * #username ~ the username based upon the data is fetched * ] * @returns : [ returns user account information ] */ public function get_account_info() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $set = $this->methods["Private"][4]; return $this->json_encode_as_object([ "User" => [ "Information" => $this->get_private_user_data($arguments[0], $set) ] ]); } /* * Verify Purchase | Requires User's Purchase Code / Own API Key / Own Username * * @arguments : [ * * #username ~ the username based upon the data is fetched * #purchase_code ~ used to check if a buyer purchased an item * ] * @returns : [ * * { * Item { * Verified : { * "buyer" : "buyer_id_here", * "created_at" : "Wed Dec 01 05:00:47 +1100 2010", * "licence" : "Regular Licence", * "item_name" : "Your Item Name Here", * "item_id" : "116430" * } * } * } * { * Item { * Verified : false * } * } * ] */ public function verify_purchase() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $verified = []; $set = $this->methods["Private"][5]; if(empty($arguments[1])) { return "[ Download Purchase [ Failed ] | Set Purchase Code ]"; }; $validity = $this->get_private_user_data($arguments[0], $set, $arguments[1]); if (is_array($validity) || is_object($validity) && array_key_exists("item_id", $validity)) { $verified = $validity; } else { $verified = false; }; return $this->json_encode_as_object([ "Item" => [ "Verified" => $verified ] ]); } /* * Download Purchase | Requires User's Purchase Code / User's API Key / User's Username * * @arguments : [ * * #username ~ the username based upon the data is fetched * #purchase_code ~ used to check if a buyer purchased an item * ] * @returns : [ * * { * Item { * Download : { * "download_url": "http://s3.amazonaws.com/marketplace-downloads.envato.com/files/123456/blablabla.zip?AWSAccessKeyId=blablabla\u0026Expires=123456789\u0026Signature=foobarfoobar\u0026response-content-disposition=attachment;%20filename=blablabla.zip" * } * } * } * { * Item { * Download : false * } * } * ] */ public function download_purchase() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $download = []; $set = $this->methods["Private"][6]; if(empty($arguments[1])) { return "[ Download Purchase [ Failed ] | Set Purchase Code [ 1 + Required ] ]"; }; $validity = $this->get_private_user_data($arguments[0], $set, $arguments[1]); if (is_array($validity) || is_object($validity) && array_key_exists("download_url", $validity)) { $download = $validity; } else { $download = false; }; return $this->json_encode_as_object([ "Item" => [ "Download" => $download ] ]); } /* * Get Blog Posts * * @arguments : [ * * #marketplace ~ the marketplace ( or marketplaces ) based upon the data is fetched * ] * @returns : [ returns the marketplace's blog posts ] */ public function get_blog_posts() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $blog_posts = []; $set = $this->methods["Public"][0]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); array_push($blog_posts, $this->fetch($url, $set)); }; unset($argument); return $this->json_encode_as_object([ "Blog" => [ "Posts" => ( count($arguments) === 1 ) ? $blog_posts[0] : $blog_posts ] ]); } /* * Get Blog Active Threads * * @arguments : [ * * #marketplace ~ the marketplace ( or marketplaces ) based upon the data is fetched * ] * @returns : [ returns the marketplace's blog active threads ] */ public function get_active_threads() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $blog_threads = []; $set = $this->methods["Public"][1]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); array_push($blog_threads, $this->fetch($url, $set)); }; unset($argument); return $this->json_encode_as_object([ "Blog" => [ "ActiveThreads" => ( count($arguments) === 1 ) ? $blog_threads[0] : $blog_threads ] ]); } /* * Get Marketplace File Count * * @arguments : [ * * #marketplace ~ the marketplace ( or marketplaces ) based upon the data is fetched * ] * @returns : [ returns the marketplace's total file count ] */ public function get_number_of_files() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $files = []; $set = $this->methods["Public"][2]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); $files[$argument] = $this->fetch($url, $set); }; unset($argument); return $this->json_encode_as_object([ "Items" => [ "Marketplaces" => $files ] ]); } /* * Get Marketplace Popular Files * * @arguments : [ * * #marketplace ~ the marketplace based upon the data is fetched * ] * @returns : [ returns the marketplace's most popular files ] */ public function get_popular_files() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $files = []; $set = $this->methods["Public"][3]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); array_push($files, $this->fetch($url, $set)); }; unset($argument); return $this->json_encode_as_object([ "Items" => [ "Popular" => ( count($arguments) === 1 ) ? $files[0] : $files ] ]); } /* * Get API Releases * * @arguments : [ * * ] * @returns : [ returns the api releases ] */ public function get_releases() { $set = $this->methods["Public"][4]; $public_url = $this->public_url; $url = preg_replace('/set/i', $set, $public_url); $releases = $this->fetch($url, $set); return $this->json_encode_as_object([ "API" => [ "Releases" => $releases ] ]); } /* * Get Thread Status * * @arguments : [ * * #thread ~ the thread id ( or ids ) based upon the status is fetched * ] * @returns : [ returns the thread status ] */ public function get_thread_status() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $threads = []; $set = $this->methods["Public"][5]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); array_push($threads, $this->fetch($url, $set)); }; unset($argument); return $this->json_encode_as_object([ "Blog" => [ "Threads" => ( count($arguments) === 1 ) ? $threads[0] : $threads ] ]); } /* * Get Collection * * @arguments : [ * * #collection ~ the collection id ( or ids ) based upon the collection data is fetched * ] * @returns : [ returns the collection data ] */ public function get_collection() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $collections = []; $set = $this->methods["Public"][6]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); $collections[$argument] = $this->fetch($url, $set); }; unset($argument); return $this->json_encode_as_object([ "Items" => [ "Collections" => $collections ] ]); } /* * Get Featured Items * * @arguments : [ * * #marketplace ~ the marketplace ( or marketplaces ) based upon the data is fetched * ] * @returns : [ returns the featured items of the selected marketplace ] */ public function get_featured_items() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $featured = []; $set = $this->methods["Public"][7]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); $featured[$argument] = $this->fetch($url, $set); }; unset($argument); return $this->json_encode_as_object([ "Items" => [ "Featured" => $featured ] ]); } /* * Get Marketplace New Files * * @arguments : [ * * #marketplace ~ the marketplace based upon the data is fetched * #category ~ the category ( or categories ) based upon the data is fetched from the marketplace * ] * @returns : [ returns the new items of the selected marketplace and category ] */ public function get_new_files_from_market() { $filtered_arguments = []; $arguments = func_get_args(); $args_count = func_num_args(); $first_argument_index = []; $second_argument_index = []; $files = []; $files = []; $set = $this->methods["Public"][8]; $public_url = $this->public_url; switch ($args_count) { case 0: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Insufficient ][ 2 Required ] ]"); case 1: $first_argument_index = $arguments[0]; switch (gettype($first_argument_index)) { case 'string': $filtered_arguments = $this->filter_arguments_recursive($arguments, $args_count); switch (count($filtered_arguments)) { case 0: case 1: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Insufficient ][ 2 Required ] ]"); case 2: $url = preg_replace('/set/i', $set . ":" . $filtered_arguments[0] . "," . $filtered_arguments[1], $public_url); array_push($files, [ "Marketplace" => $filtered_arguments[0], "Categories" => [ $filtered_arguments[1] => $this->fetch($url, $set) ] ]); break; default: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Exceeded ][ 2 Required ] ]"); }; break; case 'array': switch (count($first_argument_index)) { case 0: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Insufficient ][ 2 Required ] ]"); case 1: $filtered_arguments = $this->filter_arguments_recursive($arguments, $args_count); switch (count($filtered_arguments)) { case 0: case 1: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Insufficient ][ 2 Required ] ]"); case 2: $url = preg_replace('/set/i', $set . ":" . $filtered_arguments[0] . "," . $filtered_arguments[1], $public_url); array_push($files, [ "Marketplace" => $filtered_arguments[0], "Categories" => [ $filtered_arguments[1] => $this->fetch($url, $set) ] ]); break; default: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Exceeded ][ 2 Required ] ]"); }; break; case 2: switch (gettype($first_argument_index[0])) { case 'string': switch (gettype($first_argument_index[1])) { case 'string': $filtered_arguments = $this->filter_arguments_recursive([ $first_argument_index[1] ], 1); switch (count($filtered_arguments)) { case 0: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Category ][ Missing ][ 1 + Required ] ]"); case 1: $url = preg_replace('/set/i', $set . ":" . $first_argument_index[0] . "," . $filtered_arguments[0], $public_url); array_push($files, [ "Marketplace" => $first_argument_index[0], "Categories" => [ $filtered_arguments[0] => $this->fetch($url, $set) ] ]); break; default: $results = []; foreach ($filtered_arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $first_argument_index[0] . "," . $argument, $public_url); array_push($results, [ $argument => $this->fetch($url, $set) ] ); }; unset($argument); array_push($files, [ "Marketplace" => $first_argument_index[0], "Categories" => $results ]); break; }; break; case 'array': $results = []; foreach ($first_argument_index[1] as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $first_argument_index[0] . "," . $argument, $public_url); $results[$argument] = $this->fetch($url, $set); }; unset($argument); array_push($files, [ "Marketplace" => $first_argument_index[0], "Categories" => $results ]); break; default: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]"); }; break; default: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]"); }; break; default: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Exceeded ][ 2 Required ] ]"); }; break; default: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]"); }; break; case 2: $first_argument_index = $arguments[0]; $second_argument_index = $arguments[1]; switch (gettype($first_argument_index)) { case 'string': switch (gettype($second_argument_index)) { case 'string': $filtered_arguments = $this->filter_arguments_recursive([ $second_argument_index ], 1); switch (count($filtered_arguments)) { case 0: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Category ][ Missing ][ 1 + Required ] ]"); case 1: $url = preg_replace('/set/i', $set . ":" . $first_argument_index . "," . $filtered_arguments[0], $public_url); array_push($files, [ "Marketplace" => $first_argument_index, "Categories" => [ $filtered_arguments[0] => $this->fetch($url, $set) ] ]); break; default: $results = []; foreach ($filtered_arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $first_argument_index . "," . $argument, $public_url); array_push($results, [ $argument => $this->fetch($url, $set) ] ); }; unset($argument); array_push($files, [ "Marketplace" => $first_argument_index, "Categories" => $results ]); break; }; break; case 'array': $results = []; foreach ($second_argument_index as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $first_argument_index . "," . $argument, $public_url); $results[$argument] = [ $argument => $this->fetch($url, $set) ]; }; unset($argument); array_push($files, [ "Marketplace" => $first_argument_index, "Categories" => $results ]); break; default: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]"); }; break; case 'array': if (is_array($second_argument_index)) { foreach ($arguments as $key => $argument) { $results = json_decode($this->get_new_files_from_market($argument), true); array_push($files, $results["Items"]["New"]["Marketplaces"][0]); }; unset($argument); }; break; default: return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Unknown Type ][ String Required ] ]"); }; break; default: $types = []; foreach ($arguments as $key => $argument) { if (is_array($argument)) { array_push($types, true); }; }; if (count($arguments) === count($types)) { foreach ($arguments as $key => $argument) { $results = json_decode($this->get_new_files_from_market($argument), true); array_push($files, $results["Items"]["New"]["Marketplaces"][0]); }; unset($argument); } else { return json_encode("[ Get Items [ New ][ Failed ] | Arguments [ Exceeded ][ 2 Required ] ]"); } break; }; return $this->json_encode_as_object($this->array_unique_multidimensional([ "Items" => [ "New" => [ "Marketplaces" => $files ] ] ])); } /* * Get Marketplace User's New Files * * @arguments : [ * * #user ~ the user based upon the data is fetched * #marketplace ~ the marketplace based upon the data is fetched from the user * ] * @returns : [ returns the user's new files of the selected marketplace ] */ public function get_new_files_from_user($marketplace = null, $user = null) { $args = func_num_args(); if($args === 1) { $user = $marketplace; } $url = preg_replace('/set/i', $this->methods["Public"][9] . ":" . $user . "," . $this->default_marketplace, $this->public_url); if(empty($user)) { return "[ User | Set User ]"; } return $this->fetch($url); } /* * Get Marketplace Random New Files * * @arguments : [ * * #marketplace ~ the marketplace based upon the data is fetched * ] * @returns : [ returns the marketplace random new files of the selected marketplace ] */ public function get_random_new_files() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $random = []; $set = $this->methods["Public"][10]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); $random[$argument] = $this->fetch($url, $set); }; unset($argument); return $this->json_encode_as_object([ "Items" => [ "Random" => $random ] ]); } /* * Get Marketplace Total Users * * @arguments : [ * * ] * @returns : [ returns the marketplace's total of users ] */ public function get_total_users() { $set = $this->methods["Public"][11]; $public_url = $this->public_url; $url = preg_replace('/set/i', $set, $public_url); return $this->json_encode_as_object([ "Users" => [ "Total" => $this->fetch($url, $set) ] ]); } /* * Get Item Information * * @arguments : [ * * #item ~ the item id ( or ids ) based upon the data is fetched * ] * @returns : [ returns the item information ] */ public function get_item_details() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $information = []; $set = $this->methods["Public"][12]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); $information[$argument] = $this->fetch($url, $set); }; unset($argument); return $this->json_encode_as_object([ "Items" => [ "Information" => $information ] ]); } /* * Get Item Price * * @arguments : [ * * #item ~ the item id ( or ids ) based upon the data is fetched * ] * @returns : [ returns the item price ] */ public function get_item_prices() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $prices = []; $set = $this->methods["Public"][13]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); $prices[$argument] = $this->fetch($url, $set); }; unset($argument); return $this->json_encode_as_object([ "Items" => [ "Prices" => $prices ] ]); } /* * Get Search Results * * @arguments : [ * * #expression ~ the expression based upon the search is done, required argument * #marketplace ~ the marketplace, provided as a filter, it isn't a required argument * #category ~ the category, provided as a filter, it isn't a required argument ( you can additionally pass subcategory and other hierarchy categories ) * ] * @returns : [ returns search results from all marketplaces or by market and or category, limited to the first 50 ] */ public function get_search_results($expression, $marketplace = null, $category = null) { $search = []; $set = $this->methods["Public"][14]; $public_url = $this->public_url; $regex = "/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|" . "[\s,]*'([^']+)'[\s,]*|" . "[\s,]+/"; if (empty($expression)) { return json_encode("[ Search Items [ Failed ][ Expression Required ] ]"); } else { $expression = preg_replace($regex, "|", $expression); } if (!is_null($category)) { $category = preg_replace($regex, "%2f", $category); } $url = preg_replace('/set/i', $set . ":" . ( ( is_null($marketplace) ) ? '' : $marketplace ) . ',' . ( ( is_null($category) ) ? '' : $category ) . ',' . $expression, $public_url ); $search = $this->fetch($url, $set); return $this->json_encode_as_object([ "Items" => [ "Search" => $search ] ]); } /* * Get User Info * * @arguments : [ * * #user ~ the user id ( or ids ) based upon the data is fetched * ] * @returns : [ returns the user info ] */ public function get_user_info() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $users = []; $set = $this->methods["Public"][15]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); $users[$argument] = [ "Information" => $this->fetch($url, $set) ]; }; unset($argument); return $this->json_encode_as_object([ "Users" => $users ]); } /* * Get User Items Count * * @arguments : [ * * #user ~ the user id ( or ids ) based upon the data is fetched * ] * @returns : [ returns the user items count by site ] */ public function get_user_items_by_site() { $arguments = $this->filter_arguments_recursive(func_get_args(), func_num_args()); $users = []; $set = $this->methods["Public"][16]; $public_url = $this->public_url; foreach ($arguments as $key => $argument) { $url = preg_replace('/set/i', $set . ":" . $argument, $public_url); $users[$argument] = [ "Items" => $this->fetch($url, $set) ]; }; unset($argument); return $this->json_encode_as_object([ "Users" => $users ]); } } } ?>

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter