/**
  * Constructor
  *
  * @since 1.0-beta
  */
 public function __construct()
 {
     global $bp;
     $bp_docs_tab_name = bp_docs_get_group_tab_name();
     if (!empty($bp->groups->current_group->id)) {
         $this->maybe_group_id = $bp->groups->current_group->id;
     } else {
         if (!empty($bp->groups->new_group_id)) {
             $this->maybe_group_id = $bp->groups->new_group_id;
         } else {
             $this->maybe_group_id = false;
         }
     }
     // Load the bp-docs setting for the group, for easy access
     $this->settings = bp_docs_get_group_settings($this->maybe_group_id);
     $this->group_enable = !empty($this->settings['group-enable']) ? true : false;
     $this->name = !empty($bp_docs_tab_name) ? $bp_docs_tab_name : __('Docs', 'bp-docs');
     $this->slug = bp_docs_get_docs_slug();
     $this->enable_create_step = $this->enable_create_step();
     $this->create_step_position = 18;
     $this->nav_item_position = 45;
     $this->visibility = 'public';
     $this->enable_nav_item = $this->enable_nav_item();
     // Create some default settings if the create step is skipped
     if (apply_filters('bp_docs_force_enable_at_group_creation', false)) {
         add_action('groups_created_group', array(&$this, 'enable_at_group_creation'));
     }
     // Backward compatibility for group-based Doc URLs
     add_action('bp_actions', array($this, 'url_backpat'));
 }
Exemplo n.º 2
0
    public function slug_setting_markup()
    {
        global $bp;
        $slug = bp_docs_get_docs_slug();
        $is_in_wp_config = 1 === $bp->bp_docs->slug_defined_in_wp_config['slug'];
        ?>
		<input name="bp-docs-slug" id="bp-docs-slug" type="text" value="<?php 
        echo esc_html($slug);
        ?>
" <?php 
        if ($is_in_wp_config) {
            ?>
disabled="disabled" <?php 
        }
        ?>
/>
		<p class="description"><?php 
        _e("Change the slug used to build Docs URLs.", 'bp-docs');
        if ($is_in_wp_config) {
            ?>
 <?php 
            _e('You have already defined this value in <code>wp-config.php</code>, so it cannot be edited here.', 'bp-docs');
        }
        ?>
</p>

		<?php 
    }
Exemplo n.º 3
0
 /**
  * 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');
     }
 }
/**
 * Get the link to the Edited By tab of the displayed user
 *
 * @package BuddyPress_Docs
 * @since 1.9
 */
function bp_docs_get_displayed_user_docs_edited_link()
{
    return apply_filters('bp_docs_get_displayed_user_docs_edited_link', user_trailingslashit(trailingslashit(bp_displayed_user_domain() . bp_docs_get_docs_slug()) . BP_DOCS_EDITED_SLUG));
}
/**
 * Process folder creation from manage-folders.
 */
