/app/view/settings/page/class-ms-view-settings-page-setup.php

  1. <?php 
  2. /** 
  3. * Displays the Setup form. 
  4. * Used in both the success popup when creating the first membership and in the 
  5. * settings page. 
  6. * 
  7. * @since 1.0.0 
  8. * @package Membership2 
  9. * @subpackage Model 
  10. */ 
  11. class MS_View_Settings_Page_Setup extends MS_View { 
  12.  
  13. /** 
  14. * Type of form displayed. Used to determine height of the popup. 
  15. * 
  16. * @var string 
  17. */ 
  18. protected $form_type = 'full'; 
  19.  
  20. /** 
  21. * Displays the settings form. 
  22. * 
  23. * @since 1.0.0 
  24. * @return string 
  25. */ 
  26. public function to_html() { 
  27. if ( ! empty( $_REQUEST['full_popup'] ) ) { 
  28. $show_wizard_done = true; 
  29. } else { 
  30. $show_wizard_done = MS_Plugin::instance()->settings->is_first_membership; 
  31.  
  32. if ( $show_wizard_done ) { 
  33. $this->form_type = 'full'; 
  34. $code = $this->html_full_form(); 
  35. } else { 
  36. $this->form_type = 'short'; 
  37. $code = $this->html_short_form(); 
  38.  
  39. return $code; 
  40.  
  41. /** 
  42. * Display the small "completed" form 
  43. * 
  44. * @since 1.0.0 
  45. * @return string HTML Code 
  46. */ 
  47. public function html_short_form() { 
  48. $code = sprintf( 
  49. '<center>%1$s</center>',  
  50. sprintf( 
  51. __( 'You can now go to page %sProtection Rules%s to set up access levels for this Membership.', 'membership2' ),  
  52. sprintf( '<a href="%1$s">', MS_Controller_Plugin::get_admin_url( 'protection' ) ),  
  53. '</a>' 
  54. ); 
  55.  
  56. return $code; 
  57.  
  58. /** 
  59. * Display the full settings form, used either by first membership 
  60. * "completed" popup and also by the general settings tab. 
  61. * 
  62. * @since 1.0.0 
  63. * @return string HTML code 
  64. */ 
  65. public function html_full_form() { 
  66. $fields = $this->prepare_fields(); 
  67.  
  68. ob_start(); 
  69. ?> 
  70. <div class="ms-setup-form"> 
  71. <?php if ( ! MS_Plugin::is_network_wide() ) : ?> 
  72. <div class="ms-setup-nav"> 
  73. <div class="ms-title"> 
  74. <i class="ms-icon dashicons dashicons-menu"></i> 
  75. <?php _e( 'Please select pages you want to appear in your Navigation', 'membership2' ); ?> 
  76. </div> 
  77. <div class="ms-description"> 
  78. <?php 
  79. printf( 
  80. __( 'You can always change those later by going to %1$s in your admin sidebar.', 'membership2' ),  
  81. sprintf( 
  82. '<a href="%1$s" target="_blank">%2$s</a>',  
  83. admin_url( 'nav-menus.php' ),  
  84. __( 'Appearance' ) . ' » ' . __( 'Menus' ) 
  85. ); 
  86. ?> 
  87. </div> 
  88. <?php echo $this->show_menu_controls(); ?> 
  89. </div> 
  90. <?php // Network-wide IS PRO ONLY! ?> 
  91. <?php endif; ?> 
  92. <div class="ms-setup-pages"> 
  93. <div class="ms-title"> 
  94. <i class="ms-icon dashicons dashicons-admin-page"></i> 
  95. <?php _e( 'Membership 2 Pages', 'membership2' ); ?> 
  96. </div> 
  97. <div class="ms-description"> 
  98. <?php _e( 'Set Up Membership 2 Pages that will be displayed on your website.', 'membership2' ); ?> 
  99. </div> 
  100. <?php 
  101.  
  102. if ( is_array( $fields['pages'] ) ) { 
  103. $page_types = array_keys( $fields['pages'] ); 
  104. $page_types_menu = array( 
  105. 'memberships',  
  106. 'register',  
  107. 'account',  
  108. ); 
  109. $page_types_rest = array_diff( $page_types, $page_types_menu ); 
  110. $groups = array( 
  111. 'in-menu' => $page_types_menu,  
  112. 'no-menu' => $page_types_rest,  
  113. ); 
  114.  
  115. $pages_site_id = MS_Model_Pages::get_site_info( 'id' ); 
  116. MS_Factory::select_blog( $pages_site_id ); 
  117.  
  118. foreach ( $groups as $group_key => $group_items ) : 
  119. printf( '<div class="ms-pages-group %1$s">', esc_attr( $group_key ) ); 
  120.  
  121. foreach ( $group_items as $key ) : 
  122. $field = $fields['pages'][$key]; 
  123. ?> 
  124. <div class="ms-settings-page-wrapper"> 
  125. <?php MS_Helper_Html::html_element( $field ); ?> 
  126. <div class="ms-action"> 
  127. <?php 
  128. MS_Helper_Html::html_link( 
  129. array( 
  130. 'id' => 'url_page_' . $field['value'],  
  131. 'url' => '',  
  132. 'value' => __( 'View Page', 'membership2' ),  
  133. 'target' => '_blank',  
  134. 'data_ms' => array( 
  135. 'base' => MS_Helper_Utility::get_home_url( 
  136. $pages_site_id, 'index.php?page_id=' 
  137. ),  
  138. ); 
  139. ?> 
  140. <span> | </span> 
  141. <?php 
  142. MS_Helper_Html::html_link( 
  143. array( 
  144. 'id' => 'edit_url_page_' . $field['value'],  
  145. 'url' => '',  
  146. 'value' => __( 'Edit Page', 'membership2' ),  
  147. 'target' => '_blank',  
  148. 'data_ms' => array( 
  149. 'base' => get_admin_url( 
  150. $pages_site_id, 'post.php?action=edit&post=' 
  151. ),  
  152. ); 
  153. ?> 
  154. </div> 
  155. </div> 
  156. <?php 
  157. endforeach; 
  158.  
  159. echo '</div>'; 
  160. endforeach; 
  161. } else { 
  162. echo $fields['pages']; 
  163.  
  164. MS_Factory::revert_blog(); 
  165. ?> 
  166. </div> 
  167. </div> 
  168. <?php 
  169.  
  170. $html = ob_get_clean(); 
  171.  
  172. return apply_filters( 
  173. 'ms_view_settings_page_setup_to_html',  
  174. $html 
  175. ); 
  176.  
  177. /** 
  178. * Prepare the HTML fields that can be displayed 
  179. * 
  180. * @since 1.0.0 
  181. * 
  182. * @return array 
  183. */ 
  184. protected function prepare_fields() { 
  185. // Prepare the return value. 
  186. $nav = array(); 
  187. $pages = array(); 
  188.  
  189. MS_Model_Pages::create_missing_pages(); 
  190. $page_types = MS_Model_Pages::get_page_types(); 
  191. $page_types_menu = array( 
  192. 'memberships',  
  193. 'register',  
  194. 'account',  
  195. ); 
  196. $page_types_rest = array_diff( $page_types, $page_types_menu ); 
  197.  
  198. // Prepare NAV fields. 
  199. $menu_action = MS_Controller_Pages::AJAX_ACTION_TOGGLE_MENU; 
  200. $menu_nonce = wp_create_nonce( $menu_action ); 
  201. foreach ( $page_types_menu as $type ) { 
  202. $nav_exists = MS_Model_Pages::has_menu( $type ); 
  203. $nav[$type] = array( 
  204. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  205. 'id' => 'nav_' . $type,  
  206. 'value' => $nav_exists,  
  207. 'title' => $page_types[$type],  
  208. 'ajax_data' => array( 
  209. 'action' => $menu_action,  
  210. 'item' => $type,  
  211. '_wpnonce' => $menu_nonce,  
  212. ),  
  213. ); 
  214.  
  215. $nav['sep'] = array( 
  216. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  217. ); 
  218.  
  219. // Prepare PAGES fields. 
  220. $pages_action = MS_Controller_Pages::AJAX_ACTION_UPDATE_PAGES; 
  221. $pages_nonce = wp_create_nonce( $pages_action ); 
  222.  
  223. foreach ( $page_types as $type => $label ) { 
  224. $page_id = MS_Model_Pages::get_setting( $type ); 
  225. $title = sprintf( 
  226. '<strong>%1$s</strong><span class="lbl-details">: %2$s</span>',  
  227. $label,  
  228. MS_Model_Pages::get_description( $type ) 
  229. ); 
  230.  
  231. $pages[ $type ] = array( 
  232. 'id' => $type,  
  233. 'type' => MS_Helper_Html::INPUT_TYPE_WP_PAGES,  
  234. 'title' => $title,  
  235. 'value' => $page_id,  
  236. 'field_options' => array( 
  237. 'no_item' => __( '- Select a page -', 'membership2' ),  
  238. ),  
  239. 'ajax_data' => array( 
  240. 'field' => $type,  
  241. 'action' => $pages_action,  
  242. '_wpnonce' => $pages_nonce,  
  243. ),  
  244. ); 
  245.  
  246. $fields = array( 
  247. 'nav' => $nav,  
  248. 'pages' => $pages,  
  249. ); 
  250.  
  251. return apply_filters( 
  252. 'ms_view_settings_page_setup_prepare_fields',  
  253. $fields,  
  254. $this 
  255. ); 
  256.  
  257. /** 
  258. * Outputs the HTML code to toggle Membership2 menu items. 
  259. * 
  260. * @since 1.0.0 
  261. * @return string 
  262. */ 
  263. public function show_menu_controls() { 
  264. $code = ''; 
  265. $can_create_nav = MS_Model_Pages::can_edit_menus(); 
  266.  
  267. if ( $can_create_nav ) { 
  268. $fields = $this->prepare_fields(); 
  269. foreach ( $fields['nav'] as $field ) { 
  270. $code .= MS_Helper_Html::html_element( $field, true ); 
  271. } else { 
  272. $button = array( 
  273. 'id' => 'create_menu',  
  274. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  275. 'value' => __( 'Okay, create the menu', 'membership2' ),  
  276. 'ajax_data' => array( 
  277. 'action' => MS_Controller_Pages::AJAX_ACTION_CREATE_MENU,  
  278. '_wpnonce' => wp_create_nonce( MS_Controller_Pages::AJAX_ACTION_CREATE_MENU ),  
  279. ); 
  280. $code = sprintf( 
  281. '<div style="padding-left:10px"><p><em>%s</em></p><p>%s</p></div>',  
  282. __( 'Wait! You did not create a menu yet...<br>Let us create it now, so you can choose which pages to display to your visitors!', 'membership2' ),  
  283. MS_Helper_Html::html_element( $button, true ) 
  284. ); 
  285.  
  286. return '<div class="ms-nav-controls">' . $code . '</div>'; 
  287.  
  288. /** 
  289. * Returns the height needed to display this dialog inside a popup without 
  290. * adding scrollbars 
  291. * 
  292. * @since 1.0.0 
  293. * @return int Popup height 
  294. */ 
  295. public function dialog_height() { 
  296. switch ( $this->form_type ) { 
  297. case 'short': 
  298. $height = 200; 
  299. break; 
  300.  
  301. case 'full': 
  302. default: 
  303. if ( MS_Model_Pages::can_edit_menus() ) { 
  304. $height = 412; 
  305. } else { 
  306. $height = 460; 
  307. break; 
  308.  
  309. return $height; 
  310.  
.