예제 #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 function will check the security for the specified term and all parent terms.
  * If security exists, a multi-dimensional array will be returned following the format
  * array( term_id=>array(group_id=>group_name) ), with the first item being the current
  * term and additional items being parents. If no security is present for any ancestor
  * then the function will return false.
  *
  * @global wpdb $wpdb
  *
  * @param int $term_id The id of the post to get permissions for.
  * @param string $taxonomy The name of the taxonomy that needs to be checked
  * @return mixed Returns an array with all the required permissions to access this page. If no security is present, returns false.
  */
 public static function get_term_protection($term_id, $taxonomy)
 {
     //If this branch isn't protected, just stop now and save all that processing power
     if (!CTXPS_Queries::check_term_protection($term_id, $taxonomy)) {
         return false;
     }
     //If we're still going, then it means something above us is protected, so lets get the list of permissions
     global $wpdb;
     $return = array();
     $group_array = array();
     /**Gets the parent id of the current page/post*/
     $parent_id = get_term($term_id, $taxonomy);
     $parent_id = (int) $parent_id->parent;
     /**Gets the ctx_ps_security data for this post (if it exists) - used to determine if this is the topmost secured page*/
     //$amisecure = get_post_meta($postid,'ctx_ps_security',true);
     //1. If I am secure, get my groups
     //if(!empty($amisecure)){
     //Get Group relationship info for this page from wp_ps_security, join wp_posts on postid
     $groups = CTXPS_Queries::get_groups_by_object('term', $term_id, true);
     //If 0 results, dont do anything. Otherwise...
     if (!empty($groups)) {
         foreach ($groups as $group) {
             $group_array[$group->group_id] = $group->group_title;
         }
         unset($group);
     }
     //}
     //Add an item to the array. 'pageid'=>array('groupid','groupname')
     $return[(string) $term_id] = $group_array;
     unset($group_array);
     //2. If I have a parent, recurse
     //Using our earlier results, check post_parent. If it's != 0 then recurse this function, adding the return value to $array
     if ($parent_id != 0) {
         //$recursedArray = CTXPS_Security::get_protection($parentid);
         //$array = array_merge($array,$recursedArray);
         $parent_array = self::get_term_protection($parent_id);
         if (!!$parent_array) {
             $return += $parent_array;
         }
     }
     //3. Return the completed $array
     return $return;
 }
$txt_label_protect = __('Protect Term', 'contexture-page-security');
$txt_prottext = __('Protect this term and any content associated with it.', 'contexture-page-security');
$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::::
';