function bp_docs_process_folder_create_cb()
{
    if (!bp_docs_is_docs_component() && !bp_is_current_action(bp_docs_get_docs_slug())) {
        return;
    }
    if (!bp_docs_is_folder_manage_view()) {
        return;
    }
    if (empty($_POST['bp-docs-create-folder-submit'])) {
        return;
    }
    $nonce = isset($_POST['bp-docs-create-folder-nonce']) ? stripslashes($_POST['bp-docs-create-folder-nonce']) : '';
    $redirect_url = bp_get_requested_url();
    if (!wp_verify_nonce($nonce, 'bp-docs-create-folder')) {
        bp_core_add_message(__('There was a problem editing that folder. Please try again.', 'bp-docs'), 'error');
        bp_core_redirect($redirect_url);
        die;
    }
    $folder_args = array('name' => stripslashes($_POST['new-folder']));
    $parent = isset($_POST['new-folder-parent']) ? intval($_POST['new-folder-parent']) : null;
    if (!empty($parent)) {
        $folder_args['parent'] = $parent;
    }
    // If there's a parent, the parent's folder type takes precedence
    if (!empty($parent)) {
        $folder_args['group_id'] = bp_docs_get_folder_group($parent);
        $folder_args['user_id'] = bp_docs_get_folder_user($parent);
        // Otherwise, trust the values passed
    } else {
        // Type
        $folder_type = stripslashes($_POST['new-folder-type']);
        if ('global' === $folder_type) {
            // Nothing to do
        } else {
            if ('me' === $folder_type) {
                $folder_args['user_id'] = bp_loggedin_user_id();
            } else {
                if (is_numeric($folder_type)) {
                    // This is a group
                    $folder_args['group_id'] = intval($folder_type);
                }
            }
        }
    }
    // Create the folder
    // @todo permissions checks
    $success = bp_docs_create_folder($folder_args);
    if (!empty($success) && !is_wp_error($success)) {
        bp_core_add_message(__('Folder successfully created.', 'bp-docs'), 'success');
    } else {
        bp_core_add_message(__('There was a problem creating the folder. Please try again.', 'bp-docs'), 'error');
    }
    bp_core_redirect($redirect_url);
    die;
}
 /**
  * Saves a doc.
  *
  * This method handles saving for both new and existing docs. It detects the difference by
  * looking for the presence of $this->doc_slug
  *
  * @since 1.0-beta
  */
 function save($args = false)
 {
     global $bp, $wp_rewrite;
     // bbPress plays naughty with revision saving
     add_action('pre_post_update', 'wp_save_post_revision');
     // Get the required taxonomy items associated with the group. We only run this
     // on a save because it requires extra database hits.
     $this->setup_terms();
     // Set up the default value for the result message
     $results = array('message' => __('Unknown error. Please try again.', 'bp-docs'), 'redirect' => 'create');
     // Backward compatibility. Had to change to doc_content to work with wp_editor
     $doc_content = '';
     if (isset($_POST['doc_content'])) {
         $doc_content = $_POST['doc_content'];
     } else {
         if (isset($_POST['doc']['content'])) {
             $doc_content = $_POST['doc']['content'];
         }
     }
     // Check group associations
     // @todo Move into group integration piece
     // This group id is only used to check whether the user can associate the doc with the group.
     $associated_group_id = isset($_POST['associated_group_id']) ? intval($_POST['associated_group_id']) : null;
     if (bp_is_active('groups')) {
         if (!empty($associated_group_id) && !current_user_can('bp_docs_associate_with_group', $associated_group_id)) {
             $retval = array('message_type' => 'error', 'message' => __('You are not allowed to associate a Doc with that group.', 'bp-docs'), 'redirect_url' => bp_docs_get_create_link());
             return $retval;
         }
     }
     if (empty($_POST['doc']['title'])) {
         // The title field is required
         $result['message'] = __('The title field is required.', 'bp-docs');
         $result['redirect'] = !empty($this->doc_slug) ? 'edit' : 'create';
     } else {
         $defaults = array('post_type' => $this->post_type_name, 'post_title' => $_POST['doc']['title'], 'post_name' => isset($_POST['doc']['permalink']) ? sanitize_title($_POST['doc']['permalink']) : sanitize_title($_POST['doc']['title']), 'post_content' => sanitize_post_field('post_content', $doc_content, 0, 'db'), 'post_status' => 'publish');
         $r = wp_parse_args($args, $defaults);
         if (empty($this->doc_slug)) {
             $this->is_new_doc = true;
             $r['post_author'] = bp_loggedin_user_id();
             // If there's a 'doc_id' value in the POST, use
             // the autodraft as a starting point
             if (isset($_POST['doc_id']) && 0 != $_POST['doc_id']) {
                 $post_id = (int) $_POST['doc_id'];
                 $r['ID'] = $post_id;
                 wp_update_post($r);
             } else {
                 $post_id = wp_insert_post($r);
             }
             if (!$post_id) {
                 $result['message'] = __('There was an error when creating the doc.', 'bp-docs');
                 $result['redirect'] = 'create';
             } else {
                 $this->doc_id = $post_id;
                 $the_doc = get_post($this->doc_id);
                 $this->doc_slug = $the_doc->post_name;
                 // A normal, successful save
                 $result['message'] = __('Doc successfully created!', 'bp-docs');
                 $result['redirect'] = 'single';
             }
         } else {
             $this->is_new_doc = false;
             $doc = bp_docs_get_current_doc();
             $this->doc_id = $doc->ID;
             $r['ID'] = $this->doc_id;
             // Make sure the post_name is set
             if (empty($r['post_name'])) {
                 $r['post_name'] = sanitize_title($r['post_title']);
             }
             // Make sure the post_name is unique
             $r['post_name'] = wp_unique_post_slug($r['post_name'], $this->doc_id, $r['post_status'], $this->post_type_name, $doc->post_parent);
             $this->doc_slug = $r['post_name'];
             // Save pre-update post data, for comparison by callbacks.
             $this->previous_revision = clone $doc;
             if (!wp_update_post($r)) {
                 $result['message'] = __('There was an error when saving the doc.', 'bp-docs');
                 $result['redirect'] = 'edit';
             } else {
                 // Remove the edit lock
                 delete_post_meta($this->doc_id, '_edit_lock');
                 delete_post_meta($this->doc_id, '_bp_docs_last_pinged');
                 // When the post has been autosaved, we need to leave a
                 // special success message
                 if (!empty($_POST['is_auto']) && $_POST['is_auto']) {
                     $result['message'] = __('You idled a bit too long while in Edit mode. In order to allow others to edit the doc you were working on, your changes have been autosaved. Click the Edit button to return to Edit mode.', 'bp-docs');
                 } else {
                     // A normal, successful save
                     $result['message'] = __('Doc successfully edited!', 'bp-docs');
                 }
                 $result['redirect'] = 'single';
             }
             $post_id = $this->doc_id;
         }
     }
     // If the Doc was successfully created, run some more stuff
     if (!empty($post_id)) {
         // Add to a group, if necessary
         if (!is_null($associated_group_id)) {
             bp_docs_set_associated_group_id($post_id, $associated_group_id);
         }
         // Make sure the current user is added as one of the authors
         wp_set_post_terms($post_id, $this->user_term_id, $this->associated_item_tax_name, true);
         // Save the last editor id. We'll use this to create an activity item
         update_post_meta($this->doc_id, 'bp_docs_last_editor', bp_loggedin_user_id());
         // Save settings
         bp_docs_save_doc_access_settings($this->doc_id);
         // Increment the revision count
         $revision_count = get_post_meta($this->doc_id, 'bp_docs_revision_count', true);
         update_post_meta($this->doc_id, 'bp_docs_revision_count', intval($revision_count) + 1);
     }
     // Provide a custom hook for plugins and optional components.
     // WP's default save_post isn't enough, because we need something that fires
     // only when we save from the front end (for things like taxonomies, which
     // the WP admin handles automatically)
     do_action('bp_docs_doc_saved', $this);
     do_action('bp_docs_after_save', $this->doc_id);
     $message_type = $result['redirect'] == 'single' ? 'success' : 'error';
     // Stuff data into a cookie so it can be accessed on next page load
     if ('error' === $message_type) {
         setcookie('bp-docs-submit-data', json_encode($_POST), time() + 30, '/');
     }
     $redirect_base = trailingslashit(bp_get_root_domain());
     if ($wp_rewrite->using_index_permalinks()) {
         $redirect_base .= 'index.php/';
     }
     $redirect_url = apply_filters('bp_docs_post_save_redirect_base', trailingslashit($redirect_base . bp_docs_get_docs_slug()));
     if ($result['redirect'] == 'single') {
         $redirect_url .= $this->doc_slug;
     } else {
         if ($result['redirect'] == 'edit') {
             $redirect_url .= $this->doc_slug . '/' . BP_DOCS_EDIT_SLUG;
         } else {
             if ($result['redirect'] == 'create') {
                 $redirect_url .= BP_DOCS_CREATE_SLUG;
             }
         }
     }
     $retval = array('message_type' => $message_type, 'message' => $result['message'], 'redirect_url' => $redirect_url);
     return $retval;
 }
