'byline', //menu, byline, footnote, box 'publisher_rel' => '', //Google Plus URL of publisher 'footnote_last_updated_by' => 'Last updated by', 'footnote_last_updated_at' => 'at', 'footnote_show_updated_date' => true, 'box_about' => 'About', 'box_gravatar_size' => 60, 'box_nofollow_links' => true, 'hide_box_on_pages' => false, 'hide_box_on_front_page' => false, 'menu_about_page' => '', 'menu_primary_author' => '', 'author_page_hook' => 'loop_start', 'author_page_hook_index' => '1', 'author_page_filter_bio' => false, 'author_show_title' => true, 'author_show_avatar' => false, 'author_about' => 'About', 'author_bio' => 'summary', 'author_bio_nofollow_links' => true, 'author_find_more' => 'Find more about me on:', 'author_profiles_image_size' => 16, 'author_profiles_no_labels' => false, 'author_archive_heading'=> 'Here are my most recent posts', 'archive_link' => 'publisher', //publisher, top or bottom 'archive_intro_enabled' => false, 'archive_last_updated_by' => 'Last updated by', 'archive_author_id' => 0, 'archive_hook' => false ); private static $pro_defaults = array( 'facebook' => array('Facebook','Facebook URL'), 'flickr' => array('Flickr', 'Flickr Profile URL'), 'googleplus'=> array('Google Plus', 'Google Plus Profile URL'), 'linkedin' => array('LinkedIn', 'Linked In Profile URL'), 'pinterest' => array('Pinterest', 'Pinterest Profile URL'), 'skype' => array('Skype', 'Skype Name'), 'twitter'=> array('Twitter','Twitter Profile URL'), 'youtube'=> array('YouTube', 'YouTube Channel URL') ); private static $options = array(); private static $pro_options = array(); private static $term_options = array(); private static $author = false; private static $intro = ''; private static function get_defaults() { return self::$defaults; } private static function get_pro_defaults() { return self::$pro_defaults; } public static function get_pro_options ($cache = true) { if ($cache && (count(self::$pro_options) > 0)) return self::$pro_options; $defaults = self::get_pro_defaults(); $options = get_option('authorsure_pro_options'); self::$pro_options = empty($options) ? $defaults : wp_parse_args($options, $defaults); return self::$pro_options; } public static function get_options ($cache = true) { if ($cache && (count(self::$options) > 0)) return self::$options; $defaults = self::get_defaults(); $options = get_option('authorsure_options'); self::$options = empty($options) ? $defaults : wp_parse_args($options, $defaults); return self::$options; } public static function get_term_options ($cache = true) { if ($cache && (count(self::$term_options) > 0)) return self::$term_options; $options = get_option('authorsure_term_options'); self::$term_options = empty($options) ? array() : $options; return self::$term_options; } public static function get_option($option_name) { $options = self::get_options(); if ($option_name && $options && array_key_exists($option_name,$options)) return $options[$option_name]; else return false; } public static function get_archive_hook() { $archive_link = self::get_option('archive_link'); switch ($archive_link) { case 'top': return 'loop_start'; case 'bottom': return 'loop_end'; default: return ''; } } public static function get_author_page_hook() { $hook = self::get_option('author_page_hook'); if (empty($hook)) $hook = self::$defaults['author_page_hook']; return $hook; } public static function get_author_page_hook_index() { $hook_index = self::get_option('author_page_hook_index'); if (empty($hook_index)) $hook_index = self::$defaults['author_page_hook_index']; return $hook_index; } public static function get_show_author_key() { return self::$show_author_metakey; } public static function get_extended_bio_key() { return self::$extended_bio_metakey; } public static function get_hide_author_box_key() { return self::$hide_author_box_metakey; } public static function get_show_author_box_key() { return self::$show_author_box_metakey; } public static function get_include_css_key() { return self::$include_css_metakey; } public static function get_publisher() { return self::get_option('publisher_rel'); } public static function get_archive_option($term_id, $key) { if (!$term_id || !$key) return false; $options = self::get_term_options(); $arc_options= (is_array($options) && array_key_exists($term_id, $options)) ? $options[$term_id] : array(); return is_array($arc_options) && array_key_exists($key, $arc_options) ? $arc_options[$key] : false; } public static function save_options ($options) { $result = update_option('authorsure_options',$options); self::get_options(false); //update cache return $result; } public static function save_archive_option ($term_id, $values) { if (! $term_id || ! $values || !is_array($values) || !is_numeric($term_id)) return false; $term_options = self::get_term_options(false); //get the option to update $term_options[$term_id] = $values; //update it $result = update_option('authorsure_term_options', $term_options); //save to the database self::get_term_options(false); //update cache return $result; } public static function save_pro_options ($options) { $result = update_option('authorsure_pro_options',$options); self::get_pro_options(false); //update cache return $result; } private static function allow_img($allowedtags) { if ( !array_key_exists('img', $allowedtags) || (array_key_exists('img',$allowedtags) && !array_key_exists('src', $allowedtags['img']))) { $allowedtags['img']['src'] = array (); $allowedtags['img']['title'] = array (); $allowedtags['img']['alt'] = array (); $allowedtags['img']['height'] = array (); $allowedtags['img']['width'] = array (); } return $allowedtags; } private static function allow_arel($allowedtags) { if ( !array_key_exists('a', $allowedtags) || (array_key_exists('a',$allowedtags) && !array_key_exists('rel', $allowedtags['a']))) $allowedtags['a']['rel'] = array (); return $allowedtags; } public static function wordpress_allow_img() { global $allowedtags; $allowedtags = self::allow_img($allowedtags); } public static function wordpress_allow_arel() { global $allowedtags; $allowedtags = self::allow_arel($allowedtags); } public function genesis_allow_arel($allowedtags) { return self::allow_arel($allowedtags); } public static function genesis_allow_img($allowedtags) { return self::allow_img($allowedtags); } public static function is_author($user) { return user_can($user, 'edit_posts'); } public static function get_icon($profile, $label, $size ) { return sprintf('%2$s%3$s', AUTHORSURE_PLUGIN_URL.'images/'.$size.'px/'.$profile.'.png', $profile, $label); } public static function list_authors() { $s=''; $authors = get_users(array('who' => 'authors', orderby => 'display_name')); foreach ($authors as $author) { if (get_user_option(self::get_show_author_key(), $author->ID)) $s .= self::get_box($author->ID); } return $s; } public static function add_contactmethods_profile( $contactmethods) { return self::add_contactmethods( $contactmethods, 1, 16); } public static function add_contactmethods_nolabels( $contactmethods) { return self::add_contactmethods( $contactmethods, -1); } public static function add_contactmethods( $contactmethods, $label_index=0, $size=0) { if ($size==0) $size = self::get_option('author_profiles_image_size'); $profiles = self::get_pro_options(); if (is_array($profiles)) foreach ($profiles as $profile => $labels) //if (!array_key_exists($profile,$contactmethods)) $contactmethods[$profile] = self::get_icon($profile, $label_index<0 ? '' : (' '.$labels[$label_index]),$size); return $contactmethods; } public static function get_blog_author_link($id) { return ''.get_bloginfo().''; } private static function get_author_link($id) { return ''; } private static function get_avatar($id) { return get_avatar( get_the_author_meta('email', $id), self::get_option('box_gravatar_size') ); } private static function about_author($id) { return sprintf( '

