示例#1
0
 /**
  * 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'));
             }
         }
     }
 }
/**
 * Outputs the tabs at the top of the Docs view (All Docs, New Doc, etc)
 *
 * At the moment, the group-specific stuff is hard coded in here.
 * @todo Get the group stuff out
 */
function bp_docs_tabs($show_create_button = true)
{
    $current_view = '';
    ?>

	<ul id="bp-docs-all-docs">
		<li<?php 
    if (bp_docs_is_global_directory()) {
        ?>
 class="current"<?php 
    }
    ?>
><a href="<?php 
    bp_docs_archive_link();
    ?>
"><?php 
    _e('All Docs', 'bp-docs');
    ?>
</a></li>

		<?php 
    if (is_user_logged_in()) {
        ?>
			<?php 
        if (function_exists('bp_is_group') && bp_is_group()) {
            ?>
				<li<?php 
            if (bp_is_current_action('docs')) {
                ?>
 class="current"<?php 
            }
            ?>
><a href="<?php 
            bp_group_permalink(groups_get_current_group());
            bp_docs_slug();
            ?>
"><?php 
            printf(__("%s's Docs", 'bp-docs'), bp_get_current_group_name());
            ?>
</a></li>
			<?php 
        } else {
            ?>
				<li><a href="<?php 
            bp_docs_mydocs_started_link();
            ?>
"><?php 
            _e('Started By Me', 'bp-docs');
            ?>
</a></li>
				<li><a href="<?php 
            bp_docs_mydocs_edited_link();
            ?>
"><?php 
            _e('Edited By Me', 'bp-docs');
            ?>
</a></li>

				<?php 
            if (bp_is_active('groups')) {
                ?>
					<li<?php 
                if (bp_docs_is_mygroups_docs()) {
                    ?>
 class="current"<?php 
                }
                ?>
><a href="<?php 
                bp_docs_mygroups_link();
                ?>
"><?php 
                _e('My Groups', 'bp-docs');
                ?>
</a></li>
				<?php 
            }
            ?>
			<?php 
        }
        ?>

		<?php 
    }
    ?>

		<?php 
    if ($show_create_button) {
        ?>
			<?php 
        bp_docs_create_button();
        ?>
		<?php 
    }
    ?>

	</ul>
	<?php 
}
示例#3
0
 /**
  * Loads JavaScript
  *
  * @package BuddyPress Docs
  * @since 1.0-beta
  */
 function enqueue_scripts()
 {
     wp_register_script('bp-docs-js', plugins_url(BP_DOCS_PLUGIN_SLUG . '/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(BP_DOCS_PLUGIN_SLUG . '/includes/js/idle.js'), array('jquery', 'bp-docs-js'));
         wp_enqueue_script('bp-docs-idle-js');
         wp_register_script('jquery-colorbox', plugins_url(BP_DOCS_PLUGIN_SLUG . '/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(BP_DOCS_PLUGIN_SLUG . '/includes/js/bp-docs.js'), array('jquery', 'editor', 'heartbeat'));
         wp_register_script('word-counter', site_url() . '/wp-admin/js/word-count.js', array('jquery'));
         wp_enqueue_script('bp-docs-edit-validation', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/edit-validation.js'), array('jquery', 'bp-docs-js'));
     }
     // Only load our JS on the right sorts of pages. Generous to account for
     // different item types
     if (in_array(bp_docs_get_docs_slug(), $this->slugstocheck) || bp_docs_is_single_doc() || bp_docs_is_global_directory() || bp_docs_is_mygroups_directory() || bp_docs_is_doc_create()) {
         wp_enqueue_script('bp-docs-js');
         wp_enqueue_script('comment-reply');
         $strings = array('upload_title' => __('Upload File', 'bp-docs'), 'upload_button' => __('OK', 'bp-docs'), 'still_working' => __('Still working?', 'bp-docs'), 'and_x_more' => __('and %d more', 'bp-docs'), 'failed_submission' => !empty(buddypress()->bp_docs->submitted_data) ? 1 : 0);
         if (bp_docs_is_doc_edit()) {
             $strings['pulse'] = bp_docs_heartbeat_pulse();
         }
         wp_localize_script('bp-docs-js', 'bp_docs', $strings);
     }
 }
/**
 * Folder-specific meta cap mapping.
 *
 * @since 1.9.0
 */
function bp_docs_folders_map_meta_caps($caps, $cap, $user_id, $args)
{
    switch ($cap) {
        case 'bp_docs_manage_folders':
            $caps = array('do_not_allow');
            if (user_can($user_id, 'bp_moderate')) {
                $caps = array('exist');
                // Group
            } else {
                if (function_exists('bp_is_group') && bp_is_group()) {
                    if (groups_is_user_member($user_id, bp_get_current_group_id())) {
                        $caps = array('exist');
                    }
                    // User
                } else {
                    if (bp_is_user()) {
                        if (bp_displayed_user_id() == $user_id) {
                            $caps = array('exist');
                        }
                        // Global - bp_moderate only for now
                    } else {
                        if (bp_docs_is_global_directory()) {
                        }
                    }
                }
            }
            break;
        case 'bp_docs_manage_folder':
            $caps = array('do_not_allow');
            $folder_id = 0;
            if (isset($args[0])) {
                $folder_id = intval($args[0]);
            }
            if (!$folder_id) {
                return $caps;
            }
            $group_id = bp_docs_get_folder_group($folder_id);
            $f_user_id = bp_docs_get_folder_user($folder_id);
            if (user_can($user_id, 'bp_moderate')) {
                $caps = array('exist');
            } else {
                if ($group_id && groups_is_user_admin($user_id, $group_id)) {
                    $caps = array('exist');
                } else {
                    if ($f_user_id && $f_user_id == $user_id) {
                        $caps = array('exist');
                    } else {
                        if (user_can($user_id, 'bp_moderate')) {
                            $caps = array('exist');
                        }
                    }
                }
            }
            break;
            // Temp
        // Temp
        case 'bp_docs_create_global_folder':
        case 'bp_docs_create_personal_folder':
            if (is_user_logged_in()) {
                $caps = array('exist');
            } else {
                $caps = array();
            }
            break;
        case 'bp_docs_change_folder_type':
            $caps = array('bp_moderate');
            break;
    }
    return $caps;
}
 /**
  * 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'));
             }
         }
     }
 }
示例#6
0
 /**
  * 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')));
     }
 }
 /**
  * Renew the last directory cookie if the user is viewing the main docs library.
  *
  * @since 1.9.0
  */
 public function set_directory_cookie()
 {
     if (bp_docs_is_global_directory()) {
         @setcookie('bp-docs-last-docs-directory', home_url($_SERVER['REQUEST_URI']), 0, '/');
     }
 }