Exemplo n.º 7
0
 function flush_rewrite_rules()
 {
     if (!is_admin()) {
         return;
     }
     if (!is_super_admin()) {
         return;
     }
     global $wp_rewrite;
     // Check to see whether our rules have been registered yet, by
     // finding a Docs rule and then comparing it to the registered rules
     $test_rewrite = null;
     foreach ($wp_rewrite->extra_rules_top as $rewrite => $rule) {
         if (0 === strpos($rewrite, bp_docs_get_docs_slug())) {
             $test_rewrite = $rewrite;
             $test_rule = $rule;
             break;
         }
     }
     $registered_rules = get_option('rewrite_rules');
     if ($test_rewrite && is_array($registered_rules) && (!isset($registered_rules[$test_rewrite]) || $test_rule !== $registered_rules[$test_rewrite])) {
         flush_rewrite_rules();
     }
 }
/**
 * Get an archive link for a given tag
 *
 * Optional arguments:
 *  - 'tag' 	The tag linked to. This one is required
 *  - 'type' 	'html' returns a link; anything else returns a URL
 *
 * @since 1.0-beta
 *
 * @param array $args Optional arguments
 * @return array $filters
 */
function bp_docs_get_tag_link($args = array())
{
    global $bp;
    $defaults = array('tag' => false, 'type' => 'html');
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if (bp_is_user()) {
        $current_action = bp_current_action();
        $item_docs_url = bp_displayed_user_domain() . bp_docs_get_docs_slug() . '/';
        if (empty($current_action) || BP_DOCS_STARTED_SLUG == $current_action) {
            $item_docs_url = bp_docs_get_displayed_user_docs_started_link();
        } elseif (BP_DOCS_EDITED_SLUG == $current_action) {
            $item_docs_url = bp_docs_get_displayed_user_docs_edited_link();
        }
    } elseif (bp_is_active('groups') && ($current_group = groups_get_current_group())) {
        /*
         * Pass the group object to bp_get_group_permalink() so that it works
         * when $groups_template may not be set, like during AJAX requests.
         */
        $item_docs_url = trailingslashit(bp_get_group_permalink($current_group) . bp_docs_get_docs_slug());
    } else {
        $item_docs_url = bp_docs_get_archive_link();
    }
    $url = apply_filters('bp_docs_get_tag_link_url', add_query_arg('bpd_tag', urlencode($tag), $item_docs_url), $args, $item_docs_url);
    if ($type != 'html') {
        return apply_filters('bp_docs_get_tag_link_url', $url, $tag, $type);
    }
    $html = '<a href="' . $url . '" title="' . sprintf(__('Docs tagged %s', 'bp-docs'), esc_attr($tag)) . '">' . esc_html($tag) . '</a>';
    return apply_filters('bp_docs_get_tag_link', $html, $url, $tag, $type);
}
Exemplo n.º 9
0
			<input type="text" id="doc-title" name="doc[title]" class="long" value="<?php 
