purevtsooj

Get Categories

Oct 20th, 2014
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.     Usage: yourpath/file.php?s=1 - [1..8]
  5. */
  6.  
  7. function get_dataa($url) {
  8.     $ch = curl_init();
  9.     $timeout = 5;
  10.     curl_setopt($ch, CURLOPT_URL, $url);
  11.     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)");
  12.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  13.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
  14.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
  15.     curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
  16.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  17.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  18.     $data = curl_exec($ch);
  19.     curl_close($ch);
  20.     return $data;
  21. }
  22.  
  23. $sites = array("",
  24.                 "themeforest",   //-1
  25.                 "codecanyon",   //-2
  26.                 "videohive",    //-3
  27.                 "audiojungle",  //-4
  28.                 "graphicriver", //-5
  29.                 "photodune",    //-6
  30.                 "3docean",      //-7
  31.                 "activeden");   //-8
  32.  
  33.  
  34. if( !isset($_GET['s']) )
  35.     exit;
  36.  
  37. if( (int)$_GET['s']>0 && (int)$_GET['s']<9 ){
  38.     $index = (int)$_GET['s'];
  39.     $url = "http://marketplace.envato.com/api/edge/categories:$sites[$index].json";
  40.     $data = get_dataa($url);
  41.    
  42.     $cats = array();
  43.     if( !empty($data) ){
  44.         $json = json_decode($data);
  45.         if( isset($json->categories) ){
  46.             foreach ($json->categories as $value) {
  47.                 $cats []= array( 'name'=>$value->name, 'path'=>$value->path );
  48.             }
  49.         }
  50.     }
  51.  
  52.     echo '&lt;option value="http://'.$sites[$index].'.net/feeds/new-'.$sites[$index].'-items.atom" title="All feed"&gt;All Categories Feed&lt;/option&gt;';
  53.     echo "<br>";
  54.     foreach ($cats as $value) {
  55.         $name = $value['name'];
  56.         $path = $value['path'];
  57.         $p = str_replace("/", "-slash-", $path);
  58.         $uri = "http://$sites[$index].net/feeds/new-$p-items.atom";
  59.  
  60.         $xp = explode("/", $path);
  61.         $count = count($xp)-1;
  62.         $title = str_repeat("&amp;nbsp;&amp;nbsp;&amp;nbsp;", $count) . $name;
  63.  
  64.         echo '&lt;option value="'.$uri.'"&gt;'.$title.'&lt;/option&gt;';
  65.         echo "<br>";
  66.     }
  67.  
  68. }
  69.  
  70.  
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment