Beispiel #1
0
/**
 * Links the users & tags in posts
 *
 * @see bp_activity_at_name_filter() BuddyPress Function
 * 
 * @param $content The content to be parsed
 */
function em_do_linking($content)
{
    global $em_plugopts;
    if ($em_plugopts['link-tags'] == 1) {
        preg_match_all('/[#]+([A-Za-z0-9-_]+)/', $content, $tags);
        $tags = $tags[1];
        foreach ((array) $tags as $tag) {
            if (!($t = bb_get_tag($tag))) {
                continue;
            }
            if ($link = bb_get_tag_link($t)) {
                $content = str_replace("#{$tag}", "#<a href='" . $link . "'>{$tag}</a>", $content);
            }
            //should we add rel='nofollow'?
        }
    }
    if ($em_plugopts['link-users'] == 1) {
        preg_match_all('/[@]+([A-Za-z0-9-_]+)/', $content, $usernames);
        $usernames = $usernames[1];
        foreach ((array) $usernames as $username) {
            if (!($user = bb_get_user($username, array('by' => 'login')))) {
                //check #1, by username
                if (!($user = bb_get_user($username, array('by' => 'nicename')))) {
                    //check #2, by nicename
                    continue;
                }
            }
            /* Increase the number of new @ mentions for the user - maybe later */
            /*$new_mention_count = (int)bb_get_usermeta( $user_id, 'em_mention_count' );
            		bb_update_usermeta( $user_id, 'em_mention_count', $new_mention_count + 1 );*/
            if ('website' == $em_plugopts['link-user-to']) {
                if (!($link = $user->user_url)) {
                    $link = get_user_profile_link($user->ID);
                }
            } else {
                $link = get_user_profile_link($user->ID);
            }
            if ($link) {
                $content = str_replace("@{$username}", "@<a href='" . $link . "'>{$username}</a>", $content);
            }
            //should we add rel='nofollow'?
        }
    }
    return $content;
}
Beispiel #2
0
<?php

