MS_View

Abstract class for all Views.

Defined (1)

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

/app/class-ms-view.php  
  1. class MS_View extends MS_Hooker { 
  2.  
  3. /** 
  4. * The storage of all data associated with this render. 
  5. * @since 1.0.0 
  6. * @var array 
  7. */ 
  8. protected $data; 
  9.  
  10. /** 
  11. * Flag is set to true while in Simulation mode. 
  12. * @since 1.0.0 
  13. * @var bool 
  14. */ 
  15. static protected $is_simulating = false; 
  16.  
  17. /** 
  18. * Constructor. 
  19. * @since 1.0.0 
  20. * @param array $data The data what has to be associated with this render. 
  21. */ 
  22. public function __construct( $data = array() ) { 
  23. static $Simulate = null; 
  24.  
  25. $this->data = $data; 
  26.  
  27. /** 
  28. * Actions to execute when constructing the parent View. 
  29. * @since 1.0.0 
  30. * @param object $this The MS_View object. 
  31. */ 
  32. do_action( 'ms_view_construct', $this ); 
  33.  
  34. if ( null === $Simulate && MS_Model_Simulate::can_simulate() ) { 
  35. $Simulate = MS_Factory::load( 'MS_Model_Simulate' ); 
  36. self::$is_simulating = $Simulate->is_simulating(); 
  37.  
  38. /** 
  39. * Displays a note while simulation mode is enabled. 
  40. * @since 1.0.0 
  41. */ 
  42. protected function check_simulation() { 
  43. if ( self::$is_simulating ) : 
  44. ?> 
  45. <div class="error below-h2"> 
  46. <p> 
  47. <strong><?php _e( 'You are in Simulation mode!', 'membership2' ); ?></strong> 
  48. </p> 
  49. <p> 
  50. <?php _e( 'Content displayed here might be altered because of simulated restrictions.', 'membership2' ); ?><br /> 
  51. <?php 
  52. printf( 
  53. __( 'We recommend to %sExit Simulation%s before making any changes!', 'membership2' ),  
  54. '<a href="' . MS_Controller_Adminbar::get_simulation_exit_url() . '">',  
  55. '</a>' 
  56. ); 
  57. ?> 
  58. </p> 
  59. <p> 
  60. <em><?php _e( 'This page is only available to Administrators - you can always see it, even during Simulation.', 'membership2' ); ?></em> 
  61. </p> 
  62. </div> 
  63. <?php 
  64. endif; 
  65.  
  66. /** 
  67. * Displays a warning if network-wide protection is enabled for a large 
  68. * network. 
  69. * @since 1.0.0 
  70. */ 
  71. protected function check_network() { 
  72. // Network-wide IS PRO ONLY! 
  73. return; 
  74.  
  75. /** 
  76. * Builds template and return it as string. 
  77. * @since 1.0.0 
  78. * @return string 
  79. */ 
  80. protected function to_html() { 
  81. // This function is implemented different in each child class. 
  82. return apply_filters( 'ms_view_to_html', '' ); 
  83.  
  84. /** 
  85. * Output the rendered template to the browser. 
  86. * @since 1.0.0 
  87. */ 
  88. public function render() { 
  89. $html = $this->to_html(); 
  90.  
  91. echo apply_filters( 
  92. 'ms_view_render',  
  93. $html,  
  94. $this 
  95. );