bp_docs_edit_doc_title();
?>
" />
		</div>

		<?php 
if (bp_docs_is_existing_doc()) {
    ?>
			<div id="doc-content-permalink">
				<label for="doc-permalink"><?php 
    _e('Permalink', 'bp-docs');
    ?>
</label>
				<code><?php 
    echo trailingslashit(bp_get_root_domain()) . bp_docs_get_docs_slug() . '/';
    ?>
</code><input type="text" id="doc-permalink" name="doc[permalink]" class="long" value="<?php 
    bp_docs_edit_doc_slug();
    ?>
" />
			</div>
		<?php 
}
?>

		<?php 
do_action('bp_docs_before_doc_edit_content', $doc_id);
?>

		<div id="doc-content-textarea">
Exemplo n.º 10
0
/**
 * Is this the BP Docs component?
 */
function bp_docs_is_docs_component()
{
    $retval = false;
    $p = get_queried_object();
    if (is_post_type_archive(bp_docs_get_post_type_name())) {
        $retval = true;
    } else {
        if (isset($p->post_type) && bp_docs_get_post_type_name() == $p->post_type) {
            $retval = true;
        } else {
            if (bp_is_current_component(bp_docs_get_docs_slug())) {
                // This covers cases where we're looking at the Docs component of a user
                $retval = true;
            }
        }
    }
    return $retval;
}
/**
 * Get an archive link for a given tag
 *
 * Optional arguments:
 *  - 'tag' 	The tag linked to. This one is required
 *  - 'type' 	'html' returns a link; anything else returns a URL
 *  - 'tags'    The selected tags
 *
 * @param array $args Optional arguments
 * @return array $filters
 */
