Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Commit 1cde12f

Browse files
committed
Merged in updates from the philsturgeon/codeigniter-restserver
repository.
1 parent 30529f6 commit 1cde12f

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

application/controllers/api/key.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ private function _generate_key()
235235

236236
private function _get_key($key)
237237
{
238-
return $this->db->where('key', $key)->get(config_item('rest_keys_table'))->row();
238+
return $this->db->where(config_item('rest_key_column'), $key)->get(config_item('rest_keys_table'))->row();
239239
}
240240

241241
// --------------------------------------------------------------------
242242

243243
private function _key_exists($key)
244244
{
245-
return $this->db->where('key', $key)->count_all_results(config_item('rest_keys_table')) > 0;
245+
return $this->db->where(config_item('rest_key_column'), $key)->count_all_results(config_item('rest_keys_table')) > 0;
246246
}
247247

248248
// --------------------------------------------------------------------
@@ -260,13 +260,13 @@ private function _insert_key($key, $data)
260260

261261
private function _update_key($key, $data)
262262
{
263-
return $this->db->where('key', $key)->update(config_item('rest_keys_table'), $data);
263+
return $this->db->where(config_item('rest_key_column'), $key)->update(config_item('rest_keys_table'), $data);
264264
}
265265

266266
// --------------------------------------------------------------------
267267

268268
private function _delete_key($key)
269269
{
270-
return $this->db->where('key', $key)->delete(config_item('rest_keys_table'));
270+
return $this->db->where(config_item('rest_key_column'), $key)->delete(config_item('rest_keys_table'));
271271
}
272272
}

application/libraries/Format.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ public function to_csv()
197197
$data = array($data);
198198
}
199199

200-
$output = implode(',', $headings).PHP_EOL;
200+
$output = '"'.implode('","', $headings).'"'.PHP_EOL;
201201
foreach ($data as &$row)
202202
{
203+
$row = str_replace('"', '""', $row); // Escape dbl quotes per RFC 4180
203204
$output .= '"'.implode('","', $row).'"'.PHP_EOL;
204205
}
205206

@@ -209,7 +210,7 @@ public function to_csv()
209210
// Encode as JSON
210211
public function to_json()
211212
{
212-
return json_encode($this->_data);
213+
return json_encode($this->_data);
213214
}
214215

215216
// Encode as Serialized array

application/libraries/REST_Controller.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ protected function early_checks()
146146
public function __construct()
147147
{
148148
parent::__construct();
149+
150+
// init objects
151+
$this->request = new stdClass();
152+
$this->response = new stdClass();
153+
$this->rest = new stdClass();
149154

150155
$this->_zlib_oc = @ini_get('zlib.output_compression');
151156

@@ -170,8 +175,6 @@ public function __construct()
170175
// Set up our GET variables
171176
$this->_get_args = array_merge($this->_get_args, $this->uri->ruri_to_assoc(2));
172177

173-
$this->load->library('security');
174-
175178
// This library is bundled with REST_Controller 2.5+, but will eventually be part of CodeIgniter itself
176179
$this->load->library('format');
177180

@@ -197,7 +200,7 @@ public function __construct()
197200
// Which format should the data be returned in?
198201
$this->response = new stdClass();
199202
$this->response->format = $this->_detect_output_format();
200-
203+
201204
// Which format should the data be returned in?
202205
$this->response->lang = $this->_detect_lang();
203206

@@ -232,7 +235,7 @@ public function __construct()
232235
}
233236

234237
// Use whatever database is in use (isset returns false)
235-
elseif (@$this->db)
238+
elseif (property_exists($this, "db"))
236239
{
237240
$this->rest->db = $this->db;
238241
}
@@ -1089,7 +1092,7 @@ protected function _check_login($username = '', $password = NULL)
10891092
return $this->_perform_ldap_auth($username, $password);
10901093
}
10911094

1092-
$valid_logins = & $this->config->item('rest_valid_logins');
1095+
$valid_logins = $this->config->item('rest_valid_logins');
10931096

10941097
if ( ! array_key_exists($username, $valid_logins))
10951098
{
@@ -1184,7 +1187,7 @@ protected function _prepare_digest_auth()
11841187
$this->_force_login($uniqid);
11851188
}
11861189

1187-
$valid_logins = & $this->config->item('rest_valid_logins');
1190+
$valid_logins = $this->config->item('rest_valid_logins');
11881191
$valid_pass = $valid_logins[$digest['username']];
11891192

11901193
// This is the valid response expected

0 commit comments

Comments
 (0)