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. /** 
  6. * @var C_Admin_Notification_Manager 
  7. */ 
  8. static $_instance = NULL; 
  9. static function get_instance() 
  10. if (!isset(self::$_instance)) { 
  11. $klass = get_class(); 
  12. self::$_instance = new $klass(); 
  13. return self::$_instance; 
  14. function __construct() 
  15. $this->_dismiss_url = site_url('/?ngg_dismiss_notice=1'); 
  16. function has_displayed_notice() 
  17. return $this->_displayed_notice; 
  18. function add($name, $handler) 
  19. $this->_notifications[$name] = $handler; 
  20. function remove($name) 
  21. unset($this->_notifications[$name]); 
  22. function render() 
  23. $output = array(); 
  24. foreach (array_keys($this->_notifications) as $notice) { 
  25. if ($html = $this->render_notice($notice)) { 
  26. $output[] = $html; 
  27. echo implode("\n", $output); 
  28. function is_dismissed($name) 
  29. $retval = FALSE; 
  30. $settings = C_NextGen_Settings::get_instance(); 
  31. $dismissed = $settings->get('dismissed_notifications', array()); 
  32. if (isset($dismissed[$name])) { 
  33. if ($id = get_current_user_id()) { 
  34. if (in_array($id, $dismissed[$name])) { 
  35. $retval = TRUE; 
  36. } else { 
  37. if (in_array('unknown', $dismissed[$name])) { 
  38. $retval = TRUE; 
  39. return $retval; 
  40. function dismiss($name, $dismiss_code = 1) 
  41. $response = array(); 
  42. if ($handler = $this->get_handler_instance($name)) { 
  43. $has_method = method_exists($handler, 'is_dismissable'); 
  44. if ($has_method && $handler->is_dismissable() || !$has_method) { 
  45. if (method_exists($handler, 'dismiss')) { 
  46. $response = $handler->dismiss($dismiss_code); 
  47. $response['handled'] = TRUE; 
  48. if (is_bool($response)) { 
  49. $response = array('dismiss' => $response); 
  50. // Set default key/values 
  51. if (!isset($response['handled'])) { 
  52. $response['handled'] = FALSE; 
  53. if (!isset($response['dismiss'])) { 
  54. $response['dismiss'] = TRUE; 
  55. if (!isset($response['persist'])) { 
  56. $response['persist'] = $response['dismiss']; 
  57. if (!isset($response['success'])) { 
  58. $response['success'] = $response['dismiss']; 
  59. if (!isset($response['code'])) { 
  60. $response['code'] = $dismiss_code; 
  61. if ($response['dismiss']) { 
  62. $settings = C_NextGen_Settings::get_instance(); 
  63. $dismissed = $settings->get('dismissed_notifications', array()); 
  64. if (!isset($dismissed[$name])) { 
  65. $dismissed[$name] = array(); 
  66. $user_id = get_current_user_id(); 
  67. $dismissed[$name][] = $user_id ? $user_id : 'unknown'; 
  68. $settings->set('dismissed_notifications', $dismissed); 
  69. if ($response['persist']) { 
  70. $settings->save(); 
  71. } else { 
  72. $response['error'] = __("Notice is not dismissible", 'nggallery'); 
  73. } else { 
  74. $response['error'] = __("No handler defined for this notice", 'nggallery'); 
  75. return $response; 
  76. function get_handler_instance($name) 
  77. $retval = NULL; 
  78. if (isset($this->_notifications[$name])) { 
  79. $handler = $this->_notifications[$name]; 
  80. if (is_object($handler)) { 
  81. $retval = $handler; 
  82. } elseif (is_array($handler)) { 
  83. $retval = new C_Admin_Notification_Wrapper($name, $handler); 
  84. } elseif (class_exists($handler)) { 
  85. $retval = call_user_func(array($handler, 'get_instance'), $name); 
  86. return $retval; 
  87. function enqueue_scripts() 
  88. if ($this->has_displayed_notice()) { 
  89. $router = C_Router::get_instance(); 
  90. wp_enqueue_script('ngg_admin_notices', $router->get_static_url('photocrati-nextgen_admin#admin_notices.js'), FALSE, NGG_SCRIPT_VERSION, TRUE); 
  91. wp_localize_script('ngg_admin_notices', 'ngg_dismiss_url', $this->_dismiss_url); 
  92. function serve_ajax_request() 
  93. $retval = array('failure' => TRUE); 
  94. if (isset($_REQUEST['ngg_dismiss_notice'])) { 
  95. if (!headers_sent()) { 
  96. header('Content-Type: application/json'); 
  97. ob_start(); 
  98. if (!isset($_REQUEST['code'])) { 
  99. $_REQUEST['code'] = 1; 
  100. if (isset($_REQUEST['name'])) { 
  101. $retval = $this->dismiss($_REQUEST['name'], intval($_REQUEST['code'])); 
  102. } else { 
  103. $retval['msg'] = __('Not a valid notice name', 'nggallery'); 
  104. ob_end_clean(); 
  105. echo json_encode($retval); 
  106. throw new E_Clean_Exit(); 
  107. function render_notice($name) 
  108. $retval = ''; 
  109. if (($handler = $this->get_handler_instance($name)) && !$this->is_dismissed($name)) { 
  110. // Does the handler want to render? 
  111. $has_method = method_exists($handler, 'is_renderable'); 
  112. if ($has_method && $handler->is_renderable() || !$has_method) { 
  113. $show_dismiss_button = method_exists($handler, 'show_dismiss_button') ? $handler->show_dismiss_button() : method_exists($handler, 'is_dismissable') ? $handler->is_dismissable() : FALSE; 
  114. $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() : '', 'show_dismiss_button' => $show_dismiss_button, 'notice_name' => $name)); 
  115. $retval = $view->render(TRUE); 
  116. $this->_displayed_notice = TRUE; 
  117. return $retval;