/inc/aioseop_functions.php

  1. <?php 
  2. /** 
  3. * General functions file. 
  4. * 
  5. * We'll eventually move these to a better place, and figure out ones not being used anymore. 
  6. * 
  7. * @package All-in-One-SEO-Pack 
  8. */ 
  9.  
  10. if ( ! function_exists( 'aioseop_load_modules' ) ) { 
  11. /** 
  12. * Load the module manager. 
  13. */ 
  14. function aioseop_load_modules() { 
  15. global $aioseop_modules, $aioseop_module_list; 
  16. require_once( AIOSEOP_PLUGIN_DIR . 'admin/aioseop_module_manager.php' ); 
  17. $aioseop_modules = new All_in_One_SEO_Pack_Module_Manager( apply_filters( 'aioseop_module_list', $aioseop_module_list ) ); 
  18. $aioseop_modules->load_modules(); 
  19.  
  20. if ( ! function_exists( 'aioseop_get_options' ) ) { 
  21. /** 
  22. * @return mixed|void 
  23. */ 
  24. function aioseop_get_options() { 
  25. global $aioseop_options; 
  26. $aioseop_options = get_option( 'aioseop_options' ); 
  27. $aioseop_options = apply_filters( 'aioseop_get_options', $aioseop_options ); 
  28.  
  29. return $aioseop_options; 
  30.  
  31. if ( ! function_exists( 'aioseop_update_settings_check' ) ) { 
  32. /** 
  33. * Check if settings need to be updated / migrated from old version. 
  34. * 
  35. * @TODO See when this is from and if we can move it elsewhere... our new db updates/upgrades class? 
  36. */ 
  37. function aioseop_update_settings_check() { 
  38. global $aioseop_options; 
  39. if ( empty( $aioseop_options ) || isset( $_POST['aioseop_migrate_options'] ) ) { 
  40. aioseop_mrt_mkarry(); 
  41. // WPML has now attached to filters, read settings again so they can be translated. 
  42. aioseop_get_options(); 
  43. $update_options = false; 
  44. if ( ! empty( $aioseop_options ) ) { 
  45. if ( ! empty( $aioseop_options['aiosp_archive_noindex'] ) ) { // Migrate setting for noindex archives. 
  46. $aioseop_options['aiosp_archive_date_noindex'] = $aioseop_options['aiosp_archive_author_noindex'] = $aioseop_options['aiosp_archive_noindex']; 
  47. unset( $aioseop_options['aiosp_archive_noindex'] ); 
  48. $update_options = true; 
  49. if ( ! empty( $aioseop_options['aiosp_archive_title_format'] ) && empty( $aioseop_options['aiosp_date_title_format'] ) ) { 
  50. $aioseop_options['aiosp_date_title_format'] = $aioseop_options['aiosp_archive_title_format']; 
  51. unset( $aioseop_options['aiosp_archive_title_format'] ); 
  52. $update_options = true; 
  53. if ( ! empty( $aioseop_options['aiosp_archive_title_format'] ) && ( $aioseop_options['aiosp_archive_title_format'] === '%date% | %blog_title%' ) ) { 
  54. $aioseop_options['aiosp_archive_title_format'] = '%archive_title% | %blog_title%'; 
  55. $update_options = true; 
  56. if ( $update_options ) { 
  57. update_option( 'aioseop_options', $aioseop_options ); 
  58.  
  59. if ( ! function_exists( 'aioseop_mrt_mkarry' ) ) { 
  60. /** 
  61. * Initialize settings to defaults. 
  62. * 
  63. * @TODO Should also move. 
  64. */ 
  65. function aioseop_mrt_mkarry() { 
  66. global $aiosp; 
  67. global $aioseop_options; 
  68. $naioseop_options = $aiosp->default_options(); 
  69.  
  70. if ( get_option( 'aiosp_post_title_format' ) ) { 
  71. foreach ( $naioseop_options as $aioseop_opt_name => $value ) { 
  72. if ( $aioseop_oldval = get_option( $aioseop_opt_name ) ) { 
  73. $naioseop_options[ $aioseop_opt_name ] = $aioseop_oldval; 
  74. if ( $aioseop_oldval == '' ) { 
  75. $naioseop_options[ $aioseop_opt_name ] = ''; 
  76. delete_option( $aioseop_opt_name ); 
  77. add_option( 'aioseop_options', $naioseop_options ); 
  78. $aioseop_options = $naioseop_options; 
  79.  
  80. if ( ! function_exists( 'aioseop_activate_pl' ) ) { 
  81. /** 
  82. * @TODO see if this still gets used. 
  83. */ 
  84. function aioseop_activate_pl() { 
  85. if ( $aioseop_options = get_option( 'aioseop_options' ) ) { 
  86. $aioseop_options['aiosp_enabled'] = '0'; 
  87.  
  88. if ( empty( $aioseop_options['aiosp_posttypecolumns'] ) ) { 
  89. $aioseop_options['aiosp_posttypecolumns'] = array( 'post', 'page' ); 
  90.  
  91. update_option( 'aioseop_options', $aioseop_options ); 
  92.  
  93. if ( ! function_exists( 'aioseop_get_version' ) ) { 
  94. /** 
  95. * Returns the version. 
  96. * 
  97. * I'm not sure why we have BOTH a function and a constant for this. -mrt 
  98. * 
  99. * @return string 
  100. */ 
  101. function aioseop_get_version() { 
  102. return AIOSEOP_VERSION; 
  103.  
  104. if ( ! function_exists( 'aioseop_option_isset' ) ) { 
  105. /** 
  106. * Checks if an option isset. 
  107. * 
  108. * @param $option 
  109. * 
  110. * @return bool 
  111. */ 
  112. function aioseop_option_isset( $option ) { 
  113. global $aioseop_options; 
  114.  
  115. return ( isset( $aioseop_options[ $option ] ) && $aioseop_options[ $option ] ); 
  116.  
  117. if ( ! function_exists( 'aioseop_addmycolumns' ) ) { 
  118. /** 
  119. * Adds posttype columns. 
  120. * 
  121. * @TODO We should see if this is still being used, and move it either way. 
  122. */ 
  123. function aioseop_addmycolumns() { 
  124. global $aioseop_options, $pagenow; 
  125. $aiosp_posttypecolumns = Array(); 
  126. if ( ! empty( $aioseop_options ) && ! empty( $aioseop_options['aiosp_posttypecolumns'] ) ) { 
  127. $aiosp_posttypecolumns = $aioseop_options['aiosp_posttypecolumns']; 
  128. if ( ! empty( $pagenow ) && ( $pagenow === 'upload.php' ) ) { 
  129. $post_type = 'attachment'; 
  130. } elseif ( ! isset( $_REQUEST['post_type'] ) ) { 
  131. $post_type = 'post'; 
  132. } else { 
  133. $post_type = $_REQUEST['post_type']; 
  134.  
  135. if ( is_array( $aiosp_posttypecolumns ) && in_array( $post_type, $aiosp_posttypecolumns ) ) { 
  136. add_action( 'admin_head', 'aioseop_admin_head' ); 
  137. if ( $post_type === 'page' ) { 
  138. add_filter( 'manage_pages_columns', 'aioseop_mrt_pcolumns' ); 
  139. } elseif ( $post_type === 'attachment' ) { 
  140. add_filter( 'manage_media_columns', 'aioseop_mrt_pcolumns' ); 
  141. } else { 
  142. add_filter( 'manage_posts_columns', 'aioseop_mrt_pcolumns' ); 
  143. if ( $post_type === 'attachment' ) { 
  144. add_action( 'manage_media_custom_column', 'aioseop_mrt_pccolumn', 10, 2 ); 
  145. } elseif ( is_post_type_hierarchical( $post_type ) ) { 
  146. add_action( 'manage_pages_custom_column', 'aioseop_mrt_pccolumn', 10, 2 ); 
  147. } else { 
  148. add_action( 'manage_posts_custom_column', 'aioseop_mrt_pccolumn', 10, 2 ); 
  149.  
  150. if ( ! function_exists( 'aioseop_mrt_pcolumns' ) ) { 
  151.  
  152. /** 
  153. * @param $aioseopc 
  154. * 
  155. * @return mixed 
  156. */ 
  157. function aioseop_mrt_pcolumns( $aioseopc ) { 
  158. global $aioseop_options; 
  159. $aioseopc['seotitle'] = __( 'SEO Title', 'all-in-one-seo-pack' ); 
  160. $aioseopc['seodesc'] = __( 'SEO Description', 'all-in-one-seo-pack' ); 
  161. if ( empty( $aioseop_options['aiosp_togglekeywords'] ) ) { 
  162. $aioseopc['seokeywords'] = __( 'SEO Keywords', 'all-in-one-seo-pack' ); 
  163.  
  164. return $aioseopc; 
  165.  
  166. if ( ! function_exists( 'aioseop_admin_head' ) ) { 
  167.  
  168. function aioseop_admin_head() { 
  169. echo '<script type="text/javascript" src="' . AIOSEOP_PLUGIN_URL . 'js/quickedit_functions.js" ></script>'; 
  170. ?> 
  171. <style> 
  172. .aioseop_edit_button { 
  173. margin: 0 0 0 5px; 
  174. opacity: 0.6; 
  175. width: 12px; 
  176.  
  177. .aioseop_edit_link { 
  178. display: inline-block; 
  179. position: absolute; 
  180.  
  181. .aioseop_mpc_SEO_admin_options_edit img { 
  182. margin: 3px 2px; 
  183. opacity: 0.7; 
  184.  
  185. .aioseop_mpc_admin_meta_options { 
  186. float: left; 
  187. display: block; 
  188. opacity: 1; 
  189. max-height: 75px; 
  190. overflow: hidden; 
  191. width: 100%; 
  192.  
  193. .aioseop_mpc_admin_meta_options.editing { 
  194. max-height: initial; 
  195. overflow: visible; 
  196.  
  197. .aioseop_mpc_admin_meta_content { 
  198. float: left; 
  199. width: 100%; 
  200. margin: 0 0 10px 0; 
  201.  
  202. td.seotitle.column-seotitle,  
  203. td.seodesc.column-seodesc,  
  204. td.seokeywords.column-seokeywords { 
  205. overflow: visible; 
  206.  
  207. @media screen and (max-width: 782px) { 
  208. body.wp-admin th.column-seotitle, th.column-seodesc, th.column-seokeywords, td.seotitle.column-seotitle, td.seodesc.column-seodesc, td.seokeywords.column-seokeywords { 
  209. display: none; 
  210. </style> 
  211. <?php wp_print_scripts( Array( 'sack' ) ); 
  212. ?> 
  213. <script type="text/javascript"> 
  214. //<![CDATA[ 
  215. var aioseopadmin = { 
  216. blogUrl: "<?php print get_bloginfo( 'url' ); ?>",  
  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: "<?php _e( 'Edit', 'all-in-one-seo-pack' ); ?>",  
  221. Post: "<?php _e( 'Post', 'all-in-one-seo-pack' ); ?>",  
  222. Save: "<?php _e( 'Save', 'all-in-one-seo-pack' ); ?>",  
  223. Cancel: "<?php _e( 'Cancel', 'all-in-one-seo-pack' ); ?>",  
  224. postType: "post",  
  225. pleaseWait: "<?php _e( 'Please wait...', 'all-in-one-seo-pack' ); ?>",  
  226. slugEmpty: "<?php _e( 'Slug may not be empty!', 'all-in-one-seo-pack' ); ?>",  
  227. Revisions: "<?php _e( 'Revisions', 'all-in-one-seo-pack' ); ?>",  
  228. Time: "<?php _e( 'Insert time', 'all-in-one-seo-pack' ); ?>" 
  229. //]]> 
  230. </script> 
  231. <?php 
  232.  
  233. if ( ! function_exists( 'aioseop_handle_ignore_notice' ) ) { 
  234.  
  235. function aioseop_handle_ignore_notice() { 
  236.  
  237. if ( ! empty( $_GET ) ) { 
  238. global $current_user; 
  239. $user_id = $current_user->ID; 
  240.  
  241. if ( ! empty( $_GET['aioseop_reset_notices'] ) ) { 
  242. delete_user_meta( $user_id, 'aioseop_ignore_notice' ); 
  243. if ( ! empty( $_GET['aioseop_ignore_notice'] ) ) { 
  244. add_user_meta( $user_id, 'aioseop_ignore_notice', $_GET['aioseop_ignore_notice'], false ); 
  245.  
  246. if ( ! function_exists( 'aioseop_output_notice' ) ) { 
  247.  
  248. /** 
  249. * @param $message 
  250. * @param string $id 
  251. * @param string $class 
  252. * 
  253. * @return bool 
  254. */ 
  255. function aioseop_output_notice( $message, $id = '', $class = 'updated fade' ) { 
  256. $class = 'aioseop_notice ' . $class; 
  257. if ( ! empty( $class ) ) { 
  258. $class = ' class="' . esc_attr( $class ) . '"'; 
  259. if ( ! empty( $id ) ) { 
  260. $class .= ' id="' . esc_attr( $id ) . '"'; 
  261. $dismiss = ' '; 
  262. echo "<div{$class}>" . wp_kses_post( $message ) . '<br class=clear /></div>'; 
  263.  
  264. return true; 
  265.  
  266. if ( ! function_exists( 'aioseop_output_dismissable_notice' ) ) { 
  267.  
  268. /** 
  269. * @param $message 
  270. * @param string $id 
  271. * @param string $class 
  272. * 
  273. * @return bool 
  274. */ 
  275. function aioseop_output_dismissable_notice( $message, $id = '', $class = 'updated fade' ) { 
  276. global $current_user; 
  277. if ( ! empty( $current_user ) ) { 
  278. $user_id = $current_user->ID; 
  279. $msgid = md5( $message ); 
  280. $ignore = get_user_meta( $user_id, 'aioseop_ignore_notice' ); 
  281. if ( ! empty( $ignore ) && in_array( $msgid, $ignore ) ) { 
  282. return false; 
  283. global $wp; 
  284. $qa = Array(); 
  285. wp_parse_str( $_SERVER['QUERY_STRING'], $qa ); 
  286. $qa['aioseop_ignore_notice'] = $msgid; 
  287. $url = '?' . build_query( $qa ); 
  288. $message = '<p class=alignleft>' . $message . '</p><p class="alignright"><a class="aioseop_dismiss_link" href="' . $url . '">Dismiss</a></p>'; 
  289.  
  290. return aioseop_output_notice( $message, $id, $class ); 
  291.  
  292. if ( ! function_exists( 'aioseop_ajax_save_meta' ) ) { 
  293.  
  294. function aioseop_ajax_save_meta() { 
  295. if ( ! empty( $_POST['_inline_edit'] ) && ( $_POST['_inline_edit'] !== 'undefined' ) ) { 
  296. check_ajax_referer( 'inlineeditnonce', '_inline_edit' ); 
  297. $post_id = intval( $_POST['post_id'] ); 
  298. $new_meta = strip_tags( $_POST['new_meta'] ); 
  299. $target = $_POST['target_meta']; 
  300. check_ajax_referer( 'aioseop_meta_' . $target . '_' . $post_id, '_nonce' ); 
  301. $result = ''; 
  302. if ( in_array( $target, Array( 
  303. 'title',  
  304. 'description',  
  305. 'keywords',  
  306. ) ) && current_user_can( 'edit_post', $post_id ) 
  307. ) { 
  308. update_post_meta( $post_id, '_aioseop_' . $target, esc_attr( $new_meta ) ); 
  309. $result = get_post_meta( $post_id, '_aioseop_' . $target, true ); 
  310. } else { 
  311. die(); 
  312. if ( $result != '' ): 
  313. $label = "<label id='aioseop_label_{$target}_{$post_id}'><span style='width: 20px;display: inline-block;'></span>" . $result . '</label>'; 
  314. else: 
  315. $label = "<label id='aioseop_label_{$target}_{$post_id}'></label><span style='width: 20px;display: inline-block;'></span><strong><i>" . __( 'No', 'all-in-one-seo-pack' ) . ' ' . $target . '</i></strong>'; 
  316. endif; 
  317. $nonce = wp_create_nonce( "aioseop_meta_{$target}_{$post_id}" ); 
  318. $output = '<a id="' . $target . 'editlink' . $post_id . '" class="aioseop_edit_link" href="javascript:void(0);"' 
  319. . 'onclick=\'aioseop_ajax_edit_meta_form(' . $post_id . ', "' . $target . '", "' . $nonce . '");return false;\' title="' . __( 'Edit' ) . '">' 
  320. . '<img class="aioseop_edit_button" id="aioseop_edit_id" src="' . AIOSEOP_PLUGIN_IMAGES_URL . '/cog_edit.png" /></a> ' . $label; 
  321. die( "jQuery('div#aioseop_" . $target . '_' . $post_id . "').fadeOut('fast', function() { var my_label = " . json_encode( $output ) . "; 
  322. jQuery('div#aioseop_" . $target . '_' . $post_id . "').html(my_label).fadeIn('fast'); 
  323. });" ); 
  324.  
  325. if ( ! function_exists( 'aioseop_ajax_init' ) ) { 
  326.  
  327. function aioseop_ajax_init() { 
  328. if ( ! empty( $_POST ) && ! empty( $_POST['settings'] ) && ( ! empty( $_POST['nonce-aioseop'] ) || ( ! empty( $_POST['nonce-aioseop-edit'] ) ) ) && ! empty( $_POST['options'] ) ) { 
  329. $_POST = stripslashes_deep( $_POST ); 
  330. $settings = esc_attr( $_POST['settings'] ); 
  331. if ( ! defined( 'AIOSEOP_AJAX_MSG_TMPL' ) ) { 
  332. define( 'AIOSEOP_AJAX_MSG_TMPL', "jQuery('div#aiosp_$settings').fadeOut('fast', function() {jQuery('div#aiosp_$settings').html('%s').fadeIn('fast');});" ); 
  333.  
  334. if ( ! wp_verify_nonce( $_POST['nonce-aioseop'], 'aioseop-nonce' ) ) { 
  335. die( sprintf( AIOSEOP_AJAX_MSG_TMPL, __( 'Unauthorized access; try reloading the page.', 'all-in-one-seo-pack' ) ) ); 
  336. } else { 
  337. die( 0 ); 
  338.  
  339. /** 
  340. * @param $return 
  341. * @param $url 
  342. * @param $attr 
  343. * 
  344. * @return mixed 
  345. */ 
  346. function aioseop_embed_handler_html( $return, $url, $attr ) { 
  347. return AIO_ProGeneral::aioseop_embed_handler_html(); 
  348.  
  349. function aioseop_ajax_update_oembed() { 
  350. AIO_ProGeneral::aioseop_ajax_update_oembed(); 
  351.  
  352. if ( ! function_exists( 'aioseop_ajax_save_url' ) ) { 
  353.  
  354. function aioseop_ajax_save_url() { 
  355. aioseop_ajax_init(); 
  356. $options = Array(); 
  357. parse_str( $_POST['options'], $options ); 
  358. foreach ( $options as $k => $v ) { 
  359. $_POST[ $k ] = $v; 
  360. $_POST['action'] = 'aiosp_update_module'; 
  361. global $aiosp, $aioseop_modules; 
  362. aioseop_load_modules(); 
  363. $aiosp->admin_menu(); 
  364. if ( ! empty( $_POST['settings'] ) && ( $_POST['settings'] === 'video_sitemap_addl_pages' ) ) { 
  365. $module = $aioseop_modules->return_module( 'All_in_One_SEO_Pack_Video_Sitemap' ); 
  366. } elseif ( ! empty( $_POST['settings'] ) && ( $_POST['settings'] === 'news_sitemap_addl_pages' ) ) { 
  367. $module = $aioseop_modules->return_module( 'All_in_One_SEO_Pack_News_Sitemap' ); 
  368. } else { 
  369. $module = $aioseop_modules->return_module( 'All_in_One_SEO_Pack_Sitemap' ); 
  370. $_POST['location'] = null; 
  371. $_POST['Submit'] = 'ajax'; 
  372. $module->add_page_hooks(); 
  373. $prefix = $module->get_prefix(); 
  374. $_POST = $module->get_current_options( $_POST, null ); 
  375. $module->handle_settings_updates( null ); 
  376. $options = $module->get_current_options( Array(), null ); 
  377. $output = $module->display_custom_options( '', Array( 
  378. 'name' => $prefix . 'addl_pages',  
  379. 'type' => 'custom',  
  380. 'save' => true,  
  381. 'value' => $options[ $prefix . 'addl_pages' ],  
  382. 'attr' => '',  
  383. ) ); 
  384. $output = str_replace( "'", "\'", $output ); 
  385. $output = str_replace( "\n", '\n', $output ); 
  386. die( sprintf( AIOSEOP_AJAX_MSG_TMPL, $output ) ); 
  387.  
  388. if ( ! function_exists( 'aioseop_ajax_delete_url' ) ) { 
  389.  
  390. function aioseop_ajax_delete_url() { 
  391. aioseop_ajax_init(); 
  392. $options = Array(); 
  393. $options = esc_attr( $_POST['options'] ); 
  394. $_POST['action'] = 'aiosp_update_module'; 
  395. global $aiosp, $aioseop_modules; 
  396. aioseop_load_modules(); 
  397. $aiosp->admin_menu(); 
  398. $module = $aioseop_modules->return_module( 'All_in_One_SEO_Pack_Sitemap' ); 
  399. $_POST['location'] = null; 
  400. $_POST['Submit'] = 'ajax'; 
  401. $module->add_page_hooks(); 
  402. $_POST = (Array) $module->get_current_options( $_POST, null ); 
  403. if ( ! empty( $_POST['aiosp_sitemap_addl_pages'] ) && is_object( $_POST['aiosp_sitemap_addl_pages'] ) ) { 
  404. $_POST['aiosp_sitemap_addl_pages'] = (Array) $_POST['aiosp_sitemap_addl_pages']; 
  405. if ( ! empty( $_POST['aiosp_sitemap_addl_pages'] ) && ( ! empty( $_POST['aiosp_sitemap_addl_pages'][ $options ] ) ) ) { 
  406. unset( $_POST['aiosp_sitemap_addl_pages'][ $options ] ); 
  407. if ( empty( $_POST['aiosp_sitemap_addl_pages'] ) ) { 
  408. $_POST['aiosp_sitemap_addl_pages'] = ''; 
  409. } else { 
  410. $_POST['aiosp_sitemap_addl_pages'] = json_encode( $_POST['aiosp_sitemap_addl_pages'] ); 
  411. $module->handle_settings_updates( null ); 
  412. $options = $module->get_current_options( Array(), null ); 
  413. $output = $module->display_custom_options( '', Array( 
  414. 'name' => 'aiosp_sitemap_addl_pages',  
  415. 'type' => 'custom',  
  416. 'save' => true,  
  417. 'value' => $options['aiosp_sitemap_addl_pages'],  
  418. 'attr' => '',  
  419. ) ); 
  420. $output = str_replace( "'", "\'", $output ); 
  421. $output = str_replace( "\n", '\n', $output ); 
  422. } else { 
  423. $output = sprintf( __( 'Row %s not found; no rows were deleted.', 'all-in-one-seo-pack' ), esc_attr( $options ) ); 
  424. die( sprintf( AIOSEOP_AJAX_MSG_TMPL, $output ) ); 
  425.  
  426. if ( ! function_exists( 'aioseop_ajax_scan_header' ) ) { 
  427.  
  428. function aioseop_ajax_scan_header() { 
  429. $_POST['options'] = 'foo'; 
  430. aioseop_ajax_init(); 
  431. $options = Array(); 
  432. parse_str( $_POST['options'], $options ); 
  433. foreach ( $options as $k => $v ) { 
  434. $_POST[ $k ] = $v; 
  435. $_POST['action'] = 'aiosp_update_module'; 
  436. $_POST['location'] = null; 
  437. $_POST['Submit'] = 'ajax'; 
  438. ob_start(); 
  439. do_action( 'wp' ); 
  440. global $aioseop_modules; 
  441. $module = $aioseop_modules->return_module( 'All_in_One_SEO_Pack_Opengraph' ); 
  442. wp_head(); 
  443. $output = ob_get_clean(); 
  444. global $aiosp; 
  445. $output = $aiosp->html_string_to_array( $output ); 
  446. $meta = ''; 
  447. $metatags = Array( 
  448. 'facebook' => Array( 'name' => 'property', 'value' => 'content' ),  
  449. 'twitter' => Array( 'name' => 'name', 'value' => 'value' ),  
  450. 'google+' => Array( 'name' => 'itemprop', 'value' => 'content' ),  
  451. ); 
  452. $metadata = Array( 
  453. 'facebook' => Array( 
  454. 'title' => 'og:title',  
  455. 'type' => 'og:type',  
  456. 'url' => 'og:url',  
  457. 'thumbnail' => 'og:image',  
  458. 'sitename' => 'og:site_name',  
  459. 'key' => 'fb:admins',  
  460. 'description' => 'og:description',  
  461. ),  
  462. 'google+' => Array( 
  463. 'thumbnail' => 'image',  
  464. 'title' => 'name',  
  465. 'description' => 'description',  
  466. ),  
  467. 'twitter' => Array( 
  468. 'card' => 'twitter:card',  
  469. 'url' => 'twitter:url',  
  470. 'title' => 'twitter:title',  
  471. 'description' => 'twitter:description',  
  472. 'thumbnail' => 'twitter:image',  
  473. ),  
  474. ); 
  475. if ( ! empty( $output ) && ! empty( $output['head'] ) && ! empty( $output['head']['meta'] ) ) { 
  476. foreach ( $output['head']['meta'] as $v ) { 
  477. if ( ! empty( $v['@attributes'] ) ) { 
  478. $m = $v['@attributes']; 
  479. foreach ( $metatags as $type => $tags ) { 
  480. if ( ! empty( $m[ $tags['name'] ] ) && ! empty( $m[ $tags['value'] ] ) ) { 
  481. foreach ( $metadata[ $type ] as $tk => $tv ) { 
  482. if ( $m[ $tags['name'] ] == $tv ) { 
  483. $meta .= "<tr><th style='color:red;'>" . sprintf( __( 'Duplicate %s Meta' ), ucwords( $type ) ) . '</th><td>' . ucwords( $tk ) . "</td><td>{$m[$tags['name']]}</td><td>{$m[$tags['value']]}</td></tr>\n"; 
  484. if ( empty( $meta ) ) { 
  485. $meta = '<span style="color:green;">' . __( 'No duplicate meta tags found.', 'all-in-one-seo-pack' ) . '</span>'; 
  486. } else { 
  487. $meta = "<table cellspacing=0 cellpadding=0 width=80% class='aioseop_table'><tr class='aioseop_table_header'><th>Meta For Site</th><th>Kind of Meta</th><th>Element Name</th><th>Element Value</th></tr>" . $meta . '</table>'; 
  488. $meta .= "<p><div class='aioseop_meta_info'><h3 style='padding:5px;margin-bottom:0px;'>" . __( 'What Does This Mean?', 'all-in-one-seo-pack' ) . "</h3><div style='padding:5px;padding-top:0px;'>" 
  489. . '<p>' . __( 'All in One SEO Pack has detected that a plugin(s) or theme is also outputting social meta tags on your site. You can view this social meta in the source code of your site (check your browser help for instructions on how to view source code).', 'all-in-one-seo-pack' ) 
  490. . '</p><p>' . __( 'You may prefer to use the social meta tags that are being output by the other plugin(s) or theme. If so, then you should deactivate this Social Meta feature in All in One SEO Pack Feature Manager.', 'all-in-one-seo-pack' ) 
  491. . '</p><p>' . __( 'You should avoid duplicate social meta tags. You can use these free tools from Facebook, Google and Twitter to validate your social meta and check for errors:', 'all-in-one-seo-pack' ) . '</p>'; 
  492.  
  493. foreach ( 
  494. Array( 
  495. 'https://developers.facebook.com/tools/debug',  
  496. 'http://www.google.com/webmasters/tools/richsnippets',  
  497. 'https://dev.twitter.com/docs/cards/validation/validator',  
  498. ) as $link 
  499. ) { 
  500. $meta .= "<a href='{$link}' target='_blank'>{$link}</a><br />"; 
  501. $meta .= '<p>' . __( 'Please refer to the document for each tool for help in using these to debug your social meta.', 'all-in-one-seo-pack' ) . '</div></div>'; 
  502. $output = $meta; 
  503. $output = str_replace( "'", "\'", $output ); 
  504. $output = str_replace( "\n", '\n', $output ); 
  505. die( sprintf( AIOSEOP_AJAX_MSG_TMPL, $output ) ); 
  506.  
  507. if ( ! function_exists( 'aioseop_ajax_save_settings' ) ) { 
  508.  
  509. function aioseop_ajax_save_settings() { 
  510. aioseop_ajax_init(); 
  511. $options = Array(); 
  512. parse_str( $_POST['options'], $options ); 
  513. $_POST = $options; 
  514. $_POST['action'] = 'aiosp_update_module'; 
  515. global $aiosp, $aioseop_modules; 
  516. aioseop_load_modules(); 
  517. $aiosp->admin_menu(); 
  518. $module = $aioseop_modules->return_module( $_POST['module'] ); 
  519. unset( $_POST['module'] ); 
  520. if ( empty( $_POST['location'] ) ) { 
  521. $_POST['location'] = null; 
  522. $_POST['Submit'] = 'ajax'; 
  523. $module->add_page_hooks(); 
  524. $output = $module->handle_settings_updates( $_POST['location'] ); 
  525.  
  526. if ( AIOSEOPPRO ) { 
  527. $output = '<div id="aioseop_settings_header"><div id="message" class="updated fade"><p>' . $output . '</p></div></div><style>body.all-in-one-seo_page_all-in-one-seo-pack-pro-aioseop_feature_manager .aioseop_settings_left { margin-top: 45px !important; }</style>'; 
  528. } else { 
  529. $output = '<div id="aioseop_settings_header"><div id="message" class="updated fade"><p>' . $output . '</p></div></div><style>body.all-in-one-seo_page_all-in-one-seo-pack-aioseop_feature_manager .aioseop_settings_left { margin-top: 45px !important; }</style>'; 
  530.  
  531. die( sprintf( AIOSEOP_AJAX_MSG_TMPL, $output ) ); 
  532.  
  533. if ( ! function_exists( 'aioseop_ajax_get_menu_links' ) ) { 
  534.  
  535. function aioseop_ajax_get_menu_links() { 
  536. aioseop_ajax_init(); 
  537. $options = Array(); 
  538. parse_str( $_POST['options'], $options ); 
  539. $_POST = $options; 
  540. $_POST['action'] = 'aiosp_update_module'; 
  541. global $aiosp, $aioseop_modules; 
  542. aioseop_load_modules(); 
  543. $aiosp->admin_menu(); 
  544. if ( empty( $_POST['location'] ) ) { 
  545. $_POST['location'] = null; 
  546. $_POST['Submit'] = 'ajax'; 
  547. $modlist = $aioseop_modules->get_loaded_module_list(); 
  548. $links = Array(); 
  549. $link_list = Array(); 
  550. $link = $aiosp->get_admin_links(); 
  551. if ( ! empty( $link ) ) { 
  552. foreach ( $link as $l ) { 
  553. if ( ! empty( $l ) ) { 
  554. if ( empty( $link_list[ $l['order'] ] ) ) { 
  555. $link_list[ $l['order'] ] = Array(); 
  556. $link_list[ $l['order'] ][ $l['title'] ] = $l['href']; 
  557. if ( ! empty( $modlist ) ) { 
  558. foreach ( $modlist as $k => $v ) { 
  559. $mod = $aioseop_modules->return_module( $v ); 
  560. if ( is_object( $mod ) ) { 
  561. $mod->add_page_hooks(); 
  562. $link = $mod->get_admin_links(); 
  563. foreach ( $link as $l ) { 
  564. if ( ! empty( $l ) ) { 
  565. if ( empty( $link_list[ $l['order'] ] ) ) { 
  566. $link_list[ $l['order'] ] = Array(); 
  567. $link_list[ $l['order'] ][ $l['title'] ] = $l['href']; 
  568. if ( ! empty( $link_list ) ) { 
  569. ksort( $link_list ); 
  570. foreach ( $link_list as $ll ) { 
  571. foreach ( $ll as $k => $v ) { 
  572. $links[ $k ] = $v; 
  573. $output = '<ul>'; 
  574. if ( ! empty( $links ) ) { 
  575. foreach ( $links as $k => $v ) { 
  576. if ( $k === 'Feature Manager' ) { 
  577. $current = ' class="current"'; 
  578. } else { 
  579. $current = ''; 
  580. $output .= "<li{$current}><a href='" . esc_url( $v ) . "'>" . esc_attr( $k ) . '</a></li>'; 
  581. $output .= '</ul>'; 
  582. die( sprintf( "jQuery('{$_POST['target']}').fadeOut('fast', function() {jQuery('{$_POST['target']}').html('%s').fadeIn('fast');});", addslashes( $output ) ) ); 
  583.  
  584. if ( ! function_exists( 'aioseop_mrt_pccolumn' ) ) { 
  585.  
  586. /** 
  587. * @param $aioseopcn 
  588. * @param $aioseoppi 
  589. */ 
  590. function aioseop_mrt_pccolumn( $aioseopcn, $aioseoppi ) { 
  591. $id = $aioseoppi; 
  592. $target = null; 
  593. if ( $aioseopcn === 'seotitle' ) { 
  594. $target = 'title'; 
  595. if ( $aioseopcn === 'seokeywords' ) { 
  596. $target = 'keywords'; 
  597. if ( $aioseopcn === 'seodesc' ) { 
  598. $target = 'description'; 
  599. if ( ! $target ) { 
  600. return; 
  601. if ( current_user_can( 'edit_post', $id ) ) { ?> 
  602. <div class="aioseop_mpc_admin_meta_container"> 
  603. <div class="aioseop_mpc_admin_meta_options" 
  604. id="aioseop_<?php print $target; ?>_<?php echo $id; ?>" 
  605. style="float:left;"> 
  606. <?php $content = strip_tags( stripslashes( get_post_meta( $id, '_aioseop_' . $target, true ) ) ); 
  607. if ( ! empty( $content ) ): 
  608. $label = "<label id='aioseop_label_{$target}_{$id}'><span style='width: 20px;display: inline-block;'></span>" . $content . '</label>'; 
  609. else: 
  610. $label = "<label id='aioseop_label_{$target}_{$id}'></label><span style='width: 20px;display: inline-block;'></span><strong><i>" . __( 'No', 'all-in-one-seo-pack' ) . ' ' . $target . '</i></strong>'; 
  611. endif; 
  612. $nonce = wp_create_nonce( "aioseop_meta_{$target}_{$id}" ); 
  613. echo '<a id="' . $target . 'editlink' . $id . '" class="aioseop_edit_link" href="javascript:void(0);" onclick=\'aioseop_ajax_edit_meta_form(' . 
  614. $id . ', "' . $target . '", "' . $nonce . '");return false;\' title="' . __( 'Edit' ) . '">' 
  615. . "<img class='aioseop_edit_button' 
  616. id='aioseop_edit_id' 
  617. src='" . AIOSEOP_PLUGIN_IMAGES_URL . "cog_edit.png' /></a> " . $label; 
  618. ?> 
  619. </div> 
  620. </div> 
  621. <?php } 
  622.  
  623. if ( ! function_exists( 'aioseop_unprotect_meta' ) ) { 
  624.  
  625. /** 
  626. * @param $protected 
  627. * @param $meta_key 
  628. * @param $meta_type 
  629. * 
  630. * @return bool 
  631. */ 
  632. function aioseop_unprotect_meta( $protected, $meta_key, $meta_type ) { 
  633. if ( isset( $meta_key ) && ( substr( $meta_key, 0, 9 ) === '_aioseop_' ) ) { 
  634. return false; 
  635.  
  636. return $protected; 
  637.  
  638. if ( ! function_exists( 'aioseop_mrt_exclude_this_page' ) ) { 
  639.  
  640. /** 
  641. * @param null $url 
  642. * 
  643. * @return bool 
  644. */ 
  645. function aioseop_mrt_exclude_this_page( $url = null ) { 
  646. static $excluded = false; 
  647. if ( $excluded === false ) { 
  648. global $aioseop_options; 
  649. $ex_pages = ''; 
  650. if ( isset( $aioseop_options['aiosp_ex_pages'] ) ) { 
  651. $ex_pages = trim( $aioseop_options['aiosp_ex_pages'] ); 
  652. if ( ! empty( $ex_pages ) ) { 
  653. $excluded = explode( ', ', $ex_pages ); 
  654. if ( ! empty( $excluded ) ) { 
  655. foreach ( $excluded as $k => $v ) { 
  656. $excluded[ $k ] = trim( $v ); 
  657. if ( empty( $excluded[ $k ] ) ) { 
  658. unset( $excluded[ $k ] ); 
  659. if ( empty( $excluded ) ) { 
  660. $excluded = null; 
  661. if ( ! empty( $excluded ) ) { 
  662. if ( $url === null ) { 
  663. $url = $_SERVER['REQUEST_URI']; 
  664. } else { 
  665. $url = parse_url( $url ); 
  666. if ( ! empty( $url['path'] ) ) { 
  667. $url = $url['path']; 
  668. } else { 
  669. return false; 
  670. if ( ! empty( $url ) ) { 
  671. foreach ( $excluded as $exedd ) { 
  672. if ( $exedd && ( stripos( $url, $exedd ) !== false ) ) { 
  673. return true; 
  674.  
  675. return false; 
  676.  
  677. if ( ! function_exists( 'aioseop_get_pages_start' ) ) { 
  678.  
  679. /** 
  680. * @param $excludes 
  681. * 
  682. * @return mixed 
  683. */ 
  684. function aioseop_get_pages_start( $excludes ) { 
  685. global $aioseop_get_pages_start; 
  686. $aioseop_get_pages_start = 1; 
  687.  
  688. return $excludes; 
  689.  
  690. if ( ! function_exists( 'aioseop_get_pages' ) ) { 
  691.  
  692. /** 
  693. * @param $pages 
  694. * 
  695. * @return mixed 
  696. */ 
  697. function aioseop_get_pages( $pages ) { 
  698. global $aioseop_get_pages_start; 
  699. if ( ! $aioseop_get_pages_start ) { 
  700. return $pages; 
  701. foreach ( $pages as $k => $v ) { 
  702. $postID = $v->ID; 
  703. $menulabel = stripslashes( get_post_meta( $postID, '_aioseop_menulabel', true ) ); 
  704. if ( $menulabel ) { 
  705. $pages[ $k ]->post_title = $menulabel; 
  706. $aioseop_get_pages_start = 0; 
  707.  
  708. return $pages; 
  709.  
  710. // The following two functions are GPLed from Sarah G's Page Menu Editor, http://wordpress.org/extend/plugins/page-menu-editor/. 
  711. if ( ! function_exists( 'aioseop_list_pages' ) ) { 
  712. /** 
  713. * Adds stuff to the HTML in list_pages. 
  714. * @TODO See if we still use, or even want, these functions. 
  715. * 
  716. * @param $content 
  717. * 
  718. * @return mixed 
  719. */ 
  720. function aioseop_list_pages( $content ) { 
  721. global $wp_version; 
  722. $matches = array(); 
  723. if ( preg_match_all( '/<li class="page_item page-item-(\d+)/i', $content, $matches ) ) { 
  724. update_postmeta_cache( array_values( $matches[1] ) ); 
  725. unset( $matches ); 
  726. if ( $wp_version >= 3.3 ) { 
  727. $pattern = '@<li class="page_item page-item-(\d+)([^\"]*)"><a href=\"([^\"]+)">@is'; 
  728. } else { 
  729. $pattern = '@<li class="page_item page-item-(\d+)([^\"]*)"><a href=\"([^\"]+)" title="([^\"]+)">@is'; 
  730.  
  731. return preg_replace_callback( $pattern, 'aioseop_filter_callback', $content ); 
  732.  
  733. return $content; 
  734.  
  735. if ( ! function_exists( 'aioseop_filter_callback' ) ) { 
  736.  
  737. /** 
  738. * @param $matches 
  739. * 
  740. * @return string 
  741. */ 
  742. function aioseop_filter_callback( $matches ) { 
  743. if ( $matches[1] && ! empty( $matches[1] ) ) { 
  744. $postID = $matches[1]; 
  745. if ( empty( $postID ) ) { 
  746. $postID = get_option( 'page_on_front' ); 
  747. $title_attrib = stripslashes( get_post_meta( $postID, '_aioseop_titleatr', true ) ); 
  748. if ( empty( $title_attrib ) && ! empty( $matches[4] ) ) { 
  749. $title_attrib = $matches[4]; 
  750. if ( ! empty( $title_attrib ) ) { 
  751. $title_attrib = ' title="' . strip_tags( $title_attrib ) . '"'; 
  752.  
  753. return '<li class="page_item page-item-' . $postID . $matches[2] . '"><a href="' . $matches[3] . '"' . $title_attrib . '>'; 
  754.  
  755. if ( ! function_exists( 'aioseop_add_contactmethods' ) ) { 
  756.  
  757. /** 
  758. * @param $contactmethods 
  759. * 
  760. * @return mixed 
  761. */ 
  762. function aioseop_add_contactmethods( $contactmethods ) { 
  763. global $aioseop_options, $aioseop_modules; 
  764. if ( empty( $aioseop_options['aiosp_google_disable_profile'] ) ) { 
  765. $contactmethods['googleplus'] = __( 'Google+', 'all-in-one-seo-pack' ); 
  766. if ( ! empty( $aioseop_modules ) && is_object( $aioseop_modules ) ) { 
  767. $m = $aioseop_modules->return_module( 'All_in_One_SEO_Pack_Opengraph' ); 
  768. if ( ( $m !== false ) && is_object( $m ) ) { 
  769. if ( $m->option_isset( 'twitter_creator' ) ) { 
  770. $contactmethods['twitter'] = __( 'Twitter', 'all-in-one-seo-pack' ); 
  771. if ( $m->option_isset( 'facebook_author' ) ) { 
  772. $contactmethods['facebook'] = __( 'Facebook', 'all-in-one-seo-pack' ); 
  773.  
  774. return $contactmethods; 
  775.  
  776. if ( ! function_exists( 'aioseop_localize_script_data' ) ) { 
  777.  
  778. function aioseop_localize_script_data() { 
  779. static $loaded = 0; 
  780. if ( ! $loaded ) { 
  781. $data = apply_filters( 'aioseop_localize_script_data', Array() ); 
  782. wp_localize_script( 'aioseop-module-script', 'aiosp_data', $data ); 
  783. $loaded = 1; 
  784.  
  785. if ( ! function_exists( 'aioseop_array_insert_after' ) ) { 
  786. /** 
  787. * Utility function for inserting elements into associative arrays by key. 
  788. * 
  789. * @param $arr 
  790. * @param $insertKey 
  791. * @param $newValues 
  792. * 
  793. * @return array 
  794. */ 
  795. function aioseop_array_insert_after( $arr, $insertKey, $newValues ) { 
  796. $keys = array_keys( $arr ); 
  797. $vals = array_values( $arr ); 
  798. $insertAfter = array_search( $insertKey, $keys ) + 1; 
  799. $keys2 = array_splice( $keys, $insertAfter ); 
  800. $vals2 = array_splice( $vals, $insertAfter ); 
  801. foreach ( $newValues as $k => $v ) { 
  802. $keys[] = $k; 
  803. $vals[] = $v; 
  804.  
  805. return array_merge( array_combine( $keys, $vals ), array_combine( $keys2, $vals2 ) ); 
  806.  
  807. if ( ! function_exists( 'fnmatch' ) ) { 
  808. /** 
  809. * Support for fnmatch() doesn't exist on Windows pre PHP 5.3. 
  810. * 
  811. * @param $pattern 
  812. * @param $string 
  813. * 
  814. * @return int 
  815. */ 
  816. function fnmatch( $pattern, $string ) { 
  817. return preg_match( '#^' . strtr( preg_quote( $pattern, '#' ), array( 
  818. '\*' => '.*',  
  819. '\?' => '.',  
  820. ) ) . "$#i", $string ); 
  821.  
  822. if ( ! function_exists( 'parse_ini_string' ) ) { 
  823. /** 
  824. * Parse_ini_string() doesn't exist pre PHP 5.3. 
  825. * 
  826. * @param $string 
  827. * @param $process_sections 
  828. * 
  829. * @return array|bool 
  830. */ 
  831. function parse_ini_string( $string, $process_sections ) { 
  832.  
  833. if ( ! class_exists( 'parse_ini_filter' ) ) { 
  834.  
  835. /** 
  836. * Class parse_ini_filter 
  837. * 
  838. * Define our filter class. 
  839. */ 
  840. class parse_ini_filter extends php_user_filter { 
  841. static $buf = ''; 
  842.  
  843. /** 
  844. * The actual filter for parsing. 
  845. * 
  846. * @param $in 
  847. * @param $out 
  848. * @param $consumed 
  849. * @param $closing 
  850. * 
  851. * @return int 
  852. */ 
  853. function filter( $in, $out, &$consumed, $closing ) { 
  854. $bucket = stream_bucket_new( fopen( 'php://memory', 'wb' ), self::$buf ); 
  855. stream_bucket_append( $out, $bucket ); 
  856.  
  857. return PSFS_PASS_ON; 
  858.  
  859. // Register our filter with PHP. 
  860. if ( ! stream_filter_register( 'parse_ini', 'parse_ini_filter' ) ) { 
  861. return false; 
  862. parse_ini_filter::$buf = $string; 
  863.  
  864. return parse_ini_file( 'php://filter/read=parse_ini/resource=php://memory', $process_sections ); 
  865.  
  866. function aioseop_update_user_visibilitynotice() { 
  867.  
  868. update_user_meta( get_current_user_id(), 'aioseop_visibility_notice_dismissed', true ); 
  869.  
  870. function aioseop_update_yst_detected_notice() { 
  871.  
  872. update_user_meta( get_current_user_id(), 'aioseop_yst_detected_notice_dismissed', true ); 
  873.  
  874. function aioseop_woo_upgrade_notice_dismissed() { 
  875.  
  876. update_user_meta( get_current_user_id(), 'aioseop_woo_upgrade_notice_dismissed', true ); 
.