/app/controller/class-ms-controller-shortcode.php

  1. <?php 
  2. /** 
  3. * Controller for managing Plugin Shortcodes. 
  4. * 
  5. * @since 1.0.0 
  6. * 
  7. * @package Membership2 
  8. * @subpackage Controller 
  9. */ 
  10. class MS_Controller_Shortcode extends MS_Controller { 
  11.  
  12. /** 
  13. * Prepare the shortcode hooks. 
  14. * 
  15. * @since 1.0.0 
  16. */ 
  17. public function __construct() { 
  18. parent::__construct(); 
  19. $this->run_action( 'init', 'init' ); 
  20.  
  21. /** 
  22. * Initialize the Shortcodes after we have determined the current user. 
  23. * 
  24. * @since 1.0.0 
  25. */ 
  26. public function init() { 
  27. // By default assume no content for the protected-content code 
  28. add_shortcode( 
  29. MS_Helper_Shortcode::SCODE_PROTECTED,  
  30. array( $this, '__return_null' ) 
  31. ); 
  32.  
  33. if ( MS_Plugin::is_enabled() ) { 
  34. add_shortcode( 
  35. MS_Helper_Shortcode::SCODE_REGISTER_USER,  
  36. array( $this, 'membership_register_user' ) 
  37. ); 
  38.  
  39. add_shortcode( 
  40. MS_Helper_Shortcode::SCODE_SIGNUP,  
  41. array( $this, 'membership_signup' ) 
  42. ); 
  43.  
  44. add_shortcode( 
  45. MS_Helper_Shortcode::SCODE_MS_TITLE,  
  46. array( $this, 'membership_title' ) 
  47. ); 
  48.  
  49. add_shortcode( 
  50. MS_Helper_Shortcode::SCODE_MS_PRICE,  
  51. array( $this, 'membership_price' ) 
  52. ); 
  53.  
  54. add_shortcode( 
  55. MS_Helper_Shortcode::SCODE_MS_BUY,  
  56. array( $this, 'membership_buy' ) 
  57. ); 
  58.  
  59. add_shortcode( 
  60. MS_Helper_Shortcode::SCODE_MS_DETAILS,  
  61. array( $this, 'membership_details' ) 
  62. ); 
  63.  
  64. add_shortcode( 
  65. MS_Helper_Shortcode::SCODE_LOGIN,  
  66. array( $this, 'membership_login' ) 
  67. ); 
  68.  
  69. add_shortcode( 
  70. MS_Helper_Shortcode::SCODE_LOGOUT,  
  71. array( $this, 'membership_logout' ) 
  72. ); 
  73.  
  74. add_shortcode( 
  75. MS_Helper_Shortcode::SCODE_MS_ACCOUNT,  
  76. array( $this, 'membership_account' ) 
  77. ); 
  78.  
  79. add_shortcode( 
  80. MS_Helper_Shortcode::SCODE_MS_ACCOUNT_LINK,  
  81. array( $this, 'membership_account_link' ) 
  82. ); 
  83.  
  84. add_shortcode( 
  85. MS_Helper_Shortcode::SCODE_MS_INVOICE,  
  86. array( $this, 'membership_invoice' ) 
  87. ); 
  88.  
  89. add_shortcode( 
  90. MS_Helper_Shortcode::SCODE_NOTE,  
  91. array( $this, 'ms_note' ) 
  92. ); 
  93.  
  94. add_shortcode( 
  95. MS_Helper_Shortcode::SCODE_GREEN_NOTE,  
  96. array( $this, 'ms_green_note' ) 
  97. ); 
  98.  
  99. add_shortcode( 
  100. MS_Helper_Shortcode::SCODE_RED_NOTE,  
  101. array( $this, 'ms_red_note' ) 
  102. ); 
  103.  
  104. add_shortcode( 
  105. MS_Helper_Shortcode::SCODE_USER,  
  106. array( $this, 'show_to_user' ) 
  107. ); 
  108.  
  109. add_shortcode( 
  110. MS_Helper_Shortcode::SCODE_MEMBER_INFO,  
  111. array( $this, 'ms_member_info' ) 
  112. ); 
  113.  
  114. if ( MS_Model_Member::is_normal_admin() ) { 
  115. add_shortcode( 
  116. MS_Rule_Shortcode_Model::PROTECT_CONTENT_SHORTCODE,  
  117. array( 'MS_Rule_Shortcode_Model', 'debug_protect_content_shortcode') 
  118. ); 
  119. } else { 
  120. $shortcodes = array( 
  121. MS_Helper_Shortcode::SCODE_REGISTER_USER,  
  122. MS_Helper_Shortcode::SCODE_SIGNUP,  
  123. MS_Helper_Shortcode::SCODE_MS_TITLE,  
  124. MS_Helper_Shortcode::SCODE_MS_PRICE,  
  125. MS_Helper_Shortcode::SCODE_MS_DETAILS,  
  126. MS_Helper_Shortcode::SCODE_LOGIN,  
  127. MS_Helper_Shortcode::SCODE_LOGOUT,  
  128. MS_Helper_Shortcode::SCODE_MS_ACCOUNT,  
  129. MS_Helper_Shortcode::SCODE_MS_ACCOUNT_LINK,  
  130. MS_Helper_Shortcode::SCODE_MS_INVOICE,  
  131. MS_Helper_Shortcode::SCODE_NOTE,  
  132. MS_Helper_Shortcode::SCODE_GREEN_NOTE,  
  133. MS_Helper_Shortcode::SCODE_RED_NOTE,  
  134. ); 
  135.  
  136. foreach ( $shortcodes as $shortcode ) { 
  137. add_shortcode( $shortcode, array( $this, 'ms_no_value' ) ); 
  138.  
  139. add_shortcode( 
  140. MS_Rule_Shortcode_Model::PROTECT_CONTENT_SHORTCODE,  
  141. array( $this, 'hide_shortcode') 
  142. ); 
  143.  
  144. add_shortcode( 
  145. MS_Helper_Shortcode::SCODE_USER,  
  146. array( $this, 'hide_shortcode') 
  147. ); 
  148.  
  149. /** 
  150. * Set up the protected-content shortcode to display the protection message. 
  151. * 
  152. * This function is only called from the Frontend-Controller when the 
  153. * Membership Page "Membership2" is displayed. 
  154. * 
  155. * @since 1.0.0 
  156. */ 
  157. public function page_is_protected() { 
  158. remove_shortcode( 
  159. MS_Helper_Shortcode::SCODE_PROTECTED,  
  160. array( $this, '__return_null' ) 
  161. ); 
  162.  
  163. add_shortcode( 
  164. MS_Helper_Shortcode::SCODE_PROTECTED,  
  165. array( $this, 'protected_content' ) 
  166. ); 
  167.  
  168.  
  169. /**========================================*\ 
  170. ============================================ 
  171. == == 
  172. == SHORTCODE HANDLERS == 
  173. == == 
  174. ============================================ 
  175. \*========================================*/ 
  176.  
  177.  
  178.  
  179. /** 
  180. * Membership register callback function. 
  181. * 
  182. * @since 1.0.0 
  183. * 
  184. * @param mixed[] $atts Shortcode attributes. 
  185. */ 
  186. public function membership_register_user( $atts ) { 
  187. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_REGISTER_USER ); 
  188.  
  189. lib3()->array->equip_request( 
  190. 'first_name',  
  191. 'last_name',  
  192. 'username',  
  193. 'email',  
  194. 'membership_id' 
  195. ); 
  196.  
  197. $data = apply_filters( 
  198. 'ms_controller_shortcode_membership_register_user_atts',  
  199. shortcode_atts( 
  200. array( 
  201. 'first_name' => substr( trim( $_REQUEST['first_name'] ), 0, 50 ),  
  202. 'last_name' => substr( trim( $_REQUEST['last_name'] ), 0, 50 ),  
  203. 'username' => substr( trim( $_REQUEST['username'] ), 0, 50 ),  
  204. 'email' => substr( trim( $_REQUEST['email'] ), 0, 50 ),  
  205. 'membership_id' => trim( $_REQUEST['membership_id'] ),  
  206. 'label_first_name' => __( 'First Name', 'membership2' ),  
  207. 'label_last_name' => __( 'Last Name', 'membership2' ),  
  208. 'label_username' => __( 'Choose a Username', 'membership2' ),  
  209. 'label_email' => __( 'Email Address', 'membership2' ),  
  210. 'label_password' => __( 'Password', 'membership2' ),  
  211. 'label_password2' => __( 'Confirm Password', 'membership2' ),  
  212. 'label_register' => __( 'Register My Account', 'membership2' ),  
  213. 'hint_first_name' => '',  
  214. 'hint_last_name' => '',  
  215. 'hint_username' => '',  
  216. 'hint_email' => '',  
  217. 'hint_password' => '',  
  218. 'hint_password2' => '',  
  219. 'title' => __( 'Create an Account', 'membership2' ),  
  220. 'loginlink' => true,  
  221. ),  
  222. $atts 
  223. ); 
  224. $data['action'] = 'register_user'; 
  225. $data['step'] = MS_Controller_Frontend::STEP_REGISTER_SUBMIT; 
  226. $data['loginlink'] = lib3()->is_true( $data['loginlink'] ); 
  227.  
  228. $view = MS_Factory::create( 'MS_View_Shortcode_RegisterUser' ); 
  229. $view->data = apply_filters( 'ms_view_shortcode_registeruser_data', $data, $this ); 
  230.  
  231. return $view->to_html(); 
  232.  
  233. /** 
  234. * Membership signup callback function. 
  235. * 
  236. * @since 1.0.0 
  237. * 
  238. * @param mixed[] $atts Shortcode attributes. 
  239. */ 
  240. public function membership_signup( $atts ) { 
  241. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_SIGNUP ); 
  242.  
  243. $data = apply_filters( 
  244. 'ms_controller_shortcode_membership_signup_atts',  
  245. shortcode_atts( 
  246. array( 
  247. MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP . '_text' => __( 'Signup', 'membership2' ),  
  248. MS_Helper_Membership::MEMBERSHIP_ACTION_MOVE . '_text' => __( 'Change', 'membership2' ),  
  249. MS_Helper_Membership::MEMBERSHIP_ACTION_CANCEL . '_text' => __( 'Cancel', 'membership2' ),  
  250. MS_Helper_Membership::MEMBERSHIP_ACTION_RENEW . '_text' => __( 'Renew', 'membership2' ),  
  251. MS_Helper_Membership::MEMBERSHIP_ACTION_PAY . '_text' => __( 'Complete Payment', 'membership2' ),  
  252. ),  
  253. $atts 
  254. ); 
  255.  
  256. $member = MS_Model_Member::get_current_member(); 
  257. $data['member'] = $member; 
  258. $data['subscriptions'] = array(); 
  259. $exclude = array(); 
  260.  
  261. if ( $member->is_valid() ) { 
  262. // Get member's memberships, including pending relationships. 
  263. $data['subscriptions'] = MS_Model_Relationship::get_subscriptions( 
  264. array( 
  265. 'user_id' => $data['member']->id,  
  266. 'status' => 'valid',  
  267. ); 
  268.  
  269. foreach ( $data['subscriptions'] as $key => $subscription ) { 
  270. $exclude[] = $subscription->membership_id; 
  271. if ( ! $member->can_subscribe_to( $subscription->membership_id ) ) { 
  272. unset( $data['subscriptions'][$key] ); 
  273.  
  274. $memberships = MS_Model_Membership::get_signup_membership_list( 
  275. null,  
  276. $exclude 
  277. ); 
  278.  
  279. if ( ! $member->is_valid() || ! $member->has_membership() ) { 
  280. foreach( $memberships as $key => $membership ) { 
  281. if( isset( $membership->update_denied['guest'] ) && lib3()->is_true( $membership->update_denied['guest'] ) ) { 
  282. unset( $memberships[$key] ); 
  283.  
  284.  
  285. $data['memberships'] = $memberships; 
  286. $move_from_ids = array(); 
  287.  
  288. // When Multiple memberships is not enabled, a member should move to another membership. 
  289. if ( ! MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_MULTI_MEMBERSHIPS ) ) { 
  290. // Membership Relationship status which can move to another one 
  291. $valid_status = array( 
  292. MS_Model_Relationship::STATUS_TRIAL,  
  293. MS_Model_Relationship::STATUS_ACTIVE,  
  294. MS_Model_Relationship::STATUS_EXPIRED,  
  295. ); 
  296.  
  297. foreach ( $data['member']->subscriptions as $subscription ) { 
  298. if ( $subscription->is_system() ) { continue; } 
  299.  
  300. if ( in_array( $subscription->status, $valid_status ) ) { 
  301. $move_from_ids[] = $subscription->membership_id; 
  302. foreach ( $data['memberships'] as $key => $membership ) { 
  303. $data['memberships'][$key]->_move_from = $move_from_ids; 
  304. } else { 
  305. foreach ( $data['memberships'] as $key => $membership ) { 
  306. $move_from_ids = $member->cancel_ids_on_subscription( 
  307. $membership->id 
  308. ); 
  309.  
  310. $data['memberships'][$key]->_move_from = $move_from_ids; 
  311.  
  312. $data['action'] = MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP; 
  313. $data['step'] = MS_Controller_Frontend::STEP_PAYMENT_TABLE; 
  314.  
  315. $view = MS_Factory::create( 'MS_View_Shortcode_MembershipSignup' ); 
  316. $view->data = apply_filters( 
  317. 'ms_view_shortcode_membershipsignup_data',  
  318. $data,  
  319. $this 
  320. ); 
  321.  
  322. return $view->to_html(); 
  323.  
  324. /** 
  325. * Membership title shortcode callback function. 
  326. * 
  327. * @since 1.0.0 
  328. * 
  329. * @param mixed[] $atts Shortcode attributes. 
  330. */ 
  331. public function membership_title( $atts ) { 
  332. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_TITLE ); 
  333.  
  334. $code = ''; 
  335.  
  336. $data = apply_filters( 
  337. 'ms_controller_shortcode_membership_title_atts',  
  338. shortcode_atts( 
  339. array( 
  340. 'id' => 0,  
  341. 'label' => __( 'Membership title:', 'membership2' ),  
  342. 'title' => '', // deprecated @since 1.0.0 
  343. ),  
  344. $atts 
  345. ); 
  346. extract( $data ); 
  347.  
  348. if ( ! empty( $id ) ) { 
  349. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  350. $code = sprintf( 
  351. '%1$s %2$s',  
  352. $label,  
  353. $membership->name 
  354. ); 
  355.  
  356. $code = trim( $code ); 
  357. } else { 
  358. $code = $title; 
  359.  
  360. $code = sprintf( 
  361. '<span class="ms-membership-title ms-membership-%1$s">%2$s</span>',  
  362. esc_attr( $id ),  
  363. $code 
  364. ); 
  365.  
  366. return apply_filters( 
  367. 'ms_controller_shortcode_membership_title',  
  368. $code,  
  369. $atts,  
  370. $this 
  371. ); 
  372.  
  373. /** 
  374. * Membership price shortcode callback function. 
  375. * 
  376. * @since 1.0.0 
  377. * 
  378. * @param mixed[] $atts Shortcode attributes. 
  379. */ 
  380. public function membership_price( $atts ) { 
  381. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_PRICE ); 
  382.  
  383. $code = 0; 
  384.  
  385. $data = apply_filters( 
  386. 'ms_controller_shortcode_membership_price_atts',  
  387. shortcode_atts( 
  388. array( 
  389. 'id' => 0,  
  390. 'currency' => true,  
  391. 'label' => __( 'Membership price:', 'membership2' ),  
  392. ),  
  393. $atts 
  394. ); 
  395. extract( $data ); 
  396.  
  397. if ( ! empty( $id ) ) { 
  398. if ( lib3()->is_true( $currency ) ) { 
  399. $settings = MS_Factory::load( 'MS_Model_Settings' ); 
  400. $currency = $settings->currency; 
  401. } else { 
  402. $currency = ''; 
  403.  
  404. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  405. $code = sprintf( 
  406. '%1$s %2$s %3$s',  
  407. $label,  
  408. $currency,  
  409. $membership->total_price 
  410. ); 
  411.  
  412. $code = trim( $code ); 
  413.  
  414. $code = sprintf( 
  415. '<span class="ms-membership-price ms-membership-%1$s price">%2$s</span>',  
  416. esc_attr( $id ),  
  417. $code 
  418. ); 
  419.  
  420. do_action( 'ms_show_prices' ); 
  421. return apply_filters( 
  422. 'ms_controller_shortcode_membership_price',  
  423. $code,  
  424. $atts,  
  425. $this 
  426. ); 
  427.  
  428. /** 
  429. * Buy membership button. 
  430. * 
  431. * @since 1.0.0 
  432. * 
  433. * @param mixed[] $atts Shortcode attributes. 
  434. */ 
  435. public function membership_buy( $atts ) { 
  436. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_BUY ); 
  437.  
  438. $code = ''; 
  439.  
  440. $data = apply_filters( 
  441. 'ms_controller_shortcode_membership_buy_atts',  
  442. shortcode_atts( 
  443. array( 
  444. 'id' => 0,  
  445. 'label' => __( 'Signup', 'membership2' ),  
  446. ),  
  447. $atts 
  448. ); 
  449. extract( $data ); 
  450.  
  451. if ( ! empty( $id ) ) { 
  452. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  453. $data['action'] = MS_Helper_Membership::MEMBERSHIP_ACTION_SIGNUP; 
  454. $data['step'] = MS_Controller_Frontend::STEP_PAYMENT_TABLE; 
  455.  
  456. $view = MS_Factory::create( 'MS_View_Shortcode_MembershipSignup' ); 
  457. $view->data = apply_filters( 
  458. 'ms_view_shortcode_membershipsignup_data',  
  459. $data,  
  460. $this 
  461. ); 
  462.  
  463. $code = $view->signup_form( $membership, $label ); 
  464.  
  465. $code = sprintf( 
  466. '<span class="ms-membership-buy ms-membership-%1$s">%2$s</span>',  
  467. esc_attr( $id ),  
  468. $code 
  469. ); 
  470.  
  471. return apply_filters( 
  472. 'ms_controller_shortcode_membership_buy',  
  473. $code,  
  474. $atts,  
  475. $this 
  476. ); 
  477.  
  478. /** 
  479. * Membership details shortcode callback function. 
  480. * 
  481. * @since 1.0.0 
  482. * 
  483. * @param mixed[] $atts Shortcode attributes. 
  484. */ 
  485. public function membership_details( $atts ) { 
  486. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_DETAILS ); 
  487.  
  488. $code = ''; 
  489.  
  490. $data = apply_filters( 
  491. 'ms_controller_shortcode_membership_details_atts',  
  492. shortcode_atts( 
  493. array( 
  494. 'id' => 0,  
  495. 'label' => __( 'Membership details:', 'membership2' ),  
  496. ),  
  497. $atts 
  498. ); 
  499. extract( $data ); 
  500.  
  501. if ( ! empty( $id ) ) { 
  502. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  503. $code = sprintf( 
  504. '%1$s %2$s',  
  505. $label,  
  506. $membership->get_description() 
  507. ); 
  508.  
  509. $code = trim( $code ); 
  510.  
  511. $code = sprintf( 
  512. '<span class="ms-membership-details ms-membership-%1$s">%2$s</span>',  
  513. esc_attr( $id ),  
  514. $code 
  515. ); 
  516.  
  517. return apply_filters( 
  518. 'ms_controller_shortcode_membership_details',  
  519. $code,  
  520. $atts,  
  521. $this 
  522. ); 
  523.  
  524. /** 
  525. * Display the "Membership2" message. 
  526. * 
  527. * @since 1.0.0 
  528. * 
  529. * @param mixed[] $atts Shortcode attributes. 
  530. */ 
  531. public function protected_content( $atts ) { 
  532. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_PROTECTED ); 
  533.  
  534. global $post; 
  535.  
  536. $setting = MS_Plugin::instance()->settings; 
  537. $member = MS_Model_Member::get_current_member(); 
  538.  
  539. if( defined( 'MS_PROTECTED_MESSAGE_REVERSE_RULE' ) && MS_PROTECTED_MESSAGE_REVERSE_RULE && isset( $_REQUEST['membership_id'] ) ) { 
  540. $protection_msg = $setting->get_protection_message( 
  541. MS_Model_Settings::PROTECTION_MSG_CONTENT,  
  542. $_REQUEST['membership_id'] 
  543. ); 
  544. }else{ 
  545. if ( count( $member->subscriptions ) ) { 
  546. $sub = $member->get_subscription( 'priority' ); 
  547. $protection_msg = $setting->get_protection_message( 
  548. MS_Model_Settings::PROTECTION_MSG_CONTENT,  
  549. $sub->membership_id 
  550. ); 
  551. } else { 
  552. $protection_msg = $setting->get_protection_message( 
  553. MS_Model_Settings::PROTECTION_MSG_CONTENT 
  554. ); 
  555.  
  556. $html = '<div class="ms-protected-content">'; 
  557. if ( ! empty( $protection_msg ) ) { 
  558. $html .= $protection_msg; 
  559.  
  560. if ( ! MS_Model_Member::is_logged_in() ) { 
  561. $has_login_form = MS_Helper_Shortcode::has_shortcode( 
  562. MS_Helper_Shortcode::SCODE_LOGIN,  
  563. $post->post_content 
  564. ); 
  565.  
  566. if ( ! $has_login_form ) { 
  567. $scode = '[' . MS_Helper_Shortcode::SCODE_LOGIN . ']'; 
  568. $html .= do_shortcode( $scode ); 
  569. $html .= '</div>'; 
  570.  
  571. return apply_filters( 
  572. 'ms_controller_shortcode_protected_content',  
  573. $html,  
  574. $this 
  575. ); 
  576.  
  577. /** 
  578. * Membership login shortcode callback function. 
  579. * 
  580. * @since 1.0.0 
  581. * 
  582. * @param mixed[] $atts Shortcode attributes. 
  583. */ 
  584. public function membership_login( $atts ) { 
  585. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_LOGIN ); 
  586.  
  587. $data = apply_filters( 
  588. 'ms_controller_shortcode_membership_login_atts',  
  589. shortcode_atts( 
  590. array( 
  591. 'holder' => 'div',  
  592. 'holderclass' => 'ms-login-form',  
  593. 'item' => '',  
  594. 'itemclass' => '',  
  595. 'postfix' => '',  
  596. 'prefix' => '',  
  597. 'wrapwith' => '',  
  598. 'wrapwithclass' => '',  
  599. 'redirect_login' => MS_Model_Pages::get_url_after_login(),  
  600. 'redirect_logout' => MS_Model_Pages::get_url_after_logout(),  
  601. 'header' => true,  
  602. 'register' => true,  
  603. 'title' => '',  
  604. 'show_note' => true, // Show the "you are not logged in" note? 
  605. 'form' => '', // [login|lost|reset|logout] 
  606. 'show_labels' => false,  
  607. 'autofocus' => true,  
  608. 'nav_pos' => 'top', // [top|bottom] 
  609.  
  610. // form="login" 
  611. 'show_remember' => true,  
  612. 'label_username' => __( 'Username', 'membership2' ),  
  613. 'label_password' => __( 'Password', 'membership2' ),  
  614. 'label_remember' => __( 'Remember Me', 'membership2' ),  
  615. 'label_log_in' => __( 'Log In', 'membership2' ),  
  616. 'id_login_form' => 'loginform',  
  617. 'id_username' => 'user_login',  
  618. 'id_password' => 'user_pass',  
  619. 'id_remember' => 'rememberme',  
  620. 'id_login' => 'wp-submit',  
  621. 'value_username' => '',  
  622. 'value_remember' => false,  
  623.  
  624. // form="lost" 
  625. 'label_lost_username' => __( 'Username or E-mail', 'membership2' ),  
  626. 'label_lostpass' => __( 'Reset Password', 'membership2' ),  
  627. 'id_lost_form' => 'lostpasswordform',  
  628. 'id_lost_username' => 'user_login',  
  629. 'id_lostpass' => 'wp-submit',  
  630. 'value_username' => '',  
  631. ),  
  632. $atts 
  633. ); 
  634.  
  635. $data['header'] = lib3()->is_true( $data['header'] ); 
  636. $data['register'] = lib3()->is_true( $data['register'] ); 
  637. $data['show_note'] = lib3()->is_true( $data['show_note'] ); 
  638. $data['show_labels'] = lib3()->is_true( $data['show_labels'] ); 
  639. $data['show_remember'] = lib3()->is_true( $data['show_remember'] ); 
  640. $data['value_remember'] = lib3()->is_true( $data['value_remember'] ); 
  641. $data['autofocus'] = lib3()->is_true( $data['autofocus'] ); 
  642.  
  643. $view = MS_Factory::create( 'MS_View_Shortcode_Login' ); 
  644. $view->data = apply_filters( 'ms_view_shortcode_login_data', $data, $this ); 
  645.  
  646. return $view->to_html(); 
  647.  
  648. /** 
  649. * Membership logout shortcode callback function. 
  650. * 
  651. * @since 1.0.0 
  652. * 
  653. * @param mixed[] $atts Shortcode attributes. 
  654. */ 
  655. public function membership_logout( $atts ) { 
  656. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_LOGOUT ); 
  657.  
  658. $data = apply_filters( 
  659. 'ms_controller_shortcode_membership_logout_atts',  
  660. shortcode_atts( 
  661. array( 
  662. 'holder' => 'div',  
  663. 'holderclass' => 'ms-logout-form',  
  664. 'redirect' => MS_Model_Pages::get_url_after_logout(),  
  665. ),  
  666. $atts 
  667. ); 
  668.  
  669. // The form attribute triggers the logout-link to be displayed. 
  670. $data['form'] = 'logout'; 
  671. $data['redirect_logout'] = $data['redirect']; 
  672.  
  673. $view = MS_Factory::create( 'MS_View_Shortcode_Login' ); 
  674. $view->data = apply_filters( 'ms_view_shortcode_logout_data', $data, $this ); 
  675.  
  676. return $view->to_html(); 
  677.  
  678. /** 
  679. * Membership account page shortcode callback function. 
  680. * 
  681. * @since 1.0.0 
  682. * 
  683. * @param mixed[] $atts Shortcode attributes. 
  684. */ 
  685. public function membership_account( $atts ) { 
  686. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_ACCOUNT ); 
  687.  
  688. $data = apply_filters( 
  689. 'ms_controller_shortcode_membership_account_atts',  
  690. shortcode_atts( 
  691. array( 
  692. 'show_membership' => true,  
  693. 'show_membership_change' => true,  
  694. 'membership_title' => __( 'Your Membership', 'membership2' ),  
  695. 'membership_change_label' => __( 'Change', 'membership2' ),  
  696. 'show_profile' => true,  
  697. 'show_profile_change' => true,  
  698. 'profile_title' => __( 'Personal details', 'membership2' ),  
  699. 'profile_change_label' => __( 'Edit', 'membership2' ),  
  700. 'show_invoices' => true,  
  701. 'limit_invoices' => 10,  
  702. 'show_all_invoices' => true,  
  703. 'invoices_title' => __( 'Invoices', 'membership2' ),  
  704. 'invoices_details_label' => __( 'View all', 'membership2' ),  
  705. 'show_activity' => true,  
  706. 'limit_activities' => 10,  
  707. 'show_all_activities' => true,  
  708. 'activity_title' => __( 'Activities', 'membership2' ),  
  709. 'activity_details_label' => __( 'View all', 'membership2' ),  
  710. ),  
  711. $atts 
  712. ); 
  713.  
  714. $data['show_membership'] = lib3()->is_true( $data['show_membership'] ); 
  715. $data['show_membership_change'] = lib3()->is_true( $data['show_membership_change'] ); 
  716. $data['show_profile'] = lib3()->is_true( $data['show_profile'] ); 
  717. $data['show_profile_change'] = lib3()->is_true( $data['show_profile_change'] ); 
  718. $data['show_invoices'] = lib3()->is_true( $data['show_invoices'] ); 
  719. $data['show_all_invoices'] = lib3()->is_true( $data['show_all_invoices'] ); 
  720. $data['show_activity'] = lib3()->is_true( $data['show_activity'] ); 
  721. $data['show_all_activities'] = lib3()->is_true( $data['show_all_activities'] ); 
  722.  
  723. $data['limit_invoices'] = absint( $data['limit_invoices'] ); 
  724. $data['limit_activities'] = absint( $data['limit_activities'] ); 
  725.  
  726. $data['member'] = MS_Model_Member::get_current_member(); 
  727. $data['membership'] = array(); 
  728.  
  729. $subscriptions = MS_Model_Relationship::get_subscriptions( 
  730. array( 
  731. 'user_id' => $data['member']->id,  
  732. 'status' => 'all',  
  733. ); 
  734. if ( is_array( $subscriptions ) ) { 
  735. foreach ( $subscriptions as $subscription ) { 
  736. // Do not display system-memberships in Account 
  737. if ( $subscription->is_system() ) { continue; } 
  738.  
  739. // Do not display deactivated memberships in Account 
  740. if ( $subscription->get_status() == MS_Model_Relationship::STATUS_DEACTIVATED ) { continue; } 
  741.  
  742. $data['subscription'][] = $subscription; 
  743.  
  744. $data['invoices'] = MS_Model_Invoice::get_public_invoices( 
  745. $data['member']->id,  
  746. $data['limit_invoices'] 
  747. ); 
  748.  
  749. $data['events'] = MS_Model_Event::get_events( 
  750. array( 
  751. 'author' => $data['member']->id,  
  752. 'posts_per_page' => $data['limit_activities'],  
  753. ); 
  754.  
  755. $view = MS_Factory::create( 'MS_View_Shortcode_Account' ); 
  756. $view->data = apply_filters( 
  757. 'ms_view_shortcode_account_data',  
  758. $data,  
  759. $this 
  760. ); 
  761.  
  762. return $view->to_html(); 
  763.  
  764. /** 
  765. * Link to the Membership account page shortcode. 
  766. * 
  767. * @since 1.0.0 
  768. * 
  769. * @param mixed[] $atts Shortcode attributes. 
  770. */ 
  771. public function membership_account_link( $atts ) { 
  772. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_ACCOUNT_LINK ); 
  773.  
  774. $html = ''; 
  775.  
  776. $data = apply_filters( 
  777. 'ms_controller_shortcode_membership_account_link_atts',  
  778. shortcode_atts( 
  779. array( 
  780. 'label' => __( 'Visit your account page for more information.', 'membership2' ),  
  781. ),  
  782. $atts 
  783. ); 
  784.  
  785. $html = sprintf( 
  786. '<a href="%1$s">%2$s</a>',  
  787. MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_ACCOUNT ),  
  788. $data['label'] 
  789. ); 
  790.  
  791. return apply_filters( 
  792. 'ms_controller_shortcode_protected_content',  
  793. $html,  
  794. $this 
  795. ); 
  796.  
  797. /** 
  798. * Membership invoice shortcode callback function. 
  799. * 
  800. * @since 1.0.0 
  801. * 
  802. * @param mixed[] $atts Shortcode attributes. 
  803. */ 
  804. public function membership_invoice( $atts ) { 
  805. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MS_INVOICE ); 
  806.  
  807. $data = apply_filters( 
  808. 'ms_controller_shortcode_invoice_atts',  
  809. shortcode_atts( 
  810. array( 
  811. 'post_id' => 0,  
  812. 'id' => 0,  
  813. 'pay_button' => 1,  
  814. ),  
  815. $atts,  
  816. MS_Helper_Shortcode::SCODE_MS_INVOICE 
  817. ); 
  818.  
  819. if ( ! empty( $data['id'] ) ) { 
  820. $data['post_id'] = $data['id']; 
  821.  
  822. if ( ! empty( $data['post_id'] ) ) { 
  823. $invoice = MS_Factory::load( 'MS_Model_Invoice', $data['post_id'] ); 
  824. $subscription = MS_Factory::load( 'MS_Model_Relationship', $invoice->ms_relationship_id ); 
  825.  
  826. $data['invoice'] = $invoice; 
  827. $data['member'] = MS_Factory::load( 'MS_Model_Member', $invoice->user_id ); 
  828. $data['ms_relationship'] = $subscription; 
  829. $data['membership'] = $subscription->get_membership(); 
  830. $data['gateway'] = MS_Model_Gateway::factory( $invoice->gateway_id ); 
  831.  
  832. $view = MS_Factory::create( 'MS_View_Shortcode_Invoice' ); 
  833. $view->data = apply_filters( 
  834. 'ms_view_shortcode_invoice_data',  
  835. $data,  
  836. $this 
  837. ); 
  838.  
  839. return $view->to_html(); 
  840.  
  841. /** 
  842. * Text note shortcode callback function. 
  843. * 
  844. * @since 1.0.0 
  845. * 
  846. * @param mixed[] $atts Shortcode attributes. 
  847. */ 
  848. public function ms_note( $atts, $content = '' ) { 
  849. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_NOTE ); 
  850.  
  851. lib3()->ui->css( 'ms-styles' ); 
  852.  
  853. $atts = apply_filters( 
  854. 'ms_controller_shortcode_note_atts',  
  855. shortcode_atts( 
  856. array( 
  857. 'type' => 'info',  
  858. 'class' => '',  
  859. ),  
  860. $atts,  
  861. MS_Helper_Shortcode::SCODE_NOTE 
  862. ); 
  863.  
  864. $class = $atts['class']; 
  865.  
  866. switch ( $atts['type'] ) { 
  867. case 'info': 
  868. case 'success': 
  869. $class .= ' ms-alert-success'; 
  870. break; 
  871.  
  872. case 'error': 
  873. case 'warning': 
  874. $class .= ' ms-alert-error'; 
  875. break; 
  876.  
  877. /** 
  878. * The $content of the notice is translated! 
  879. * This gives translators the option to translate even custom messages 
  880. * that are entered into the shortcode! 
  881. * 
  882. * @since 1.0.0 
  883. */ 
  884. $content = sprintf( 
  885. '<p class="ms-alert-box %1$s">%2$s</p> ',  
  886. $class,  
  887. __( $content, 'membership2' ) 
  888. ); 
  889.  
  890. $content = do_shortcode( $content ); 
  891.  
  892. return apply_filters( 
  893. 'ms_controller_shortcode_ms_note',  
  894. $content,  
  895. $this 
  896. ); 
  897.  
  898. /** 
  899. * Display a green text note. 
  900. * 
  901. * @since 1.0.0 
  902. * @deprecated since 1.0.4.5 
  903. * 
  904. * @param mixed[] $atts Shortcode attributes. 
  905. */ 
  906. public function ms_green_note( $atts, $content = '' ) { 
  907. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_GREEN_NOTE ); 
  908.  
  909. $content = $this->ms_note( array( 'type' => 'info' ), $content ); 
  910.  
  911. return apply_filters( 
  912. 'ms_controller_shortcode_ms_green_note',  
  913. $content,  
  914. $this 
  915. ); 
  916.  
  917. /** 
  918. * Display a red text note. 
  919. * 
  920. * @since 1.0.0 
  921. * @deprecated since 1.0.4.5 
  922. * 
  923. * @param mixed[] $atts Shortcode attributes. 
  924. */ 
  925. public function ms_red_note( $atts, $content = '' ) { 
  926. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_RED_NOTE ); 
  927.  
  928. $content = $this->ms_note( array( 'type' => 'warning' ), $content ); 
  929.  
  930. return apply_filters( 
  931. 'ms_controller_shortcode_ms_red_note',  
  932. $content,  
  933. $this 
  934. ); 
  935.  
  936. /** 
  937. * Shortcode callback: Show message only to certain users. 
  938. * 
  939. * @since 1.0.0 
  940. * 
  941. * @param mixed[] $atts Shortcode attributes. 
  942. */ 
  943. public function show_to_user( $atts, $content = '' ) { 
  944. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_USER ); 
  945.  
  946. $data = apply_filters( 
  947. 'ms_controller_shortcode_show_to_user_atts',  
  948. shortcode_atts( 
  949. array( 
  950. 'type' => 'loggedin',  
  951. 'msg' => '',  
  952. ),  
  953. $atts 
  954. ); 
  955.  
  956. extract( $data ); 
  957. $access = false; 
  958.  
  959. $user_type = 'guest'; 
  960. if ( is_user_logged_in() ) { 
  961. $user_type = 'loggedin'; 
  962.  
  963. if ( MS_Model_Member::is_admin_user() ) { 
  964. $user_type = 'admin'; 
  965.  
  966. $class = 'ms-user-is-' . $user_type; 
  967.  
  968. switch ( $type ) { 
  969. case 'all': 
  970. $access = true; 
  971. break; 
  972.  
  973. case 'loggedin': 
  974. case 'login': 
  975. $access = in_array( $user_type, array( 'loggedin', 'admin' ) ); 
  976. break; 
  977.  
  978. case 'guest': 
  979. $access = ($user_type == 'guest' ); 
  980. break; 
  981.  
  982. case 'admin': 
  983. $access = ( $user_type == 'admin' ); 
  984. break; 
  985.  
  986. case 'non-admin': 
  987. $access = ( $user_type != 'admin' ); 
  988. break; 
  989.  
  990. if ( ! $access ) { 
  991. $content = $msg; 
  992. $class .= ' ms-user-not-' . $type; 
  993.  
  994. $content = sprintf( 
  995. '<div class="ms-user %1$s">%2$s</div>',  
  996. esc_attr( $class ),  
  997. do_shortcode( $content ) 
  998. ); 
  999.  
  1000. return apply_filters( 
  1001. 'ms_controller_shortcode_show_to_user',  
  1002. $content,  
  1003. $this 
  1004. ); 
  1005.  
  1006. /** 
  1007. * Shortcode callback: Show member infos. 
  1008. * 
  1009. * @since 1.0.0 
  1010. * 
  1011. * @param mixed[] $atts Shortcode attributes. 
  1012. */ 
  1013. public function ms_member_info( $atts, $content = '' ) { 
  1014. MS_Helper_Shortcode::did_shortcode( MS_Helper_Shortcode::SCODE_MEMBER_INFO ); 
  1015.  
  1016. $data = apply_filters( 
  1017. 'ms_controller_shortcode_member_info_atts',  
  1018. shortcode_atts( 
  1019. array( 
  1020. 'value' => 'fullname',  
  1021. 'before' => '<span>',  
  1022. 'after' => '</span>',  
  1023. 'default' => '',  
  1024. 'custom_field' => '', // used for: custom 
  1025. 'list_before' => '', // used for: membership 
  1026. 'list_after' => '', // used for: membership 
  1027. 'list_separator' => ', ', // used for: membership 
  1028. 'user' => 0, // user-id; 0 = current user 
  1029. ),  
  1030. $atts 
  1031. ); 
  1032.  
  1033. $data['user'] = intval( $data['user'] ); 
  1034. if ( $data['user'] < 1 ) { 
  1035. $data['user'] = get_current_user_id(); 
  1036. $member = MS_Factory::load( 'MS_Model_Member', $data['user'] ); 
  1037. $content = ''; 
  1038.  
  1039. switch ( $data['value'] ) { 
  1040. case 'email': 
  1041. $content = $member->email; 
  1042. break; 
  1043.  
  1044. case 'firstname': 
  1045. case 'first name': 
  1046. $content = $member->first_name; 
  1047. break; 
  1048.  
  1049. case 'lastname': 
  1050. case 'last name': 
  1051. $content = $member->last_name; 
  1052. break; 
  1053.  
  1054. case 'fullname': 
  1055. case 'full name': 
  1056. $content = $member->first_name . ' ' . $member->last_name; 
  1057. break; 
  1058.  
  1059. case 'memberships': 
  1060. case 'membership': 
  1061. $ids = $member->get_membership_ids(); 
  1062. $content = array(); 
  1063. foreach ( $ids as $id ) { 
  1064. $membership = MS_Factory::load( 'MS_Model_Membership', $id ); 
  1065. if ( $membership->is_system() ) { continue; } 
  1066. $content[] = $membership->name; 
  1067. break; 
  1068.  
  1069. case 'custom': 
  1070. $content = $member->get_custom_data( $data['custom_field'] ); 
  1071. break; 
  1072.  
  1073. if ( is_array( $content ) ) { 
  1074. if ( $content ) { 
  1075. $content = 
  1076. $data['list_before'] . 
  1077. implode( $data['list_separator'], $content ) . 
  1078. $data['list_after']; 
  1079. } else { 
  1080. $content = ''; 
  1081. } else { 
  1082. $content = (string) $content; 
  1083.  
  1084. $content = trim( $content ); 
  1085. if ( $content ) { 
  1086. $content = $data['before'] . 
  1087. $content . 
  1088. $data['after']; 
  1089. } else { 
  1090. $content = $data['default']; 
  1091.  
  1092. return apply_filters( 
  1093. 'ms_controller_shortcode_member_info',  
  1094. $content,  
  1095. $this 
  1096. ); 
  1097.  
  1098.  
  1099. /** 
  1100. * Special Shortcode Callback: Replace shortcodes with empty value. 
  1101. * 
  1102. * All Shortcodes use this callback function 
  1103. * when Content Protection is DISABLED! 
  1104. * 
  1105. * @since 1.0.0 
  1106. * @param mixed[] $atts Shortcode attributes. 
  1107. * @param string $content 
  1108. * @return string 
  1109. */ 
  1110. public function ms_no_value( $atts, $content = '' ) { 
  1111. static $Done = false; 
  1112.  
  1113. if ( $Done ) { return ''; } 
  1114. $Done = true; 
  1115.  
  1116. if ( MS_Model_Member::is_admin_user() ) { 
  1117. $content = sprintf( 
  1118. '<p class="ms-alert-box ms-alert-error ms-unprotected">%s<br /><br /><em>(%s)</em></p>',  
  1119. __( 
  1120. 'Content Protection is disabled. Please enable the protection to see this shortcode.',  
  1121. 'membership2' 
  1122. ),  
  1123. __( 
  1124. 'This message is only displayed to Site Administrators',  
  1125. 'membership2' 
  1126. ); 
  1127. } else { 
  1128. $content = ''; 
  1129.  
  1130. return apply_filters( 
  1131. 'ms_controller_shortcode_ms_no_value',  
  1132. $content,  
  1133. $this 
  1134. ); 
  1135.  
  1136. /** 
  1137. * Special Shortcode Callback: Strip the shortcode tag without changing the 
  1138. * original content. 
  1139. * 
  1140. * This is used for Admin users to strip all content-protection tags. 
  1141. * 
  1142. * @since 1.0.0 
  1143. * @param mixed[] $atts Shortcode attributes. 
  1144. * @param string $content 
  1145. * @return string 
  1146. */ 
  1147. public function hide_shortcode( $atts, $content = '' ) { 
  1148. return do_shortcode( $content ); 
  1149.  
.