-
Notifications
You must be signed in to change notification settings - Fork 2
/
showproducts.php
426 lines (363 loc) · 14.8 KB
/
showproducts.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<?php
error_reporting(0);
session_start();
/*
* author: Jayaseelan Gabriel
* Run: getproductlist.php?userid=ID&boardname=BOARDNAME
*example: http://localhost/<appname>/getproductlist.php?userid=rockey_nebhwani&boardname=value-clocks
*/
//error_reporting(0);
require_once 'simple_html_dom.php';
include_once 'constants.php';
include_once 'utility.php';
function getTextBetweenTags($string) {
//"totalPages": 7
$pattern = "/totalPages\": (\d)/";
preg_match($pattern, $string, $matches);
if(count($matches)>0){
return str_replace('"',"",$matches[0]);
}
return '';
}
$id=trim($_GET['id']);
$explodeArray=explode("/", $id);
$userid= $explodeArray[1];
$boardname=$explodeArray[2];
// Get pins from local database
$pinsArray=getPinsByPinnerId($userid);
$url = "http://pinterest.com/$userid/$boardname/";
$html = file_get_html($url);
$totalnumberofpage='';
// Check for total number of pages.
foreach($html->find('script') as $e){
$x=getTextBetweenTags($e);
if($x!=''){
$totalnumberofpage=$x;
}
}
if($totalnumberofpage!=''){
$arr=explode(":",$totalnumberofpage);
$totalPages= trim($arr[1]);
}else{
$totalPages=1;
}
$rs = array();
$productName='';
$productURL='';
$productDomain='';
$productImageURL='';
$data_id='';
$ii=0;
for($i=1;$i<=$totalPages;$i++){
$url = "http://pinterest.com/$userid/$boardname/?page=".$i;
$html = file_get_html($url);
foreach($html->find('div[class=pin]') as $pin){
$productName=$pin->find('p[class=description]',0)->plaintext;
$productURL=$pin->find('p[class=NoImage] a',0)->href;
$productDomain=$pin->find('p[class=NoImage] a',0)->plaintext;
$productImageURL=$pin->find('img[class=PinImageImg]',0)->src;
$data_id=$pin->getAttribute('data-id');
//PinImageImg
// Added Country code
//$cleanURLs = cleanProductURLs($productURL) . "#" . getcountryCode($productDomain);;
$cleanURLs = cleanProductURLs($productURL);
// Created an based on locale. Same locale products were saved in single array element.
if(isset($urls[getcountryCode($productDomain)])){
$urls[getcountryCode($productDomain)]= $urls[getcountryCode($productDomain)] ."|" . $cleanURLs;
}else{
$urls[getcountryCode($productDomain)]=$cleanURLs;
}
$rs[$ii++]=array($productName,$productDomain,$productURL,$productImageURL,$data_id);
}
}
/* Convert URL array in PIPE delimited string. This is needed to pass this to Google API */
//$urlString = implode('|',$urls);
/* Google API will return JSON object */
if($PRICETRACKING=="G"){
foreach ($urls as $k=>$v){
$results= fetchGoogleAPIResults($v,$k);
}
//$results = fetchGoogleAPIResults($urlString);
/* Decode JSON object returned by Google API */
$obj = json_decode($results,true);
/* foreach(search($obj, "price") as $price){
$total_price=$total_price+$price['price'];
} */
$linkArray=search($obj, "link");
//print_r($linkArray);
}else{
$linkArray=array();
}
$total_price=0;
//header('Content-type: application/json');
//echo json_encode($rs);
//print_r($rs);
/* $rss = new SimpleXMLElement('http://api-product.skimlinks.com/query?q=url:"http://www.target.com/p/Keurig-V700-Vue-Brewer/-/A-14007156"&key=0108d30aa31f2c12266dc8560193a93b&format=xml', null, true);
echo "<br>----Status:".$rss->status;
echo "<br>----Price :".$rss->products->product->price;
echo "<br>----Merchant: ".$rss->products->product->merchant;
echo "<br>----Merchant ID: ".$rss->products->product->merchantId;
echo "<br>----Product ID: ".$rss->products->product->productId;
echo "<br>----Num Found: " . $rss->numFound;
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Value Clocks</title>
<link rel="icon" href="http://passets-cdn.pinterest.com/images/favicon.png" type="image/x-icon" />
<link rel="apple-touch-icon-precomposed" href="http://passets-cdn.pinterest.com/images/ipad_touch_icon.png" />
<link rel="stylesheet" href="http://passets-cdn.pinterest.com/css/pinboard_a38aaafa.css" type="text/css" media="all"/>
<!--[if (gt IE 6)&(lt IE 9)]><link rel="stylesheet" href="http://passets-cdn.pinterest.com/css/ie7-and-up_83d98ccb.css" type="text/css" media="all" /><![endif]-->
<script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script>
<script type="text/javascript">if (!window.console) { window.console = {log: function(){}} };</script>
<script type="text/javascript">window.repinExperiment = "";</script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://passets-cdn.pinterest.com/js/bundle_pin_4d500df1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function addall(){
alert("hai");
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("action", "showindividualproduct.php");
for(var i=0;i<document.productform.length;i++){
var hiddenFieldPinId = document.createElement("input");
hiddenFieldPinId.setAttribute("name", "pinid[]");
hiddenFieldPinId.setAttribute("value", document.productform[i].pinid.value);
form.appendChild(hiddenFieldPinId);
var hiddenFieldPinerId = document.createElement("input");
hiddenFieldPinerId.setAttribute("name", "pinnerId");
hiddenFieldPinerId.setAttribute("value", document.productform[i].pinnerId.value);
form.appendChild(hiddenFieldPinerId);
var hiddenFieldId = document.createElement("input");
hiddenFieldId.setAttribute("name", "id");
hiddenFieldId.setAttribute("value", document.productform[i].id.value);
form.appendChild(hiddenFieldId);
var hiddenFieldcurrentPrice = document.createElement("input");
hiddenFieldcurrentPrice.setAttribute("name", "currentPrice[]");
hiddenFieldcurrentPrice.setAttribute("value", document.productform[i].currentPrice.value);
form.appendChild(hiddenFieldcurrentPrice);
var hiddenFieldproductURL = document.createElement("input");
hiddenFieldproductURL.setAttribute("name", "productURL[]");
hiddenFieldproductURL.setAttribute("value",encodeURIComponent(document.productform[i].productURL.value));
form.appendChild(hiddenFieldproductURL);
}
var ReqType = document.createElement("input");
ReqType.setAttribute("name", "requestType");
ReqType.setAttribute("value","addall");
form.appendChild(ReqType);
document.body.appendChild(form);
form.submit();
}
</script>
</head>
<body>
<div id="Header">
<div class="LiquidContainer HeaderContainer">
<a href="/" id="Pinterest"><img src="http://passets-cdn.pinterest.com/images/LogoRed.png" width="100" height="26" alt="Pinterest Logo" /></a>
<!-- top level Menu -->
<ul id="Navigation">
<li>
<a href="/about/" class="nav">About<span></span></a>
<ul>
<li><a href="/about/help/">Help</a></li>
<li class="divider"><a href="/about/terms/">Terms of Service</a></li>
<li><a href="/about/privacy/">Privacy Policy</a></li>
<li><a href="/about/copyright/">Copyright</a></li>
<li><a href="/about/trademark/">Trademark</a></li>
</ul>
</li>
<li>
<?php if(isset($_SESSION['auth'])){?>
<a href="logout.php" class="nav LoginNav">Logout</a>
<?php }?>
</li>
</ul>
</div>
</div>
<div id="wrapper" class="BoardLayout">
<script type="text/javascript">
$(document).ready(function() {
Nag.setup('UnauthCallout');
});
</script>
<div id="BoardTitle">
<h1 class="serif"><strong><?php echo $boardname;?><span id="BoardLikeButton"></span></strong></h1>
<div id="BoardMeta">
<div id="BoardUsers">
<a href="#/<?php echo $userid;?>/" class="ImgLink"></a>
<span id="BoardUserName"><?php echo $userid;?></span>
<input type="button" name="addall" value="Add All" onclick="addall();"/>
</div>
<div id="BoardStats"><strong>Total price of Products: <span id="total_price"> </span></strong>
</div>
<div id="BoardButton">
</div>
</div><!-- #BoardMeta -->
</div><!-- #BoardTitle -->
<div id="ColumnContainer" style="margin-top: 16px;">
<?php
foreach ($rs as $r){
$tempurl=explode("#",$r[2]);
if(count($tempurl)==1){
$tempurl=explode("?",$r[2]);
}
$productIndividualPrice=getProductPrice($linkArray, $tempurl[0],$PRICETRACKING);
$total_price=$total_price+$productIndividualPrice;
if($productIndividualPrice!=''){
?>
<form action="showindividualproduct.php" method="post" name="productform">
<div class="pin" data-id="<?php echo $r[4];?>" data-width="600" data-height="800">
<div class="PinHolder">
<div class="actions">
<div class="right">
</div>
<div class="left">
<a href="#" class="Button Button11 WhiteButton">
<?php if(array_key_exists($r[4], $pinsArray)){?>
<input type="submit" name="rfa" value="Remove from alert">
<?php }else{?>
<input type="submit" name="ata" value="Add to alert">
<?php }?>
</a>
</div>
</div>
<a href="/pin/<?php echo $r[4];?>/" class="PinImage ImgLink">
<img src="<?php echo $r[3];?>" alt="Stylish red clock" class="PinImageImg" style="height: 256px;" />
<?php if($productIndividualPrice!=''){?>
<strong class="PriceContainer"><strong class="price"><?php echo $productIndividualPrice;?> GBP</strong></strong>
<?php }?>
</a>
</div>
<p class="description"><?php echo $r[0];?></p>
<p class="stats colorless">
<span class="RepinsCount">
<?php //echo $tempurl[0];?>
</span>
</p>
<div class="convo attribution clearfix">
<p class="NoImage">
<a href="<?php echo $r[2];?>" target="_blank" rel="nofollow"><?php echo $r[1];?></a></p>
</div>
</div>
<input type="hidden" name="pinid" value="<?php echo $r[4];?>">
<input type="hidden" name="pinnerId" value="<?php echo $userid;?>">
<input type="hidden" name="id" value="<?php echo $id;?>">
<input type="hidden" name="currentPrice" value="<?php echo $productIndividualPrice;?>" />
<input type="hidden" name="productURL" value="<?php echo$r[2]; ?>">
</form>
<?php }?>
<?php
}
?>
</div>
<div id="fb-root"></div>
<a class="MoreGrid Button WhiteButton Button18" href="?page=2" style="display:none"><strong>More Pins</strong><span></span></a>
<div id="LoadingPins"><img src="http://passets-cdn.pinterest.com/images/BouncingLoader.gif" alt="Pin Loader Image" /><span>Fetching pins…</span></div>
</div>
</body>
<script type="text/javascript">
document.getElementById('total_price').innerHTML='<?php echo $total_price;?>' + " GBP";
</script>
<script type="text/javascript">
var board = 56084026548592326;
BoardLayout.setup();
$.pageless.settings.complete = function() {
if ($.pageless.settings.currentPage == 10) {
$(".MoreGrid").css('display', 'block');
}
BoardLayout.newPins();
};
$(document).ready(function() {
// Show user / collaborator names on :hover
$('.collaborator').tipsy();
$('#ColumnContainer').pageless({
"totalPages": 1,
"currentPage": 1,
"loader": "LoadingPins",
"distance": 3000
});
if (50 > 8) {
$('#LoadingPins').hide();
}
// Prevent click-jacking
if (top != self) {
$('body').html('<h1>Unauthorized</h1>')
}
});
</script>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: '274266067164',
status: true,
cookie: true,
xfbml: true
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());
</script>
<div id="SearchAutocompleteHolder"></div>
<script type="text/javascript">
function trackGAEvent(category, action, label, value) {
_gaq = _gaq || []
// Event
_gaq.push(['_trackEvent', category, action, label, value]);
// Virtual Page
virtual_page = '_event_';
virtual_page += "/" + category;
if(!action) action = '_';
virtual_page+="/" + action;
if(label) virtual_page+= "/" + label;
_gaq.push(['_trackPageview', virtual_page]);
}
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12967896-1']);
_gaq.push(['_setCustomVar', 1, 'is_logged_in', 'logged out', 2]);
_gaq.push(['_setCustomVar', 2, 'page_name', 'board', 1]);
trackGAEvent('board_view', 'viewed');
_gaq.push(['_trackPageview', '/board/?name=Value Clocks']);
(function() {
var ga = document.createElement('script'); ga.type='text/javascript'; ga.async=true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
<script type="text/javascript">
var autoLoginFbook = function(response) {
if (response.status !== 'connected') {
return;
}
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
$.post("/login/facebook/", {
access_token: accessToken,
fb_id: uid},
function(resp) {
if (resp.status === "success") {
window.location.reload()
}
});
};
window.fbAsyncInit = function() {
FB.init({
appId: 274266067164,
cookie: true
});
FB.getLoginStatus(autoLoginFbook);
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
var scriptTag = document.getElementsByTagName('script')[0];
scriptTag.parentNode.appendChild(e);
} ());
</script>
</html>