@@ -22,6 +22,7 @@ class REST_Controller extends Controller
2222 'xml ' => 'application/xml ' ,
2323 'rawxml ' => 'application/xml ' ,
2424 'json ' => 'application/json ' ,
25+ 'jsonp ' => 'application/json ' ,
2526 'serialize ' => 'application/vnd.php.serialized ' ,
2627 'php ' => 'text/plain ' ,
2728 'html ' => 'text/html ' ,
@@ -95,17 +96,17 @@ function __construct()
9596 // Which format should the data be returned in?
9697 $ this ->request ->lang = $ this ->_detect_lang ();
9798
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+ }
109110 }
110111
111112 /*
@@ -319,7 +320,7 @@ private function _detect_api_key()
319320 // Find the key from server or arguments
320321 if ($ key = isset ($ this ->_args ['API-Key ' ]) ? $ this ->_args ['API-Key ' ] : $ this ->input ->server ($ key_name ))
321322 {
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 ())
323324 {
324325 return FALSE ;
325326 }
@@ -377,7 +378,7 @@ private function _detect_lang()
377378 */
378379 private function _log_request ($ authorized = FALSE )
379380 {
380- return $ this ->rest ->db ->insert (' logs ' , array (
381+ return $ this ->rest ->db ->insert (config_item ( ' rest_logs_table ' ) , array (
381382 'uri ' => $ this ->uri ->uri_string (),
382383 'method ' => $ this ->request ->method ,
383384 'params ' => serialize ($ this ->_args ),
@@ -410,7 +411,7 @@ private function _check_limit($controller_method)
410411 $ result = $ this ->rest ->db
411412 ->where ('uri ' , $ this ->uri ->uri_string ())
412413 ->where ('api_key ' , $ this ->rest ->key )
413- ->get (' limits ' )
414+ ->get (config_item ( ' rest_limits_table ' ) )
414415 ->row ();
415416
416417 // No calls yet, or been an hour since they called
@@ -438,7 +439,7 @@ private function _check_limit($controller_method)
438439 ->where ('uri ' , $ this ->uri ->uri_string ())
439440 ->where ('api_key ' , $ this ->rest ->key )
440441 ->set ('count ' , 'count + 1 ' , FALSE )
441- ->update ('limits ' );
442+ ->update (config_item ( 'limits ' ) );
442443 }
443444
444445 return TRUE ;
@@ -816,6 +817,12 @@ private function _format_json($data = array())
816817 {
817818 return json_encode ($ data );
818819 }
820+
821+ // Encode as JSONP
822+ private function _format_jsonp ($ data = array ())
823+ {
824+ return $ this ->get ('callback ' ).'( ' .json_encode ($ data ).') ' ;
825+ }
819826
820827 // Encode as Serialized array
821828 private function _format_serialize ($ data = array ())
0 commit comments