Skip to:
Content

bbPress.org


Ignore:
Timestamp:
06/10/2009 08:09:35 AM (17 years ago)
Author:
sambauers
Message:

Update bb-taxonomy based on last sync of wp-taxonomy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-includes/class.bb-taxonomy.php

    r2011 r2139  
    6666                $terms = "'" . implode("', '", $terms) . "'";
    6767
    68                 $sql = "SELECT tr.object_id FROM {$this->db->term_relationships} AS tr INNER JOIN {$this->db->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_taxonomy_id IN ($terms)";
     68                $sql = "SELECT tr.object_id FROM {$this->db->term_relationships} AS tr INNER JOIN {$this->db->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND $field IN ($terms)";
    6969                if ( $user_id )
    7070                        $sql .= " AND tr.user_id = '$user_id'";
    … …  
    8080
    8181        /**
    82          * Will unlink the term from the taxonomy
     82         * Will unlink the term from the taxonomy.
    8383         *
    8484         * Will remove the term's relationship to the taxonomy, not the term or taxonomy
    … …  
    9292         * @param int $object_id The term Object Id that refers to the term
    9393         * @param string|array $taxonomy List of Taxonomy Names or single Taxonomy name.
     94         * @param int $user_id The ID of the user who created the relationship.
    9495         */
    9596        function delete_object_term_relationships( $object_id, $taxonomies, $user_id = 0 ) {
    … …  
    163164                        foreach ( $taxonomies as $index => $taxonomy ) {
    164165                                $t = $this->get_taxonomy($taxonomy);
    165                                 if ( is_array($t->args) && $args != array_merge($args, $t->args) ) {
     166                                if ( isset($t->args) && is_array($t->args) && $args != array_merge($args, $t->args) ) {
    166167                                        unset($taxonomies[$index]);
    167168                                        $terms = array_merge($terms, $this->get_object_terms($object_ids, $taxonomy, array_merge($args, $t->args)));
    … …  
    187188                else if ( 'term_order' == $orderby )
    188189                        $orderby = 'tr.term_order';
    189                 else
     190                else if ( 'none' == $orderby ) {
     191                        $orderby = '';
     192                        $order = '';
     193                } else {
    190194                        $orderby = 't.term_id';
     195                }
     196
     197                // tt_ids queries can only be none or tr.term_taxonomy_id
     198                if ( ('tt_ids' == $fields) && !empty($orderby) )
     199                        $orderby = 'tr.term_taxonomy_id';
     200
     201                if ( !empty($orderby) )
     202                        $orderby = "ORDER BY $orderby";
    191203
    192204                $taxonomies = "'" . implode("', '", $taxonomies) . "'";
    … …  
    206218                if ( $user_id )
    207219                        $query .= " AND user_id = '$user_id'";
    208                 $query .= " ORDER BY $orderby $order";
     220                $query .= " $orderby $order";
    209221
    210222                if ( 'all' == $fields || 'all_with_object_id' == $fields ) {
    … …  
    217229                        if ( $user_id )
    218230                                $query .= " AND tr.user_id = '$user_id'";
    219                         $query .= " ORDER BY tr.term_taxonomy_id $order";
     231                        $query .= " $orderby $order";
    220232                        $terms = $this->db->get_col( $query );
    221233                }
    222234
    223235                if ( ! $terms )
    224                         return array();
    225 
    226                 return $terms;
     236                        $terms = array();
     237
     238                return apply_filters('wp_get_object_terms', $terms, $object_ids, $taxonomies, $args);
    227239        }
    228240
    … …  
    243255         *
    244256         * @param int $object_id The object to relate to.
    245          * @param array|int|string $term The slug or id of the term.
     257         * @param array|int|string $term The slug or id of the term, will replace all existing
     258         * related terms in this taxonomy.
    246259         * @param array|string $taxonomy The context in which to relate the term to the object.
    247260         * @param bool $append If false will delete difference of terms.
    … …  
    266279
    267280                if ( ! $append )
    268                         $old_terms =  $this->get_object_terms($object_id, $taxonomy, array( 'user_id' => $user_id, 'fields' => 'tt_ids' ));
     281                        $old_tt_ids = $this->get_object_terms($object_id, $taxonomy, array('user_id' => $user_id, 'fields' => 'tt_ids', 'orderby' => 'none'));
    269282
    270283                $tt_ids = array();
    … …  
    291304
    292305                if ( ! $append ) {
    293                         $delete_terms = array_diff($old_terms, $tt_ids);
     306                        $delete_terms = array_diff($old_tt_ids, $tt_ids);
    294307                        if ( $delete_terms ) {
    295308                                $in_delete_terms = "'" . implode("', '", $delete_terms) . "'";
    … …  
    303316                        $values = array();
    304317                        $term_order = 0;
    305                         $final_term_ids = $this->get_object_terms($object_id, $taxonomy, array( 'user_id' => $user_id, 'fields' => 'tt_ids' ));
    306                         foreach ( $term_ids as $term_id )
    307                                 if ( in_array($term_id, $final_term_ids) )
    308                                         $values[] = $this->db->prepare( "(%d, %d, %d, %d)", $object_id, $term_id, $user_id, ++$term_order);
     318                        $final_tt_ids = $this->get_object_terms($object_id, $taxonomy, array( 'user_id' => $user_id, 'fields' => 'tt_ids' ));
     319                        foreach ( $tt_ids as $tt_id )
     320                                if ( in_array($tt_id, $final_tt_ids) )
     321                                        $values[] = $this->db->prepare( "(%d, %d, %d, %d)", $object_id, $tt_id, $user_id, ++$term_order);
    309322                        if ( $values )
    310323                                $this->db->query("INSERT INTO {$this->db->term_relationships} (object_id, term_taxonomy_id, user_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)");
    311324                }
    312325
     326                do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append);
    313327                return $tt_ids;
    314328        }
Note: See TracChangeset for help on using the changeset viewer.