Skip to:
Content

bbPress.org

Changeset 139


Ignore:
Timestamp:
06/11/2005 09:50:08 PM (21 years ago)
Author:
mdawaffe
Message:

Add topic_resolved column and resolution functions. Run most recent (top) line in bb-admin/upgrade.php. Fixes #78. Ensures normal users cannot edit resolution status, tags, etc. on close topic. Fixes #77.

Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/bb-admin/upgrade-schema.php

    r121 r139  
    3737  forum_id int(10) NOT NULL default '1',
    3838  topic_status tinyint(1) NOT NULL default '0',
     39  topic_resolved varchar(15) NOT NULL default 'no',
    3940  topic_open tinyint(1) NOT NULL default '1',
    4041  topic_last_post_id bigint(20) NOT NULL default '1',
  • trunk/bb-admin/upgrade.php

    r121 r139  
    44set_time_limit(600);
    55// Uncomment to use. Best to run one at a time
     6
     7/* Add _topics.topic_resolved column
     8$bbdb->query("ALTER TABLE $bbdb->topics ADD topic_resolved VARCHAR(15) DEFAULT 'no' NOT NULL AFTER topic_status");
     9echo "Done with adding topic_resolved column\n";
     10flush();
     11*/
    612
    713/* Populate _topics.topic_start_time: June 3rd, 2005
     
    1723unset($topics);
    1824echo "Done with adding topic_start_time...\n";
     25flush();
     26*/
     27
     28/* Add _topics.topic_start_time column
     29$bbdb->query("ALTER TABLE $bbdb->topics ADD topic_start_time DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER topic_last_poster_name");
     30echo "Done with adding topic_start_time column\n";
    1931flush();
    2032*/
  • trunk/bb-includes/functions.php

    r137 r139  
    344344    if ( $forum && $title ) {
    345345        $bbdb->query("INSERT INTO $bbdb->topics
    346         (topic_title, topic_poster, topic_poster_name, topic_last_poster, topic_last_poster_name, topic_time, forum_id, topic_start_time)
     346        (topic_title, topic_poster, topic_poster_name, topic_last_poster, topic_last_poster_name, topic_start_time, topic_time, forum_id)
    347347        VALUES
    348         ('$title', $current_user->user_id, '$current_user->username', $current_user->user_id, '$current_user->username', '$now', $forum, '$now')");
     348        ('$title', $current_user->user_id, '$current_user->username', $current_user->user_id, '$current_user->username', '$now', '$now', $forum)");
    349349        $topic_id = $bbdb->insert_id;
    350350        if ( !empty( $tags ) )
     
    428428}
    429429
     430function bb_resolve_topic ( $topic_id, $resolved = 'yes' ) {
     431    global $bbdb;
     432    if ( ! in_array($resolved, array('yes', 'no', 'mu')) )
     433        return false;
     434    bb_do_action('resolve_topic', $topic_id);
     435    return $bbdb->query("UPDATE $bbdb->topics SET topic_resolved = '$resolved' WHERE topic_id = '$topic_id'");
     436}
     437
    430438function bb_close_topic ( $topic_id ) {
    431439    global $bbdb;
     
    545553    else
    546554        return true;
     555}
     556
     557function can_edit_topic( $topic_id, $user_id = 0 ) {
     558    global $current_user;
     559    if ( empty($current_user) )
     560        return false;
     561    if ( ! $user_id )
     562        $user_id = $current_user->user_id;
     563    $user = bb_get_user( $user_id );
     564    $topic = get_topic( $topic_id );
     565    $topic_poster = bb_get_user( $topic->topic_poster );
     566
     567    if ( $user->user_type > 1)
     568        return true;
     569
     570    if ( $user->user_type > $topic_poster->user_type )
     571        return true;
     572
     573    if ( $user->user_id != $topic_poster->user_id )
     574        return false;
     575   
     576    if ( ! topic_is_open( $topic_id ) )
     577        return false;
     578
     579    return true;
    547580}
    548581
     
    628661function add_topic_tag( $topic_id, $tag ) {
    629662    global $bbdb, $current_user;
    630     if ( !$tag_id = create_tag( $tag ))
     663    if ( !topic_is_open($topic_id) && $current_user->user_type < 1 )
     664        return false;
     665    if ( !$tag_id = create_tag( $tag ) )
    631666        return false;
    632667    $now    = bb_current_time('mysql');
     
    696731    $user = bb_get_user($user_id);
    697732
    698     if ( $current_user->user_id != $user_id && $current_user->user_type < 1 )
     733    if ( $current_user->user_type < 1 && ( !topic_is_open($topic_id) || $current_user->user_id != $user_id ) )
    699734        return false;
    700735   
  • trunk/bb-includes/template-functions.php

    r133 r139  
    288288        $topic = get_topic( $id );
    289289    return strtotime( $topic->topic_start_time );
     290}
     291
     292function topic_resolved( $yes = 'resolved', $no = 'not resolved', $mu = 'not a support question', $id = 0 ) {
     293    global $current_user, $topic;
     294    if ( can_edit_topic( $topic->topic_id ) ) :
     295        $resolved_form  = '<form id="resolved" method="post" action="' . bb_get_option('uri') . 'topic-resolve.php">' . "\n";
     296        $resolved_form .= '<input type="hidden" name="id" value="' . $topic->topic_id . "\" />\n";
     297        $resolved_form .= '<select name="resolved" tabindex="2">' . "\n";
     298
     299        $cases = array( 'yes', 'no', 'mu' );
     300        $resolved = get_topic_resolved( $id );
     301        foreach ( $cases as $case ) {
     302            $selected = ( $case == $resolved ) ? ' selected="selected"' : '';
     303            $resolved_form .= "<option value=\"$case\"$selected>${$case}</option>\n";
     304        }
     305
     306        $resolved_form .= "</select>\n";
     307        $resolved_form .= '<input type="submit" name="submit" value="Change" />' . "\n</form>";
     308        echo $resolved_form;
     309    else:
     310        switch ( get_topic_resolved( $id ) ) {
     311            case 'yes' : echo $yes; break;
     312            case 'no'  : echo $no;  break;
     313            case 'mu'  : echo $mu;  break;
     314        }
     315    endif;
     316}   
     317
     318function get_topic_resolved( $id = 0 ) {
     319    global $topic;
     320    if ( $id )
     321        $topic = get_topic( $id );
     322    return $topic->topic_resolved;
    290323}
    291324
     
    543576
    544577function tag_form() {
    545     global $current_user;
    546     if ( $current_user )
     578    global $topic, $current_user;
     579    if ( !$current_user || $current_user->user_type < 1 && !topic_is_open($topic->topic_id) )
     580        return false;
     581    else
    547582        include( BBPATH . '/bb-templates/tag-form.php');
    548583}
     
    584619function tag_remove_link( $tag_id = 0, $user_id = 0, $topic_id = 0 ) {
    585620    global $tag, $current_user;
    586     if ( $current_user->user_id != $tag->user_id && $current_user->user_type < 1 )
     621    if ( $current_user->user_type < 1 && ( !topic_is_open($tag->topic_id) || $current_user->user_id != $tag->user_id ) )
    587622        return false;
    588623    echo '[<a href="' . bb_get_option('uri') . 'tag-remove.php?tag=' . $tag->tag_id . '&user=' . $tag->user_id . '&topic=' . $tag->topic_id . '" onclick="return confirm(\'Are you sure you want to remove the \\\'' . $tag->raw_tag . '\\\' tag?\')" title="Remove this tag">x</a>]';
  • trunk/bb-post.php

    r102 r139  
    1010    $topic = trim( $_POST['topic'] );
    1111    $tags  = trim( $_POST['tags']  );
     12    $support = (int) $_POST['support'];
    1213
    1314    if ('' == $topic)
     
    1516
    1617    $topic_id = bb_new_topic( $topic, $forum, $tags );
     18    if ( 1 != $support )
     19        bb_resolve_topic( $topic_id, 'mu' );
    1720} elseif ( isset($_POST['topic_id'] ) ) {
    1821    $topic_id = (int) $_POST['topic_id'];
  • trunk/bb-templates/post-form.php

    r101 r139  
    77  <input name="topic" type="text" id="topic" size="50" maxlength="80" tabindex="1" />
    88</label>
     9<label><input name="support" type="checkbox" id="support" checked="checked" value="1" tabindex="2"/>This is a support question.</label>
    910</p>
    1011<?php endif; ?>
    1112<p><label>Post:<br />
    12   <textarea name="post_content" cols="50" rows="8" id="post_content" tabindex="2"></textarea>
     13  <textarea name="post_content" cols="50" rows="8" id="post_content" tabindex="3"></textarea>
    1314  </label>
    1415</p>
    1516<?php if ( is_forum() || is_tag() ) : ?>
    1617<p>Enter a few words (called <a href="<?php tag_page_link(); ?>">tags</a>) separated by spaces to help someone find your topic:<br />
    17 <input name="tags" type="text" size="50" maxlength="100" value="<?php tag_name(); ?> " tabindex="3" />
     18<input name="tags" type="text" size="50" maxlength="100" value="<?php tag_name(); ?> " tabindex="4" />
    1819</p>
    1920<?php endif; ?>
  • trunk/bb-templates/topic.php

    r138 r139  
    1313    <li><?php topic_posts(); ?> posts so far</li>
    1414    <li>Latest reply from <?php topic_last_poster(); ?></li>
     15    <li>This topic is <?php topic_resolved(); ?></li>
    1516</ul>
    1617<br clear="all" />
  • trunk/tag-add.php

    r82 r139  
    1616if ( add_topic_tag( $topic_id, $tag ) )
    1717    header('Location: ' . get_topic_link( $topic_id ) );
     18else
     19    die('The tag was not added.  Either the tag name was invalid or the topic is closed.');
    1820?>
  • trunk/tag-remove.php

    r120 r139  
    1717    header( 'Location: ' . $_SERVER['HTTP_REFERER'] );
    1818else
    19     die('The tag was not fully removed.');
     19    die('The tag was not removed.  You cannot remove a tag from a closed topic.');
    2020exit;
    2121?>
Note: See TracChangeset for help on using the changeset viewer.