/**
  * Set the current view
  *
  * @package CollabPress
  * @since 1.2
  */
 function set_current_view()
 {
     if (!empty($this->current_item['task'])) {
         $view = 'task';
     } else {
         if (!empty($this->current_item['task_list'])) {
             $view = 'task_list';
         } else {
             if (!empty($this->current_item['project'])) {
                 $view = 'project';
             } else {
                 $view = 'list';
             }
         }
     }
     $this->current_view = $view;
     // Set the global current view as well
     cp_bp()->current_view = apply_filters('bp_cp_current_group_view', $view);
     // Now let's get the post ID for the currently viewed item
     if (in_array($this->current_view, array('task', 'task_list', 'project'))) {
         // Hackish, but needed for the query
         $post_type_name = 'cp-' . str_replace('_', '-', $this->current_view) . 's';
         $current_item_query = new WP_Query(array('name' => $this->current_item[$view], 'post_type' => $post_type_name));
         if ($current_item_query->have_posts()) {
             $this->current_item_id = $current_item_query->posts[0]->ID;
             $this->current_item_obj = $current_item_query->posts[0];
             $this->current_item_ancestry = cp_bp_get_item_ancestry($this->current_item_obj);
             cp_bp()->current_item_id = $this->current_item_id;
             cp_bp()->current_item_obj = $this->current_item_obj;
             cp_bp()->current_item_ancestry = $this->current_item_ancestry;
         }
     }
 }
Exemple #2
0
function cp_bp_get_item_permalink($item_type = 'project', $item_id, $item_obj = false)
{
    global $post;
    if ('project' == $item_type) {
        $link = cp_bp_get_project_permalink($item_id, $item_obj);
    } else {
        if (!$item_obj) {
            $item_obj = get_post($item_id);
        }
        $item_ancestry = cp_bp_get_item_ancestry($item_obj);
        $slug_chain = array();
        foreach ($item_ancestry->ancestors as $ancestor) {
            // We're getting the project URL from cp_bp_get_project_permalink()
            if ('cp-projects' == $ancestor->type) {
                continue;
            }
            $slug_chain[] = $ancestor->slug;
        }
        $slug_chain = implode('/', $slug_chain);
        $project_id = get_post_meta($item_id, '_cp-project-id', true);
        $project_url = cp_bp_get_project_permalink($project_id);
        $link = $project_url . '/' . $slug_chain;
    }
    return $link;
}