25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

class.akismet-admin.php 42 KiB

3 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. <?php
  2. class Akismet_Admin {
  3. const NONCE = 'akismet-update-key';
  4. private static $initiated = false;
  5. private static $notices = array();
  6. private static $allowed = array(
  7. 'a' => array(
  8. 'href' => true,
  9. 'title' => true,
  10. ),
  11. 'b' => array(),
  12. 'code' => array(),
  13. 'del' => array(
  14. 'datetime' => true,
  15. ),
  16. 'em' => array(),
  17. 'i' => array(),
  18. 'q' => array(
  19. 'cite' => true,
  20. ),
  21. 'strike' => array(),
  22. 'strong' => array(),
  23. );
  24. public static function init() {
  25. if ( ! self::$initiated ) {
  26. self::init_hooks();
  27. }
  28. if ( isset( $_POST['action'] ) && $_POST['action'] == 'enter-key' ) {
  29. self::enter_api_key();
  30. }
  31. }
  32. public static function init_hooks() {
  33. // The standalone stats page was removed in 3.0 for an all-in-one config and stats page.
  34. // Redirect any links that might have been bookmarked or in browser history.
  35. if ( isset( $_GET['page'] ) && 'akismet-stats-display' == $_GET['page'] ) {
  36. wp_safe_redirect( esc_url_raw( self::get_page_url( 'stats' ) ), 301 );
  37. die;
  38. }
  39. self::$initiated = true;
  40. add_action( 'admin_init', array( 'Akismet_Admin', 'admin_init' ) );
  41. add_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 ); # Priority 5, so it's called before Jetpack's admin_menu.
  42. add_action( 'admin_notices', array( 'Akismet_Admin', 'display_notice' ) );
  43. add_action( 'admin_enqueue_scripts', array( 'Akismet_Admin', 'load_resources' ) );
  44. add_action( 'activity_box_end', array( 'Akismet_Admin', 'dashboard_stats' ) );
  45. add_action( 'rightnow_end', array( 'Akismet_Admin', 'rightnow_stats' ) );
  46. add_action( 'manage_comments_nav', array( 'Akismet_Admin', 'check_for_spam_button' ) );
  47. add_action( 'admin_action_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) );
  48. add_action( 'wp_ajax_akismet_recheck_queue', array( 'Akismet_Admin', 'recheck_queue' ) );
  49. add_action( 'wp_ajax_comment_author_deurl', array( 'Akismet_Admin', 'remove_comment_author_url' ) );
  50. add_action( 'wp_ajax_comment_author_reurl', array( 'Akismet_Admin', 'add_comment_author_url' ) );
  51. add_action( 'jetpack_auto_activate_akismet', array( 'Akismet_Admin', 'connect_jetpack_user' ) );
  52. add_filter( 'plugin_action_links', array( 'Akismet_Admin', 'plugin_action_links' ), 10, 2 );
  53. add_filter( 'comment_row_actions', array( 'Akismet_Admin', 'comment_row_action' ), 10, 2 );
  54. add_filter( 'plugin_action_links_'.plugin_basename( plugin_dir_path( __FILE__ ) . 'akismet.php'), array( 'Akismet_Admin', 'admin_plugin_settings_link' ) );
  55. add_filter( 'wxr_export_skip_commentmeta', array( 'Akismet_Admin', 'exclude_commentmeta_from_export' ), 10, 3 );
  56. add_filter( 'all_plugins', array( 'Akismet_Admin', 'modify_plugin_description' ) );
  57. }
  58. public static function admin_init() {
  59. load_plugin_textdomain( 'akismet' );
  60. add_meta_box( 'akismet-status', __('Comment History', 'akismet'), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' );
  61. }
  62. public static function admin_menu() {
  63. if ( class_exists( 'Jetpack' ) )
  64. add_action( 'jetpack_admin_menu', array( 'Akismet_Admin', 'load_menu' ) );
  65. else
  66. self::load_menu();
  67. }
  68. public static function admin_head() {
  69. if ( !current_user_can( 'manage_options' ) )
  70. return;
  71. }
  72. public static function admin_plugin_settings_link( $links ) {
  73. $settings_link = '<a href="'.esc_url( self::get_page_url() ).'">'.__('Settings', 'akismet').'</a>';
  74. array_unshift( $links, $settings_link );
  75. return $links;
  76. }
  77. public static function load_menu() {
  78. if ( class_exists( 'Jetpack' ) )
  79. $hook = add_submenu_page( 'jetpack', __( 'Akismet' , 'akismet'), __( 'Akismet' , 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
  80. else
  81. $hook = add_options_page( __('Akismet', 'akismet'), __('Akismet', 'akismet'), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ) );
  82. if ( version_compare( $GLOBALS['wp_version'], '3.3', '>=' ) ) {
  83. add_action( "load-$hook", array( 'Akismet_Admin', 'admin_help' ) );
  84. }
  85. }
  86. public static function load_resources() {
  87. global $hook_suffix;
  88. if ( in_array( $hook_suffix, apply_filters( 'akismet_admin_page_hook_suffixes', array(
  89. 'index.php', # dashboard
  90. 'edit-comments.php',
  91. 'comment.php',
  92. 'post.php',
  93. 'settings_page_akismet-key-config',
  94. 'jetpack_page_akismet-key-config',
  95. 'plugins.php',
  96. ) ) ) ) {
  97. wp_register_style( 'akismet.css', plugin_dir_url( __FILE__ ) . '_inc/akismet.css', array(), AKISMET_VERSION );
  98. wp_enqueue_style( 'akismet.css');
  99. wp_register_script( 'akismet.js', plugin_dir_url( __FILE__ ) . '_inc/akismet.js', array('jquery'), AKISMET_VERSION );
  100. wp_enqueue_script( 'akismet.js' );
  101. $inline_js = array(
  102. 'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' ),
  103. 'strings' => array(
  104. 'Remove this URL' => __( 'Remove this URL' , 'akismet'),
  105. 'Removing...' => __( 'Removing...' , 'akismet'),
  106. 'URL removed' => __( 'URL removed' , 'akismet'),
  107. '(undo)' => __( '(undo)' , 'akismet'),
  108. 'Re-adding...' => __( 'Re-adding...' , 'akismet'),
  109. )
  110. );
  111. if ( isset( $_GET['akismet_recheck'] ) && wp_verify_nonce( $_GET['akismet_recheck'], 'akismet_recheck' ) ) {
  112. $inline_js['start_recheck'] = true;
  113. }
  114. wp_localize_script( 'akismet.js', 'WPAkismet', $inline_js );
  115. }
  116. }
  117. /**
  118. * Add help to the Akismet page
  119. *
  120. * @return false if not the Akismet page
  121. */
  122. public static function admin_help() {
  123. $current_screen = get_current_screen();
  124. // Screen Content
  125. if ( current_user_can( 'manage_options' ) ) {
  126. if ( !Akismet::get_api_key() || ( isset( $_GET['view'] ) && $_GET['view'] == 'start' ) ) {
  127. //setup page
  128. $current_screen->add_help_tab(
  129. array(
  130. 'id' => 'overview',
  131. 'title' => __( 'Overview' , 'akismet'),
  132. 'content' =>
  133. '<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
  134. '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
  135. '<p>' . esc_html__( 'On this page, you are able to set up the Akismet plugin.' , 'akismet') . '</p>',
  136. )
  137. );
  138. $current_screen->add_help_tab(
  139. array(
  140. 'id' => 'setup-signup',
  141. 'title' => __( 'New to Akismet' , 'akismet'),
  142. 'content' =>
  143. '<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
  144. '<p>' . esc_html__( 'You need to enter an API key to activate the Akismet service on your site.' , 'akismet') . '</p>' .
  145. '<p>' . sprintf( __( 'Sign up for an account on %s to get an API Key.' , 'akismet'), '<a href="https://akismet.com/plugin-signup/" target="_blank">Akismet.com</a>' ) . '</p>',
  146. )
  147. );
  148. $current_screen->add_help_tab(
  149. array(
  150. 'id' => 'setup-manual',
  151. 'title' => __( 'Enter an API Key' , 'akismet'),
  152. 'content' =>
  153. '<p><strong>' . esc_html__( 'Akismet Setup' , 'akismet') . '</strong></p>' .
  154. '<p>' . esc_html__( 'If you already have an API key' , 'akismet') . '</p>' .
  155. '<ol>' .
  156. '<li>' . esc_html__( 'Copy and paste the API key into the text field.' , 'akismet') . '</li>' .
  157. '<li>' . esc_html__( 'Click the Use this Key button.' , 'akismet') . '</li>' .
  158. '</ol>',
  159. )
  160. );
  161. }
  162. elseif ( isset( $_GET['view'] ) && $_GET['view'] == 'stats' ) {
  163. //stats page
  164. $current_screen->add_help_tab(
  165. array(
  166. 'id' => 'overview',
  167. 'title' => __( 'Overview' , 'akismet'),
  168. 'content' =>
  169. '<p><strong>' . esc_html__( 'Akismet Stats' , 'akismet') . '</strong></p>' .
  170. '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
  171. '<p>' . esc_html__( 'On this page, you are able to view stats on spam filtered on your site.' , 'akismet') . '</p>',
  172. )
  173. );
  174. }
  175. else {
  176. //configuration page
  177. $current_screen->add_help_tab(
  178. array(
  179. 'id' => 'overview',
  180. 'title' => __( 'Overview' , 'akismet'),
  181. 'content' =>
  182. '<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
  183. '<p>' . esc_html__( 'Akismet filters out spam, so you can focus on more important things.' , 'akismet') . '</p>' .
  184. '<p>' . esc_html__( 'On this page, you are able to enter/remove an API key, view account information and view spam stats.' , 'akismet') . '</p>',
  185. )
  186. );
  187. $current_screen->add_help_tab(
  188. array(
  189. 'id' => 'settings',
  190. 'title' => __( 'Settings' , 'akismet'),
  191. 'content' =>
  192. '<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
  193. '<p><strong>' . esc_html__( 'API Key' , 'akismet') . '</strong> - ' . esc_html__( 'Enter/remove an API key.' , 'akismet') . '</p>' .
  194. '<p><strong>' . esc_html__( 'Comments' , 'akismet') . '</strong> - ' . esc_html__( 'Show the number of approved comments beside each comment author in the comments list page.' , 'akismet') . '</p>' .
  195. '<p><strong>' . esc_html__( 'Strictness' , 'akismet') . '</strong> - ' . esc_html__( 'Choose to either discard the worst spam automatically or to always put all spam in spam folder.' , 'akismet') . '</p>',
  196. )
  197. );
  198. $current_screen->add_help_tab(
  199. array(
  200. 'id' => 'account',
  201. 'title' => __( 'Account' , 'akismet'),
  202. 'content' =>
  203. '<p><strong>' . esc_html__( 'Akismet Configuration' , 'akismet') . '</strong></p>' .
  204. '<p><strong>' . esc_html__( 'Subscription Type' , 'akismet') . '</strong> - ' . esc_html__( 'The Akismet subscription plan' , 'akismet') . '</p>' .
  205. '<p><strong>' . esc_html__( 'Status' , 'akismet') . '</strong> - ' . esc_html__( 'The subscription status - active, cancelled or suspended' , 'akismet') . '</p>',
  206. )
  207. );
  208. }
  209. }
  210. // Help Sidebar
  211. $current_screen->set_help_sidebar(
  212. '<p><strong>' . esc_html__( 'For more information:' , 'akismet') . '</strong></p>' .
  213. '<p><a href="https://akismet.com/faq/" target="_blank">' . esc_html__( 'Akismet FAQ' , 'akismet') . '</a></p>' .
  214. '<p><a href="https://akismet.com/support/" target="_blank">' . esc_html__( 'Akismet Support' , 'akismet') . '</a></p>'
  215. );
  216. }
  217. public static function enter_api_key() {
  218. if ( function_exists('current_user_can') && !current_user_can('manage_options') )
  219. die(__('Cheatin&#8217; uh?', 'akismet'));
  220. if ( !wp_verify_nonce( $_POST['_wpnonce'], self::NONCE ) )
  221. return false;
  222. foreach( array( 'akismet_strictness', 'akismet_show_user_comments_approved' ) as $option ) {
  223. update_option( $option, isset( $_POST[$option] ) && (int) $_POST[$option] == 1 ? '1' : '0' );
  224. }
  225. if ( defined( 'WPCOM_API_KEY' ) )
  226. return false; //shouldn't have option to save key if already defined
  227. $new_key = preg_replace( '/[^a-f0-9]/i', '', $_POST['key'] );
  228. $old_key = Akismet::get_api_key();
  229. if ( empty( $new_key ) ) {
  230. if ( !empty( $old_key ) ) {
  231. delete_option( 'wordpress_api_key' );
  232. self::$notices[] = 'new-key-empty';
  233. }
  234. }
  235. elseif ( $new_key != $old_key ) {
  236. self::save_key( $new_key );
  237. }
  238. return true;
  239. }
  240. public static function save_key( $api_key ) {
  241. $key_status = Akismet::verify_key( $api_key );
  242. if ( $key_status == 'valid' ) {
  243. $akismet_user = self::get_akismet_user( $api_key );
  244. if ( $akismet_user ) {
  245. if ( in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) ) )
  246. update_option( 'wordpress_api_key', $api_key );
  247. if ( $akismet_user->status == 'active' )
  248. self::$notices['status'] = 'new-key-valid';
  249. elseif ( $akismet_user->status == 'notice' )
  250. self::$notices['status'] = $akismet_user;
  251. else
  252. self::$notices['status'] = $akismet_user->status;
  253. }
  254. else
  255. self::$notices['status'] = 'new-key-invalid';
  256. }
  257. elseif ( in_array( $key_status, array( 'invalid', 'failed' ) ) )
  258. self::$notices['status'] = 'new-key-'.$key_status;
  259. }
  260. public static function dashboard_stats() {
  261. if ( !function_exists('did_action') || did_action( 'rightnow_end' ) )
  262. return; // We already displayed this info in the "Right Now" section
  263. if ( !$count = get_option('akismet_spam_count') )
  264. return;
  265. global $submenu;
  266. echo '<h3>' . esc_html( _x( 'Spam', 'comments' , 'akismet') ) . '</h3>';
  267. echo '<p>'.sprintf( _n(
  268. '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comment</a>.',
  269. '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.',
  270. $count
  271. , 'akismet'), 'https://akismet.com/wordpress/', esc_url( add_query_arg( array( 'page' => 'akismet-admin' ), admin_url( isset( $submenu['edit-comments.php'] ) ? 'edit-comments.php' : 'edit.php' ) ) ), number_format_i18n($count) ).'</p>';
  272. }
  273. // WP 2.5+
  274. public static function rightnow_stats() {
  275. if ( $count = get_option('akismet_spam_count') ) {
  276. $intro = sprintf( _n(
  277. '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already. ',
  278. '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already. ',
  279. $count
  280. , 'akismet'), 'https://akismet.com/wordpress/', number_format_i18n( $count ) );
  281. } else {
  282. $intro = sprintf( __('<a href="%s">Akismet</a> blocks spam from getting to your blog. ', 'akismet'), 'https://akismet.com/wordpress/' );
  283. }
  284. $link = add_query_arg( array( 'comment_status' => 'spam' ), admin_url( 'edit-comments.php' ) );
  285. if ( $queue_count = self::get_spam_count() ) {
  286. $queue_text = sprintf( _n(
  287. 'There&#8217;s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
  288. 'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
  289. $queue_count
  290. , 'akismet'), number_format_i18n( $queue_count ), esc_url( $link ) );
  291. } else {
  292. $queue_text = sprintf( __( "There&#8217;s nothing in your <a href='%s'>spam queue</a> at the moment." , 'akismet'), esc_url( $link ) );
  293. }
  294. $text = $intro . '<br />' . $queue_text;
  295. echo "<p class='akismet-right-now'>$text</p>\n";
  296. }
  297. public static function check_for_spam_button( $comment_status ) {
  298. // The "Check for Spam" button should only appear when the page might be showing
  299. // a comment with comment_approved=0, which means an un-trashed, un-spammed,
  300. // not-yet-moderated comment.
  301. if ( 'all' != $comment_status && 'moderated' != $comment_status ) {
  302. return;
  303. }
  304. if ( function_exists('plugins_url') )
  305. $link = add_query_arg( array( 'action' => 'akismet_recheck_queue' ), admin_url( 'admin.php' ) );
  306. else
  307. $link = add_query_arg( array( 'page' => 'akismet-admin', 'recheckqueue' => 'true', 'noheader' => 'true' ), admin_url( 'edit-comments.php' ) );
  308. echo '</div>';
  309. echo '<div class="alignleft">';
  310. echo '<a
  311. class="button-secondary checkforspam"
  312. href="' . esc_url( $link ) . '"
  313. data-active-label="' . esc_attr( __( 'Checking for Spam', 'akismet' ) ) . '"
  314. data-progress-label-format="' . esc_attr( __( '(%1$s...)', 'akismet' ) ) . '"
  315. data-success-url="' . esc_attr( remove_query_arg( 'akismet_recheck', add_query_arg( array( 'akismet_recheck_complete' => 1, 'recheck_count' => urlencode( '__recheck_count__' ), 'spam_count' => urlencode( '__spam_count__' ) ) ) ) ) . '"
  316. >';
  317. echo '<span class="akismet-label">' . esc_html__('Check for Spam', 'akismet') . '</span>';
  318. echo '<span class="checkforspam-progress"></span>';
  319. echo '</a>';
  320. echo '<span class="checkforspam-spinner"></span>';
  321. }
  322. public static function recheck_queue() {
  323. global $wpdb;
  324. Akismet::fix_scheduled_recheck();
  325. if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) ) {
  326. return;
  327. }
  328. $result_counts = self::recheck_queue_portion( empty( $_POST['offset'] ) ? 0 : $_POST['offset'], empty( $_POST['limit'] ) ? 100 : $_POST['limit'] );
  329. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  330. wp_send_json( array(
  331. 'counts' => $result_counts,
  332. ));
  333. }
  334. else {
  335. $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' );
  336. wp_safe_redirect( $redirect_to );
  337. exit;
  338. }
  339. }
  340. public static function recheck_queue_portion( $start = 0, $limit = 100 ) {
  341. global $wpdb;
  342. $paginate = '';
  343. if ( $limit <= 0 ) {
  344. $limit = 100;
  345. }
  346. if ( $start < 0 ) {
  347. $start = 0;
  348. }
  349. $moderation = $wpdb->get_col( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_approved = '0' LIMIT %d OFFSET %d", $limit, $start ) );
  350. $result_counts = array(
  351. 'processed' => count( $moderation ),
  352. 'spam' => 0,
  353. 'ham' => 0,
  354. 'error' => 0,
  355. );
  356. foreach ( $moderation as $comment_id ) {
  357. $api_response = Akismet::recheck_comment( $comment_id, 'recheck_queue' );
  358. if ( 'true' === $api_response ) {
  359. ++$result_counts['spam'];
  360. }
  361. elseif ( 'false' === $api_response ) {
  362. ++$result_counts['ham'];
  363. }
  364. else {
  365. ++$result_counts['error'];
  366. }
  367. }
  368. return $result_counts;
  369. }
  370. // Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link
  371. public static function remove_comment_author_url() {
  372. if ( !empty( $_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
  373. $comment_id = intval( $_POST['id'] );
  374. $comment = get_comment( $comment_id, ARRAY_A );
  375. if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
  376. $comment['comment_author_url'] = '';
  377. do_action( 'comment_remove_author_url' );
  378. print( wp_update_comment( $comment ) );
  379. die();
  380. }
  381. }
  382. }
  383. public static function add_comment_author_url() {
  384. if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
  385. $comment_id = intval( $_POST['id'] );
  386. $comment = get_comment( $comment_id, ARRAY_A );
  387. if ( $comment && current_user_can( 'edit_comment', $comment['comment_ID'] ) ) {
  388. $comment['comment_author_url'] = esc_url( $_POST['url'] );
  389. do_action( 'comment_add_author_url' );
  390. print( wp_update_comment( $comment ) );
  391. die();
  392. }
  393. }
  394. }
  395. public static function comment_row_action( $a, $comment ) {
  396. // failsafe for old WP versions
  397. if ( !function_exists('add_comment_meta') )
  398. return $a;
  399. $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
  400. $akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
  401. $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
  402. $comment_status = wp_get_comment_status( $comment->comment_ID );
  403. $desc = null;
  404. if ( $akismet_error ) {
  405. $desc = __( 'Awaiting spam check' , 'akismet');
  406. } elseif ( !$user_result || $user_result == $akismet_result ) {
  407. // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
  408. if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
  409. $desc = __( 'Flagged as spam by Akismet' , 'akismet');
  410. elseif ( $akismet_result == 'false' && $comment_status == 'spam' )
  411. $desc = __( 'Cleared by Akismet' , 'akismet');
  412. } else {
  413. $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true );
  414. if ( $user_result == 'true' )
  415. $desc = sprintf( __('Flagged as spam by %s', 'akismet'), $who );
  416. else
  417. $desc = sprintf( __('Un-spammed by %s', 'akismet'), $who );
  418. }
  419. // add a History item to the hover links, just after Edit
  420. if ( $akismet_result ) {
  421. $b = array();
  422. foreach ( $a as $k => $item ) {
  423. $b[ $k ] = $item;
  424. if (
  425. $k == 'edit'
  426. || ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 )
  427. ) {
  428. $b['history'] = '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="'. esc_attr__( 'View comment history' , 'akismet') . '"> '. esc_html__('History', 'akismet') . '</a>';
  429. }
  430. }
  431. $a = $b;
  432. }
  433. if ( $desc )
  434. echo '<span class="akismet-status" commentid="'.$comment->comment_ID.'"><a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="' . esc_attr__( 'View comment history' , 'akismet') . '">'.esc_html( $desc ).'</a></span>';
  435. $show_user_comments_option = get_option( 'akismet_show_user_comments_approved' );
  436. if ( $show_user_comments_option === false ) {
  437. // Default to active if the user hasn't made a decision.
  438. $show_user_comments_option = '1';
  439. }
  440. $show_user_comments = apply_filters( 'akismet_show_user_comments_approved', $show_user_comments_option );
  441. $show_user_comments = $show_user_comments === 'false' ? false : $show_user_comments; //option used to be saved as 'false' / 'true'
  442. if ( $show_user_comments ) {
  443. $comment_count = Akismet::get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url );
  444. $comment_count = intval( $comment_count );
  445. echo '<span class="akismet-user-comment-count" commentid="'.$comment->comment_ID.'" style="display:none;"><br><span class="akismet-user-comment-counts">'. sprintf( esc_html( _n( '%s approved', '%s approved', $comment_count , 'akismet') ), number_format_i18n( $comment_count ) ) . '</span></span>';
  446. }
  447. return $a;
  448. }
  449. public static function comment_status_meta_box( $comment ) {
  450. $history = Akismet::get_comment_history( $comment->comment_ID );
  451. if ( $history ) {
  452. echo '<div class="akismet-history" style="margin: 13px;">';
  453. foreach ( $history as $row ) {
  454. $time = date( 'D d M Y @ h:i:m a', $row['time'] ) . ' GMT';
  455. $message = '';
  456. if ( ! empty( $row['message'] ) ) {
  457. // Old versions of Akismet stored the message as a literal string in the commentmeta.
  458. // New versions don't do that for two reasons:
  459. // 1) Save space.
  460. // 2) The message can be translated into the current language of the blog, not stuck
  461. // in the language of the blog when the comment was made.
  462. $message = $row['message'];
  463. }
  464. // If possible, use a current translation.
  465. switch ( $row['event'] ) {
  466. case 'recheck-spam';
  467. $message = __( 'Akismet re-checked and caught this comment as spam.', 'akismet' );
  468. break;
  469. case 'check-spam':
  470. $message = __( 'Akismet caught this comment as spam.', 'akismet' );
  471. break;
  472. case 'recheck-ham':
  473. $message = __( 'Akismet re-checked and cleared this comment.', 'akismet' );
  474. break;
  475. case 'check-ham':
  476. $message = __( 'Akismet cleared this comment.', 'akismet' );
  477. break;
  478. case 'wp-blacklisted':
  479. $message = __( 'Comment was caught by wp_blacklist_check.', 'akismet' );
  480. break;
  481. case 'report-spam':
  482. if ( isset( $row['user'] ) ) {
  483. $message = sprintf( __( '%s reported this comment as spam.', 'akismet' ), $row['user'] );
  484. }
  485. else if ( ! $message ) {
  486. $message = __( 'This comment was reported as spam.', 'akismet' );
  487. }
  488. break;
  489. case 'report-ham':
  490. if ( isset( $row['user'] ) ) {
  491. $message = sprintf( __( '%s reported this comment as not spam.', 'akismet' ), $row['user'] );
  492. }
  493. else if ( ! $message ) {
  494. $message = __( 'This comment was reported as not spam.', 'akismet' );
  495. }
  496. break;
  497. case 'cron-retry-spam':
  498. $message = __( 'Akismet caught this comment as spam during an automatic retry.' , 'akismet');
  499. break;
  500. case 'cron-retry-ham':
  501. $message = __( 'Akismet cleared this comment during an automatic retry.', 'akismet');
  502. break;
  503. case 'check-error':
  504. if ( isset( $row['meta'], $row['meta']['response'] ) ) {
  505. $message = sprintf( __( 'Akismet was unable to check this comment (response: %s) but will automatically retry later.', 'akismet'), $row['meta']['response'] );
  506. }
  507. break;
  508. case 'recheck-error':
  509. if ( isset( $row['meta'], $row['meta']['response'] ) ) {
  510. $message = sprintf( __( 'Akismet was unable to recheck this comment (response: %s).', 'akismet'), $row['meta']['response'] );
  511. }
  512. break;
  513. default:
  514. if ( preg_match( '/^status-changed/', $row['event'] ) ) {
  515. // Half of these used to be saved without the dash after 'status-changed'.
  516. // See https://plugins.trac.wordpress.org/changeset/1150658/akismet/trunk
  517. $new_status = preg_replace( '/^status-changed-?/', '', $row['event'] );
  518. $message = sprintf( __( 'Comment status was changed to %s', 'akismet' ), $new_status );
  519. }
  520. else if ( preg_match( '/^status-/', $row['event'] ) ) {
  521. $new_status = preg_replace( '/^status-/', '', $row['event'] );
  522. if ( isset( $row['user'] ) ) {
  523. $message = sprintf( __( '%1$s changed the comment status to %2$s.', 'akismet' ), $row['user'], $new_status );
  524. }
  525. }
  526. break;
  527. }
  528. echo '<div style="margin-bottom: 13px;">';
  529. echo '<span style="color: #999;" alt="' . $time . '" title="' . $time . '">' . sprintf( esc_html__('%s ago', 'akismet'), human_time_diff( $row['time'] ) ) . '</span>';
  530. echo ' - ';
  531. echo esc_html( $message );
  532. echo '</div>';
  533. }
  534. echo '</div>';
  535. }
  536. }
  537. public static function plugin_action_links( $links, $file ) {
  538. if ( $file == plugin_basename( plugin_dir_url( __FILE__ ) . '/akismet.php' ) ) {
  539. $links[] = '<a href="' . esc_url( self::get_page_url() ) . '">'.esc_html__( 'Settings' , 'akismet').'</a>';
  540. }
  541. return $links;
  542. }
  543. // Total spam in queue
  544. // get_option( 'akismet_spam_count' ) is the total caught ever
  545. public static function get_spam_count( $type = false ) {
  546. global $wpdb;
  547. if ( !$type ) { // total
  548. $count = wp_cache_get( 'akismet_spam_count', 'widget' );
  549. if ( false === $count ) {
  550. if ( function_exists('wp_count_comments') ) {
  551. $count = wp_count_comments();
  552. $count = $count->spam;
  553. } else {
  554. $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_approved = 'spam'");
  555. }
  556. wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
  557. }
  558. return $count;
  559. } elseif ( 'comments' == $type || 'comment' == $type ) { // comments
  560. $type = '';
  561. }
  562. return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM {$wpdb->comments} WHERE comment_approved = 'spam' AND comment_type = %s", $type ) );
  563. }
  564. // Check connectivity between the WordPress blog and Akismet's servers.
  565. // Returns an associative array of server IP addresses, where the key is the IP address, and value is true (available) or false (unable to connect).
  566. public static function check_server_ip_connectivity() {
  567. $servers = $ips = array();
  568. // Some web hosts may disable this function
  569. if ( function_exists('gethostbynamel') ) {
  570. $ips = gethostbynamel( 'rest.akismet.com' );
  571. if ( $ips && is_array($ips) && count($ips) ) {
  572. $api_key = Akismet::get_api_key();
  573. foreach ( $ips as $ip ) {
  574. $response = Akismet::verify_key( $api_key, $ip );
  575. // even if the key is invalid, at least we know we have connectivity
  576. if ( $response == 'valid' || $response == 'invalid' )
  577. $servers[$ip] = 'connected';
  578. else
  579. $servers[$ip] = $response ? $response : 'unable to connect';
  580. }
  581. }
  582. }
  583. return $servers;
  584. }
  585. // Simpler connectivity check
  586. public static function check_server_connectivity($cache_timeout = 86400) {
  587. $debug = array();
  588. $debug[ 'PHP_VERSION' ] = PHP_VERSION;
  589. $debug[ 'WORDPRESS_VERSION' ] = $GLOBALS['wp_version'];
  590. $debug[ 'AKISMET_VERSION' ] = AKISMET_VERSION;
  591. $debug[ 'AKISMET__PLUGIN_DIR' ] = AKISMET__PLUGIN_DIR;
  592. $debug[ 'SITE_URL' ] = site_url();
  593. $debug[ 'HOME_URL' ] = home_url();
  594. $servers = get_option('akismet_available_servers');
  595. if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false ) {
  596. $servers = self::check_server_ip_connectivity();
  597. update_option('akismet_available_servers', $servers);
  598. update_option('akismet_connectivity_time', time());
  599. }
  600. if ( function_exists( 'wp_http_supports' ) && ( wp_http_supports( array( 'ssl' ) ) ) ) {
  601. $response = wp_remote_get( 'https://rest.akismet.com/1.1/test' );
  602. }
  603. else {
  604. $response = wp_remote_get( 'http://rest.akismet.com/1.1/test' );
  605. }
  606. $debug[ 'gethostbynamel' ] = function_exists('gethostbynamel') ? 'exists' : 'not here';
  607. $debug[ 'Servers' ] = $servers;
  608. $debug[ 'Test Connection' ] = $response;
  609. Akismet::log( $debug );
  610. if ( $response && 'connected' == wp_remote_retrieve_body( $response ) )
  611. return true;
  612. return false;
  613. }
  614. // Check the server connectivity and store the available servers in an option.
  615. public static function get_server_connectivity($cache_timeout = 86400) {
  616. return self::check_server_connectivity( $cache_timeout );
  617. }
  618. public static function get_number_spam_waiting() {
  619. global $wpdb;
  620. return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'" );
  621. }
  622. public static function get_page_url( $page = 'config' ) {
  623. $args = array( 'page' => 'akismet-key-config' );
  624. if ( $page == 'stats' )
  625. $args = array( 'page' => 'akismet-key-config', 'view' => 'stats' );
  626. elseif ( $page == 'delete_key' )
  627. $args = array( 'page' => 'akismet-key-config', 'view' => 'start', 'action' => 'delete-key', '_wpnonce' => wp_create_nonce( self::NONCE ) );
  628. $url = add_query_arg( $args, class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'options-general.php' ) );
  629. return $url;
  630. }
  631. public static function get_akismet_user( $api_key ) {
  632. $akismet_user = false;
  633. $subscription_verification = Akismet::http_post( Akismet::build_query( array( 'key' => $api_key, 'blog' => get_option( 'home' ) ) ), 'get-subscription' );
  634. if ( ! empty( $subscription_verification[1] ) ) {
  635. if ( 'invalid' !== $subscription_verification[1] ) {
  636. $akismet_user = json_decode( $subscription_verification[1] );
  637. }
  638. }
  639. return $akismet_user;
  640. }
  641. public static function get_stats( $api_key ) {
  642. $stat_totals = array();
  643. foreach( array( '6-months', 'all' ) as $interval ) {
  644. $response = Akismet::http_post( Akismet::build_query( array( 'blog' => get_option( 'home' ), 'key' => $api_key, 'from' => $interval ) ), 'get-stats' );
  645. if ( ! empty( $response[1] ) ) {
  646. $stat_totals[$interval] = json_decode( $response[1] );
  647. }
  648. }
  649. return $stat_totals;
  650. }
  651. public static function verify_wpcom_key( $api_key, $user_id, $extra = array() ) {
  652. $akismet_account = Akismet::http_post( Akismet::build_query( array_merge( array(
  653. 'user_id' => $user_id,
  654. 'api_key' => $api_key,
  655. 'get_account_type' => 'true'
  656. ), $extra ) ), 'verify-wpcom-key' );
  657. if ( ! empty( $akismet_account[1] ) )
  658. $akismet_account = json_decode( $akismet_account[1] );
  659. Akismet::log( compact( 'akismet_account' ) );
  660. return $akismet_account;
  661. }
  662. public static function connect_jetpack_user() {
  663. if ( $jetpack_user = self::get_jetpack_user() ) {
  664. if ( isset( $jetpack_user['user_id'] ) && isset( $jetpack_user['api_key'] ) ) {
  665. $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'], array( 'action' => 'connect_jetpack_user' ) );
  666. if ( is_object( $akismet_user ) ) {
  667. self::save_key( $akismet_user->api_key );
  668. return in_array( $akismet_user->status, array( 'active', 'active-dunning', 'no-sub' ) );
  669. }
  670. }
  671. }
  672. return false;
  673. }
  674. public static function display_alert() {
  675. Akismet::view( 'notice', array(
  676. 'type' => 'alert',
  677. 'code' => (int) get_option( 'akismet_alert_code' ),
  678. 'msg' => get_option( 'akismet_alert_msg' )
  679. ) );
  680. }
  681. public static function display_spam_check_warning() {
  682. Akismet::fix_scheduled_recheck();
  683. if ( wp_next_scheduled('akismet_schedule_cron_recheck') > time() && self::get_number_spam_waiting() > 0 ) {
  684. $link_text = apply_filters( 'akismet_spam_check_warning_link_text', sprintf( __( 'Please check your <a href="%s">Akismet configuration</a> and contact your web host if problems persist.', 'akismet'), esc_url( self::get_page_url() ) ) );
  685. Akismet::view( 'notice', array( 'type' => 'spam-check', 'link_text' => $link_text ) );
  686. }
  687. }
  688. public static function display_api_key_warning() {
  689. Akismet::view( 'notice', array( 'type' => 'plugin' ) );
  690. }
  691. public static function display_page() {
  692. if ( !Akismet::get_api_key() || ( isset( $_GET['view'] ) && $_GET['view'] == 'start' ) )
  693. self::display_start_page();
  694. elseif ( isset( $_GET['view'] ) && $_GET['view'] == 'stats' )
  695. self::display_stats_page();
  696. else
  697. self::display_configuration_page();
  698. }
  699. public static function display_start_page() {
  700. if ( isset( $_GET['action'] ) ) {
  701. if ( $_GET['action'] == 'delete-key' ) {
  702. if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], self::NONCE ) )
  703. delete_option( 'wordpress_api_key' );
  704. }
  705. }
  706. if ( $api_key = Akismet::get_api_key() && ( empty( self::$notices['status'] ) || 'existing-key-invalid' != self::$notices['status'] ) ) {
  707. self::display_configuration_page();
  708. return;
  709. }
  710. //the user can choose to auto connect their API key by clicking a button on the akismet done page
  711. //if jetpack, get verified api key by using connected wpcom user id
  712. //if no jetpack, get verified api key by using an akismet token
  713. $akismet_user = false;
  714. if ( isset( $_GET['token'] ) && preg_match('/^(\d+)-[0-9a-f]{20}$/', $_GET['token'] ) )
  715. $akismet_user = self::verify_wpcom_key( '', '', array( 'token' => $_GET['token'] ) );
  716. elseif ( $jetpack_user = self::get_jetpack_user() )
  717. $akismet_user = self::verify_wpcom_key( $jetpack_user['api_key'], $jetpack_user['user_id'] );
  718. if ( isset( $_GET['action'] ) ) {
  719. if ( $_GET['action'] == 'save-key' ) {
  720. if ( is_object( $akismet_user ) ) {
  721. self::save_key( $akismet_user->api_key );
  722. self::display_configuration_page();
  723. return;
  724. }
  725. }
  726. }
  727. Akismet::view( 'start', compact( 'akismet_user' ) );
  728. /*
  729. // To see all variants when testing.
  730. $akismet_user->status = 'no-sub';
  731. Akismet::view( 'start', compact( 'akismet_user' ) );
  732. $akismet_user->status = 'cancelled';
  733. Akismet::view( 'start', compact( 'akismet_user' ) );
  734. $akismet_user->status = 'suspended';
  735. Akismet::view( 'start', compact( 'akismet_user' ) );
  736. $akismet_user->status = 'other';
  737. Akismet::view( 'start', compact( 'akismet_user' ) );
  738. $akismet_user = false;
  739. */
  740. }
  741. public static function display_stats_page() {
  742. Akismet::view( 'stats' );
  743. }
  744. public static function display_configuration_page() {
  745. $api_key = Akismet::get_api_key();
  746. $akismet_user = self::get_akismet_user( $api_key );
  747. if ( ! $akismet_user ) {
  748. // This could happen if the user's key became invalid after it was previously valid and successfully set up.
  749. self::$notices['status'] = 'existing-key-invalid';
  750. self::display_start_page();
  751. return;
  752. }
  753. $stat_totals = self::get_stats( $api_key );
  754. // If unset, create the new strictness option using the old discard option to determine its default.
  755. // If the old option wasn't set, default to discarding the blatant spam.
  756. if ( get_option( 'akismet_strictness' ) === false ) {
  757. add_option( 'akismet_strictness', ( get_option( 'akismet_discard_month' ) === 'false' ? '0' : '1' ) );
  758. }
  759. $notices = array();
  760. if ( empty( self::$notices ) ) {
  761. if ( ! empty( $stat_totals['all'] ) && isset( $stat_totals['all']->time_saved ) && $akismet_user->status == 'active' && $akismet_user->account_type == 'free-api-key' ) {
  762. $time_saved = false;
  763. if ( $stat_totals['all']->time_saved > 1800 ) {
  764. $total_in_minutes = round( $stat_totals['all']->time_saved / 60 );
  765. $total_in_hours = round( $total_in_minutes / 60 );
  766. $total_in_days = round( $total_in_hours / 8 );
  767. $cleaning_up = __( 'Cleaning up spam takes time.' , 'akismet');
  768. if ( $total_in_days > 1 )
  769. $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %s day!', 'Akismet has saved you %s days!', $total_in_days, 'akismet' ), number_format_i18n( $total_in_days ) );
  770. elseif ( $total_in_hours > 1 )
  771. $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %d hour!', 'Akismet has saved you %d hours!', $total_in_hours, 'akismet' ), $total_in_hours );
  772. elseif ( $total_in_minutes >= 30 )
  773. $time_saved = $cleaning_up . ' ' . sprintf( _n( 'Akismet has saved you %d minute!', 'Akismet has saved you %d minutes!', $total_in_minutes, 'akismet' ), $total_in_minutes );
  774. }
  775. $notices[] = array( 'type' => 'active-notice', 'time_saved' => $time_saved );
  776. }
  777. if ( !empty( $akismet_user->limit_reached ) && in_array( $akismet_user->limit_reached, array( 'yellow', 'red' ) ) ) {
  778. $notices[] = array( 'type' => 'limit-reached', 'level' => $akismet_user->limit_reached );
  779. }
  780. }
  781. if ( !isset( self::$notices['status'] ) && in_array( $akismet_user->status, array( 'cancelled', 'suspended', 'missing', 'no-sub' ) ) ) {
  782. $notices[] = array( 'type' => $akismet_user->status );
  783. }
  784. /*
  785. // To see all variants when testing.
  786. $notices[] = array( 'type' => 'active-notice', 'time_saved' => 'Cleaning up spam takes time. Akismet has saved you 1 minute!' );
  787. $notices[] = array( 'type' => 'plugin' );
  788. $notices[] = array( 'type' => 'spam-check', 'link_text' => 'Link text.' );
  789. $notices[] = array( 'type' => 'notice', 'notice_header' => 'This is the notice header.', 'notice_text' => 'This is the notice text.' );
  790. $notices[] = array( 'type' => 'missing-functions' );
  791. $notices[] = array( 'type' => 'servers-be-down' );
  792. $notices[] = array( 'type' => 'active-dunning' );
  793. $notices[] = array( 'type' => 'cancelled' );
  794. $notices[] = array( 'type' => 'suspended' );
  795. $notices[] = array( 'type' => 'missing' );
  796. $notices[] = array( 'type' => 'no-sub' );
  797. $notices[] = array( 'type' => 'new-key-valid' );
  798. $notices[] = array( 'type' => 'new-key-invalid' );
  799. $notices[] = array( 'type' => 'existing-key-invalid' );
  800. $notices[] = array( 'type' => 'new-key-failed' );
  801. $notices[] = array( 'type' => 'limit-reached', 'level' => 'yellow' );
  802. $notices[] = array( 'type' => 'limit-reached', 'level' => 'red' );
  803. */
  804. Akismet::log( compact( 'stat_totals', 'akismet_user' ) );
  805. Akismet::view( 'config', compact( 'api_key', 'akismet_user', 'stat_totals', 'notices' ) );
  806. }
  807. public static function display_notice() {
  808. global $hook_suffix;
  809. if ( in_array( $hook_suffix, array( 'jetpack_page_akismet-key-config', 'settings_page_akismet-key-config' ) ) ) {
  810. // This page manages the notices and puts them inline where they make sense.
  811. return;
  812. }
  813. if ( in_array( $hook_suffix, array( 'edit-comments.php' ) ) && (int) get_option( 'akismet_alert_code' ) > 0 ) {
  814. Akismet::verify_key( Akismet::get_api_key() ); //verify that the key is still in alert state
  815. if ( get_option( 'akismet_alert_code' ) > 0 )
  816. self::display_alert();
  817. }
  818. elseif ( $hook_suffix == 'plugins.php' && !Akismet::get_api_key() ) {
  819. self::display_api_key_warning();
  820. }
  821. elseif ( $hook_suffix == 'edit-comments.php' && wp_next_scheduled( 'akismet_schedule_cron_recheck' ) ) {
  822. self::display_spam_check_warning();
  823. }
  824. else if ( isset( $_GET['akismet_recheck_complete'] ) ) {
  825. $recheck_count = (int) $_GET['recheck_count'];
  826. $spam_count = (int) $_GET['spam_count'];
  827. if ( $recheck_count === 0 ) {
  828. $message = __( 'There were no comments to check. Akismet will only check comments in the Pending queue.', 'akismet' );
  829. }
  830. else {
  831. $message = sprintf( _n( 'Akismet checked %s comment.', 'Akismet checked %s comments.', $recheck_count, 'akismet' ), number_format( $recheck_count ) );
  832. $message .= ' ';
  833. if ( $spam_count === 0 ) {
  834. $message .= __( 'No comments were caught as spam.' );
  835. }
  836. else {
  837. $message .= sprintf( _n( '%s comment was caught as spam.', '%s comments were caught as spam.', $spam_count, 'akismet' ), number_format( $spam_count ) );
  838. }
  839. }
  840. echo '<div class="notice notice-success"><p>' . esc_html( $message ) . '</p></div>';
  841. }
  842. }
  843. public static function display_status() {
  844. if ( ! self::get_server_connectivity() ) {
  845. Akismet::view( 'notice', compact( 'servers-be-down' ) );
  846. }
  847. else if ( ! empty( self::$notices ) ) {
  848. foreach ( self::$notices as $index => $type ) {
  849. if ( is_object( $type ) ) {
  850. $notice_header = $notice_text = '';
  851. if ( property_exists( $type, 'notice_header' ) ) {
  852. $notice_header = wp_kses( $type->notice_header, self::$allowed );
  853. }
  854. if ( property_exists( $type, 'notice_text' ) ) {
  855. $notice_text = wp_kses( $type->notice_text, self::$allowed );
  856. }
  857. if ( property_exists( $type, 'status' ) ) {
  858. $type = wp_kses( $type->status, self::$allowed );
  859. Akismet::view( 'notice', compact( 'type', 'notice_header', 'notice_text' ) );
  860. unset( self::$notices[ $index ] );
  861. }
  862. }
  863. else {
  864. Akismet::view( 'notice', compact( 'type' ) );
  865. unset( self::$notices[ $index ] );
  866. }
  867. }
  868. }
  869. }
  870. private static function get_jetpack_user() {
  871. if ( !class_exists('Jetpack') )
  872. return false;
  873. Jetpack::load_xml_rpc_client();
  874. $xml = new Jetpack_IXR_ClientMulticall( array( 'user_id' => get_current_user_id() ) );
  875. $xml->addCall( 'wpcom.getUserID' );
  876. $xml->addCall( 'akismet.getAPIKey' );
  877. $xml->query();
  878. Akismet::log( compact( 'xml' ) );
  879. if ( !$xml->isError() ) {
  880. $responses = $xml->getResponse();
  881. if ( count( $responses ) > 1 ) {
  882. $api_key = array_shift( $responses[0] );
  883. $user_id = (int) array_shift( $responses[1] );
  884. return compact( 'api_key', 'user_id' );
  885. }
  886. }
  887. return false;
  888. }
  889. /**
  890. * Some commentmeta isn't useful in an export file. Suppress it (when supported).
  891. *
  892. * @param bool $exclude
  893. * @param string $key The meta key
  894. * @param object $meta The meta object
  895. * @return bool Whether to exclude this meta entry from the export.
  896. */
  897. public static function exclude_commentmeta_from_export( $exclude, $key, $meta ) {
  898. if ( in_array( $key, array( 'akismet_as_submitted', 'akismet_rechecking', 'akismet_delayed_moderation_email' ) ) ) {
  899. return true;
  900. }
  901. return $exclude;
  902. }
  903. /**
  904. * When Akismet is active, remove the "Activate Akismet" step from the plugin description.
  905. */
  906. public static function modify_plugin_description( $all_plugins ) {
  907. if ( isset( $all_plugins['akismet/akismet.php'] ) ) {
  908. if ( Akismet::get_api_key() ) {
  909. $all_plugins['akismet/akismet.php']['Description'] = __( 'Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. Your site is fully configured and being protected, even while you sleep.', 'akismet' );
  910. }
  911. else {
  912. $all_plugins['akismet/akismet.php']['Description'] = __( 'Used by millions, Akismet is quite possibly the best way in the world to <strong>protect your blog from spam</strong>. It keeps your site protected even while you sleep. To get started, just go to <a href="admin.php?page=akismet-key-config">your Akismet Settings page</a> to set up your API key.', 'akismet' );
  913. }
  914. }
  915. return $all_plugins;
  916. }
  917. }