forked from drewry/hype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
140 lines (108 loc) · 2.81 KB
/
index.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
<?php
require_once('inc/config.php');
if(!isset($_GET['p'])) {
$_GET['p'] = 'home';
}
if(isset($_POST['a'])) {
switch($_POST['a']) {
case 'checkin' :
unset($_POST['a']);
extract($_POST);
$row = $h->db->query_first("SELECT id FROM users WHERE email = '$email' OR user_Name = '$email'");
if($row) {
$user_id = $row['id'];
$h->db->query("SELECT check_In($user_id, 1)");
$user = $h->get_user($user_id);
echo json_encode($user);
} else {
echo json_encode('fail');
}
exit;
break;
case 'signup' :
unset($_POST['a']);
extract($_POST);
// add a new user row, sign them up and check them in
$user_id = $h->create_user($_POST);
$h->signup($user_id, $email, $pass);
$h->db->query("SELECT check_In($user_id, 1)");
$user = $h->get_user($user_id);
echo json_encode($user);
exit;
break;
default :
break;
}
}
switch($_GET['p']) {
case 'foursquare' :
$h->foursquare($_POST['checkin']);
break;
case 'nfc' :
$user_id = $_GET['nfc'];
$h->nfc($user_id);
echo 'You are now checked into the hype';
break;
case 'clear' :
session_start();
session_destroy();
header('Location: index.php?p=checkin');
break;
case 'twitter' :
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$screen_name = str_replace('@','',$_POST['screen_name']);
$email = $_POST['email'];
$user = $twitter->get("users/show", array('screen_name' => $screen_name));
$name_parts = explode(" ", $user->name);
if(count($name_parts) == 2) {
$firstname = $name_parts[0];
$lastname = $name_parts[1];
} elseif(count($name_parts) == 3) {
$firstname = $name_parts[0].' '.$name_parts[1];
$lastname = $name_parts[2];
} else {
$firstname = $user->name;
}
$insert_data = array(
'firstname' => $firstname,
'lastname' => $lastname,
'twitter' => $screen_name,
'user_Name' => $screen_name,
'avatar' => $user->profile_image_url
);
$user_id = $h->create_user($insert_data);
$h->signup($user_id, $email);
$h->db->query("SELECT check_In($user_id, 1)");
$user = $h->get_user($user_id);
include('views/header.php');
include('views/twitter.php');
include('views/footer.php');
break;
case 'welcome' :
$user = $h->get_most_recent();
if($user) {
echo "<img src='{$user['avatar']}'><h2>Welcome {$user['firstname']} {$user['lastname']} to Hypepotamus</h2>";
} else {
echo 0;
}
exit;
break;
case 'checkins' :
$users = $h->get_users();
include('views/checkins.php');
exit;
break;
case 'checkin' :
$title = 'Checkin to Hypepotamus';
include('views/header.php');
include('views/checkin.php');
include('views/footer.php');
break;
default :
$title = 'Welcome to Hypepotamus';
$users = $h->get_users();
include('views/header.php');
include('views/home.php');
include('views/footer.php');
break;
}