-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrollers.php
102 lines (73 loc) · 1.9 KB
/
controllers.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
<?php
class Redirects {
function delete(){
global $wpdb;
$sql = "DELETE FROM ts_redirects";
$wpdb->query($sql);
}
function edit($title, $section, $new_link, $old_link)
{
global $wpdb;
$sql = $wpdb->prepare("INSERT INTO ts_redirects (title, section, new_link, old_link) VALUES ('%s', '%s', '%s', '%s')", array($title, $section, $new_link, $old_link));
$result = $wpdb->query($sql);
}
function getFields($id){
global $wpdb;
$sql = $wpdb->prepare("SELECT * FROM ts_redirects WHERE id = '%s'", array($id));
$result = $wpdb->query($sql);
if($result!==0)
{
$fields = array();
foreach($wpdb->get_results($sql) as $row)
{
$fields['title'] = $row->title;
$fields['section'] = $row->section;
$fields['new_link'] = $row->new_link;
$fields['old_link'] = $row->old_link;
}
return $fields;
} else {
return false;
}
}
function createRedirectsTable()
{
global $wpdb;
$sql = "CREATE TABLE ts_redirects (id BIGINT(20) PRIMARY KEY AUTO_INCREMENT,title TEXT,section TEXT, new_link TEXT, old_link TEXT)";
$result = $wpdb->query($sql);
}
function checkForRedirectsTable()
{
global $wpdb;
$sql = "SHOW TABLES LIKE 'ts_redirects'";
$result = $wpdb->query($sql);
if($result==1) {
} else {
$this->createRedirectsTable();
}
}
function getAll()
{
global $wpdb;
$this->checkForRedirectsTable();
$sql = "SELECT * FROM ts_redirects ORDER by id ASC";
$result = $wpdb->query($sql);
if($result!==0){
$id_arr = array();
foreach($wpdb->get_results($sql) as $row){
$id_arr[] = $row->id;
}
return $id_arr;
} else {
return false;
}
}
function remove($custom_id)
{
global $wpdb;
$sql = $wpdb->prepare("DELETE FROM ts_redirects WHERE id = '%s'", array($custom_id));
$wpdb->query($sql);
}
}
$redirectsplugin = new Redirects();
$GLOBALS['redirectsplugins'] = $redirectsplugin;