Skip to:
Content

bbPress.org

Ticket #1471: 1471-1.diff

File 1471-1.diff, 10.7 KB (added by jkudish, 12 years ago)
  • bb-templates/kakumei/style.css

     
    695695        margin-top: -8px;
    696696}
    697697
    698 #latest td, #forumlist td, #favorites td { padding: 5px 10px; }
     698#latest td, #forumlist td, #favorites td, #subscriptions td { padding: 5px 10px; }
    699699
    700700#forumlist tr td div.nest {
    701701        padding-left: 2.5ex;
    702702}
    703703
    704 #latest tr:hover, #forumlist tr:hover, #favorites tr:hover { background-color: #e4f3e1; }
     704#latest tr:hover, #forumlist tr:hover, #favorites tr:hover, #subscriptions tr:hover { background-color: #e4f3e1; }
    705705
    706 #latest th, #forumlist th, #favorites th {
     706#latest th, #forumlist th, #favorites th, #subscriptions th {
    707707        text-align: left;
    708708        background-color: rgb(102, 102, 102);
    709709        font: 11px Verdana,Arial,Helvetica,sans-serif;
     
    712712        color: rgb(255, 255, 255);
    713713}
    714714
    715 #latest th a, #forumlist th a, #favorites th a {
     715#latest th a, #forumlist th a, #favorites th a, #subscriptions th a {
    716716        color: rgb(200, 200, 200);
    717717        font-style: italic;
    718718}
    719719
    720 #latest th a:hover, #forumlist th a:hover, #favorites th a:hover {
     720#latest th a:hover, #forumlist th a:hover, #favorites th a:hover, #subscriptions th a:hover {
    721721        color: rgb(255, 255, 255);
    722722}
    723723
     
    725725        background-color: #ddd;
    726726}
    727727
    728 #latest, #forumlist, #favorites {
     728#latest, #forumlist, #favorites, #subscriptions {
    729729        background-color: #f7f7f7;
    730730        margin-bottom: 3em;
    731731        width: 100%;
  • bb-templates/kakumei/subscriptions.php

     
     1<?php bb_get_header(); ?>
     2
     3<div class="bbcrumb"><a href="<?php bb_uri(); ?>"><?php bb_option('name'); ?></a> &raquo; <a href="<?php user_profile_link( $user_id ); ?>"><?php echo get_user_display_name( $user_id ); ?></a> &raquo; <?php _e('Subscriptions'); ?></div>
     4
     5<h2 id="userlogin" role="main"><?php echo get_user_display_name( $user->ID ); ?> <small>(<?php echo get_user_name( $user->ID ); ?>)</small> <?php _e( 'subscriptions' ); ?><?php if ( !empty( $topics ) ) echo ' (' . count( $topics ) . ')'; ?></h2>
     6
     7<p class="lead-in"><?php _e('Subscriptions allow you to receive an email each time a reply is posted on your subscribed forum topics.'); ?></p>
     8
     9<?php if ( count( $topics ) > 1 ) : ?>
     10        <p><a href="<?php echo bb_get_uri( null, array( 'doit' => 'bb-subscribe', 'remove_all' => true, 'user_id' => $user_id ) ) ?>"><?php _e( 'Unsubscribe from all topics' ) ?></a></p>
     11<?php endif; ?>
     12
     13<?php
     14if ( !empty( $_GET['unsubscribed'] ) ) {
     15        if ( 'all' == $_GET['unsubscribed'] ) {
     16                echo '<p class="subscribed">' . __( "You are now unubscribed from all topics." ) . '</p>';
     17        } elseif ( is_numeric( $_GET['unsubscribed'] ) && !bb_is_user_subscribed( array( 'user_id' => $user_id, 'topic_id' => (int) $_GET['unsubscribed'] ) ) ) {
     18                $unsub_id = (int) $_GET['unsubscribed'];
     19                echo '<p class="subscribed">' . sprintf( __( "You are now unubscribed from the '<a href='%s'>%s</a>' topic." ), get_topic_link( $unsub_id ), get_topic_title( $unsub_id ) ) . '</p>';
     20        }
     21}
     22?>
     23
     24<?php if ( !empty( $topics ) ) : ?>
     25
     26<table id="subscriptions">
     27        <tr>
     28                <th><?php _e('Topic'); ?></th>
     29                <th><?php _e('Post Count'); ?></th>
     30                <th><?php _e('Freshness'); ?></th>
     31                <th><?php _e('Remove'); ?></th>
     32        </tr>
     33        <?php foreach ( $topics as $topic ) : ?>
     34                <tr<?php topic_class(); ?>>
     35                        <td><?php bb_topic_labels(); ?> <a href="<?php topic_link(); ?>"><?php topic_title(); ?></a></td>
     36                        <td class="num"><?php topic_posts(); ?></td>
     37                        <td class="num"><?php topic_time(); ?></td>
     38                        <td class="num">[<a href="<?php echo bb_nonce_url( bb_get_uri( null, array( 'doit' => 'bb-subscribe', 'topic_id' => $topic->topic_id, 'and' => 'remove', 'redirect_to' => urlencode( add_query_arg( array( 'unsubscribed' => $topic->topic_id ), get_subscriptions_link( $user_id ) ) ) ) ), 'toggle-subscribe_' . $topic->topic_id ) ?>">X</a>]</td>
     39                </tr>
     40        <?php endforeach; ?>
     41</table>
     42
     43<?php else: if ( $user_id == $bb_current_user->ID ) : ?>
     44
     45<p style="margin-left: 12px;"><?php _e('You currently have no subscriptions.'); ?></p>
     46
     47<?php else : ?>
     48
     49<p style="margin-left: 12px;"><?php echo get_user_name( $user_id ); ?> <?php _e('currently has no subscriptions.'); ?></p>
     50
     51<?php endif; endif; ?>
     52
     53<?php bb_get_footer(); ?>
     54 No newline at end of file
  • bb-includes/functions.bb-users.php

     
    494494        do_action('bb_remove_user_favorite', $user_id, $topic_id);
    495495        return true;
    496496}
     497
     498/**
     499 * Get all topics the user is subscribed to
     500 *
     501 * @since 1.2
     502 * @param int $user_id ID of user
     503 * @param int $limit the max amount of topics to return
     504 * @return array $topics the topics the user is subscribed to
     505 */
     506function bb_get_user_subscriptions( $user_id = '', $limit = 250 ) {
     507
     508        if ( !bb_is_user_logged_in() )
     509                return false;
     510
     511        if ( empty( $user_id ) )
     512                $user_id = bb_get_current_user_info( 'id' );
     513
     514        if ( $user_id != bb_get_current_user_info( 'id' ) && !bb_current_user_can( 'edit_favorites_of', $user_id ) )
     515                return false;
     516
     517        global $bbdb;
     518        $topics = array();
     519
     520        $topic_ids = $bbdb->get_results( $bbdb->prepare( "SELECT slug FROM `$bbdb->term_relationships` AS tr JOIN `$bbdb->term_taxonomy` as tt ON tt.`term_taxonomy_id` = tr.`term_taxonomy_id` JOIN $bbdb->terms AS terms ON terms.`term_id` = tt.`term_id` WHERE tt.`taxonomy` = 'bb_subscribe' AND tr.`object_id` = %d LIMIT 0, %d", $user_id, $limit ) );
     521        if ( !empty( $topic_ids ) ) {
     522                foreach ( $topic_ids as $term_object ) {
     523                        $_topic_id = explode( 'topic-', $term_object->slug );
     524                        $topic_id = (int) $_topic_id[1];
     525                        if ( $bbdb->get_var( $bbdb->prepare( "SELECT topic_id FROM $bbdb->topics WHERE topic_id = %d AND topic_status = 0", $topic_id ) ) )
     526                                $topics[] = get_topic( $topic_id );
     527                }
     528        }
     529
     530        return apply_filters( 'bb_get_user_subscriptions', $topics );
     531
     532}
     533 No newline at end of file
  • bb-includes/action.subscribe.php

     
    1 <?php
    2 
    3 if ( !isset( $_GET['doit'] ) || 'bb-subscribe' != $_GET['doit'] ) // sanity check
    4         bb_die( __( 'What are you trying to do, exactly?' ) );
    5 
    6 if ( !bb_is_subscriptions_active() )
    7         bb_die( __( 'You can not subscribe to topics.' ) );
    8 
    9 if ( !isset( $_GET['topic_id'] ) )
    10         bb_die( __( 'Missing topic ID!' ) );
    11 
    12 bb_auth( 'logged_in' );
    13 
    14 $topic_id = (int) $_GET['topic_id'];
    15 
    16 $topic = get_topic( $topic_id );
    17 if ( !$topic )
    18         bb_die( __( 'Topic not found! What are you subscribing to?' ) );
    19 
    20 bb_check_admin_referer( 'toggle-subscribe_' . $topic_id );
    21 
    22 // Okay, we should be covered now
    23 
    24 if ( in_array( $_GET['and'], array( 'add', 'remove' ) ) )
    25         bb_subscription_management( $topic->topic_id, $_GET['and'] );
    26 
    27 wp_redirect( get_topic_link( $topic_id, 1 ) );
    28 
    29 exit;
     1<?php
     2
     3if ( !isset( $_GET['doit'] ) || 'bb-subscribe' != $_GET['doit'] ) // sanity check
     4        bb_die( __( 'What are you trying to do, exactly?' ) );
     5
     6if ( !bb_is_subscriptions_active() )
     7        bb_die( __( 'You can not un/subscribe to topics.' ) );
     8
     9bb_auth( 'logged_in' );
     10
     11$default_redirect_to = get_subscriptions_link();
     12
     13// single topic
     14if ( !empty( $_GET['topic_id'] ) && is_numeric( $_GET['topic_id'] ) ) {
     15        $topic_id = (int) $_GET['topic_id'];
     16
     17        $topic = get_topic( $topic_id );
     18        if ( !$topic )
     19                bb_die( __( 'Topic not found! What are you subscribing to?' ) );
     20
     21        bb_check_admin_referer( 'toggle-subscribe_' . $topic_id );
     22
     23        if ( in_array( $_GET['and'], array( 'add', 'remove' ) ) )
     24                bb_subscription_management( $topic->topic_id, $_GET['and'] );
     25
     26        $default_redirect_to = get_topic_link( $topic_id, 1 );
     27}
     28
     29// unsub all
     30if ( !empty( $_GET['remove_all'] ) && !empty( $_GET['user_id'] ) && is_numeric( $_GET['user_id'] ) ) {
     31        $user_id = (int) $_GET['user_id'];
     32        $topics = bb_get_user_subscriptions( $user_id );
     33        if ( !empty( $topics ) ) {
     34                foreach ( $topics as $topic )
     35                        bb_subscription_management( $topic->topic_id, 'remove' );
     36        }
     37
     38        $default_redirect_to = add_query_arg( array( 'unsubscribed' => 'all' ), get_subscriptions_link( $user_id ) );
     39}
     40
     41
     42$redirect_to = ( isset( $_GET['redirect_to'] ) ) ? esc_url_raw( $_GET['redirect_to'] ) : $default_redirect_to;
     43
     44wp_redirect( $redirect_to );
     45exit;
     46 No newline at end of file
  • bb-includes/functions.bb-template.php

     
    35643564}
    35653565
    35663566/**
     3567 * Outputs the subscription link.
     3568 *
     3569 * @since 1.1
     3570 * @param $user_id the user id for whom to generate the link
     3571 */
     3572function get_subscriptions_link( $user_id = 0 ) {
     3573        if ( !$user_id )
     3574                $user_id = bb_get_current_user_info( 'id' );
     3575        return apply_filters( 'get_subscriptions_link', get_profile_tab_link( $user_id, 'subscriptions' ), $user_id );
     3576}
     3577
     3578/**
    35673579 * Outputs the post form subscription checkbox.
    35683580 *
    35693581 * Checks if user is subscribed and outputs checkbox based on status.
  • bb-includes/functions.bb-core.php

     
    857857        // Item name for URL (nontranslated)
    858858        $profile_menu[0] = array(__('Edit'), 'edit_profile', 'edit_users', 'profile-edit.php', 'edit');
    859859        $profile_menu[5] = array(__('Favorites'), '', '', 'favorites.php', 'favorites');
     860        if ( bb_is_subscriptions_active() )
     861                $profile_menu[6] = array(__('Subscriptions'), '', '', 'subscriptions.php', 'subscriptions');
    860862
    861863        // Create list of page plugin hook names the current user can access
    862864        $profile_hooks = array();
  • subscriptions.php

     
     1<?php
     2require_once('./bb-load.php');
     3
     4if ( !bb_is_subscriptions_active() )
     5        bb_die( __( 'You can not (un)subscribe to topics.' ) );
     6
     7if ( !bb_current_user_can( 'edit_favorites_of', $user_id ) ) {
     8        bb_die( __( 'You cannot edit these subscriptions. How did you get here?' ) );
     9}
     10
     11if ( !bb_is_profile() ) {
     12        $sendto = get_profile_tab_link( $user_id, 'subscriptions' );
     13        wp_redirect( $sendto );
     14        exit;
     15}
     16
     17if ( $topics = bb_get_user_subscriptions( $user_id ) ) {
     18        bb_cache_last_posts( $topics );
     19}
     20
     21bb_load_template( 'subscriptions.php' );
     22 No newline at end of file