function form($instance) { $defaults = array('widget_ID' => '', 'twitter_username' => largo_twitter_url_to_username(of_get_option('twitter_link')), 'twitter_list_slug' => 'inn-staff-and-associates', 'twitter_search' => __('your search', 'largo'), 'widget_type' => 'timeline', 'widget_theme' => 'light'); $instance = wp_parse_args((array) $instance, $defaults); ?> <p> <label for="<?php echo $this->get_field_id('widget_type'); ?> "><?php _e('Widget Type', 'largo'); ?> </label> <select id="<?php echo $this->get_field_id('widget_type'); ?> " name="<?php echo $this->get_field_name('widget_type'); ?> " class="widefat" style="width:90%;"> <option <?php selected($instance['widget_type'], 'timeline'); ?> value="timeline"><?php _e('Timeline', 'largo'); ?> </option> <option <?php selected($instance['widget_type'], 'favorites'); ?> value="favorites"><?php _e('Favorites', 'largo'); ?> </option> <option <?php selected($instance['widget_type'], 'list'); ?> value="list"><?php _e('List', 'largo'); ?> </option> <option <?php selected($instance['widget_type'], 'search'); ?> value="search"><?php _e('Search', 'largo'); ?> </option> </select> </p> <p> <label for="<?php echo $this->get_field_id('widget_theme'); ?> "><?php _e('Widget Theme', 'largo'); ?> </label> <select id="<?php echo $this->get_field_id('widget_theme'); ?> " name="<?php echo $this->get_field_name('widget_theme'); ?> " class="widefat" style="width:90%;"> <option <?php selected($instance['widget_theme'], 'light'); ?> value="light"><?php _e('Light', 'largo'); ?> </option> <option <?php selected($instance['widget_theme'], 'dark'); ?> value="dark"><?php _e('Dark', 'largo'); ?> </option> </select> </p> <p> <label for="<?php echo $this->get_field_id('widget_ID'); ?> "><?php _e('Twitter Widget ID (from https://twitter.com/settings/widgets):', 'largo'); ?> </label> <input id="<?php echo $this->get_field_id('widget_ID'); ?> " name="<?php echo $this->get_field_name('widget_ID'); ?> " value="<?php echo esc_attr($instance['widget_ID']); ?> " style="width:90%;" /> </p> <p> <label for="<?php echo $this->get_field_id('twitter_username'); ?> "><?php _e('Twitter Username (for timeline, favorites and list widgets):', 'largo'); ?> </label> <input id="<?php echo $this->get_field_id('twitter_username'); ?> " name="<?php echo $this->get_field_name('twitter_username'); ?> " value="<?php echo esc_attr($instance['twitter_username']); ?> " style="width:90%;" /> </p> <p> <label for="<?php echo $this->get_field_id('twitter_list_slug'); ?> "><?php _e('Twitter List Slug (for list widget):', 'largo'); ?> </label> <input id="<?php echo $this->get_field_id('twitter_list_slug'); ?> " name="<?php echo $this->get_field_name('twitter_list_slug'); ?> " value="<?php echo esc_attr($instance['twitter_list_slug']); ?> " style="width:90%;" /> </p> <p> <label for="<?php echo $this->get_field_id('twitter_search'); ?> "><?php _e('Twitter Search Query (for search widget):', 'largo'); ?> </label> <input id="<?php echo $this->get_field_id('twitter_search'); ?> " name="<?php echo $this->get_field_name('twitter_search'); ?> " value="<?php echo esc_attr($instance['twitter_search']); ?> " style="width:90%;" /> </p> <?php }
<?php // $coauthor covers base case (1 dimensional) or where coauthors were defined. ?> <?php foreach ($coauthors as $author) { ?> <div class="follow-author"> <a href="<?php echo get_author_feed_link($author->ID, ''); ?> " class="icon-rss"></a> <?php if ($twitter = get_the_author_meta('twitter', $author->ID)) { ?> <a href="https://twitter.com/<?php echo largo_twitter_url_to_username(esc_url($twitter)); ?> " class="icon-twitter"></a> <?php } ?> <a href="<?php echo get_author_posts_url($author->ID, $author->user_nicename); ?> "><?php echo esc_html($author->display_name); ?> </a> </div> <?php }
function validate_twitter_username($errors, $update, $user) { if (isset($_POST["twitter"])) { $tw_suspect = trim($_POST["twitter"]); if (!empty($tw_suspect)) { if (preg_match('/[^a-zA-Z0-9_]/', largo_twitter_url_to_username($tw_suspect))) { // it's not a valid twitter username, because it uses an invalid character $errors->add('twitter_username', '<b>' . $tw_suspect . '</b>' . __('is an invalid Twitter username.') . '</p>' . '<p>' . __('Twitter usernames only use the uppercase and lowercase alphabet letters (a-z A-Z), the Arabic numbers (0-9), and underscores (_).')); } } } }
function largo_post_social_links($echo = true) { $utilities = of_get_option('article_utilities'); $output = '<div class="post-social clearfix"><div class="left">'; if ($utilities['twitter'] === '1') { $twitter_link = of_get_option('twitter_link') ? 'data-via="' . esc_attr(largo_twitter_url_to_username(of_get_option('twitter_link'))) . '"' : ''; $twitter_related = get_the_author_meta('twitter') ? sprintf('%s:' . __('Follow the author of this article', 'largo'), get_the_author_meta('twitter')) : ''; $twitter_count = of_get_option('show_twitter_count') == 0 ? 'data-count="none"' : ''; $output .= sprintf('<span class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-url="%1$s" data-text="%2$s" %3$s data-via="%4$s" %5$s>%6$s</a></span>', get_permalink(), get_the_title(), $twitter_link, $twitter_related, $twitter_count, esc_attr(__('Tweet', 'largo'))); } if ($utilities['facebook'] === '1') { $output .= sprintf('<span class="facebook"><fb:like href="%1$s" send="false" layout="button_count" show_faces="false" action="%2$s"></fb:like></span>', get_permalink(), esc_attr(of_get_option('fb_verb'))); } $output .= '</div><div class="right">'; if ($utilities['print'] === '1') { $output .= '<span class="print"><a href="#" onclick="window.print()" title="' . esc_attr(__('Print this article', 'largo')) . '" rel="nofollow"><i class="icon-print"></i> ' . esc_attr(__('Print', 'largo')) . '</a></span>'; } if ($utilities['email'] === '1') { $output .= '<span data-service="email" class="email custom-share-button icon-mail share-button"> Email</span>'; } $output .= '</div></div>'; if ($echo) { echo $output; } else { return $output; } }
?> " title="<?php echo esc_attr($author_obj->display_name); ?> on Facebook" rel="me"><i class="icon-facebook"></i></a> </li> <?php } ?> <?php if ($twitter = $author_obj->twitter) { ?> <li class="twitter"> <a href="https://twitter.com/<?php echo largo_twitter_url_to_username($twitter); ?> "><i class="icon-twitter"></i></a> </li> <?php } ?> <?php if ($email = $author_obj->user_email) { ?> <li class="email"> <a class="email" href="mailto:<?php echo esc_attr($email); ?> " title="e-mail <?php
function largo_opengraph() { global $post; // set a default thumbnail, if a post has a featured image use that instead if (is_single() && has_post_thumbnail($post->ID)) { $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); $thumbnailURL = $image[0]; } else { if (of_get_option('logo_thumbnail_sq')) { $thumbnailURL = of_get_option('logo_thumbnail_sq'); } else { $thumbnailURL = false; } } // start the output, some attributes will be the same for all page types ?> <meta name="twitter:card" content="summary"> <?php if (of_get_option('twitter_link')) { echo '<meta name="twitter:site" content="@' . largo_twitter_url_to_username(of_get_option('twitter_link')) . '">'; } ?> <?php // output appropriate OG tags by page type if (is_single()) { if (have_posts()) { the_post(); // we need to queue up the post to get the post specific info if (get_the_author_meta('twitter') && !get_post_meta($post->ID, 'largo_byline_text')) { echo '<meta name="twitter:creator" content="@' . largo_twitter_url_to_username(get_the_author_meta('twitter')) . '">'; } ?> <meta property="og:title" content="<?php the_title(); ?> " /> <meta property="og:type" content="article" /> <meta property="og:url" content="<?php the_permalink(); ?> "/> <meta property="og:description" content="<?php echo strip_tags(get_the_excerpt()); ?> " /> <meta name="description" content="<?php echo strip_tags(get_the_excerpt()); ?> " /> <?php } // have_posts rewind_posts(); } elseif (is_home()) { ?> <meta property="og:title" content="<?php bloginfo('name'); echo ' - '; bloginfo('description'); ?> " /> <meta property="og:type" content="website" /> <meta property="og:url" content="<?php echo home_url(); ?> "/> <meta property="og:description" content="<?php bloginfo('description'); ?> " /> <meta name="description" content="<?php bloginfo('description'); ?> " /> <?php } else { ?> <meta property="og:title" content="<?php bloginfo('name'); wp_title(); ?> " /> <meta property="og:type" content="article" /> <meta property="og:url" content="<?php echo esc_url(largo_get_current_url()); ?> "/> <?php //let's try to get a better description when available if (is_category() && category_description()) { $description = category_description(); } elseif (is_author()) { if (have_posts()) { the_post(); // we need to queue up the post to get the post specific info if (get_the_author_meta('description')) { $description = get_the_author_meta('description'); } } rewind_posts(); } else { $description = get_bloginfo('description'); } if ($description) { echo '<meta property="og:description" content="' . strip_tags($description) . '" />'; echo '<meta name="description" content="' . strip_tags($description) . '" />'; } } // else // a few more attributes that are common to all page types echo '<meta property="og:site_name" content="' . get_bloginfo() . '" />'; // thumbnail url if ($thumbnailURL) { echo '<meta property="og:image" content="' . esc_url($thumbnailURL) . '" />'; } // google author/publisher markup // see: https://support.google.com/webmasters/answer/1408986 if (of_get_option('gplus_link')) { echo '<link href="' . esc_url(of_get_option('gplus_link')) . '" rel="publisher" />'; } }
?> " data-layout="button_count" data-show-faces="false" data-width="225"></div> </li> <?php } ?> <?php if ($twitter = $author_obj->twitter) { ?> <li class="twitter"> <a href="https://twitter.com/<?php echo largo_twitter_url_to_username($twitter); ?> " class="twitter-follow-button" data-show-count="false"><?php printf(__('Follow @%1$s', 'largo'), largo_twitter_url_to_username($twitter)); ?> </a> </li> <?php } ?> <?php if ($email = $author_obj->user_email) { ?> <li class="email"> <a class="email" href="mailto:<?php echo esc_attr($email); ?> " title="e-mail <?php
function test_largo_twitter_url_to_username() { /** * With no input, it should return an empty string */ $result = largo_twitter_url_to_username(""); $this->assertEquals("", $result); unset($result); /** * With a valid username, it should return the username */ $result = largo_twitter_url_to_username("foo_1"); $this->assertEquals("foo_1", $result); unset($result); /** * With a valid url, it should return a valid username */ $result = largo_twitter_url_to_username("http://twitter.com/foo_2"); $this->assertEquals("foo_2", $result); unset($result); $result = largo_twitter_url_to_username("https://twitter.com/foo_3"); $this->assertEquals("foo_3", $result); unset($result); $result = largo_twitter_url_to_username("https://www.twitter.com/foo_4"); $this->assertEquals("foo_4", $result); unset($result); /** * With an @ in the username, it should return the username without the @ */ $result = largo_twitter_url_to_username("https://twitter.com/@foo_5"); $this->assertEquals("foo_5", $result); unset($result); $result = largo_twitter_url_to_username("@foo_6"); $this->assertEquals("foo_6", $result); unset($result); /** * With a username that has invalid characters and URL parameters in it, it should return the invalid characters, but not URL parameters */ $result = largo_twitter_url_to_username("http://twitter.com/@foo.bar_7-!0?baz=qux&yes=no#hi"); $this->assertEquals("foo.bar_7-!0", $result); unset($result); $result = largo_twitter_url_to_username("https://twitter.com/@foo.bar_8-!0?baz=qux&yes=no#hi"); $this->assertEquals("foo.bar_8-!0", $result); unset($result); /** * With a non-Twitter URL, it should still return the last section after the / */ $result = largo_twitter_url_to_username("http://github.com/INN/foo_9"); $this->assertEquals("foo_9", $result); unset($result); $result = largo_twitter_url_to_username("https://plus.google.com/foo_10"); $this->assertEquals("foo_10", $result); unset($result); /** * With no input, it should return an empty string */ $result = largo_twitter_url_to_username(""); $this->assertEquals("", $result); unset($result); }
/** * How to display the widget on the screen. */ function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); echo $before_widget; /* Display the widget title if one was input */ if ($title) { echo $before_title . $title . $after_title; } $feed = get_feed_link(); if (is_single() && isset($id) && $id == 'article-bottom') { // display the post social bar largo_post_social_links(); } else { // display the usual buttons and whatnot if (of_get_option('rss_link')) { $feed = esc_url(of_get_option('rss_link')); } printf(__('<a class="subscribe" href="%1$s"><i class="icon-rss"></i>Subscribe via RSS</a>', 'largo'), $feed); if (of_get_option('twitter_link')) { ?> <a href="<?php echo esc_url(of_get_option('twitter_link')); ?> " class="twitter-follow-button" data-width="100%" data-align="left" data-size="large"><?php printf(__('Follow @%1$s', 'largo'), largo_twitter_url_to_username(of_get_option('twitter_link'))); ?> </a> <?php } if (of_get_option('facebook_link')) { ?> <div class="fb-like" data-href="<?php echo esc_url(of_get_option('facebook_link')); ?> " data-send="false" data-show-faces="false"></div> <?php } if (of_get_option('linkedin_link')) { ?> <a class="subscribe" href="<?php echo esc_url(of_get_option('linkedin_link')); ?> "><i class="icon-linkedin"></i>Find Us on LinkedIn</a> <?php } if (of_get_option('gplus_link')) { ?> <div class="g-follow" data-annotation="bubble" data-height="24" data-href="<?php echo esc_url(of_get_option('gplus_link')); ?> " data-rel="publisher"></div> <?php } if (of_get_option('flickr_link')) { ?> <div class="flickr-follow"><a href="<?php echo esc_url(of_get_option('flickr_link')); ?> " title="See our photos on Flickr!"><img src="https://s.yimg.com/pw/images/goodies/white-flickr.png" width="56" height="26" alt=""></a></div> <?php } if (of_get_option('youtube_link')) { $path = parse_url(of_get_option('youtube_link'), PHP_URL_PATH); $pathFragments = explode('/', $path); $yt_user = end($pathFragments); ?> <div class="g-ytsubscribe" data-channel="<?php echo esc_attr($yt_user); ?> " data-layout="default" data-count="default"></div> <?php } //the below is for G+ and YouTube subscribe buttons ?> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/platform.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> <?php } echo $after_widget; }
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); echo $before_widget; /* Display the widget title if one was input */ if ($title) { echo $before_title . $title . $after_title; } $feed = get_feed_link(); if (is_single() && isset($id) && $id == 'article-bottom') { // display the post social bar largo_post_social_links(); } else { // display the usual buttons and whatnot if (of_get_option('rss_link')) { $feed = esc_url(of_get_option('rss_link')); } printf(__('<a class="rss subscribe btn social-btn" href="%1$s"><i class="icon-rss"></i>Subscribe via RSS</a>', 'largo'), $feed); if (of_get_option('twitter_link')) { ?> <a href="<?php echo esc_url(of_get_option('twitter_link')); ?> " class="twitter subscribe btn social-btn"><i class="icon-twitter"></i><?php printf(__('Follow @%1$s', 'largo'), largo_twitter_url_to_username(of_get_option('twitter_link'))); ?> </a> <?php } if (of_get_option('facebook_link')) { ?> <a href="<?php echo esc_url(of_get_option('facebook_link')); ?> " class="facebook subscribe btn social-btn"><i class="icon-facebook"></i> <?php _e('Like on Facebook', 'largo'); ?> </a> <?php } if (of_get_option('linkedin_link')) { ?> <a class="linkedin subscribe btn social-btn" href="<?php echo esc_url(of_get_option('linkedin_link')); ?> "><i class="icon-linkedin"></i><?php _e('Find on LinkedIn', 'largo'); ?> </a> <?php } if (of_get_option('gplus_link')) { ?> <a class="gplus subscribe btn social-btn" href="<?php echo esc_url(of_get_option('gplus_link')); ?> "><i class="icon-gplus"></i><?php _e('Follow on G+', 'largo'); ?> </a> <?php } if (of_get_option('flickr_link')) { ?> <a class="flickr subscribe btn social-btn" href="<?php echo esc_url(of_get_option('flickr_link')); ?> "><i class="icon-flickr"></i><?php _e('Follow on Flickr', 'largo'); ?> </a> <?php } if (of_get_option('youtube_link')) { ?> <a class="youtube subscribe btn social-btn" href="<?php echo esc_url(of_get_option('youtube_link')); ?> "><i class="icon-youtube"></i><?php _e('Follow on YouTube', 'largo'); ?> </a> <?php } //the below is for G+ and YouTube subscribe buttons ?> <script type="text/javascript"> (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/platform.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> <?php } echo $after_widget; }