Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit 999738fa1475f223195f9a4755f36ff6b57cdd28
Showing with 521 additions and 0 deletions.
  1. +100 −0 admin/bp-activity-hashtags-admin.php
  2. +110 −0 bp-activity-hashtags-loader.php
  3. +145 −0 bp-activity-hashtags.php
  4. +54 −0 feeds/bp-activity-hashtags-feed.php
  5. +112 −0 readme.txt
@@ -0,0 +1,100 @@
<?php
function etivite_bp_activity_hashtags_admin() {
global $bp;
if ( isset( $_POST['submit'] ) && check_admin_referer('etivite_bp_activity_stream_hashtags_admin') ) {
$new = Array();
if( isset( $_POST['ah_tag_slug'] ) && !empty( $_POST['ah_tag_slug'] ) ) {
$new['slug'] = $_POST['ah_tag_slug'];
} else {
$new['slug'] = false;
}
if( isset( $_POST['ah_activity'] ) && !empty( $_POST['ah_activity'] ) && $_POST['ah_activity'] == 1) {
$new['blogactivity']['enabled'] = true;
} else {
$new['blogactivity']['enabled'] = false;
}
if( isset( $_POST['ah_blog'] ) && !empty( $_POST['ah_blog'] ) && $_POST['ah_blog'] == 1) {
$new['blogposts']['enabled'] = true;
} else {
$new['blogposts']['enabled'] = false;
}
update_option( 'etivite_bp_activity_stream_hashtags', $new );
$updated = true;
}
?>
<div class="wrap">
<h2><?php _e( 'Activity Stream Hastags Admin', 'bp-activity-hashtags' ); ?></h2>
<?php if ( isset($updated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Settings updated.', 'bp-activity-hashtags' ) . "</p></div>"; endif;
$data = maybe_unserialize( get_option( 'etivite_bp_activity_stream_hashtags' ) );
?>
<form action="<?php echo network_admin_url('/admin.php?page=bp-activity-hashtags-settings') ?>" name="groups-autojoin-form" id="groups-autojoin-form" method="post">
<h4><?php _e( 'Hashtag Base Slug', 'bp-activity-hashtags' ); ?></h4>
<table class="form-table">
<tr>
<th><label for="ah_tag_slug"><?php _e('Slug','bp-activity-hashtags') ?></label></th>
<td><input type="text" name="ah_tag_slug" id="ah_tag_slug" value="<?php echo $data['slug']; ?>" /></td>
</tr>
</table>
<h4><?php _e( 'Blog Posts/Comments - in Activity Stream', 'bp-restrictgroups' ); ?></h4>
<table class="form-table">
<tr>
<th><label for="ah_activity"><?php _e('Enable hashtags in blog activity stream','bp-restrictgroups') ?></label></th>
<td><input type="checkbox" name="ah_activity" id="ah_activity" value="1" <?php if ( $data['blogactivity']['enabled'] ) { echo 'checked'; } ?>/></td>
</tr>
</table>
<?php if ( !is_multisite() ) { ?>
<h4><?php _e( 'Blog Posts/Comments - in Main Blog', 'bp-restrictgroups' ); ?></h4>
<table class="form-table">
<tr>
<th><label for="ah_blog"><?php _e('Enable hashtags on main blog','bp-restrictgroups') ?></label></th>
<td><input type="checkbox" name="ah_blog" id="ah_blog" value="1" <?php if ( $data['blogposts']['enabled'] ) { echo 'checked'; } ?>/></td>
</tr>
</table>
<?php } ?>
<?php wp_nonce_field( 'etivite_bp_activity_stream_hashtags_admin' ); ?>
<p class="submit"><input type="submit" name="submit" value="Save Settings"/></p>
</form>
<h3>About:</h3>
<div id="plugin-about" style="margin-left:15px;">
<p>
<a href="http://etivite.com/wordpress-plugins/buddypress-activity-stream-hashtags/">Activity Stream Hashtags - About Page</a><br/>
</p>
<div class="plugin-author">
<strong>Author:</strong> <a href="http://profiles.wordpress.org/users/etivite/"><img style="height: 24px; width: 24px;" class="photo avatar avatar-24" src="http://www.gravatar.com/avatar/9411db5fee0d772ddb8c5d16a92e44e0?s=24&amp;d=monsterid&amp;r=g" alt=""> rich @etivite</a><br/>
<a href="http://twitter.com/etivite">@etivite</a>
</div>
<p>
<a href="http://etivite.com">Author's site</a><br/>
<a href="http://etivite.com/api-hooks/">Developer Hook and Filter API Reference</a><br/>
<a href="http://etivite.com/wordpress-plugins/">WordPress Plugins</a><br/>
</p>
</div>
</div>
<?php
}
?>
@@ -0,0 +1,110 @@
<?php
/*
Plugin Name: BuddyPress Activity Stream Hashtags
Plugin URI: http://wordpress.org/extend/plugins/buddypress-activity-stream-hashtags/
Description: Enable #hashtags linking within activity stream content - converts before database.
Author: rich @etiviti
Author URI: http://etivite.com
License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt
Version: 0.5.1
Text Domain: bp-activity-hashtags
Network: true
*/
//TODO - We really need unicode support =) For example ”#tag” works ok, but ”#?????” — nope.
//TODO - support post db content filter rewrite on #tag
function etivite_bp_activity_hashtags_init() {
if ( !bp_is_active( 'activity' ) )
return;
if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
load_textdomain( 'bp-activity-hashtags', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
$data = maybe_unserialize( get_option( 'etivite_bp_activity_stream_hashtags' ) );
//if you want to change up the /activity/tag/myhashtag
if ( !defined( 'BP_ACTIVITY_HASHTAGS_SLUG' ) )
define( 'BP_ACTIVITY_HASHTAGS_SLUG', $data['slug'] );
require( dirname( __FILE__ ) . '/bp-activity-hashtags.php' );
//same set used for atme mentions
add_filter( 'bp_activity_comment_content', 'etivite_bp_activity_hashtags_filter' );
add_filter( 'bp_activity_new_update_content', 'etivite_bp_activity_hashtags_filter' );
add_filter( 'group_forum_topic_text_before_save', 'etivite_bp_activity_hashtags_filter' );
add_filter( 'group_forum_post_text_before_save', 'etivite_bp_activity_hashtags_filter' );
add_filter( 'groups_activity_new_update_content', 'etivite_bp_activity_hashtags_filter' );
//what about blog posts in the activity stream
if ( $data['blogactivity']['enabled'] ) {
add_filter( 'bp_blogs_activity_new_post_content', 'etivite_bp_activity_hashtags_filter' );
add_filter( 'bp_blogs_activity_new_comment_content', 'etivite_bp_activity_hashtags_filter' );
}
//what about general blog posts/comments?
if ( $data['blogposts']['enabled'] ) {
add_filter( 'get_comment_text' , 'etivite_bp_activity_hashtags_filter', 9999 );
add_filter( 'the_content', 'etivite_bp_activity_hashtags_filter', 9999 );
}
//support edit activity stream plugin
add_filter( 'bp_edit_activity_action_edit_content', 'etivite_bp_activity_hashtags_filter' );
//ignore this - if we wanted to filter after - this would be it
//but then we can't search by the #hashtag via search_terms (since the trick is the ending </a>)
//as the search_term uses LIKE %%term%% so we would match #child #children
//add_filter( 'bp_get_activity_content_body', 'etivite_bp_activity_hashtags_filter' );
add_action( bp_core_admin_hook(), 'etivite_bp_activity_hashtags_admin_add_admin_menu' );
}
add_action( 'bp_include', 'etivite_bp_activity_hashtags_init', 88 );
//add_action( 'bp_init', 'etivite_bp_activity_hashtags_init', 88 );
//add admin_menu page
function etivite_bp_activity_hashtags_admin_add_admin_menu() {
global $bp;
if ( !is_super_admin() )
return false;
//Add the component's administration tab under the "BuddyPress" menu for site administrators
require ( dirname( __FILE__ ) . '/admin/bp-activity-hashtags-admin.php' );
add_submenu_page( 'bp-general-settings', __( 'Activity Hashtags Admin', 'bp-activity-hashtags' ), __( 'Activity Hashtags', 'bp-activity-hashtags' ), 'manage_options', 'bp-activity-hashtags-settings', 'etivite_bp_activity_hashtags_admin' );
//set up defaults
$new = Array();
$new['slug'] = 'tag';
$new['install_version'] = etivite_plugin_get_version();
add_option( 'etivite_bp_activity_stream_hashtags', $new );
}
/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
function etivite_bp_activity_hashtags_admin_add_action_link( $links, $file ) {
if ( 'buddypress-activity-stream-hashtags/bp-activity-hashtags-loader.php' != $file )
return $links;
if ( function_exists( 'bp_core_do_network_admin' ) ) {
$settings_url = add_query_arg( 'page', 'bp-activity-hashtags-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
} else {
$settings_url = add_query_arg( 'page', 'bp-activity-hashtags-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
}
$settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-activity-hashtags' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links', 'etivite_bp_activity_hashtags_admin_add_action_link', 10, 2 );
function etivite_plugin_get_version() {
$plugin_data = get_plugin_data( __FILE__ );
$plugin_version = $plugin_data['Version'];
return $plugin_version;
}
?>
@@ -0,0 +1,145 @@
<?php
if ( !defined( 'ABSPATH' ) ) exit;
function etivite_bp_activity_hashtags_filter( $content ) {
global $bp;
//what are we doing here? - same at atme mentions
//$pattern = '/[#]([_0-9a-zA-Z-]+)/';
$pattern = '/(?(?<!color: )(?<!color: )[#]([_0-9a-zA-Z-]+)|(^|\s|\b)[#]([_0-9a-zA-Z-]+))/';
//unicode support???
//$pattern = '/(#|\\uFF03)([a-z0-9_\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff]+)/i';
//$pattern = '/(^|[^0-9A-Z&/]+)(#|\uFF03)([0-9A-Z_]*[A-Z_]+[a-z0-9_\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff]*)/i';
//the twitter pattern
//"(^|[^0-9A-Z&/]+)(#|\uFF03)([0-9A-Z_]*[A-Z_]+[a-z0-9_\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u00ff]*)"
preg_match_all( $pattern, $content, $hashtags );
if ( $hashtags ) {
/* Make sure there's only one instance of each tag */
if ( !$hashtags = array_unique( $hashtags[1] ) )
return $content;
//but we need to watch for edits and if something was already wrapped in html link - thus check for space or word boundary prior
foreach( (array)$hashtags as $hashtag ) {
$pattern = "/(^|\s|\b)#". $hashtag ."($|\b)/";
$content = preg_replace( $pattern, ' <a href="' . $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . htmlspecialchars( $hashtag ) . '" rel="nofollow" class="hashtag">#'. htmlspecialchars( $hashtag ) .'</a>', $content );
}
}
return $content;
}
function etivite_bp_activity_hashtags_querystring( $query_string, $object ) {
global $bp;
if ( !bp_is_activity_component() || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
return $query_string;
if ( empty( $bp->action_variables[0] ) )
return $query_string;
if ( 'feed' == $bp->action_variables[1] )
return $query_string;
if ( strlen( $query_string ) < 1 )
return 'display_comments=true&search_terms=#'. $bp->action_variables[0] . '<';
/* Now pass the querystring to override default values. */
$query_string .= '&display_comments=true&search_terms=#'. $bp->action_variables[0] . '<';
return $query_string;
}
add_filter( 'bp_ajax_querystring', 'etivite_bp_activity_hashtags_querystring', 11, 2 );
//thanks r-a-y for the snippet
function etivite_bp_activity_hashtags_header() {
global $bp, $bp_unfiltered_uri;
if ( !bp_is_activity_component() || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
return;
printf( __( '<h3>Activity results for #%s</h3>', 'bp-activity-hashtags' ), $bp->action_variables[0] );
}
add_action( 'bp_before_activity_loop', 'etivite_bp_activity_hashtags_header' );
function etivite_bp_activity_hashtags_page_title( $title) {
global $bp;
if ( !bp_is_activity_component() || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
return $title;
if ( empty( $bp->action_variables[0] ) )
return $title;
return apply_filters( 'bp_activity_page_title', 'Activity results for #'. esc_attr( $bp->action_variables[0] ) . $title, esc_attr( $bp->action_variables[0] ) );
}
add_filter( 'wp_title', 'etivite_bp_activity_hashtags_page_title', 99 );
function etivite_bp_activity_hashtags_insert_rel_head() {
global $bp;
if ( !bp_is_activity_component() || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
return false;
if ( empty( $bp->action_variables[0] ) )
return false;
$link = $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . esc_attr( $bp->action_variables[0] ) . '/feed/';
echo '<link rel="alternate" type="application/rss+xml" title="'. get_blog_option( BP_ROOT_BLOG, 'blogname' ) .' | '. esc_attr( $bp->action_variables[0] ) .' | Hashtag" href="'. $link .'" />';
}
add_action('bp_head','etivite_bp_activity_hashtags_insert_rel_head');
function etivite_bp_activity_hashtags_activity_feed_link( $feedurl ) {
global $bp;
if ( !bp_is_activity_component() || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
return $feedurl;
if ( empty( $bp->action_variables[0] ) )
return $feedurl;
return $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . esc_attr( $bp->action_variables[0] ) . '/feed/';
}
add_filter( 'bp_get_sitewide_activity_feed_link', 'etivite_bp_activity_hashtags_activity_feed_link', 1, 1 );
function etivite_bp_activity_hashtags_action_router() {
global $bp, $wp_query;
if ( !bp_is_activity_component() || $bp->current_action != BP_ACTIVITY_HASHTAGS_SLUG )
return false;
if ( empty( $bp->action_variables[0] ) )
return false;
if ( 'feed' == $bp->action_variables[1] ) {
$link = $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . esc_attr( $bp->action_variables[0] );
$link_self = $bp->root_domain . "/" . $bp->activity->slug . "/". BP_ACTIVITY_HASHTAGS_SLUG ."/" . esc_attr( $bp->action_variables[0] ) . '/feed/';
$wp_query->is_404 = false;
status_header( 200 );
include_once( dirname( __FILE__ ) . '/feeds/bp-activity-hashtags-feed.php' );
die;
} else {
bp_core_load_template( 'activity/index' );
}
}
add_action( 'wp', 'etivite_bp_activity_hashtags_action_router', 3 );
function etivite_bp_activity_hashtags_current_activity() {
global $activities_template;
return $activities_template->current_activity;
}
?>
Oops, something went wrong.

0 comments on commit 999738f

Please sign in to comment.