コード例 #1
0
 /**
  * CONFIG PACKAGE for groups attached to taxonomy terms
  */
 public function package_taxonomy_term_groups()
 {
     $this->table_conf = array('form_id' => '', 'form_method' => '', 'list_id' => 'ctxps-relationships', 'record_slug' => 'term_group_rec', 'bulk' => 'false', 'no_records' => __('No groups have been added yet.', 'contexture-page-security'), 'actions_col' => 'name');
     $this->bulk_conf = array();
     // Indexed array. Each entry is an assoc array. All values required.
     $this->column_conf = array(array('title' => 'id', 'slug' => 'id', 'class' => 'col-first', 'width' => '30px'), array('title' => __('Name', 'contexture-page-security'), 'slug' => 'name', 'class' => '', 'width' => '300px'), array('title' => __('Description', 'contexture-page-security'), 'slug' => 'description', 'class' => '', 'width' => ''), array('title' => __('Users', 'contexture-page-security'), 'slug' => 'users', 'class' => 'col-last', 'width' => '60px'));
     // Indexed array. Each entry is an associative array. All values required.
     $this->actions_conf = array(array('title' => __('Edit', 'contexture-page-security'), 'tip' => __('Edit this content.', 'contexture-page-security'), 'slug' => 'edit', 'color' => ''), array('title' => __('Remove', 'contexture-page-security'), 'tip' => __('Detach this group from the content.', 'contexture-page-security'), 'slug' => 'trash', 'color' => 'red'));
     //Try to get a tag id (can be called different things in different places)
     $term_id = 0;
     if (isset($_REQUEST['tag_ID'])) {
         $term_id = $_REQUEST['tag_ID'];
     } else {
         if (isset($_REQUEST['content_id'])) {
             $term_id = $_REQUEST['content_id'];
         } else {
             if (isset($_REQUEST['object_id'])) {
                 $term_id = $_REQUEST['object_id'];
             }
         }
     }
     //Get a list of all the groups attached to this term
     $list = CTXPS_Queries::get_groups_by_object('term', $term_id);
     foreach ($list as $record) {
         //Get edit URL
         $edit_url = admin_url("users.php?page=ps_groups_edit&groupid={$record->ID}");
         //Build records
         $this->list_data[] = array('id' => $record->ID, 'columns' => array('id' => $record->ID, 'name' => sprintf('<strong><a href="%s">%s</a></strong>', $edit_url, $record->group_title), 'description' => $record->group_description, 'users' => CTXPS_Queries::count_members($record->ID)), 'actions' => array('edit' => $edit_url, 'trash' => array('onclick' => 'CTXPS_Ajax.removeGroupFromTerm(' . $record->ID . ',jQuery(this))')));
         //End array add
     }
     //End foreach
 }
コード例 #2
0
 /**
  * This tag will output a list of groups attached to the current page.
  *
  * @global wpdb $wpdb
  * @global array $post
  */
 public static function groups_attached($atts)
 {
     global $wpdb, $post;
     //Attribute defaults
     $output = shortcode_atts(array('public' => 'false', 'label' => __('Groups attached to this page:', 'contexture-page-security')), $atts);
     //Create an array of groups that are already attached to the page
     $currentGroups = '';
     foreach (CTXPS_Queries::get_groups_by_post($post->ID) as $curGrp) {
         $currentGroups .= "<li>" . $curGrp->group_title . " (id:{$curGrp->sec_access_id})</li>";
     }
     $currentGroups = empty($currentGroups) ? '<li><em>' . __('No groups attached.', 'contexture-page-security') . '</em></li>' : $currentGroups;
     $return = "<div class=\"ctx-ps-groupvis\"><h3>{$output['label']}</h3><ol>{$currentGroups}</ol></div>";
     if ($output['public'] === 'true') {
         return $return;
     } else {
         return current_user_can('edit_others_posts') ? $return : '';
     }
 }
