/**
  * Callback function for replacing bracketed links with the proper links
  *
  * If a page is found, a link to the page is produced. Otherwise a link to the create page
  * is produced, with the create_title flag.
  *
  * @since 1.2
  *
  * @param array $match A single match passed from preg_replace_callback()
  * @return str A formatted link
  */
 function process_bracket_content($match)
 {
     global $bp, $wpdb;
     // Check for a pipe
     if ($pipe_pos = strpos($match[1], '|')) {
         // If one is found, then the link text will be different from
         // the page name
         $link_text = substr($match[1], $pipe_pos + 1);
         $link_page = substr($match[1], 0, $pipe_pos);
     } else {
         // If no pipe is found, set the link text and link page the same
         $link_text = $link_page = $match[1];
     }
     // Look for a page with this title. WP_Query does not allow this for some reason
     $docs = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_title = %s AND post_type = %s {$in_clause}", $link_page, bp_docs_get_post_type_name()));
     // If none were found, do the same query with page slugs
     if (empty($docs)) {
         $docs = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s {$in_clause}", sanitize_title_with_dashes($link_page), bp_docs_get_post_type_name()));
     }
     // Filter the docs. This will be used to exclude docs that do not belong to a group
     $docs = apply_filters('bp_docs_bracket_matches', $docs);
     if (!empty($docs)) {
         // If we have a result, create a link to that page
         // There might be more than one result. I guess we take the first one
         $doc = $docs[0];
         $permalink = get_permalink($doc);
         $class = 'existing-doc';
     } else {
         // If no result is found, create a link to the edit page
         $permalink = add_query_arg('create_title', urlencode($link_page), bp_docs_get_create_link());
         $class = 'nonexistent-doc';
     }
     return apply_filters('bp_docs_bracket_link', '<a href="' . $permalink . '" class="' . $class . '">' . $link_text . '</a>');
 }
/**
 * Echoes the Create A Doc button
 *
 * @since 1.2
 */
function bp_docs_create_button()
{
    if (!bp_docs_is_doc_create() && current_user_can('bp_docs_create')) {
        echo apply_filters('bp_docs_create_button', '<a class="button" id="bp-create-doc-button" href="' . bp_docs_get_create_link() . '">' . __("Create New Doc", 'bp-docs') . '</a>');
    }
}
示例#3
0
		<div id="bp-docs-paginate-links">
			<?php 
    bp_docs_paginate_links();
    ?>
		</div>
	</div>

