private function __construct()
 {
     global $wpdb;
     $this->levels = array();
     $query = "SELECT id FROM " . $wpdb->prefix . "wp_eMember_membership_tbl WHERE id != 1";
     $this->ids = $wpdb->get_col($query);
     foreach ($this->ids as $id) {
         $this->levels[$id] = Emember_Permission::get_instance($id);
     }
 }
 public function __construct($userInfo)
 {
     $level_info = array();
     $current_level = $userInfo->membership_level;
     $more_levels = $userInfo->more_membership_levels;
     $more_levels = is_array($more_levels) ? array_filter($more_levels) : $more_levels;
     $userInfo->more_membership_levels = explode(',', $more_levels);
     $this->primary_level = Emember_Permission::get_instance($userInfo->membership_level);
     $this->secondary_levels = array();
     $config = Emember_Config::getInstance();
     $options = $this->primary_level->get_options();
     if (isset($options['promoted_level_id']) && $options['promoted_level_id'] != -1) {
         $current_subscription_starts = strtotime($userInfo->subscription_starts);
         $sec_levels = $userInfo->more_membership_levels;
         $level_before = $userInfo->membership_level;
         $current_time = time();
         while (1) {
             if ($current_level === $options['promoted_level_id']) {
                 break;
             }
             $promoted_after = trim($options['days_after']);
             if (empty($promoted_after)) {
                 break;
             }
             $d = $promoted_after == 1 ? ' day' : ' days';
             $expires = strtotime(" + " . abs($promoted_after) . $d, $current_subscription_starts);
             if ($expires > $current_time) {
                 break;
             }
             if (!isset($options['promoted_level_id']) || $options['promoted_level_id'] == -1) {
                 break;
             }
             //$current_subscription_starts = $expires;
             $sec_levels[] = $current_level;
             $current_level = $options['promoted_level_id'];
             $this->primary_level = Emember_Permission::get_instance($current_level);
             $options = $this->primary_level->get_options();
         }
         if ($current_level != -1) {
             $level_info['membership_level'] = $current_level;
             //$level_info ['current_subscription_starts'] = date('y-m-d', $current_subscription_starts);
             if ($config->getValue('eMember_enable_secondary_membership')) {
                 $sec_levels = array_unique($sec_levels);
                 $level_info['more_membership_levels'] = implode(',', $sec_levels);
                 $userInfo->more_membership_levels = $sec_levels;
             }
             $userInfo->membership_level = $current_level;
             dbAccess::update(WP_EMEMBER_MEMBERS_TABLE_NAME, 'member_id=' . $userInfo->member_id, $level_info);
             if ($level_info['membership_level'] != $level_before) {
                 do_action('emember_membership_changed', array('member_id' => $userInfo->member_id, 'from_level' => $level_before, 'to_level' => $level_info['membership_level']));
             }
         }
     }
     if ($config->getValue('eMember_enable_secondary_membership')) {
         if (!empty($userInfo->more_membership_levels)) {
             foreach ($userInfo->more_membership_levels as $l) {
                 if (empty($l)) {
                     continue;
                 }
                 $this->secondary_levels[] = Emember_Permission::get_instance($l);
             }
         }
     }
     $my_subcript_period = $this->primary_level->get('subscription_period');
     $my_subscript_unit = $this->primary_level->get('subscription_unit');
     if ($my_subcript_period == 0 && empty($my_subscript_unit)) {
         $type = 'noexpire';
     } else {
         if ($my_subcript_period == 0 && !empty($my_subscript_unit)) {
             $type = 'fixeddate';
             $my_subcript_period = $my_subscript_unit;
         } else {
             $type = 'interval';
             switch ($my_subscript_unit) {
                 case 'Days':
                     break;
                 case 'Weeks':
                     $my_subcript_period = $my_subcript_period * 7;
                     break;
                 case 'Months':
                     $my_subcript_period = $my_subcript_period * 30;
                     break;
                 case 'Years':
                     $my_subcript_period = $my_subcript_period * 365;
                     break;
             }
         }
     }
     $this->subscription_duration = array('duration' => $my_subcript_period, 'type' => $type);
 }
