/app_old/membershipincludes/classes/membershippublic.php

  1. <?php 
  2. if(!class_exists('membershippublic')) { 
  3.  
  4. class membershippublic { 
  5.  
  6. var $build = 2; 
  7.  
  8. var $db; 
  9.  
  10. var $tables = array('membership_levels', 'membership_rules', 'subscriptions', 'subscriptions_levels', 'membership_relationships'); 
  11.  
  12. var $membership_levels; 
  13. var $membership_rules; 
  14. var $membership_relationships; 
  15. var $subscriptions; 
  16. var $subscriptions_levels; 
  17.  
  18. function __construct() { 
  19.  
  20. global $wpdb; 
  21.  
  22. $this->db =& $wpdb; 
  23.  
  24. foreach($this->tables as $table) { 
  25. $this->$table = membership_db_prefix($this->db, $table); 
  26.  
  27. add_action('plugins_loaded', array(&$this, 'load_textdomain')); 
  28.  
  29. // Set up Actions 
  30. add_action('init', array(&$this, 'initialise_plugin'), 1 ); 
  31. add_filter('query_vars', array(&$this, 'add_queryvars') ); 
  32. add_action('generate_rewrite_rules', array(&$this, 'add_rewrites') ); 
  33.  
  34. // Add protection 
  35. add_action('parse_request', array(&$this, 'initialise_membership_protection'), 2 ); 
  36. // Download protection 
  37. add_action('pre_get_posts', array(&$this, 'handle_download_protection'), 3 ); 
  38.  
  39. // Payment return 
  40. add_action('pre_get_posts', array(&$this, 'handle_paymentgateways'), 1 ); 
  41.  
  42. // add feed protection 
  43. add_filter('feed_link', array(&$this, 'add_feed_key'), 99, 2); 
  44.  
  45. // Register 
  46. add_filter('register', array(&$this, 'override_register') ); 
  47.  
  48. // Ultimate Facebook Compatibility 
  49. add_filter( 'wdfb_registration_redirect_url', array(&$this, 'wdfb_registration_redirect_url') ); 
  50.  
  51. // Level shortcodes filters 
  52. add_filter( 'membership_level_shortcodes', array(&$this, 'build_level_shortcode_list' ) ); 
  53. add_filter( 'membership_not_level_shortcodes', array(&$this, 'build_not_level_shortcode_list' ) ); 
  54.  
  55.  
  56. function wdfb_registration_redirect_url($url) { 
  57. global $M_options; 
  58. $url = get_permalink($M_options['registration_page']); 
  59. return $url; 
  60.  
  61. function membershippublic() { 
  62. $this->__construct(); 
  63.  
  64. function load_textdomain() { 
  65.  
  66. $locale = apply_filters( 'membership_locale', get_locale() ); 
  67. $mofile = membership_dir( "membershipincludes/languages/membership-$locale.mo" ); 
  68.  
  69. if ( file_exists( $mofile ) ) 
  70. load_textdomain( 'membership', $mofile ); 
  71.  
  72.  
  73. function initialise_plugin() { 
  74.  
  75. global $user, $member, $M_options, $M_Rules, $wp_query, $wp_rewrite, $M_active, $bp; 
  76.  
  77. if(defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true ) { 
  78. if(function_exists('get_blog_option')) { 
  79. $M_options = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', array()); 
  80. } else { 
  81. $M_options = get_option('membership_options', array()); 
  82. } else { 
  83. $M_options = get_option('membership_options', array()); 
  84.  
  85. // Check if the membership plugin is active 
  86. $M_active = M_get_membership_active(); 
  87.  
  88. // Create our subscription page shortcode 
  89. add_shortcode('subscriptionform', array(&$this, 'do_subscription_shortcode') ); 
  90. add_shortcode('accountform', array(&$this, 'do_account_shortcode') ); 
  91. add_shortcode('upgradeform', array(&$this, 'do_upgrade_shortcode') ); 
  92. add_shortcode('renewform', array(&$this, 'do_renew_shortcode') ); 
  93.  
  94. // Moved extra shortcodes over to the main plugin for new registration forms 
  95. add_shortcode('subscriptiontitle', array(&$this, 'do_subscriptiontitle_shortcode') ); 
  96. add_shortcode('subscriptiondetails', array(&$this, 'do_subscriptiondetails_shortcode') ); 
  97. add_shortcode('subscriptionprice', array(&$this, 'do_subscriptionprice_shortcode') ); 
  98. add_shortcode('subscriptionbutton', array(&$this, 'do_subscriptionbutton_shortcode') ); 
  99.  
  100. do_action('membership_register_shortcodes'); 
  101.  
  102. // Check if we are on a membership specific page 
  103. add_filter('the_posts', array(&$this, 'check_for_membership_pages'), 1); 
  104. // Check for subscription shortcodes - and if needed queue styles 
  105. add_filter('the_posts', array(&$this, 'add_subscription_styles')); 
  106.  
  107. $user = wp_get_current_user(); 
  108. if(!method_exists($user, 'has_cap') || $user->has_cap('membershipadmin') || $M_active == 'no') { 
  109. // Admins can see everything 
  110. return; 
  111.  
  112. if( $M_active == 'no' ) { 
  113. // The plugin isn't active so just return 
  114. return; 
  115.  
  116. if(!method_exists($user, 'has_cap') || $user->has_cap('membershipadmin')) { 
  117. // Admins can see everything - unless we have a cookie set to limit viewing 
  118. if(empty($_COOKIE['membershipuselevel']) || $_COOKIE['membershipuselevel'] == '0') { 
  119. return; 
  120.  
  121. // More tags 
  122. if( isset($M_options['moretagdefault']) && $M_options['moretagdefault'] == 'no' ) { 
  123. // More tag content is not visible by default - works for both web and rss content - unfortunately 
  124. add_filter('the_content_more_link', array(&$this, 'show_moretag_protection'), 99, 2); 
  125. add_filter('the_content', array(&$this, 'replace_moretag_content'), 1); 
  126. add_filter('the_content_feed', array(&$this, 'replace_moretag_content'), 1); 
  127.  
  128. // Shortcodes setup 
  129. if(!empty($M_options['membershipshortcodes'])) { 
  130. foreach($M_options['membershipshortcodes'] as $key => $value) { 
  131. if(!empty($value)) { 
  132. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_membership_shortcode') ); 
  133.  
  134. // Shortcodes now default to protected for those entered by the user (which will be none for new users / installs) 
  135. $this->override_shortcodes(); 
  136.  
  137. // Downloads protection 
  138. if(!empty($M_options['membershipdownloadgroups'])) { 
  139. add_filter('the_content', array(&$this, 'protect_download_content') ); 
  140.  
  141. // Makes sure that despite other rules, the pages set in the options panel are available to the user 
  142. add_action('pre_get_posts', array(&$this, 'ensure_option_pages_visible'), 999 ); 
  143. // check for a no-access page and always filter it if needed 
  144. if(!empty($M_options['nocontent_page']) && $M_options['nocontent_page'] != $M_options['registration_page']) { 
  145. add_filter('get_pages', array(&$this, 'hide_nocontent_page_from_menu'), 99); 
  146.  
  147. // New registration form settings 
  148. if( (isset($M_options['formtype']) && $M_options['formtype'] == 'new') ) { 
  149. add_action( 'wp_ajax_nopriv_buynow', array(&$this, 'popover_signup_form') ); 
  150.  
  151. //login and register are no-priv only because, well they aren't logged in or registered 
  152. add_action( 'wp_ajax_nopriv_register_user', array(&$this, 'popover_register_process') ); 
  153. add_action( 'wp_ajax_nopriv_login_user', array(&$this, 'popover_login_process') ); 
  154.  
  155. // if logged in: 
  156. add_action( 'wp_ajax_buynow', array(&$this, 'popover_sendpayment_form') ); 
  157. add_action( 'wp_ajax_register_user', array(&$this, 'popover_register_process') ); 
  158. add_action( 'wp_ajax_login_user', array(&$this, 'popover_login_process') ); 
  159.  
  160.  
  161. function add_queryvars($vars) { 
  162.  
  163. if(!in_array('feedkey', $vars)) $vars[] = 'feedkey'; 
  164. if(!in_array('protectedfile', $vars)) $vars[] = 'protectedfile'; 
  165. if(!in_array('paymentgateway', $vars)) $vars[] = 'paymentgateway'; 
  166.  
  167. return $vars; 
  168.  
  169. function add_rewrites($wp_rewrite) { 
  170.  
  171. global $M_options; 
  172.  
  173. // This function adds in the api rewrite rules 
  174. // Note the addition of the namespace variable so that we know these are vent based 
  175. // calls 
  176.  
  177. $new_rules = array(); 
  178.  
  179. if(!empty($M_options['masked_url'])) { 
  180. $new_rules[trailingslashit($M_options['masked_url']) . '(.*)'] = 'index.php?protectedfile=' . $wp_rewrite->preg_index(1); 
  181.  
  182. $new_rules['paymentreturn/(.+)'] = 'index.php?paymentgateway=' . $wp_rewrite->preg_index(1); 
  183.  
  184. $new_rules = apply_filters('M_rewrite_rules', $new_rules); 
  185.  
  186. $wp_rewrite->rules = array_merge($new_rules, $wp_rewrite->rules); 
  187.  
  188. return $wp_rewrite; 
  189.  
  190. function override_register( $link ) { 
  191.  
  192. global $M_options; 
  193.  
  194. if ( ! is_user_logged_in() ) { 
  195. if ( get_option('users_can_register') ) { 
  196. // get the new registration stuff. 
  197. if(!empty($M_options['registration_page'])) { 
  198. $url = get_permalink( $M_options['registration_page'] ); 
  199. $link = preg_replace('/<a href(.+)a>/', '<a href="' . $url . '">' . __('Register', 'membership') . '</a>', $link); 
  200.  
  201. } else { 
  202. // change to account page? 
  203. if(!empty($M_options['account_page'])) { 
  204. $url = get_permalink( $M_options['account_page'] ); 
  205. $link = preg_replace('/<a href(.+)a>/', '<a href="' . $url . '">' . __('My Account', 'membership') . '</a>', $link); 
  206.  
  207. return $link; 
  208.  
  209. function add_feed_key( $output, $feed ) { 
  210. global $user; 
  211.  
  212. if(empty($user) || !method_exists($user, 'has_cap')) { 
  213. $user = wp_get_current_user(); 
  214.  
  215. if($user->ID > 0) { 
  216.  
  217. $member = new M_Membership($user->ID); 
  218.  
  219. if($member->is_member()) { 
  220. $key = get_user_meta($user->ID, '_membership_key', true); 
  221.  
  222. if(empty($key)) { 
  223. $key = md5($user->ID . $user->user_pass . time()); 
  224. update_user_meta($user->ID, '_membership_key', $key); 
  225.  
  226. if(!empty($key)) { 
  227. $output = add_query_arg('k', $key, untrailingslashit($output)); 
  228.  
  229.  
  230. return $output; 
  231.  
  232.  
  233. function initialise_membership_protection($wp) { 
  234.  
  235. global $user, $member, $M_options, $M_Rules, $wp_query, $wp_rewrite, $M_active; 
  236. // Set up some common defaults 
  237.  
  238. static $initialised = false; 
  239.  
  240. if($initialised) { 
  241. // ensure that this is only called once, so return if we've been here already. 
  242. return; 
  243.  
  244. if(empty($user) || !method_exists($user, 'has_cap')) { 
  245. $user = wp_get_current_user(); 
  246.  
  247. if( $M_active == 'no' ) { 
  248. // The plugin isn't active so just return 
  249. return; 
  250.  
  251. if(!method_exists($user, 'has_cap') || $user->has_cap('membershipadmin')) { 
  252. // Admins can see everything - unless we have a cookie set to limit viewing 
  253. if(!empty($_COOKIE['membershipuselevel']) && $_COOKIE['membershipuselevel'] != '0') { 
  254.  
  255. $level_id = (int) $_COOKIE['membershipuselevel']; 
  256.  
  257. $member = new M_Membership($user->ID); 
  258. $member->assign_level( $level_id, true ); 
  259. } else { 
  260. return; 
  261. } else { 
  262. // We are not a membershipadmin user 
  263. if(!empty($wp->query_vars['feed'])) { 
  264. // This is a feed access 
  265. // Set the feed rules 
  266. if(isset($_GET['k'])) { 
  267. $key = $_GET['k']; 
  268.  
  269. $user_id = $this->find_user_from_key($key); 
  270. $user_id = (int) $user_id; 
  271. if($user_id > 0) { 
  272. // Logged in - check there settings, if they have any. 
  273. $member = new M_Membership($user_id); 
  274. // Load the levels for this member - and associated rules 
  275. $member->load_levels( true ); 
  276. } else { 
  277. $member = new M_Membership(false); 
  278. if(isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) { 
  279. $member->assign_level($M_options['strangerlevel'], true ); 
  280. } else { 
  281. // This user can't access anything on the site - show a blank feed. 
  282. add_filter('the_posts', array(&$this, 'show_noaccess_feed'), 1 ); 
  283.  
  284. } else { 
  285. // not passing a key so limit based on stranger settings 
  286. // need to grab the stranger settings 
  287. $member = new M_Membership($user->ID); 
  288. if(isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) { 
  289. $member->assign_level($M_options['strangerlevel'], true ); 
  290. } else { 
  291. // This user can't access anything on the site - show a blank feed. 
  292. add_filter('the_posts', array(&$this, 'show_noaccess_feed'), 1 ); 
  293. } else { 
  294. // Users 
  295. $member = new M_Membership($user->ID); 
  296.  
  297. if($user->ID > 0 && $member->has_levels()) { 
  298. // Load the levels for this member - and associated rules 
  299. $member->load_levels( true ); 
  300. } else { 
  301. // not logged in so limit based on stranger settings 
  302. // need to grab the stranger settings 
  303. if(isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) { 
  304. $member->assign_level( $M_options['strangerlevel'], true ); 
  305. } else { 
  306. // This user can't access anything on the site - . 
  307. add_filter('comments_open', array(&$this, 'close_comments'), 99, 2); 
  308. // Changed for this version to see if it helps to get around changed in WP 3.5 
  309. //add_action('pre_get_posts', array(&$this, 'show_noaccess_page'), 1 ); 
  310. add_action('the_posts', array(&$this, 'show_noaccess_page'), 1 ); 
  311. //the_posts 
  312. // Hide all pages from menus - except the signup one 
  313. add_filter('get_pages', array(&$this, 'remove_pages_menu')); 
  314. // Hide all categories from lists 
  315. add_filter( 'get_terms', array(&$this, 'remove_categories'), 1, 3 ); 
  316.  
  317. // Set up the level shortcodes here 
  318. $shortcodes = apply_filters('membership_level_shortcodes', array() ); 
  319. if(!empty($shortcodes)) { 
  320. foreach($shortcodes as $key => $value) { 
  321. if(!empty($value)) { 
  322. if($member->has_level($key)) { 
  323. // member is on this level so can see the content 
  324. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_level_shortcode') ); 
  325. } else { 
  326. // member isn't on this level and so can't see the content 
  327. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_levelprotected_shortcode') ); 
  328.  
  329. $shortcodes = apply_filters('membership_not_level_shortcodes', array() ); 
  330. if(!empty($shortcodes)) { 
  331. foreach($shortcodes as $key => $value) { 
  332. if(!empty($value)) { 
  333. if(!$member->has_level($key)) { 
  334. // member is on this level so can see the content 
  335. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_level_shortcode') ); 
  336. } else { 
  337. // member isn't on this level and so can't see the content 
  338. add_shortcode(stripslashes(trim($value)), array(&$this, 'do_levelprotected_shortcode') ); 
  339.  
  340. do_action('membership-add-shortcodes'); 
  341.  
  342. // Set the initialisation status 
  343. $initialised = true; 
  344.  
  345.  
  346. function remove_categories($terms, $taxonomies, $args) { 
  347.  
  348. foreach( (array) $terms as $key => $value ) { 
  349. if($value->taxonomy == 'category') { 
  350. unset($terms[$key]); 
  351.  
  352. return $terms; 
  353.  
  354. function remove_pages_menu($pages) { 
  355.  
  356. global $M_options; 
  357.  
  358. foreach( (array) $pages as $key => $page ) { 
  359. if(!empty($M_options['registration_page']) && $page->ID == $M_options['registration_page']) { 
  360. // We want to keep this page available 
  361. } else { 
  362. unset($pages[$key]); 
  363.  
  364. return $pages; 
  365.  
  366. function handle_paymentgateways($wp_query) { 
  367. if(!empty($wp_query->query_vars['paymentgateway'])) { 
  368. do_action( 'membership_process_payment_return', $wp_query->query_vars['paymentgateway'] ); 
  369. // exit(); 
  370.  
  371. function handle_download_protection($wp_query) { 
  372.  
  373. global $user, $member, $wpdb, $M_options; 
  374.  
  375. if(!empty($wp_query->query_vars['protectedfile'])) { 
  376. $protected = explode("/", $wp_query->query_vars['protectedfile']); 
  377. $protected = array_pop( $protected ); 
  378.  
  379. if(empty($protected) && !empty($_GET['file'])) { 
  380. $protected = $_GET['file']; 
  381.  
  382. if(!empty($protected)) { 
  383. // See if the filename has a size extension and if so, strip it out 
  384. $filename_exp = '/(.+)\-(\d+[x]\d+)\.(.+)$/'; 
  385. $filematch = array(); 
  386. if(preg_match($filename_exp, $protected, $filematch)) { 
  387. // We have an image with an image size attached 
  388. $newfile = $filematch[1] . "." . $filematch[3]; 
  389. $size_extension = "-" . $filematch[2]; 
  390. } else { 
  391. $newfile = $protected; 
  392. $size_extension = ''; 
  393. // Process based on the protection type 
  394. switch($M_options['protection_type']) { 
  395. case 'complete' : // Work out the post_id again 
  396. $post_id = preg_replace('/^' . MEMBERSHIP_FILE_NAME_PREFIX . '/', '', $newfile); 
  397. $post_id -= (INT) MEMBERSHIP_FILE_NAME_INCREMENT; 
  398.  
  399. if(is_numeric($post_id) && $post_id > 0) { 
  400. $image = get_post_meta($post_id, '_wp_attached_file', true); 
  401. if(!empty($size_extension)) { 
  402. // Add back in a size extension if we need to 
  403. $image = str_replace( '.' . pathinfo($image, PATHINFO_EXTENSION), $size_extension . '.' . pathinfo($image, PATHINFO_EXTENSION), $image ); 
  404. // hack to remove any double extensions :/ need to change when work out a neater way 
  405. $image = str_replace( $size_extension . $size_extension, $size_extension, $image ); 
  406. break; 
  407.  
  408. case 'hybrid' : // Work out the post_id again 
  409.  
  410. $post_id = preg_replace('/^' . MEMBERSHIP_FILE_NAME_PREFIX . '/', '', $newfile); 
  411. $post_id -= (INT) MEMBERSHIP_FILE_NAME_INCREMENT; 
  412.  
  413. if(is_numeric($post_id) && $post_id > 0) { 
  414. $image = get_post_meta($post_id, '_wp_attached_file', true); 
  415. if(!empty($size_extension)) { 
  416. // Add back in a size extension if we need to 
  417. $image = str_replace( '.' . pathinfo($image, PATHINFO_EXTENSION), $size_extension . '.' . pathinfo($image, PATHINFO_EXTENSION), $image ); 
  418. // hack to remove any double extensions :/ need to change when work out a neater way 
  419. $image = str_replace( $size_extension . $size_extension, $size_extension, $image ); 
  420. break; 
  421.  
  422. case 'basic' : 
  423. default: // The basic protection - need to change this 
  424. $sql = $this->db->prepare( "SELECT post_id FROM {$this->db->postmeta} WHERE meta_key = '_wp_attached_file' AND meta_value LIKE %s", '%' . $newfile . '%' ); 
  425. $post_id = $wpdb->get_var( $sql ); 
  426.  
  427. if(empty($post_id)) { 
  428. // Can't find the file in the first pass, try the second pass. 
  429. $sql = $this->db->prepare( "SELECT post_id FROM {$this->db->postmeta} WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s", '%' . $protected . '%'); 
  430. $post_id = $this->db->get_var( $sql ); 
  431.  
  432. if(is_numeric($post_id) && $post_id > 0) { 
  433. $image = get_post_meta($post_id, '_wp_attached_file', true); 
  434. if(!empty($size_extension)) { 
  435. // Add back in a size extension if we need to 
  436. $image = str_replace( '.' . pathinfo($image, PATHINFO_EXTENSION), $size_extension . '.' . pathinfo($image, PATHINFO_EXTENSION), $image ); 
  437. // hack to remove any double extensions :/ need to change when work out a neater way 
  438. $image = str_replace( $size_extension . $size_extension, $size_extension, $image ); 
  439. break; 
  440.  
  441.  
  442. if(!empty($image) && !empty($post_id) && is_numeric($post_id)) { 
  443. // check for protection 
  444. $group = get_post_meta($post_id, '_membership_protected_content_group', true); 
  445.  
  446. if(empty($group) || $group == 'no') { 
  447. // it's not protected so grab and display it 
  448. //$file = $wp_query->query_vars['protectedfile']; 
  449. $this->output_file($image); 
  450. } else { 
  451. // check we can see it 
  452. if(empty($member) || !method_exists($member, 'has_level_rule')) { 
  453. $user = wp_get_current_user(); 
  454. $member = new M_Membership( $user->ID ); 
  455.  
  456. if( method_exists($member, 'has_level_rule') && $member->has_level_rule('downloads') && $member->pass_thru( 'downloads', array( 'can_view_download' => $group ) ) ) { 
  457. //$file = $wp_query->query_vars['protectedfile']; 
  458. $this->output_file($image); 
  459. } else { 
  460. $this->show_noaccess_image($wp_query); 
  461. } else { 
  462. // We haven't found anything so default to the no access image 
  463. $this->show_noaccess_image($wp_query); 
  464.  
  465. exit(); 
  466.  
  467.  
  468. function output_file($pathtofile) { 
  469.  
  470. global $wpdb, $M_options; 
  471.  
  472. // The directory and direct path dir 
  473. $uploadpath = membership_wp_upload_dir(); 
  474. $file = trailingslashit($uploadpath) . $pathtofile; 
  475. // The url and direct url 
  476. $origpath = membership_upload_url(); 
  477. $trueurl = trailingslashit($origpath) . $pathtofile; 
  478.  
  479. if ( !is_file( $file ) ) { 
  480. status_header( 404 ); 
  481. die( '404 — File not found.' ); 
  482.  
  483. $mime = wp_check_filetype( $file ); 
  484. if( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) ) 
  485. $mime[ 'type' ] = mime_content_type( $file ); 
  486.  
  487. if( $mime[ 'type' ] ) 
  488. $mimetype = $mime[ 'type' ]; 
  489. else 
  490. $mimetype = 'image/' . substr( $trueurl, strrpos( $trueurl, '.' ) + 1 ); 
  491.  
  492. header( 'Content-type: ' . $mimetype ); // always send this 
  493. if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) 
  494. header( 'Content-Length: ' . filesize( $file ) ); 
  495.  
  496. $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ); 
  497. $etag = '"' . md5( $last_modified ) . '"'; 
  498. header( "Last-Modified: $last_modified GMT" ); 
  499. header( 'ETag: ' . $etag ); 
  500. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' ); 
  501.  
  502. // Support for Conditional GET 
  503. $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false; 
  504.  
  505. if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) 
  506. $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; 
  507.  
  508. $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); 
  509. // If string is empty, return 0. If not, attempt to parse into a timestamp 
  510. $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; 
  511.  
  512. // Make a timestamp for our most recent modification... 
  513. $modified_timestamp = strtotime($last_modified); 
  514.  
  515. if ( ( $client_last_modified && $client_etag ) 
  516. ? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) ) 
  517. : ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) ) 
  518. ) { 
  519. status_header( 304 ); 
  520. exit; 
  521.  
  522. // If we made it this far, just serve the file 
  523. readfile( $file ); 
  524.  
  525. function show_noaccess_image($wp_query) { 
  526.  
  527. $locale = apply_filters( 'membership_locale', get_locale() ); 
  528. if(file_exists(membership_dir( "membershipincludes/images/noaccess/noaccess-$locale.png" ))) { 
  529. $file = membership_dir( "membershipincludes/images/noaccess/noaccess-$locale.png" ); 
  530. $trueurl = membership_url( "membershipincludes/images/noaccess/noaccess-$locale.png" ); 
  531. } elseif( file_exists(membership_dir( "membershipincludes/images/noaccess/noaccess.png" )) ) { 
  532. $file = membership_dir( "membershipincludes/images/noaccess/noaccess.png" ); 
  533. $trueurl = membership_url( "membershipincludes/images/noaccess/noaccess.png" ); 
  534.  
  535.  
  536. if(!empty($file)) { 
  537. if ( !is_file( $file ) ) { 
  538. status_header( 404 ); 
  539. die( '404 — File not found.' ); 
  540.  
  541. $mime = wp_check_filetype( $file ); 
  542. if( false === $mime[ 'type' ] && function_exists( 'mime_content_type' ) ) 
  543. $mime[ 'type' ] = mime_content_type( $file ); 
  544.  
  545. if( $mime[ 'type' ] ) 
  546. $mimetype = $mime[ 'type' ]; 
  547. else 
  548. $mimetype = 'image/' . substr( $trueurl, strrpos( $trueurl, '.' ) + 1 ); 
  549.  
  550. header( 'Content-type: ' . $mimetype ); // always send this 
  551. if ( false === strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS' ) ) 
  552. header( 'Content-Length: ' . filesize( $file ) ); 
  553.  
  554. $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ); 
  555. $etag = '"' . md5( $last_modified ) . '"'; 
  556. header( "Last-Modified: $last_modified GMT" ); 
  557. header( 'ETag: ' . $etag ); 
  558. header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' ); 
  559.  
  560. // Support for Conditional GET 
  561. $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false; 
  562.  
  563. if( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) 
  564. $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; 
  565.  
  566. $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); 
  567. // If string is empty, return 0. If not, attempt to parse into a timestamp 
  568. $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; 
  569.  
  570. // Make a timestamp for our most recent modification... 
  571. $modified_timestamp = strtotime($last_modified); 
  572.  
  573. if ( ( $client_last_modified && $client_etag ) 
  574. ? ( ( $client_modified_timestamp >= $modified_timestamp) && ( $client_etag == $etag ) ) 
  575. : ( ( $client_modified_timestamp >= $modified_timestamp) || ( $client_etag == $etag ) ) 
  576. ) { 
  577. status_header( 304 ); 
  578. exit; 
  579.  
  580. // If we made it this far, just serve the file 
  581. readfile( $file ); 
  582.  
  583.  
  584. function find_user_from_key($key = false) { 
  585.  
  586. global $wpdb; 
  587.  
  588. //$key = get_usermeta($user->ID, '_membership_key'); 
  589. $sql = $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 0, 1", '_membership_key', $key ); 
  590.  
  591. $user_id = $wpdb->get_var($sql); 
  592.  
  593. return $user_id; 
  594.  
  595.  
  596. // loop and page overrides 
  597.  
  598. function show_moretag_protection($more_tag_link, $more_tag) { 
  599.  
  600. global $M_options; 
  601.  
  602. return stripslashes($M_options['moretagmessage']); 
  603.  
  604.  
  605. function replace_moretag_content($the_content) { 
  606.  
  607. global $M_options; 
  608.  
  609. $morestartsat = strpos($the_content, '<span id="more-'); 
  610.  
  611. if($morestartsat !== false) { 
  612. $the_content = substr($the_content, 0, $morestartsat); 
  613. $the_content .= stripslashes($M_options['moretagmessage']); 
  614.  
  615. return $the_content; 
  616.  
  617.  
  618. // Output the level based shortcode content 
  619. function do_level_shortcode($atts, $content = null, $code = "") { 
  620.  
  621. return do_shortcode($content); 
  622.  
  623.  
  624. // Output the protected shortcode content 
  625. function do_membership_shortcode($atts, $content = null, $code = "") { 
  626.  
  627. return do_shortcode($content); 
  628.  
  629.  
  630. // Show the protected shortcode message 
  631. function do_protected_shortcode($atts, $content = null, $code = "") { 
  632.  
  633. global $M_options; 
  634.  
  635. return stripslashes($M_options['shortcodemessage']); 
  636.  
  637.  
  638. // Show the level based protected shortcode message 
  639. function do_levelprotected_shortcode($atts, $content = null, $code = "") { 
  640.  
  641. global $M_options; 
  642.  
  643. // Set up the level shortcodes here 
  644. $shortcodes = apply_filters('membership_level_shortcodes', array() ); 
  645. $notshortcodes = apply_filters('membership_not_level_shortcodes', array() ); 
  646.  
  647. $code = strtolower( $code ); 
  648.  
  649. if( substr( $code, 0, 4 ) !== "not-" ) { 
  650. if(!empty($shortcodes)) { 
  651. // search positive shortcodes first 
  652. $id = array_search( $code, $shortcodes ); 
  653. if($id !== false) { 
  654. // we have found a level so we need to check if it has a custom protected message, otherwise we'll just output the default main on 
  655. $level = new M_Level( $id ); 
  656. $message = $level->get_meta( 'level_protectedcontent' ); 
  657. if(!empty($message)) { 
  658. return stripslashes($message); 
  659. } else { 
  660. if(!empty($notshortcodes)) { 
  661. // search positive shortcodes first 
  662. $id = array_search( $code, $notshortcodes ); 
  663. if($id !== false) { 
  664. // we have found a level so we need to check if it has a custom protected message, otherwise we'll just output the default main on 
  665. $level = new M_Level( $id ); 
  666. $message = $level->get_meta( 'level_protectedcontent' ); 
  667. if(!empty($message)) { 
  668. return stripslashes($message); 
  669.  
  670. // If we are here then we have no custom message, or the shortcode wasn't found so just output the standard message 
  671. if(isset($M_options['shortcodemessage'])) { 
  672. return stripslashes( do_shortcode($M_options['shortcodemessage'])); 
  673. } else { 
  674. return ''; 
  675.  
  676.  
  677.  
  678.  
  679. function override_shortcodes() { 
  680. // By default all the shortcodes are protected to override them here 
  681. global $M_shortcode_tags, $shortcode_tags; 
  682.  
  683. $M_shortcode_tags = $shortcode_tags; 
  684.  
  685. if(!empty($M_options['membershipshortcodes'])) { 
  686. foreach($M_options['membershipshortcodes'] as $key => $value) { 
  687. if(!empty($value)) { 
  688. $shortcode_tags[$value] = array(&$this, 'do_protected_shortcode'); 
  689.  
  690.  
  691. function may_be_singular($wp_query) { 
  692.  
  693. if( is_archive() || is_author() || is_category() || is_tag() || is_tax() || is_search() ) { 
  694. return false; 
  695. } else { 
  696. return true; 
  697.  
  698.  
  699. function check_for_posts_existance($posts, $wp_query) { 
  700.  
  701. global $bp, $wp_query; 
  702.  
  703. if(!empty($bp)) { 
  704. // BuddyPress exists so we have to handle "pretend" pages. 
  705. $thepage = substr($wp_query->query['pagename'], 0 , strpos($wp_query->query['pagename'], '/')); 
  706. if(empty($thepage)) $thepage = $wp_query->query['pagename']; 
  707.  
  708. $bppages = apply_filters('membership_buddypress_pages', (array) $bp->root_components ); 
  709.  
  710. if(in_array($thepage, $bppages)) { 
  711. return $posts; 
  712.  
  713. $M_options = get_option('membership_options', array()); 
  714.  
  715. if(empty($posts)) { 
  716.  
  717. if( !empty( $wp_query->query['pagename'] )) { 
  718. // we have a potentially fake page that a plugin is creating or using. 
  719. if( !in_array( $wp_query->query['pagename'], apply_filters( 'membership_notallowed_pagenames', array() ) ) ) { 
  720. return $posts; 
  721. } else { 
  722. $this->show_noaccess_page($wp_query); 
  723. } else { 
  724.  
  725. if($M_options['override_404'] == 'yes') { 
  726.  
  727. // empty posts 
  728. $this->show_noaccess_page($wp_query); 
  729. } else { 
  730. return $posts; 
  731.  
  732. if($this->posts_actually_exist() && $this->may_be_singular($wp_query)) { 
  733. // we have nothing to see because it either doesn't exist, is a pretend or it's protected - move to no access page. 
  734. $this->show_noaccess_page($wp_query); 
  735. } else { 
  736. return $posts; 
  737.  
  738.  
  739. return $posts; 
  740.  
  741.  
  742. function posts_actually_exist() { 
  743.  
  744. $sql = $this->db->prepare( "SELECT count(*) FROM {$this->db->posts} WHERE post_type = %s AND post_status = %s", 'post', 'publish' ); 
  745.  
  746. if($this->db->get_var( $sql ) > 0) { 
  747. return true; 
  748. } else { 
  749. return false; 
  750.  
  751.  
  752. function show_noaccess_feed($wp_query) { 
  753.  
  754. global $M_options; 
  755.  
  756. //$wp_query->query_vars['post__in'] = array(0); 
  757. /** 
  758. * What we are going to do here, is create a fake post. A post 
  759. * that doesn't actually exist. We're gonna fill it up with 
  760. * whatever values you want. The content of the post will be 
  761. * the output from your plugin. The questions and answers. 
  762. */ 
  763.  
  764. if(!empty($M_options['nocontent_page'])) { 
  765. // grab the content form the no content page 
  766. $post = get_post( $M_options['nocontent_page'] ); 
  767. } else { 
  768. if(empty($M_options['protectedmessagetitle'])) { 
  769. $M_options['protectedmessagetitle'] = __('No access to this content', 'membership'); 
  770.  
  771. $post = new stdClass; 
  772. $post->post_author = 1; 
  773. $post->post_name = 'membershipnoaccess'; 
  774. add_filter('the_permalink', create_function('$permalink', 'return "' . get_option('home') . '";')); 
  775. $post->guid = get_bloginfo('wpurl'); 
  776. $post->post_title = esc_html(stripslashes($M_options['protectedmessagetitle'])); 
  777. $post->post_content = stripslashes($M_options['protectedmessage']); 
  778. $post->ID = -1; 
  779. $post->post_status = 'publish'; 
  780. $post->post_type = 'post'; 
  781. $post->comment_status = 'closed'; 
  782. $post->ping_status = 'open'; 
  783. $post->comment_count = 0; 
  784. $post->post_date = current_time('mysql'); 
  785. $post->post_date_gmt = current_time('mysql', 1); 
  786.  
  787. return array($post); 
  788.  
  789.  
  790. function ensure_option_pages_visible($wp_query) { 
  791.  
  792. global $M_options; 
  793.  
  794. if(empty($wp_query->query_vars['post__in'])) { 
  795. return; 
  796.  
  797. $forchecking = array(); 
  798.  
  799. if(!empty($M_options['registration_page'])) { 
  800. $wp_query->query_vars['post__in'][] = $M_options['registration_page']; 
  801. $forchecking[] = $M_options['registration_page']; 
  802.  
  803. if(!empty($M_options['account_page'])) { 
  804. $wp_query->query_vars['post__in'][] = $M_options['account_page']; 
  805. $forchecking[] = $M_options['account_page']; 
  806.  
  807. if(!empty($M_options['nocontent_page'])) { 
  808. $wp_query->query_vars['post__in'][] = $M_options['nocontent_page']; 
  809. $forchecking[] = $M_options['nocontent_page']; 
  810.  
  811. if(!empty($M_options['registrationcompleted_page'])) { 
  812. $wp_query->query_vars['post__in'][] = $M_options['registrationcompleted_page']; 
  813. $forchecking[] = $M_options['registrationcompleted_page']; 
  814.  
  815. if(!empty($M_options['subscriptions_page'])) { 
  816. $wp_query->query_vars['post__in'][] = $M_options['subscriptions_page']; 
  817. $forchecking[] = $M_options['subscriptions_page']; 
  818.  
  819. if(is_array($wp_query->query_vars['post__not_in'])) { 
  820. foreach($wp_query->query_vars['post__not_in'] as $key => $value) { 
  821. if(in_array( $value, (array) $forchecking ) ) { 
  822. unset($wp_query->query_vars['post__not_in'][$key]); 
  823.  
  824. $wp_query->query_vars['post__in'] = array_unique($wp_query->query_vars['post__in']); 
  825.  
  826.  
  827. function hide_nocontent_page_from_menu($pages) { 
  828.  
  829. global $M_options; 
  830.  
  831. foreach( (array) $pages as $key => $page ) { 
  832. if( ($page->ID == $M_options['nocontent_page']) || ($page->ID == $M_options['registrationcompleted_page'])) { 
  833. unset($pages[$key]); 
  834.  
  835. return $pages; 
  836.  
  837. //function show_noaccess_page($wp_query, $forceviewing = false) { 
  838. function show_noaccess_page($posts, $forceviewing = false) { 
  839.  
  840. global $M_options; 
  841.  
  842. if(!empty($posts)) { 
  843.  
  844. if(count($posts) == 1 && isset($posts[0]->post_type) && $posts[0]->post_type == 'page') { 
  845. // We are on a page so get the first page and then check for ones we want to allow 
  846. $page = $posts[0]; 
  847.  
  848. if(!empty($page->ID) && !empty($M_options['nocontent_page']) && $page->ID == $M_options['nocontent_page']) { 
  849. return $posts; 
  850.  
  851. if(!empty($page->ID) && !empty($M_options['registration_page']) && $page->ID == $M_options['registration_page']) { 
  852. // We know what we are looking at, the registration page has been set and we are trying to access it 
  853. return $posts; 
  854.  
  855. if(!empty($page->ID) && !empty($M_options['account_page']) && $page->ID == $M_options['account_page']) { 
  856. // We know what we are looking at, the registration page has been set and we are trying to access it 
  857. return $posts; 
  858.  
  859. if(!empty($page->ID) && !empty($M_options['registrationcompleted_page']) && $page->ID == $M_options['registrationcompleted_page']) { 
  860. // We know what we are looking at, the registration page has been set and we are trying to access it 
  861. return $posts; 
  862.  
  863. if(!empty($page->ID) && !empty($M_options['subscriptions_page']) && $page->ID == $M_options['subscriptions_page']) { 
  864. // We know what we are looking at, the registration page has been set and we are trying to access it 
  865. return $posts; 
  866.  
  867. // We are still here so we may be at a page that we shouldn't be able to see 
  868. if(!empty($M_options['nocontent_page']) && isset($page->ID) && $page->ID != $M_options['nocontent_page'] && !headers_sent()) { 
  869. // grab the content form the no content page 
  870. $url = get_permalink( (int) $M_options['nocontent_page'] ); 
  871.  
  872. wp_safe_redirect( $url ); 
  873. exit; 
  874. } else { 
  875. return $posts; 
  876.  
  877.  
  878. } else { 
  879. // We could be on a posts page / or on a single post. 
  880. if(count($posts) == 1) { 
  881. // We could be on a single posts page, or only have the one post to view 
  882. if(isset($posts[0]->post_type) && $posts[0]->post_type != 'nav_menu_item') { 
  883. // We'll redirect if this isn't a navigation menu item 
  884. $post = $posts[0]; 
  885.  
  886. if(!empty($M_options['nocontent_page']) && isset($post->ID) && $post->ID != $M_options['nocontent_page'] && !headers_sent()) { 
  887. // grab the content form the no content page 
  888. $url = get_permalink( (int) $M_options['nocontent_page'] ); 
  889.  
  890. wp_safe_redirect( $url ); 
  891. exit; 
  892. } else { 
  893. return $posts; 
  894. } else { 
  895. // Check the first post in the list 
  896. if(isset($posts[0]->post_type) && $posts[0]->post_type != 'nav_menu_item') { 
  897. // We'll redirect if this isn't a navigation menu item 
  898. $post = $posts[0]; 
  899.  
  900. if(!empty($M_options['nocontent_page']) && isset($post->ID) && $post->ID != $M_options['nocontent_page'] && !headers_sent()) { 
  901. // grab the content form the no content page 
  902. $url = get_permalink( (int) $M_options['nocontent_page'] ); 
  903.  
  904. wp_safe_redirect( $url ); 
  905. exit; 
  906. } else { 
  907. return $posts; 
  908.  
  909.  
  910. } else { 
  911. // We don't have any posts, so we should just redirect to the no content page. 
  912. if(!empty($M_options['nocontent_page']) && !headers_sent()) { 
  913. // grab the content form the no content page 
  914. $url = get_permalink( (int) $M_options['nocontent_page'] ); 
  915.  
  916. wp_safe_redirect( $url ); 
  917. exit; 
  918. } else { 
  919. return $posts; 
  920.  
  921. // If we've reached here then something weird has happened :/ 
  922. return $posts; 
  923.  
  924. /** 
  925. if(!empty($wp_query->query_vars['protectedfile']) && !$forceviewing) { 
  926. return; 
  927. } 
  928. */ 
  929.  
  930.  
  931. function close_comments($open, $postid) { 
  932.  
  933. return false; 
  934.  
  935.  
  936. // Content / downloads protection 
  937. function protect_download_content($the_content) { 
  938.  
  939. global $M_options; 
  940.  
  941. $origpath = membership_upload_url(); 
  942. $newpath = trailingslashit(trailingslashit(get_option('home')) . $M_options['masked_url']); 
  943.  
  944. // Find all the urls in the post and then we'll check if they are protected 
  945. /** Regular expression from http://blog.mattheworiordan.com/post/13174566389/url-regular-expression-for-links-with-or-without-the */ 
  946.  
  947. $url_exp = '/((([A-Za-z]{3, 9}:(?:\/\/)?)(?:[-;:&=\+\$, \w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$, \w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)/'; 
  948.  
  949. $matches = array(); 
  950. if(preg_match_all($url_exp, $the_content, $matches)) { 
  951. $home = get_option('home'); 
  952. if(!empty($matches) && !empty($matches[2])) { 
  953.  
  954. foreach((array) $matches[2] as $key => $domain) { 
  955. if(untrailingslashit($home) == untrailingslashit($domain)) { 
  956. $foundlocal = $key; 
  957. $file = basename($matches[4][$foundlocal]); 
  958.  
  959. $filename_exp = '/(.+)\-(\d+[x]\d+)\.(.+)$/'; 
  960. $filematch = array(); 
  961. if(preg_match($filename_exp, $file, $filematch)) { 
  962. // We have an image with an image size attached 
  963. $newfile = $filematch[1] . "." . $filematch[3]; 
  964. $size_extension = "-" . $filematch[2]; 
  965. } else { 
  966. $newfile = $file; 
  967. $size_extension = ''; 
  968.  
  969. $sql = $this->db->prepare( "SELECT post_id FROM {$this->db->postmeta} WHERE meta_key = '_wp_attached_file' AND meta_value LIKE %s", '%' . $newfile . '%'); 
  970. $post_id = $this->db->get_var( $sql ); 
  971. if(empty($post_id)) { 
  972. // Can't find the file in the first pass, try the second pass. 
  973. $sql = $this->db->prepare( "SELECT post_id FROM {$this->db->postmeta} WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s", '%' . $file . '%'); 
  974. $post_id = $this->db->get_var( $sql ); 
  975.  
  976. if(!empty($post_id)) { 
  977. // Found the file and it's in the media library 
  978. $protected = get_post_meta( $post_id, '_membership_protected_content_group', true ); 
  979.  
  980. if(!empty($protected)) { 
  981. // We have a protected file - so we'll mask it 
  982. switch($M_options['protection_type']) { 
  983. case 'complete' : $protectedfilename = MEMBERSHIP_FILE_NAME_PREFIX . ($post_id + (int) MEMBERSHIP_FILE_NAME_INCREMENT) . $size_extension; 
  984. $protectedfilename .= "." . pathinfo($newfile, PATHINFO_EXTENSION); 
  985.  
  986. $the_content = str_replace( $matches[0][$foundlocal], $newpath . $protectedfilename, $the_content ); 
  987. break; 
  988.  
  989. case 'hybrid' : $protectedfilename = MEMBERSHIP_FILE_NAME_PREFIX . ($post_id + (int) MEMBERSHIP_FILE_NAME_INCREMENT) . $size_extension; 
  990. $protectedfilename .= "." . pathinfo($newfile, PATHINFO_EXTENSION); 
  991.  
  992. $the_content = str_replace( $matches[0][$foundlocal], $newpath . "?file=" . $protectedfilename, $the_content ); 
  993. break; 
  994.  
  995. case 'basic' : 
  996. default: $the_content = str_replace( $matches[0][$foundlocal], str_replace( $origpath, $newpath, $matches[0][$foundlocal] ), $the_content ); 
  997.  
  998. break; 
  999.  
  1000.  
  1001.  
  1002. return $the_content; 
  1003.  
  1004.  
  1005. // Shortcodes 
  1006.  
  1007. function show_account_page( $content = null ) { 
  1008.  
  1009. global $bp, $profileuser, $user, $user_id; 
  1010.  
  1011. if(!is_user_logged_in()) { 
  1012. return apply_filters('membership_account_form_not_logged_in', $content ); 
  1013.  
  1014. require_once(ABSPATH . 'wp-admin/includes/user.php'); 
  1015.  
  1016. $user = wp_get_current_user(); 
  1017.  
  1018. $user_id = $user->ID; 
  1019.  
  1020. $profileuser = get_user_to_edit($user_id); 
  1021.  
  1022. $content = ''; 
  1023.  
  1024. $content = apply_filters('membership_account_form_before_content', $content); 
  1025.  
  1026. ob_start(); 
  1027. if( defined('MEMBERSHIP_ACCOUNT_FORM') && file_exists( MEMBERSHIP_ACCOUNT_FORM ) ) { 
  1028. include_once( MEMBERSHIP_ACCOUNT_FORM ); 
  1029. } elseif(!empty($bp) && file_exists( apply_filters('membership_override_bpaccount_form', membership_dir('membershipincludes/includes/bp.account.form.php'), $user_id) )) { 
  1030. include_once( apply_filters('membership_override_bpaccount_form', membership_dir('membershipincludes/includes/bp.account.form.php'), $user_id) ); 
  1031. } elseif( file_exists( apply_filters('membership_override_account_form', membership_dir('membershipincludes/includes/account.form.php'), $user_id) ) ) { 
  1032. include_once( apply_filters('membership_override_account_form', membership_dir('membershipincludes/includes/account.form.php'), $user_id) ); 
  1033. $content .= ob_get_contents(); 
  1034. ob_end_clean(); 
  1035.  
  1036. $content = apply_filters('membership_account_form_after_content', $content, $user_id); 
  1037.  
  1038. return $content; 
  1039.  
  1040.  
  1041. function show_subpage_one($error = false) { 
  1042.  
  1043. global $bp; 
  1044.  
  1045. $content = ''; 
  1046.  
  1047. $content = apply_filters('membership_subscription_form_registration_before_content', $content, $error); 
  1048.  
  1049. ob_start(); 
  1050. if( defined('MEMBERSHIP_REGISTRATION_FORM') && file_exists( MEMBERSHIP_REGISTRATION_FORM ) ) { 
  1051. include_once( MEMBERSHIP_REGISTRATION_FORM ); 
  1052. } elseif(!empty($bp) && file_exists( apply_filters('membership_override_bpregistration_form', membership_dir('membershipincludes/includes/bp.registration.form.php'), $error) )) { 
  1053. include_once( apply_filters('membership_override_bpregistration_form', membership_dir('membershipincludes/includes/bp.registration.form.php'), $error) ); 
  1054. } elseif( file_exists( apply_filters('membership_override_registration_form', membership_dir('membershipincludes/includes/registration.form.php'), $error) ) ) { 
  1055. include_once( apply_filters('membership_override_registration_form', membership_dir('membershipincludes/includes/registration.form.php'), $error) ); 
  1056. $content .= ob_get_contents(); 
  1057. ob_end_clean(); 
  1058.  
  1059. $content = apply_filters('membership_subscription_form_registration_after_content', $content, $error); 
  1060.  
  1061. return $content; 
  1062.  
  1063.  
  1064. function show_subpage_two($user_id) { 
  1065.  
  1066. $content = ''; 
  1067.  
  1068. $content = apply_filters('membership_subscription_form_before_content', $content, $user_id); 
  1069.  
  1070. ob_start(); 
  1071. if( defined('MEMBERSHIP_SUBSCRIPTION_FORM') && file_exists( MEMBERSHIP_SUBSCRIPTION_FORM ) ) { 
  1072. include_once( MEMBERSHIP_SUBSCRIPTION_FORM ); 
  1073. } elseif(file_exists( apply_filters('membership_override_subscription_form', membership_dir('membershipincludes/includes/subscription.form.php'), $user_id) ) ) { 
  1074. include_once( apply_filters('membership_override_subscription_form', membership_dir('membershipincludes/includes/subscription.form.php'), $user_id) ); 
  1075. $content .= ob_get_contents(); 
  1076. ob_end_clean(); 
  1077.  
  1078. $content = apply_filters('membership_subscription_form_after_content', $content, $user_id ); 
  1079.  
  1080. return $content; 
  1081.  
  1082.  
  1083. function show_subpage_member() { 
  1084.  
  1085. $content = ''; 
  1086.  
  1087. $content = apply_filters('membership_subscription_form_member_before_content', $content, $user_id); 
  1088.  
  1089. ob_start(); 
  1090. if( defined('MEMBERSHIP_MEMBER_FORM') && file_exists( MEMBERSHIP_MEMBER_FORM ) ) { 
  1091. include_once( MEMBERSHIP_MEMBER_FORM ); 
  1092. } elseif(file_exists( apply_filters('membership_override_member_form', membership_dir('membershipincludes/includes/member.form.php')) )) { 
  1093. include_once( apply_filters('membership_override_member_form', membership_dir('membershipincludes/includes/member.form.php')) ); 
  1094. $content .= ob_get_contents(); 
  1095. ob_end_clean(); 
  1096.  
  1097. $content = apply_filters('membership_subscription_form_member_after_content', $content, $user_id ); 
  1098.  
  1099. return $content; 
  1100.  
  1101.  
  1102. function show_upgrade_page() { 
  1103.  
  1104. $content = ''; 
  1105.  
  1106. $content = apply_filters('membership_upgrade_form_member_before_content', $content, $user_id); 
  1107.  
  1108. ob_start(); 
  1109. if( defined('MEMBERSHIP_UPGRADE_FORM') && file_exists( MEMBERSHIP_UPGRADE_FORM ) ) { 
  1110. include_once( MEMBERSHIP_UPGRADE_FORM ); 
  1111. } elseif(file_exists( apply_filters('membership_override_upgrade_form', membership_dir('membershipincludes/includes/upgrade.form.php')) )) { 
  1112. include_once( apply_filters('membership_override_upgrade_form', membership_dir('membershipincludes/includes/upgrade.form.php')) ); 
  1113. $content .= ob_get_contents(); 
  1114. ob_end_clean(); 
  1115.  
  1116. $content = apply_filters('membership_upgrade_form_member_after_content', $content, $user_id ); 
  1117.  
  1118. return $content; 
  1119.  
  1120.  
  1121. function show_renew_page( $user_id = false ) { 
  1122.  
  1123. global $M_options; 
  1124.  
  1125. $content = ''; 
  1126.  
  1127. $content = apply_filters('membership_renew_form_member_before_content', $content, $user_id); 
  1128.  
  1129. ob_start(); 
  1130. if( defined('MEMBERSHIP_RENEW_FORM') && file_exists( MEMBERSHIP_RENEW_FORM ) ) { 
  1131. include_once( MEMBERSHIP_RENEW_FORM ); 
  1132. } elseif(file_exists( apply_filters('membership_override_renew_form', membership_dir('membershipincludes/includes/renew.form.php')) )) { 
  1133. include_once( apply_filters('membership_override_renew_form', membership_dir('membershipincludes/includes/renew.form.php')) ); 
  1134. $content .= ob_get_contents(); 
  1135. ob_end_clean(); 
  1136.  
  1137. $content = apply_filters('membership_renew_form_member_after_content', $content, $user_id ); 
  1138.  
  1139. return $content; 
  1140.  
  1141.  
  1142. function do_renew_shortcode($atts, $content = null, $code = "") { 
  1143.  
  1144. global $wp_query; 
  1145.  
  1146. $error = array(); 
  1147.  
  1148. $page = addslashes($_REQUEST['action']); 
  1149.  
  1150. $M_options = get_option('membership_options', array()); 
  1151.  
  1152. $content = $this->show_renew_page(); 
  1153.  
  1154. $content = apply_filters('membership_renew_form', $content); 
  1155.  
  1156. return $content; 
  1157.  
  1158.  
  1159. function do_upgrade_shortcode($atts, $content = null, $code = "") { 
  1160.  
  1161. global $wp_query; 
  1162.  
  1163. $error = array(); 
  1164.  
  1165. $page = addslashes($_REQUEST['action']); 
  1166.  
  1167. $M_options = get_option('membership_options', array()); 
  1168.  
  1169. $content = $this->show_upgrade_page(); 
  1170.  
  1171. $content = apply_filters('membership_upgrade_form', $content); 
  1172.  
  1173. return $content; 
  1174.  
  1175.  
  1176. function do_account_shortcode($atts, $content = null, $code = "") { 
  1177.  
  1178. global $wp_query; 
  1179.  
  1180. $error = array(); 
  1181.  
  1182. $page = addslashes($_REQUEST['action']); 
  1183.  
  1184. $M_options = get_option('membership_options', array()); 
  1185.  
  1186. $content = $this->show_account_page( $content ); 
  1187.  
  1188. $content = apply_filters('membership_account_form', $content); 
  1189.  
  1190. return $content; 
  1191.  
  1192.  
  1193. function do_account_form() { 
  1194.  
  1195. global $wp_query, $M_options, $bp; 
  1196.  
  1197. $content = $this->show_account_page(); 
  1198.  
  1199. return $content; 
  1200.  
  1201.  
  1202.  
  1203. function do_renew_form() { 
  1204. global $wp_query, $M_options, $bp; 
  1205.  
  1206. $page = (isset($_REQUEST['action'])) ? addslashes($_REQUEST['action']) : ''; 
  1207. if(empty($page)) { 
  1208. $page = 'renewform'; 
  1209.  
  1210. $content = ''; 
  1211.  
  1212. switch($page) { 
  1213.  
  1214. case 'subscriptionsignup': 
  1215. if(is_user_logged_in()) { 
  1216.  
  1217. $member = current_member(); 
  1218. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  1219.  
  1220. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id) ) { 
  1221. $gateway = $_POST['gateway']; 
  1222. // Join the new subscription 
  1223. $member->create_subscription($sub_id, $gateway); 
  1224. // Timestamp the update 
  1225. update_user_meta( $user_id, '_membership_last_upgraded', time()); 
  1226. } else { 
  1227. // check if a custom is posted and of so then process the user 
  1228. if(isset($_POST['custom'])) { 
  1229. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  1230.  
  1231. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id) ) { 
  1232. $gateway = $_POST['gateway']; 
  1233. // Join the new subscription 
  1234. $member = new M_Membership( $user_id ); 
  1235. $member->create_subscription($sub_id, $gateway); 
  1236. // Timestamp the update 
  1237. update_user_meta( $user_id, '_membership_last_upgraded', time()); 
  1238. $content = $this->show_renew_page(); 
  1239. break; 
  1240.  
  1241. case 'renewform': 
  1242. default: // Just show the page 
  1243. $content = $this->show_renew_page(); 
  1244. break; 
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251. return $content; 
  1252.  
  1253. function output_subscriptionform() { 
  1254.  
  1255. global $wp_query, $M_options, $bp; 
  1256.  
  1257. if(empty($user_id)) { 
  1258. $user = wp_get_current_user(); 
  1259.  
  1260. if(!empty($user->ID) && is_numeric($user->ID) ) { 
  1261. $user_id = $user->ID; 
  1262. } else { 
  1263. $user_id = 0; 
  1264.  
  1265. $content = apply_filters('membership_subscription_form_before_content', '', $user_id); 
  1266. ob_start(); 
  1267. if( defined('MEMBERSHIP_SUBSCRIPTION_FORM') && file_exists( MEMBERSHIP_SUBSCRIPTION_FORM ) ) { 
  1268. include_once( MEMBERSHIP_SUBSCRIPTION_FORM ); 
  1269. } elseif(file_exists( apply_filters('membership_override_subscription_form', membership_dir('membershipincludes/includes/subscription.form.php'), $user_id) ) ) { 
  1270. include_once( apply_filters('membership_override_subscription_form', membership_dir('membershipincludes/includes/subscription.form.php'), $user_id) ); 
  1271. $content .= ob_get_contents(); 
  1272. ob_end_clean(); 
  1273.  
  1274. $content = apply_filters('membership_subscription_form_after_content', $content, $user_id ); 
  1275.  
  1276. return $content; 
  1277.  
  1278. function output_registeruser( $error = false ) { 
  1279.  
  1280. global $wp_query, $M_options, $bp; 
  1281.  
  1282. $subscription = (int) $_GET['subscription']; 
  1283. $content = apply_filters('membership_subscription_form_registration_before_content', '', $error); 
  1284. ob_start(); 
  1285. if( defined('MEMBERSHIP_REGISTRATION_FORM') && file_exists( MEMBERSHIP_REGISTRATION_FORM ) ) { 
  1286. include_once( MEMBERSHIP_REGISTRATION_FORM ); 
  1287. } elseif(!empty($bp) && file_exists( apply_filters('membership_override_bpregistration_form', membership_dir('membershipincludes/includes/bp.registration.form.php'), $error) )) { 
  1288. include_once( apply_filters('membership_override_bpregistration_form', membership_dir('membershipincludes/includes/bp.registration.form.php'), $error) ); 
  1289. } elseif( file_exists( apply_filters('membership_override_registration_form', membership_dir('membershipincludes/includes/registration.form.php'), $error) ) ) { 
  1290. include_once( apply_filters('membership_override_registration_form', membership_dir('membershipincludes/includes/registration.form.php'), $error) ); 
  1291. $content .= ob_get_contents(); 
  1292. ob_end_clean(); 
  1293.  
  1294. $content = apply_filters('membership_subscription_form_registration_after_content', $content, $error); 
  1295.  
  1296. return $content; 
  1297.  
  1298. function output_paymentpage( $user_id = false ) { 
  1299.  
  1300. global $wp_query, $M_options; 
  1301.  
  1302. $subscription = (int) $_REQUEST['subscription']; 
  1303.  
  1304. if(!$user_id) { 
  1305. $user = wp_get_current_user(); 
  1306.  
  1307. if(!empty($user->ID) && is_numeric($user->ID) ) { 
  1308. $member = new M_Membership( $user->ID); 
  1309. } else { 
  1310. $member = current_member(); 
  1311. } else { 
  1312. $member = new M_Membership( $user_id ); 
  1313.  
  1314. if(empty($error)) { 
  1315. $error = ''; 
  1316.  
  1317. $content = apply_filters('membership_subscription_form_payment_before_content', '', $error); 
  1318. ob_start(); 
  1319. if( defined('MEMBERSHIP_PAYMENT_FORM') && file_exists( MEMBERSHIP_PAYMENT_FORM ) ) { 
  1320. include_once( MEMBERSHIP_PAYMENT_FORM ); 
  1321. } elseif( file_exists( apply_filters('membership_override_payment_form', membership_dir('membershipincludes/includes/payment.form.php'), $error) ) ) { 
  1322. include_once( apply_filters('membership_override_payment_form', membership_dir('membershipincludes/includes/payment.form.php'), $error) ); 
  1323. $content .= ob_get_contents(); 
  1324. ob_end_clean(); 
  1325.  
  1326. $content = apply_filters('membership_subscription_form_payment_after_content', $content, $error); 
  1327.  
  1328. return $content; 
  1329.  
  1330.  
  1331. function do_subscription_form() { 
  1332.  
  1333. global $wp_query, $M_options, $bp; 
  1334.  
  1335. if(isset($_REQUEST['action'])) $page = addslashes($_REQUEST['action']); 
  1336. if(empty($page)) { 
  1337. $page = 'subscriptionform'; 
  1338.  
  1339. $content = ''; 
  1340.  
  1341. switch($page) { 
  1342.  
  1343. case 'subscriptionform': $content = $this->output_subscriptionform(); 
  1344. break; 
  1345.  
  1346. case 'registeruser': 
  1347. if(!is_user_logged_in()) { 
  1348. $content = $this->output_registeruser(); 
  1349. } else { 
  1350. $content = $this->output_paymentpage(); 
  1351. break; 
  1352.  
  1353. case 'subscriptionsignup': if(!is_user_logged_in()) { 
  1354. $content = $this->output_registeruser(); 
  1355. } else { 
  1356. $content = $this->output_paymentpage(); 
  1357. break; 
  1358.  
  1359. case 'validatepage1': // Page 1 of the form has been submitted - validate 
  1360. //include_once(ABSPATH . WPINC . '/registration.php'); 
  1361.  
  1362. $required = array( 'user_login' => __('Username', 'membership'),  
  1363. 'user_email' => __('Email address', 'membership'),  
  1364. 'password' => __('Password', 'membership'),  
  1365. 'password2' => __('Password confirmation', 'membership'),  
  1366. ); 
  1367.  
  1368. $error = new WP_Error(); 
  1369.  
  1370. foreach($required as $key => $message) { 
  1371. if(empty($_POST[$key])) { 
  1372. $error->add($key, __('Please ensure that the ', 'membership') . "<strong>" . $message . "</strong>" . __(' information is completed.', 'membership')); 
  1373.  
  1374. if($_POST['password'] != $_POST['password2']) { 
  1375. $error->add('passmatch', __('Please ensure the passwords match.', 'membership')); 
  1376.  
  1377. if(!validate_username( $_POST['user_login'] )) { 
  1378. $error->add('usernamenotvalid', __('The username is not valid, sorry.', 'membership')); 
  1379.  
  1380. if(username_exists(sanitize_user($_POST['user_login']))) { 
  1381. $error->add('usernameexists', __('That username is already taken, sorry.', 'membership')); 
  1382.  
  1383. if(!is_email($_POST['user_email'])) { 
  1384. $error->add('emailnotvalid', __('The email address is not valid, sorry.', 'membership')); 
  1385.  
  1386. if(email_exists($_POST['user_email'])) { 
  1387. $error->add('emailexists', __('That email address is already taken, sorry.', 'membership')); 
  1388.  
  1389. $error = apply_filters( 'membership_subscription_form_before_registration_process', $error ); 
  1390.  
  1391. $result = array('user_name' => $_POST['user_login'], 'orig_username' => $_POST['user_login'], 'user_email' => $_POST['user_email'], 'errors' => $error); 
  1392.  
  1393. $result = apply_filters('wpmu_validate_user_signup', $result); 
  1394.  
  1395. $error = $result['errors']; 
  1396.  
  1397. // Hack for now - eeek 
  1398. $anyerrors = $error->get_error_code(); 
  1399. if( empty($anyerrors) ) { 
  1400. // No errors so far - error reporting check for final add user *note $error should always be an error object becuase we created it as such. 
  1401. $user_id = wp_create_user( sanitize_user($_POST['user_login']), $_POST['password'], $_POST['user_email'] ); 
  1402.  
  1403. if(is_wp_error($user_id) && method_exists($userid, 'get_error_message')) { 
  1404. $error->add('userid', $user_id->get_error_message()); 
  1405. } else { 
  1406. $member = new M_Membership( $user_id ); 
  1407.  
  1408. if(defined('MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION') && MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION == true) { 
  1409. $member->deactivate(); 
  1410. } else { 
  1411. $creds = array( 
  1412. 'user_login' => $_POST['user_login'],  
  1413. 'user_password' => $_POST['password'],  
  1414. 'remember' => true 
  1415. ); 
  1416.  
  1417. if(!headers_sent()) { 
  1418. $is_ssl = (isset($_SERVER['https']) && strtolower($_SERVER['https']) == 'on' ? true : false); 
  1419. $user = @wp_signon( $creds, $is_ssl ); 
  1420.  
  1421. if ( is_wp_error($user) && method_exists($user, 'get_error_message') ) { 
  1422. $error->add('userlogin', $user->get_error_message()); 
  1423. } else { 
  1424. // Set the current user up 
  1425. wp_set_current_user( $user_id ); 
  1426. } else { 
  1427. // Set the current user up 
  1428. wp_set_current_user( $user_id ); 
  1429.  
  1430.  
  1431. if( has_action('membership_susbcription_form_registration_notification') ) { 
  1432. do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['password']); 
  1433. } else { 
  1434. wp_new_user_notification($user_id, $_POST['password']); 
  1435.  
  1436.  
  1437. do_action( 'membership_subscription_form_registration_process', $error, $user_id ); 
  1438.  
  1439. } else { 
  1440. do_action( 'membership_subscription_form_registration_process', $error, 0 ); 
  1441.  
  1442. // Hack for now - eeek 
  1443. $anyerrors = $error->get_error_code(); 
  1444. if( !empty($anyerrors) ) { 
  1445. // we have an error - output 
  1446. // Show the page again so that it can display the errors 
  1447. $content = $this->output_registeruser( $error ); 
  1448.  
  1449. } else { 
  1450. $content = $this->output_paymentpage( $user_id ); 
  1451.  
  1452. break; 
  1453.  
  1454. case 'validatepage1bp': 
  1455. global $bp; 
  1456.  
  1457. //include_once(ABSPATH . WPINC . '/registration.php'); 
  1458.  
  1459. $required = array( 'signup_username' => __('Username', 'membership'),  
  1460. 'signup_email' => __('Email address', 'membership'),  
  1461. 'signup_password' => __('Password', 'membership'),  
  1462. 'signup_password_confirm' => __('Password confirmation', 'membership'),  
  1463. ); 
  1464.  
  1465. $error = new WP_Error(); 
  1466.  
  1467. foreach($required as $key => $message) { 
  1468. if(empty($_POST[$key])) { 
  1469. $error->add($key, __('Please ensure that the ', 'membership') . "<strong>" . $message . "</strong>" . __(' information is completed.', 'membership')); 
  1470.  
  1471. if($_POST['signup_password'] != $_POST['signup_password_confirm']) { 
  1472. $error->add('passmatch', __('Please ensure the passwords match.', 'membership')); 
  1473.  
  1474. if(!validate_username( $_POST['signup_username'] )) { 
  1475. $error->add('usernamenotvalid', __('The username is not valid, sorry.', 'membership')); 
  1476.  
  1477. if(username_exists(sanitize_user($_POST['signup_username']))) { 
  1478. $error->add('usernameexists', __('That username is already taken, sorry.', 'membership')); 
  1479.  
  1480. if(!is_email($_POST['signup_email'])) { 
  1481. $error->add('emailnotvalid', __('The email address is not valid, sorry.', 'membership')); 
  1482.  
  1483. if(email_exists($_POST['signup_email'])) { 
  1484. $error->add('emailexists', __('That email address is already taken, sorry.', 'membership')); 
  1485.  
  1486. // Initial fix provided by user: cmurtagh - modified to add extra checks and rejigged a bit 
  1487. // Run the buddypress validation 
  1488. do_action( 'bp_signup_validate' ); 
  1489.  
  1490. // Add any errors to the action for the field in the template for display. 
  1491. if ( !empty( $bp->signup->errors ) ) { 
  1492. foreach ( (array)$bp->signup->errors as $fieldname => $error_message ) { 
  1493. $error->add($fieldname, $error_message); 
  1494.  
  1495. $meta_array = array(); 
  1496.  
  1497. // xprofile required fields 
  1498. /** Now we've checked account details, we can check profile information */ 
  1499. //if ( function_exists( 'xprofile_check_is_required_field' ) ) { 
  1500. if ( function_exists('bp_is_active') && bp_is_active( 'xprofile' ) ) { 
  1501.  
  1502. /** Make sure hidden field is passed and populated */ 
  1503. if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) { 
  1504.  
  1505. /** Let's compact any profile field info into an array */ 
  1506. $profile_field_ids = explode( ', ', $_POST['signup_profile_field_ids'] ); 
  1507.  
  1508. /** Loop through the posted fields formatting any datebox values then validate the field */ 
  1509. foreach ( (array) $profile_field_ids as $field_id ) { 
  1510. if ( !isset( $_POST['field_' . $field_id] ) ) { 
  1511. if ( isset( $_POST['field_' . $field_id . '_day'] ) ) 
  1512. $_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] ); 
  1513.  
  1514. /** Create errors for required fields without values */ 
  1515. if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) ) { 
  1516. $field = new BP_Xprofile_Field( $field_id ); 
  1517. $error->add($field->name, __('Please ensure that the ', 'membership') . "<strong>" . $field->name . "</strong>" . __(' information is completed.', 'membership')); 
  1518.  
  1519. $meta_array[ $field_id ] = $_POST['field_' . $field_id]; 
  1520.  
  1521.  
  1522. $error = apply_filters( 'membership_subscription_form_before_registration_process', $error ); 
  1523.  
  1524. // Hack for now - eeek 
  1525. $anyerrors = $error->get_error_code(); 
  1526. if( empty($anyerrors) ) { 
  1527. // No errors so far - error reporting check for final add user *note $error should always be an error object becuase we created it as such. 
  1528. $user_id = wp_create_user( sanitize_user($_POST['signup_username']), $_POST['signup_password'], $_POST['signup_email'] ); 
  1529.  
  1530. if(is_wp_error($user_id) && method_exists($userid, 'get_error_message')) { 
  1531. $error->add('userid', $user_id->get_error_message()); 
  1532. } else { 
  1533. $member = new M_Membership( $user_id ); 
  1534. if(defined('MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION') && MEMBERSHIP_DEACTIVATE_USER_ON_REGISTRATION == true) { 
  1535. $member->deactivate(); 
  1536. } else { 
  1537. $creds = array( 
  1538. 'user_login' => $_POST['signup_username'],  
  1539. 'user_password' => $_POST['signup_password'],  
  1540. 'remember' => true 
  1541. ); 
  1542.  
  1543. if(!headers_sent()) { 
  1544. $is_ssl = (isset($_SERVER['https']) && strtolower($_SERVER['https']) == 'on' ? true : false); 
  1545. $user = @wp_signon( $creds, $is_ssl ); 
  1546.  
  1547. if ( is_wp_error($user) && method_exists($user, 'get_error_message') ) { 
  1548. $error->add('userlogin', $user->get_error_message()); 
  1549. } else { 
  1550. // Set the current user up 
  1551. wp_set_current_user( $user_id ); 
  1552. } else { 
  1553. // Set the current user up 
  1554. wp_set_current_user( $user_id ); 
  1555.  
  1556.  
  1557. if( has_action('membership_susbcription_form_registration_notification') ) { 
  1558. do_action('membership_susbcription_form_registration_notification', $user_id, $_POST['signup_password']); 
  1559. } else { 
  1560. wp_new_user_notification($user_id, $_POST['signup_password']); 
  1561.  
  1562. // Add the bp filter for usermeta signup 
  1563. $meta_array = apply_filters( 'bp_signup_usermeta', $meta_array ); 
  1564.  
  1565. foreach((array) $meta_array as $field_id => $field_content) { 
  1566. if(function_exists('xprofile_set_field_data')) { 
  1567. xprofile_set_field_data( $field_id, $user_id, $field_content ); 
  1568.  
  1569.  
  1570. do_action( 'membership_subscription_form_registration_process', $error, $user_id ); 
  1571. } else { 
  1572. do_action( 'membership_subscription_form_registration_process', $error, 0 ); 
  1573.  
  1574. // Hack for now - eeek 
  1575. $anyerrors = $error->get_error_code(); 
  1576. if(!empty($anyerrors)) { 
  1577. // Show the page so that it can display the errors 
  1578. $content = $this->output_registeruser( $error ); 
  1579. } else { 
  1580. // everything seems fine (so far), so we have our queued user so let's 
  1581. // run the bp complete signup action 
  1582. do_action( 'bp_complete_signup' ); 
  1583. // display the payment forms 
  1584. $content = $this->output_paymentpage( $user_id ); 
  1585.  
  1586. break; 
  1587.  
  1588.  
  1589.  
  1590.  
  1591. return $content; 
  1592.  
  1593.  
  1594. function do_subscription_shortcode($atts, $content = null, $code = "") { 
  1595.  
  1596. global $wp_query; 
  1597.  
  1598. return $this->do_subscription_form(); 
  1599.  
  1600.  
  1601.  
  1602. function do_subscriptiontitle_shortcode($atts, $content = null, $code = "") { 
  1603.  
  1604. global $wp_query; 
  1605.  
  1606. $defaults = array( "holder" => '',  
  1607. "holderclass" => '',  
  1608. "item" => '',  
  1609. "itemclass" => '',  
  1610. "postfix" => '',  
  1611. "prefix" => '',  
  1612. "wrapwith" => '',  
  1613. "wrapwithclass" => '',  
  1614. "subscription" => '' 
  1615. ); 
  1616.  
  1617. extract(shortcode_atts($defaults, $atts)); 
  1618.  
  1619. if(empty($subscription)) { 
  1620. return ''; 
  1621.  
  1622. $html = ''; 
  1623.  
  1624. if(!empty($holder)) { 
  1625. $html .= "<{$holder} class='{$holderclass}'>"; 
  1626. if(!empty($item)) { 
  1627. $html .= "<{$item} class='{$itemclass}'>"; 
  1628. $html .= $prefix; 
  1629.  
  1630. // The title 
  1631. if(!empty($wrapwith)) { 
  1632. $html .= "<{$wrapwith} class='{$wrapwithclass}'>"; 
  1633.  
  1634. $sub = new M_Subscription( (int) $subscription ); 
  1635. $html .= $sub->sub_name(); 
  1636.  
  1637. if(!empty($wrapwith)) { 
  1638. $html .= "</{$wrapwith}>"; 
  1639.  
  1640. $html .= $postfix; 
  1641. if(!empty($item)) { 
  1642. $html .= "</{$item}>"; 
  1643. if(!empty($holder)) { 
  1644. $html .= "</{$holder}>"; 
  1645.  
  1646.  
  1647. return $html; 
  1648.  
  1649. function do_subscriptiondetails_shortcode($atts, $content = null, $code = "") { 
  1650.  
  1651. global $wp_query; 
  1652.  
  1653. $defaults = array( "holder" => '',  
  1654. "holderclass" => '',  
  1655. "item" => '',  
  1656. "itemclass" => '',  
  1657. "postfix" => '',  
  1658. "prefix" => '',  
  1659. "wrapwith" => '',  
  1660. "wrapwithclass" => '',  
  1661. "subscription" => '' 
  1662. ); 
  1663.  
  1664. extract(shortcode_atts($defaults, $atts)); 
  1665.  
  1666. if(empty($subscription)) { 
  1667. return ''; 
  1668.  
  1669. $html = ''; 
  1670.  
  1671. if(!empty($holder)) { 
  1672. $html .= "<{$holder} class='{$holderclass}'>"; 
  1673. if(!empty($item)) { 
  1674. $html .= "<{$item} class='{$itemclass}'>"; 
  1675. $html .= $prefix; 
  1676.  
  1677. // The title 
  1678. if(!empty($wrapwith)) { 
  1679. $html .= "<{$wrapwith} class='{$wrapwithclass}'>"; 
  1680.  
  1681. $sub = new M_Subscription( (int) $subscription ); 
  1682. $html .= stripslashes($sub->sub_description()); 
  1683.  
  1684. if(!empty($wrapwith)) { 
  1685. $html .= "</{$wrapwith}>"; 
  1686.  
  1687. $html .= $postfix; 
  1688. if(!empty($item)) { 
  1689. $html .= "</{$item}>"; 
  1690. if(!empty($holder)) { 
  1691. $html .= "</{$holder}>"; 
  1692.  
  1693. return $html; 
  1694.  
  1695. function do_subscriptionprice_shortcode($atts, $content = null, $code = "") { 
  1696.  
  1697. global $wp_query; 
  1698.  
  1699. $defaults = array( "holder" => '',  
  1700. "holderclass" => '',  
  1701. "item" => '',  
  1702. "itemclass" => '',  
  1703. "postfix" => '',  
  1704. "prefix" => '',  
  1705. "wrapwith" => '',  
  1706. "wrapwithclass" => '',  
  1707. "subscription" => '',  
  1708. "level" => 1,  
  1709. ); 
  1710.  
  1711. extract(shortcode_atts($defaults, $atts)); 
  1712.  
  1713. $level = (int) $level; 
  1714.  
  1715. if(empty($subscription)) { 
  1716. return ''; 
  1717.  
  1718. $html = ''; 
  1719.  
  1720. if(!empty($holder)) { 
  1721. $html .= "<{$holder} class='{$holderclass}'>"; 
  1722. if(!empty($item)) { 
  1723. $html .= "<{$item} class='{$itemclass}'>"; 
  1724. $html .= $prefix; 
  1725.  
  1726. // The title 
  1727. if(!empty($wrapwith)) { 
  1728. $html .= "<{$wrapwith} class='{$wrapwithclass}'>"; 
  1729.  
  1730. $sub = new M_Subscription( (int) $subscription ); 
  1731. $first = $sub->get_level_at_position( $level ); 
  1732.  
  1733. if(!empty($first)) { 
  1734. $price = $first->level_price; 
  1735. if($price == 0) { 
  1736. $price = "Free"; 
  1737. } else { 
  1738.  
  1739. $M_options = get_option('membership_options', array()); 
  1740.  
  1741. switch( $M_options['paymentcurrency'] ) { 
  1742. case "USD": $price = "$" . $price; 
  1743. break; 
  1744.  
  1745. case "GBP": $price = "£" . $price; 
  1746. break; 
  1747.  
  1748. case "EUR": $price = "€" . $price; 
  1749. break; 
  1750.  
  1751. default: $price = apply_filters('membership_currency_symbol_' . $M_options['paymentcurrency'], $M_options['paymentcurrency']) . $price; 
  1752.  
  1753. $html .= $price; 
  1754.  
  1755. if(!empty($wrapwith)) { 
  1756. $html .= "</{$wrapwith}>"; 
  1757.  
  1758. $html .= $postfix; 
  1759. if(!empty($item)) { 
  1760. $html .= "</{$item}>"; 
  1761. if(!empty($holder)) { 
  1762. $html .= "</{$holder}>"; 
  1763.  
  1764. return $html; 
  1765.  
  1766. function do_subscriptionbutton_shortcode($atts, $content = null, $code = "") { 
  1767.  
  1768. global $wp_query, $M_options; 
  1769.  
  1770. $defaults = array( "holder" => '',  
  1771. "holderclass" => '',  
  1772. "item" => '',  
  1773. "itemclass" => '',  
  1774. "postfix" => '',  
  1775. "prefix" => '',  
  1776. "wrapwith" => '',  
  1777. "wrapwithclass" => '',  
  1778. "subscription" => '',  
  1779. "color" => 'blue',  
  1780. 'buttontext' => __('Subscribe', 'membership') 
  1781. ); 
  1782.  
  1783. extract(shortcode_atts($defaults, $atts)); 
  1784.  
  1785. if(isset($M_options['formtype']) && $M_options['formtype'] == 'new') { 
  1786. // pop up form 
  1787. $link = admin_url( 'admin-ajax.php' ); 
  1788. $link .= '?action=buynow&subscription=' . (int) $subscription; 
  1789. $class = 'popover'; 
  1790. } else { 
  1791. // original form 
  1792. $link = M_get_registration_permalink(); 
  1793. $link .= '?action=registeruser&subscription=' . (int) $subscription; 
  1794. $class = ''; 
  1795.  
  1796. if(empty($content)) { 
  1797. $content = $buttontext; 
  1798.  
  1799. $html = "<a href='" . $link . "' class='popover button " . $color . "'>" . $content . "</a>"; 
  1800.  
  1801. //$html = do_shortcode("[button class='popover' link='{$link}']Buy Now[/button]"); 
  1802.  
  1803.  
  1804. return $html; 
  1805.  
  1806. function create_the_user_and_notify() { 
  1807. //$user_id = wp_create_user(sanitize_user($_POST['user_login']), $_POST['password'], $_POST['user_email']); 
  1808. //wp_new_user_notification( $user_id, $_POST['password'] ); 
  1809.  
  1810. function check_for_membership_pages($posts) { 
  1811.  
  1812. global $M_options; 
  1813.  
  1814. if(count($posts) == 1) { 
  1815. // We have only the one post, so check if it's one of our pages 
  1816. $post = $posts[0]; 
  1817. if($post->post_type == 'page') { 
  1818. if($post->ID == $M_options['registration_page']) { 
  1819. // check if page contains a shortcode 
  1820. if(strstr($post->post_content, '[subscriptionform]') !== false) { 
  1821. // There is content in there with the shortcode so just return it 
  1822. return $posts; 
  1823. } else { 
  1824. // registration page found - add in the styles 
  1825. if(!current_theme_supports('membership_subscription_form')) { 
  1826. wp_enqueue_style('subscriptionformcss', membership_url('membershipincludes/css/subscriptionform.css')); 
  1827. wp_enqueue_style('publicformscss', membership_url('membershipincludes/css/publicforms.css')); 
  1828. wp_enqueue_style('buttoncss', membership_url('membershipincludes/css/buttons.css')); 
  1829.  
  1830. if($M_options['formtype'] == 'new') { 
  1831. // pop up registration form 
  1832. wp_enqueue_style('fancyboxcss', membership_url('membershipincludes/js/fancybox/jquery.fancybox-1.3.4.css')); 
  1833. wp_enqueue_script('fancyboxjs', membership_url('membershipincludes/js/fancybox/jquery.fancybox-1.3.4.pack.js'), array('jquery'), false, true); 
  1834.  
  1835. wp_enqueue_script('popupmemjs', membership_url('membershipincludes/js/popupregistration.js'), array('jquery'), false, true); 
  1836. wp_enqueue_style('popupmemcss', membership_url('membershipincludes/css/popupregistration.css')); 
  1837.  
  1838. wp_localize_script('popupmemjs', 'membership', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),  
  1839. 'registernonce' => wp_create_nonce('membership_register'),  
  1840. 'loginnonce' => wp_create_nonce('membership_login'),  
  1841. 'regproblem' => __('Problem with registration.', 'membership'),  
  1842. 'logpropblem' => __('Problem with Login.', 'membership'),  
  1843. 'regmissing' => __('Please ensure you have completed all the fields', 'membership'),  
  1844. 'regnomatch' => __('Please ensure passwords match', 'membership'),  
  1845. 'logmissing' => __('Please ensure you have entered an username or password', 'membership') 
  1846. )); 
  1847.  
  1848. do_action('membership_subscriptionbutton_onpage'); 
  1849. // There is no shortcode content in there, so override 
  1850. remove_filter( 'the_content', 'wpautop' ); 
  1851. $post->post_content .= $this->do_subscription_form(); 
  1852. if($post->ID == $M_options['account_page']) { 
  1853. // account page - check if page contains a shortcode 
  1854. if(strstr($post->post_content, '[accountform]') !== false || strstr($post->post_content, '[upgradeform]') !== false || strstr($post->post_content, '[renewform]') !== false) { 
  1855. // There is content in there with the shortcode so just return it 
  1856. return $posts; 
  1857. } else { 
  1858. // account page found - add in the styles 
  1859. if(!current_theme_supports('membership_account_form')) { 
  1860. wp_enqueue_style('accountformcss', membership_url('membershipincludes/css/accountform.css')); 
  1861. wp_enqueue_script('accountformjs', membership_url('membershipincludes/js/accountform.js'), array('jquery')); 
  1862.  
  1863. wp_enqueue_style('publicformscss', membership_url('membershipincludes/css/publicforms.css')); 
  1864. wp_enqueue_style('buttoncss', membership_url('membershipincludes/css/buttons.css')); 
  1865. // There is no shortcode in there, so override 
  1866. remove_filter( 'the_content', 'wpautop' ); 
  1867. $post->post_content .= $this->do_account_form(); 
  1868. if($post->ID == $M_options['subscriptions_page']) { 
  1869.  
  1870. // Handle any updates passed 
  1871. $page = isset($_REQUEST['action']) ? addslashes($_REQUEST['action']) : ''; 
  1872. if(empty($page)) { 
  1873. $page = 'renewform'; 
  1874.  
  1875. switch($page) { 
  1876. case 'subscriptionsignup': if(is_user_logged_in()) { 
  1877. $member = current_member(); 
  1878. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  1879.  
  1880. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id) ) { 
  1881. $gateway = $_POST['gateway']; 
  1882. // Join the new subscription 
  1883. $member->create_subscription($sub_id, $gateway); 
  1884. do_action('membership_payment_subscr_signup', $user_id, $sub_id); 
  1885. // Timestamp the update 
  1886. update_user_meta( $user_id, '_membership_last_upgraded', time()); 
  1887.  
  1888. // Added another redirect to the same url because the show_no_access filters 
  1889. // have already run on the "parse_request" action (Cole) 
  1890. wp_redirect(M_get_subscription_permalink()); 
  1891. exit; 
  1892. } else { 
  1893. // check if a custom is posted and of so then process the user 
  1894. if(isset($_POST['custom'])) { 
  1895. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  1896.  
  1897. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id) ) { 
  1898. $gateway = $_POST['gateway']; 
  1899. // Join the new subscription 
  1900. $member = new M_Membership( $user_id ); 
  1901. $member->create_subscription($sub_id, $gateway); 
  1902. do_action('membership_payment_subscr_signup', $user_id, $sub_id); 
  1903. // Timestamp the update 
  1904. update_user_meta( $user_id, '_membership_last_upgraded', time()); 
  1905.  
  1906. // Added another redirect to the same url because the show_no_access filters 
  1907. // have already run on the "parse_request" action (Cole) 
  1908. wp_redirect(M_get_subscription_permalink()); 
  1909. exit; 
  1910. break; 
  1911.  
  1912. default: 
  1913. break; 
  1914.  
  1915. // account page - check if page contains a shortcode 
  1916. if(strstr($post->post_content, '[upgradeform]') !== false || strstr($post->post_content, '[renewform]') !== false) { 
  1917. // There is content in there with the shortcode so just return it 
  1918. return $posts; 
  1919. } else { 
  1920. // account page found - add in the styles 
  1921. if(!current_theme_supports('membership_account_form')) { 
  1922. wp_enqueue_style('subscriptionformcss', membership_url('membershipincludes/css/subscriptionform.css')); 
  1923. wp_enqueue_style('upgradeformcss', membership_url('membershipincludes/css/upgradeform.css')); 
  1924. wp_enqueue_style('renewformcss', membership_url('membershipincludes/css/renewform.css')); 
  1925. wp_enqueue_script('renewformjs', membership_url('membershipincludes/js/renewform.js'), array('jquery')); 
  1926. wp_localize_script( 'renewformjs', 'membership', array( 'unsubscribe' => __('Are you sure you want to unsubscribe from this subscription?', 'membership'), 'deactivatelevel' => __('Are you sure you want to deactivate this level?', 'membership') ) ); 
  1927.  
  1928. wp_enqueue_style('publicformscss', membership_url('membershipincludes/css/publicforms.css')); 
  1929. wp_enqueue_style('buttoncss', membership_url('membershipincludes/css/buttons.css')); 
  1930.  
  1931. if($M_options['formtype'] == 'new') { 
  1932. // pop up registration form 
  1933. wp_enqueue_style('fancyboxcss', membership_url('membershipincludes/js/fancybox/jquery.fancybox-1.3.4.css')); 
  1934. wp_enqueue_script('fancyboxjs', membership_url('membershipincludes/js/fancybox/jquery.fancybox-1.3.4.pack.js'), array('jquery'), false, true); 
  1935.  
  1936. wp_enqueue_script('popupmemjs', membership_url('membershipincludes/js/popupregistration.js'), array('jquery'), false, true); 
  1937. wp_enqueue_style('popupmemcss', membership_url('membershipincludes/css/popupregistration.css')); 
  1938.  
  1939. wp_localize_script('popupmemjs', 'membership', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),  
  1940. 'registernonce' => wp_create_nonce('membership_register'),  
  1941. 'loginnonce' => wp_create_nonce('membership_login'),  
  1942. 'regproblem' => __('Problem with registration.', 'membership'),  
  1943. 'logpropblem' => __('Problem with Login.', 'membership'),  
  1944. 'regmissing' => __('Please ensure you have completed all the fields', 'membership'),  
  1945. 'regnomatch' => __('Please ensure passwords match', 'membership'),  
  1946. 'logmissing' => __('Please ensure you have entered an username or password', 'membership') 
  1947. )); 
  1948.  
  1949. // There is no shortcode in there, so override 
  1950. remove_filter( 'the_content', 'wpautop' ); 
  1951. $post->post_content .= $this->do_renew_form(); 
  1952. if($post->ID == $M_options['nocontent_page']) { 
  1953. // no access page - we must return the content entered by the user so just return it 
  1954. return $posts; 
  1955. // Registration complete page 
  1956. if($post->ID == $M_options['registrationcompleted_page']) { 
  1957.  
  1958. // Handle any updates passed 
  1959. if(isset($_REQUEST['action']) && !empty($_REQUEST['action'])) { 
  1960. $page = addslashes($_REQUEST['action']); 
  1961. } else { 
  1962. $page = 'renewform'; 
  1963.  
  1964. switch($page) { 
  1965. case 'subscriptionsignup': 
  1966. if(is_user_logged_in() && isset($_POST['custom'])) { 
  1967. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  1968.  
  1969. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id) ) { 
  1970.  
  1971. $member = current_member(); 
  1972.  
  1973. $gateway = $_POST['gateway']; 
  1974. // Join the new subscription 
  1975. $member->create_subscription($sub_id, $gateway); 
  1976. do_action('membership_payment_subscr_signup', $user_id, $sub_id); 
  1977. // Timestamp the update 
  1978. update_user_meta( $user_id, '_membership_last_upgraded', time()); 
  1979.  
  1980. // Added another redirect to the same url because the show_no_access filters 
  1981. // have already run on the "parse_request" action (Cole) 
  1982. wp_redirect(M_get_returnurl_permalink()); 
  1983. exit; 
  1984. } else { 
  1985.  
  1986.  
  1987. } else { 
  1988. // check if a custom is posted and of so then process the user 
  1989. if(isset($_POST['custom'])) { 
  1990. list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); 
  1991.  
  1992. if( wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id) ) { 
  1993.  
  1994. $gateway = $_POST['gateway']; 
  1995. // Join the new subscription 
  1996. $member = new M_Membership( $user_id ); 
  1997. $member->create_subscription($sub_id, $gateway); 
  1998. do_action('membership_payment_subscr_signup', $user_id, $sub_id); 
  1999. // Timestamp the update 
  2000. update_user_meta( $user_id, '_membership_last_upgraded', time()); 
  2001.  
  2002. // Added another redirect to the same url because the show_no_access filters 
  2003. // have already run on the "parse_request" action (Cole) 
  2004. wp_redirect(M_get_returnurl_permalink()); 
  2005. exit; 
  2006. break; 
  2007.  
  2008. return $posts; 
  2009.  
  2010. // If nothing else is hit, just return the content 
  2011. return $posts; 
  2012.  
  2013. function add_subscription_styles($posts) { 
  2014.  
  2015. global $M_options; 
  2016.  
  2017. foreach($posts as $key => $post) { 
  2018. if(strstr($post->post_content, '[subscriptionform]') !== false) { 
  2019. // The shortcode is in a post on this page, add the header 
  2020. if(!current_theme_supports('membership_subscription_form')) { 
  2021. wp_enqueue_style('subscriptionformcss', membership_url('membershipincludes/css/subscriptionform.css')); 
  2022. wp_enqueue_style('publicformscss', membership_url('membershipincludes/css/publicforms.css')); 
  2023. wp_enqueue_style('fancyboxcss', membership_url('membershipincludes/js/fancybox/jquery.fancybox-1.3.4.css')); 
  2024. wp_enqueue_script('fancyboxjs', membership_url('membershipincludes/js/fancybox/jquery.fancybox-1.3.4.pack.js'), array('jquery'), false, true); 
  2025.  
  2026. wp_enqueue_script('popupmemjs', membership_url('membershipincludes/js/popupregistration.js'), array('jquery'), false, true); 
  2027. wp_enqueue_style('popupmemcss', membership_url('membershipincludes/css/popupregistration.css')); 
  2028.  
  2029. wp_enqueue_style('buttoncss', membership_url('membershipincludes/css/buttons.css')); 
  2030.  
  2031. wp_localize_script('popupmemjs', 'membership', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),  
  2032. 'registernonce' => wp_create_nonce('membership_register'),  
  2033. 'loginnonce' => wp_create_nonce('membership_login'),  
  2034. 'regproblem' => __('Problem with registration.', 'membership'),  
  2035. 'logpropblem' => __('Problem with Login.', 'membership'),  
  2036. 'regmissing' => __('Please ensure you have completed all the fields', 'membership'),  
  2037. 'regnomatch' => __('Please ensure passwords match', 'membership'),  
  2038. 'logmissing' => __('Please ensure you have entered an username or password', 'membership') 
  2039. )); 
  2040.  
  2041. if(strstr($post->post_content, '[accountform]') !== false) { 
  2042. // The shortcode is in a post on this page, add the header 
  2043. if(!current_theme_supports('membership_account_form')) { 
  2044. wp_enqueue_style('accountformcss', membership_url('membershipincludes/css/accountform.css')); 
  2045. wp_enqueue_style('publicformscss', membership_url('membershipincludes/css/publicforms.css')); 
  2046. wp_enqueue_script('accountformjs', membership_url('membershipincludes/js/accountform.js'), array('jquery')); 
  2047. if(strstr($post->post_content, '[upgradeform]') !== false) { 
  2048. // The shortcode is in a post on this page, add the header 
  2049. if(!current_theme_supports('membership_account_form')) { 
  2050. wp_enqueue_style('upgradeformcss', membership_url('membershipincludes/css/upgradeform.css')); 
  2051. wp_enqueue_style('publicformscss', membership_url('membershipincludes/css/publicforms.css')); 
  2052. if(strstr($post->post_content, '[renewform]') !== false) { 
  2053. // The shortcode is in a post on this page, add the header 
  2054. if(!current_theme_supports('membership_account_form')) { 
  2055. wp_enqueue_style('renewformcss', membership_url('membershipincludes/css/renewform.css')); 
  2056. wp_enqueue_style('publicformscss', membership_url('membershipincludes/css/publicforms.css')); 
  2057. wp_enqueue_script('renewformjs', membership_url('membershipincludes/js/renewform.js'), array('jquery')); 
  2058. wp_localize_script( 'renewformjs', 'membership', array( 'unsubscribe' => __('Are you sure you want to unsubscribe from this subscription?', 'membership'), 'deactivatelevel' => __('Are you sure you want to deactivate this level?', 'membership') ) ); 
  2059.  
  2060. // New subscription styles 
  2061. if(strstr($post->post_content, '[subscriptiontitle') !== false) { 
  2062. do_action('membership_subscriptiontitle_onpage'); 
  2063.  
  2064. if(strstr($post->post_content, '[subscriptiondetails') !== false) { 
  2065. do_action('membership_subscriptiondetails_onpage'); 
  2066.  
  2067. if(strstr($post->post_content, '[subscriptionbutton') !== false) { 
  2068. // The shortcode is in a post on this page, add the header 
  2069. if(!current_theme_supports('membership_subscription_form')) { 
  2070. wp_enqueue_style('fancyboxcss', membership_url('membershipincludes/js/fancybox/jquery.fancybox-1.3.4.css')); 
  2071. wp_enqueue_script('fancyboxjs', membership_url('membershipincludes/js/fancybox/jquery.fancybox-1.3.4.pack.js'), array('jquery'), false, true); 
  2072.  
  2073. wp_enqueue_style('buttoncss', membership_url('membershipincludes/css/buttons.css')); 
  2074.  
  2075. if(isset($M_options['formtype']) && $M_options['formtype'] == 'new') { 
  2076. wp_enqueue_script('popupmemjs', membership_url('membershipincludes/js/popupregistration.js'), array('jquery'), false, true); 
  2077. wp_enqueue_style('popupmemcss', membership_url('membershipincludes/css/popupregistration.css')); 
  2078.  
  2079. wp_localize_script('popupmemjs', 'membership', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),  
  2080. 'registernonce' => wp_create_nonce('membership_register'),  
  2081. 'loginnonce' => wp_create_nonce('membership_login'),  
  2082. 'regproblem' => __('Problem with registration.', 'membership'),  
  2083. 'logpropblem' => __('Problem with Login.', 'membership'),  
  2084. 'regmissing' => __('Please ensure you have completed all the fields', 'membership'),  
  2085. 'regnomatch' => __('Please ensure passwords match', 'membership'),  
  2086. 'logmissing' => __('Please ensure you have entered an username or password', 'membership') 
  2087. )); 
  2088.  
  2089.  
  2090. do_action('membership_subscriptionbutton_onpage'); 
  2091.  
  2092. //wp_enqueue_style('upgradeformcss', membership_url('membershipincludes/css/upgradeform.css')); 
  2093.  
  2094. if(strstr($post->post_content, '[subscriptionprice') !== false) { 
  2095. do_action('membership_subscriptionprice_onpage'); 
  2096.  
  2097. return $posts; 
  2098.  
  2099.  
  2100. function pending_username_exists( $username, $email ) { 
  2101.  
  2102. // Initial delete of pending subscriptions 
  2103. $sql = $this->db->prepare( "DELETE FROM {$this->user_queue} WHERE user_timestamp < %d", strtotime('-3 hours') ); 
  2104. $this->db->query( $sql ); 
  2105.  
  2106. // Now check for a pending username that doesn't have the same email address 
  2107. $sql = $this->db->prepare( "SELECT id FROM {$this->user_queue} WHERE user_login = %s AND user_email != %s LIMIT 0, 1", $username, $email ); 
  2108.  
  2109. $res = $this->db->get_var( $sql ); 
  2110. if(!empty($res)) { 
  2111. return true; 
  2112. } else { 
  2113. // because even though the username could exist - if the email address is the same it could just be that they hit the back button. 
  2114. return false; 
  2115.  
  2116.  
  2117. function queue_user( $user_login, $user_pass, $user_email, $user_meta = '' ) { 
  2118.  
  2119. $sql = "INSERT INTO {$this->user_queue} (user_login, user_pass, user_email, user_timestamp, user_meta) VALUES "; 
  2120. $sql .= $this->db->prepare( "( %s, %s, %s, %d, %s )", $user_login, wp_hash_password( $user_pass ), $user_email, time(), serialize($user_meta) ); 
  2121. $sql .= $this->db->prepare( " ON DUPLICATE KEY UPDATE user_timestamp = %d", time()); 
  2122.  
  2123. if( $this->db->query( $sql ) ) { 
  2124. return $this->db->insert_id; 
  2125. } else { 
  2126. return new WP_Error('queueerror', __('Could not create your user account.', 'membership')); 
  2127.  
  2128.  
  2129.  
  2130. //db stuff 
  2131. function get_subscriptions() { 
  2132.  
  2133. $where = array(); 
  2134. $orderby = array(); 
  2135.  
  2136. $where[] = "sub_public = 1"; 
  2137. $where[] = "sub_active = 1"; 
  2138.  
  2139. $orderby[] = 'id ASC'; 
  2140.  
  2141. $sql = "SELECT * FROM {$this->subscriptions}"; 
  2142.  
  2143. if(!empty($where)) { 
  2144. $sql .= " WHERE " . implode(' AND ', $where); 
  2145.  
  2146. if(!empty($orderby)) { 
  2147. $sql .= " ORDER BY " . implode(', ', $orderby); 
  2148.  
  2149. return $this->db->get_results($sql); 
  2150.  
  2151.  
  2152. function get_levels() { 
  2153.  
  2154. $where = array(); 
  2155. $orderby = array(); 
  2156.  
  2157. $where[] = "level_active = 1"; 
  2158.  
  2159. $orderby[] = 'id ASC'; 
  2160.  
  2161. $sql = "SELECT * FROM {$this->membership_levels}"; 
  2162.  
  2163. if(!empty($where)) { 
  2164. $sql .= " WHERE " . implode(' AND ', $where); 
  2165.  
  2166. if(!empty($orderby)) { 
  2167. $sql .= " ORDER BY " . implode(', ', $orderby); 
  2168.  
  2169. return $this->db->get_results($sql); 
  2170.  
  2171.  
  2172. // Level shortcodes function 
  2173. function build_level_shortcode_list( $shortcodes = array() ) { 
  2174.  
  2175. if(!is_array($shortcodes)) { 
  2176. $shortcodes = array(); 
  2177.  
  2178. $levels = $this->get_levels(); 
  2179.  
  2180. if(!empty($levels)) { 
  2181. foreach($levels as $level) { 
  2182. $shortcodes[$level->id] = M_normalize_shortcode($level->level_title); 
  2183.  
  2184. return $shortcodes; 
  2185.  
  2186.  
  2187. function build_not_level_shortcode_list( $shortcodes = array() ) { 
  2188.  
  2189. if(!is_array($shortcodes)) { 
  2190. $shortcodes = array(); 
  2191.  
  2192. $levels = $this->get_levels(); 
  2193.  
  2194. if(!empty($levels)) { 
  2195. foreach($levels as $level) { 
  2196. $shortcodes[$level->id] = 'not-' . M_normalize_shortcode($level->level_title); 
  2197.  
  2198. return $shortcodes; 
  2199.  
  2200.  
  2201.  
  2202. ?> 
.