/** Content Index/Cart Style pages Running in non cart mode */ function ym_get_all_content_buttons($args, $featured_only = FALSE) { if (!is_user_logged_in()) { global $ym_res; return $ym_res->msg_header . ym_filter_message($ym_res->all_content_not_logged_in) . $ym_res->msg_footer; } $category = isset($args['category']) ? $args['category'] : ''; $hide_purchased = isset($args['hide_purchased']) ? $args['hide_purchased'] : TRUE; $max = isset($args['max']) ? $args['max'] : -1; if (!empty($category) && !is_int($category)) { // get ID $term = get_term_by('name', $category, 'category'); $category = $term->name; } $offset = isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0; $supported_args = array('gateways', 'hidecoupon'); $arg_string = ''; foreach ($supported_args as $arg) { if (isset($args[$arg])) { $arg_string .= $arg . '=' . $args[$arg] . ' '; } } // [ym_buy_content] // get purchaseable posts using stated restrcitions $args = array('numberposts' => -1, 'post_type' => 'any', 'category' => $category, 'meta_key' => '_ym_post_purchasable', 'meta_value' => '1'); if ($featured_only) { // shaun did it on this key only.... even if he did it with a query $args['meta_key'] = '_ym_post_purchasable_featured'; } $posts = get_posts($args); $total = count($posts); $args['numberposts'] = $max; $args['offset'] = $offset; $posts = get_posts($args); $content = ''; global $ym_user; $user_id = $ym_user->ID; // rinse and repeat $count = 0; foreach ($posts as $post) { $post_id = $post->ID; if ($hide_purchased && ym_has_purchased_post($post_id, $user_id)) { // skip if purchased continue; } $content .= '[ym_buy_content post_id="' . $post_id . '" ' . $arg_string . ']' . "\n"; $count++; } // pagniate? if ($max != -1) { // paginate $content .= '<p style="overflow: hidden;">'; if ($offset) { $url = get_permalink(); if (FALSE === strpos($url, '?')) { $url .= '?'; } else { $url .= '&'; } $url .= 'offset=' . ($offset - $max); $content .= '<a href="' . $url . '">' . __('Back', 'ym') . '</a> '; } if ($count + $offset < $total) { $url = get_permalink(); if (FALSE === strpos($url, '?')) { $url .= '?'; } else { $url .= '&'; } $url .= 'offset=' . ($offset + $max); $content .= ' <a href="' . $url . '" class="ym_forward_link">' . __('Forward', 'ym') . '</a>'; } $content .= '</p>'; } // and spit return do_shortcode($content); }
function ym_post_replace($matches, $override_message = false) { get_currentuserinfo(); global $wpdb, $current_user, $ym_res, $ym_sys; //returns nothing in the event of an empty string if ($matches == '') { return ''; } //user has access copes with validation against user level and ppp if (ym_user_has_access()) { $return = '<span class="ym_private_access">' . $matches . '</span>'; } else { //by this time the user does not have access if (!ym_post_is_purchasable()) { if ($current_user->ID == 0) { $return = $ym_res->msg_header . $ym_res->private_text . $ym_res->msg_footer; } else { $return = $ym_res->msg_header . ($override_message ? $override_message : $ym_res->no_access) . $ym_res->msg_footer; } } else { $post_id = get_the_ID(); if ($current_user->ID > 0) { $purchase_limit = get_post_meta($post_id, '_ym_post_purchasable_limit', true); $purchased = ym_post_purchased_count($post_id); if ($purchase_limit && $purchase_limit - $purchased <= 0) { $return = '<div style="margin-bottom:5px;width:100%;">' . $ym_res->msg_header . $ym_res->purchasable_at_limit . $ym_res->msg_footer . '</div>'; } else { // TODO: refactor/split out $cost = get_post_meta($post_id, '_ym_post_purchasable_cost', 1); if ($cost) { $product_id = get_post_meta($post_id, '_ym_post_purchasable_product_id', 1); $title = get_the_title(); $modules = get_option('ym_modules'); $return = '<div style="margin-bottom:5px;width:100%;">' . $ym_res->msg_header . $ym_res->private_text_purchasable . $ym_res->msg_footer . '</div>'; //'<div style="margin-bottom:5px;width:100%;">' . $res->private_text_purchasable . '</div>'; foreach ($modules as $module) { if (in_array($module, array('ym_free'))) { continue; } $obj = new $module(); $button = $obj->gen_buy_now_button($cost, $title, true, $product_id); $return .= "<div style='width:100%;'>" . $button . "</div>"; } } else { $return = '<div style="margin-bottom:5px;width:100%;">' . $ym_res->msg_header . $ym_res->purchasable_pack_only . $ym_res->msg_footer . '</div>'; } } } else { // not logged in $return = '<div style="margin-bottom:5px;width:100%;">' . $ym_res->msg_header . $ym_res->login_first_text . $ym_res->msg_footer . '</div>'; } } $return = '<div class="ym_private_no_access">' . $return . '</div>'; } $return = ym_filter_message($return); return $return; }
/** 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); }