Changeset 125
- Timestamp:
- 06/04/2005 11:27:38 PM (21 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
-
bb-admin/tag-destroy.php (modified) (1 diff)
-
bb-admin/tag-merge.php (added)
-
bb-includes/formatting-functions.php (modified) (1 diff)
-
bb-includes/functions.php (modified) (5 diffs)
-
bb-includes/template-functions.php (modified) (1 diff)
-
bb-templates/tag-single.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bb-admin/tag-destroy.php
r123 r125 13 13 die('Tag not found.'); 14 14 15 if ( $destroyed = destroy_tag( $tag_id ) ) 16 header('Location: ' . $bb->path ); 17 else 18 die("Something odd happened when attempting to destroy that tag. Error code: $destroyed. <a href=\"" . $_SERVER['HTTP_REFERER'] . '">Try Again</a>'); 15 if ( $destroyed = destroy_tag( $tag_id ) ) { 16 echo 'Rows deleted from tags table: ' . $destroyed['tags'] . "<br />\n"; 17 echo 'Rows deleted from tagged table: ' . $destroyed['tagged'] . "<br />\n"; 18 echo 'Destruction Successful? ' . ($destroyed['destroyed']) ? "TRUE\n" : "FALSE<br />\n 19 \t NOTE: destruction of a tag that is not associated with any posts will give a false negative.<br />\n"; 20 echo '<a href="'. $bb->path . '">Home</a>'; 21 } else { 22 var_dump($destroyed); 23 die("<br />Something odd happened when attempting to destroy that tag. See the above Error codes.<br />\n<a href=\"" . $_SERVER['HTTP_REFERER'] . '">Try Again?</a>'); 24 } 19 25 ?> -
trunk/bb-includes/formatting-functions.php
r59 r125 117 117 } 118 118 119 function tag_sanitize( $tag ) { 120 $tag = trim ( $tag ); 121 $tag = strtolower ( $tag ); 122 $tag = preg_replace ( '/\s/', '', $tag ); 123 $tag = user_sanitize( $tag ); 124 return $tag; 125 } 126 119 127 function show_context( $term, $text ) { 120 128 $text = strip_tags($text); -
trunk/bb-includes/functions.php
r122 r125 658 658 global $bbdb; 659 659 $raw_tag = $tag; 660 $tag = trim ( $tag ); 661 $tag = strtolower ( $tag ); 662 $tag = preg_replace ( '/\s/', '', $tag ); 663 $tag = user_sanitize( $tag ); 660 $tag = tag_sanitize( $tag ); 664 661 if ( empty( $tag ) ) 665 662 return false; … … 677 674 return false; 678 675 $raw_tag = $tag; 679 $tag = trim ( $tag ); 680 $tag = strtolower ( $tag ); 681 $tag = preg_replace ( '/\s/', '', $tag ); 682 $tag = user_sanitize( $tag ); 676 $tag = tag_sanitize( $tag ); 683 677 684 678 if ( empty( $tag ) ) … … 705 699 bb_do_action('bb_tag_removed', $tagged); 706 700 707 if ( $removed = $bbdb->query("DELETE FROM $bbdb->tagged WHERE tag_id = '$tag_id' AND user_id = '$user_id' AND topic_id = '$topic_id'") ); 708 $removed += $bbdb->query("UPDATE $bbdb->tags SET tag_count = tag_count - 1 WHERE tag_id = '$tag_id'"); 709 $removed *= 10; 701 if ( $tags = $bbdb->query("DELETE FROM $bbdb->tagged WHERE tag_id = '$tag_id' AND user_id = '$user_id' AND topic_id = '$topic_id'") ); 702 $tagged = $bbdb->query("UPDATE $bbdb->tags SET tag_count = tag_count - 1 WHERE tag_id = '$tag_id'"); 710 703 if ( !$bbdb->get_var("SELECT tag_id FROM $bbdb->tagged WHERE tag_id = '$tag_id' LIMIT 1") ) // don't trust tag_count? 711 $removed += destroy_tag( $tag_id ); 712 return $removed; // debugging: 2_ normally, 1_ if didn't update count, 0_ if didn't delete from tagged 704 $destroyed = destroy_tag( $tag_id ); 705 return array( 'removed' => ($tags && $tagged), 'tags' => $tags, 'tagged' => $tagged, 'destroyed' => $destroyed ); 706 } 707 708 // merge $old_id into $new_id. MySQL 4.0 can't do IN on tuples! 709 function merge_tags( $old_id, $new_id ) { 710 global $bbdb, $current_user; 711 if ( $current_user->user_type < 2) 712 return false; 713 if ( $old_id == $new_id ) 714 return false; 715 716 $merged_tags = serialize( array( 'old_id' => $old_id, 'new_id' => $new_id ) ); 717 718 bb_do_action('bb_tag_merged', $merged_tags); 719 720 $tagged_del = 0; 721 if ( $old_topic_ids = $bbdb->get_col( "SELECT topic_id FROM $bbdb->tagged WHERE tag_id = '$old_id'" ) ) { 722 $old_topic_ids = join(',', $old_topic_ids); 723 $shared_query = "SELECT user_id, topic_id FROM $bbdb->tagged WHERE tag_id = '$new_id' AND topic_id IN ($old_topic_ids)"; 724 $shared_topics = $bbdb->get_results( $shared_query ); 725 $shared_count = count($shared_topics); 726 foreach ( $shared_topics as $shared_topic ) 727 $tagged_del += $bbdb->query( "DELETE FROM $bbdb->tagged WHERE tag_id = '$old_id' AND user_id = '$shared_topic->user_id' AND topic_id = '$shared_topic->topic_id'" ); 728 } 729 730 if ( $diff_count = $bbdb->query( "UPDATE $bbdb->tagged SET tag_id = '$new_id' WHERE tag_id = '$old_id'" ) ) 731 $bbdb->query( "UPDATE $bbdb->tags SET tag_count = tag_count + $diff_count WHERE tag_id = '$new_id'" ); 732 733 // return values and destroy the old tag 734 return array( 'destroyed' => destroy_tag( $old_id ), 'old_count' => $diff_count + $shared_count, 'diff_count' => $diff_count ); 713 735 } 714 736 … … 720 742 bb_do_action('bb_tag_destroyed', $tag_id); 721 743 722 if ( $ destroyed= $bbdb->query("DELETE FROM $bbdb->tags WHERE tag_id = '$tag_id'") )723 $ destroyed += $bbdb->query("DELETE FROM $bbdb->tagged WHERE tag_id = '$tag_id'");724 return $destroyed; // debugging: 2 normally, 1 if didn't delete from tagged, 0 if didn't delete from tags744 if ( $tags = $bbdb->query("DELETE FROM $bbdb->tags WHERE tag_id = '$tag_id'") ) 745 $tagged = $bbdb->query("DELETE FROM $bbdb->tagged WHERE tag_id = '$tag_id'"); 746 return array( 'destroyed' => ($tags && $tagged), 'tags' => $tags, 'tagged' => $tagged ); 725 747 } 726 748 727 749 function get_tag_id( $tag ) { 728 750 global $bbdb; 729 $tag = strtolower ( $tag ); 730 $tag = preg_replace ( '/\s/', '', $tag ); 731 $tag = user_sanitize( $tag ); 751 $tag = tag_sanitize( $tag ); 732 752 733 753 return $bbdb->get_var("SELECT tag_id FROM $bbdb->tags WHERE tag = '$tag'"); … … 742 762 function get_tag_by_name( $tag ) { 743 763 global $bbdb; 744 $tag = strtolower ( $tag ); 745 $tag = preg_replace ( '/\s/', '', $tag ); 746 $tag = user_sanitize( $tag ); 764 $tag = tag_sanitize( $tag ); 747 765 748 766 return $bbdb->get_row("SELECT * FROM $bbdb->tags WHERE tag = '$tag'"); -
trunk/bb-includes/template-functions.php
r124 r125 549 549 } 550 550 551 function tag_merge_form() { 552 global $tag, $current_user; 553 if ( $current_user->user_type < 2 ) 554 return false; 555 $tag_merge_form = '<form id="tag-merge" method="post" action="' . bb_get_option('uri') . 'bb-admin/tag-merge.php">' . "\n"; 556 $tag_merge_form .= "<p>Merge this tag into the tag specified</p>\n<p>\n" . '<input type="text" name="tag" size="10" maxlength="30" />' . "\n"; 557 $tag_merge_form .= '<input type="hidden" name="id" value="' . $tag->tag_id . '" />' . "\n"; 558 $tag_merge_form .= '<input type="submit" name="Submit" value="Merge" />' . "\n</p>\n</form>"; 559 echo $tag_merge_form; 560 } 561 551 562 function tag_destroy_form() { 552 563 global $tag, $current_user; -
trunk/bb-templates/tag-single.php
r120 r125 6 6 7 7 <?php tag_destroy_form(); ?> 8 9 <?php tag_merge_form(); ?> 8 10 9 11 <h2><a href="<?php option('uri'); ?>"><?php option('name'); ?></a> » <a href="<?php tag_page_link(); ?>">Tags</a> » <?php tag_name(); ?></h2>
Note: See TracChangeset
for help on using the changeset viewer.