示例#1
0
    		$url .= '&random='.$random_number;
    */
    //Download PDF -Issue #763
    $title = 'EARNIGS REPORT ';
    if (!empty($data[0]['date_start']) && !empty($data[0]['date_start'])) {
        $title .= 'FROM  ' . $data[0]['date_start'] . ' TO ' . $data[0]['date_end'];
    }
    if (!empty($data[0]['member_type'])) {
        if ($data[0]['member_type'] == 'all') {
            $title .= ' FOR ALL MEMBERSHIP TYPES';
        } else {
            $title .= ' FOR ' . strtoupper($data[0]['member_type']) . ' MEMBERSHIP TYPE';
        }
    }
    $system_obj = mgm_get_class('system');
    $currency_symbol = mgm_get_currency_symbols($system_obj->setting['currency']);
    $html = '';
    $html = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
    $html .= '<br/><center>' . $title . '</center><br/><hr />';
    $html .= '<table class="width100">
	<tr>
		<td class="mgm_rp_head">' . __('Date', 'mgm') . ' </td>
		<td class="mgm_rp_head" align="right">' . __('Subscription', 'mgm') . '</td>
		<td class="mgm_rp_head" align="right">' . __('Recurring', 'mgm') . '</td>
		<td class="mgm_rp_head" align="right">' . __('Pay Per Post', 'mgm') . '</td>
		<td class="mgm_rp_head" align="right">' . __('Total Earnings', 'mgm') . ' </td>
	</tr>';
    $s_total = 0;
    $p_total = 0;
    $su_total = 0;
    $pu_total = 0;
