/** * Utility function to get and cache the current doc * * @package BuddyPress Docs * @since 1.0-beta * * @return obj Current doc */ function bp_docs_get_current_doc() { global $bp, $post; if (empty($bp->bp_docs->doc_slug)) { return false; } $doc = false; if (empty($bp->bp_docs->current_post)) { if (bp_docs_has_docs(array('doc_slug' => $bp->bp_docs->doc_slug))) { while (bp_docs_has_docs()) { bp_docs_the_doc(); $doc = $bp->bp_docs->current_post = $post; break; } } } else { $doc = $bp->bp_docs->current_post; } return $doc; }
/** * Render Meta Box content. * * @param WP_Post $post The post object. */ public function render_meta_box_content($post) { // Add an nonce field so we can check for it later. wp_nonce_field($this->meta_box_name, $this->nonce); $meta_field = 'group_story_related_docs'; // Use get_post_meta to retrieve an existing value from the database. $doc_associations = get_post_meta($post->ID, $meta_field, true); // Use true to actually get an unserialized array back // Get candidate docs: must be associated with the group, must be readable by anyone. We can search for docs that are associated with the group, then in the while loop ignore those with privacy not "read:anyone" //This assumes that each group only has one associated category, otherwise we'll have docs crossing over. $category_ids = wp_get_post_terms($post->ID, 'related_groups', array("fields" => "ids")); $group_ids = $this->get_group_ids($category_ids[0]); $docs_args = array('group_id' => $group_ids); echo '<p class="howto">In order to associate a document with a group story, the doc must be able to be read by anyone and be associated with the group that is producing the story.</p>'; if (bp_docs_has_docs($docs_args)) { echo '<ul>'; while (bp_docs_has_docs()) { bp_docs_the_doc(); //Only allow to attach docs that have read set to anyone. // $doc = get_post(); // print_r($doc); $doc_id = get_the_ID(); $settings = bp_docs_get_doc_settings($doc_id); if ($settings['read'] == 'anyone') { ?> <li> <input type="checkbox" id="<?php echo $meta_field; ?> -<?php echo $doc_id; ?> " name="<?php echo $meta_field; ?> []" value="<?php echo $doc_id; ?> " <?php checked(in_array($doc_id, $doc_associations)); ?> /> <label for="<?php echo $meta_field; ?> -<?php echo $doc_id; ?> "><?php the_title(); ?> </label> </li> <?php // the_title(); // echo '<pre>' . PHP_EOL; // print_r($settings); // echo '</pre>'; } } echo '</ul>'; } // Display the form, using the current value. ?> <!-- <label for="<?php echo $meta_field; ?> " class="description"><h4>Featured video URL</h4> <em>e.g.: http://www.youtube.com/watch?v=UueU0-EFido</em></label><br /> <input type="text" id="<?php echo $meta_field; ?> " name="<?php echo $meta_field; ?> " value="<?php echo esc_attr($value); ?> " size="75" /> --> <?php }
/** * Loads the display template * * @since 1.0-beta * * @param int $group_id ID of the current group. Available only in BP 2.2+. */ function display($group_id = null) { global $bp; // Docs are stored on the root blog if (!bp_is_root_blog()) { switch_to_blog(BP_ROOT_BLOG); } switch ($bp->bp_docs->current_view) { case 'create': // Todo: Make sure the user has permission to create /** * Load the template tags for the edit screen */ if (!function_exists('wp_tiny_mce')) { bp_docs_define_tiny_mce(); } require_once BP_DOCS_INCLUDES_PATH . 'templatetags-edit.php'; $template = 'edit-doc.php'; break; case 'list': $template = 'docs-loop.php'; break; case 'category': // Check to make sure the category exists // If not, redirect back to list view with error // Otherwise, get args based on category ID // Then load the loop template break; case 'single': case 'edit': case 'delete': case 'history': // If this is the edit screen, we won't really be able to use a // regular have_posts() loop in the template, so we'll stash the // post in the $bp global for the edit-specific template tags if ($bp->bp_docs->current_view == 'edit') { if (bp_docs_has_docs()) { while (bp_docs_has_docs()) { bp_docs_the_doc(); $bp->bp_docs->current_post = $post; // Set an edit lock wp_set_post_lock($post->ID); } } /** * Load the template tags for the edit screen */ require_once BP_DOCS_INCLUDES_PATH . 'templatetags-edit.php'; } switch ($bp->bp_docs->current_view) { case 'single': $template = 'single/index.php'; break; case 'edit': $template = 'single/edit.php'; break; case 'history': $template = 'single/history.php'; break; } // Todo: Maybe some sort of error if there is no edit permission? break; } // Only register on the root blog if (!bp_is_root_blog()) { restore_current_blog(); } $template_path = bp_docs_locate_template($template); if (!empty($template)) { include apply_filters('bp_docs_template', $template_path, $this); } }
?> "><?php _e('Last Edited', 'bp-docs'); ?> </a> </th> <?php do_action('bp_docs_loop_additional_th'); ?> </tr> </thead> <tbody> <?php while (bp_docs_has_docs()) { bp_docs_the_doc(); ?> <tr> <td> </td> <td class="title-cell"> <a href="<?php bp_docs_doc_link(); ?> "><?php the_title(); ?> </a> <?php
/** * Outputs the content for the current Recent Docs widget instance. * * @since 1.9.0 * @access public * * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance Settings for the current Recent Docs widget instance. */ public function widget($args, $instance) { $bp = buddypress(); // Store the existing doc_query, so ours is made from scratch. $temp_doc_query = isset($bp->bp_docs->doc_query) ? $bp->bp_docs->doc_query : null; $bp->bp_docs->doc_query = null; if (!isset($args['widget_id'])) { $args['widget_id'] = $this->id; } $title = !empty($instance['title']) ? $instance['title'] : __('Recent BuddyPress Docs', 'bp_docs'); /* This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = !empty($instance['number']) ? absint($instance['number']) : 5; if (!$number) { $number = 5; } $show_date = isset($instance['show_date']) ? $instance['show_date'] : false; $doc_args = array('posts_per_page' => $number, 'post_status' => array('publish')); /* If this widget appears on a single user's profile, we want to * limit the returned posts to those started by the displayed user. * If viewing another user's profile, doc access will kick in. */ if (bp_is_user()) { $doc_args['author_id'] = bp_displayed_user_id(); } if (bp_docs_has_docs($doc_args)) { echo $args['before_widget']; if ($title) { echo $args['before_title'] . $title . $args['after_title']; } ?> <ul> <?php while (bp_docs_has_docs()) { bp_docs_the_doc(); ?> <li> <a href="<?php the_permalink(); ?> "><?php get_the_title() ? the_title() : the_ID(); ?> </a> <?php if ($show_date) { ?> <span class="post-date"><?php echo get_the_date(); ?> </span> <?php } ?> </li> <?php } ?> </ul> <?php echo $args['after_widget']; } // Restore the main doc_query; obliterate our secondary loop arguments. $bp->bp_docs->doc_query = $temp_doc_query; }
function ccgn_get_shareable_docs($group_id = null) { $group_id = !$group_id ? bp_get_current_group_id() : $group_id; $docs_args = array('group_id' => $group_id); $good_docs = array(); if (function_exists('bp_docs_has_docs') && bp_docs_has_docs($docs_args)) { while (bp_docs_has_docs()) { bp_docs_the_doc(); //Only allow to attach docs that have read set to anyone. $doc_id = get_the_ID(); $settings = bp_docs_get_doc_settings($doc_id); if ($settings['read'] == 'anyone') { $good_docs[] = array('ID' => $doc_id, 'title' => get_the_title(), 'permalink' => get_the_permalink(), 'info' => 'Doc', 'datetime' => get_the_date('Ymd')); } } } return $good_docs; }