PageRenderTime 47ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/blog/wp-content/plugins/pushpress/send-ping.php

https://github.com/kennethreitz-archive/wordpress-skeleton
PHP | 78 lines | 58 code | 16 blank | 4 comment | 9 complexity | eb96b64d12bb247309b08aa88eb18f9a MD5 | raw file
  1. <?php
  2. add_action( 'pushpress_scheduled_ping', 'pushpress_send_ping', 10, 4 );
  3. if ( !function_exists( 'pushpress_send_ping' ) ) {
  4. function pushpress_send_ping( $callback, $post_id, $feed_type, $secret ) {
  5. global $pushpress;
  6. // Need to make sure that the PuSHPress options are initialized
  7. $pushpress->init( );
  8. do_action( 'pushpress_send_ping' );
  9. $remote_opt = array(
  10. 'headers' => array(
  11. 'format' => $feed_type
  12. ),
  13. 'sslverify' => FALSE,
  14. 'timeout' => $pushpress->http_timeout,
  15. 'user-agent' => $pushpress->http_user_agent
  16. );
  17. $post = get_post( $post_id );
  18. do_enclose( $post->post_content, $post_id );
  19. update_postmeta_cache( array( $post_id ) );
  20. query_posts( "p={$post_id}" );
  21. ob_start( );
  22. $feed_url = FALSE;
  23. if ( $feed_type == 'rss2' ) {
  24. do_action( 'pushpress_send_ping_rss2' );
  25. $feed_url = get_bloginfo( 'rss2_url' );
  26. $remote_opt['headers']['Content-Type'] = 'application/rss+xml';
  27. $remote_opt['headers']['Content-Type'] .= '; charset=' . get_option( 'blog_charset' );
  28. @load_template( ABSPATH . WPINC . '/feed-rss2.php' );
  29. } elseif ( $feed_type == 'atom' ) {
  30. do_action( 'pushpress_send_ping_atom' );
  31. $feed_url = get_bloginfo( 'atom_url' );
  32. $remote_opt['headers']['Content-Type'] = 'application/atom+xml';
  33. $remote_opt['headers']['Content-Type'] .= '; charset=' . get_option( 'blog_charset' );
  34. @load_template( ABSPATH . WPINC . '/feed-atom.php' );
  35. }
  36. $remote_opt['body'] = ob_get_contents( );
  37. ob_end_clean( );
  38. // Figure out the signatur header if we have a secret on
  39. // on file for this callback
  40. if ( !empty( $secret ) ) {
  41. $remote_opt['headers']['X-Hub-Signature'] = 'sha1=' . hash_hmac(
  42. 'sha1', $remote_opt['body'], $secret
  43. );
  44. }
  45. $response = wp_remote_post( $callback, $remote_opt );
  46. // look for failures
  47. if ( is_wp_error( $result ) ) {
  48. do_action( 'pushpress_ping_wp_error' );
  49. return FALSE;
  50. }
  51. if ( isset( $response->errors['http_request_failed'][0] ) ) {
  52. do_action( 'pushpress_ping_http_failure' );
  53. return FALSE;
  54. }
  55. $status_code = (int) $response['response']['code'];
  56. if ( $status_code < 200 || $status_code > 299 ) {
  57. do_action( 'pushpress_ping_not_2xx_failure' );
  58. $pushpress->unsubscribe_callback( $feed_url, $callback );
  59. return FALSE;
  60. }
  61. } // function send_ping
  62. } // if !function_exists