user_login"]['id'] = $user->ID;
$users_to_array[] = $user->ID;
}
// get nicenames (can take out if you only want to handle display names)
$user_ids = join( ',', array_map( 'intval', $users_to_array ) );
foreach ( $wpdb->get_results( "SELECT ID, display_name, user_nicename from $wpdb->users WHERE ID IN($user_ids)" ) as $user ) {
$name_map["@$user->display_name"]['id'] = $user->ID;
$name_map["@$user->user_nicename"]['id'] = $user->ID;
}
foreach( $name_map as $name => $values)
$name_map[$name]['replacement'] = '' . wp_specialchars( $name ) . '';
// remove any empty name just in case
unset( $name_map['@'] );
return $name_map;
}
add_action( 'init', 'mention_taxonomy', 0 ); // initialize the taxonomy
function mention_taxonomy() {
register_taxonomy( 'mentions', 'post', array( 'hierarchical' => false, 'label' => 'Mentions', 'query_var' => true, 'rewrite' => true ) );
}
function p2_at_names( $content ) {
global $post, $comment;
$name_map = p2_get_at_name_map(); // get users user_login and display_name map
$content_original = $content; // save content before @names are found
foreach($name_map as $name => $values) { //loop and...
$content = str_ireplace( $name, $values['replacement'], $content ); // Change case to that in $name_map
$content = strtr( $content, $name, $name ); // Replaces keys with values longest to shortest, without re-replacing pieces it's already done
if( $content != $content_original ) // if the content has changed, an @name has been found.
$users_to_add[] = get_usermeta( $name_map[$name]['id'], 'user_login' ); // add that user to an array.
$content_original = $content;
}
if( is_array($users_to_add) ) $cache_data = implode($users_to_add); // if we've got an array, make it a comma delimited string
if( isset($cache_data) && $cache_data != wp_cache_get( 'mentions', $post->ID) ) {
wp_set_object_terms( $post->ID, $users_to_add, 'mentions', true ); // tag the post.
wp_cache_set( 'mentions', $cache_data, $post->ID);
}
return $content;
}
if( !is_admin() ) add_filter( 'the_content', 'p2_at_names' ); // hook into content
if( !is_admin() ) add_filter( 'comment_text', 'p2_at_names' ); // hook into comment text
function p2_at_name_highlight( $c ) {
global $wp_query;
if($wp_query->query_vars['taxonomy'] != 'mentions') return $c;
$mention_name = $wp_query->query_vars['term'];
$name_map = p2_get_at_name_map();
$names[] = get_usermeta( $name_map["@$mention_name"]['id'], 'display_name' );
$names[] = get_usermeta( $name_map["@$mention_name"]['id'], 'user_login' );
foreach( $names as $key => $name ) {
$at_name = "@$name";
$c = str_replace($at_name, "$at_name", $c);
}
return $c;
}
add_filter( 'the_content', 'p2_at_name_highlight' );
add_filter( 'comment_text', 'p2_at_name_highlight' );
// Widgets
function prologue_flush_tag_cache() {
wp_cache_delete( 'prologue_theme_tag_list' );
}
add_action( 'save_post', 'prologue_flush_tag_cache' );
function prologue_get_avatar( $user_id, $email, $size ) {
if ( $user_id )
return get_avatar( $user_id, $size );
else
return get_avatar( $email, $size );
}
function prologue_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
?>
id="comment-">
$depth, 'max_depth' => $args['max_depth'], 'before' => ' | ')) ?>
', $after = '', $returner = false) {
if( is_page() ) return;
if (is_single() && p2_the_title( '','', true ) == false ) {?>
', $after = '', $returner = false) {
global $post, $looping;
$temp = $post;
$t = apply_filters('the_title', $temp->post_title);
$title = $temp->post_title;
$content = $temp->post_content;
$pos = 0;
if ( (int)get_option('prologue_show_titles') != 1 or $title == 'Post Title' ) return false;
$content = trim($content);
$title = trim($title);
$title = preg_replace('/\.\.\.$/','',$title);
$title = str_replace("\n", ' ', $title );
$title = str_replace(' ',' ', $title);
$content = str_replace("\n", ' ', strip_tags($content) );
$content = str_replace(' ',' ', $content);
$content = trim($content);
$title = trim($title);
if( strpos($title, 'http') !== false ) {
$split = @str_split( $content, strpos($content, 'http'));
$content = $split[0];
$split2 = @str_split( $title, strpos($title, 'http'));
$title = $split2[0];
}
$pos = strpos( $content, $title );
if( ( false === $pos or $pos > 0) && $title != '' ) {
$outputs = ( is_single() ) ? $before.$t.$after : $before.''.$t.' '.$after;
if($returner == true) {
return $outputs;
} else {
echo $outputs;
}
}
}
function prologue_loop() {
global $looping;
$looping = ($looping === 1 ) ? 0 : 1;
}
add_action('loop_start', 'prologue_loop');
add_action('loop_end', 'prologue_loop');
function p2_comments( $comment, $args, $echocomment = true ) {
$GLOBALS['comment'] = $comment;
$depth = prologue_get_comment_depth( get_comment_ID() );
$comment_text = apply_filters( 'comment_text', $comment->comment_content );
$comment_class = comment_class( $class = '', $comment_id = null, $post_id = null, $echo = false );
$comment_time = get_comment_time();
$comment_date = get_comment_date();
$id = get_comment_ID();
$avatar = get_avatar( $comment, 32 );
$author_link = get_comment_author_link();
$reply_link = prologue_get_comment_reply_link(
array('depth' => $depth, 'max_depth' => $args['max_depth'], 'before' => ' | ', 'reply_text' => __('Reply', 'p2') ),
$comment->comment_ID, $comment->comment_post_ID );
$can_edit = current_user_can( 'edit_post', $comment->comment_post_ID );
$edit_comment_url = get_edit_comment_link( $comment->comment_ID );
$edit_link = $can_edit? " | " : '';
$content_class = $can_edit? 'commentcontent comment-edit' : 'commentcontent';
$awaiting_message = $comment->comment_approved == '0'? ''.__('Your comment is awaiting moderation.', 'p2').'
' : '';
$permalink = clean_url( get_comment_link() );
$permalink_text = __('Permalink', 'p2');
$date_time = p2_date_time_with_microformat('comment');
$html = <<
$avatar
$author_link
$date_time
$permalink_text $reply_link $edit_link
HTML;
if(!is_single() && get_comment_type() != 'comment')
return false;
if ($echocomment)
echo $html;
else
return $html;
}
function tags_with_count( $format = 'list', $before = '', $sep = '', $after = '' ) {
global $post;
$posttags = get_the_tags($post->ID, 'post_tag');
if ( !$posttags )
return;
foreach ( $posttags as $tag ) {
if ( $tag->count > 1 && !is_tag($tag->slug) ) {
$tag_link = '' . $tag->name . ' (' . number_format_i18n( $tag->count ) . ')';
} else {
$tag_link = $tag->name;
}
if ( $format == 'list' )
$tag_link = '' . $tag_link . '';
$tag_links[] = $tag_link;
}
echo $before . join( $sep, $tag_links ) . $after;
}
function latest_post_permalink() {
global $wpdb;
$sql = "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1";
$last_post_id = $wpdb->get_var($sql);
$permalink = get_permalink($last_post_id);
return $permalink;
}
function prologue_title_from_content( $content ) {
static $strlen = null;
if ( !$strlen ) {
$strlen = function_exists('mb_strlen')? 'mb_strlen' : 'strlen';
}
$max_len = 40;
$title = $strlen( $content ) > $max_len? wp_html_excerpt( $content, $max_len ) . '...' : $content;
$title = trim( strip_tags( $title ) );
$title = str_replace("\n", " ", $title);
//Try to detect image or video only posts, and set post title accordingly
if ( !$title ) {
if ( preg_match("/