C_Admin_Notification_Manager

The NextGEN Gallery C Admin Notification Manager class.

Defined (1)

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

/products/photocrati_nextgen/modules/nextgen_admin/package.module.nextgen_admin.php  
  1. class C_Admin_Notification_Manager 
  2. public $_notifications = array(); 
  3. public $_displayed_notice = FALSE; 
  4. public $_dismiss_url = NULL; 
  5. static $_instance = NULL; 
  6. static function get_instance() 
  7. if (!isset(self::$_instance)) { 
  8. $klass = get_class(); 
  9. self::$_instance = new $klass(); 
  10. return self::$_instance; 
  11. public function __construct() 
  12. $this->_dismiss_url = site_url('/?ngg_dismiss_notice=1'); 
  13. public function has_displayed_notice() 
  14. return $this->_displayed_notice; 
  15. public function add($name, $handler) 
  16. $this->_notifications[$name] = $handler; 
  17. public function remove($name) 
  18. unset($this->_notifications[$name]); 
  19. public function render() 
  20. $output = array(); 
  21. foreach (array_keys($this->_notifications) as $notice) { 
  22. if ($html = $this->render_notice($notice)) { 
  23. $output[] = $html; 
  24. echo implode(' 
  25. ', $output); 
  26. public function is_dismissed($name) 
  27. $retval = FALSE; 
  28. $settings = C_NextGen_Settings::get_instance(); 
  29. $dismissed = $settings->get('dismissed_notifications', array()); 
  30. if (isset($dismissed[$name])) { 
  31. if ($id = get_current_user_id()) { 
  32. if (in_array($id, $dismissed[$name])) { 
  33. $retval = TRUE; 
  34. } else { 
  35. if (in_array('unknown', $dismissed[$name])) { 
  36. $retval = TRUE; 
  37. return $retval; 
  38. public function dismiss($name) 
  39. $retval = FALSE; 
  40. if ($handler = $this->get_handler_instance($name)) { 
  41. $has_method = method_exists($handler, 'is_dismissable'); 
  42. if ($has_method && $handler->is_dismissable() || !$has_method) { 
  43. $settings = C_NextGen_Settings::get_instance(); 
  44. $dismissed = $settings->get('dismissed_notifications', array()); 
  45. if (!isset($dismissed[$name])) { 
  46. $dismissed[$name] = array(); 
  47. $user_id = get_current_user_id(); 
  48. $dismissed[$name][] = $user_id ? $user_id : 'unknown'; 
  49. $settings->set('dismissed_notifications', $dismissed); 
  50. $settings->save(); 
  51. $retval = TRUE; 
  52. return $retval; 
  53. public function get_handler_instance($name) 
  54. $retval = NULL; 
  55. if (isset($this->_notifications[$name])) { 
  56. $handler = $this->_notifications[$name]; 
  57. if (is_object($handler)) { 
  58. $retval = $handler; 
  59. } elseif (is_array($handler)) { 
  60. $retval = new C_Admin_Notification_Wrapper($name, $handler); 
  61. } elseif (class_exists($handler)) { 
  62. $retval = call_user_func(array($handler, 'get_instance'), $name); 
  63. return $retval; 
  64. public function enqueue_scripts() 
  65. if ($this->has_displayed_notice()) { 
  66. $router = C_Router::get_instance(); 
  67. wp_enqueue_script('ngg_admin_notices', $router->get_static_url('photocrati-nextgen_admin#admin_notices.js'), FALSE, NGG_SCRIPT_VERSION, TRUE); 
  68. wp_localize_script('ngg_admin_notices', 'ngg_dismiss_url', $this->_dismiss_url); 
  69. public function serve_ajax_request() 
  70. $retval = array('failure' => TRUE); 
  71. if (isset($_REQUEST['ngg_dismiss_notice'])) { 
  72. header('Content-Type: application/json'); 
  73. // ob_start(); 
  74. if (isset($_REQUEST['name']) && $this->dismiss($_REQUEST['name'])) { 
  75. $retval = array('success' => TRUE); 
  76. } else { 
  77. $retval['msg'] = __('Not a valid notice name', 'nggallery'); 
  78. // ob_end_clean(); 
  79. echo json_encode($retval); 
  80. throw new E_Clean_Exit(); 
  81. public function render_notice($name) 
  82. $retval = ''; 
  83. if (($handler = $this->get_handler_instance($name)) && !$this->is_dismissed($name)) { 
  84. // Does the handler want to render? 
  85. $has_method = method_exists($handler, 'is_renderable'); 
  86. if ($has_method && $handler->is_renderable() || !$has_method) { 
  87. $view = new C_MVC_View('photocrati-nextgen_admin#admin_notice', array('css_class' => method_exists($handler, 'get_css_class') ? $handler->get_css_class() : 'updated', 'is_dismissable' => method_exists($handler, 'is_dismissable') ? $handler->is_dismissable() : FALSE, 'html' => method_exists($handler, 'render') ? $handler->render() : '', 'notice_name' => $name)); 
  88. $retval = $view->render(TRUE); 
  89. $this->_displayed_notice = TRUE; 
  90. return $retval;