',self::get_option('author_find_more'), $s);
}
private static function get_archive_term_id() {
global $wp_query;
if (is_archive() && ($term = $wp_query->get_queried_object()))
return $term->term_id;
else
return false;
}
private static function get_archive_author() {
if ($author = self::get_archive_option(self::get_archive_term_id(), 'author'))
return $author; //return author explicitly chosen for this archive
else
return self::get_option('archive_author_id'); //return the default author for archives
}
private static function get_archive_intro() {
if ($intro = self::get_archive_option(self::get_archive_term_id(),'intro'))
return sprintf ('
%1$s
',stripslashes($intro));
else
return '';
}
//add a section to archive page with rel=author to primary author
private static function show_archive_primary_author($at_top ) {
if (is_archive() && (!is_author()) //it's an archive page that is not an author page
&& (self::$authorsure_count == 0) // and we have not already added a link
&& ($author = self::get_archive_author())) { //and we have a primary author
self::$authorsure_count += 1;
if ($at_top && self::get_option('archive_intro_enabled') && ($intro = self::get_archive_intro())) echo $intro;
echo self::get_footnote($author);
}
}
private static function show_author_profile($user) {
$id = $user->ID;
if ($archive_heading = self::get_option('author_archive_heading'))
$subtitle = sprintf('
%1$s
',$archive_heading);
else
$subtitle = '';
if ( self::is_author($user))
echo sprintf('%1$s
%2$s %3$s
%4$s',
self::get_title($id), self::get_bio($id), self::get_profiles($user), $subtitle);
}
private static function fetch_footnote($author) {
return self::show_author_rel($author) ? self::get_footnote($author) : '';
}
//is the post/page suitable to show rel=author?
public static function show_author_rel($author_id, $show = true) {
return $show && (is_single() || is_page()) && self::is_author($author_id) ;
}
//link (rel="author") the post/post to the author page in a post footnote
public static function append_post_author_footnote($content) {
global $post;
return $content . self::fetch_footnote($post->post_author);
}
//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 ;
}
//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->ID) ;
else
return '';
}
//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;
$show = (is_single() || is_page()) && (! get_post_meta($post->ID, self::$hide_author_box_metakey, true)) ;
if (self::show_author_rel($post->post_author,$show)) $content .= self::get_box($post->post_author);
return $content;
}
//add primary author contact links to the about page
public static function append_primary_author($content) {
global $post;
$about_page = self::get_option('menu_about_page');
$primary = self::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()) { //we're on an author page
$author_hook_index = self::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);
}
}
}
//add a section to the top of archive page with rel=author to primary author
public static function insert_archive_primary_author() {
self::show_archive_primary_author(true);
}
//add a section to the foot of archive page with rel=author to primary author
public static function append_archive_primary_author() {
self::show_archive_primary_author(false);
}
//link the home page and possibly the archive pages to GooglePlus Page (rel="publisher")
public static function add_publisher_rel() {
if (($publisher = self::get_publisher())
&& (is_front_page() || (is_archive() && ('publisher'==self::get_option('archive_link')))))
echo ('');
}
public static function add_css() {
$author_rel = self::get_option('author_rel');
$about_page = self::get_option('menu_about_page');
if (('box'==$author_rel) || is_author() || ($about_page && is_page($about_page))) { //include css for author boxes and on author page
wp_enqueue_style( 'AUTHORSURE', AUTHORSURE_PLUGIN_URL.'authorsure.css',array(),AUTHORSURE_VERSION);
}
}
public static function init() {
//additions to head section
add_action('wp_head', array(AUTHORSURE, 'add_css'));
if (self::get_publisher()) add_action('wp_head', array(AUTHORSURE,'add_publisher_rel')) ; //add publisher link
//additions to posts and pages
$author_rel = self::get_option('author_rel');
switch($author_rel) {
case 'menu': add_filter('the_content', array(AUTHORSURE,'append_primary_author')); break;
case 'footnote': add_filter('the_content', array(AUTHORSURE,'append_post_author_footnote')); break;
case 'box': add_filter('the_content', array(AUTHORSURE,'append_post_author_box')); break;
default:
}
//additions to author pages
if ($author_rel != 'menu') add_action(self::get_author_page_hook(), array(AUTHORSURE,'insert_author_bio')); //add bio to author page
//additions to archive pages
$archive_link = self::get_option('archive_link');
if ('top'==$archive_link) add_action('loop_start', array(AUTHORSURE, 'insert_archive_primary_author')); //add archive link at top
if ('bottom'==$archive_link) add_action('loop_end', array(AUTHORSURE, 'append_archive_primary_author')); //add archive link at bottom
}
}
add_action( 'wp_loaded', array(AUTHORSURE,'wordpress_allow_arel') );
add_filter( 'genesis_formatting_allowedtags', array(AUTHORSURE,'genesis_allow_arel') );
$thisdir = dirname(__FILE__) . '/';
if (is_admin()) {
require_once($thisdir.'authorsure-admin.php');
require_once($thisdir.'authorsure-archive.php');
require_once($thisdir.'authorsure-profile.php');
require_once($thisdir.'authorsure-post.php');
} else {
add_action('init', array(AUTHORSURE,'init'));
add_shortcode('authorsure_authors', array(AUTHORSURE,'list_authors'));
add_shortcode('authorsure_author_box', array(AUTHORSURE,'show_author_box'));
add_shortcode('authorsure_author_profiles', array(AUTHORSURE,'show_author_profiles'));
}
?>