',
$title, self::get_bio($user->ID), self::get_profiles($user), $subtitle);
}
}
//obtain user fron parameter or context
private static function derive_user($attr) {
if (is_array($attr) && array_key_exists('id',$attr)) {
$id= $attr['id'];
} else { //try looking in the post
global $post;
$id = ($post && property_exists($post,'post_author') && isset($post->post_author)) ? $post->post_author : 0;
}
if ($id > 0)
$user_obj = new WP_User($id);
else //try the URL
$user_obj = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
return ($user_obj && ($user_obj->ID > 0)) ? $user_obj : false ;
}
private static function get_home_author() {
return authorsure_options::get_option('home_author');
}
private static function get_home_author_rel() {
$method = 'googleplus';
$user_id = self::get_home_author();
if ($user_id) {
add_filter('user_contactmethods', array('authorsure_options','add_contactmethods_nolabels'),10,1);
if (($user = new WP_User($user_id))
&& $user->has_prop($method)
&& ($url = $user->get($method)))
return $url;
}
return false;
}
private static function get_author_link_eligibility($post_author, $post_id, $post_type) {
if (is_front_page() && authorsure_options::get_option('hide_box_on_front_page')) return false;
if (is_singular() && authorsure_options::is_author($post_author) )
switch ($post_type) {
case 'post':
return ! get_post_meta($post_id, authorsure_options::get_hide_author_box_key(), true);
case 'page': {
if (authorsure_options::get_option('hide_box_on_pages'))
return get_post_meta($post_id, authorsure_options::get_show_author_box_key(), true);
else
return ! get_post_meta($post_id, authorsure_options::get_hide_author_box_key(), true);
}
default:
$key = strtolower($post_type).'s';
if (($custom = authorsure_options::get_option('show_box_on_custom'))
&& is_array($custom) && array_key_exists($key,$custom) && $custom[$key])
return ! get_post_meta($post_id, authorsure_options::get_hide_author_box_key(), true);
else
return get_post_meta($post_id, authorsure_options::get_show_author_box_key(), true);
}
else
return false; //not an individual page or not an author
}
public static function get_blog_author_link($id) {
return ''.get_bloginfo().'';
}
//link (rel="author") the post/post to the author page in a post footnote
public static function append_post_author_footnote($content) {
global $post;
if (self::get_author_link_eligibility($post->post_author, $post->ID, $post->post_type) ) {
$content .= self::get_footnote($post->post_author,get_post_modified_time('c'),get_the_modified_date());
}
return $content;
}
//link (rel="author") the post/post to the author page in an author box at the foot of the post
public static function append_post_author_box($content) {
global $post;
if (($user = self::derive_user(array('id' => $post->post_author)))
&& self::get_author_link_eligibility($post->post_author, $post->ID, $post->post_type) ) {
$content .= self::get_box($user);
}
return $content;
}
//add primary author contact links to the about page
public static function append_primary_author($content) {
global $post;
$about_page = authorsure_options::get_option('menu_about_page');
$primary = authorsure_options::get_option('menu_primary_author');
if ($primary && $about_page && is_page($about_page)) {
$author = new WP_User($primary);
$content .= sprintf('
%1$s
', self::get_profiles($author));
}
return $content;
}
//add a header to author page to link to Google (rel="me")
public static function insert_author_bio() {
global $post;
if (is_author() && !is_feed()) { //we're on an author page and it is not a feed
$author_hook_index = authorsure_options::get_author_page_hook_index();
self::$authorsure_count += 1;
if ($author_hook_index == self::$authorsure_count) { //only add the bio once on the specified instance
$curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
self::show_author_profile($curauth);
}
}
}
//link the home page and possibly the archive pages to GooglePlus Page (rel="publisher")
public static function add_publisher_rel() {
if (($publisher = authorsure_options::get_publisher())
&& (is_front_page() || (is_archive() && ('publisher'==authorsure_options::get_option('archive_link')))))
printf ('', AUTHORSURE_GOOGLEPLUS_URL.$publisher);
}
//link the home page with (rel="author")
public static function add_author_rel() {
if ($url = self::get_home_author_rel()) printf ('', $url);
}
public static function add_head() {
global $post;
if (authorsure_options::get_publisher()) add_action('wp_head', array(__CLASS__,'add_publisher_rel')) ; //add publisher link
if (is_front_page() && self::get_home_author()) add_action('wp_head', array(__CLASS__,'add_author_rel')) ; //add author link
$author_rel = authorsure_options::get_option('author_rel');
$about_page = authorsure_options::get_option('menu_about_page');
if (('box'==$author_rel)
|| is_author()
|| ($about_page && is_page($about_page))
|| ((is_page() || is_single()) && ($id = get_queried_object_id()) && get_post_meta($id,authorsure_options::get_include_css_key()))) {
//include css for author boxes and on author page
add_action('wp_enqueue_scripts', array(__CLASS__,'enqueue_css')) ; //add CSS
}
}
public static function enqueue_css() {
wp_enqueue_style( AUTHORSURE, AUTHORSURE_PLUGIN_URL.'styles/public.css',array(),AUTHORSURE_VERSION);
}
//** filter for use at the get_the_author_description hook **/
public static function append_profiles($content, $user_id = false) {
$args = array();
if ($user_id && ($user_id > 0)) $args['id'] = $user_id;
if (is_author() //only run on author pages
&& ($user = self::derive_user($args))
&& authorsure_options::is_author($user))
$content = sprintf('%1$s
%2$s
', $content, self::get_profiles($user));
return $content;
}
public static function add_single_author() {
if (is_singular()) {
//additions to posts and pages
$author_rel = authorsure_options::get_option('author_rel');
switch($author_rel) {
case 'menu': add_filter('the_content', array(__CLASS__,'append_primary_author')); break;
case 'footnote': add_filter('the_content', array(__CLASS__,'append_post_author_footnote')); break;
case 'box': add_filter('the_content', array(__CLASS__,'append_post_author_box')); break;
default:
}
//additions to author pages
if ($author_rel != 'menu')
if (authorsure_options::get_option('author_page_filter_bio'))
add_filter('get_the_author_description', array(__CLASS__,'append_profiles'),10,2); //append profiles to existing bio
else
add_action(authorsure_options::get_author_page_hook(), array(__CLASS__,'insert_author_bio')); //add bio to author page
}
}
public static function add_archive_author () {
if (is_archive() && ! is_author() ) {
if (authorsure_options::get_option('archive_intro_enabled') && (self::$intro = self::get_archive_intro()))
add_action('loop_start', array(__CLASS__, 'show_archive_intro'));
if (($archive_hook = authorsure_options::get_archive_hook())
&& (self::$author = self::get_archive_author())) { //get the archive author for later
add_action($archive_hook, array(__CLASS__, 'show_archive_primary_author')); //add archive
}
}
}
public static function filter_links( $content, $nofollow = false, $strip = false) {
if ($nofollow || $strip)
return preg_replace_callback( '/]*)>(.*?)<\/a[^>]*>/is',
array( AUTHORSURE, $strip ? 'make_links_text_only' : 'nofollow_link' ), $content ) ;
else
return $content ;
}
public static function nofollow_link($matches) { //make link nofollow
$attrs = shortcode_parse_atts( stripslashes ($matches[ 1 ]) );
$atts='';
foreach ( $attrs AS $key => $value ) {
$key = strtolower($key);
if ('rel' != $key) $atts .= sprintf('%1$s="%2$s" ', $key, $value);
}
$atts = substr( $atts, 0, -1 );
return sprintf('%2$s', $atts, $matches[ 2 ]);
}
public static function make_links_text_only($matches) { //return only text of link
return $matches[ 2 ];
}
public static function donotcache_avatar($donotcache, $src, $tag) {
if ( strpos($src, 'gravatar') !== FALSE ) $donotcache = true; //do not cache avatars
return $donotcache;
}
public static function add_author_bio() {
//additions to author pages
$author_rel = authorsure_options::get_option('author_rel');
if ($author_rel != 'menu')
if (authorsure_options::get_option('author_page_filter_bio'))
add_filter('get_the_author_description', array(__CLASS__,'append_profiles'),10,2); //append profiles to existing bio
else
add_action(authorsure_options::get_author_page_hook(), array(__CLASS__,'insert_author_bio')); //add bio to author page
}
//add a top section to archive page
public static function show_archive_intro() {
echo self::$intro;
}
//add a section to archive page with rel=author to primary author
public static function show_archive_primary_author( ) {
if (self::$authorsure_count == 0) {
self::$authorsure_count += 1;
if($last_update = self::get_last_update())
echo self::get_footnote(self::$author,$last_update['datetime'], $last_update['date']);
}
}
public static function strip_rel_author ($content, $args) {
return str_replace(' rel="author"','',$content);
}
public static function tweak_if_genesis() {
if ( basename( TEMPLATEPATH ) == 'genesis') { //disable Genesis authorship as AuthorSure gives more granular control
add_filter( 'genesis_formatting_allowedtags', array(__CLASS__,'genesis_allow_arel') );
remove_filter( 'user_contactmethods', 'genesis_user_contactmethods' ); //avoid collisions
remove_action( 'wp_head', 'genesis_rel_author' ); //kill off link in the head
if (authorsure_options::get_option('author_rel') != 'byline') //maybe kill the rel="author" link in the byline
add_filter('genesis_post_author_posts_link_shortcode', array(__CLASS__, 'strip_rel_author'),20,2);
}
}
//shortcode for adding author profiles into a page
public static function show_author_profiles($attr) {
if ($user = self::derive_user($attr))
return self::get_profiles($user) ;
else
return '';
}
//shortcode for adding author box into a page
public static function show_author_box($attr) {
if ($user = self::derive_user($attr))
return self::get_box($user) ;
else
return '';
}
//shortcode for listing all authors short bios on a page
public static function list_authors() {
$s='';
$authors = get_users(array('who' => 'authors', orderby => 'display_name'));
foreach ($authors as $author) {
if (get_user_option(authorsure_options::get_show_author_key(), $author->ID))
$s .= self::get_box($author);
}
return $s;
}
}
?>