/
rss.php
138 lines (117 loc) · 4.57 KB
/
rss.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
// Create an RSS Feed
require("app/app-config.php");
require("app/db-config.php");
require("app/HtmlElement.class.php");
require("app/MysqlDatabase.class.php");
class RSS extends MysqlDatabase
{
public $feed = array();
public $localData = array();
public function __construct( $data )
{// construct RSS Class
$this->localData = $data;
parent::Connect( dbHost, dbUser, dbPass, dbName );
switch( $this->localData[ "feed_type" ] )
{
case 'by_location' :
parent::SetQuery("SELECT * FROM `table_locations` WHERE location_id='{$this->localData["location_id"]}'");
$locationData = parent::DoQuery();
$this->CreateRSS("SELECT * FROM `table_offerlocations`,`table_offers` WHERE
`table_offers`.`offer_id`=`table_offerlocations`.`offer_id` AND
`table_offerlocations`.`location_id`='{$this->localData["location_id"]}'
ORDER BY expiration DESC LIMIT 15",
'Find My Monkey, Recent Deals in ' . $locationData[0]["location"],
'http://www.findmymonkey.com/offers?location_id=' . $this->localData["location_id"],
'Get the latest Monkey Deals in ' .$locationData[0]["location"] . '!');
break;
case 'most_recent' :
$this->CreateRSS("SELECT * FROM `table_offers` ORDER BY expiration DESC LIMIT 15",
'Find My Monkey, Deals RSS',
'http://www.findmymonkey/offers',
'Get the latest Monkey Deals for Find My Monkey.');
break;
}
}
public function CreateRSS( $query, $title_p, $link_p, $description_p )
{// recent
$rss_top = new HtmlElement('rss');
$rss_top->Set('version', '2.0');
$channel = new HtmlElement('channel');
$title = new HtmlElement('title');
$title->Set('text', $title_p);
$link = new HtmlElement('link');
$link->Set('text', $link_p);
$description = new HtmlElement('description');
$description->Set('text', $description_p);
$language = new HtmlElement('language');
$language->Set('text', 'en-us');
$webmaster = new HtmlElement('webMaster');
$webmaster->Set('text', 'admin@findmymonkey.com');
$channel->Inject( $title );
$channel->Inject( $link );
$channel->Inject( $description );
$channel->Inject( $language );
$channel->Inject( $webmaster );
parent::SetQuery( $query );
$exists = parent::CountDBResults();
if( $exists )
{// records exist
$num = 0;
$results = parent::DoQuery();
while( $results[ $num ] )
{// loop through results
$item = new HtmlElement('item');
$title = new HtmlElement('title');
$title->Set('text', $results[ $num ][ "one_liner" ] );
$link = new HtmlElement('link');
$append_to_url[] = "offer_id={$results[$num]["offer_id"]}";
$offer_url = "offer-details";
if( $this->localData["aff_id"] )
{// affiliate set
$append_to_url[] = "aff_id={$this->localData["aff_id"]}";
}
if( $this->localData["location_id"] )
{// location id set
//$append_to_url[] = "location_id={$this->localData["location_id"]}";
$offer_url = "offer-details";
}
if( sizeOf( $append_to_url ) > 0 )
{// append parameters to URL
$appended_url_string = "?" . join("&", $append_to_url );
}
$link->Set('text', 'http://www.findmymonkey.com/' . $offer_url . $appended_url_string );
parent::SetQuery("SELECT * FROM `table_offerlocations`,`table_locations` WHERE
`table_offerlocations`.`location_id`=`table_locations`.`location_id`
AND
`table_offerlocations`.`offer_id`='{$results[$num]["offer_id"]}'");
$offerLocations = parent::DoQuery();
$locationArr = array();
foreach( $offerLocations as $offerLocation )
{// loop through each location
$locationArr[] = $offerLocation["location"];
}
$locationStr = join(", ", $locationArr);
$description = new HtmlElement('description');
$description->Set('text', $results[ $num ][ "description" ].
htmlentities( "<br/><br/>A <b>\${$results[$num]["value"]} value</b> for <i>only</i> <b>\${$results[$num]["price"]}</b>"
. " - Limit: <b>{$results[$num]["limit"]}</b>"
. "<br/><br/>Offer Available for these Locations: {$locationStr}<br/><br/>"
. "" , ENT_QUOTES ));
$pubDate = new HtmlElement('pubDate');
$pubDate->Set('text', date("M-d-Y H:i:s", time()));
$item->Inject( $title );
$item->Inject( $link );
$item->Inject( $description );
$item->Inject( $pubDate );
$channel->Inject( $item );
$num+=1;
}
$rss_top->Inject($channel);
echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
echo $rss_top->BuildHTML();
}
}
}
$RSS = new RSS( array_merge( $_GET, $_POST ) );
?>