Ejemplo n.º 1
0
/**
 * Plugin Name: Post Notification
 * Plugin Description: Sends an Notification email if there's a new post to an favorite topic. (Modified Version 1.4 with Post Content included in E-Mail)
 * Author: Thomas Klaiber
 * Author URI: http://thomasklaiber.com/
 * Plugin URI: http://thomasklaiber.com/bbpress/post-notification/
 * Version: 1.4
 */
function notification_new_post($post_id = 0)
{
    global $bbdb, $bb_table_prefix, $topic_id, $bb_current_user;
    $all_users = notification_select_all_users();
    foreach ($all_users as $userdata) {
        if (notification_is_activated($userdata->ID)) {
            if (is_user_favorite($userdata->ID, $topic_id)) {
                //$topic = get_topic($topic_id);
                $message = __("Hello,\n\nA new post on \"%1\$s\" has been added by %2\$s at DHAnswers. \n\nMessage:\n\n%3\$s \n\n%4\$s ");
                mail($userdata->user_email, '[DHAnswers] New Post for Favorite Question', sprintf($message, get_topic_title($topic_id), get_user_name($bb_current_user->ID), strip_tags(get_post_text($post_id)), get_topic_link($topic_id)), 'From: ' . bb_get_option('name') . ' <' . bb_get_option('from_email') . '>');
            }
        }
    }
}
Ejemplo n.º 2
0
function post_form_auto_add_checkbox()
{
    global $topic_id, $bb_current_user;
    if (is_user_favorite($bb_current_user->ID, $topic_id)) {
        return;
    } else {
        $checked = !empty($bb_current_user->data->auto_add_favorit) ? ' checked="checked"' : '';
        echo '
		<p>
			<input type="checkbox" name="add_to_my_favorites" id="add_to_my_favorites" value="1"' . $checked . ' />
			<label for="add_to_my_favorites" style="display:inline;">Add this question to my favorites </label>
			<span> (change your default <a href="' . attribute_escape(get_profile_tab_link($bb_current_user->ID, 'edit')) . '">here</a>)</span>
		</p>';
    }
}
Ejemplo n.º 3
0
<ul class="topicmeta">
	<li><?php 
    printf(__('Started %1$s ago by %2$s'), get_topic_start_time(), get_topic_author());
    ?>
</li>
<?php 
    if (1 < get_topic_posts()) {
        ?>
	<li><?php 
        printf(__('<a href="%1$s">Latest reply</a> from %2$s'), attribute_escape(get_topic_last_post_link()), get_topic_last_poster());
        ?>
</li>
<?php 
    }
    if (bb_is_user_logged_in()) {
        $class = 0 === is_user_favorite(bb_get_current_user_info('id')) ? ' class="is-not-favorite"' : '';
        ?>
	<li<?php 
        echo $class;
        ?>
 id="favorite-toggle"><?php 
        user_favorites_link();
        ?>
</li>
<?php 
    }
    do_action('topicmeta');
    ?>
