MS_Controller_Shortcode

Controller for managing Plugin Shortcodes.

Defined (1)

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

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