/** * Prevent a user from visiting the Edit page if it's locked. * * @since 1.6.0 */ function bp_docs_edit_lock_redirect() { if (!bp_docs_is_doc_edit()) { return; } $doc_id = get_queried_object_id(); $lock = bp_docs_check_post_lock($doc_id); if (!empty($lock) && $lock != bp_loggedin_user_id()) { $bounce = bp_docs_get_doc_link($doc_id); wp_redirect($bounce); } }
?> > <a href="<?php bp_docs_doc_link(); ?> "><?php _e('Read', 'bp-docs'); ?> </a> </li> <?php if (bp_docs_current_user_can('edit')) { ?> <li<?php if (bp_docs_is_doc_edit()) { ?> class="current"<?php } ?> > <a href="<?php bp_docs_doc_edit_link(); ?> "><?php _e('Edit', 'bp-docs'); ?> </a> </li> <?php }
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 (current_user_can('bp_docs_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; }
/** * 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'); } }
/** * 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')); } } } }
function enqueue_scripts() { if (bp_docs_is_doc_edit() || bp_docs_is_doc_create()) { wp_enqueue_script('bp-docs-attachments', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/attachments.js'), array('media-editor', 'media-views'), false, true); } }
function enable_more_buttons_2($buttons) { if (bp_docs_is_doc_edit() or bp_docs_is_doc_create()) { $buttons = array('formatselect', 'fontsizeselect', 'undo', 'redo', 'removeformat', 'searchreplace', 'charmap', 'hr', 'link', 'unlink', 'anchor', 'wp_page', 'tabindent', 'image', 'media', 'visualblocks'); } return $buttons; }
/** * 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')); } } } }
/** * 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)); } }
function enqueue_scripts() { if (bp_docs_is_doc_edit() || bp_docs_is_doc_create()) { wp_enqueue_script('bp-docs-attachments', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/attachments.js'), array('media-editor', 'media-views', 'bp-docs-js'), false, true); wp_localize_script('bp-docs-attachments', 'bp_docs_attachments', array('upload_title' => __('Upload File', 'bp-docs'), 'upload_button' => __('OK', 'bp-docs'))); } }
/** * 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'))); } }
<?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>
/** * Is the current page a single Doc 'read' view? * * By process of elimination. * * @since 1.2 * @return bool */ function bp_docs_is_doc_read() { $is_doc_read = false; if (bp_docs_is_single_doc() && !bp_docs_is_doc_edit() && (!function_exists('bp_docs_is_doc_history') || !bp_docs_is_doc_history())) { $is_doc_read = true; } return apply_filters('bp_docs_is_doc_read', $is_doc_read); }
/** * 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">
} ?> </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';