Exemple #1
0
 /**
  * Handles publishing or updating a post
  *
  * @param  string $post_id the post id
  * @return bool   whether the request worked
  */
 public static function post_notify($post_id)
 {
     global $wpdb;
     $post = get_post($post_id);
     $url = get_permalink($post_id);
     $tags = wp_get_post_tags($post_id, array('fields' => 'names'));
     $categories = array_map(array('ShareaholicNotifier', 'post_notify_iterator'), get_the_category($post_id));
     if (function_exists('has_post_thumbnail') && has_post_thumbnail($post_id)) {
         $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'large');
     } else {
         $featured_image = ShareaholicUtilities::post_first_image();
         if (!$featured_image) {
             $featured_image = '';
         }
     }
     if ($post->post_author) {
         $author_data = get_userdata($post->post_author);
         $author_name = $author_data->display_name;
     }
     $notification = array('url' => $url, 'api_key' => ShareaholicUtilities::get_option('api_key'), 'content' => array('title' => $post->post_title, 'excerpt' => $post->post_excerpt, 'body' => $post->post_content, 'featured-image-url' => $featured_image), 'metadata' => array('author-id' => $post->post_author, 'author-name' => $author_name, 'post-type' => $post->post_type, 'post-id' => $post_id, 'post-tags' => $tags, 'post-categories' => $categories, 'post-language' => get_bloginfo('language'), 'published' => $post->post_date_gmt, 'updated' => get_lastpostmodified('GMT'), 'visibility' => $post->post_status), 'diagnostics' => array('platform' => 'wordpress', 'platform-version' => get_bloginfo('version'), 'shareaholic-version' => Shareaholic::VERSION, 'wp-multisite' => is_multisite(), 'wp-theme' => get_option('template'), 'wp-posts-total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->posts} where post_type = 'post' AND post_status = 'publish'"), 'wp-pages-total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->posts} where post_type = 'page' AND post_status = 'publish'"), 'wp-comments-total' => wp_count_comments()->approved, 'wp-users-total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->users}")));
     return self::send_notification($notification);
 }
Exemple #2
0
 /**
  * Draws an open graph image meta tag if they are enabled and exist. Will only run on pages or posts.
  */
 private static function draw_og_tags()
 {
     if (in_array(ShareaholicUtilities::page_type(), array('page', 'post'))) {
         global $post;
         $thumbnail_src = '';
         $settings = ShareaholicUtilities::get_settings();
         if (!get_post_meta($post->ID, 'shareaholic_disable_open_graph_tags', true) && (isset($settings['disable_og_tags']) && $settings['disable_og_tags'] == "off")) {
             if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
                 $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large');
                 $thumbnail_src = esc_attr($thumbnail[0]);
             }
             if ($thumbnail_src == NULL) {
                 $thumbnail_src = ShareaholicUtilities::post_first_image();
             }
             if ($thumbnail_src != NULL) {
                 echo "\n<!-- Shareaholic Open Graph Tags -->\n";
                 echo "<meta property='og:image' content='" . $thumbnail_src . "' />";
                 echo "\n<!-- Shareaholic Open Graph Tags End -->\n";
             }
         }
     }
 }
Exemple #3
0
 /**
  * Function to return a thumbnail for a given permalink
  *
  * @return thumbnail URL
  */
 public static function permalink_thumbnail($post_id = NULL, $size = "large")
 {
     $thumbnail_src = '';
     // Get Featured Image
     if (function_exists('has_post_thumbnail') && has_post_thumbnail($post_id)) {
         $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size);
         $thumbnail_src = esc_attr($thumbnail[0]);
     }
     // Get first image included in the post
     if ($thumbnail_src == NULL) {
         $thumbnail_src = ShareaholicUtilities::post_first_image();
     }
     if ($thumbnail_src == NULL) {
         return NULL;
     } else {
         return $thumbnail_src;
     }
 }