Advertisement
Guest User

Untitled

a guest
May 25th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1.  
  2. function Prosperent($term, $x=0, $perlu='keyword'){
  3. $api = '51bf441d80d02bbad997b0feb2896ccf';
  4. $url = 'http://api.prosperent.com/api/search?api_key='.$api.'&query='.urlencode($term);
  5. $curl = curl_init();
  6. curl_setopt_array($curl, array(
  7. CURLOPT_RETURNTRANSFER => 1,
  8. CURLOPT_URL => $url,
  9. CURLOPT_CONNECTTIMEOUT => 30,
  10. CURLOPT_TIMEOUT => 30
  11. ));
  12. $response = curl_exec($curl);
  13.  
  14. curl_close($curl);
  15.  
  16. $response = json_decode($response, true);
  17.  
  18. if (count($response['errors']))
  19. {
  20. throw new Exception(implode('; ', $response['errors']));
  21. }
  22.  
  23. $data = $response['data'];
  24. if(!empty($data)){
  25. $array = array();
  26. foreach ($data as $key => $value){
  27. $item = array(
  28. 'title' => $value['keyword'],
  29. 'desc' => $value['description'],
  30. 'img' => $value['image_url'],
  31. 'link' => $value['affiliate_url'],
  32. 'price' => $value['price'],
  33. 'currency' => $value['currency'],
  34. 'merchant' => $value['merchant'],
  35. 'brand' => $value['brand'],
  36. );
  37. array_push($array, $item);
  38. }
  39.  
  40. foreach($array as $a){
  41. $desc[] = $a['desc'];
  42. $title[] = $a['title'];
  43. $link[] = $a['link'];
  44. $img[] = $a['img'];
  45. $price[] = $a['price'];
  46. $currency[] = $a['currency'];
  47. $merchant[] = $a['merchant'];
  48. $brand[] = $a['brand'];
  49. }
  50.  
  51. $deskripsi = array_unique($desc);
  52. $judul = array_unique($title);
  53. $url = array_unique($link);
  54. $gambar = array_unique($img);
  55. $hrg = array_unique($price);
  56. $matauang = array_unique($currency);
  57. $toko = array_unique($merchant);
  58. $produk = array_unique($brand);
  59.  
  60. if($perlu == 'aff'){
  61. if(!empty($url[$x])){$isi = $url[$x];} else {$isi = '';}
  62. } else if($perlu == 'gbr'){
  63. if(!empty($gambar[$x])){$isi = $gambar[$x];} else {$isi = '';}
  64. } else if($perlu == 'desc'){
  65. if(!empty($deskripsi[$x])){$isi = filterku($deskripsi[$x]);} else {$isi = '';}
  66. } else if($perlu == 'hrg'){
  67. if(!empty($hrg[$x])){$isi = $hrg[$x];} else {$isi = '';}
  68. } else if($perlu == 'uang'){
  69. if(!empty($matauang[$x])){$isi = $matauang[$x];} else {$isi = '';}
  70. } else if($perlu == 'toko'){
  71. if(!empty($toko[$x])){$isi = $toko[$x];} else {$isi = '';}
  72. } else if($perlu == 'produk'){
  73. if(!empty($produk[$x])){$isi = $produk[$x];} else {$isi = '';}
  74. } else {
  75. if(!empty($judul[$x])){$isi = filterku($judul[$x]);} else {$isi = '';}
  76. }
  77.  
  78. return $isi;
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement