-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.php
More file actions
149 lines (109 loc) · 3.44 KB
/
Utilities.php
File metadata and controls
149 lines (109 loc) · 3.44 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
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
141
142
143
144
145
146
147
148
149
<?php
namespace Twist;
use Twist;
/**
*
* @author doug5997
*
*/
class Utilities
{
private $config;
private $connection;
public $log;
function __construct()
{
$this->log = new Logger('Constructed Utilities');
}
public function quote($value)
{
$item = sprintf("'%s'", $value);
return $item;
}
public function hasPrefix($value, $prefix)
{
return stripos($value, $prefix) === 0;
}
private function getConfig()
{
if($this->config != null){
return;
}else{
$file = PLUGIN_DIR . 'app.ini';
if (!$this->config = parse_ini_file($file, TRUE)) {
$this->log->log('Problem reading app.ini.');
//TODO SEND EMAIL ALERT
}
}
}
private function createConnection()
{
global $wpdb;
if($this->connection != null) {
$connection = $this->connection;
}else{
$this->getConfig();
$settings = $this->config;
$credentials = implode(",",array(
$settings['staging']['user'],
$settings['staging']['password'],
$settings['staging']['dbname'],
$settings['staging']['host']
));
$this->connection = new wpdb($this->credentials);
$connection = $this->connection;
}
return $connection;
}
public function getConnection()
{
$connection = $this->createConnection();
return $connection;
}
public function contains($haystack, $needle)
{
return stripos($haystack, $needle) !== false ? true : false;
}
public function createProjectsTable()
{
global $wpdb;
$table = "CREATE TABLE IF NOT EXISTS cab_Projects_Table(id INT NOT NULL AUTO_INCREMENT,uid INT NOT NULL,project TINYTEXT NOT NULL,created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,updated TIMESTAMP, PRIMARY KEY ( id ))";
$results = $wpdb->get_results($table);
$dump = print_r($results, true);
$this->log->log($dump);
}
public function insertProjectName($args)
{
global $wpdb;
try {
$uid = addslashes($args['uid']);
$projectName = addslashes($args['projectName']);
$insert = "INSERT INTO _Projects_Table (id, uid, project) VALUES (null, '$uid','$projectName')";
$this->log->log($insert);
$results = $wpdb->get_results($insert);
$this->log->log(print_r($results));
}catch (\Exception $e){
$this->log->log("error");
}
}
public function selectProjectName($args)
{
global $wpdb;
try {
$uid = addslashes($args['uid']);
$select = "SELECT project FROM _Projects_Table WHERE uid = $uid";
$this->log->log($select);
$results = $wpdb->get_results($select);
return $results;
}catch (\Exception $e){
$this->log->log("select project names error");
}
}
/**
*/
function __destruct()
{
// TODO - Insert your code here
}
}
?>