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 do_buy_post($postId, $userId, $complete = FALSE) { global $wpdb, $ym_sys; @ym_log_transaction(YM_IPN, $_POST, $userId); $posts = false; $pack = false; if (substr($postId, 0, 6) == 'bundle') { $pack = substr($postId, 6); $postId = false; $posts = array(); } if ($complete) { if ($pack) { @ym_log_transaction(YM_PPP_PACK_PURCHASED, $pack, $userId); if (!ym_has_purchased_bundle($pack, $userId)) { $sql = 'INSERT INTO ' . $wpdb->prefix . 'ym_post_packs_purchased(user_id, pack_id, unixtime, payment_method) VALUES (' . $userId . ', \'' . $pack . '\', UNIX_TIMESTAMP(), \'' . addslashes($this->code) . '\') '; $wpdb->query($sql); } } else { if (strpos($postId, ',') !== false) { // Todo: remove ppp // support old system for the moment // This should switch over to ad hoc?/cart @ym_log_transaction(YM_PPP_PACK_PURCHASED, $postId, $userId); $posts = explode(',', $postId); } else { @ym_log_transaction(YM_PPP_PURCHASED, $postId, $userId); $posts = array($postId); } } $posts = array_unique($posts); foreach ($posts as $post_id) { if (!ym_has_purchased_post($post_id, $userId)) { $sql = 'INSERT INTO ' . $wpdb->prefix . 'posts_purchased(user_id, post_id, unixtime, payment_method) VALUES (' . $userId . ', \'' . $post_id . '\', UNIX_TIMESTAMP(), \'' . addslashes($this->code) . '\') '; $wpdb->query($sql); // logged in logged out email? } } } //Do Return Action $packet = array('user_id' => $userId, 'post_id' => $postId, 'ppack_id' => $pack, 'status' => $complete); if ($complete) { do_action('ym_post_transaction_success', $packet); } else { do_action('ym_post_transaction_failed', $packet); } do_action('ym_gateway_return', $packet); do_action('ym_gateway_return_' . $this->code, $packet); $this->notify_user($packet); }
function ym_gift_post($post_id, $user_id) { global $wpdb; //check if post already purchased if (ym_has_purchased_post($post_id, $user_id)) { return false; } //Insert into Table $sql = 'INSERT INTO ' . $wpdb->prefix . 'posts_purchased (user_id, post_id, unixtime) VALUES (' . $user_id . ', ' . $post_id . ', UNIX_TIMESTAMP())'; if ($wpdb->query($sql)) { do_action('ym_post_gift_post', $post_id, $user_id); return true; } else { return false; } }