1- <?php if ( ! defined ('BASEPATH ' )) exit ('No direct script access allowed ' );
1+ <?php defined ('BASEPATH ' ) OR exit ('No direct script access allowed ' );
22
33class REST_Controller extends Controller
44{
@@ -391,7 +391,7 @@ private function _log_request($authorized = FALSE)
391391 private function _check_limit ($ controller_method )
392392 {
393393 // They are special, or it might not even have a limit
394- if ( !empty ($ this ->rest ->ignore_limits ) OR ! isset ($ this ->methods [$ controller_method ]['limit ' ]))
394+ if ( ! empty ($ this ->rest ->ignore_limits ) OR ! isset ($ this ->methods [$ controller_method ]['limit ' ]))
395395 {
396396 // On your way sonny-jim.
397397 return TRUE ;
@@ -447,7 +447,7 @@ public function get($key = NULL, $xss_clean = TRUE)
447447 return $ this ->_get_args ;
448448 }
449449
450- return $ this ->_xss_clean ($ this ->_get_args [$ key ], $ xss_clean );
450+ return array_key_exists ( $ key , $ this -> _get_args ) ? $ this ->_xss_clean ($ this ->_get_args [$ key ], $ xss_clean ) : FALSE ;
451451 }
452452
453453 public function post ($ key = NULL , $ xss_clean = TRUE )
@@ -467,7 +467,7 @@ public function put($key = NULL, $xss_clean = TRUE)
467467 return $ this ->_put_args ;
468468 }
469469
470- return array_key_exists ($ key , $ this ->_put_args ) ? $ this ->_xss_clean ( $ this ->_put_args [$ key ], $ xss_clean ) : FALSE ;
470+ return array_key_exists ($ key , $ this ->_put_args ) ? $ this ->_xss_clean ( $ this ->_put_args [$ key ], $ xss_clean ) : FALSE ;
471471 }
472472
473473 public function delete ($ key = NULL , $ xss_clean = TRUE )
@@ -517,12 +517,9 @@ private function _check_login($username = '', $password = NULL)
517517 }
518518
519519 // If actually NULL (not empty string) then do not check it
520- if ($ password !== NULL )
520+ if ($ password !== NULL AND $ valid_logins [ $ username ] != $ password )
521521 {
522- if ($ valid_logins [$ username ] != $ password )
523- {
524- return FALSE ;
525- }
522+ return FALSE ;
526523 }
527524
528525 return TRUE ;
@@ -541,15 +538,15 @@ private function _prepare_basic_auth()
541538 }
542539
543540 // most other servers
544- elseif ( $ this ->input ->server ('HTTP_AUTHENTICATION ' ) )
541+ elseif ($ this ->input ->server ('HTTP_AUTHENTICATION ' ))
545542 {
546543 if (strpos (strtolower ($ this ->input ->server ('HTTP_AUTHENTICATION ' )),'basic ' ) === 0 )
547544 {
548545 list ($ username ,$ password ) = explode (': ' ,base64_decode (substr ($ this ->input ->server ('HTTP_AUTHORIZATION ' ), 6 )));
549546 }
550547 }
551548
552- if ( !$ this ->_check_login ($ username , $ password ) )
549+ if ( ! $ this ->_check_login ($ username , $ password ) )
553550 {
554551 $ this ->_force_login ();
555552 }
@@ -589,7 +586,7 @@ private function _prepare_digest_auth()
589586 preg_match_all ('@(username|nonce|uri|nc|cnonce|qop|response)=[ \'"]?([^ \'",]+)@ ' , $ digest_string , $ matches );
590587 $ digest = array_combine ($ matches [1 ], $ matches [2 ]);
591588
592- if ( !array_key_exists ('username ' , $ digest ) || !$ this ->_check_login ($ digest ['username ' ]) )
589+ if ( ! array_key_exists ('username ' , $ digest ) OR !$ this ->_check_login ($ digest ['username ' ]) )
593590 {
594591 $ this ->_force_login ($ uniqid );
595592 }
@@ -627,15 +624,14 @@ private function _force_login($nonce = '')
627624 header ('WWW-Authenticate: Digest realm=" ' .$ this ->config ->item ('rest_realm ' ). '" qop="auth" nonce=" ' .$ nonce .'" opaque=" ' .md5 ($ this ->config ->item ('rest_realm ' )).'" ' );
628625 }
629626
630- echo 'Not authorized. ' ;
631- die ();
627+ exit ('Not authorized. ' );
632628 }
633629
634630 // Force it into an array
635631 private function _force_loopable ($ data )
636632 {
637633 // Force it to be something useful
638- if ( ! is_array ($ data ) AND !is_object ($ data ))
634+ if ( ! is_array ($ data ) AND ! is_object ($ data ))
639635 {
640636 $ data = (array ) $ data ;
641637 }
@@ -650,7 +646,7 @@ private function _format_xml($data = array(), $structure = NULL, $basenode = 'xm
650646 // turn off compatibility mode as simple xml throws a wobbly if you don't.
651647 if (ini_get ('zend.ze1_compatibility_mode ' ) == 1 )
652648 {
653- ini_set ('zend.ze1_compatibility_mode ' , 0 );
649+ ini_set ('zend.ze1_compatibility_mode ' , 0 );
654650 }
655651
656652 if ($ structure == NULL )
@@ -674,7 +670,7 @@ private function _format_xml($data = array(), $structure = NULL, $basenode = 'xm
674670 $ key = preg_replace ('/[^a-z_]/i ' , '' , $ key );
675671
676672 // if there is another array found recrusively call this function
677- if (is_array ($ value ) || is_object ($ value ))
673+ if (is_array ($ value ) OR is_object ($ value ))
678674 {
679675 $ node = $ structure ->addChild ($ key );
680676 // recrusive call.
@@ -704,7 +700,7 @@ private function _format_rawxml($data = array(), $structure = NULL, $basenode =
704700 // turn off compatibility mode as simple xml throws a wobbly if you don't.
705701 if (ini_get ('zend.ze1_compatibility_mode ' ) == 1 )
706702 {
707- ini_set ('zend.ze1_compatibility_mode ' , 0 );
703+ ini_set ('zend.ze1_compatibility_mode ' , 0 );
708704 }
709705
710706 if ($ structure == NULL )
@@ -728,7 +724,7 @@ private function _format_rawxml($data = array(), $structure = NULL, $basenode =
728724 $ key = preg_replace ('/[^a-z0-9_-]/i ' , '' , $ key );
729725
730726 // if there is another array found recrusively call this function
731- if (is_array ($ value ) || is_object ($ value ))
727+ if (is_array ($ value ) OR is_object ($ value ))
732728 {
733729 $ node = $ structure ->addChild ($ key );
734730 // recrusive call.
0 commit comments