Пример #1
0
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));
}
Пример #2
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;
 }
Пример #3
0
function destroy_tag($tag_id, $recount_topics = true)
{
    bb_log_deprecated('function', __FUNCTION__, 'bb_destroy_tag');
    return bb_destroy_tag($tag_id, $recount_topics);
}
Пример #4
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'];
bb_check_admin_referer('destroy-tag_' . $tag_id);
if (!($old_tag = bb_get_tag($tag_id))) {
    bb_die(__('Tag not found.'));
}
if (bb_destroy_tag($tag_id)) {
    bb_die(__('That tag was successfully destroyed'));
} else {
    bb_die(printf(__("Something odd happened when attempting to destroy that tag.<br />\n<a href=\"%s\">Try Again?</a>"), wp_get_referer()));
}
Пример #5
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'];
bb_check_admin_referer('destroy-tag_' . $tag_id);
$old_tag = bb_get_tag($tag_id);
if (!$old_tag) {
    bb_die(__('Tag not found.'));
}
if ($destroyed = bb_destroy_tag($tag_id)) {
    printf(__("Rows deleted from tags table: %d <br />\n"), $destroyed['tags']);
    printf(__("Rows deleted from tagged table: %d <br />\n"), $destroyed['tagged']);
    printf(__('<a href="%s">Home</a>'), bb_get_uri());
} else {
    die(printf(__("Something odd happened when attempting to destroy that tag.<br />\n<a href=\"%s\">Try Again?</a>"), wp_get_referer()));
}
Пример #6
0
function bb_recount_tag_delete_empty()
{
    // Get all tags
    if (!isset($terms)) {
        $terms = $wp_taxonomy_object->get_terms('bb_topic_tag', array('hide_empty' => false));
    }
    if (!is_wp_error($terms) && is_array($terms)) {
        $message = __('Deleted tags with no topics');
        foreach ($terms as $term) {
            $topic_ids = bb_get_tagged_topic_ids($term->term_id);
            if (!is_wp_error($topic_ids) && is_array($topic_ids)) {
                if (false === $topic_ids || is_array($topic_ids) && !count($topic_ids)) {
                    bb_destroy_tag($term->term_taxonomy_id);
                }
            }
            unset($topic_ids);
        }
    }
    unset($terms, $term);
    return $message;
}
Пример #7
0
         }
     }
     unset($term, $_terms);
 }
 if (isset($_POST['tags-delete-empty']) && 1 == $_POST['tags-delete-empty']) {
     // Get all tags
     if (!isset($terms)) {
         $terms = $wp_taxonomy_object->get_terms('bb_topic_tag', array('hide_empty' => false));
     }
     if (!is_wp_error($terms) && is_array($terms)) {
         $messages[] = __('Deleted tags with no topics');
         foreach ($terms as $term) {
             $topic_ids = bb_get_tagged_topic_ids($term->term_id);
             if (!is_wp_error($topic_ids) && is_array($topic_ids)) {
                 if (false === $topic_ids || is_array($topic_ids) && !count($topic_ids)) {
                     bb_destroy_tag($term->term_taxonomy_id);
                 }
             }
             unset($topic_ids);
         }
     }
     unset($terms, $term);
 }
 if (isset($_POST['clean-favorites']) && 1 == $_POST['clean-favorites']) {
     $favorites_key = $bbdb->prefix . 'favorites';
     if ($users = $bbdb->get_results("SELECT user_id AS id, meta_value AS favorites FROM {$bbdb->usermeta} WHERE meta_key = '" . $favorites_key . "'")) {
         $messages[] = __('Removed deleted topics from users\' favorites');
         $topics = $bbdb->get_col("SELECT topic_id FROM {$bbdb->topics} WHERE topic_status = '0'");
         foreach ($users as $user) {
             foreach (explode(',', $user->favorites) as $favorite) {
                 if (!in_array($favorite, $topics)) {