',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 top section to archive page
static function show_archive_intro() {
echo self::$intro;
}
//add a section to archive page with rel=author to primary author
static function show_archive_primary_author( ) {
if (self::$authorsure_count == 0) {
self::$authorsure_count += 1;
echo self::get_footnote(self::$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 = '';
$title = self::get_title($id);
if (self::get_option('author_show_avatar')) $title .= self::get_avatar($id);
if ( self::is_author($user))
echo sprintf('
%1$s%2$s%3$s%4$s
',
$title, self::get_bio($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 ;
}
//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 '';
}
private static function get_author_link_eligibility($post_author, $post_id, $post_type) {
if (is_front_page() && self::get_option('hide_box_on_front_page')) return false;
if (is_singular() && self::is_author($post_author) )
switch ($post_type) {
case 'post':
return ! get_post_meta($post_id, self::$hide_author_box_metakey, true);
case 'page': {
if (self::get_option('hide_box_on_pages'))
return get_post_meta($post_id, self::$show_author_box_metakey, true);
else
return ! get_post_meta($post_id, self::$hide_author_box_metakey, true);
}
default:
return get_post_meta($post_id, self::$show_author_box_metakey, true);
}
else
return false; //not an individual page or not an author
}
//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);
}
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 (self::get_author_link_eligibility($post->post_author, $post->ID, $post->post_type) ) {
$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() && !is_feed()) { //we're on an author page and it is not a feed
$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);
}
}
}
//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() {
global $post;
$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))
|| ((is_page() || is_single()) && ($id = get_queried_object_id()) && get_post_meta($id,self::$include_css_metakey))) {
//include css for author boxes and on author page
wp_enqueue_style( AUTHORSURE, AUTHORSURE_PLUGIN_URL.'authorsure.css',array(),AUTHORSURE_VERSION);
}
}
//** filter for use at the get_the_author_description hook **/
public static function append_profiles($content, $user_id = false) {
if (is_author()) { //only run on author pages
if ($user_id && ($user_id > 0))
$user = new WP_User( $user_id ); //use user_id is passed
else
$user = self::derive_user(false); //otherwise derive it
if (self::is_author($user))
$content = sprintf('%1$s
%2$s
', $content, self::get_profiles($user));
}
return $content;
}
public static function init() {
//additions to head section
add_action('wp', 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')
if (self::get_option('author_page_filter_bio'))
add_filter('get_the_author_description', array(AUTHORSURE,'append_profiles'),10,2); //append profiles to existing bio
else
add_action(self::get_author_page_hook(), array(AUTHORSURE,'insert_author_bio')); //add bio to author page
add_action('wp', array(AUTHORSURE,'add_archive_author')); //add archive author
}
static function add_archive_author () {
if (is_archive() && ! is_author() ) {
if (self::get_option('archive_intro_enabled') && (self::$intro = self::get_archive_intro()))
add_action('loop_start', array(AUTHORSURE, 'show_archive_intro'));
if (($archive_hook = self::get_archive_hook())
&& (self::$author = self::get_archive_author())) { //get the archive author for later
add_action($archive_hook, array(AUTHORSURE, 'show_archive_primary_author')); //add archive
}
}
}
static function add_footer_filter() {
add_filter('wp_list_bookmarks', array(self::CLASSNAME,'filter_links'),20); //nofollow links in custom footer widgets
}
static function filter_links( $content, $nofollow = true) {
return $nofollow ?
preg_replace_callback( '/]*)>(.*?)<\/a[^>]*>/is', array( AUTHORSURE, 'nofollow_link' ), $content ) : $content ;
}
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 ]);
}
}
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'));
}
?>