|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| -* Module Name: Google+ Profile |
4 |
| -* Module Description: Give users the ability to share posts to Google+, and add your site link to your Google+ profile. |
5 |
| -* Sort Order: 18 |
6 |
| -* First Introduced: 2.5 |
7 |
| -* Requires Connection: Yes |
8 |
| -* Auto Activate: Yes |
9 |
| -*/ |
10 |
| -function jetpack_init_gplus_authorship() { |
11 |
| - new GPlus_Authorship; |
12 |
| -} |
13 |
| -add_action( 'init', 'jetpack_init_gplus_authorship' ); |
14 |
| - |
15 |
| -class GPlus_Authorship { |
16 |
| - |
17 |
| - private $byline_displayed = false; |
18 |
| - |
19 |
| - function __construct() { |
20 |
| - $this->in_jetpack = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? false : true; |
21 |
| - if ( $this->in_jetpack ) { |
22 |
| - require dirname( __FILE__ ) . "/gplus-authorship/admin/ui.php"; |
23 |
| - $gplus_admin = new GPlus_Authorship_Admin; |
24 |
| - add_action( 'save_post', array( 'GPlus_Authorship_Admin', 'save_post_meta' ) ); |
25 |
| - add_action( 'wp_ajax_save_gplus_profile_data', array( $this, 'save_profile_data' ) ); |
26 |
| - add_filter( 'the_content', array( $this, 'post_output_wrapper' ), 22, 1 ); |
27 |
| - } else { |
28 |
| - add_filter( 'post_flair', array( $this, 'post_output_wrapper' ), 22 ); |
29 |
| - } |
30 |
| - add_action( 'wp_head', array( $this, 'link_tag_styles_and_scripts' ) ); |
31 |
| - add_filter( 'the_author', array( $this, 'overwrite_the_author' ) ); |
32 |
| - add_filter( 'the_content', array( $this, 'overwrite_rel_attrs' ) ); |
33 |
| - } |
34 |
| - |
35 |
| - function show_on_this_post() { |
36 |
| - global $post; |
37 |
| - if ( ! apply_filters( 'gplus_authorship_show', true, $post ) ) { |
38 |
| - return false; |
39 |
| - } |
40 |
| - $author = $this->information( $post->post_author ); |
41 |
| - if ( empty( $author ) ) |
42 |
| - return false; |
43 |
| - $meta = get_post_meta( $post->ID, 'gplus_authorship_disabled', true ); |
44 |
| - if ( isset( $meta ) && true == $meta ) |
45 |
| - return false; |
46 |
| - return true; |
47 |
| - } |
48 |
| - |
49 |
| - function information( $author ) { |
50 |
| - $authors = get_option( 'gplus_authors', array() ); |
51 |
| - return ( empty( $authors[ $author ] ) ? array() : $authors[ $author ] ); |
52 |
| - } |
53 |
| - |
54 |
| - /** |
55 |
| - * Both overwrite_rel_attrs and rel_callback remove 'author' from the rel attribute of a link if it is found |
56 |
| - * and if the post is being viewed on a single page, with G+ authorship enabled. |
57 |
| - * based on prior art from privatize_link in wp-content/mu-plugins/private-blog.php |
58 |
| - */ |
59 |
| - function overwrite_rel_attrs( $content ) { |
60 |
| - if ( !is_single() ) // don't bother unless we are on a page where the G+ authorship link is actually being displayed |
61 |
| - return $content; |
62 |
| - if ( !$this->show_on_this_post() ) // G+ isn't enabled |
63 |
| - return $content; |
64 |
| - if ( ! is_main_query() || ! in_the_loop() ) |
65 |
| - return $content; |
66 |
| - return preg_replace_callback( '#<a\s+[^>]+>#i', array( $this, 'rel_callback' ), $content ); |
67 |
| - } |
68 |
| - |
69 |
| - function rel_callback( $link ) { |
70 |
| - $link = $link[0]; // preg replace returns as array |
71 |
| - |
72 |
| - // See if the link contains a rel="author ..." attribute, and if so, remove the author part |
73 |
| - $link = preg_replace_callback( '/rel\s*=\s*("|\').*author[^"\']*("|\')/i', array( $this, 'rel_attr_callback' ), $link ); |
74 |
| - |
75 |
| - // See if we have an empty rel attribute now and remove it if need be |
76 |
| - $link = preg_replace( '/rel\s*=\s*("|\')\s*("|\')\s*/i', '', $link ); |
77 |
| - |
78 |
| - return $link; |
79 |
| - } |
80 |
| - |
81 |
| - function rel_attr_callback( $attr ) { |
82 |
| - $attr = $attr[0]; |
83 |
| - $attr = preg_replace( '/author\s*/i', '', $attr ); |
84 |
| - return $attr; |
85 |
| - } |
86 |
| - |
87 |
| - /** |
88 |
| - * Jetpack Only |
89 |
| - */ |
90 |
| - function save_profile_data() { |
91 |
| - global $current_user; |
92 |
| - check_ajax_referer( 'gplus-connect', 'state' ); |
93 |
| - if ( !is_numeric( $_POST['id'] ) ) |
94 |
| - return; |
95 |
| - $connections = get_option( 'gplus_authors', array() ); |
96 |
| - $connections[ $current_user->ID ]['name'] = stripslashes( $_POST['name'] ); |
97 |
| - $connections[ $current_user->ID ]['id'] = $_POST['id']; |
98 |
| - $connections[ $current_user->ID ]['url'] = esc_url_raw( $_POST['url'] ); |
99 |
| - $connections[ $current_user->ID ]['profile_image'] = esc_url_raw( $_POST['profile_image'] ); |
100 |
| - update_option( 'gplus_authors', $connections ); |
101 |
| - } |
102 |
| - |
103 |
| - /** |
104 |
| - * Google+ insits we don't have two different bylines.. |
105 |
| - * so we will display their G+ username in the byline here too |
106 |
| - */ |
107 |
| - function overwrite_the_author( $author_name ) { |
108 |
| - global $post; |
109 |
| - |
110 |
| - if ( !$this->show_on_this_post() ) |
111 |
| - return $author_name; |
112 |
| - |
113 |
| - if ( ! is_main_query() || ! in_the_loop() ) |
114 |
| - return $author_name; |
115 |
| - |
116 |
| - $author = $this->information( $post->post_author ); |
117 |
| - return esc_html( $author['name'] ); |
118 |
| - } |
119 |
| - |
120 |
| - function byline( $post ) { |
121 |
| - $author = $this->information( $post->post_author ); |
122 |
| - $image = '<img src="' . esc_url( $author['profile_image'] ) . '?sz=40" alt="' . esc_attr( $author['name'] ) . '" width="20" height="20" align="absmiddle" /> '; |
123 |
| - $byline = sprintf( '<a href="%1$s">%2$s</a><a rel="author" href="%1$s" class="gplus-profile">%3$s</a>', esc_url( $author['url'] ), $image, esc_html( $author['name'] ) ); |
124 |
| - return apply_filters( 'gplus_authorship_byline', $byline, $post ); |
125 |
| - } |
126 |
| - |
127 |
| - function link_tag_styles_and_scripts() { |
128 |
| - if ( !is_single() ) |
129 |
| - return; |
130 |
| - if ( get_post_type() != 'post' ) |
131 |
| - return; |
132 |
| - if ( !$this->show_on_this_post() ) |
133 |
| - return; |
134 |
| - |
135 |
| - global $post; |
136 |
| - $author = $this->information( $post->post_author ); |
137 |
| - echo '<link rel="author" href="'. esc_url( $author['url'] ) .'" title="' . esc_attr( $author['name'] ) . ' ' . __( 'on Google+', 'jetpack' ) .'" /> ' . "\n"; |
138 |
| - if ( $this->in_jetpack ) |
139 |
| - $css = plugins_url( 'gplus-authorship/style.css', __FILE__ ); |
140 |
| - else |
141 |
| - $css = plugins_url( 'gplus/style.css', __FILE__ ); |
142 |
| - wp_enqueue_style( 'gplus', $css ); |
143 |
| - wp_enqueue_script( 'plusone', '//apis.google.com/js/plusone.js' ); |
144 |
| - } |
145 |
| - |
146 |
| - function follow_button( $post ) { |
147 |
| - $author = $this->information( $post->post_author ); |
148 |
| - return '<span class="g-follow-wrapper"><span class="g-follow" data-href="' . esc_url( $author['url'] ) . '" data-rel="author" data-height="15"></span></span>'; |
149 |
| - } |
150 |
| - |
151 |
| - function post_output_wrapper( $text = '', $echo = false ) { |
152 |
| - global $post, $wp_current_filter; |
153 |
| - if ( true == get_option( 'hide_gplus', false ) ) |
154 |
| - return $text; |
155 |
| - if ( !is_single() ) |
156 |
| - return $text; |
157 |
| - if ( get_post_type() != 'post' ) |
158 |
| - return $text; |
159 |
| - if ( true === $this->byline_displayed ) |
160 |
| - return $text; |
161 |
| - $author = $this->information( $post->post_author ); |
162 |
| - if ( empty( $author ) ) |
163 |
| - return $text; |
164 |
| - |
165 |
| - // Don't allow G+ to be added to the_content more than once (prevent infinite loops) |
166 |
| - $done = false; |
167 |
| - foreach ( $wp_current_filter as $filter ) { |
168 |
| - if ( 'the_content' == $filter ) { |
169 |
| - if ( $done ) |
170 |
| - return $text; |
171 |
| - else |
172 |
| - $done = true; |
173 |
| - } |
174 |
| - } |
175 |
| - |
176 |
| - if ( !$this->show_on_this_post()) |
177 |
| - return $text; |
178 |
| - |
179 |
| - if ( ! is_main_query() || ! in_the_loop() ) |
180 |
| - return $text; |
181 |
| - |
182 |
| - $output = ''; |
183 |
| - $output .= '<div class="sharedaddy sd-block sd-social sd-gplus">'; |
184 |
| - $output .= '<h3 class="sd-title">' . __( 'Google+', 'jetpack' ) . '</h3>'; |
185 |
| - $output .= '<div class="sd-content">'; |
186 |
| - $output .= $this->byline( $post ); |
187 |
| - $output .= $this->follow_button( $post ); |
188 |
| - $output .= '</div>'; |
189 |
| - $output .= '</div>'; |
190 |
| - |
191 |
| - $this->byline_displayed = true; |
192 |
| - |
193 |
| - if ( $echo ) |
194 |
| - echo $text . $output; |
195 |
| - else |
196 |
| - return $text . $output; |
197 |
| - } |
198 |
| - |
199 |
| -} |
200 |
| - |
201 |
| -?> |
| 3 | + * Deprecated. No longer needed. |
| 4 | + * |
| 5 | + * @package Jetpack |
| 6 | + */ |
0 commit comments