-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharedatabasefunctions.php
More file actions
106 lines (89 loc) · 2.98 KB
/
sharedatabasefunctions.php
File metadata and controls
106 lines (89 loc) · 2.98 KB
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
<?php
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
class ShareDatabase {
private $table_name;
private $user_id;
private $platform;
private $db;
function __construct($userid) {
global $wpdb;
$this->db = $wpdb;
$this->table_name = $this->db->prefix . "share_plugin";
$this->user_id = $userid;
$sql = "CREATE TABLE IF NOT EXISTS $this->table_name (
user_id BIGINT,
PRIMARY KEY(user_id),
logged_in int,
access_token_value longtext,
access_token_secret longtext,
topic longtext,
sharers longtext
)
COLLATE utf8_general_ci";
dbDelta($sql);
$this->insertRow();
}
function deleteTable() {
$sql = "DROP TABLE IF EXISTS $this->table_name";
$this->db->query($sql);
dbDelta($sql);
}
private function insertRow() {
$sql = "INSERT INTO $this->table_name (user_id, logged_in, access_token_value, access_token_secret, topic, sharers) VALUES ('$this->user_id', 0, '', '', '', '') ON DUPLICATE KEY UPDATE user_id = $this->user_id";
dbDelta($sql);
}
function setAccessTokenValue($value) {
$sql = "UPDATE $this->table_name SET access_token_value = '$value' WHERE user_id = $this->user_id";
$this->db->query($sql);
}
function setAccessTokenSecret($secret) {
$sql = "UPDATE $this->table_name SET access_token_secret = '$secret' WHERE user_id = $this->user_id";
$this->db->query($sql);
}
function setTopic($topic) {
$sql = "UPDATE $this->table_name SET topic = '$topic' WHERE user_id = $this->user_id";
$this->db->query($sql);
}
function setSharers($sharers) {
$sql = "UPDATE $this->table_name SET sharers = '$sharers' WHERE user_id = $this->user_id";
$this->db->query($sql);
}
function LogIn() {
$sql = "UPDATE $this->table_name SET logged_in = 1 WHERE user_id = $this->user_id";
$this->db->query($sql);
}
function LogOut() {
$sql = "UPDATE $this->table_name SET logged_in = 0 WHERE user_id = $this->user_id";
$this->db->query($sql);
$this->setAccessTokenValue('');
$this->setAccessTokenSecret('');
$this->setTopic('');
$this->setSharers('');
}
function getAccessTokenValue() {
$sql = "SELECT access_token_value FROM $this->table_name WHERE user_id = $this->user_id";
$row = $this->db->get_row($sql, ARRAY_A);
return $row['access_token_value'];
}
function getAccessTokenSecret() {
$sql = "SELECT access_token_secret FROM $this->table_name WHERE user_id = $this->user_id";
$row = $this->db->get_row($sql, ARRAY_A);
return $row['access_token_secret'];
}
function getTopic() {
$sql = "SELECT topic FROM $this->table_name WHERE user_id = $this->user_id";
$row = $this->db->get_row($sql, ARRAY_A);
return $row['topic'];
}
function getSharers() {
$sql = "SELECT sharers FROM $this->table_name WHERE user_id = $this->user_id";
$row = $this->db->get_row($sql, ARRAY_A);
return $row['sharers'];
}
function isLoggedIn() {
$sql = "SELECT logged_in FROM $this->table_name WHERE user_id = $this->user_id";
$row = $this->db->get_row($sql, ARRAY_A);
return $row['logged_in'];
}
}
?>