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); }
/** Content Index/Cart Style pages Running in non cart mode */ function ym_get_all_bundle_buttons($args) { if (!is_user_logged_in()) { global $ym_res; return $ym_res->msg_header . ym_filter_message($ym_res->all_bundles_not_logged_in) . $ym_res->msg_footer; } $hide_purchased = isset($args['hide_purchased']) ? $args['hide_purchased'] : TRUE; $max = isset($args['max']) ? $args['max'] : FALSE; $bundleoffset = isset($_REQUEST['bundleoffset']) ? $_REQUEST['bundleoffset'] : 0; // [ym_buy_bundle] $supported_args = array('gateways', 'hidecoupon', 'list_contents', 'hide_purchased'); $arg_string = ''; foreach ($supported_args as $arg) { if (isset($args[$arg])) { $arg_string .= $arg . '=' . $args[$arg] . ' '; } } $content = ''; global $ym_user; $user_id = $ym_user->ID; // rinse and repeat $bundles = ym_get_bundles(); $count = 0; $bundleoffsetcount = 0; foreach ($bundles as $bundle) { if ($hide_purchased && ym_has_purchased_bundle($bundle->id, $user_id)) { // skip if purchased continue; } $bundleoffsetcount++; if ($bundleoffset && $bundleoffsetcount <= $bundleoffset) { continue; } $content .= '[ym_buy_bundle bundle_id="' . $bundle->id . '" ' . $arg_string . ']' . "\n"; $count++; if ($max && $count >= $max) { // exit it max reached break; } } $total = count($bundles); // pagniate? if ($max) { // paginate $content .= '<p style="overflow: hidden;">'; if ($bundleoffset) { $url = get_permalink(); if (FALSE === strpos($url, '?')) { $url .= '?'; } else { $url .= '&'; } $url .= 'bundleoffset=' . ($bundleoffset - $max); $content .= '<a href="' . $url . '">' . __('Back', 'ym') . '</a> '; } // if ($count == $max) { if ($count + $bundleoffset < $total) { $url = get_permalink(); if (FALSE === strpos($url, '?')) { $url .= '?'; } else { $url .= '&'; } $url .= 'bundleoffset=' . ($bundleoffset + $max); $content .= ' <a href="' . $url . '" class="ym_forward_link">' . __('Forward', 'ym') . '</a>'; } } // and spit return do_shortcode($content); }