Mixin_NextGen_Admin_Page_Instance_Methods

The NextGEN Gallery Mixin NextGen Admin Page Instance Methods 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 Mixin_NextGen_Admin_Page_Instance_Methods extends Mixin 
  2. /** 
  3. * Authorizes the request 
  4. */ 
  5. function is_authorized_request($privilege = NULL) 
  6. if (!$privilege) { 
  7. $privilege = $this->object->get_required_permission(); 
  8. $security = $this->get_registry()->get_utility('I_Security_Manager'); 
  9. $retval = $sec_token = $security->get_request_token(str_replace(array(' ', "\n", "\t"), '_', $privilege)); 
  10. $sec_actor = $security->get_current_actor(); 
  11. // Ensure that the user has permission to access this page 
  12. if (!$sec_actor->is_allowed($privilege)) { 
  13. $retval = FALSE; 
  14. // Ensure that nonce is valid 
  15. if ($this->object->is_post_request() && !$sec_token->check_current_request()) { 
  16. $retval = FALSE; 
  17. return $retval; 
  18. /** 
  19. * Returns the permission required to access this page 
  20. * @return string 
  21. */ 
  22. function get_required_permission() 
  23. return $this->object->name; 
  24. /** 
  25. * Enqueues resources required by a NextGEN Admin page 
  26. */ 
  27. function enqueue_backend_resources() 
  28. wp_enqueue_script('jquery'); 
  29. $this->object->enqueue_jquery_ui_theme(); 
  30. wp_enqueue_script('photocrati_ajax'); 
  31. wp_enqueue_script('jquery-ui-accordion'); 
  32. wp_enqueue_script('nextgen_display_settings_page_placeholder_stub', $this->get_static_url('photocrati-nextgen_admin#jquery.placeholder.min.js'), array('jquery'), NGG_SCRIPT_VERSION, TRUE); 
  33. wp_register_script('iris', $this->get_router()->get_url('/wp-admin/js/iris.min.js', FALSE, TRUE), array('jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch'), NGG_SCRIPT_VERSION); 
  34. wp_register_script('wp-color-picker', $this->get_router()->get_url('/wp-admin/js/color-picker.js', FALSE, TRUE), array('iris'), NGG_SCRIPT_VERSION); 
  35. wp_localize_script('wp-color-picker', 'wpColorPickerL10n', array('clear' => __('Clear', 'nggallery'), 'defaultString' => __('Default', 'nggallery'), 'pick' => __('Select Color', 'nggallery'), 'current' => __('Current Color', 'nggallery'))); 
  36. wp_enqueue_script('nextgen_admin_page', $this->get_static_url('photocrati-nextgen_admin#nextgen_admin_page.js'), array('wp-color-picker'), NGG_SCRIPT_VERSION); 
  37. wp_enqueue_style('nextgen_admin_page', $this->get_static_url('photocrati-nextgen_admin#nextgen_admin_page.css'), array('wp-color-picker'), NGG_SCRIPT_VERSION); 
  38. // Ensure select2 
  39. wp_enqueue_style('ngg_select2'); 
  40. wp_enqueue_script('ngg_select2'); 
  41. function enqueue_jquery_ui_theme() 
  42. $settings = C_NextGen_Settings::get_instance(); 
  43. wp_enqueue_style($settings->jquery_ui_theme, is_ssl() ? str_replace('http:', 'https:', $settings->jquery_ui_theme_url) : $settings->jquery_ui_theme_url, FALSE, $settings->jquery_ui_theme_version); 
  44. /** 
  45. * Returns the page title 
  46. * @return string 
  47. */ 
  48. function get_page_title() 
  49. return $this->object->name; 
  50. /** 
  51. * Returns the page heading 
  52. * @return string 
  53. */ 
  54. function get_page_heading() 
  55. return $this->object->get_page_title(); 
  56. /** 
  57. * Returns the type of forms to render on this page 
  58. * @return string 
  59. */ 
  60. function get_form_type() 
  61. return is_array($this->object->context) ? $this->object->context[0] : $this->object->context; 
  62. function get_success_message() 
  63. return __("Saved successfully", 'nggallery'); 
  64. /** 
  65. * Returns an accordion tab, encapsulating the form 
  66. * @param I_Form $form 
  67. */ 
  68. function to_accordion_tab($form) 
  69. return $this->object->render_partial('photocrati-nextgen_admin#accordion_tab', array('id' => $form->get_id(), 'title' => $form->get_title(), 'content' => $form->render(TRUE)), TRUE); 
  70. /** 
  71. * Returns the 
  72. * @return type 
  73. */ 
  74. function get_forms() 
  75. $forms = array(); 
  76. $form_manager = C_Form_Manager::get_instance(); 
  77. foreach ($form_manager->get_forms($this->object->get_form_type()) as $form) { 
  78. $forms[] = $this->get_registry()->get_utility('I_Form', $form); 
  79. return $forms; 
  80. /** 
  81. * Gets the action to be executed 
  82. * @return string 
  83. */ 
  84. function _get_action() 
  85. $retval = preg_quote($this->object->param('action'), '/'); 
  86. $retval = strtolower(preg_replace("/[^\\w]/", '_', $retval)); 
  87. return preg_replace("/_{2, }/", "_", $retval) . '_action'; 
  88. /** 
  89. * Returns the template to be rendered for the index action 
  90. * @return string 
  91. */ 
  92. function index_template() 
  93. return 'photocrati-nextgen_admin#nextgen_admin_page'; 
  94. /** 
  95. * Returns a list of parameters to include when rendering the view 
  96. * @return array 
  97. */ 
  98. function get_index_params() 
  99. return array(); 
  100. function show_save_button() 
  101. return TRUE; 
  102. /** 
  103. * Renders a NextGEN Admin Page using jQuery Accordions 
  104. */ 
  105. function index_action() 
  106. $this->object->enqueue_backend_resources(); 
  107. if ($token = $this->object->is_authorized_request()) { 
  108. // Get each form. Validate it and save any changes if this is a post 
  109. // request 
  110. $tabs = array(); 
  111. $errors = array(); 
  112. $action = $this->object->_get_action(); 
  113. $success = $this->param('message'); 
  114. if ($success) { 
  115. $success = $this->object->get_success_message(); 
  116. } else { 
  117. $success = $this->object->is_post_request() ? $this->object->get_success_message() : ''; 
  118. // First, process the Post request 
  119. if ($this->object->is_post_request() && $this->has_method($action)) { 
  120. $this->object->{$action}($this->object->param($this->context)); 
  121. foreach ($this->object->get_forms() as $form) { 
  122. $form->page = $this->object; 
  123. $form->enqueue_static_resources(); 
  124. if ($this->object->is_post_request()) { 
  125. if ($form->has_method($action)) { 
  126. $form->{$action}($this->object->param($form->context)); 
  127. $tabs[] = $this->object->to_accordion_tab($form); 
  128. if ($form->has_method('get_model') && $form->get_model()) { 
  129. if ($form->get_model()->is_invalid()) { 
  130. if ($form_errors = $this->object->show_errors_for($form->get_model(), TRUE)) { 
  131. $errors[] = $form_errors; 
  132. $form->get_model()->clear_errors(); 
  133. // Render the view 
  134. $index_params = array('page_heading' => $this->object->get_page_heading(), 'tabs' => $tabs, 'errors' => $errors, 'success' => $success, 'form_header' => $token->get_form_html(), 'show_save_button' => $this->object->show_save_button(), 'model' => $this->object->has_method('get_model') ? $this->get_model() : NULL); 
  135. $index_params = array_merge($index_params, $this->object->get_index_params()); 
  136. $this->render_partial($this->object->index_template(), $index_params); 
  137. } else { 
  138. $this->render_view('photocrati-nextgen_admin#not_authorized', array('name' => $this->object->name, 'title' => $this->object->get_page_title()));