membershippublic

The Membership 2 membershippublic class.

Defined (1)

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

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