function mgm_replace_message_tags($message, $user_id = NULL)
{
    // get user
    if (!$user_id) {
        // cusrrent user
        $current_user = wp_get_current_user();
        // set
        $user_id = $current_user->ID;
    }
    // int
    $logged_in = isset($current_user) && $current_user->ID > 0 ? true : false;
    // user
    if ($user_id > 0) {
        // get user
        $user = get_userdata($user_id);
        // mgm member
        $member = mgm_get_member($user_id);
        // set
        $username = $user->user_login;
        $name = mgm_str_concat($user->first_name, $user->last_name);
        $email = $user->user_email;
        $url = $user->user_url;
        $display_name = $user->display_name;
        $first_name = $user->first_name;
        $last_name = $user->last_name;
        $description = $user->description;
        $nickname = $user->nickname;
        // get active custom fields
        $custom_fields = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true, 'on_profile' => true, 'on_public_profile' => true)));
        // init
        $custom_field_tags = array();
        // loop
        foreach ($custom_fields as $custom_field) {
            // if already set skip it
            if (!isset(${$custom_field['name']}) || isset(${$custom_field['name']}) && empty(${$custom_field['name']})) {
                // check
                if (isset($member->custom_fields->{$custom_field}['name'])) {
                    // skip password always
                    if ($custom_field['name'] == 'password') {
                        continue;
                    }
                    // value
                    $value = $member->custom_fields->{$custom_field}['name'];
                    // country
                    if ($custom_field['name'] == 'country') {
                        $value = mgm_country_from_code($value);
                    }
                    // set
                    $custom_field_tags[$custom_field['name']] = $value;
                }
            }
        }
    } else {
        // get active custom fields
        $custom_fields = mgm_get_class('member_custom_fields')->get_fields_where(array('display' => array('on_register' => true, 'on_profile' => true, 'on_public_profile' => true)));
        // init
        $custom_field_tags = array();
        // loop
        foreach ($custom_fields as $custom_field) {
            // set
            $custom_field_tags[$custom_field['name']] = '';
        }
    }
    /*
     * [[purchase_cost]] = Cost and currency of a purchasable post
     * [[login_register]] = Login or register form
     * [[login_register_links]] = Links for login and register
     * [[login_link]] = Login link only
     * [[facebook_login_button]] = Facebook login button	 
     * [[register_link]] = Register link only
     * [[membership_types]] = A list of membership levels that can see this post/page
     * [[duration]] = number of days that the user will have access for
     * [[username]] = username
     * [[name]] = name / username
     * [[register]] = register form
     */
    // post
    $post_id = get_the_ID();
    // vars
    $system_obj = mgm_get_class('system');
    $currency = $system_obj->setting['currency'];
    $post_obj = mgm_get_post($post_id);
    $duration = $post_obj->get_access_duration();
    if (!$duration) {
        $duration = __('unlimited', 'mgm');
    }
    $purchase_cost = $post_obj->purchase_cost;
    $currency_sign = mgm_get_currency_symbols($system_obj->setting['currency']);
    // these function calls are called repeadtedly as filter is used in multiple places
    // call only when tag present in message
    // [login_register_links]
    if (preg_match('/[[login_register_links]]/', $message)) {
        $login_register_links = !$logged_in ? mgm_get_login_register_links() : '';
    }
    // [login_link]
    if (preg_match('/[[login_link]]/', $message)) {
        $login_link = !$logged_in ? mgm_get_login_link() : '';
    }
    // [facebook_login_button]
    if (preg_match('/[[facebook_login_button]]/', $message)) {
        $facebook_login_button = !$logged_in ? mgm_generate_facebook_login() : '';
    }
    // [register_link]
    if (preg_match('/[[register_link]]/', $message)) {
        $register_link = !$logged_in ? mgm_get_register_link() : '';
    }
    // [login_register]
    if (preg_match('/[[login_register]]/', $message)) {
        $login_register = !$logged_in ? mgm_sidebar_user_login_form(__('Register', 'mgm')) : '';
    }
    // [register]
    if (preg_match('/[[register]]/', $message)) {
        $register = !$logged_in ? mgm_user_register_form() : '';
    }
    // membership type
    if (!($membership_types = $post_obj->get_access_membership_types())) {
        // purchasble
        if (mgm_post_is_purchasable($post_id)) {
            $membership_types = 'Purchasable Only';
        } else {
            // access
            $membership_types = 'No access';
        }
    } else {
        // get object
        $membership_types_obj = mgm_get_class('membership_types');
        // init array
        $ms_types_array = array();
        // loop
        foreach ($membership_types as $membership_type) {
            // set
            if (isset($membership_types_obj->membership_types[$membership_type])) {
                $ms_types_array[] = $membership_types_obj->membership_types[$membership_type];
            }
        }
        // reset
        $membership_types = implode(', ', $ms_types_array);
        // unset
        unset($ms_types_array);
    }
    // loop defined
    $tags = array('purchase_cost', 'login_register', 'login_register_links', 'login_link', 'register_link', 'membership_types', 'duration', 'register', 'username', 'name', 'email', 'url', 'display_name', 'first_name', 'last_name', 'description', 'nickname', 'facebook_login_button', 'currency_sign');
    // loop
    foreach ($tags as $tag) {
        // check
        if (!isset(${$tag})) {
            ${$tag} = '';
        }
        // set
        $message = str_replace('[[' . $tag . ']]', ${$tag}, $message);
    }
    // custom_field_tags
    if (is_array($custom_field_tags)) {
        // loop
        foreach ($custom_field_tags as $tag => $value) {
            // check
            if (!isset($value)) {
                $value = '';
            }
            // set
            $message = str_replace('[[' . $tag . ']]', $value, $message);
        }
    }
    // return
    return $message;
}
    /** 
     * get pack description
     *	
     * @param array $pack
     * @return string $desc
     */
    function get_pack_desc($pack)
    {
        // system
        $system_obj = mgm_get_class('system');
        // format
        $date_fmt = mgm_get_date_format('date_format_short');
        // tpl data
        $tpl_data = array();
        // tpl vars
        $tpl_vars = array('membership_type', 'cost', 'currency', 'duration', 'duration_period', 'num_cycles', 'trial_cost', 'trial_duration', 'trial_duration_period', 'description', 'currency_sign', 'pack_start_date', 'pack_end_date');
        // get template
        if (!($pack_desc_template = $system_obj->get_template('pack_desc_template', array(), true))) {
            $pack_desc_template = sprintf('[membership_type] - [cost] [currency] %s [duration] [duration_period] [num_cycles].<br/> 
										   [if_trial_on] %s [trial_cost] [currency] %s [trial_duration] [trial_duration_period] [/if_trial_on]', __('per', 'mgm'), __('This pack includes a special, limited trial-offer:', 'mgm'), __('for', 'mgm'));
        }
        // lifetime template:
        if ($pack['duration_type'] == 'l') {
            // template	-issue #988
            if (!($pack_desc_template = $system_obj->get_template('pack_desc_lifetime_template', array(), true))) {
                $pack_desc_template = sprintf('[membership_type] - [cost] [currency] %s', __('for Lifetime', 'mgm'));
            }
        } elseif ($pack['duration_type'] == 'dr') {
            $date_range = '';
            // check
            if (mgm_is_valid_date($pack['duration_range_start_dt'], '-') && mgm_is_valid_date($pack['duration_range_end_dt'], '-')) {
                $tpl_data['pack_start_date'] = date($date_fmt, strtotime($pack['duration_range_start_dt']));
                $tpl_data['pack_end_date'] = date($date_fmt, strtotime($pack['duration_range_end_dt']));
            }
            if (!($pack_desc_template = $system_obj->get_template('pack_desc_date_range_template', array(), true))) {
                $pack_desc_template = sprintf('[membership_type] - [cost] [currency] starts from [pack_start_date]  to [pack_end_date]');
            }
        }
        // currency - issue #1602
        if (!isset($pack['currency']) || empty($pack['currency'])) {
            $tpl_data['currency'] = $system_obj->get_setting('currency');
        } else {
            $tpl_data['currency'] = $pack['currency'];
        }
        // issue #1177
        $tpl_data['currency_sign'] = mgm_get_currency_symbols($tpl_data['currency']);
        // type
        $tpl_data['membership_type'] = mgm_stripslashes_deep(mgm_get_class('membership_types')->get_type_name($pack['membership_type']));
        $tpl_data['duration_period'] = strtolower($this->get_pack_duration($pack));
        // transalation issue #950
        $tpl_data['text_for'] = __('for', 'mgm');
        $tpl_data['num_cycles'] = $pack['num_cycles'] == 0 ? __(' - Ongoing', 'mgm') : sprintf(' - %s %d %s', $tpl_data['text_for'], (int) $pack['num_cycles'], $pack['num_cycles'] == 1 ? __('time', 'mgm') : __('times', 'mgm'));
        $tpl_data['trial_duration_period'] = strtolower($this->get_pack_duration($pack, true));
        // merge rest, overwrite tpl_data
        if (is_array($pack)) {
            $tpl_data = array_merge($pack, $tpl_data);
        }
        // remove next lines as preg_replace will fail
        $pack_desc_template = str_replace(array("\r\n", "\n", "\r"), '', $pack_desc_template);
        // copy template
        $pack_desc = $pack_desc_template;
        // replace 0 cost
        if (isset($tpl_data['cost']) && $tpl_data['cost'] == 0.0) {
            $pack_desc = str_replace('[cost] [currency]', __('free', 'mgm'), $pack_desc);
        }
        // replace 0 trial_cost
        if (isset($tpl_data['trial_cost']) && $tpl_data['trial_cost'] == 0.0) {
            $pack_desc = str_replace('[trial_cost] [currency]', __('free', 'mgm'), $pack_desc);
        }
        // replace
        foreach ($tpl_vars as $var) {
            if (isset($tpl_data[$var])) {
                $pack_desc = str_replace('[' . $var . ']', $tpl_data[$var], $pack_desc);
            }
        }
        // num cycles
        if ($pack['num_cycles']) {
            $pack_desc = preg_replace("'\\[/?\\s?if_num_cycles\\s?\\]'i", '', $pack_desc);
        } else {
            $pack_desc = preg_replace("'\\[if_num_cycles\\s?\\](.*)\\[/if_num_cycles\\s?\\]'i", '', $pack_desc);
        }
        // trial on
        if (isset($pack['trial_on']) && (int) $pack['trial_on'] == 1) {
            $pack_desc = preg_replace("'\\[/?\\s?if_trial_on\\s?\\]'i", '', $pack_desc);
        } else {
            $pack_desc = preg_replace("'\\[if_trial_on\\s?\\](.*)\\[/if_trial_on\\s?\\]'i", '', $pack_desc);
        }
        // send
        return $pack_desc;
    }
/**
 * Replace email short tags with contnet 
 *
 * @param string $message and $user_id 
 * @return string $message
 */
function mgm_replace_email_tags($message, $user_id = NULL)
{
    global $wpdb;
    // has user
    if (!$user_id) {
        // cusrrent user
        $current_user = wp_get_current_user();
        // set
        $user_id = $current_user->ID;
    } else {
        // get user
        $current_user = new WP_User($user_id);
    }
    // mgm member
    $member = mgm_get_member($user_id);
    $system_obj = mgm_get_class('system');
    // user
    if ($user_id > 0) {
        // display name
        if (isset($current_user->first_name) && !empty($current_user->first_name)) {
            $name = $current_user->first_name;
        } elseif (isset($member->custom_fields->first_name) && !empty($member->custom_fields->first_name)) {
            $name = $member->custom_fields->first_name;
        } else {
            $name = $current_user->display_name;
        }
        //first name
        if (isset($member->custom_fields->first_name) && !empty($member->custom_fields->first_name)) {
            $first_name = $member->custom_fields->first_name;
        }
        //last name
        if (isset($member->custom_fields->last_name) && !empty($member->custom_fields->last_name)) {
            $last_name = $member->custom_fields->last_name;
        }
        //user name
        $username = $current_user->user_login;
        //password
        $password = mgm_decrypt_password($member->user_password, $user_id);
        //client email
        $email = $current_user->user_email;
        //reason email
        $reason = $member->status_str;
        //expire_date
        $expire_date = $member->expire_date;
        //just fetch the key from db as it is already updated
        $key = $current_user->user_activation_key;
        //passwordlink
        $passwordlink = network_site_url("wp-login.php?action=rp&key={$key}&login=" . rawurlencode($username), 'login');
        //amount email -#issue 1069
        $amount = $member->amount;
        //membership_type email
        $membership_type = $member->membership_type;
    }
    //admin_email
    $admin_email = $system_obj->get_setting('admin_email');
    // blog name
    $blogname = get_option('blogname');
    // siteurl name
    $siteurl = network_site_url();
    //login_url
    $login_url = wp_login_url();
    //loginurl
    $loginurl = mgm_get_custom_url('login');
    // issue #1177
    $currency_sign = mgm_get_currency_symbols($system_obj->setting['currency']);
    //email short tags array
    $tags = array('name', 'username', 'password', 'login_url', 'admin_email', 'email', 'blogname', 'siteurl', 'loginurl', 'reason', 'expire_date', 'passwordlink', 'first_name', 'last_name', 'amount', 'membership_type', 'currency_sign');
    // loop
    foreach ($tags as $tag) {
        // check
        if (!isset(${$tag})) {
            ${$tag} = '';
        }
        // set
        $message = str_replace('[' . $tag . ']', ${$tag}, $message);
    }
    // return
    return $message;
}