/app/class-ms-view.php

  1. <?php 
  2. /** 
  3. * Abstract class for all Views. 
  4. * 
  5. * All views will extend or inherit from the MS_View class. 
  6. * Methods of this class will prepare and output views. 
  7. * 
  8. * @since 1.0.0 
  9. * @package Membership2 
  10. * @subpackage View 
  11. */ 
  12. class MS_View extends MS_Hooker { 
  13.  
  14. /** 
  15. * The storage of all data associated with this render. 
  16. * 
  17. * @since 1.0.0 
  18. * 
  19. * @var array 
  20. */ 
  21. protected $data; 
  22.  
  23. /** 
  24. * Flag is set to true while in Simulation mode. 
  25. * 
  26. * @since 1.0.0 
  27. * 
  28. * @var bool 
  29. */ 
  30. static protected $is_simulating = false; 
  31.  
  32. /** 
  33. * Constructor. 
  34. * 
  35. * @since 1.0.0 
  36. * 
  37. * @param array $data The data what has to be associated with this render. 
  38. */ 
  39. public function __construct( $data = array() ) { 
  40. static $Simulate = null; 
  41.  
  42. $this->data = $data; 
  43.  
  44. /** 
  45. * Actions to execute when constructing the parent View. 
  46. * 
  47. * @since 1.0.0 
  48. * @param object $this The MS_View object. 
  49. */ 
  50. do_action( 'ms_view_construct', $this ); 
  51.  
  52. if ( null === $Simulate && MS_Model_Simulate::can_simulate() ) { 
  53. $Simulate = MS_Factory::load( 'MS_Model_Simulate' ); 
  54. self::$is_simulating = $Simulate->is_simulating(); 
  55.  
  56. /** 
  57. * Displays a note while simulation mode is enabled. 
  58. * 
  59. * @since 1.0.0 
  60. */ 
  61. protected function check_simulation() { 
  62. if ( self::$is_simulating ) : 
  63. ?> 
  64. <div class="error below-h2"> 
  65. <p> 
  66. <strong><?php _e( 'You are in Simulation mode!', 'membership2' ); ?></strong> 
  67. </p> 
  68. <p> 
  69. <?php _e( 'Content displayed here might be altered because of simulated restrictions.', 'membership2' ); ?><br /> 
  70. <?php 
  71. printf( 
  72. __( 'We recommend to %sExit Simulation%s before making any changes!', 'membership2' ),  
  73. '<a href="' . MS_Controller_Adminbar::get_simulation_exit_url() . '">',  
  74. '</a>' 
  75. ); 
  76. ?> 
  77. </p> 
  78. <p> 
  79. <em><?php _e( 'This page is only available to Administrators - you can always see it, even during Simulation.', 'membership2' ); ?></em> 
  80. </p> 
  81. </div> 
  82. <?php 
  83. endif; 
  84.  
  85. /** 
  86. * Displays a warning if network-wide protection is enabled for a large 
  87. * network. 
  88. * 
  89. * @since 1.0.0 
  90. */ 
  91. protected function check_network() { 
  92. if ( MS_Plugin::is_network_wide() && wp_is_large_network() ) : 
  93. ?> 
  94. <div class="error below-h2"> 
  95. <p> 
  96. <strong><?php _e( 'Warning!', 'membership2' ); ?></strong> 
  97. </p> 
  98. <p> 
  99. <?php _e( 'This network has a large number of sites. Some features of network protection might be slow or unavailable.', 'membership2' ); ?> 
  100. </p> 
  101. </div> 
  102. <?php 
  103. endif; 
  104.  
  105. /** 
  106. * Builds template and return it as string. 
  107. * 
  108. * @since 1.0.0 
  109. * 
  110. * @return string 
  111. */ 
  112. protected function to_html() { 
  113. // This function is implemented different in each child class. 
  114. return apply_filters( 'ms_view_to_html', '' ); 
  115.  
  116. /** 
  117. * Output the rendered template to the browser. 
  118. * 
  119. * @since 1.0.0 
  120. */ 
  121. public function render() { 
  122. $html = $this->to_html(); 
  123.  
  124. echo apply_filters( 
  125. 'ms_view_render',  
  126. $html,  
  127. $this 
  128. ); 
.