/** * Send Email Notification to Admin * * @uses mgm_mail() * @param string optional $admin_email * @param string $subject * @param string $message * @return bool $send */ function mgm_notify_admin($admin_email = null, $subject = 'You have a notification', $message = 'Notification for Administrator') { // admin email if (!$admin_email) { $admin_email = mgm_get_setting('admin_email'); } // log // mgm_log( sprintf('%s, %s, %s', $admin_email, $subject, $message), __FUNCTION__ ); // send return @mgm_mail($admin_email, $subject, $message); }
/** * the meta box for post/page purchase * */ function mgm_post_setup_meta_box_form($post) { // get object $post_obj = mgm_get_post($post->ID); $datepickerformat = mgm_get_datepicker_format(); // set default price if ($post_obj->purchase_cost == 0) { if (mgm_get_module('mgm_paypal', 'payment')->setting['purchase_price']) { $post_obj->purchase_cost = mgm_get_module('mgm_paypal', 'payment')->setting['purchase_price']; } else { $post_obj->purchase_cost = mgm_get_class('system')->setting['post_purchase_price']; } } // protect $protect_content = mgm_protect_content(); //issue#: 414(changed id submitpost => submitpost_member for the below div ) ?> <div class="submitbox" id="submitpost_member"> <div class="misc-pub-section"> <p id="howto"> <?php _e('Select which membership types will have access to read this post/page.', 'mgm'); ?> <?php _e('Note: The private parts of the post should be inside the following tags: <strong>[private]</strong> <em>your text</em> <strong>[/private]</strong>', 'mgm'); ?> </p> <p> <div class="mgm_post_setup_meta_box_div"> <input type="checkbox" name="check_all" value="mgm_post[access_membership_types][]" /> <span><?php _e('Select all', 'mgm'); ?> </span> </div> </p> <p> <?php echo mgm_make_checkbox_group('mgm_post[access_membership_types][]', mgm_get_class('membership_types')->get_membership_types(), $post_obj->access_membership_types, MGM_KEY_VALUE); ?> </p> <?php if ($protect_content == false) { ?> <div class="information mgm_width_230px"><?php echo sprintf(__('<a href="%s">Content Protection</a> is <b>%s</b>. Make sure its enabled to Protect Post/Page.', 'mgm'), 'admin.php?page=mgm/admin', $protect_content ? 'enabled' : 'disabled'); ?> </div> <?php } ?> </div> <div class="misc-pub-section"> <b><?php _e('Pay Per Post', 'mgm'); ?> :</b> <a href="#payperpost" class="mgm-toggle"><?php _e('Edit'); ?> </a> <div id="payperpostdiv" class="hide-if-js"> <div class="mgm_padding_5px"> <p class="postpurhase-heading"><?php _e('Purchasable Settings', 'mgm'); ?> :</p> <ul class="mgm_post_setup_meta_box_ul"> <li> <label><?php _e('If the user doesn\'t have access, is this post/page available to buy?', 'mgm'); ?> </label><br/> <input type="radio" class="radio" name="mgm_post[purchasable]" value='N' <?php mgm_check_if_match('N', $post_obj->purchasable); ?> /> <label><?php _e('No', 'mgm'); ?> </label> <input type="radio" class="radio" name="mgm_post[purchasable]" value='Y' <?php mgm_check_if_match('Y', $post_obj->purchasable); ?> /> <label><?php _e('Yes', 'mgm'); ?> </label> </li> <li> <label><?php _e('Cost of Post?', 'mgm'); ?> </label><br> <input type="text" name="mgm_post[purchase_cost]" class="mgm_width_55px" value="<?php echo $post_obj->purchase_cost; ?> "/> <?php echo mgm_get_setting('currency'); ?> </li> <li> <label><?php _e('The date that the ability to buy this page/post expires (Leave blank for indefinate).', 'mgm'); ?> </label><br /> <input type="text" name="mgm_post[purchase_expiry]" class="date_input mgm_width_100px" value="<?php echo intval($post_obj->purchase_expiry) > 0 ? date(MGM_DATE_FORMAT_INPUT, strtotime($post_obj->purchase_expiry)) : ''; ?> "/> <span class="mgm_font_size_8px">(<?php echo $datepickerformat; ?> )</span> </li> <li> <label><?php _e('The number of days that the buyer will have access for (0 for indefinate).', 'mgm'); ?> </label><br /> <input type="text" name="mgm_post[access_duration]" class="mgm_width_50px" value="<?php echo $post_obj->get_access_duration(); ?> "/> </li> <li> <label><?php _e('The number of times that the buyer will have access for, "PAY PER VIEW" (0 for unlimited views).', 'mgm'); ?> </label><br /> <input type="text" name="mgm_post[access_view_limit]" class="mgm_width_50px" value="<?php echo $post_obj->get_access_view_limit(); ?> "/> </li> </ul> <?php if ($addons = mgm_get_all_addon_combo()) { ?> <p class="postpurhase-heading"><?php _e('Addon Settings', 'mgm'); ?> :</p> <ul class="mgm_post_setup_meta_box_ul"> <li> <label><?php _e('Allow Addons?', 'mgm'); ?> </label> <br /> <select name="mgm_post[addons][]" class="mgm_width_50px"> <option value="">-</option> <?php echo mgm_make_combo_options($addons, $post_obj->get_addons(), MGM_KEY_VALUE); ?> </select> </li> </ul> <?php } ?> <p class="postpurhase-heading"><?php _e('Payment Settings', 'mgm'); ?> :</p> <p class="fontweightbold"><?php _e('Allow Modules', 'mgm'); ?> :</p> <?php if ($payment_modules = mgm_get_class('system')->get_active_modules('payment')) { $modue_i = 0; foreach ($payment_modules as $payment_module) { if (!in_array($payment_module, array('mgm_trial'))) { ?> <input type="checkbox" name="mgm_post[allowed_modules][<?php echo $modue_i; ?> ]" value="<?php echo $payment_module; ?> " <?php echo in_array($payment_module, $post_obj->get_allowed_modules()) ? 'checked' : ''; ?> /> <label><?php echo mgm_get_module($payment_module)->name; ?> </label><br/> <?php $modue_i++; } } } else { ?> <b class="mgm_color_red"><?php _e('No payment module is active.', 'mgm'); ?> </b> <?php } ?> <?php // init $payment_settings = ''; // product id mapping if ($payment_modules) { foreach ($payment_modules as $payment_module) { if ($module = mgm_is_valid_module($payment_module, 'payment', 'object')) { if ($module->has_product_map()) { $payment_settings .= $module->settings_post_purchase($post_obj); } } } } // print if (!empty($payment_settings)) { echo $payment_settings; } ?> <?php do_action('mgm_widget_payperpost_options', $post->ID); ?> </div> </div> </div> <div class="misc-pub-section misc-pub-section-last"> <b><?php _e('Post Delay (sequential posts)', 'mgm'); ?> :</b> <a href="#postdelay" class="mgm-toggle"><?php _e('Edit'); ?> </a> <div id="postdelaydiv" class="hide-if-js"> <div class="mgm_padding_5px"> <p id="howto"><?php _e('How long should the user have been a member to see this content?', 'mgm'); ?> </p> <div class="div_table mgm_width_100pr"> <?php foreach (mgm_get_class('membership_types')->membership_types as $type_code => $type_name) { $val = isset($post_obj->access_delay[$type_code]) ? (int) $post_obj->access_delay[$type_code] : 0; ?> <div class="row"> <div class="cell mgm_width_100px mgm_font_size_11px"><?php echo $type_name; ?> </div> <div class="cell mgm_font_size_11px"> <input type="text" name="mgm_post[access_delay][<?php echo $type_code; ?> ]" value="<?php echo $val; ?> " class="mgm_width_50px"/> Day(s) </div> </div> <?php } ?> </div> </div> </div> </div> </div> <script language="javascript"> jQuery(document).ready(function(){ jQuery('.mgm-toggle').bind('click', function(){ if(jQuery(this).html() == '<?php _e('Edit', 'mgm'); ?> '){ jQuery(jQuery(this).attr('href')+'div').slideDown(); jQuery(this).html('<?php _e('Close', 'mgm'); ?> ') }else{ jQuery(jQuery(this).attr('href')+'div').slideUp(); jQuery(this).html('<?php _e('Edit', 'mgm'); ?> ') } }); // check bind jQuery("#submitpost_member :checkbox[name='check_all']").bind('click',function(){ // check jQuery("#submitpost_member :checkbox[name='"+jQuery(this).val()+"']").attr('checked', (jQuery(this).attr('checked')=='checked') ); // label if(jQuery(this).attr('checked')){ jQuery(this).next().html('<?php _e('Deselect all', 'mgm'); ?> '); }else{ jQuery(this).next().html('<?php _e('Select all', 'mgm'); ?> '); } }); // bind module allow jQuery(":checkbox[name^='mgm_post[allowed_modules]']").bind('click',function() { var _m = jQuery(this).val().replace('mgm_', ''); if(jQuery(this).attr('checked')){ jQuery('#settings_postpurchase_package_' + _m).slideDown('slow'); }else{ jQuery('#settings_postpurchase_package_' + _m).slideUp('slow'); } }); // date try{ mgm_date_picker('.date_input', false, {yearRange:"<?php echo mgm_get_calendar_year_range(); ?> ", dateFormat: "<?php echo $datepickerformat; ?> "}); }catch(ex){} }); </script> <?php }
/** * override default template * * @param array $column * @param init $post_id * @return void */ function mgm_template_include($template) { // check override if (bool_from_yn(mgm_get_setting('override_theme_for_custom_pages'))) { // name $name = mgm_get_query_var('name'); // switch switch ($name) { case 'register': case 'profile': case 'lost_password': case 'login': $content = mgm_get_query_post_content(); // @todo check #BUG_PENDING // check if (mgm_is_custom_page_published($name, $content)) { // if template exists in theme only if ($c_template = mgm_get_page_template($name, false, true)) { $template = $c_template; } } break; } } // return return $template; }
<?php _e('No members', 'mgm'); ?> </td> </tr> <?php } else { // packs $s_packs = mgm_get_class('subscription_packs'); $m_types = mgm_get_class('membership_types'); $duration_exprs = $s_packs->get_duration_exprs(); // not used $date_format = mgm_get_date_format('date_format'); $date_format_time = mgm_get_date_format('date_format_time'); $email_as_username = bool_from_yn(mgm_get_setting('enable_email_as_username')); // loop users foreach ($data['users'] as $user) { // user object $user = get_userdata($user->ID); // mgm member object $member = mgm_get_member($user->ID); // pack desc, issue #: 509 if (strtolower($member->membership_type) == 'guest') { $pack_desc = __('N/A', 'mgm'); } else { // member data $currency = esc_html($member->currency); $amount = esc_html($member->amount); $duration = esc_html($member->duration); $duration_type = $member->duration_type;
function mgm_login_footer_scripts() { global $wp_version; if (bool_from_yn(mgm_get_setting('enable_email_as_username'))) { ?> <script language="javascript"> jQuery(document).ready(function(){ if ( document.getElementById('loginform') ) document.getElementById('loginform').childNodes[1].childNodes[1].childNodes[0].nodeValue = '<?php echo esc_js(__('Username or Email', 'email-login')); ?> '; }); </script> <?php } }
/** * Getting member purchasable post packs for current user */ function mgm_member_purchasable_postpacks($pagetype = 'admin') { global $wpdb; // current_user $current_user = wp_get_current_user(); // snippet $snippet_length = 200; // purchased $purchasable_postpacks = mgm_get_member_postpacks($current_user->ID, 'purchasable'); // posts $postpacks = $purchasable_postpacks['postpacks']; // total_posts $total_postpacks = $purchasable_postpacks['total_postpacks']; // init $html = $alt = ''; // start output $html .= '<div class="table width100 br">' . '<div class="row br_bottom">' . '<div class="cell th_div width25 padding10px"><b>' . __('Post Pack Title', 'mgm') . '</b></div>' . '<div class="cell th_div width45 padding10px"><b>' . __('Post Pack Description', 'mgm') . '</b></div>' . '<div class="cell th_div width15 padding10px"><b>' . __('Price', 'mgm') . '</b></div>' . '<div class="cell th_div width15 padding10px"><b></b></div>' . '</div>'; // check $currency = mgm_get_setting('currency'); // id, name, description, if ($total_postpacks > 0) { // loop foreach ($postpacks as $id => $obj) { // set $title = $obj->name; $content = $obj->description; if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) { $title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($title); $content = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($content); } $content = preg_replace("'\\[/?\\s?private\\s?\\]'i", '', $content); $content = preg_replace("/\\[.*?\\]/", '', $content); $content = substr(strip_tags($content), 0, $snippet_length); $content .= strlen($content) > $snippet_length ? '...' : ''; $html .= '<div class="row br_bottom ' . ($alt = $alt == '' ? 'alternate' : '') . '">' . '<div class="cell width25 padding10px"><a href="#">' . $title . '</a></div>' . '<div class="cell width45 padding10px">' . $content . '</div>' . '<div class="cell width15 padding10px">' . $obj->cost . ' ' . $currency . '</div>' . '<div class="cell width15 padding10px">' . mgm_get_postpack_purchase_button($obj->id) . '</div>' . '</div>'; } } else { $html .= '<div class="row br_bottom' . ($alt = $alt == '' ? 'alternate' : '') . '">' . '<div class="cell mgm_text_align_center">' . __('No purchased post packs', 'mgm') . '</div>' . '</div>'; } $html .= '</div>'; //return $html; if ($total_postpacks > 0) { $html .= '<div class="mgm_margin10px">'; if (isset($_GET['section']) && $_GET['section'] == 'purchasable_postpacks') { $html .= '<div class="mgm_content_back_link_div">' . '<a href="' . ($pagetype == 'admin' ? admin_url('profile.php?page=mgm/membership/content') : mgm_get_custom_url('membership_contents')) . '" class="button">' . __('Back', 'mgm') . '</a>' . '</div>'; } $html .= '<div class="mgm_content_total_post_div">' . sprintf(__('You have a total of %d %s you can purchase and access.', 'mgm'), $total_postpacks, $total_postpacks == 1 ? __('Post Pack', 'mgm') : __('Post Packs', 'mgm')) . '</div>'; $html .= '<div class="mgm_content_total_publish_div">'; if (isset($_GET['section']) && $_GET['section'] == 'purchasable_postpacks') { $html .= '<span class="pager">' . $purchasable_postpacks['pager'] . '</span>'; //}elseif($total_post_rows > $total_posts) { //Do not show See All if number of records are <= $total_posts } elseif ($total_postpacks > count($postpacks)) { $html .= '<a href="' . ($pagetype == 'admin' ? admin_url('profile.php?page=mgm/membership/content§ion=purchasable_postpacks') : mgm_get_custom_url('membership_contents', false, array('section' => 'purchasable_postpacks'))) . '" class="button">' . __('See All', 'mgm') . '</a>'; } $html .= '</div>'; $html .= '<br/><div class="clearfix"></div>'; $html .= '</div>'; } return $html; }
/** * checks multiple logins from different IPs * * @since 1.8.38 */ function mgm_check_multiple_logins_violation($user, $member, $pack) { global $wpdb; // ip $ip_address = mgm_get_client_ip_address(); // time period $time_period = mgm_get_setting('multiple_login_time_span'); // 1 HOUR // datetime $current_time = strtotime(current_time('mysql', 1)); // last time $last_time = strtotime('-' . $time_period, $current_time); // sql $sql = "SELECT COUNT(*) AS _C FROM `" . TBL_MGM_MULTIPLE_LOGIN_RECORDS . "` WHERE 1\r\r\n\t AND `user_id`='{$user->ID}' AND `pack_id`='{$member->pack_id}' AND `logout_at` IS NULL\r\r\n\t AND `login_at` >= FROM_UNIXTIME({$last_time}) AND `login_at` <= FROM_UNIXTIME({$current_time})"; // check $login_count = $wpdb->get_var($sql); // check // mgm_log( $pack, __FUNCTION__); // check if (isset($pack['multiple_logins_limit']) && (int) $pack['multiple_logins_limit'] > 0) { if ($login_count >= (int) $pack['multiple_logins_limit']) { return true; // error } } // check // mgm_log( $wpdb->last_query .' -- LOGIN COUNT: ' . $login_count, __FUNCTION__); // insert only if not done yet $sql = "SELECT COUNT(*) AS _C FROM `" . TBL_MGM_MULTIPLE_LOGIN_RECORDS . "` WHERE \r\r\n\t `user_id`='{$user->ID}' AND `pack_id`='{$member->pack_id}' AND `ip_address`='{$ip_address}'"; $count = $wpdb->get_var($sql); // check // mgm_log( $wpdb->last_query .' -- PREV RECORD COUNT: ' . $count, __FUNCTION__); // record if ($count == 0) { // first $sql = "INSERT INTO `" . TBL_MGM_MULTIPLE_LOGIN_RECORDS . "` SET `user_id`='{$user->ID}',\r\r\n\t\t `pack_id`='{$member->pack_id}',`ip_address`='{$ip_address}',`login_at`=NOW(),\r\r\n\t\t `logout_at`=NULL"; } else { // next $sql = "UPDATE `" . TBL_MGM_MULTIPLE_LOGIN_RECORDS . "` SET `login_at`=NOW(),\r\r\n\t\t `logout_at`=NULL WHERE `user_id`='{$user->ID}' AND `pack_id`='{$member->pack_id}' \r\r\n\t\t AND `ip_address`='{$ip_address}'"; } // execute $wpdb->query($sql); // check // mgm_log( $wpdb->last_query, __FUNCTION__); // return return false; }
/** * Check transaction page content is to be loaded if buddypress and mgm shares registration page. */ function mgm_is_bp_registration() { // If Buddypress is enabled if (mgm_is_plugin_active('buddypress/bp-loader.php')) { // If setting is enabled - is registration urls same for BP and MGM if (bool_from_yn(mgm_get_setting('share_registration_url_with_bp'))) { // if current url is registration url and transaction page is to be loaded if (false !== strpos(mgm_current_url(), untrailingslashit(mgm_get_setting('register_url'))) && isset($_GET['method']) && preg_match('/^payment/', $_GET['method'])) { return true; } } } return false; }
/** * custom login form, used in sidebar * * @param string $register_text * @param string $lostpassword_text * @return string $form */ function mgm_sidebar_user_login_form($register_text = '', $lostpassword_text = '') { // system $system_obj = mgm_get_class('system'); // email as username if (bool_from_yn($system_obj->get_setting('enable_email_as_username'))) { $email_username_label = __('Email', 'mgm'); } else { $email_username_label = __('Username', 'mgm'); } // form action $form_action = mgm_get_custom_url('login'); // build html $html = '<div class="mgm-sidebar-loginform-wrap"> <form class="mgm_form" name="mgm_sidebar_loginform" id="mgm_sidebar_loginform" action="' . $form_action . '" method="post"> <label>' . $email_username_label . ':</label> <div> <input type="text" name="log" id="user_login" class="input" value="" tabindex="10" size="20" /> </div> <label>' . __('Password', 'mgm') . ':</label> <div> <input type="password" name="pwd" id="user_pass" class="input" value="" tabindex="20" size="20"/> </div>'; // add captcha if ($captcha = mgm_get_form_captcha()) { $html .= sprintf('<div>%s</div>', $captcha); } // login form, fetch as return // do_action('login_form'); // custom code attach $html .= apply_filters('mgm_login_form', $html); $html .= ' <div> <div id="remember_me_container"> <input id="rememberme" type="checkbox" tabindex="90" value="forever" name="rememberme"/> ' . __('Remember Me', 'mgm') . ' </div>'; // buttons $buttons = array(sprintf('<input class="button mgm-login-button" type="submit" name="wp-submit" id="wp-submit" value="%s" tabindex="100" />', __('Log In', 'mgm'))); // apply filters $buttons_s = implode(apply_filters('mgm_login_form_buttons_sep', ' '), apply_filters('mgm_login_form_buttons', $buttons)); // append $html .= sprintf('<div class="login-sidebar-buttons">%s</div>', $buttons_s); // post redirection if (bool_from_yn(mgm_get_setting('enable_post_url_redirection'))) { $html .= ' <input type="hidden" name="redirect_to" value="' . get_permalink() . '" />'; } // nonce $html .= wp_nonce_field('user_login', '_mgmnonce_user_login', true, false); // html $html .= '</div></form>'; // after links $links = array(); // register link if (get_option('users_can_register')) { // has text if ($register_text) { // get urls from settings $links[] = sprintf('<a class="mgm-register-link" href="%s">%s</a>', mgm_get_custom_url('register'), $register_text); } } // lostpassword link if ($lostpassword_text) { // get urls from settings $links[] = sprintf('<a class="mgm-lostpassword-link" href="%s">%s</a>', mgm_get_custom_url('lostpassword'), $lostpassword_text); } // apply filters $links_s = implode(apply_filters('mgm_login_form_after_links_sep', ' | '), apply_filters('mgm_login_form_after_links', $links)); // appaend $html .= sprintf('<div class="login-sidebar-links">%s</div>', $links_s); // end wrap $html .= '</div>'; // scripts & styles -------------------- // focus $focus = 'user_login'; // script // $script = 'function wp_attempt_focus(){setTimeout( function(){ try{ d = document.getElementById("'.$focus.'"); d.focus();} catch(e){}}, 200);}'; // focus // if ( @!$error ) { // $script .= 'wp_attempt_focus();'; // } $script = ''; // script $script = sprintf('<script type="text/javascript">%s</script>', apply_filters('mgm_login_form_inline_script', $script)); // scripts $html .= apply_filters('mgm_login_form_scripts', $script); // style $style = '.login-sidebar-links, .login-sidebar-buttons{margin-top:10px; clear:both}'; // style $style = sprintf('<style type="text/css">%s</style>', apply_filters('mgm_login_form_inline_style', $style)); // style $html .= apply_filters('mgm_login_form_styles', $style); // apply filters and return return apply_filters('mgm_sidebar_login_form_html', $html); }