Skip to content

Commit

Permalink
Merge branch '1.6.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
boonebgorges committed Mar 14, 2014
2 parents 61d9d35 + e806fc3 commit 5d38a43
Show file tree
Hide file tree
Showing 18 changed files with 1,025 additions and 447 deletions.
37 changes: 10 additions & 27 deletions bp-docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ function includes() {

require( BP_DOCS_INCLUDES_PATH . 'theme-bridge.php' );

require( BP_DOCS_INCLUDES_PATH . 'edit-lock.php' );

// formatting.php contains filters and functions used to modify appearance only
require( BP_DOCS_INCLUDES_PATH . 'formatting.php' );

Expand Down Expand Up @@ -173,8 +175,9 @@ function load_constants() {
}

// You should never really need to override this bad boy
if ( !defined( 'BP_DOCS_INSTALL_PATH' ) )
define( 'BP_DOCS_INSTALL_PATH', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . BP_DOCS_PLUGIN_SLUG . DIRECTORY_SEPARATOR );
if ( !defined( 'BP_DOCS_INSTALL_PATH' ) ) {
define( 'BP_DOCS_INSTALL_PATH', plugin_dir_path( __FILE__ ) );
}

// Ditto
if ( !defined( 'BP_DOCS_INCLUDES_PATH' ) )
Expand Down Expand Up @@ -541,32 +544,12 @@ function protect_doc_access() {
}

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;
$redirect_to = wp_login_url( bp_docs_get_doc_link() );

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 );
bp_core_no_access( array(
'mode' => 2,
'redirect' => $redirect_to,
) );
}
}