コード例 #3
0
/**
 * Used for
 */
function gd_display_teacher_groups($user)
{
    if (current_user_can('manage_options')) {
        $user_type = get_user_meta($user->ID, 'rpr_user_type', true);
        $teacher_groups = get_user_meta($user->ID, 'gd_teacher_groups', true);
        if ($user_type === 'Teacher') {
            ?>
        <h3>Great Disease Teacher Groups</h3>
        <p>Select groups that belong to <?php 
            echo $user->display_name;
            ?>
:</p>
        <?php 
            if (class_exists('CTXPS_Queries')) {
                $groups = CTXPS_Queries::get_groups();
                foreach ($groups as $group) {
                    if ($group->ID > 1) {
                        $checked = in_array($group->ID, $teacher_groups) ? 'checked' : '';
                        echo '<input type="checkbox" id="gd-group[]" name="gd-group[]" ' . $checked . ' value="' . $group->ID . '">';
                        echo $group->group_title;
                        echo '<br />';
                    }
                }
            }
            ?>
    <?php 
        }
        // end user type check
    }
}
コード例 #4
0
$txt_addgroup = __('Add group...', 'contexture-page-security');
$txt_subtitle_table = __('Groups With Access', 'contexture-page-security');
/**
 * LOGIC
 ******************************************************************************/
