-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl.php
138 lines (110 loc) · 4.63 KB
/
curl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
//カテゴリ取得
$id = '1';
if(isset($_GET['id'])){
$id = $_GET['id'];
}
$urlC = "http://shopping.yahooapis.jp/ShoppingWebService/V1/json/categorySearch?appid=".$app_id."&category_id=".$id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_URL, $urlC);
$responseC = curl_exec($ch);
$resC = json_decode($responseC, true);
if(!isset($resC["ResultSet"])){
echo '<link rel="stylesheet" type="text/css" href="./style.css" />ただいまご利用いただけません。しばらくお待ちください。<br /><a href="http://tiger4th.com/yamazon/">トップページに戻る</a>';
exit;
}
//アフィリエイトウィジェット
$keyword = "特価";
$category = "";
$query = "";
if(isset($_GET['query'])){
$query = $_GET['query'];
}
if(isset($resC["ResultSet"][0]["Result"]["Categories"]["Current"]["Id"])){
$category = $resC["ResultSet"][0]["Result"]["Categories"]["Current"]["Id"];
}
if($query != ""){
$keyword = $query;
}else{
$urlW = "http://shopping.yahooapis.jp/ShoppingWebService/V1/json/queryRanking?appid=".$app_id."&hits=2&category_id=".$resC["ResultSet"][0]["Result"]["Categories"]["Current"]["Id"];
curl_setopt($ch, CURLOPT_URL, $urlW);
$responseW = curl_exec($ch);
$resW = json_decode($responseW, true);
if(isset($resW["ResultSet"][0]["Result"][0]["Query"]) && substr($resW["ResultSet"][0]["Result"][0]["Query"], 0, 1) != "-"){
if($resW["ResultSet"][0]["Result"][0]["Query"] != "あすつく" && !ctype_digit($resW["ResultSet"][0]["Result"][0]["Query"])){
$keyword = rawurlencode($resW["ResultSet"][0]["Result"][0]["Query"]);
}else{
$keyword = rawurlencode($resW["ResultSet"][0]["Result"][1]["Query"]);
}
}else{
$keyword = $resC["ResultSet"][0]["Result"]["Categories"]["Current"]["Title"]["Medium"];
$keyword = str_replace("全般", "", $keyword);
$keyword = str_replace("その他", "", $keyword);
$keyword = str_replace("関連用品", "", $keyword);
$keyword = str_replace("用品作成", "", $keyword);
$keyword = str_replace("用品", "", $keyword);
$keyword = explode("、", $keyword);
$keyword = explode("(", $keyword[0]);
$keyword = explode("用", $keyword[0]);
if(isset($keyword[1])){$keyword[0] = $keyword[1];}
$keyword = $keyword[0];
}
}
//変数
$newest = "";
$newer = "";
$older = "";
$blinker = "";
$res = array();
$sort = "-score";
$results = 15;
$start = 1;
if(isset($_GET['sort']) && ($_GET['sort'] == '-sold' || $_GET['sort'] == '+price' || $_GET['sort'] == '-price' || $_GET['sort'] == '-score' || $_GET['sort'] == '-review_count')){
$sort = rawurlencode($_GET['sort']);
}
if(isset($_GET['start']) && ctype_digit($_GET['start'])){
$start = $_GET['start'];
}
//商品情報取得
$url = "http://shopping.yahooapis.jp/ShoppingWebService/V1/json/itemSearch?appid=".$app_id."&affiliate_type=vc&affiliate_id=http%3A%2F%2Fck.jp.ap.valuecommerce.com%2Fservlet%2Freferral%3Fsid%3D3146778%26pid%3D883209894%26vc_url%3D&hits=".$results."&category_id=".$id."&sort=".$sort."&offset=".($start-1)."&query=".rawurlencode($query);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
$res = json_decode($response, true);
if(!isset($res["ResultSet"])){
$res["ResultSet"][0] = "";
$res["ResultSet"]["totalResultsAvailable"] = 0;
$res["ResultSet"]["totalResultsReturned"] = 0;
$category = $resC["ResultSet"][0]["Result"]["Categories"]["Current"]["ParentId"];
}
if(!isset($res["ResultSet"]["totalResultsReturned"]) || $res["ResultSet"]["totalResultsReturned"] <= 0){
if($query != ""){
$tweet[0]["text"] = "<span class=\"sm bold\">\"".$query."\"</span><span class=\"sm bold red\">の検索に一致する商品はありませんでした。</span>";
}elseif($start == 1){
$tweet[0]["text"] = "<span class=\"sm bold red\">このカテゴリには商品がありません。</span>";
}else{
$tweet[0]["text"] = "<span class=\"sm bold red\">商品がありません。</span>";
}
}
curl_close($ch);
//ページ移動
if(isset($res["ResultSet"]["totalResultsAvailable"]) && $res["ResultSet"]["totalResultsAvailable"] > $results && !isset($text)){
$base_url = "./index.php?id=".$id."&sort=".$sort;
if($query != ""){
$base_url .= "&query=".$query;
}
if($start > 1){
$newest = '<a href="'.$base_url.'">« 先頭</a> ';
$newer = '<a href="'.$base_url.'&start='.($start - $results).'">‹ 戻る</a>';
}else{
$newer = '‹ 戻る';
}
if($res["ResultSet"]["totalResultsAvailable"] > ($start + $results - 1)){
$older = '<a href="'.$base_url.'&start='.($start + $results).'">次へ ›</a>';
}else{
$older = '次へ ›';
}
$blinker .= $newest.$newer.' | '.$older;
}
?>