@@ -22,6 +22,7 @@ class REST_Controller extends Controller
22
22
'xml ' => 'application/xml ' ,
23
23
'rawxml ' => 'application/xml ' ,
24
24
'json ' => 'application/json ' ,
25
+ 'jsonp ' => 'application/json ' ,
25
26
'serialize ' => 'application/vnd.php.serialized ' ,
26
27
'php ' => 'text/plain ' ,
27
28
'html ' => 'text/html ' ,
@@ -95,17 +96,17 @@ function __construct()
95
96
// Which format should the data be returned in?
96
97
$ this ->request ->lang = $ this ->_detect_lang ();
97
98
98
- // Load DB if its enabled
99
- if (config_item ('rest_database_group ' ) AND (config_item ('rest_enable_keys ' ) OR config_item ('rest_enable_logging ' )))
100
- {
101
- $ this ->rest ->db = $ this ->load ->database (config_item ('rest_database_group ' ), TRUE );
102
- }
103
-
104
- // Checking for keys? GET TO WORK!
105
- if (config_item ('rest_enable_keys ' ))
106
- {
107
- $ this ->_allow = $ this ->_detect_api_key ();
108
- }
99
+ // Load DB if its enabled
100
+ if (config_item ('rest_database_group ' ) AND (config_item ('rest_enable_keys ' ) OR config_item ('rest_enable_logging ' )))
101
+ {
102
+ $ this ->rest ->db = $ this ->load ->database (config_item ('rest_database_group ' ), TRUE );
103
+ }
104
+
105
+ // Checking for keys? GET TO WORK!
106
+ if (config_item ('rest_enable_keys ' ))
107
+ {
108
+ $ this ->_allow = $ this ->_detect_api_key ();
109
+ }
109
110
}
110
111
111
112
/*
@@ -319,7 +320,7 @@ private function _detect_api_key()
319
320
// Find the key from server or arguments
320
321
if ($ key = isset ($ this ->_args ['API-Key ' ]) ? $ this ->_args ['API-Key ' ] : $ this ->input ->server ($ key_name ))
321
322
{
322
- if ( ! $ row = $ this ->rest ->db ->where ('key ' , $ key )->get (' keys ' )->row ())
323
+ if ( ! $ row = $ this ->rest ->db ->where ('key ' , $ key )->get (config_item ( ' rest_keys_table ' ) )->row ())
323
324
{
324
325
return FALSE ;
325
326
}
@@ -377,7 +378,7 @@ private function _detect_lang()
377
378
*/
378
379
private function _log_request ($ authorized = FALSE )
379
380
{
380
- return $ this ->rest ->db ->insert (' logs ' , array (
381
+ return $ this ->rest ->db ->insert (config_item ( ' rest_logs_table ' ) , array (
381
382
'uri ' => $ this ->uri ->uri_string (),
382
383
'method ' => $ this ->request ->method ,
383
384
'params ' => serialize ($ this ->_args ),
@@ -410,7 +411,7 @@ private function _check_limit($controller_method)
410
411
$ result = $ this ->rest ->db
411
412
->where ('uri ' , $ this ->uri ->uri_string ())
412
413
->where ('api_key ' , $ this ->rest ->key )
413
- ->get (' limits ' )
414
+ ->get (config_item ( ' rest_limits_table ' ) )
414
415
->row ();
415
416
416
417
// No calls yet, or been an hour since they called
@@ -438,7 +439,7 @@ private function _check_limit($controller_method)
438
439
->where ('uri ' , $ this ->uri ->uri_string ())
439
440
->where ('api_key ' , $ this ->rest ->key )
440
441
->set ('count ' , 'count + 1 ' , FALSE )
441
- ->update ('limits ' );
442
+ ->update (config_item ( 'limits ' ) );
442
443
}
443
444
444
445
return TRUE ;
@@ -816,6 +817,12 @@ private function _format_json($data = array())
816
817
{
817
818
return json_encode ($ data );
818
819
}
820
+
821
+ // Encode as JSONP
822
+ private function _format_jsonp ($ data = array ())
823
+ {
824
+ return $ this ->get ('callback ' ).'( ' .json_encode ($ data ).') ' ;
825
+ }
819
826
820
827
// Encode as Serialized array
821
828
private function _format_serialize ($ data = array ())
0 commit comments