/** * Possibly intercept the template being loaded * * Listens to the 'template_include' filter and waits for a BP Docs post_type * to appear. When one is found, we look to see whether the current theme provides * its own version of the template; otherwise we fall back on the template shipped * with BuddyPress Docs. * * @since 1.2 * * @param string $template * * @return string The path to the template file that is being used */ function bp_docs_template_include($template = '') { if (bp_docs_is_single_doc() && ($new_template = bp_docs_locate_template('single-bp_doc.php'))) { } elseif (bp_docs_is_doc_create() && ($new_template = bp_docs_locate_template('single-bp_doc.php'))) { } elseif (is_post_type_archive(bp_docs_get_post_type_name()) && ($new_template = bp_docs_locate_template('archive-bp_doc.php'))) { } // Custom template file exists $template = !empty($new_template) ? $new_template : $template; return apply_filters('bp_docs_template_include', $template); }
/** * Loads styles * * @package BuddyPress Docs * @since 1.0-beta */ function enqueue_styles() { global $bp; // Load the main CSS only on the proper pages if (in_array(bp_docs_get_docs_slug(), $this->slugstocheck) || bp_docs_is_docs_component()) { wp_enqueue_style('bp-docs-css', $this->includes_url . 'css/screen.css'); } if (bp_docs_is_doc_edit() || bp_docs_is_doc_create()) { wp_enqueue_style('bp-docs-edit-css', $this->includes_url . 'css/edit.css'); wp_enqueue_style('thickbox'); } }
/** * Nach dem speichern eines neuen Artikels nicht automatisch auf die Lesen Seite wechseln. */ function rw_bp_docs_redirect_fallback($status, $url) { if (function_exists('bp_docs_is_doc_create') && bp_docs_is_doc_create() && !empty($_POST['doc-edit-submit'])) { header("Location: " . $url . '/edit', true, $status); die; } return $status; }
/** * Add the meta box to the edit page. * * @since 1.9 */ function bp_docs_folders_meta_box() { $doc_id = get_the_ID(); $associated_group_id = bp_is_active('groups') ? bp_docs_get_associated_group_id($doc_id) : 0; if (!$associated_group_id && isset($_GET['group'])) { $group_id = BP_Groups_Group::get_id_from_slug(urldecode($_GET['group'])); if (current_user_can('bp_docs_associate_with_group', $group_id)) { $associated_group_id = $group_id; } } // On the Create screen, respect the 'folder' $_GET param if (bp_docs_is_doc_create()) { $folder_id = bp_docs_get_current_folder_id(); } else { $folder_id = bp_docs_get_doc_folder($doc_id); } ?> <div id="doc-folders" class="doc-meta-box"> <div class="toggleable <?php bp_docs_toggleable_open_or_closed_class(); ?> "> <p id="folders-toggle-edit" class="toggle-switch"> <span class="hide-if-js toggle-link-no-js"><?php _e('Folders', 'bp-docs'); ?> </span> <a class="hide-if-no-js toggle-link" id="folders-toggle-link" href="#"><span class="show-pane plus-or-minus"></span><span class="toggle-title"><?php _e('Folders', 'bp-docs'); ?> </span></a> </p> <div class="toggle-content"> <table class="toggle-table" id="toggle-table-tags"> <tr> <td class="desc-column"> <label for="bp_docs_tag"><?php _e('Select a folder for this Doc.', 'bp-docs'); ?> </label> </td> <td> <div class="existing-or-new-selector"> <input type="radio" name="existing-or-new-folder" id="use-existing-folder" value="existing" checked="checked" /> <label for="use-existing-folder" class="radio-label"><?php _e('Use an existing folder', 'bp-docs'); ?> </label><br /> <div class="selector-content"> <?php bp_docs_folder_selector(array('name' => 'bp-docs-folder', 'id' => 'bp-docs-folder', 'group_id' => $associated_group_id, 'selected' => $folder_id)); ?> </div> </div> <div class="existing-or-new-selector" id="new-folder-block"> <input type="radio" name="existing-or-new-folder" id="create-new-folder" value="new" /> <label for="create-new-folder" class="radio-label"><?php _e('Create a new folder', 'bp-docs'); ?> </label> <div class="selector-content"> <?php bp_docs_create_new_folder_markup(array('group_id' => $associated_group_id, 'selected' => $associated_group_id)); ?> </div><!-- .selector-content --> </div> </td> </tr> </table> </div> </div> </div> <?php }
/** * Give users the 'upload_files' cap, when appropriate * * @since 1.4 * * @param array $caps The mapped caps * @param string $cap The cap being mapped * @param int $user_id The user id in question * @param $args * @return array $caps */ public static function map_meta_cap($caps, $cap, $user_id, $args) { if ('upload_files' !== $cap) { return $caps; } $maybe_user = new WP_User($user_id); if (!is_a($maybe_user, 'WP_User') || empty($maybe_user->ID)) { return $caps; } $is_doc = false; // DOING_AJAX is not set yet, so we cheat $is_ajax = isset($_SERVER['REQUEST_METHOD']) && 'POST' === $_SERVER['REQUEST_METHOD'] && 'async-upload.php' === substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '/') + 1); if ($is_ajax) { // Clean up referer $referer = $_SERVER['HTTP_REFERER']; $qp = strpos($referer, '?'); if (false !== $qp) { $referer = substr($referer, 0, $qp); } $referer = trailingslashit($referer); // Existing Doc $item_id = self::get_doc_id_from_url($referer); if ($item_id) { $item = get_post($item_id); $is_doc = bp_docs_get_post_type_name() === $item->post_type; } // Create Doc if (!$is_doc) { $is_doc = $referer === bp_docs_get_create_link(); } } else { $is_doc = bp_docs_is_existing_doc() || bp_docs_is_doc_create(); } if ($is_doc) { $caps = array('exist'); // Since we've already done the permissions check, // we can filter future current_user_can() checks on // this pageload add_filter('map_meta_cap', array(__CLASS__, 'map_meta_cap_supp'), 10, 4); } return $caps; }
/** * Protects group docs from unauthorized access * * @since 1.2 */ function protect_doc_access() { // What is the user trying to do? if (bp_docs_is_doc_read()) { $action = 'bp_docs_read'; } else { if (bp_docs_is_doc_create()) { $action = 'bp_docs_create'; } else { if (bp_docs_is_doc_edit()) { $action = 'bp_docs_edit'; } else { if (bp_docs_is_doc_history()) { $action = 'bp_docs_view_history'; } } } } if (!isset($action)) { return; } if (!current_user_can($action)) { $redirect_to = bp_docs_get_doc_link(); bp_core_no_access(array('mode' => 2, 'redirect' => $redirect_to)); } }
/** * Determine whether a user can edit the group doc in question * * @since 1.0-beta * * @param bool $user_can The default perms passed from bp_docs_user_can_edit() * @param str $action At the moment, 'edit', 'manage', 'create', 'read' * @param int $user_id The user id whose perms are being tested * @param int $doc_id Optional. The id of the doc being checked. Defaults to current */ function user_can($user_can, $action, $user_id, $doc_id = false) { global $bp, $post; // If a doc_id is provided, check it against the current post before querying if ($doc_id && isset($post->ID) && $doc_id == $post->ID) { $doc = $post; } if (empty($post->ID)) { $doc = !empty($bp->bp_docs->current_post) ? $bp->bp_docs->current_post : false; } // Keep on trying to set up a post if (empty($doc)) { $doc = bp_docs_get_current_doc(); } // If we still haven't got a post by now, query based on doc id if (empty($doc) && !empty($doc_id)) { $doc = get_post($doc_id); } if (!empty($doc)) { $doc_settings = bp_docs_get_doc_settings($doc->ID); // Manage settings don't always get set on doc creation, so we need a default if (empty($doc_settings['manage'])) { $doc_settings['manage'] = 'creator'; } // Likewise with view_history if (empty($doc_settings['view_history'])) { $doc_settings['view_history'] = 'anyone'; } // Likewise with read_comments if (empty($doc_settings['read_comments'])) { $doc_settings['read_comments'] = 'anyone'; } } else { if (bp_docs_is_doc_create() && 'manage' == $action) { // Anyone can do anything during doc creation return true; } } // Default to the current group, but get the associated doc if not $group_id = bp_get_current_group_id(); if (!$group_id && !empty($doc)) { $group_id = bp_docs_get_associated_group_id($doc->ID, $doc); $group = groups_get_group(array('group_id' => $group_id)); } if (!$group_id) { return $user_can; } switch ($action) { case 'associate_with_group': $group_settings = bp_docs_get_group_settings($group_id); // Provide a default value for legacy backpat if (empty($group_settings['can-create'])) { $group_settings['can-create'] = 'member'; } if (!empty($group_settings['can-create'])) { switch ($group_settings['can-create']) { case 'admin': if (groups_is_user_admin($user_id, $group_id)) { $user_can = true; } break; case 'mod': if (groups_is_user_mod($user_id, $group_id) || groups_is_user_admin($user_id, $group_id)) { $user_can = true; } break; case 'member': default: if (groups_is_user_member($user_id, $group_id)) { $user_can = true; } break; } } break; case 'read': case 'delete': // Delete and Edit are the same for the time being // Delete and Edit are the same for the time being case 'edit': default: // Delete defaults to Edit for now if ('delete' == $action) { $action = 'edit'; } // Make sure there's a default if (empty($doc_settings[$action])) { if (!empty($group_id)) { $doc_settings[$action] = 'group-members'; } else { $doc_settings[$action] = 'anyone'; } } switch ($doc_settings[$action]) { case 'anyone': $user_can = true; break; case 'creator': if ($doc->post_author == $user_id) { $user_can = true; } break; case 'group-members': if (groups_is_user_member($user_id, $group_id)) { $user_can = true; } break; case 'admins-mods': if (groups_is_user_admin($user_id, $group_id) || groups_is_user_mod($user_id, $group_id)) { $user_can = true; } break; case 'no-one': default: break; // In other words, other types return false } break; } return $user_can; }
/** * Give users the 'edit_post' and 'upload_files' cap, when appropriate * * @since 1.4 * * @param array $caps The mapped caps * @param string $cap The cap being mapped * @param int $user_id The user id in question * @param $args * @return array $caps */ public static function map_meta_cap($caps, $cap, $user_id, $args) { if ('upload_files' !== $cap && 'edit_post' !== $cap) { return $caps; } $maybe_user = new WP_User($user_id); if (!is_a($maybe_user, 'WP_User') || empty($maybe_user->ID)) { return $caps; } $is_doc = false; // DOING_AJAX is not set yet, so we cheat $is_ajax = isset($_SERVER['REQUEST_METHOD']) && 'POST' === $_SERVER['REQUEST_METHOD'] && 'async-upload.php' === substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '/') + 1); if ($is_ajax) { // WordPress sends the 'media-form' nonce, which we use // as an initial screen $nonce = isset($_REQUEST['_wpnonce']) ? stripslashes($_REQUEST['_wpnonce']) : ''; $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : ''; if (wp_verify_nonce($nonce, 'media-form') && $post_id) { $post = get_post($post_id); // The dummy Doc created during the Create // process should pass this test, in addition to // existing Docs $is_doc = isset($post->post_type) && bp_docs_get_post_type_name() === $post->post_type; } } else { $is_doc = bp_docs_is_existing_doc() || bp_docs_is_doc_create(); } if ($is_doc) { $caps = array('exist'); // Since we've already done the permissions check, // we can filter future current_user_can() checks on // this pageload add_filter('map_meta_cap', array(__CLASS__, 'map_meta_cap_supp'), 10, 4); } return $caps; }
/** * Loads JavaScript * * @package BuddyPress Docs * @since 1.0-beta */ function enqueue_scripts() { wp_register_script('bp-docs-js', plugins_url('buddypress-docs/includes/js/bp-docs.js'), array('jquery')); // This is for edit/create scripts if (bp_docs_is_doc_edit() || bp_docs_is_doc_create() || !empty($this->query->current_view) && ('edit' == $this->query->current_view || 'create' == $this->query->current_view)) { require_once ABSPATH . '/wp-admin/includes/post.php'; wp_enqueue_script('common'); wp_enqueue_script('jquery-color'); wp_enqueue_script('editor'); wp_enqueue_script('utils'); wp_register_script('bp-docs-idle-js', plugins_url('buddypress-docs/includes/js/idle.js'), array('jquery', 'bp-docs-js')); wp_enqueue_script('bp-docs-idle-js'); wp_register_script('jquery-colorbox', plugins_url('buddypress-docs/lib/js/colorbox/jquery.colorbox-min.js'), array('jquery')); wp_enqueue_script('jquery-colorbox'); // Edit mode requires bp-docs-js to be dependent on TinyMCE, so we must // reregister bp-docs-js with the correct dependencies wp_deregister_script('bp-docs-js'); wp_register_script('bp-docs-js', plugins_url('buddypress-docs/includes/js/bp-docs.js'), array('jquery', 'editor')); wp_register_script('word-counter', site_url() . '/wp-admin/js/word-count.js', array('jquery')); wp_enqueue_script('bp-docs-edit-validation', plugins_url('buddypress-docs/includes/js/edit-validation.js'), array('jquery')); } // Only load our JS on the right sorts of pages. Generous to account for // different item types if (in_array(BP_DOCS_SLUG, $this->slugstocheck) || bp_docs_is_single_doc() || bp_docs_is_global_directory()) { wp_enqueue_script('bp-docs-js'); wp_enqueue_script('comment-reply'); wp_localize_script('bp-docs-js', 'bp_docs', array('still_working' => __('Still working?', 'bp-docs'))); } }
/** * Echoes the Create A Doc button * * @since 1.2 */ function bp_docs_create_button() { if (!bp_docs_is_doc_create() && bp_docs_current_user_can('create')) { echo '<a class="button" id="bp-create-doc-button" href="' . bp_docs_get_create_link() . '">' . __("Create New Doc", 'bp-docs') . '</a>'; } }
<?php if (bp_docs_is_doc_edit() || bp_docs_is_doc_create()) { ?> <?php bp_docs_media_buttons('doc_content'); } ?> <ul id="doc-attachments-ul"> <?php foreach (bp_docs_get_doc_attachments() as $attachment) { ?> <?php echo bp_docs_attachment_item_markup($attachment->ID); } ?> </ul>
function bp_docs_attachment_item_markup($attachment_id, $format = 'full') { $markup = ''; $att_url = bp_docs_get_attachment_url($attachment_id); $attachment = get_post($attachment_id); $att_base = basename(get_attached_file($attachment_id)); $doc_url = bp_docs_get_doc_link($attachment->post_parent); $attachment_ext = preg_replace('/^.+?\\.([^.]+)$/', '$1', $att_url); if ('full' === $format) { $attachment_delete_html = ''; if (bp_docs_current_user_can('edit') && (bp_docs_is_doc_edit() || bp_docs_is_doc_create())) { $attachment_delete_url = wp_nonce_url($doc_url, 'bp_docs_delete_attachment_' . $attachment_id); $attachment_delete_url = add_query_arg(array('delete_attachment' => $attachment_id), $attachment_delete_url); $attachment_delete_html = sprintf('<a href="%s" class="doc-attachment-delete confirm button">%s</a> ', $attachment_delete_url, __('Delete', 'buddypress')); } $markup = sprintf('<li id="doc-attachment-%d"><span class="doc-attachment-mime-icon doc-attachment-mime-%s"></span><a href="%s" title="%s">%s</a>%s</li>', $attachment_id, $attachment_ext, $att_url, esc_attr($att_base), esc_html($att_base), $attachment_delete_html); } else { $markup = sprintf('<li id="doc-attachment-%d"><span class="doc-attachment-mime-icon doc-attachment-mime-%s"></span><a href="%s" title="%s">%s</a></li>', $attachment_id, $attachment_ext, $att_url, esc_attr($att_base), esc_html($att_base)); } return $markup; }
/** * Protects group docs from unauthorized access * * @since 1.2 * @uses bp_docs_current_user_can() This does most of the heavy lifting */ function protect_doc_access() { // What is the user trying to do? if (bp_docs_is_doc_read()) { $action = 'read'; } else { if (bp_docs_is_doc_create()) { $action = 'create'; } else { if (bp_docs_is_doc_edit()) { $action = 'edit'; } else { if (bp_docs_is_doc_history()) { $action = 'view_history'; } } } } if (!isset($action)) { return; } if (!bp_docs_current_user_can($action)) { $redirect_to = wp_get_referer(); if (!$redirect_to || trailingslashit($redirect_to) == trailingslashit(wp_guess_url())) { $redirect_to = bp_get_root_domain(); } switch ($action) { case 'read': $message = __('You are not allowed to read that Doc.', 'bp-docs'); break; case 'create': $message = __('You are not allowed to create Docs.', 'bp-docs'); break; case 'edit': $message = __('You are not allowed to edit that Doc.', 'bp-docs'); break; case 'view_history': $message = __('You are not allowed to view that Doc\'s history.', 'bp-docs'); break; } bp_core_add_message($message, 'error'); bp_core_redirect($redirect_to); } }
<?php global $class; $is_group_single_doc = ''; if (function_exists('bp_docs_is_doc_edit')) { //fix boss code with rw_bp_doc_single_group_id() $is_group_single_doc = (bp_docs_is_doc_edit() || bp_docs_is_doc_read() || bp_docs_is_doc_create() || bp_docs_is_doc_history()) && rw_bp_doc_single_group_id(false); } if ($is_group_single_doc) { $class .= ' group-single'; } ?> <?php // Boxed layout cover if (boss_get_option('boss_cover_profile')) { if (boss_get_option('boss_layout_style') == 'boxed' && (!bp_is_current_component('events') || bp_is_current_component('events') && 'profile' == bp_current_action())) { // show here for boxed and if not Events Manager page or if it is My Profile of Events if (bp_is_user()) { echo buddyboss_cover_photo("user", bp_displayed_user_id()); } } } ?> <?php if (bp_is_current_component('groups') && !bp_is_group() && !bp_is_user()) { ?> <div class="dir-page-entry"> <div class="inner-padding"> <header class="group-header page-header">
/** * Are we looking at something that needs docs theme compatability? * * @since 1.3 */ public function is_docs() { // Bail if not looking at the docs component if (!bp_docs_is_docs_component()) { return; } add_filter('bp_get_template_stack', array($this, 'add_plugin_templates_to_stack')); add_filter('bp_get_buddypress_template', array($this, 'query_templates')); if (bp_docs_is_global_directory()) { bp_update_is_directory(true, 'docs'); do_action('bp_docs_screen_index'); add_action('bp_template_include_reset_dummy_post_data', array($this, 'directory_dummy_post')); add_filter('bp_replace_the_content', array($this, 'directory_content')); } else { if (bp_docs_is_existing_doc()) { if (bp_docs_is_doc_history()) { $this->single_content_template = 'docs/single/history'; add_filter('bp_force_comment_status', '__return_false'); } else { if (bp_docs_is_doc_edit()) { $this->single_content_template = 'docs/single/edit'; add_filter('bp_force_comment_status', '__return_false'); } else { $this->single_content_template = 'docs/single/index'; add_filter('bp_docs_allow_comment_section', '__return_false'); } } add_action('bp_template_include_reset_dummy_post_data', array($this, 'single_dummy_post')); add_filter('bp_replace_the_content', array($this, 'single_content')); } else { if (bp_docs_is_doc_create()) { add_action('bp_template_include_reset_dummy_post_data', array($this, 'create_dummy_post')); add_filter('bp_replace_the_content', array($this, 'create_content')); } } } }
/** * Determine whether a given user can do something with a given doc * * @package BuddyPress Docs * @since 1.0-beta * * @param str $action Optional. The action being queried. Eg 'edit', 'read_comments', 'manage' * @param int $user_id Optional. Unique user id for the user being tested. Defaults to logged-in ID * @param int $doc_id Optional. Unique doc id. Defaults to doc currently being viewed */ function bp_docs_user_can($action = 'edit', $user_id = false, $doc_id = false) { global $bp, $post; if (false === $user_id) { $user_id = bp_loggedin_user_id(); } // Grant all permissions on documents being created, as long as the // user is logged in if ($user_id && false === $doc_id && bp_docs_is_doc_create()) { return true; } if (!$doc_id) { if (!empty($post->ID) && bp_docs_get_post_type_name() === $post->post_type) { $doc_id = $post->ID; $doc = $post; } else { $doc = bp_docs_get_current_doc(); if (isset($doc->ID)) { $doc_id = $doc->ID; } } } $user_can = false; if ('create' === $action) { // In the case of Doc creation, this value gets passed through // to other components $user_can = 0 != $user_id; } else { if (!empty($doc)) { $doc_settings = bp_docs_get_doc_settings($doc_id); $the_setting = isset($doc_settings[$action]) ? $doc_settings[$action] : ''; if (empty($the_setting)) { $the_setting = 'anyone'; } switch ($the_setting) { case 'anyone': $user_can = true; break; case 'loggedin': $user_can = 0 != $user_id; break; case 'creator': $user_can = $doc->post_author == $user_id; break; // Do nothing with other settings - they are passed through } } } if ($user_id) { if (is_super_admin($user_id)) { // Super admin always gets to edit. What a big shot $user_can = true; } else { // Filter this so that groups-integration and other plugins can give their // own rules. Done inside the conditional so that plugins don't have to // worry about the is_super_admin() check $user_can = apply_filters('bp_docs_user_can', $user_can, $action, $user_id, $doc_id); } } return $user_can; }
/** * Output 'toggle-open' or 'toggle-closed' class for toggleable div. * * @since 1.8 */ function bp_docs_toggleable_open_or_closed_class() { if (bp_docs_is_doc_create()) { echo 'toggle-open'; } else { echo 'toggle-closed'; } }
/** * Are we looking at something that needs docs theme compatability? * * @since 1.3 */ public function is_docs() { $is_docs = bp_docs_is_docs_component(); if (bp_is_active('groups') && bp_is_group() && bp_is_current_action(buddypress()->bp_docs->slug)) { $is_docs = true; } // Bail if not looking at the docs component if (!$is_docs) { return; } add_filter('bp_get_template_stack', array($this, 'add_plugin_templates_to_stack')); add_filter('bp_get_buddypress_template', array($this, 'query_templates')); add_filter('bp_use_theme_compat_with_current_theme', 'bp_docs_do_theme_compat'); if (bp_docs_is_global_directory() || bp_docs_is_mygroups_directory()) { bp_update_is_directory(true, 'docs'); do_action('bp_docs_screen_index'); add_action('bp_template_include_reset_dummy_post_data', array($this, 'directory_dummy_post')); add_filter('bp_replace_the_content', array($this, 'directory_content')); } else { if (bp_docs_is_existing_doc()) { if (bp_docs_is_doc_history()) { $this->single_content_template = 'docs/single/history'; add_filter('bp_force_comment_status', '__return_false'); } else { if (bp_docs_is_doc_edit()) { $this->single_content_template = 'docs/single/edit'; add_filter('bp_force_comment_status', '__return_false'); } else { $this->single_content_template = 'docs/single/index'; add_filter('bp_docs_allow_comment_section', '__return_false'); // Necessary as of BP 1.9.2 remove_action('bp_replace_the_content', 'bp_theme_compat_toggle_is_page', 9999); } } add_action('bp_template_include_reset_dummy_post_data', array($this, 'single_dummy_post')); add_filter('bp_replace_the_content', array($this, 'single_content')); } else { if (bp_docs_is_doc_create()) { add_action('bp_template_include_reset_dummy_post_data', array($this, 'create_dummy_post')); add_filter('bp_replace_the_content', array($this, 'create_content')); } } } }
?> > <a href="<?php bp_docs_doc_edit_link(); ?> "><?php _e('Edit', 'bp-docs'); ?> </a> </li> <?php } ?> <?php do_action('bp_docs_header_tabs'); ?> </ul> </div> <?php } elseif (bp_docs_is_doc_create()) { ?> <h2><?php _e('New Doc', 'bp-docs'); ?> </h2> <?php }
} ?> </div> <div style="clear:both"></div> <hr> <ul id="doc-attachments-ul"> <?php foreach ($files as $file) { echo $file; } ?> </ul> <br> <div style="clear:both"></div> <?php if (!bp_docs_is_doc_edit() && !bp_docs_is_doc_create()) { ?> <script type="text/javascript"> jQuery(".fancybox").fancybox(); var images=[]; jQuery.each(jQuery('a.fancybox'), function(i,el){ console.log(el.href); if(images[el.href]){ jQuery(el).remove(); }else{ images[el.href]=1; } }); var navbar = jQuery('#item-nav .item-list-tabs ul')[0]; navbar.id='nav-bar-filter';