Esempio n. 3
0
function item_list_ajax()
{
    if (!current_user_can('manage_options')) {
        die("Access Forbidden");
    }
    global $wpdb;
    $levelId = $_REQUEST['level'];
    $tab = $_REQUEST['tab'];
    if (emember_is_ajax()) {
        $level = $levelId == 1 ? Emember_Protection::get_instance() : Emember_Permission::get_instance($levelId);
        switch ($tab) {
            case 'pages':
                $args = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 0, 'parent' => -1, 'number' => $_GET['limit'], 'offset' => $_GET['start']);
                $all_pages = get_pages($args);
                $filtered_pages = array();
                foreach ($all_pages as $page) {
                    $page_summary = array();
                    $user_info = get_userdata($page->post_author);
                    $page_summary['protected'] = $level->in_pages($page->ID) ? "checked='checked'" : "";
                    $page_summary['bookmark'] = $level->is_bookmark_disabled($page->ID) ? "checked='checked'" : "";
                    $page_summary['ID'] = $page->ID;
                    $page_summary['date'] = $page->post_date;
                    $page_summary['title'] = $page->post_title;
                    $page_summary['author'] = isset($user_info->user_nicename) ? $user_info->user_nicename : "";
                    $page_summary['status'] = $page->post_status;
                    $filtered_pages[] = $page_summary;
                }
                ob_start();
                include 'views/emember_page_protection_view.php';
                $output = ob_get_contents();
                ob_end_clean();
                echo $output;
                break;
            case 'posts':
                $sql = "SELECT ID,post_date,post_title,post_author, post_type, post_status FROM {$wpdb->posts} ";
                $sql .= " WHERE post_type = 'post' AND post_status = 'publish' LIMIT " . $_REQUEST['start'] . " , " . $_REQUEST['limit'];
                $all_posts = $wpdb->get_results($sql);
                $filtered_posts = array();
                foreach ($all_posts as $post) {
                    //if($post->post_type=='page')continue;
                    $post_summary = array();
                    $user_info = get_userdata($post->post_author);
                    $categories = get_the_category($post->ID);
                    $cat = array();
                    foreach ($categories as $category) {
                        $cat[] = $category->category_nicename;
                    }
                    $post_summary['protected'] = $level->in_posts($post->ID) ? "checked='checked'" : "";
                    $post_summary['bookmark'] = $level->is_bookmark_disabled($post->ID) ? "checked='checked'" : "";
                    $post_summary['ID'] = $post->ID;
                    $post_summary['date'] = $post->post_date;
                    $post_summary['title'] = isset($post->post_title) ? $post->post_title : "";
                    $post_summary['author'] = isset($user_info->user_nicename) ? $user_info->user_nicename : "";
                    $post_summary['categories'] = rawurldecode(implode(' ', $cat));
                    $post_summary['type'] = $post->post_type;
                    $post_summary['status'] = $post->post_status;
                    $filtered_posts[] = $post_summary;
                }
                ob_start();
                include 'views/emember_post_protection_view.php';
                $output = ob_get_contents();
                ob_end_clean();
                echo $output;
                break;
            case 'comments':
                $all_comments = get_comments(array('number' => $_GET['limit'], 'offset' => $_GET['start'], 'status' => 'approve'));
                $filtered_comments = array();
                foreach ($all_comments as $comment) {
                    $comment_summary = array();
                    $comment_summary['protected'] = $level->in_comments($comment->comment_ID) ? "checked='checked'" : "";
                    $comment_summary['ID'] = $comment->comment_ID;
                    $comment_summary['date'] = $comment->comment_date;
                    $comment_summary['author'] = $comment->comment_author;
                    $comment_summary['content'] = $comment->comment_content;
                    $filtered_comments[] = $comment_summary;
                }
                ob_start();
                include 'views/emember_comment_protection_view.php';
                $output = ob_get_contents();
                ob_end_clean();
                echo $output;
                break;
            case 'categories':
                $all_categories = array();
                $all_cat_ids = get_all_category_ids();
                for ($i = $_GET['start']; $i < $_GET['start'] + $_GET['limit'] && !empty($all_cat_ids[$i]); $i++) {
                    $all_categories[] = get_category($all_cat_ids[$i]);
                }
                foreach ($all_categories as $category) {
                    $category_summary = array();
                    $category_summary['protected'] = $level->in_categories($category->term_id) ? "checked='checked'" : "";
                    $category_summary['ID'] = $category->term_id;
                    $category_summary['name'] = $category->name;
                    $category_summary['description'] = $category->description;
                    $category_summary['count'] = $category->count;
                    $filtered_categories[] = $category_summary;
                }
                ob_start();
                include 'views/emember_category_protection_view.php';
                $output = ob_get_contents();
                ob_end_clean();
                echo $output;
                break;
            case 'attachments':
                $sql = "SELECT ID,post_date,post_title,post_author, post_type, post_status FROM {$wpdb->posts} ";
                $sql .= " WHERE post_type = 'attachment' AND post_status = 'inherit' LIMIT " . $_REQUEST['start'] . " , " . $_REQUEST['limit'];
                $all_posts = $wpdb->get_results($sql);
                $filtered_posts = array();
                foreach ($all_posts as $post) {
                    $post_summary = array();
                    $user_info = get_userdata($post->post_author);
                    $post_summary['protected'] = $level->in_attachments($post->ID) ? "checked='checked'" : "";
                    $post_summary['ID'] = $post->ID;
                    $post_summary['date'] = $post->post_date;
                    $post_summary['title'] = isset($post->post_title) ? $post->post_title : "";
                    $post_summary['author'] = isset($user_info->user_nicename) ? $user_info->user_nicename : "";
                    $post_summary['type'] = $post->post_type;
                    $post_summary['status'] = $post->post_status;
                    $filtered_posts[] = $post_summary;
                }
                ob_start();
                include 'views/emember_attachment_protection_view.php';
                $output = ob_get_contents();
                ob_end_clean();
                echo $output;
                break;
            case 'custom-posts':
                $filtered_posts = array();
                $args = array('public' => true, '_builtin' => false);
                $post_types = get_post_types($args);
                $arg = "'" . implode('\',\'', $post_types) . "'";
                if (!empty($arg)) {
                    $sql = "SELECT ID,post_date,post_title,post_author, post_type, post_status FROM {$wpdb->posts} ";
                    $sql .= " WHERE post_type IN (" . $arg . ") AND (post_status='inherit' OR post_status='publish') LIMIT " . $_REQUEST['start'] . " , " . $_REQUEST['limit'];
                    $all_posts = $wpdb->get_results($sql);
                    $filtered_posts = array();
                    foreach ($all_posts as $post) {
                        $post_summary = array();
                        $user_info = get_userdata($post->post_author);
                        $post_summary['protected'] = $level->in_custom_posts($post->ID) ? "checked='checked'" : "";
                        $post_summary['ID'] = $post->ID;
                        $post_summary['date'] = $post->post_date;
                        $post_summary['title'] = isset($post->post_title) ? $post->post_title : "";
                        $post_summary['author'] = isset($user_info->user_nicename) ? $user_info->user_nicename : "";
                        $post_summary['type'] = $post->post_type;
                        $post_summary['status'] = $post->post_status;
                        $filtered_posts[] = $post_summary;
                    }
                }
                ob_start();
                include 'views/emember_custom_protection_view.php';
                $output = ob_get_contents();
                ob_end_clean();
                echo $output;
                break;
        }
    }
    exit(0);
}