C_Ajax_Controller

Class C_Ajax_Controller.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/ajax/package.module.ajax.php  
  1. class C_Ajax_Controller extends C_MVC_Controller 
  2. static $_instances = array(); 
  3. function define($context = FALSE) 
  4. parent::define($context); 
  5. $this->implement('I_Ajax_Controller'); 
  6. function index_action() 
  7. $retval = NULL; 
  8. // Inform the MVC framework what type of content we're returning 
  9. $this->set_content_type('json'); 
  10. // Start an output buffer to avoid displaying any PHP warnings/errors 
  11. ob_start(); 
  12. // Get the action requested & find and execute the related method 
  13. if ($action = $this->param('action')) { 
  14. $method = "{$action}_action"; 
  15. if ($this->has_method($method)) { 
  16. $retval = $this->call_method($method); 
  17. } else { 
  18. $retval = array('error' => 'Not a valid AJAX action'); 
  19. } else { 
  20. $retval = array('error' => 'No action specified'); 
  21. // Flush the buffer 
  22. $buffer_limit = 0; 
  23. $zlib = ini_get('zlib.output_compression'); 
  24. if (!is_numeric($zlib) && $zlib == 'On') { 
  25. $buffer_limit = 1; 
  26. } else { 
  27. if (is_numeric($zlib) && $zlib > 0) { 
  28. $buffer_limit = 1; 
  29. while (ob_get_level() != $buffer_limit) { 
  30. ob_end_clean(); 
  31. // Return the JSON to the browser 
  32. echo json_encode($retval); 
  33. /** 
  34. * Returns an instance of this class 
  35. * @param string $context 
  36. * @return C_Ajax_Controller 
  37. */ 
  38. static function get_instance($context = FALSE) 
  39. if (!isset(self::$_instances[$context])) { 
  40. $klass = get_class(); 
  41. self::$_instances[$context] = new $klass($context); 
  42. return self::$_instances[$context]; 
  43. function validate_ajax_request($action = NULL, $check_token = false) 
  44. // TODO: remove this. Pro 2.1's proofing calls validate_ajax_request() with a null $action 
  45. if (!$action) { 
  46. return TRUE; 
  47. $valid_request = false; 
  48. $security = $this->get_registry()->get_utility('I_Security_Manager'); 
  49. $sec_actor = $security->get_current_actor(); 
  50. $sec_token = $security->get_request_token($action); 
  51. if ($sec_actor->is_allowed($action) && (!$check_token || $sec_token->check_current_request())) { 
  52. $valid_request = true; 
  53. return $valid_request;