require 'admin.php';
if (!bb_current_user_can('manage_tags')) {
    bb_die(__('You are not allowed to manage tags.'));
}
$tag_id = (int) $_POST['id'];
$tag = stripslashes($_POST['tag']);
bb_check_admin_referer('rename-tag_' . $tag_id);
if (!($old_tag = bb_get_tag($tag_id))) {
    bb_die(__('Tag not found.'));
}
if ($tag = bb_rename_tag($tag_id, $tag)) {
    wp_redirect(bb_get_tag_link());
} else {
    bb_die(printf(__('There already exists a tag by that name or the name is invalid. <a href="%s">Try Again</a>'), wp_get_referer()));
}
exit;
 /**
  * Constructor method.
  *
  * @param string $type The 'type' is the sort order/kind. 'newest',
  *        'popular', 'unreplied', 'tags'.
  * @param int $forum_id The ID of the forum for which topics are being
  *        queried.
  * @param int $user_id The ID of the user to whom topics should be
  *        limited. Pass false to remove this filter.
  * @param int $page The number of the page being requested.
  * @param int $per_page The number of items being requested perpage.
  * @param string $no_stickies Requested sticky format.
  * @param string $search_terms Filter results by a string.
  * @param int $offset Optional. Offset results by a given numeric value.
  * @param int $number Optional. Total number of items to retrieve.
  */
 function __construct($type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false)
 {
     global $bp;
     $this->pag_page = $page;
     $this->pag_num = $per_page;
     $this->type = $type;
     $this->search_terms = $search_terms;
     $this->forum_id = $forum_id;
     $this->offset = $offset;
     $this->number = $number;
     switch ($type) {
         case 'newest':
         default:
             $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number));
             break;
         case 'popular':
             $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'popular', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number));
             break;
         case 'unreplied':
             $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'unreplied', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number));
             break;
         case 'tags':
             $this->topics = bp_forums_get_forum_topics(array('user_id' => $user_id, 'type' => 'tags', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number));
             break;
     }
     $this->topics = apply_filters('bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies);
     if (!(int) $this->topics) {
         $this->topic_count = 0;
         $this->total_topic_count = 0;
     } else {
         // Get a total topic count, for use in pagination. This value will differ
         // depending on scope
         if (!empty($forum_id)) {
             // Group forums
             $topic_count = bp_forums_get_forum($forum_id);
             $topic_count = (int) $topic_count->topics;
         } else {
             if (!empty($bp->groups->current_group)) {
                 $topic_count = (int) groups_total_public_forum_topic_count($type);
             } else {
                 if (bp_is_user_forums_started() || bp_is_directory() && $user_id) {
                     // This covers the case of Profile > Forums > Topics Started, as
                     // well as Forum Directory > My Topics
                     $topic_count = bp_forums_total_topic_count_for_user(bp_displayed_user_id(), $type);
                 } else {
                     if (bp_is_user_forums_replied_to()) {
                         // Profile > Forums > Replied To
                         $topic_count = bp_forums_total_replied_count_for_user(bp_displayed_user_id(), $type);
                     } else {
                         if ('tags' == $type) {
                             $tag = bb_get_tag($search_terms);
                             $topic_count = $tag->count;
                         } else {
                             // For forum directories (All Topics), get a true count
                             $status = bp_current_user_can('bp_moderate') ? 'all' : 'public';
                             // todo: member-of
                             $topic_count = (int) groups_total_forum_topic_count($status, $search_terms);
                         }
                     }
                 }
             }
         }
         if (!$max || $max >= $topic_count) {
             $this->total_topic_count = $topic_count;
         } else {
             $this->total_topic_count = (int) $max;
         }
         if ($max) {
             if ($max >= count($this->topics)) {
                 $this->topic_count = count($this->topics);
             } else {
                 $this->topic_count = (int) $max;
             }
         } else {
             $this->topic_count = count($this->topics);
         }
     }
     $this->topic_count = apply_filters_ref_array('bp_forums_template_topic_count', array($this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies));
     $this->total_topic_count = apply_filters_ref_array('bp_forums_template_total_topic_count', array($this->total_topic_count, $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies));
     // Fetch extra information for topics, so we don't have to query inside the loop
     $this->topics = bp_forums_get_topic_extras($this->topics);
     if ((int) $this->total_topic_count && (int) $this->pag_num) {
         $this->pag_links = paginate_links(array('base' => add_query_arg(array('p' => '%#%', 'n' => $this->pag_num)), 'format' => '', 'total' => ceil((int) $this->total_topic_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('&larr;', 'Forum topic pagination previous text', 'buddypress'), 'next_text' => _x('&rarr;', 'Forum topic pagination next text', 'buddypress'), 'mid_size' => 1));
     }
 }
function bb_repermalink()
{
    global $page;
    $location = bb_get_location();
    $uri = $_SERVER['REQUEST_URI'];
    if (isset($_GET['id'])) {
        $id = $_GET['id'];
    } else {
        $id = bb_get_path();
    }
    $_original_id = $id;
    do_action('pre_permalink', $id);
    $id = apply_filters('bb_repermalink', $id);
    switch ($location) {
        case 'front-page':
            $path = null;
            $querystring = null;
            if ($page > 1) {
                if (bb_get_option('mod_rewrite')) {
                    $path = 'page/' . $page;
                } else {
                    $querystring = array('page' => $page);
                }
            }
            $permalink = bb_get_uri($path, $querystring, BB_URI_CONTEXT_HEADER);
            $issue_404 = true;
            break;
        case 'forum-page':
            if (empty($id)) {
                $permalink = bb_get_uri(null, null, BB_URI_CONTEXT_HEADER);
                break;
            }
            global $forum_id, $forum;
            $forum = bb_get_forum($id);
            $forum_id = $forum->forum_id;
            $permalink = get_forum_link($forum->forum_id, $page);
            break;
        case 'topic-edit-page':
        case 'topic-page':
            if (empty($id)) {
                $permalink = bb_get_uri(null, null, BB_URI_CONTEXT_HEADER);
                break;
            }
            global $topic_id, $topic;
            $topic = get_topic($id);
            $topic_id = $topic->topic_id;
            $permalink = get_topic_link($topic->topic_id, $page);
            break;
        case 'profile-page':
            // This handles the admin side of the profile as well.
            global $user_id, $user, $profile_hooks, $self;
            if (isset($_GET['id'])) {
                $id = $_GET['id'];
            } elseif (isset($_GET['username'])) {
                $id = $_GET['username'];
            } else {
                $id = bb_get_path();
            }
            $_original_id = $id;
            if (!$id) {
                $user = bb_get_current_user();
                // Attempt to go to the current users profile
            } else {
                if (bb_get_option('mod_rewrite') === 'slugs') {
                    if (!($user = bb_get_user_by_nicename($id))) {
                        $user = bb_get_user($id);
                    }
                } else {
                    if (!($user = bb_get_user($id))) {
                        $user = bb_get_user_by_nicename($id);
                    }
                }
            }
            if (!$user || 1 == $user->user_status && !bb_current_user_can('moderate')) {
                bb_die(__('User not found.'), '', 404);
            }
            $user_id = $user->ID;
            bb_global_profile_menu_structure();
            $valid = false;
            if ($tab = isset($_GET['tab']) ? $_GET['tab'] : bb_get_path(2)) {
                foreach ($profile_hooks as $valid_tab => $valid_file) {
                    if ($tab == $valid_tab) {
                        $valid = true;
                        $self = $valid_file;
                    }
                }
            }
            if ($valid) {
                $permalink = get_profile_tab_link($user->ID, $tab, $page);
            } else {
                $permalink = get_user_profile_link($user->ID, $page);
                unset($self, $tab);
            }
            break;
        case 'favorites-page':
            $permalink = get_favorites_link();
            break;
        case 'tag-page':
            // It's not an integer and tags.php pulls double duty.
            $id = isset($_GET['tag']) ? $_GET['tag'] : false;
            if (!$id || !bb_get_tag((string) $id)) {
                $permalink = bb_get_tag_page_link();
            } else {
                global $tag, $tag_name;
                $tag_name = $id;
                $tag = bb_get_tag((string) $id);
                $permalink = bb_get_tag_link(0, $page);
                // 0 => grabs $tag from global.
            }
            break;
        case 'view-page':
            // Not an integer
            if (isset($_GET['view'])) {
                $id = $_GET['view'];
            } else {
                $id = bb_get_path();
            }
            $_original_id = $id;
            global $view;
            $view = $id;
            $permalink = get_view_link($view, $page);
            break;
        default:
            return;
            break;
    }
    nxt_parse_str($_SERVER['QUERY_STRING'], $args);
    $args = urlencode_deep($args);
    if ($args) {
        $permalink = add_query_arg($args, $permalink);
        if (bb_get_option('mod_rewrite')) {
            $pretty_args = array('id', 'page', 'tag', 'tab', 'username');
            // these are already specified in the path
            if ($location == 'view-page') {
                $pretty_args[] = 'view';
            }
            foreach ($pretty_args as $pretty_arg) {
                $permalink = remove_query_arg($pretty_arg, $permalink);
            }
        }
    }
    $permalink = apply_filters('bb_repermalink_result', $permalink, $location);
    $domain = bb_get_option('domain');
    $domain = preg_replace('/^https?/', '', $domain);
    $check = preg_replace('|^.*' . trim($domain, ' /') . '|', '', $permalink, 1);
    $uri = rtrim($uri, " \t\n\r\v?");
    $uri = str_replace('/index.php', '/', $uri);
    global $bb_log;
    $bb_log->debug($uri, 'bb_repermalink() ' . __('REQUEST_URI'));
    $bb_log->debug($check, 'bb_repermalink() ' . __('should be'));
    $bb_log->debug($permalink, 'bb_repermalink() ' . __('full permalink'));
    $bb_log->debug(isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null, 'bb_repermalink() ' . __('PATH_INFO'));
    if ($check != $uri && $check != str_replace(urlencode($_original_id), $_original_id, $uri)) {
        if ($issue_404 && rtrim($check, " \t\n\r\v/") !== rtrim($uri, " \t\n\r\v/")) {
            status_header(404);
            bb_load_template('404.php');
        } else {
            nxt_redirect($permalink);
        }
        exit;
    }
    do_action('post_permalink', $permalink);
}
Beispiel #5
0
 /**
  * Destroys the specified tag
  *
  * @since 1.0
  * @return integer|object 1 when successfully deleted or an IXR_Error object on failure
  * @param array $args Arguments passed by the XML-RPC call
  * @param string $args[0] The username for authentication
  * @param string $args[1] The password for authentication
  * @param string $args[2] The tag name or slug to be destroyed
  *
  * XML-RPC request to destroy the tag "banana"
  * <methodCall>
  *     <methodName>bb.destroyTopicTag</methodName>
  *     <params>
  *         <param><value><string>joeblow</string></value></param>
  *         <param><value><string>123password</string></value></param>
  *         <param><value><string>banana</string></value></param>
  *     </params>
  * </methodCall>
  */
 function bb_destroyTopicTag($args)
 {
     do_action('bb_xmlrpc_call', 'bb.destroyTopicTag');
     // Escape args
     $this->escape($args);
     // Get the login credentials
     $username = $args[0];
     $password = (string) $args[1];
     // Check the user is valid
     $user = $this->authenticate($username, $password, 'manage_tags', __('You do not have permission to manage tags.'));
     do_action('bb_xmlrpc_call_authenticated', 'bb.destroyTopicTag');
     // If an error was raised by authentication or by an action then return it
     if ($this->error) {
         return $this->error;
     }
     // Can only be a string
     $tag_id = isset($args[2]) ? (string) $args[2] : false;
     // Check for bad data
     if (!$tag_id) {
         $this->error = new IXR_Error(400, __('The tag id is invalid.'));
         return $this->error;
     }
     // Check the requested tag exists
     if (!($tag = bb_get_tag($tag_id))) {
         $this->error = new IXR_Error(400, __('No tag found.'));
         return $this->error;
     }
     // Get the numeric tag id
     $tag_id = (int) $tag->tag_id;
     // Destroy the tag
     if (!($result = bb_destroy_tag($tag_id))) {
         $this->error = new IXR_Error(500, __('The tag could not be destroyed.'));
         return $this->error;
     }
     $result = 1;
     do_action('bb_xmlrpc_call_return', 'bb.destroyTopicTag');
     // Return the tag
     return $result;
 }
function bb_merge_tags($old_id, $new_id)
{
    if (!bb_current_user_can('manage_tags')) {
        return false;
    }
    $old_id = (int) $old_id;
    $new_id = (int) $new_id;
    if ($old_id == $new_id) {
        return false;
    }
    do_action('bb_pre_merge_tags', $old_id, $new_id);
    // Get all topics tagged with old tag
    $old_topics = bb_get_tagged_topic_ids($old_id);
    // Get all toics tagged with new tag
    $new_topics = bb_get_tagged_topic_ids($new_id);
    // Get intersection of those topics
    $both_topics = array_intersect($old_topics, $new_topics);
    // Discard the intersection from the old tags topics
    $old_topics = array_diff($old_topics, $both_topics);
    // Add the remainder of the old tag topics to the new tag
    if (count($old_topics)) {
        $new_tag = bb_get_tag($new_id);
        foreach ($old_topics as $old_topic) {
            bb_add_topic_tag($old_topic, $new_tag->slug);
        }
    }
    // Destroy the old tag
    $old_tag = bb_destroy_tag($old_id);
    return array('destroyed' => $old_tag, 'old_count' => count($old_topics), 'diff_count' => count($both_topics));
}
function bb_get_tag_by_name($tag)
{
    bb_log_deprecated('function', __FUNCTION__, 'bb_get_tag');
    return bb_get_tag($tag);
}
function bb_get_tag_remove_link($args = null)
{
    if (is_scalar($args) || is_object($args)) {
        $args = array('tag' => $args);
    }
    $defaults = array('tag' => 0, 'topic' => 0, 'list_id' => 'tags-list');
    $args = wp_parse_args($args, $defaults);
    extract($args, EXTR_SKIP);
    if (is_object($tag) && isset($tag->tag_id)) {
    } elseif (!($tag = bb_get_tag(bb_get_tag_id($tag)))) {
        return false;
    }
    if (!($topic = get_topic(get_topic_id($topic)))) {
        return false;
    }
    if (!bb_current_user_can('edit_tag_by_on', $tag->user_id, $topic->topic_id)) {
        return false;
    }
    $url = bb_get_uri('tag-remove.php', array('tag' => $tag->tag_id, 'user' => $tag->user_id, 'topic' => $topic->topic_id));
    $url = esc_url(bb_nonce_url($url, 'remove-tag_' . $tag->tag_id . '|' . $topic->topic_id));
    $title = esc_attr__('Remove this tag');
    $list_id = esc_attr($list_id);
    return "[<a href='{$url}' class='delete:{$list_id}:tag-{$tag->tag_id}_{$tag->user_id}' title='{$title}'>&times;</a>]";
}
Beispiel #9
0
     if (!($tag = bb_get_tag($feed_id))) {
         die;
     }
     if (!($topics = get_tagged_topics(array('tag_id' => $tag->tag_id, 'page' => 0)))) {
         die;
     }
     $posts = array();
     foreach ($topics as $topic) {
         $posts[] = bb_get_first_post($topic->topic_id);
     }
     $title = esc_html(sprintf(__('%1$s &raquo; Tag: %2$s - Recent Topics'), bb_get_option('name'), bb_get_tag_name()));
     $link = bb_get_tag_link($feed_id);
     $link_self = bb_get_tag_topics_rss_link($feed_id);
     break;
 case 'tag-posts':
     if (!($tag = bb_get_tag($feed_id))) {
         die;
     }
     if (!($posts = get_tagged_topic_posts(array('tag_id' => $tag->tag_id, 'page' => 0)))) {
         die;
     }
     $title = esc_html(sprintf(__('%1$s &raquo; Tag: %2$s - Recent Posts'), bb_get_option('name'), bb_get_tag_name()));
     $link = bb_get_tag_link($feed_id);
     $link_self = bb_get_tag_posts_rss_link($feed_id);
     break;
 case 'forum-topics':
     if (!($topics = get_latest_topics($feed_id))) {
         die;
     }
     $posts = array();
     foreach ($topics as $topic) {
Beispiel #10
0
         $tag->raw_tag = esc_attr($tag->raw_tag);
         $x->add(array('what' => 'tag', 'id' => $tag_id_val, 'data' => _bb_list_tag_item($tag, array('list_id' => 'tags-list', 'format' => 'list'))));
     }
     $x->send();
     break;
 case 'delete-tag':
     list($tag_id, $user_id) = explode('_', $_POST['id']);
     $tag_id = (int) $tag_id;
     $user_id = (int) $user_id;
     $topic_id = (int) $_POST['topic_id'];
     if (!bb_current_user_can('edit_tag_by_on', $user_id, $topic_id)) {
         die('-1');
     }
     bb_check_ajax_referer("remove-tag_{$tag_id}|{$topic_id}");
     add_action('bb_rpe_tag_removed', 'bb_grab_results', 10, 3);
     $tag = bb_get_tag($tag_id);
     $user = bb_get_user($user_id);
     $topic = get_topic($topic_id);
     if (!$tag || !$topic) {
         die('0');
     }
     if (false !== bb_remove_topic_tag($tag_id, $user_id, $topic_id)) {
         die('1');
     }
     break;
 case 'dim-favorite':
     $user_id = bb_get_current_user_info('id');
     if (!($topic = get_topic($id))) {
         die('0');
     }
     if (!bb_current_user_can('edit_favorites_of', $user_id)) {
Beispiel #11
0
<?php

require 'admin.php';
if (!bb_current_user_can('manage_tags')) {
    bb_die(__('You are not allowed to manage tags.'));
}
$old_id = (int) $_POST['id'];
$tag = $_POST['tag'];
bb_check_admin_referer('merge-tag_' . $old_id);
if (!($tag = bb_get_tag($tag))) {
    bb_die(__('The destination tag you specified could not be found.'));
}
if (!bb_get_tag($old_id)) {
    bb_die(__('The original tag could not be found.'));
}
if ($merged = bb_merge_tags($old_id, $tag->tag_id)) {
    bb_die(sprintf(__("Number of topics from which the old tag was removed: %d <br />\n"), $merged['old_count']) . sprintf(__("Number of topics to which the new tag was added: %d <br />\n"), $merged['diff_count']) . sprintf(__("Number of rows deleted from tags table:%d <br />\n"), $merged['destroyed']['tags']) . sprintf(__('<a href="%s">View Results of Merge</a>'), bb_get_tag_link()));
} else {
    bb_die(printf(__("Something odd happened when attempting to merge those tags.<br />\n<a href=\"%s\">Try Again?</a>"), nxt_get_referer()));
}