Expand Down
146 changes: 42 additions & 104 deletions includes/addon-taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function register_taxonomy() {
function register_with_post_type() {
$this->taxonomies = array( /* 'category', */ $this->docs_tag_tax_name );

foreach( $this->taxonomies as $tax ) {
foreach ( $this->taxonomies as $tax ) {
register_taxonomy_for_object_type( $tax, bp_docs_get_post_type_name() );
}
}
Expand All @@ -125,7 +125,7 @@ function register_with_post_type() {
* @return int $post_id Returns the doc's post_id on success
*/
function save_post( $query ) {
foreach( $this->taxonomies as $tax_name ) {
foreach ( $this->taxonomies as $tax_name ) {

if ( $tax_name == 'category' )
$tax_name = 'post_category';
Expand All @@ -151,10 +151,6 @@ function save_post( $query ) {
}

wp_set_post_terms( $query->doc_id, $terms, $tax_name );

// Store these terms in the item term cache, to be used for tag clouds etc
$this->cache_terms_for_item( $terms, $query->doc_id );

}

do_action( 'bp_docs_taxonomy_saved', $query );
Expand All @@ -180,11 +176,11 @@ function delete_post( $new_status, $old_status, $post ) {
$doc_id = $post->ID;

// Terms for the item (group, user, etc)
$item_terms = $this->get_item_terms();
$item_terms = $this->get_item_terms();
// Terms for the doc
$doc_terms = wp_get_post_terms( $doc_id, $this->docs_tag_tax_name );
$doc_terms = wp_get_post_terms( $doc_id, $this->docs_tag_tax_name );

foreach( $doc_terms as $doc_term ) {
foreach ( $doc_terms as $doc_term ) {
$term_name = $doc_term->name;

// If the term is currently used (should always be true - this is a
Expand All @@ -201,8 +197,6 @@ function delete_post( $new_status, $old_status, $post ) {
}
}
}

$this->save_item_terms( $item_terms );
}

/**
Expand All @@ -212,72 +206,21 @@ function delete_post( $new_status, $old_status, $post ) {
* @since 1.0-beta
*/
function show_terms() {
foreach( $this->taxonomies as $tax_name ) {
foreach ( $this->taxonomies as $tax_name ) {
$html = '';
$tagtext = array();
$tags = wp_get_post_terms( get_the_ID(), $tax_name );
$tagtext = array();
$tags = wp_get_post_terms( get_the_ID(), $tax_name );

foreach( $tags as $tag ) {
$tagtext[] = bp_docs_get_tag_link( array( 'tag' => $tag->name ) );
}
foreach ( $tags as $tag ) {
$tagtext[] = bp_docs_get_tag_link( array( 'tag' => $tag->name ) );
}

if ( ! empty( $tagtext ) ) {
$html = '<p>' . sprintf( __( 'Tags: %s', 'bp-docs' ), implode( ', ', $tagtext ) ) . '</p>';
}

echo apply_filters( 'bp_docs_taxonomy_show_terms', $html, $tagtext );
}
}

/**
* Store taxonomy terms and their use count for a given item
*
* @package BuddyPress Docs
* @since 1.0-beta
*
* @param array $terms The terms submitted in the most recent save
* @param int $doc_id The unique id of the doc
*/
function cache_terms_for_item( $terms = array(), $doc_id ) {
$existing_terms = $this->get_item_terms();

// First, make sure that each submitted term is recorded
foreach ( $terms as $term ) {
if ( empty( $existing_terms[$term] ) || ! is_array( $existing_terms[$term] ) )
$existing_terms[$term] = array();

if ( ! in_array( $doc_id, $existing_terms[$term] ) )
$existing_terms[$term][] = $doc_id;
echo apply_filters( 'bp_docs_taxonomy_show_terms', $html, $tagtext );
}

// Then, loop through to see if any existing terms have been deleted
foreach ( $existing_terms as $existing_term => $docs ) {
// If the existing term is not in the list of submitted terms...
if ( ! in_array( $existing_term, $terms ) ) {
// ... check to see whether the current doc is listed under that
// term. If so, that indicates that the term has been removed from
// the doc
$key = array_search( $doc_id, $docs );
if ( $key !== false ) {
unset( $docs[$key] );
}
}

// Reset the array keys for the term's docs
$docs = array_values( $docs );

if ( empty( $docs ) ) {
// If there are no more docs associated with the term, we can remove
// it from the array
unset( $existing_terms[$existing_term] );
} else {
// Othewise, store the docs back in the existing terms array
$existing_terms[$existing_term] = $docs;
}
}

// Save the terms back to the item
$this->save_item_terms( $existing_terms );
}

/**
Expand Down Expand Up @@ -322,23 +265,24 @@ function save_item_terms( $terms ) {
function modify_tax_query( $tax_query ) {

// Check for the existence tag filters in the request URL
if ( !empty( $_REQUEST['bpd_tag'] ) ) {
if ( ! empty( $_REQUEST['bpd_tag'] ) ) {
// The bpd_tag argument may be comma-separated
$tags = explode( ',', urldecode( $_REQUEST['bpd_tag'] ) );

// Clean up the tag input
foreach( $tags as $key => $value ) {
foreach ( $tags as $key => $value ) {
$tags[$key] = esc_attr( $value );
}

$tax_query[] = array(
'taxonomy' => $this->docs_tag_tax_name,
'terms' => $tags,
'field' => 'slug'
'field' => 'slug',
);

if ( !empty( $_REQUEST['bool'] ) && $_REQUEST['bool'] == 'and' )
if ( !empty( $_REQUEST['bool'] ) && $_REQUEST['bool'] == 'and' ) {
$tax_query['operator'] = 'AND';
}
}

return apply_filters( 'bp_docs_modify_tax_query_for_tax', $tax_query );
Expand Down Expand Up @@ -367,11 +311,11 @@ function tags_th() {
*/
function tags_td() {

$tags = get_the_terms( get_the_ID(), $this->docs_tag_tax_name );
$tagtext = array();
$tags = get_the_terms( get_the_ID(), $this->docs_tag_tax_name );
$tagtext = array();

foreach( (array)$tags as $tag ) {
if ( !empty( $tag->name ) ) {
foreach ( (array) $tags as $tag ) {
if ( ! empty( $tag->name ) ) {
$tagtext[] = bp_docs_get_tag_link( array( 'tag' => $tag->name ) );
}
}
Expand Down Expand Up @@ -399,10 +343,10 @@ function tags_td() {
function info_header_message( $message, $filters ) {
$this->current_filters = $filters;

if ( !empty( $filters['tags'] ) ) {
if ( ! empty( $filters['tags'] ) ) {
$tagtext = array();

foreach( $filters['tags'] as $tag ) {
foreach ( $filters['tags'] as $tag ) {
$tagtext[] = bp_docs_get_tag_link( array( 'tag' => $tag ) );
}

Expand Down Expand Up @@ -436,25 +380,11 @@ function filter_markup() {

<div id="docs-filter-section-tags" class="docs-filter-section<?php if ( $tag_filter ) : ?> docs-filter-section-open<?php endif ?>">
<ul id="tags-list">
<?php if ( !empty( $existing_terms ) ) : ?>
<?php foreach( $existing_terms as $term => $posts ) : ?>
<?php if ( ! empty( $existing_terms ) ) : ?>
<?php foreach ( $existing_terms as $term => $posts ) : ?>
<?php $term_count = is_int( $posts ) ? $posts : count( $posts ) ?>
<li>
<a href="<?php echo bp_docs_get_tag_link( array( 'tag' => $term, 'type' => 'url' ) ) ?>" title="<?php echo esc_html( $term ) ?>"><?php echo esc_html( $term ) ?> <?php printf( __( '(%d)', 'bp-docs' ), $term_count ) ?></a>

<?php /* Going with tag cloud type fix for now */ ?>
<?php /*
<?php
$checked = empty( $this->current_filters ) || ( !empty( $this->current_filters['tags'] ) && in_array( $term, $this->current_filters['tags'] ) ) ? true : false;
?>
<label for="filter_terms[<?php echo esc_attr( $term ) ?>]">
<input type="checkbox" value="1" name="filter_terms[<?php echo esc_attr( $term ) ?>]" <?php checked( $checked ) ?>/>
<?php echo esc_html( $term ) ?> <?php printf( __( '(%d)', 'bp-docs' ), count( $posts ) ) ?>
</label>
*/ ?>
</li>

<?php endforeach ?>
Expand All @@ -474,10 +404,10 @@ function filter_markup() {
* @since 1.0-beta
*/
function handle_filters( $redirect_url ) {
if ( !empty( $_POST['filter_terms'] ) ) {
if ( ! empty( $_POST['filter_terms'] ) ) {
$tags = array();

foreach( $_POST['filter_terms'] as $term => $value ) {
foreach ( $_POST['filter_terms'] as $term => $value ) {
$tags[] = urlencode( $term );
}

Expand Down Expand Up @@ -512,13 +442,17 @@ function bp_docs_get_tag_link( $args = array() ) {

$defaults = array(
'tag' => false,
'type' => 'html'
'type' => 'html',
);

$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );

$item_docs_url = bp_docs_get_archive_link();
if ( bp_is_user() || bp_is_group() ) {
$item_docs_url = $_SERVER['REQUEST_URI'];
} 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 );

Expand All @@ -543,15 +477,19 @@ function bp_docs_post_tags_meta_box() {

require_once(ABSPATH . '/wp-admin/includes/taxonomy.php');

$defaults = array('taxonomy' => $bp->bp_docs->docs_tag_tax_name);
if ( !isset($box['args']) || !is_array($box['args']) )
$defaults = array(
'taxonomy' => $bp->bp_docs->docs_tag_tax_name,
);

if ( ! isset( $box['args'] ) || !is_array( $box['args'] ) )
$args = array();
else
$args = $box['args'];
extract( wp_parse_args($args, $defaults), EXTR_SKIP );

$tax_name = esc_attr($taxonomy);
$taxonomy = get_taxonomy($taxonomy);
extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );

$tax_name = esc_attr( $taxonomy );
$taxonomy = get_taxonomy( $taxonomy );

$terms = bp_docs_is_existing_doc() ? get_terms_to_edit( get_the_ID(), $bp->bp_docs->docs_tag_tax_name ) : '';
?>
Expand Down
Loading

0 comments on commit 5d38a43

Please sign in to comment.