//Determined if this term is protected
$protected_status = CTXPS_Queries::get_term_protection($_REQUEST['tag_ID']);
//Determine how protected status alters display
$echo_protcheck = $protected_status ? 'checked="checked"' : '';
$echo_tlist_style = $protected_status ? 'display:block;' : '';
//Get list of all groups
$all_groups = CTXPS_Queries::get_groups();
//Start with an empty array for $term_groups
$term_groups = CTXPS_Queries::get_groups_by_object('term', $_REQUEST['tag_ID']);
//Build $term_groups manually so that the array index uses id (to make it easier to sort)
$term_groups_simple = CTXPS_Queries::process_group_array($term_groups, 'names');
//Set default option
$ddl_group_opts = sprintf('<option value="0">%s</option>', $txt_addgroup);
//Loop through all groups in the db to populate the drop-down list
foreach ($all_groups as $group) {
    //Generate the option HTML, hiding it if it's already in our $currentGroups array
    $ddl_group_opts .= CTX_Helper::gen('option', array('class' => isset($term_groups_simple[$group->ID]) ? 'detach' : '', 'value' => $group->ID), $group->group_title);
}
//Put all those options into the select box
$selectbox = CTX_Helper::gen('select', array('id' => 'ctxps-grouplist-ddl', 'name' => 'ctxps-grouplist-ddl'), $ddl_group_opts);
/*
echo '<pre>
$avail::::
';
print_r($avail_groups);
echo '
コード例 #5
0
        <p></p>
        <table id="grouptable" class="widefat fixed" cellspacing="0">
            <thead>
                <tr class="thead">
                    <th class="id">id</th>
                    <th class="name">Name</th>
                    <th class="description">Description</th>
                    <th class="user-count">Users</th>
                </tr>
            </thead>
            <tfoot>
                <tr class="thead">
                    <th class="id">id</th>
                    <th class="name">Name</th>
                    <th class="description">Description</th>
                    <th class="user-count">Users</th>
                </tr>
            </tfoot>
            <tbody>
                <?php 
if (CTXPS_Queries::count_groups() == 0) {
    echo CTXPS_Components::render_group_list();
    echo sprintf('<td colspan="4">' . __('You have not created any groups. Please <a href="%s">add a group</a>.', 'contexture-page-security') . '</td>', admin_url('users.php?page=ps_groups_add'));
} else {
    echo CTXPS_Components::render_group_list();
}
?>
            </tbody>
        </table>
    </div>
コード例 #6
0
        $user_type = get_user_meta(get_current_user_id(), 'rpr_user_type', true);
        // set $is_teacher if admin or if user_type === Teacher
        $is_teacher = false;
        if ($user_type === 'Teacher' || current_user_can('manage_options')) {
            $is_teacher = true;
        }
        if ($is_teacher) {
            the_content();
            $teacher_groups = get_user_meta(get_current_user_id(), 'gd_teacher_groups', true);
            if (!empty($teacher_groups) && class_exists('CTXPS_Queries')) {
                $students = array();
                echo '<h1 class="teacher-groups-header">' . $teacher_user->display_name . '\'s class overview:</h1>';
                echo '<div id="teacher-groups">';
                foreach ($teacher_groups as $group_id) {
                    $group_members = CTXPS_Queries::get_group_members($group_id);
                    $group_info = CTXPS_Queries::get_group_info($group_id);
                    $team_page_id = get_option('gd_team_page_id');
                    $team_page_permalink = get_permalink($team_page_id);
                    // A button that will clear a team's progress (delete their posts and the progress they've made)
                    $clear_progress = '<button class="button" id="clear-team-progress" data-teamid="' . $group_id . '">Clear Team Progress</button>';
                    ?>
                                    <div id="<?php 
                    echo $group_info->ID;
                    ?>
" class="gd-tdash-group">
                                        <p><a href="<?php 
                    echo $team_page_permalink;
                    ?>
?team_id=<?php 
                    echo $group_info->ID;
                    ?>
コード例 #7
0
//Table generator packages
/**************************** LOAD CORE CONTROLLERS ***************************/
require_once 'core/CTXPS_App.php';
//Common, reusable classes, methods, functions
require_once 'core/CTXPS_Security.php';
//Most of the permissions-checking code is here
require_once 'core/CTXPS_Ajax.php';
//AJAX-specific methods
require_once 'core/CTXPS_Router.php';
//All requests for views are sent through here
/********************** SPARTAN REQUIREMENT CHECK *****************************/
if (is_admin()) {
    //If we're accessing a WP admin page, check PHP requirements
    CTXPS_Queries::check_php_version();
    //And check that WP 3.2+ is being used
    CTXPS_Queries::check_wp_version();
}
/******************************** HOOKS ***************************************/
// Install new tables (on activate)
register_activation_hook(__FILE__, array('CTXPS_Queries', 'plugin_install'));
// Remove tables from db (on delete)
register_uninstall_hook(__FILE__, array('CTXPS_Queries', 'plugin_delete'));
// Add "Groups" option to "Users" in admin
add_action('admin_menu', array('CTXPS_App', 'admin_screens_init'));
// Add a "Groups" view to a user's user-edit.php page
add_action('edit_user_profile', array('CTXPS_Router', 'user_groups'));
// Add a "Groups" view to a user's profile.php page
add_action('show_user_profile', array('CTXPS_Router', 'user_groups'));
//Add the security box sidebar to the pages section
add_action('admin_init', array('CTXPS_App', 'admin_init'));
//Load localized language files
コード例 #8
0
 /**
  * Creates an "Add to Group" drop-down list to do bulk actions on the users page
  * @return string HTML
  */
 public static function render_bulk_add_to_group()
 {
     $addtogrp = __('Add to group', 'contexture-page-security') . '&hellip;';
     $groups = CTXPS_Queries::get_groups();
     //First, add our default option...
     $html = sprintf('<option value="">%s</option>', $addtogrp);
     //Then, add the rest of our groups as options
     foreach ($groups as $group) {
         if ($group->group_system_id !== 'CPS01') {
             //Dont include Registered Users group
             $html .= CTX_Helper::gen('option', array('value' => $group->ID), $group->group_title);
         }
     }
     //Now, lets wrap that in a select list
     $html = CTX_Helper::gen('select', array('name' => 'psc_group_add', 'id' => 'psc_group_add', 'style' => 'margin-left:5px;margin-right:5px;'), $html);
     //Add a label before the select
     $html = sprintf('<label class="screen-reader-text" for="psc_group_add">%s</label>', $addtogrp) . $html;
     //Add a button after the select
     $html .= sprintf('<input type="button" name="enrollit" id="enrollit" class="button-secondary" value="%s"/>', __('Add', 'contexture-page-security'));
     //Finally, wrap all that in a div and return
     return CTX_Helper::gen('div', array('class' => 'alignleft actions'), $html);
 }