function bp_docs_get_tag_link_multitag($args = array())
{
    global $bp;
    $defaults = array('tag' => false, 'type' => 'html', 'tags' => array());
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    if (bp_is_user()) {
        $current_action = bp_current_action();
        $item_docs_url = bp_displayed_user_domain() . bp_docs_get_docs_slug() . '/';
        if (empty($current_action) || BP_DOCS_STARTED_SLUG == $current_action) {
            $item_docs_url = bp_docs_get_displayed_user_docs_started_link();
        } elseif (BP_DOCS_EDITED_SLUG == $current_action) {
            $item_docs_url = bp_docs_get_displayed_user_docs_edited_link();
        }
    } elseif (bp_is_active('groups') && ($current_group = groups_get_current_group())) {
        /*
         * Pass the group object to bp_get_group_permalink() so that it works
         * when $groups_template may not be set, like during AJAX requests.
         */
        $item_docs_url = trailingslashit(bp_get_group_permalink($current_group) . bp_docs_get_docs_slug());
    } else {
        $item_docs_url = bp_docs_get_archive_link();
    }
    $bdp_tags = $tags;
    if (in_array($tag, $bdp_tags)) {
        // Remove because tag is selected
        $tag_key = array_search($tag, $bdp_tags);
        if ($tag_key !== FALSE) {
            unset($bdp_tags[$tag_key]);
        }
    } else {
        $bdp_tags[] = urlencode($tag);
    }
    if (!empty($_REQUEST['bool'])) {
        $item_docs_url = add_query_arg('bool', $_REQUEST['bool'], $item_docs_url);
    } else {
        /*
         * If not exist boolean argument, default add "and" condition
         */
        $item_docs_url = add_query_arg('bool', 'and', $item_docs_url);
    }
    $bdp_tags = implode(',', array_filter($bdp_tags));
    $url = apply_filters('bp_docs_get_tag_link_url', add_query_arg('bpd_tag', $bdp_tags, $item_docs_url), $args, $item_docs_url);
    if ($type != 'html') {
        return apply_filters('bp_docs_get_tag_link_url', $url, $tag, $type);
    }
    $html = '<a href="' . $url . '" title="' . sprintf(__('Docs tagged %s', 'bp-docs'), esc_attr($tag)) . '">' . esc_html($tag) . '</a>';
    return apply_filters('bp_docs_get_tag_link', $html, $url, $tag, $type);
}
 /**
  * When looking at a single doc, this adds the appropriate subnav item.
  *
  * Other navigation items are added in BP_Docs_Component. We add this item here because it's
  * not until later in the load order when we can be certain whether we're viewing a
  * single Doc.
  *
  * @since 1.2
  */
 function setup_single_doc_subnav()
 {
     global $bp;
     if (bp_is_user() && !empty($bp->bp_docs->current_view) && in_array($bp->bp_docs->current_view, array('single', 'edit', 'history', 'delete'))) {
         $doc = bp_docs_get_current_doc();
         if (!empty($doc)) {
             bp_core_new_subnav_item(array('name' => $doc->post_title, 'slug' => $doc->post_name, 'parent_url' => trailingslashit(bp_loggedin_user_domain() . bp_docs_get_docs_slug()), 'parent_slug' => bp_docs_get_docs_slug(), 'screen_function' => array($bp->bp_docs, 'template_loader'), 'position' => 30, 'user_has_access' => true));
         }
     }
 }
Exemplo n.º 13
0
/**
 * Get the link to the My Docs tab of the logged in user
 *
 * @package BuddyPress_Docs
 * @since 1.2
 */
function bp_docs_get_mydocs_link()
{
    return apply_filters('bp_docs_get_mydocs_link', trailingslashit(bp_loggedin_user_domain() . bp_docs_get_docs_slug()));
}