'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, 'menu_about_page' => '', 'menu_primary_author' => '', 'author_show_title' => true, 'author_about' => 'About', 'author_bio' => 'summary', 'author_find_more' => 'Find more about me on:', 'author_profiles'=> array( 'facebook' => array('Facebook','Facebook URL'), 'flickr' => array('Flickr', 'Flickr Profile URL'), 'googleplus'=> array('Google Plus', 'Google Plus Profile URL'), 'linkedin' => array('LinkedIn', 'Linked Profile Profile URL'), 'skype' => array('Skype', 'Skype Name'), 'twitter'=> array('Twitter','Twitter Profile URL'), 'youtube'=> array('YouTube', 'YouTube Channel URL') ), '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_term_options' => array() ); private static $authorsure_count = 0; private static $options = array(); private static $pro_options = array(); 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; $as_options = array(); $options = get_option("authorsure_pro_options"); if (empty($options)) { $as_options = self::get_pro_defaults(); } else { foreach ($options as $key => $option) if (isset($options[$key]) ) $as_options[$key] = $option; $as_options = wp_parse_args( $as_options, self::get_pro_defaults()); } self::$pro_options = $as_options; return self::$pro_options; } public static function get_options ($cache = true) { if ($cache && (count(self::$options) > 0)) return self::$options; $as_options = array(); $options = get_option('authorsure_options'); if (empty($options)) { $as_options = self::get_defaults(); } else { foreach ($options as $key => $option) if (isset($options[$key]) ) $as_options[$key] = $option; $as_options = wp_parse_args( $as_options, self::get_defaults()); } self::$options = $as_options; return self::$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_extended_bio_key() { return self::$extended_bio_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_option('archive_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; $all_options = self::get_options(false); //get all options $arc_options = $all_options['archive_term_options']; //get the option to update $arc_options[$term_id] = $values; //update it $all_options['archive_term_options']= $arc_options; //update the set of all options return self::save_options($all_options); //save to the database } 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'); } private static function add_icon($profile, $label ) { return sprintf('%2$s %3$s', AUTHORSURE_PLUGIN_URL.'/images/'.$profile.'.png', $profile, $label); } public static function add_contactmethods_profile( $contactmethods) { return self::add_contactmethods( $contactmethods, 1); } public static function add_contactmethods( $contactmethods, $label_index=0 ) { $profiles = self::get_option('author_profiles'); if (is_array($profiles)) foreach ($profiles as $profile => $labels) if (!array_key_exists($profile,$contactmethods)) $contactmethods[$profile] = self::add_icon($profile,$labels[$label_index]); 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) { switch (authorsure::get_option('author_bio')) { case 'summary': return self::get_summary_bio($id); break; case 'extended': return self::get_extended_bio($id); break; } return ''; } private static function get_summary_bio($id) { return wpautop( get_the_author_meta('description',$id) ) ; } private static function get_extended_bio($id) { return wpautop( get_the_author_meta(authorsure::$extended_bio_metakey,$id) ) ; } 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)); } 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 get_profiles($user) { $s=''; $profiles = self::get_option('author_profiles'); add_filter('user_contactmethods', array(AUTHORSURE,'add_contactmethods'),10,1); foreach (_wp_get_user_contactmethods( $user ) as $name => $desc) { if (array_key_exists($name,$profiles) && !empty($user->$name)) $s .= '
  • '.$desc.'
  • '; } return empty($s) ? '' : ('

    '.self::get_option('author_find_more').'

    '); } 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 (is_single() || (is_page() && $show)) && !is_front_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); } //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::$show_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 .= 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() && (self::$authorsure_count == 0)) { //only add the bio once if there are multiple loops on the page self::$authorsure_count += 1; $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 init() { //additions to head section if (self::get_publisher()) add_action('wp_head', array(AUTHORSURE,'add_publisher_rel')) ; //add publisher link $author_rel = self::get_option('author_rel'); $author_bio = self::get_option('author_bio'); if (('box'==$author_rel) || ('extended'==$author_bio)) //include css for author boxes and extended bios wp_enqueue_style( 'AUTHORSURE', AUTHORSURE_PLUGIN_URL.'authorsure.css',array(),AUTHORSURE_VERSION); //additions to posts and pages 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('loop_start', array(AUTHORSURE,'insert_author_bio')); //add bio to profile 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'); } else { add_action('init', array(AUTHORSURE,'init')); } ?>