|
1 <?php |
|
2 /** |
|
3 * @package All-in-One-SEO-Pack |
|
4 */ |
|
5 |
|
6 /** Ajax callback functions for quickedit functionality */ |
|
7 //add_action( 'wp_ajax_aioseop_ajax_save_meta', 'aioseop_ajax_save_meta'); |
|
8 |
|
9 if (!function_exists('aioseop_activate')) { |
|
10 function aioseop_activate() { |
|
11 global $aiosp_activation; |
|
12 $aiosp_activation = true; |
|
13 } |
|
14 } |
|
15 |
|
16 if (!function_exists('aioseop_update_settings_check')) { |
|
17 function aioseop_update_settings_check() { |
|
18 if(isset($_POST['aioseop_migrate'])) aioseop_mrt_fix_meta(); |
|
19 if ( ( isset( $_POST['aioseop_migrate_options'] ) ) || |
|
20 ( !get_option( 'aiosp_post_title_format' ) && !get_option('aioseop_options') ) ) { |
|
21 aioseop_mrt_mkarry(); |
|
22 } |
|
23 } |
|
24 } |
|
25 |
|
26 if (!function_exists('aioseop_class_defined_error')) { |
|
27 function aioseop_class_defined_error() { |
|
28 $aioseop_class_error = "The All in One SEO Pack class is already defined"; |
|
29 if ( class_exists( 'ReflectionClass' ) ) { |
|
30 $r = new ReflectionClass( 'All_in_One_SEO_Pack' ); |
|
31 $aioseop_class_error .= " in " . $r->getFileName(); |
|
32 } |
|
33 $aioseop_class_error .= ", preventing All in One SEO Pack from loading."; |
|
34 echo "<div class='error'>$aioseop_class_error</div>"; |
|
35 } |
|
36 } |
|
37 |
|
38 if (!function_exists('aioseop_mrt_fix_meta')) { |
|
39 function aioseop_mrt_fix_meta(){ |
|
40 global $wpdb, $aiosp_activation; |
|
41 $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_aioseop_keywords' WHERE meta_key = 'keywords'"); |
|
42 $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_aioseop_title' WHERE meta_key = 'title'"); |
|
43 $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_aioseop_description' WHERE meta_key = 'description'"); |
|
44 $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_aioseop_meta' WHERE meta_key = 'aiosp_meta'"); |
|
45 $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_aioseop_disable' WHERE meta_key = 'aiosp_disable'"); |
|
46 if ( !$aiosp_activation ) // don't echo on initial plugin activation |
|
47 echo "<div class='updated fade' style='background-color:green;border-color:green;'><p><strong>" . __( "Updating SEO post meta in database.", 'all_in_one_seo_pack' ) . "</strong></p></div>"; |
|
48 } |
|
49 } |
|
50 |
|
51 if (!function_exists('aioseop_mrt_mkarry')) { |
|
52 function aioseop_mrt_mkarry() { |
|
53 global $aiosp; |
|
54 $naioseop_options = array( |
|
55 "aiosp_can"=>1, |
|
56 "aiosp_donate"=>0, |
|
57 "aiosp_home_title"=>null, |
|
58 "aiosp_home_description"=>'', |
|
59 "aiosp_home_keywords"=>null, |
|
60 "aiosp_max_words_excerpt"=>'something', |
|
61 "aiosp_rewrite_titles"=>1, |
|
62 "aiosp_post_title_format"=>'%post_title% | %blog_title%', |
|
63 "aiosp_page_title_format"=>'%page_title% | %blog_title%', |
|
64 "aiosp_category_title_format"=>'%category_title% | %blog_title%', |
|
65 "aiosp_archive_title_format"=>'%date% | %blog_title%', |
|
66 "aiosp_tag_title_format"=>'%tag% | %blog_title%', |
|
67 "aiosp_search_title_format"=>'%search% | %blog_title%', |
|
68 "aiosp_description_format"=>'%description%', |
|
69 "aiosp_404_title_format"=>'Nothing found for %request_words%', |
|
70 "aiosp_paged_format"=>' - Part %page%', |
|
71 "aiosp_google_analytics_id"=>null, |
|
72 "aiosp_ga_track_outbound_links"=>0, |
|
73 "aiosp_use_categories"=>0, |
|
74 "aiosp_dynamic_postspage_keywords"=>1, |
|
75 "aiosp_category_noindex"=>0, |
|
76 "aiosp_archive_noindex"=>0, |
|
77 "aiosp_tags_noindex"=>0, |
|
78 "aiosp_cap_cats"=>1, |
|
79 "aiosp_generate_descriptions"=>0, |
|
80 "aiosp_debug_info"=>null, |
|
81 "aiosp_post_meta_tags"=>'', |
|
82 "aiosp_page_meta_tags"=>'', |
|
83 "aiosp_home_meta_tags"=>'', |
|
84 "aiosp_enabled" =>0, |
|
85 "aiosp_enablecpost" => 0, |
|
86 "aiosp_use_tags_as_keywords" =>1, |
|
87 "aiosp_seopostcol" =>1, |
|
88 "aiosp_seocustptcol" => 0, |
|
89 "aiosp_posttypecolumns" => array('post','page'), |
|
90 "aiosp_do_log"=>null); |
|
91 |
|
92 if(get_option('aiosp_post_title_format')){ |
|
93 foreach( $naioseop_options as $aioseop_opt_name => $value ) { |
|
94 if( $aioseop_oldval = get_option($aioseop_opt_name) ) { |
|
95 $naioseop_options[$aioseop_opt_name] = $aioseop_oldval; |
|
96 } |
|
97 if( $aioseop_oldval == '') { |
|
98 $naioseop_options[$aioseop_opt_name] = ''; |
|
99 } |
|
100 delete_option($aioseop_opt_name); |
|
101 } |
|
102 } |
|
103 |
|
104 add_option('aioseop_options',$naioseop_options); |
|
105 } |
|
106 } |
|
107 |
|
108 if (!function_exists('aioseop_activation_notice')) { |
|
109 function aioseop_activation_notice() { |
|
110 global $aioseop_options; |
|
111 echo '<div class="error fade"><p><strong>' . __('All in One SEO Pack must be configured.', 'all_in_one_seo_pack' ) |
|
112 . ' ' . sprintf( __('Go to %s to enable and configure the plugin.', 'all_in_one_seo_pack' ), '<a href="' |
|
113 . admin_url( 'options-general.php?page=' . AIOSEOP_PLUGIN_DIRNAME . '/aioseop.class.php' ) . '">' |
|
114 . __('the admin page', 'all_in_one_seo_pack') . '</a>' ) . '</strong><br />' |
|
115 . __( 'All in One SEO Pack now supports Custom Post Types and Google Analytics.', 'all_in_one_seo_pack' ) . '</p></div>'; |
|
116 } |
|
117 } |
|
118 |
|
119 if (!function_exists('aioseop_activate_pl')) { |
|
120 function aioseop_activate_pl(){ |
|
121 if(get_option('aioseop_options')){ |
|
122 $aioseop_options = get_option('aioseop_options'); |
|
123 $aioseop_options['aiosp_enabled'] = "0"; |
|
124 |
|
125 if(!$aioseop_options['aiosp_posttypecolumns']){ |
|
126 $aioseop_options['aiosp_posttypecolumns'] = array('post','page'); |
|
127 } |
|
128 |
|
129 update_option('aioseop_options',$aioseop_options); |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 if (!function_exists('aioseop_get_version')) { |
|
135 function aioseop_get_version(){ |
|
136 return AIOSEOP_VERSION; |
|
137 } |
|
138 } |
|
139 |
|
140 if (!function_exists('aioseop_add_plugin_row')) { |
|
141 function aioseop_add_plugin_row($links, $file) { |
|
142 echo '<td colspan="5" style="background-color:yellow;">'; |
|
143 echo wp_remote_fopen('http://aioseoppro.semperfiwebdesign.com/'); |
|
144 echo '</td>'; |
|
145 } |
|
146 } |
|
147 |
|
148 if (!function_exists('aioseop_option_isset')) { |
|
149 function aioseop_option_isset( $option ) { |
|
150 global $aioseop_options; |
|
151 return ( ( isset( $aioseop_options[$option] ) ) && $aioseop_options[$option] ); |
|
152 } |
|
153 } |
|
154 |
|
155 if (!function_exists('aioseop_addmycolumns')) { |
|
156 function aioseop_addmycolumns(){ |
|
157 $aioseop_options = get_option('aioseop_options'); |
|
158 $aiosp_posttypecolumns = $aioseop_options['aiosp_posttypecolumns']; |
|
159 |
|
160 if ( !isset($_GET['post_type']) ) |
|
161 $post_type = 'post'; |
|
162 else $post_type = $_GET['post_type']; |
|
163 add_action( 'admin_head', 'aioseop_admin_head'); |
|
164 |
|
165 if(is_array($aiosp_posttypecolumns) && in_array($post_type,$aiosp_posttypecolumns)) { |
|
166 if($post_type == 'page'){ |
|
167 add_action('manage_pages_custom_column', 'aioseop_mrt_pccolumn', 10, 2); |
|
168 add_filter('manage_pages_columns', 'aioseop_mrt_pcolumns'); |
|
169 } else { |
|
170 add_action('manage_posts_custom_column', 'aioseop_mrt_pccolumn', 10, 2); |
|
171 add_filter('manage_posts_columns', 'aioseop_mrt_pcolumns'); |
|
172 } |
|
173 } |
|
174 } |
|
175 } |
|
176 |
|
177 if (!function_exists('aioseop_mrt_pcolumns')) { |
|
178 function aioseop_mrt_pcolumns($aioseopc) { |
|
179 global $aioseop_options; |
|
180 $aioseopc['seotitle'] = __('SEO Title'); |
|
181 $aioseopc['seokeywords'] = __('SEO Keywords'); |
|
182 $aioseopc['seodesc'] = __('SEO Description'); |
|
183 return $aioseopc; |
|
184 } |
|
185 } |
|
186 |
|
187 if (!function_exists('aioseop_admin_head')) { |
|
188 function aioseop_admin_head() { |
|
189 // echo '<script type="text/javascript" src="' . AIOSEOP_PLUGIN_URL . 'quickedit_functions.js" ></script>'; |
|
190 ?><style> |
|
191 .aioseop_edit_button { |
|
192 margin: 0 0 0 5px; |
|
193 opacity: 0.6; |
|
194 width: 12px; |
|
195 } |
|
196 .aioseop_mpc_SEO_admin_options_edit img { |
|
197 margin: 3px 2px; |
|
198 opacity: 0.7; |
|
199 } |
|
200 .aioseop_mpc_admin_meta_options { |
|
201 float: left; |
|
202 display: block; |
|
203 opacity: 1; |
|
204 } |
|
205 .aioseop_mpc_admin_meta_content { |
|
206 float:left; |
|
207 width: 100%; |
|
208 margin: 0 0 10px 0; |
|
209 } |
|
210 </style> |
|
211 <?php wp_print_scripts( Array( 'sack' ) ); |
|
212 ?><script type="text/javascript"> |
|
213 //<![CDATA[ |
|
214 var aioseopadmin = { |
|
215 blogUrl: "<?php print get_bloginfo( 'url'); ?>", |
|
216 pluginPath: "<?php print AIOSEOP_PLUGIN_DIR; ?>", |
|
217 pluginUrl: "<?php print AIOSEOP_PLUGIN_URL; ?>", |
|
218 requestUrl: "<?php print WP_ADMIN_URL . '/admin-ajax.php' ?>", |
|
219 imgUrl: "<?php print AIOSEOP_PLUGIN_IMAGES_URL; ?>", |
|
220 Edit: "Edit", Post: "Post", Save: "Save", Cancel: "Cancel", postType: "post", |
|
221 pleaseWait: "Please wait...", slugEmpty: "Slug may not be empty!", |
|
222 Revisions: "Post Revisions", Time: "Insert time" |
|
223 } |
|
224 //]]> |
|
225 </script> |
|
226 <?php |
|
227 } |
|
228 } |
|
229 |
|
230 if (!function_exists('aioseop_ajax_save_meta')) { |
|
231 function aioseop_ajax_save_meta() { |
|
232 $post_id = intval( $_POST['post_id'] ); |
|
233 $new_meta = $_POST['new_meta']; |
|
234 $target = $_POST['target_meta']; |
|
235 update_post_meta( $post_id, '_aioseop_' . $target, $new_meta ); |
|
236 $result = get_post_meta( $post_id, '_aioseop_' . $target, true ); |
|
237 if( $result != '' ): $label = $result; |
|
238 else: $label = ''; $result = '<strong><i>No ' . $target . '</i></strong>' ; endif; |
|
239 $output = $result . '<a id="' . $target . 'editlink' . $post_id . '" href="javascript:void(0);"'; |
|
240 $output .= 'onclick="aioseop_ajax_edit_meta_form(' . $post_id . ', \'' . $label . '\', \'' . $target . '\');return false;" title="' . __('Edit') . '">'; |
|
241 $output .= '<img class="aioseop_edit_button" id="aioseop_edit_id" src="' . AIOSEOP_PLUGIN_IMAGES_URL . '/cog_edit.png" /></a>'; |
|
242 die( "jQuery('div#aioseop_" . $target . "_" . $post_id . "').fadeOut('fast', function() { |
|
243 jQuery('div#aioseop_" . $target . "_" . $post_id . "').html('" . addslashes_gpc($output) . "').fadeIn('fast'); |
|
244 });" ); |
|
245 } |
|
246 } |
|
247 |
|
248 if (!function_exists('aioseop_mrt_pccolumn')) { |
|
249 function aioseop_mrt_pccolumn($aioseopcn, $aioseoppi) { |
|
250 if( $aioseopcn == 'seotitle' ) { |
|
251 echo htmlspecialchars(stripcslashes(get_post_meta($aioseoppi,'_aioseop_title',TRUE))); |
|
252 } |
|
253 if( $aioseopcn == 'seokeywords' ) { |
|
254 echo htmlspecialchars(stripcslashes(get_post_meta($aioseoppi,'_aioseop_keywords',TRUE))); |
|
255 } |
|
256 if( $aioseopcn == 'seodesc' ) { |
|
257 echo htmlspecialchars(stripcslashes(get_post_meta($aioseoppi,'_aioseop_description',TRUE))); |
|
258 } |
|
259 } |
|
260 } |
|
261 |
|
262 if ( !function_exists( 'aioseop_unprotect_meta' ) ) { |
|
263 function aioseop_unprotect_meta( $protected, $meta_key, $meta_type ) { |
|
264 if ( isset( $meta_key ) && ( substr( $meta_key, 0, 9 ) === '_aioseop_' ) ) return false; |
|
265 return $protected; |
|
266 } |
|
267 } |
|
268 |
|
269 if (!function_exists('aioseop_get_pages_start')) { |
|
270 function aioseop_get_pages_start($excludes) { |
|
271 global $aioseop_get_pages_start; |
|
272 $aioseop_get_pages_start = 1; |
|
273 return $excludes; |
|
274 } |
|
275 } |
|
276 |
|
277 if (!function_exists('aioseop_get_pages')) { |
|
278 function aioseop_get_pages($pages) { |
|
279 global $aioseop_get_pages_start; |
|
280 if (!$aioseop_get_pages_start) return $pages; |
|
281 foreach ($pages as $k => $v) { |
|
282 $postID = $v->ID; |
|
283 $menulabel = stripslashes(get_post_meta($postID, '_aioseop_menulabel', true)); |
|
284 if ($menulabel) $pages[$k]->post_title = $menulabel; |
|
285 } |
|
286 $aioseop_get_pages_start = 0; |
|
287 return $pages; |
|
288 } |
|
289 } |
|
290 |
|
291 // The following two functions are GPLed from Sarah G's Page Menu Editor, http://wordpress.org/extend/plugins/page-menu-editor/. |
|
292 if (!function_exists('aioseop_list_pages')) { |
|
293 function aioseop_list_pages( $content ) { |
|
294 global $wp_version; |
|
295 $matches = array(); |
|
296 if ( preg_match_all( '/<li class="page_item page-item-(\d+)/i', $content, $matches ) ) { |
|
297 update_postmeta_cache( array_values( $matches[1] ) ); |
|
298 unset( $matches ); |
|
299 if ( $wp_version >= 3.3 ) { |
|
300 $pattern = '@<li class="page_item page-item-(\d+)([^\"]*)"><a href=\"([^\"]+)">@is'; |
|
301 } else { |
|
302 $pattern = '@<li class="page_item page-item-(\d+)([^\"]*)"><a href=\"([^\"]+)" title="([^\"]+)">@is'; |
|
303 } |
|
304 return preg_replace_callback( $pattern, "aioseop_filter_callback", $content ); |
|
305 } |
|
306 return $content; |
|
307 } |
|
308 } |
|
309 |
|
310 if (!function_exists('aioseop_filter_callback')) { |
|
311 function aioseop_filter_callback( $matches ) { |
|
312 global $wpdb; |
|
313 if ( $matches[1] && !empty( $matches[1] ) ) $postID = $matches[1]; |
|
314 if ( empty( $postID ) ) $postID = get_option( "page_on_front" ); |
|
315 $title_attrib = stripslashes( get_post_meta($postID, '_aioseop_titleatr', true ) ); |
|
316 if ( empty( $title_attrib ) && !empty( $matches[4] ) ) $title_attrib = $matches[4]; |
|
317 if ( !empty( $title_attrib ) ) $title_attrib = ' title="' . strip_tags( $title_attrib ) . '"'; |
|
318 return '<li class="page_item page-item-'.$postID.$matches[2].'"><a href="'.$matches[3].'"'.$title_attrib.'>'; |
|
319 } |
|
320 } |
|
321 |
|
322 if ( !function_exists('aioseop_add_contactmethods' ) ) { |
|
323 function aioseop_add_contactmethods( $contactmethods ) { |
|
324 $contactmethods['googleplus'] = 'Google+'; |
|
325 return $contactmethods; |
|
326 } |
|
327 } |
|
328 |
|
329 if (!function_exists('aioseop_meta_box_add')) { |
|
330 function aioseop_meta_box_add() { |
|
331 $mrt_aioseop_pts=get_post_types('','names'); |
|
332 $aioseop_options = get_option('aioseop_options'); |
|
333 $aioseop_mrt_cpt = $aioseop_options['aiosp_enablecpost']; |
|
334 foreach ($mrt_aioseop_pts as $mrt_aioseop_pt) { |
|
335 if($mrt_aioseop_pt == 'post' || $mrt_aioseop_pt == 'page' || $aioseop_mrt_cpt){ |
|
336 add_meta_box('aiosp',__('All in One SEO Pack', 'all_in_one_seo_pack'),'aiosp_meta',$mrt_aioseop_pt); |
|
337 } |
|
338 } |
|
339 } |
|
340 } |
|
341 |
|
342 if (!function_exists('aiosp_meta')) { |
|
343 function aiosp_meta() { |
|
344 global $post; |
|
345 $post_id = $post; |
|
346 if (is_object($post_id)) $post_id = $post_id->ID; |
|
347 $keywords = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_keywords', true))); |
|
348 $title = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_title', true))); |
|
349 $description = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_description', true))); |
|
350 $aiosp_meta = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aiosp_meta', true))); |
|
351 $aiosp_disable = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_disable', true))); |
|
352 $aiosp_titleatr = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_titleatr', true))); |
|
353 $aiosp_menulabel = htmlspecialchars(stripcslashes(get_post_meta($post_id, '_aioseop_menulabel', true))); |
|
354 ?> |
|
355 <SCRIPT LANGUAGE="JavaScript"> |
|
356 <!-- Begin |
|
357 function countChars(field,cntfield) { |
|
358 cntfield.value = field.value.length; |
|
359 } |
|
360 // End --> |
|
361 </script> |
|
362 <input value="aiosp_edit" type="hidden" name="aiosp_edit" /> |
|
363 |
|
364 <a target="__blank" href="http://semperplugins.com/plugins/all-in-one-seo-pack-pro-version/"><?php _e('Upgrade to All in One SEO Pack Pro Version', 'all_in_one_seo_pack') ?></a> |
|
365 <table style="margin-bottom:40px"> |
|
366 <tr> |
|
367 <th style="text-align:left;" colspan="2"> |
|
368 </th> |
|
369 </tr> |
|
370 |
|
371 <tr> |
|
372 <th scope="row" style="text-align:right;"><?php _e('Title:', 'all_in_one_seo_pack') ?></th> |
|
373 <td><input value="<?php echo $title ?>" type="text" name="aiosp_title" size="62" onKeyDown="countChars(document.post.aiosp_title,document.post.lengthT)" onKeyUp="countChars(document.post.aiosp_title,document.post.lengthT)"/><br /> |
|
374 <input readonly type="text" name="lengthT" size="3" maxlength="3" style="text-align:center;" value="<?php echo strlen($title);?>" /> |
|
375 <?php _e(' characters. Most search engines use a maximum of 60 chars for the title.', 'all_in_one_seo_pack') ?> |
|
376 </td> |
|
377 </tr> |
|
378 |
|
379 <tr> |
|
380 <th scope="row" style="text-align:right;"><?php _e('Description:', 'all_in_one_seo_pack') ?></th> |
|
381 <td><textarea name="aiosp_description" rows="3" cols="60" |
|
382 onKeyDown="countChars(document.post.aiosp_description,document.post.length1)" |
|
383 onKeyUp="countChars(document.post.aiosp_description,document.post.length1)"><?php echo $description ?></textarea><br /> |
|
384 <input readonly type="text" name="length1" size="3" maxlength="3" value="<?php echo strlen($description);?>" /> |
|
385 <?php _e(' characters. Most search engines use a maximum of 160 chars for the description.', 'all_in_one_seo_pack') ?> |
|
386 </td> |
|
387 </tr> |
|
388 |
|
389 <tr> |
|
390 <th scope="row" style="text-align:right;"><?php _e('Keywords (comma separated):', 'all_in_one_seo_pack') ?></th> |
|
391 <td><input value="<?php echo $keywords ?>" type="text" name="aiosp_keywords" size="62"/></td> |
|
392 </tr> |
|
393 <input type="hidden" name="nonce-aioseop-edit" value="<?php echo wp_create_nonce('edit-aioseop-nonce') ?>" /> |
|
394 <?php if($post->post_type=='page'){ ?> |
|
395 <tr> |
|
396 <th scope="row" style="text-align:right;"><?php _e('Title Attribute:', 'all_in_one_seo_pack') ?></th> |
|
397 <td><input value="<?php echo $aiosp_titleatr ?>" type="text" name="aiosp_titleatr" size="62"/></td> |
|
398 </tr> |
|
399 |
|
400 <tr> |
|
401 <th scope="row" style="text-align:right;"><?php _e('Menu Label:', 'all_in_one_seo_pack') ?></th> |
|
402 <td><input value="<?php echo $aiosp_menulabel ?>" type="text" name="aiosp_menulabel" size="62"/></td> |
|
403 </tr> |
|
404 <?php } ?> |
|
405 <tr> |
|
406 <th scope="row" style="text-align:right; vertical-align:top;"> |
|
407 <?php _e('Disable on this page/post:', 'all_in_one_seo_pack')?> |
|
408 </th> |
|
409 <td> |
|
410 <input type="checkbox" name="aiosp_disable" <?php if ($aiosp_disable) echo "checked=\"1\""; ?>/> |
|
411 </td> |
|
412 </tr> |
|
413 </table> |
|
414 <?php |
|
415 } |
|
416 } |