%1$s %2$s

', self::get_option('box_about'), self::get_author_link($id)); } private static function get_title($id) { if (self::get_option('author_show_title')) { $author_name = get_the_author_meta('display_name',$id); if ($prefix = self::get_option('author_about')) $title = $prefix . ' ' . $author_name; else $title = $author_name; return sprintf( '

%1$s

',$title); } else { return ''; } } private static function get_bio($id) { $nofollow = self::get_option('author_bio_nofollow_links'); //setting for author page switch (authorsure::get_option('author_bio')) { case 'summary': return self::get_summary_bio($id, $nofollow); break; case 'extended': return self::get_extended_bio($id, $nofollow); break; } return ''; } private static function get_summary_bio($id, $nofollow = true ) { return self::filter_links(wpautop( get_the_author_meta('description',$id) ), $nofollow ); } private static function get_extended_bio($id, $nofollow = true) { //return extended bio if present else return standard bio $bio = self::filter_links(wpautop( get_the_author_meta(authorsure::$extended_bio_metakey,$id)), $nofollow); return empty($bio) ? self::get_summary_bio($id, $nofollow) : $bio ; } private static function get_box($id) { return sprintf('
%1$s%2$s%3$s
', self::get_avatar($id), self::about_author($id), self::get_summary_bio($id, self::get_option('box_nofollow_links') ) ); } private static function get_footnote($id) { $author = sprintf( '%1$s', self::get_author_link($id) ); $updated_at = self::get_option('footnote_show_updated_date') ? sprintf( ' %1$s ',self::get_option('footnote_last_updated_at'),get_post_modified_time('c'),get_the_modified_date()) : ''; return sprintf( '

%2$s %3$s%4$s.

', get_permalink(), self::get_option('footnote_last_updated_by'), $author, $updated_at); } private static function skype_me ($name, $img, $nolabels) { wp_enqueue_script('skypeCheck', 'http://download.skype.com/share/skypebuttons/js/skypeCheck.js',array(),'v2.2',true); if ($pos = strpos($name,'/status')) $name = substr($name,0,$pos) ; if (($nolabels==false) && ($pos > 0)) { $img .= sprintf(' My status',$name); } return sprintf('
  • %2$s
  • ', $name, $img); } private static function get_profiles($user) { $s=''; $profiles = self::get_pro_options(); $no_labels = self::get_option('author_profiles_no_labels'); add_filter('user_contactmethods', array(AUTHORSURE,$no_labels ? 'add_contactmethods_nolabels' : 'add_contactmethods'),10,1); foreach (_wp_get_user_contactmethods( $user ) as $name => $desc) { if (array_key_exists($name,$profiles) && !empty($user->$name)) if ('skype'==$name) $s .= self::skype_me($user->$name,$desc,$no_labels); else $s .= sprintf('
  • %3$s
  • ', $user->$name,ucwords($name),$desc); } if (empty($s)) return ''; elseif ($no_labels) return sprintf('',self::get_option('author_find_more'), $s); else return sprintf('

    %1$s

    ',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')); } ?>