This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-android_helper.php
135 lines (124 loc) · 3.13 KB
/
wp-android_helper.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
<?php
/**
* Used to be the page which displayed the registration form.
*
* This file is no longer used in WordPress and is
* deprecated.
*
* @package WordPress
* @deprecated Use wp_register() to create a registration link instead
*/
require('./wp-load.php');
function useridmatches($userlogin, $userkey){
$user = get_user_by('login',$userlogin);
$userid = "";
if($user != null){
$userid = $user->ID;
}else{
return false;
}
$val = get_user_meta($user->ID,"session_bcb", true);
if($val == $userkey){
return true;
}
return false;
}
global $wpdb;
$action = $_GET['action'];
if($action == 'auth'){
if( is_user_logged_in()){
$current_user = wp_get_current_user();
if($current_user != null){
$meta = get_user_meta($current_user->ID, "session_bcb", true);
if($meta == ""){
session_start();
$meta = session_id();
add_user_meta($current_user->ID, "session_bcb", "" . $meta);
}
//echo $current_user->ID . "," . $meta;
$url = 'bcbapp://android?id='.$current_user->user_login . "&sid=" . $meta;
echo <<<END
<html>
<head>
</head>
<body>
<script type="text/javascript">
window.location = "$url"
</script>
</body>
</html>
END;
}
}
else{
echo "no user logged in ";
}
}
else if ( $action == 'getuserdata'){
$userid = esc_sql($_GET['userid']);
$userkey = esc_sql($_GET['userkey']);
if(useridmatches($userid, $userkey) == false){
die("user not authenticated");
}
$num = 2616;
$allposts = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta
WHERE post_id >= ".$num." AND meta_key='user_attending' AND meta_value='$userid'");
$allPosts = "'";
$isfirst = true;
foreach ($allposts as $posts) {
if($isfirst == false){
$allPosts = $posts->post_id."','".$allPosts;
}
else{
$allPosts = $posts->post_id."'";
$isfirst = false;
}
}
// echo $allPosts;
$allPosts = "'".$allPosts;
//echo "SELECT * FROM $wpdb->posts WHERE ID IN ($allPosts)";
$allposts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE ID IN ($allPosts)");
if($allposts == null){
die("useless");
}
print "{data: [";
$isfirst = true;
foreach ( $allposts as $posts){
if($isfirst == false){
print ",";
}
$posttitle = str_replace("'","\'",$posts->post_title);
print "{ title: '$posttitle', id: '$posts->ID'}";
$isfirst = false;
}
print " ]}";
}
else if ( $action == 'setuserdata'){
$userid = esc_sql($_GET['userid']);
$userkey = esc_sql($_GET['userkey']);
$newsessionid = esc_sql($_GET['sessionid']);
$setvalue = esc_sql($_GET['isattending']);
if(useridmatches($userid, $userkey) == false){
die("user not authenticated");
}
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id ='$newsessionid' AND meta_key='user_attending' AND meta_value='$userid'");
if( $count == 0 && $setvalue == 'true'){
add_post_meta($newsessionid, 'user_attending', $userid, true);
$wpdb->insert("wp_postmeta",
array(
'post_id'=> $newsessionid,
'meta_key' => 'user_attending',
'meta_value' => $userid
),
array(
"%d","%s","%s")
);
}
else if ( $setvalue == 'false' && $count >= 1){
delete_post_meta($newsessionid, 'user_attending', $userid);
}
print "success";
}
else{
}
?>