/**
End
*/
function ym_get_user_package_type($user_id = false, $to_lower = false)
{
    if ($user_id) {
        $ym_user = new YourMember_User($user_id);
    } else {
        global $ym_user;
    }
    $acc = $ym_user->account_type;
    if (!$acc && $ym_user->parent_id) {
        // inherit
        $acc = ym_get_user_package_type($ym_user->parent_id, $to_lower);
    }
    if ($to_lower) {
        $acc = strtolower($acc);
    }
    return $acc;
}
function ym_get_user_profile($args = array(), $content = '')
{
    global $current_user, $ym_user, $ym_sys;
    get_current_user();
    $format = get_option('date_format');
    $amount = $ym_user->amount > 0 ? sprintf(__('%1$s %2$s', 'ym'), $ym_user->amount, $ym_user->currency) : '-';
    $last_pay = $ym_user->last_pay_date ? date($format, $ym_user->last_pay_date) : '-';
    $expiry = $ym_user->expire_date ? date($format, $ym_user->expire_date) : '-';
    if (isset($args['show'])) {
        switch ($args['show']) {
            case 'last_pay_date':
                return $last_pay;
            case 'amount':
                return $amount;
            case 'expiry':
                return $expiry;
            case 'package_type':
                return ym_get_user_package_type();
            case 'upgrade':
                $html = '<a href="' . add_query_arg(array('ym_subscribe' => 1, 'ud' => 1, 'username' => $current_user->user_login), get_bloginfo('url')) . '">';
                $html .= $ym_sys->upgrade_downgrade_string;
                $html .= '</a>';
                return $html;
        }
    }
    // check for parent
    if ($ym_user->parent_id) {
        $parent_user = get_user_by('id', $ym_user->parent_id);
        $parent_user = '******' . $parent_user->email . '">' . $parent_user->display_name . '</a>';
        $html = '<p>' . sprintf(__('Your Account is managed by %s', 'ym'), $parent_user) . '</p>';
        return $html;
    }
    $html = '<table width="100%" cellpadding="0" cellspacing="0" border="0" class="form-table widefat">
			<tr>
				<td height="30"><strong>' . __('Last Payment Date:', 'ym') . '</strong></td>
				<td align="left">' . esc_html($last_pay) . '</td>
			</tr>
			<tr class="alternate">
				<td height="30"><strong>' . __('Expiry Date:', 'ym') . '</strong></td>
				<td align="left">' . esc_html($expiry) . '</td>
			</tr>
			<tr>
				<td height="30"><strong>' . __('Package Cost:', 'ym') . '</strong></td>
				<td align="left">' . esc_html($amount) . '</td>
			</tr>
			<tr class="alternate">
				<td height="30"><strong>' . __('Package Type:', 'ym') . '</strong></td>
				<td align="left">' . ym_get_user_package_type() . ' (<a href="' . add_query_arg(array('ym_subscribe' => 1, 'ud' => 1, 'username' => $current_user->user_login), get_bloginfo('url')) . '">';
    $html .= $ym_sys->upgrade_downgrade_string;
    $html .= '</a>)</td>
			</tr>
		</table>';
    return $html;
}
Exemple #3
0
function ym_user_has_access($post_id = false, $user_id = false, $allow_on_purchasable = false)
{
    get_currentuserinfo();
    global $current_user, $user_data, $wpdb, $ym_sys;
    if (isset($_GET['username']) && isset($_GET['password'])) {
        $user = wp_authenticate($_GET['username'], $_GET['password']);
    } else {
        if ($user_id) {
            $user = get_userdata($user_id);
        } else {
            if (ym_get('token') && ym_use_rss_token()) {
                $user = ym_get_user_by_token(ym_get('token'));
            } else {
                $user = $current_user;
            }
        }
    }
    $return = false;
    if (!$post_id) {
        $post_id = get_the_id();
    }
    if ($post_id) {
        $post = get_post($post_id);
        $purchasable = ym_post_is_purchasable($post_id);
        $is_published = $post->post_status == 'publish';
        if ($allow_on_purchasable && $purchasable) {
            $return = true;
        } else {
            if (isset($user->caps['administrator'])) {
                $return = true;
            } else {
                if (!$is_published) {
                    $return = false;
                    // logged out purchase
                    //		} else if (ym_check_ppp_cookie($post_id)) {
                    //			$return = true;
                } else {
                    if ($user->ID > 0 && $purchasable && (ym_has_purchased_post($post_id, $user->ID) || ym_has_purchased_bundle_post_in($post_id, $user->ID))) {
                        $return = true;
                    } else {
                        $types = strtolower(get_post_meta($post_id, '_ym_account_type', true));
                        //Logic check if no YM meta has been applied to the post return TRUE
                        if (!$types) {
                            $return = true;
                        }
                        if (!is_user_logged_in() && $ym_sys->enable_metered) {
                            //metered access check
                            $cookie = stripslashes($_COOKIE['ymmeter']);
                            $cookie = unserialize($cookie);
                            $posts = $cookie['posts'];
                            if (is_array($posts)) {
                                if (in_array($post_id, $posts)) {
                                    $return = true;
                                }
                            }
                            //Check if FCF is enabled (this is a bad thing normally)
                            if ($ym_sys->enable_fcf_metered) {
                                if (stripos($_SERVER[‘HTTP_USER_AGENT’], ‘Googlebot’) !== false) {
                                    $host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
                                    if (stripos($host, 'googlebot') !== false) {
                                        //ok we think this is Google
                                        $metered_act = strtolower($ym_sys->metered_account_types);
                                        $metered_act = explode(';', $metered_act);
                                        $metered_types = explode(';', $types);
                                        foreach ($metered_types as $metered_type) {
                                            if ($metered_type = 'guest') {
                                                $return = true;
                                            } elseif (in_array($metered_type, $meterered_act)) {
                                                $return = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        $uat = ym_get_user_package_type($user->ID, true);
                        //status is implied through the type.
                        if (!$uat) {
                            $uat = 'Guest';
                        }
                        if (in_array($uat, explode(';', $types))) {
                            $return = true;
                            if ($pack_join = get_user_meta($user->ID, 'ym_account_type_join_date', TRUE)) {
                                if ($hide_old_content = get_user_meta($user->ID, 'ym_hide_old_content', TRUE)) {
                                    $post_date = strtotime($post->post_date);
                                    $return = false;
                                    if ($pack_join < $post_date) {
                                        $return = true;
                                    }
                                }
                            }
                        }
                        if ($return == true) {
                            // @TODO re-evaluate what is going on here
                            $new_array = array();
                            $min_dur = get_post_meta($post_id, '_ym_account_min_duration', true);
                            if ($min_dur) {
                                $min_dur = explode(';', $min_dur);
                                foreach ($min_dur as $keyvalues) {
                                    $array = explode('=', $keyvalues);
                                    $new_array[$array[0]] = $array[1];
                                }
                                $min_dur = $new_array;
                                $uat_min_dur = (int) $min_dur[strtolower(str_replace(' ', '_', $uat))];
                                if ($uat_min_dur > 0) {
                                    $reg = $user->user_registered;
                                    if ($sys->post_delay_start == 'pack_join') {
                                        if ($pack_join = get_user_meta($user->ID, 'ym_account_type_join_date', TRUE)) {
                                            $reg = date('Y-m-d', $pack_join);
                                        }
                                    }
                                    $reg = mktime(0, 0, 0, substr($reg, 5, 2), substr($reg, 8, 2), substr($reg, 0, 4));
                                    $user_at = $reg + 86400 * $uat_min_dur;
                                    if ($user_at >= time()) {
                                        $return = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $return = apply_filters('ym_user_has_access_additional', $return, $post_id, $user, $allow_on_purchasable);
    return $return;
}
function ym_get_user_account_type($user_id = false, $to_lower = false)
{
    _deprecated_function(__FUNCTION__, '11.2', 'ym_get_user_package_type');
    return ym_get_user_package_type($user_id, $to_lower);
}
function ym_group_membership_get_counts($user = FALSE)
{
    if ($user) {
        $ym_user = $user;
    } else {
        global $ym_user;
    }
    $current_counts = array();
    foreach ($ym_user->child_ids as $id) {
        // check orphaned
        $child_user = new YourMember_User($id);
        if (!$child_user->valid) {
            // missing user
            unset($ym_user->child_ids[array_search($id, $ym_user->child_ids)]);
            $ym_user->save();
        } else {
            $package_type = ym_get_user_package_type($id);
            if (isset($current_counts[$package_type])) {
                $current_counts[$package_type]++;
            } else {
                $current_counts[$package_type] = 1;
            }
        }
    }
    global $ym_package_types;
    foreach ($ym_package_types->types as $package_type) {
        if (!isset($current_counts[$package_type])) {
            $current_counts[$package_type] = 0;
        }
    }
    return $current_counts;
}