-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchMenu.php
102 lines (80 loc) · 1.7 KB
/
fetchMenu.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
<?php
require 'simple_html_dom.php';
function getLocationID($location)
{
switch ($location)
{
case "danforth":
$id = 143;
break;
case "douglass":
$id = 688;
break;
case "the pit":
$id = 689;
break;
default:
$id = 143;
break;
}
return $id;
}
function getMenuItems($location, $what)
{
$location = strtolower($location);
switch ($what)
{
case 'breakfast':
$what = '#menu1';
break;
case 'lunch':
if ($location == 'danforth' || $location == 'the pit')
{
$what = '#menu1';
}
else if ($location == 'douglass')
{
$what = '#menu2';
}
break;
case 'dinner':
if ($location == 'danforth' || $location == 'the pit')
{
$what = '#menu2';
}
else if ($location == 'douglass')
{
$what = '#menu3';
}
break;
default:
$what = '#menu1';
break;
}
$location = getLocationID($location);
$html = new simple_html_dom();
$html->load_file('http://www.campusdish.com/en-US/CSNE/ROCHESTER/Home.htm?LocationID='.$location);
foreach ($html->find($what .' tbody tr td a[class="item1"]') as $entryTitle)
{
$menuEntries;
$text = strtolower($entryTitle->plaintext);
$formatted = '';
preg_match('/[\w\s\/]+/', $text, $formatted);
$submenu = '';
$entryContent = $entryTitle->next_sibling();
foreach ($entryContent->find('a') as $item)
{
$text = strtolower($item->plaintext);
$submenu[] = $text;
}
$menuEntries[] = array("name"=>trim($formatted[0]), "submenu"=>$submenu);
}
echo json_encode($menuEntries);
$html->clear();
}
if (isset($_GET['location']) && isset($_GET['what']))
{
//fetchMenu.php?location=danforth&what=lunch
getMenuItems(strip_tags($_GET['location']), strip_tags($_GET['what']));
}
?>