/** * get posts accessible to member by user id * * @param int user id * @return posts * @verb GET * @action all * @url <site>/mgmapi/members/posts.<format> */ public function posts($id) { global $wpdb; // int $id = (int) $id; // posts $posts = array(); $total_rows = 0; // get member if ($member = mgm_get_member($id)) { // get all subscribed membership types $membership_types = mgm_get_subscribed_membershiptypes($id, $member); // accessible posts $accessible = mgm_get_membership_contents($membership_types, 'accessible', $id); // purchased posts $purchased = mgm_get_purchased_posts($id); // purchasable posts $purchasable = mgm_get_membership_contents($membership_types, 'purchasable', $id); // total rows $total_rows = $accessible['total_posts'] + $purchased['total_posts'] + $purchasable['total_posts']; // posts $posts = array('accessible' => array('contents' => $this->_clean_content($accessible['posts'])), 'purchased' => array('contents' => $this->_clean_content($purchased['posts'])), 'purchasable' => array('contents' => $this->_clean_content($purchasable['posts']))); } // response $response = array('status' => 'success', 'message' => sprintf(__('Get posts accessible to member by member id#%d response', 'mgm'), $id), 'data' => array('total_rows' => $total_rows, 'posts' => $posts)); // return return array($response, 200); }
function mgm_member_purchased_contents($pagetype = 'admin') { global $wpdb; // current_user $current_user = wp_get_current_user(); // snippet $snippet_length = 200; // purchased $purchased_posts = mgm_get_purchased_posts($current_user->ID); // posts $posts = $purchased_posts['posts']; // total_posts $total_posts = $purchased_posts['total_posts']; // total post rows , unfiltered // $total_post_rows = $purchased_posts['total_post_rows']; // init $html = $alt = ''; // start output $html .= '<div class="table width100 br">' . '<div class="row br_bottom">' . '<div class="cell th_div width25 padding10px"><b>' . __('Post Title', 'mgm') . '</b></div>' . '<div class="cell th_div width45 padding10px"><b>' . __('Post Content', 'mgm') . '</b></div>' . '<div class="cell th_div width15 padding10px"><b>' . __('Purchased', 'mgm') . '</b></div>' . '<div class="cell th_div width15 padding10px"><b>' . __('Expiry', 'mgm') . '</b></div>' . '</div>'; // check if ($total_posts > 0) { // loop foreach ($posts as $id => $obj) { // set $published = date('jS F Y', strtotime($obj->post_date)); $purchased = date('jS F Y', strtotime($obj->purchase_dt)); $title = $obj->post_title; $content = $obj->post_content; if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) { $title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($title); $content = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($content); } $content = preg_replace("'\\[/?\\s?private\\s?\\]'i", '', $content); //$content = preg_replace("'\[\[(.*)\]\]'i",'', $content); //issue: 314 $content = preg_replace("/\\[.*?\\]/", '', $content); $content = substr(strip_tags($content), 0, $snippet_length); $content .= strlen($content) > $snippet_length ? '...' : ''; //expiry date: $expiry = mgm_get_post($obj->ID)->get_access_duration(); $expiry = !$expiry ? __('Indefinite', 'mgm') : date('jS F Y', 86400 * $expiry + strtotime($obj->purchase_dt)) . " (" . $expiry . (__(' Day', 'mgm') . ($expiry > 1 ? __('s', 'mgm') : '')) . ")"; $html .= '<div class="row br_bottom ' . ($alt = $alt == '' ? 'alternate' : '') . '">' . '<div class="cell width25 padding10px"><a href="' . get_permalink($obj->ID) . '">' . $title . '</a></div>' . '<div class="cell width45 padding10px">' . $content . '</div>' . '<div class="cell width15 padding10px">' . $purchased . '</div>' . '<div class="cell width15 padding10px">' . $expiry . '</div>' . '</div>'; } } else { $html .= '<div class="row br_bottom' . ($alt = $alt == '' ? 'alternate' : '') . '">' . '<div class="cell mgm_text_align_center">' . __('No purchased contents', 'mgm') . '</div>' . '</div>'; } $html .= '</div>'; //return $html; if ($total_posts > 0) { $html .= '<div class="mgm_margin10px">'; if (isset($_GET['section']) && $_GET['section'] == 'purchased') { $html .= '<div class="mgm_content_back_link_div">' . '<a href="' . ($pagetype == 'admin' ? admin_url('profile.php?page=mgm/membership/content') : mgm_get_custom_url('membership_contents')) . '" class="button">' . __('Back', 'mgm') . '</a>' . '</div>'; } $html .= '<div class="mgm_content_total_post_div">' . sprintf(__('You have purchased a total of %d %s.', 'mgm'), $total_posts, $total_posts == 1 ? __('Post', 'mgm') : __('Posts', 'mgm')) . '</div>'; $html .= '<div class="mgm_content_total_publish_div">'; if (isset($_GET['section']) && $_GET['section'] == 'purchased') { $html .= '<span class="pager">' . $purchased_posts['pager'] . '</span>'; //}elseif($total_post_rows > $total_posts) { //Do not show See All if number of records are <= $total_posts } elseif ($total_posts > count($posts)) { $html .= '<a href="' . ($pagetype == 'admin' ? admin_url('profile.php?page=mgm/membership/content§ion=purchased') : mgm_get_custom_url('membership_contents', false, array('section' => 'purchased'))) . '" class="button">' . __('See All', 'mgm') . '</a>'; } $html .= '</div>'; $html .= '<br/><div class="clearfix"></div>'; $html .= '</div>'; } return $html; }