/
GrouponCA.php
166 lines (115 loc) · 6.11 KB
/
GrouponCA.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
<?php
class GrouponCA {
public function GetNewDivisions($SID) {
global $DebugMode;
SysLogIt('Checking for new Groupon Canada divisions.');
if (!list ($Data, $DURL) = GetWebData('http://www.groupon.ca/', null, 'user_locale=en_CA')) { return SysLogIt('Error getting web data.', StatusError); }
if ($DebugMode) file_put_contents("GrouponCACity.txt", $Data);
SysLogIt('Parsing HTML.');
$DataArray = FindSubData($Data, 'id="citySelectBox"', '<ul', '</ul>', false);
if ($DataArray === false) return SysLogIt("Couldn't find city content.", StatusError);
//Large Centres
$DataArray = explode('</li>', $DataArray);
foreach ($DataArray as $DataItem) {
if (stripos($DataItem, 'http://www.groupon.ca/') !== false) {
$ID = FindData($DataItem, 'http://www.groupon.ca/', "'", 22, 0, false, 0, false);
$Name = FindSubData($DataItem, 'http://www.groupon.ca/', '<span>', '</span>', false);
if ($Name !== false && $ID !== false) {
if ($Name == '') $Name = ucwords($ID);
if (!CheckURL('Groupon Canada', $SID, $Name, $ID)) return false;
}
}
}
return UpStatus('Groupon Canada', $SID);
}
public function GetDivisionData($SRID, $URL, $LID, $TZ, $Sub = false, $WebD = false) {
global $DebugMode;
list ($Data, $DURL) = GetWebData('http://www.groupon.ca/'.$URL, null, 'user_locale=en_CA'); //fr_CA
if ($Data === false) return array(SysLogIt('Error getting web data.', StatusError), null);
if ($DebugMode) file_put_contents("GrouponCA.txt", $Data);
if (stripos($Data, '/payment') === false) return array(true, false);
$NewDeal = array (
"ID" => array('', 'http://www.facebook.com/share.php', '?u=http://www.groupon.ca', '"', false),
"Title" => array('', 'id="contentDealTitle"', '<h1>', '</h1>', false),
"PriceSale" => array(0, 'class="price"', 'C$', '<', true),
"Savings" => array(0, 'class="row2"', 'C$', '<', true),
"StoreName" => array('', 'class="merchantContact"', '>', '</h2>', false),
"Website" => array('', 'class="merchantContact"', 'href="', '"', false, true),
"Description" => array('', 'class="contentBoxNormalLeft"', '>', '<div', false),
"EndDate" => array(0, 'id="currentTimeLeft"', 'value="', '"', true)
);
if (!GetNewDealData($Data, $NewDeal)) return array(SysLogIt('Error finding key deal information.', StatusError), null);
//Start, end dates
$StartDate = time();
$EndDate = time();
$EndDate += ((int)$NewDeal['EndDate'][0] / 1000);
if ($EndDate <= time()) return array(SysLogIt('Could not determine deal end date.', StatusError), null);
//Store name
$StoreName = CleanHTML($NewDeal['StoreName'][0]);
//Expiry Date
$VExpiry = FindData($Data, '<li>Expires', '<', 11, 0, false, 0, false);
if ($VExpiry !== false) $VExpiry = strtotime($VExpiry);
if ($VExpiry === false) $VExpiry = 0;
$Website = null;
if ($NewDeal['Website'][0] !== false) $Website = $NewDeal['Website'][0];
//Address(es)
if ((stripos($Data, '<strong>Locations') === false) && (stripos($Data, 'locations:</strong>') === false)) {
$Addresses = FindSubData($Data, 'class="merchantContact"', '</h2>', '<a', false, 0, false);
if ($Addresses !== false) $Addresses = array($Addresses);
if ($Addresses === false) $Addresses = array();
} else {
$Addresses = FindSubData($Data, '<strong>Locations', '</strong>', '<p', false, 0, false);
if ($Addresses === false) $Addresses = FindSubData($Data, 'locations:</strong>', '</p>', '<p', false, 0, false);
if ($Addresses !== false) $Addresses = explode('<br /><br />', $Addresses);
if ($Addresses === false) $Addresses = array();
}
$Locations = array();
foreach ($Addresses as &$Adr) {
if ((!is_null($Adr)) && ($Adr != '')) {
if (stripos($Adr, 'online') !== false) {
$Locations[] = array(CleanHTML($Adr), -1, -1);
} else {
$Locations[] = array(CleanHTML($Adr), 0, 0);
}
}
}
if (count($Locations) == 0) $Locations[] = array(null, 0, 0);
//Side deals
$Last = $NewDeal['ID'][0];
$MoreDeals = array();
$Start = stripos($Data, '"/deals/');
while ($Start !== false) {
$New = FindData($Data, '"/deals/', '"', 1, 0, false, $Start, false);
if (($New !== false) && ($New != $Last)) {
$MoreDeals[] = $New;
$Last = $New;
}
$Start = stripos($Data, '"/deals/', $Start + 20);
}
$TitleFR = '';
list ($Data, $DURL) = GetWebData('http://www.groupon.ca/'.$URL, null, 'user_locale=fr_CA');
if ($Data !== false) {
$TitleFR = FindSubData($Data, 'id="contentDealTitle"', '<h1>', '</h1>', false, 0, false);
if ($TitleFR !== false) $TitleFR = CleanHTML($TitleFR);
}
//Save
$RData = array();
$RData['DRID'] = $NewDeal['ID'][0];
$RData['Title'] = CleanHTML($NewDeal['Title'][0]);
if (($TitleFR !== false) && ($TitleFR != '')) $RData['Title-fr'] = $TitleFR;
$RData['Descr'] = $NewDeal['Description'][0];
$RData['URL'] = 'http://www.groupon.ca'.$NewDeal['ID'][0];
$RData['Price'] = (double)$NewDeal['PriceSale'][0];
$RData['Value'] = (double)$NewDeal['PriceSale'][0] + (double)$NewDeal['Savings'][0];
$RData['Status'] = 0;
$RData['SDate'] = $StartDate;
$RData['EDate'] = $EndDate;
$RData['VDate'] = $VExpiry;
$RData['StoreName'] = $StoreName;
$RData['Website'] = $Website;
$RData['Locations'] = $Locations;
if (count($MoreDeals) > 0) $RData['Deals'] = $MoreDeals;
return array(true, array($RData));
}
}
?>