コード例 #9
0
 /**
  * Creates a new group
  *
  * @global wpdb $wpdb
  * @param string $name A short, meaningful name for the group
  * @param string $description A more detailed description for the group
  * @return <type>
  */
 public static function create_group($name, $description)
 {
     global $wpdb;
     if (!CTXPS_Queries::check_group_exists($name)) {
         $current_user = wp_get_current_user();
         if (CTXPS_Queries::add_group($name, $description, $current_user->ID) !== FALSE) {
             return '<div id="message" class="updated"><p>' . __('New group created', 'contexture-page-security') . '</p></div>';
         } else {
             return '<div id="message" class="error below-h2"><p>' . __('Unable to create group. There was an unspecified system error.', 'contexture-page-security') . '</p></div>';
         }
     } else {
         return '<div id="message" class="error below-h2"><p>' . __('Unable to create group. A group with that name already exists.', 'contexture-page-security') . '</p></div>';
     }
 }
コード例 #10
0
            ?>
</h1>
                        <p><?php 
            echo $current_group->group_description;
            ?>
</p>
                    </div>

                    <!-- team members -->
                    <div id="team-<?php 
            echo $team_id;
            ?>
-members" class="team-members">
                        <h2>Team Members:</h2>
                        <?php 
            $members = CTXPS_Queries::get_group_members($team_id);
            $team_members_ids = array();
            // used below in a WP Query
            if (!empty($members)) {
                $roles = get_option('gd-team-roles');
                foreach ($members as $member) {
                    array_push($team_members_ids, $member->ID);
                    $user_info = get_userdata($member->ID);
                    $name = get_the_author_meta('display_name', $member->ID);
                    // Display team role
                    $user_role = (int) get_user_meta($member->ID, 'gd-team-role', true);
                    ?>
                                <div id="member-<?php 
                    echo $member->ID;
                    ?>
" class="team-member">
コード例 #11
0
<?php

if (!current_user_can('delete_users')) {
    wp_die(__('You do not have sufficient permissions to manage options for this site.', 'contexture-page-security'));
}
$groupInfo = CTXPS_Queries::get_group_info($_GET['groupid']);
$groupPageCount = CTXPS_Queries::count_protected($_GET['groupid']);
$actionmessage = '';
$actionmessage2 = '';
if (!empty($_GET['action']) && !empty($_GET['submit']) && $_GET['action'] == "delete" && $_GET['submit'] == "Confirm Deletion") {
    $sqlstatus = CTXPS_Queries::delete_group($_GET['groupid']);
    if (!$sqlstatus) {
        $actionmessage = '<div class="error below-h2"><p>' . __('An error occurred. The group was not fully deleted.', 'contexture-page-security') . '</p></div>';
    } else {
        $actionmessage2 = '<div id="message" class="update below-h2"><p><strong>1</strong> ' . __('group was deleted.', 'contexture-page-security') . ' <a href="' . admin_url() . 'users.php?page=ps_groups">' . __('View all groups', 'contexture-page-security') . ' &gt;&gt;</a></p></div>';
    }
}
コード例 #12
0
            echo '<div id="message" class="error below-h2"><p>' . __('System groups cannot be deleted.', 'contexture-page-security') . ' <a href="' . admin_url() . 'users.php?page=ps_groups">' . __('View all groups', 'contexture-page-security') . ' &gt;&gt;</a></p></div>';
        } else {
            ?>
        <form id="deletegroup" name="deletegroup" method="get" action="">
            <input type="hidden" name="page" value="ps_groups_delete"/>
            <input type="hidden" name="groupid" value="<?php 
            echo $_GET['groupid'];
            ?>
" />
            <input type="hidden" name="action" value="delete" />
            <p>You are about to delete the group <strong><?php 
            echo $groupInfo->group_title;
            ?>
</strong>.</p>
            <p>Deleting this group will affect <strong><?php 
            echo CTXPS_Queries::count_members($groupInfo->ID);
            ?>
</strong> users and <strong><?php 
            echo $groupPageCount;
            ?>
</strong> pages/posts. Are you sure you want to continue?</p>
            <?php 
            wp_nonce_field('delete-group');
            ?>
            <p class="submit">
                <input class="button-secondary" type="submit" value="<?php 
            _e('Confirm Deletion', 'contexture-page-security');
            ?>
" name="submit"/>
            </p>
        </form>
コード例 #13
0
 public static function add_bulk_users_to_group()
 {
     $added_users = 0;
     //ERROR - No users selected!
     if (empty($_REQUEST['users'])) {
         $response = new WP_Ajax_Response(array('what' => 'bulk_enroll', 'action' => 'add_bulk_users_to_group', 'id' => new WP_Error('error', __('No users were selected.', 'contexture-page-security')), 'supplemental' => array('html' => CTXPS_Components::render_wp_message(__('No users were selected.', 'contexture-page-security'), 'error'))));
         $response->send();
     }
     //ERROR - No group selected
     if (empty($_REQUEST['group_id'])) {
         $response = new WP_Ajax_Response(array('what' => 'bulk_enroll', 'action' => 'add_bulk_users_to_group', 'id' => new WP_Error('error', __('No group was selected.', 'contexture-page-security')), 'supplemental' => array('html' => CTXPS_Components::render_wp_message(__('No group was selected.', 'contexture-page-security'), 'error'))));
         $response->send();
     }
     //Loop through all selected users...
     foreach ($_REQUEST['users'] as $user) {
         //Ensure users exists and is isnt already in group
         if (CTXPS_Queries::check_user_exists($user['value']) && !CTXPS_Queries::check_membership($user['value'], $_REQUEST['group_id'])) {
             //Try to add user
             if (CTXPS_Queries::add_membership($user['value'], $_REQUEST['group_id'])) {
                 //increment for added users
                 $added_users++;
             }
         }
     }
     $response = new WP_Ajax_Response(array('what' => 'bulk_enroll', 'action' => 'add_bulk_users_to_group', 'id' => 1, 'data' => '', 'supplemental' => array('html' => CTXPS_Components::render_wp_message(sprintf(__('%d users were enrolled.', 'contexture-page-security'), $added_users), 'updated fade'))));
     $response->send();
 }
コード例 #14
0
        the_title();
        ?>
</h1>
                <div class="content-page-step">
                    <div id="post-thumb-<?php 
        the_ID();
        ?>
" class="post-thumb"><?php 
        the_post_thumbnail(array(100, 100));
        ?>
</php></div>
                    <?php 
        $team_id = 0;
        if (is_user_logged_in()) {
            if (class_exists('CTXPS_Queries')) {
                $groups = CTXPS_Queries::get_groups(get_current_user_id());
                $current_group = new stdClass();
                // get the first group id if there are multiple groups
                if (count($groups) > 0) {
                    $current_group = $groups[0];
                }
                $team_id = $current_group->ID;
            }
        }
        if (is_single() || is_page()) {
            the_content();
        } else {
            the_excerpt();
        }
        $show_choices = true;
        if ($team_id > 0) {
コード例 #15
0
        $newopts['ad_opt_page_replace'] = $_POST['ad-page-replace'] === 'replace' ? 'true' : 'false';
        //Set option for sitewide lockdown
        $newopts['ad_opt_protect_site'] = isset($_POST['ad-protect-site']) ? 'true' : 'false';
        //Set option for redirecting anonymous users to login if accessing restricted content
        $newopts['ad_opt_login_anon'] = isset($_POST['ad-msg-forcelogin']) ? 'true' : 'false';
        //Update the options array
        $saveStatus = CTXPS_Queries::set_options($newopts);
        //If save was successful, show the message
        if (isset($saveStatus)) {
            $updatesettingsMessage = '<div id="message" class="updated below-h2 fade"><p><strong>' . __('Page Security settings saved.', 'contexture-page-security') . '</strong></p></div>';
        }
    }
}
//Get AD messages from options
$ADMsg = get_option('contexture_ps_options');
$ProtPages = CTXPS_Queries::get_protected_posts();
//wp_die($ProtPages);
//Generate ddls with page heirarchy
$pageDDLAuth = wp_dropdown_pages(array('name' => 'ad-page-auth', 'show_option_none' => __('-- Choose Access Denied Page --', 'contexture-page-security'), 'show_option_none_value' => 0, 'selected' => $ADMsg['ad_page_auth_id'], 'echo' => 0, 'exclude' => $ProtPages));
$pageDDLAnon = wp_dropdown_pages(array('name' => 'ad-page-anon', 'show_option_none' => __('-- Choose Access Denied Page --', 'contexture-page-security'), 'show_option_none_value' => 0, 'selected' => $ADMsg['ad_page_anon_id'], 'echo' => 0, 'exclude' => $ProtPages));
//If there aren't any pages that can be used for AD, replace with this helpful message
if (empty($pageDDLAuth)) {
    $pageDDLAuth = sprintf(__('No available pages were found. <a href="%s">Add Page</a>', 'contexture-page-security'), admin_url('post-new.php?post_type=page'));
} else {
    //Only show edit button if something is already selected
    if (!empty($ADMsg['ad_page_anon_id'])) {
        $pageDDLAuth .= sprintf('<a href="%s">%s</a> | ', admin_url('post.php?post=' . $ADMsg['ad_page_auth_id'] . '&action=edit'), __('Edit Page'));
    }
    //Add an "Add Page" button...
    $pageDDLAuth .= sprintf('<a href="%s">%s</a>', admin_url('post-new.php?post_type=page'), __('Add Page'));
}
コード例 #16
0
ファイル: author.php プロジェクト: rafdizzle86/greatdiseases
    echo '<form id="gd-avatar-upload" method="post" enctype="multipart/form-data">';
    echo '<input type="file" name="simple-local-avatar" id="simple-local-avatar" style="display: none;"/>';
    //echo '<input type="submit">';
    echo wp_nonce_field('simple_local_avatar_nonce', '_simple_local_avatar_nonce', false, false);
    echo '</form>';
}
?>
            </div>
            <h1><?php 