<?php 
} else {
    ?>

        <?php 
    if (bp_docs_current_user_can('create')) {
        ?>
                <p class="no-docs"><?php 
        printf(__('There are no docs for this view. Why not <a href="%s">create one</a>?', 'bp-docs'), bp_docs_get_create_link());
        ?>
	<?php 
    } else {
        ?>
		<p class="no-docs"><?php 
        _e('There are no docs for this view.', 'bp-docs');
        ?>
</p>
        <?php 
    }
    ?>

<?php 
}
示例#4
0
 /**
  * Sets up Docs menu under My Account toolbar
  *
  * @since 1.3
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     global $bp;
     $wp_admin_nav = array();
     if (is_user_logged_in()) {
         $title = bp_docs_get_user_tab_name();
         // Add the "My Account" sub menus
         $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => bp_docs_get_mydocs_link());
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-started', 'title' => __('Started By Me', 'bp-docs'), 'href' => bp_docs_get_mydocs_started_link());
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-edited', 'title' => __('Edited By Me', 'bp-docs'), 'href' => bp_docs_get_mydocs_edited_link());
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => __('Create New Doc', 'bp-docs'), 'href' => bp_docs_get_create_link());
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
示例#7
0
 /**
  * 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
  *
  * @package BuddyPress Docs
  * @since 1.0-beta
  */
 function save($args = false)
 {
     global $bp;
     // 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
     if (bp_is_active('groups')) {
         $associated_group_id = isset($_POST['associated_group_id']) ? intval($_POST['associated_group_id']) : 0;
         if ($associated_group_id && !BP_Docs_Groups_Integration::user_can_associate_doc_with_group(bp_loggedin_user_id(), $associated_group_id)) {
             bp_core_add_message(__('You are not allowed to associate a Doc with that group.', 'bp-docs'), 'error');
             bp_core_redirect(bp_docs_get_create_link());
         }
     }
     if (empty($_POST['doc']['title']) || empty($doc_content)) {
         // Both the title and the content fields are required
         $result['message'] = __('Both the title and the content fields are required.', 'bp-docs');
         $result['redirect'] = $this->current_view;
     } else {
         // If both the title and content fields are filled in, we can proceed
         $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' => stripslashes(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();
             // This is a new doc
             if (!($post_id = wp_insert_post($r))) {
                 $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 = get_queried_object();
             $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'];
             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');
                 // 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;
         }
     }
     // Add to a group, if necessary
     if (isset($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
     $settings = !empty($_POST['settings']) ? $_POST['settings'] : array();
     $verified_settings = bp_docs_verify_settings($settings, $post_id, bp_loggedin_user_id());
     $new_settings = array();
     foreach ($verified_settings as $verified_setting_name => $verified_setting) {
         $new_settings[$verified_setting_name] = $verified_setting['verified_value'];
         if ($verified_setting['verified_value'] != $verified_setting['original_value']) {
             $result['message'] = __('Your Doc was successfully saved, but some of your access settings have been changed to match the Doc\'s permissions.', 'bp-docs');
         }
     }
     update_post_meta($this->doc_id, 'bp_docs_settings', $new_settings);
     // The 'read' setting must also be saved to a taxonomy, for
     // easier directory queries
     $read_setting = isset($new_settings['read']) ? $new_settings['read'] : 'anyone';
     bp_docs_update_doc_access($this->doc_id, $read_setting);
     // 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);
     $message_type = $result['redirect'] == 'single' ? 'success' : 'error';
     $redirect_url = trailingslashit(bp_get_root_domain() . '/' . BP_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;
 }
示例#8
0
		<?php 
            if (current_user_can('bp_docs_edit', get_the_ID())) {
                echo '<a href="' . bp_docs_get_doc_link() . BP_DOCS_EDIT_SLUG . '" class="bp-docs-edit-link" title="Redigera"><i class="fa fa-pencil-square-o"></i></a>';
            }
            ?>
		<span class="bp-docs-date">(Senast uppdaterat <?php 
            echo get_the_modified_date();
            ?>
)</span>
	</li>

<?php 
        }
        echo '</ul></div>';
        ?>

<?php 
    } else {
        echo '<h3>' . $cat->name . '</h3>';
        echo '<p><em>Det finns för närvarande inga dokument under <strong>' . $cat->name . '</strong>. ';
        if (bp_docs_current_user_can_create_in_context()) {
            echo 'Varför inte <a href="' . bp_docs_get_create_link() . '">skapa ett</a>!';
        }
        echo '</em></p>';
    }
    wp_reset_query();
}
?>

</div><!-- /#buddypress -->
        ?>
"><?php 
        _e('Edit', 'bp-docs');
        ?>
</a>
				</li>
			<?php 
    }
    ?>

			<?php 
    do_action('bp_docs_header_tabs');
    ?>
				<li class="bp-create-doc-button"><?php 
    if (!bp_docs_is_doc_create() && current_user_can('bp_docs_create')) {
        echo apply_filters('bp_docs_create_button', '<a href="' . bp_docs_get_create_link() . '">' . __("Create New Doc", 'bp-docs') . '</a>');
    }
    ?>
</li>
		</ul>
	</div>
	<?php 
    do_action('bp_docs_before_doc_title');
    ?>
	<div id="bp-docs-single-doc-header">
		<?php 
    if (!bp_docs_is_theme_compat_active()) {
        ?>
			<h2 class="doc-title"><?php 
        the_title();
        if (bp_docs_is_doc_trashed()) {