Skip to content

Commit 0fe0051

Browse files
committed
tab to space conversion
1 parent 9306c74 commit 0fe0051

File tree

6 files changed

+543
-543
lines changed

6 files changed

+543
-543
lines changed

system/DB.php

Lines changed: 144 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -33,122 +33,122 @@
3333
namespace System;
3434

3535
class DB {
36-
static $q, $c, $p, $i = '`';
37-
38-
/**
39-
* Fetch a column offset from the result set (COUNT() queries)
40-
*
41-
* @param string $query query string
42-
* @param array $params query parameters
43-
* @param integer $key index of column offset
44-
* @return array|null
45-
*/
46-
static function column($query, $params = null, $key = 0) {
47-
if ($statement = self::query($query, $params)) {
48-
return $statement->fetchColumn($key);
49-
}
50-
}
51-
52-
/**
53-
* Fetch a single query result row
54-
*
55-
* @param string $query query string
56-
* @param array $params query parameters
57-
* @return mixed
58-
*/
59-
static function row($query, $params = null) {
60-
if ($statement = self::query($query, $params)) {
61-
return $statement->fetch();
62-
}
63-
}
64-
65-
/**
66-
* Fetches an associative array of all rows as key-value pairs (first
67-
* column is the key, second column is the value).
68-
*
69-
* @param string $query query string
70-
* @param array $params query parameters
71-
* @return array
72-
*/
73-
static function pairs($query, $params = null) {
74-
$data = array();
75-
if ($statement = self::query($query, $params)) {
76-
while ($row = $statement->fetch(\PDO::FETCH_NUM)) {
77-
$data[$row[0]] = $row[1];
78-
}
79-
return $data;
80-
}
81-
}
82-
83-
/**
84-
* Fetch all query result rows
85-
*
86-
* @param string $query query string
87-
* @param array $params query parameters
88-
* @param int $column the optional column to return
89-
* @return array
90-
*/
91-
static function fetch($query, $params = null, $column = null) {
92-
if (!$statement = self::query($query, $params)) {
93-
return;
94-
}
95-
96-
// Return an array of records
97-
if ($column === null) {
98-
return $statement->fetchAll();
99-
}
100-
101-
// Fetch a certain column from all rows
102-
return $statement->fetchAll(\PDO::FETCH_COLUMN, $column);
103-
}
104-
105-
/**
106-
* Prepare and send a query returning the PDOStatement
107-
*
108-
* @param string $query query string
109-
* @param array $params query parameters
110-
* @return object|null
111-
*/
112-
static function query($query, $params = null) {
113-
$statement = static::$c->prepare(self::$q[] = strtr($query, '`', self::$i));
114-
$statement->execute($params);
115-
return $statement;
116-
}
117-
118-
/**
119-
* Insert a row into the database
120-
*
121-
* @param string $table name
122-
* @param array $data
123-
* @return integer|null
124-
*/
125-
static function insert($table, array $data) {
126-
$query = "INSERT INTO `$table` (`".implode('`, `', array_keys($data)).'`) VALUES ('.rtrim(str_repeat('?, ', count($data = array_values($data))), ', ').')';
127-
return self::$p ? self::column($query.' RETURNING `id`', $data) : (self::query($query, $data) ? static::$c->lastInsertId() : null);
128-
}
129-
130-
/**
131-
* Update a database row
132-
*
133-
* @param string $table name
134-
* @param array $data
135-
* @param array $w where conditions
136-
* @return integer|null
137-
*/
138-
static function update($table, $data, $value, $column = 'id') {
139-
$keys = implode('`=?,`', array_keys($data));
140-
if ($statement = self::query("UPDATE `$table` SET `$keys` = ? WHERE `$column` = ?", array_values($data + array($value)))) {
141-
return $statement->rowCount();
142-
}
143-
144-
}
145-
146-
/**
147-
* Prefix array values for update function
148-
*
149-
* @param array $arr
150-
* @return array
151-
*/
36+
static $q, $c, $p, $i = '`';
37+
38+
/**
39+
* Fetch a column offset from the result set (COUNT() queries)
40+
*
41+
* @param string $query query string
42+
* @param array $params query parameters
43+
* @param integer $key index of column offset
44+
* @return array|null
45+
*/
46+
static function column($query, $params = null, $key = 0) {
47+
if ($statement = self::query($query, $params)) {
48+
return $statement->fetchColumn($key);
49+
}
50+
}
51+
52+
/**
53+
* Fetch a single query result row
54+
*
55+
* @param string $query query string
56+
* @param array $params query parameters
57+
* @return mixed
58+
*/
59+
static function row($query, $params = null) {
60+
if ($statement = self::query($query, $params)) {
61+
return $statement->fetch();
62+
}
63+
}
64+
65+
/**
66+
* Fetches an associative array of all rows as key-value pairs (first
67+
* column is the key, second column is the value).
68+
*
69+
* @param string $query query string
70+
* @param array $params query parameters
71+
* @return array
72+
*/
73+
static function pairs($query, $params = null) {
74+
$data = array();
75+
if ($statement = self::query($query, $params)) {
76+
while ($row = $statement->fetch(\PDO::FETCH_NUM)) {
77+
$data[$row[0]] = $row[1];
78+
}
79+
return $data;
80+
}
81+
}
82+
83+
/**
84+
* Fetch all query result rows
85+
*
86+
* @param string $query query string
87+
* @param array $params query parameters
88+
* @param int $column the optional column to return
89+
* @return array
90+
*/
91+
static function fetch($query, $params = null, $column = null) {
92+
if (!$statement = self::query($query, $params)) {
93+
return;
94+
}
95+
96+
// Return an array of records
97+
if ($column === null) {
98+
return $statement->fetchAll();
99+
}
100+
101+
// Fetch a certain column from all rows
102+
return $statement->fetchAll(\PDO::FETCH_COLUMN, $column);
103+
}
104+
105+
/**
106+
* Prepare and send a query returning the PDOStatement
107+
*
108+
* @param string $query query string
109+
* @param array $params query parameters
110+
* @return object|null
111+
*/
112+
static function query($query, $params = null) {
113+
$statement = static::$c->prepare(self::$q[] = strtr($query, '`', self::$i));
114+
$statement->execute($params);
115+
return $statement;
116+
}
117+
118+
/**
119+
* Insert a row into the database
120+
*
121+
* @param string $table name
122+
* @param array $data
123+
* @return integer|null
124+
*/
125+
static function insert($table, array $data) {
126+
$query = "INSERT INTO `$table` (`".implode('`, `', array_keys($data)).'`) VALUES ('.rtrim(str_repeat('?, ', count($data = array_values($data))), ', ').')';
127+
return self::$p ? self::column($query.' RETURNING `id`', $data) : (self::query($query, $data) ? static::$c->lastInsertId() : null);
128+
}
129+
130+
/**
131+
* Update a database row
132+
*
133+
* @param string $table name
134+
* @param array $data
135+
* @param array $w where conditions
136+
* @return integer|null
137+
*/
138+
static function update($table, $data, $value, $column = 'id') {
139+
$keys = implode('`=?,`', array_keys($data));
140+
if ($statement = self::query("UPDATE `$table` SET `$keys` = ? WHERE `$column` = ?", array_values($data + array($value)))) {
141+
return $statement->rowCount();
142+
}
143+
144+
}
145+
146+
/**
147+
* Prefix array values for update function
148+
*
149+
* @param array $arr
150+
* @return array
151+
*/
152152
static function array_keys_prefix($arr) {
153153
$rarr = array();
154154
foreach ($arr as $key => $val) {
@@ -157,32 +157,32 @@ static function array_keys_prefix($arr) {
157157
return $rarr;
158158
}
159159

160-
/**
161-
* Escape DB input
162-
*
163-
* @param string $value query value
164-
* @return string
165-
*/
166-
static function escape($value) {
167-
if (is_array($value)) {
168-
$newvalue = array_map_recursive($this->escape, $value);
169-
} else {
170-
$newvalue = str_replace(array(
171-
"\\",
172-
"\0",
173-
"\n",
174-
"\r",
175-
"\x1a",
176-
"'",
177-
'"'), array(
178-
"\\\\",
179-
"\\0",
180-
"\\n",
181-
"\\r",
182-
"\Z",
183-
"\'",
184-
'\"'), $value);
185-
}
186-
return $newvalue;
187-
}
160+
/**
161+
* Escape DB input
162+
*
163+
* @param string $value query value
164+
* @return string
165+
*/
166+
static function escape($value) {
167+
if (is_array($value)) {
168+
$newvalue = array_map_recursive($this->escape, $value);
169+
} else {
170+
$newvalue = str_replace(array(
171+
"\\",
172+
"\0",
173+
"\n",
174+
"\r",
175+
"\x1a",
176+
"'",
177+
'"'), array(
178+
"\\\\",
179+
"\\0",
180+
"\\n",
181+
"\\r",
182+
"\Z",
183+
"\'",
184+
'\"'), $value);
185+
}
186+
return $newvalue;
187+
}
188188
}

system/Logger.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,40 @@
1111

1212
class Logger {
1313

14-
/**
15-
* Write Log file
16-
*
17-
* @param string $file filename
18-
* @param string $type log type
19-
* @param string $content log message
20-
* @return null
21-
* @usage ;
22-
* $this->log->write('failed_logins','error','user failed to login');
23-
* $this->log->write('system.errors','warning','user is trying to select non existing language');
24-
*/
25-
function write($file, $type, $content) {
26-
$backtrace = debug_backtrace();
27-
$caller = array_shift($backtrace);
28-
$caller['file'] = after(ROOT_DIR, $caller['file']);
29-
$ipaddr = $_SERVER['REMOTE_ADDR'];
30-
$ref = $_SERVER['HTTP_REFERER'];
31-
$requri = $_SERVER['REQUEST_URI'];
32-
$reqdata = $requri.($ref ? " Ref: $ref" : '');
33-
$today = date("dMY");
34-
$filename = ROOT_DIR."/storage/logs/$today-$file.log";
35-
$now = date('H:m:s');
36-
$content = "($type) <$now> (IP: $ipaddr) | Req: $reqdata | Src: $caller[file] (Line: $caller[line]) \n $content \n--------------------\n";
37-
if (!$handle = fopen($filename, 'a')) {
38-
$errMsg = "Cannot open file ($filename)";
39-
}
40-
// Write $somecontent to our opened file.
41-
if (fwrite($handle, $content) === false) {
42-
$errMsg = "Cannot write to file ($filename)";
43-
$this->write('log', 'error', $errMsg);
44-
}
45-
fclose($handle);
46-
return $errMsg;
47-
}
14+
/**
15+
* Write Log file
16+
*
17+
* @param string $file filename
18+
* @param string $type log type
19+
* @param string $content log message
20+
* @return null
21+
* @usage ;
22+
* $this->log->write('failed_logins','error','user failed to login');
23+
* $this->log->write('system.errors','warning','user is trying to select non existing language');
24+
*/
25+
function write($file, $type, $content) {
26+
$backtrace = debug_backtrace();
27+
$caller = array_shift($backtrace);
28+
$caller['file'] = after(ROOT_DIR, $caller['file']);
29+
$ipaddr = $_SERVER['REMOTE_ADDR'];
30+
$ref = $_SERVER['HTTP_REFERER'];
31+
$requri = $_SERVER['REQUEST_URI'];
32+
$reqdata = $requri.($ref ? " Ref: $ref" : '');
33+
$today = date("dMY");
34+
$filename = ROOT_DIR."/storage/logs/$today-$file.log";
35+
$now = date('H:m:s');
36+
$content = "($type) <$now> (IP: $ipaddr) | Req: $reqdata | Src: $caller[file] (Line: $caller[line]) \n $content \n--------------------\n";
37+
if (!$handle = fopen($filename, 'a')) {
38+
$errMsg = "Cannot open file ($filename)";
39+
}
40+
// Write $somecontent to our opened file.
41+
if (fwrite($handle, $content) === false) {
42+
$errMsg = "Cannot write to file ($filename)";
43+
$this->write('log', 'error', $errMsg);
44+
}
45+
fclose($handle);
46+
return $errMsg;
47+
}
4848

4949
}
5050
?>

0 commit comments

Comments
 (0)