printf(__('%s', 'twentytwelve'), get_the_author_meta('display_name', $user_obj->ID));
?>
</h1>
            <?php 
// get the team the user belongs to ...
if (class_exists('CTXPS_Queries')) {
    $groups = CTXPS_Queries::get_groups($user_obj->ID);
    $usr_group = new stdClass();
    if (count($groups) > 0) {
        $usr_group = $groups[0];
    }
    $team_page_id = get_option('gd_team_page_id');
    $team_page_permalink = get_permalink($team_page_id);
    echo '<h1>Team: <a href="' . $team_page_permalink . '?team_id=' . $usr_group->ID . '">' . $usr_group->group_title . '</a></h1>';
    // Display team role
    $roles = get_option('gd-team-roles');
    $user_role = (int) get_user_meta($user_obj->ID, 'gd-team-role', true);
    if (is_array($roles) && isset($roles[$user_role])) {
        echo '<h1>Role: ' . $roles[$user_role] . '</h1>';
    }
}
?>
コード例 #17
0
        /**
         * JS is injected into post.php when action=edit in order to add an asterisk
         * to protected terms. This is very, very, very bad form, but there aren't the
         * necessary hooks to do this server side (well, there is, but its obviously
         * never been used for anything since it's very buggy), so it's either this or
         * nothing. In this case, I side with usability over good coding practices.
         *
         * @param type $term_name
         */
        public static function tag_protected_terms_heirarchal()
        {
            global $current_screen;
            if ($current_screen->base === 'post' && isset($_REQUEST['post'])) {
                ?>
<script type="text/javascript">jQuery(function(){<?php 
                //Get taxonomies for this post
                $taxonomies = get_post_taxonomies($_REQUEST['post']);
                //For each taxonomy, get a list of term ids used for this post
                foreach ($taxonomies as $tax) {
                    //Initialize vars
                    $terms = get_terms($tax);
                    $termlist = array();
                    //Build an array out of the term ids...
                    foreach ($terms as $term) {
                        //...but only if it's protected
                        if (CTXPS_Queries::check_term_protection($term->term_id, $tax)) {
                            $termlist[] = $term->term_id;
                        }
                    }
                    //Join the array into a CSV
                    $termlist = join(',', $termlist);
                    //Generate javascript to add asterisk to protected terms
                    if (!empty($termlist)) {
                        $tarray = "{$tax}_protect";
                        ?>
                        var <?php 
                        echo $tarray;
                        ?>
 = [<?php 
                        echo $termlist;
                        ?>
];
                        for(x in <?php 
                        echo $tarray;
                        ?>
){
                            jQuery('#<?php 
                        echo $tax;
                        ?>
div input[value="'+<?php 
                        echo $tarray;
                        ?>
[x]+'"]').parent().append('*');
                            jQuery('#<?php 
                        echo $tax;
                        ?>
div option[value="'+<?php 
                        echo $tarray;
                        ?>
[x]+'"]').append('*');
                        }
                    <?php 
                    }
                    //So there's no accidental carryovers
                    unset($terms, $termlist);
                }
                ?>
});</script><?php 
            }
            //Nothing to do
            return false;
        }
コード例 #18
0
 /**
  * Recursively checks security for this page/post and it's ancestors. Returns true
  * if any of them are protected or false if none of them are protected.
  *
  * @param int $post_id Optional. The id of the page or post to check. If left null, will try to check current post id from the loop (if available).
  * @param bool $dontcheck Optional. Set to true to prevent automatically checking current post id in the loop (if $post_id is null).
  * @return bool If this page or it's ancestors has the "protected page" flag
  */
 function psc_has_protection($post_id = null, $dontcheck = false)
 {
     global $wpdb, $post;
     //This function is deprecated
     psc_deprecated('CTXPS_Queries::check_section_protection()');
     //If $post_id isnt set, try to get global post id
     if (empty($post_id) && !$dontcheck && isset($post->ID)) {
         $post_id = $post->ID;
     }
     //Fail if the post id isn't numeric
     if (!is_numeric($post_id)) {
         return false;
     }
     //Try to get post meta
     $mymeta = get_post_meta($post_id, 'ctx_ps_security');
     //Check permissions for current page
     if (!empty($mymeta)) {
         return true;
     } else {
         //If this isn't protected, lets see if there's a parent...
         $parent_id = $wpdb->get_var(sprintf('SELECT post_parent FROM %s WHERE `ID` = %s', $wpdb->posts, $post_id));
         //If we have a parent, repeat this check with the parent.
         if ($parent_id != 0) {
             return CTXPS_Queries::check_section_protection($parent_id);
         } else {
             return false;
         }
     }
 }
コード例 #19
0
ファイル: queries.php プロジェクト: slee124565/flh-pvstation
 /**
  * Returns an array with all the groups for which a user has a current, active
  * membership. This takes into account system groups and membership expiration
  * dates.
  *
  * @global wpdb $wpdb
  * @global CTXPSC_Tables $ctxpsdb
  *
  * @param int $user_id The user id of the user to check
  * @param boolean $site_only Optional. If true, array will only include groups with site access.
  *
  * @return array Returns a flat array with all the groups that the specified user is currently a member of.
  */
 public static function get_user_groups($user_id, $site_only = false)
 {
     global $wpdb, $ctxpsdb;
     /**Empty array to be used for building output*/
     $array = array();
     $newArray = array();
     /**Todays date for MySQL comparison*/
     $today = date('Y-m-d');
     /**Assume user is multi-site user*/
     $multisitemember = true;
     //Get membership only if it's not expired
     $query = $wpdb->prepare('SELECT * FROM `' . $ctxpsdb->group_rels . '`
     JOIN `' . $ctxpsdb->groups . '`
         ON `' . $ctxpsdb->group_rels . '`.grel_group_id = `' . $ctxpsdb->groups . '`.ID
     WHERE `' . $ctxpsdb->group_rels . '`.grel_user_id = %s
     AND (grel_expires IS NULL OR grel_expires > %s)', $user_id, $today);
     //If $site_only is true, append extra restriction to query
     if ($site_only) {
         $query .= ' AND (group_site_access = "limited" OR group_site_access = "full")';
     }
     $groups = $wpdb->get_results($query);
     //We only need an ID and a name as a key/value...
     foreach ($groups as $group) {
         $array += array($group->ID => $group->group_title);
     }
     //If multisite is enabled we can better support it...
     if (function_exists('is_user_member_of_blog')) {
         $multisitemember = is_user_member_of_blog($user_id);
     }
     /*** ADD SMART GROUPS (AKA SYSTEM GROUPS ***/
     //Registered Users Smart Group
     if ($user_id != 0 && $multisitemember) {
         //Get the ID for CPS01
         $newArray = CTXPS_Queries::get_system_group('CPS01');
         //Add CPS01 to the current users permissions array
         $array += array($newArray->ID => $newArray->group_title);
     }
     return $array;
 }
コード例 #20
0
                //Make sure user isnt already in the group
                if (CTXPS_Queries::check_membership($AddUserId, $_GET['groupid']) > 0) {
                    $actionmessage = '<div class="error below-h2"><p>' . __('User is already in this group.', 'contexture-page-security') . '</p></div>';
                } else {
                    //Add user to group
                    if (CTXPS_Queries::add_membership($AddUserId, $_GET['groupid']) === false) {
                        $actionmessage = '<div class="error below-h2"><p>' . __('An error occurred. User could not be added to the group.', 'contexture-page-security') . '</p></div>';
                    } else {
                        $actionmessage = sprintf('<div id="message" class="updated below-h2"><p>' . __('User &quot;%s&quot; has been added to the group.', 'contexture-page-security') . '</p></div>', esc_attr($_GET['add-username']));
                    }
                }
            }
            break;
        case 'rmvusr':
            //Remove the user from the group
            if (CTXPS_Queries::delete_membership($_GET['usrid'], $_GET['groupid']) === false) {
                $actionmessage = '<div class="error below-h2"><p>' . __('An error occurred. User could not be removed from group.', 'contexture-page-security') . '</p></div>';
            } else {
                $actionmessage = sprintf('<div id="message" class="updated below-h2"><p>' . __('User &quot;%s&quot; was removed from the group.', 'contexture-page-security') . '</p></div>', esc_attr($_GET['usrname']));
            }
            break;
        default:
            break;
    }
}
$groupInfo = CTXPS_Queries::get_group_info($_GET['groupid']);
if (empty($groupInfo->group_site_access)) {
    $groupInfo->group_site_access = 'none';
}
$dbopts = get_option('contexture_ps_options');
//  if($_GET['page']==='ps_groups_edit') //What was this supposed to do?