</ul>
</div>
function user_favorites_link($add = array(), $rem = array(), $user_id = 0)
{
    global $topic, $bb_current_user;
    if (empty($add) || !is_array($add)) {
        $add = array('mid' => __('Add this topic to your favorites'), 'post' => __(' (%?%)'));
    }
    if (empty($rem) || !is_array($rem)) {
        $rem = array('pre' => __('This topic is one of your %favorites% ['), 'mid' => __('&times;'), 'post' => __(']'));
    }
    if ($user_id) {
        if (!bb_current_user_can('edit_favorites_of', (int) $user_id)) {
            return false;
        }
        if (!($user = bb_get_user(bb_get_user_id($user_id)))) {
            return false;
        }
    } else {
        if (!bb_current_user_can('edit_favorites')) {
            return false;
        }
        $user =& $bb_current_user->data;
    }
    $url = esc_url(get_favorites_link($user_id));
    if ($is_fav = is_user_favorite($user->ID, $topic->topic_id)) {
        $rem = preg_replace('|%(.+)%|', "<a href='{$url}'>\$1</a>", $rem);
        $favs = array('fav' => '0', 'topic_id' => $topic->topic_id);
        $pre = is_array($rem) && isset($rem['pre']) ? $rem['pre'] : '';
        $mid = is_array($rem) && isset($rem['mid']) ? $rem['mid'] : (is_string($rem) ? $rem : '');
        $post = is_array($rem) && isset($rem['post']) ? $rem['post'] : '';
    } elseif (false === $is_fav) {
        $add = preg_replace('|%(.+)%|', "<a href='{$url}'>\$1</a>", $add);
        $favs = array('fav' => '1', 'topic_id' => $topic->topic_id);
        $pre = is_array($add) && isset($add['pre']) ? $add['pre'] : '';
        $mid = is_array($add) && isset($add['mid']) ? $add['mid'] : (is_string($add) ? $add : '');
        $post = is_array($add) && isset($add['post']) ? $add['post'] : '';
    }
    $url = esc_url(bb_nonce_url(add_query_arg($favs, get_favorites_link($user_id)), 'toggle-favorite_' . $topic->topic_id));
    if (!is_null($is_fav)) {
        echo "<span id='favorite-{$topic->topic_id}'>{$pre}<a href='{$url}' class='dim:favorite-toggle:favorite-{$topic->topic_id}:is-favorite'>{$mid}</a>{$post}</span>";
    }
}
/**
 * Load localized script just in time for MCE.
 *
 * These localizations require information that may not be loaded even by init.
 */
function bb_just_in_time_script_localization()
{
    wp_localize_script('topic', 'bbTopicJS', array('currentUserId' => bb_get_current_user_info('id'), 'topicId' => get_topic_id(), 'favoritesLink' => get_favorites_link(), 'isFav' => (int) is_user_favorite(bb_get_current_user_info('id')), 'confirmPostDelete' => __("Are you sure you want to delete this post?"), 'confirmPostUnDelete' => __("Are you sure you want to undelete this post?"), 'favLinkYes' => __('favorites'), 'favLinkNo' => __('?'), 'favYes' => __('This topic is one of your %favLinkYes% [%favDel%]'), 'favNo' => __('%favAdd% (%favLinkNo%)'), 'favDel' => __('&times;'), 'favAdd' => __('Add this topic to your favorites')));
}
Ejemplo n.º 6
0
         die('0');
     }
     if (false !== bb_remove_topic_tag($tag_id, $user_id, $topic_id)) {
         die('1');
     }
     break;
 case 'dim-favorite':
     $user_id = bb_get_current_user_info('id');
     if (!($topic = get_topic($id))) {
         die('0');
     }
     if (!bb_current_user_can('edit_favorites_of', $user_id)) {
         die('-1');
     }
     bb_check_ajax_referer("toggle-favorite_{$topic->topic_id}");
     $is_fav = is_user_favorite($user_id, $topic->topic_id);
     if (1 == $is_fav) {
         if (bb_remove_user_favorite($user_id, $topic->topic_id)) {
             die('1');
         }
     } elseif (false === $is_fav) {
         if (bb_add_user_favorite($user_id, $topic->topic_id)) {
             die('1');
         }
     }
     break;
 case 'delete-post':
     // $id is post_id
     if (!bb_current_user_can('delete_post', $id)) {
         die('-1');
     }
Ejemplo n.º 7
0
    ?>
;
		var uriBase = '<?php 
    bb_option('uri');
    ?>
';
		var tagLinkBase = '<?php 
    bb_tag_link_base();
    ?>
';
		var favoritesLink = '<?php 
    favorites_link();
    ?>
'; 
		var isFav = <?php 
    if (false === ($is_fav = is_user_favorite(bb_get_current_user_info('id')))) {
        echo "'no'";
    } else {
        echo $is_fav;
    }
    ?>
;
	</script>
	
	<?php 
    wp_enqueue_script('topic');
}
?>

	<?php 
bb_head();