Exemple #1
0
 /**
  * Main function of this plugin called on publish_post action hook
  * 
  *
  * @param   int  $post_ID ID of the new/updated post
  * @return  void
  */
 public static function update_old_post($post_ID)
 {
     $shortcode_title_max_length = MicroblogPoster_Poster::get_shortcode_title_max_length();
     $shortcode_firstwords_max_length = MicroblogPoster_Poster::get_shortcode_firstwords_max_length();
     $shortcode_excerpt_max_length = MicroblogPoster_Poster::get_shortcode_excerpt_max_length();
     $apply_filters = MicroblogPoster_Poster::is_apply_filters_activated();
     $post = get_post($post_ID);
     if ($apply_filters) {
         $post_title = apply_filters('the_title', $post->post_title);
     } else {
         $post_title = $post->post_title;
     }
     $post_title = MicroblogPoster_Poster::shorten_title($post_title, $shortcode_title_max_length, ' ');
     if ($apply_filters) {
         $post_content_actual = apply_filters('the_content', $post->post_content);
     } else {
         $post_content_actual = $post->post_content;
     }
     $post_content_actual_lkn = MicroblogPoster_Poster::clean_up_and_shorten_content($post_content_actual, 350, ' ');
     $post_content_actual_tmb = MicroblogPoster_Poster::shorten_content($post_content_actual, 500, '.');
     $permalink = get_permalink($post_ID);
     $permalink_actual = $permalink;
     $update = $post_title . " {$permalink}";
     $post_thumbnail_id = get_post_thumbnail_id($post_ID);
     $featured_image_src_full = MicroblogPoster_Poster::get_featured_image_src_full($post_thumbnail_id);
     $featured_image_src_thumbnail = MicroblogPoster_Poster::get_featured_image_src_thumbnail($post_thumbnail_id);
     $featured_image_src_medium = MicroblogPoster_Poster::get_featured_image_src_medium($post_thumbnail_id);
     $post_content = array();
     $post_content[] = home_url();
     $post_content[] = $post_title;
     $post_content[] = $permalink;
     $shortened_permalink = '';
     $shortened_permalink_twitter = '';
     $short_url_results = MicroblogPoster_Poster::shorten_long_url($permalink);
     if ($short_url_results['shortened_permalink']) {
         $shortened_permalink = $short_url_results['shortened_permalink'];
         $update = $post_title . " {$shortened_permalink}";
         $permalink = $shortened_permalink;
     }
     if ($short_url_results['shortened_permalink_twitter']) {
         $shortened_permalink_twitter = $short_url_results['shortened_permalink_twitter'];
     }
     $post_content[] = $shortened_permalink;
     $post_excerpt_manual = '';
     if ($apply_filters) {
         $post_excerpt_tmp = apply_filters('the_content', $post->post_excerpt);
         $post_excerpt_tmp = MicroblogPoster_Poster::strip_shortcodes_and_tags($post_excerpt_tmp);
     } else {
         $post_excerpt_tmp = MicroblogPoster_Poster::strip_shortcodes_and_tags($post->post_excerpt);
     }
     if ($post_excerpt_tmp) {
         $post_excerpt_manual = $post_excerpt_tmp;
         $post_content_actual_lkn = $post_excerpt_tmp;
     }
     $post_content[] = $post_excerpt_manual;
     if ($post_excerpt_manual != '') {
         $post_content[] = $post_excerpt_manual;
     } else {
         $post_excerpt = MicroblogPoster_Poster::shorten_content($post_content_actual, $shortcode_excerpt_max_length, '.');
         $post_content[] = $post_excerpt;
     }
     $author = MicroblogPoster_Poster::get_author((int) $post->post_author);
     $post_content[] = $author;
     $post_content_first_words = MicroblogPoster_Poster::clean_up_and_shorten_content($post_content_actual, $shortcode_firstwords_max_length, ' ');
     $post_content[] = $post_content_first_words;
     $post_content_twitter = $post_content;
     $post_content_twitter[3] = $shortened_permalink_twitter;
     $tags = MicroblogPoster_Poster::get_post_tags($post_ID);
     $old = 1;
     $dash = 1;
     $mp = array();
     $mp['val'] = 0;
     $mp['type'] = '';
     @ini_set('max_execution_time', '0');
     MicroblogPoster_Poster::update_twitter($old, $mp, $dash, $update, $post_content_twitter, $post_ID, $featured_image_src_full);
     MicroblogPoster_Poster::update_plurk($old, $mp, $dash, $update, $post_content, $post_ID);
     MicroblogPoster_Poster::update_delicious($old, $mp, $dash, $post_title, $permalink, $tags, $post_content, $post_ID);
     MicroblogPoster_Poster::update_friendfeed($old, $mp, $dash, $post_title, $permalink, $post_content, $post_ID);
     MicroblogPoster_Poster::update_facebook($old, $mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_lkn, $featured_image_src_full);
     MicroblogPoster_Poster::update_diigo($old, $mp, $dash, $post_title, $permalink, $tags, $post_content, $post_ID);
     MicroblogPoster_Poster::update_linkedin($old, $mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_lkn, $featured_image_src_medium);
     MicroblogPoster_Poster::update_tumblr($old, $mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_tmb, $featured_image_src_full);
     MicroblogPoster_Poster::update_blogger($old, $mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_tmb, $featured_image_src_full);
     MicroblogPoster_Poster::update_instapaper($old, $mp, $dash, $post_title, $permalink, $post_content, $post_ID);
     MicroblogPoster_Poster::update_vkontakte($old, $mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_lkn, $featured_image_src_thumbnail, $permalink_actual);
     MicroblogPoster_Poster::update_xing($old, $mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_tmb);
     MicroblogPoster_Poster::maintain_logs();
 }
 /**
  * Main function of this plugin called on publish_post action hook
  * 
  *
  * @param   int  $post_ID ID of the new/updated post
  * @return  void
  */
 public static function update($post_ID)
 {
     //If this time Microblog Poster is disabled return immediatelly
     if ($_POST['microblogposteroff'] == "on") {
         return;
     }
     $post_categories = wp_get_post_categories($post_ID);
     if (is_array($post_categories) && !empty($post_categories)) {
         $excluded_categories_name = "microblogposter_excluded_categories";
         $excluded_categories_value = get_option($excluded_categories_name, "");
         $excluded_categories = json_decode($excluded_categories_value, true);
         if (is_array($excluded_categories) && !empty($excluded_categories)) {
             foreach ($excluded_categories as $cat_id) {
                 if (in_array($cat_id, $post_categories)) {
                     return;
                 }
             }
         }
     }
     $shortcode_title_max_length_name = "microblogposter_plg_shortcode_title_max_length";
     $shortcode_firstwords_max_length_name = "microblogposter_plg_shortcode_firstwords_max_length";
     $shortcode_excerpt_max_length_name = "microblogposter_plg_shortcode_excerpt_max_length";
     $shortcode_title_max_length_value = get_option($shortcode_title_max_length_name, "");
     $shortcode_title_max_length = 110;
     if (intval($shortcode_title_max_length_value) && intval($shortcode_title_max_length_value) >= 30 && intval($shortcode_title_max_length_value) <= 120) {
         $shortcode_title_max_length = $shortcode_title_max_length_value;
     }
     $shortcode_firstwords_max_length_value = get_option($shortcode_firstwords_max_length_name, "");
     $shortcode_firstwords_max_length = 90;
     if (intval($shortcode_firstwords_max_length_value) && intval($shortcode_firstwords_max_length_value) >= 30 && intval($shortcode_firstwords_max_length_value) <= 120) {
         $shortcode_firstwords_max_length = $shortcode_firstwords_max_length_value;
     }
     $shortcode_excerpt_max_length_value = get_option($shortcode_excerpt_max_length_name, "");
     $shortcode_excerpt_max_length = 400;
     if (intval($shortcode_excerpt_max_length_value) && intval($shortcode_excerpt_max_length_value) >= 100 && intval($shortcode_excerpt_max_length_value) <= 600) {
         $shortcode_excerpt_max_length = $shortcode_excerpt_max_length_value;
     }
     $post = get_post($post_ID);
     $post_content_actual = $post->post_content;
     $post_content_actual_lkn = MicroblogPoster_Poster::clean_up_and_shorten_content($post_content_actual, 350, ' ');
     $post_content_actual_tmb = MicroblogPoster_Poster::shorten_content($post_content_actual, 500, '.');
     $post_thumbnail_id = get_post_thumbnail_id($post_ID);
     $featured_image_src = '';
     $featured_image_src_thumbnail = '';
     $featured_image_src_medium = '';
     if ($post_thumbnail_id) {
         $image_attributes = wp_get_attachment_image_src($post_thumbnail_id, 'thumbnail');
         $featured_image_src_thumbnail = $image_attributes[0];
         $image_attributes = wp_get_attachment_image_src($post_thumbnail_id, 'medium');
         $featured_image_src_medium = $image_attributes[0];
     }
     $post_title = $post->post_title;
     $post_title = MicroblogPoster_Poster::shorten_title($post_title, $shortcode_title_max_length, ' ');
     $permalink = get_permalink($post_ID);
     $update = $post_title . " {$permalink}";
     $post_content = array();
     $post_content[] = home_url();
     $post_content[] = $post_title;
     $post_content[] = $permalink;
     $shortened_permalink = '';
     $shortened_permalink_twitter = '';
     $short_url_results = MicroblogPoster_Poster::shorten_long_url($permalink);
     if ($short_url_results['shortened_permalink']) {
         $shortened_permalink = $short_url_results['shortened_permalink'];
         $update = $post_title . " {$shortened_permalink}";
         $permalink = $shortened_permalink;
     }
     if ($short_url_results['shortened_permalink_twitter']) {
         $shortened_permalink_twitter = $short_url_results['shortened_permalink_twitter'];
     }
     $post_content[] = $shortened_permalink;
     $post_excerpt_manual = '';
     $post_excerpt_tmp = MicroblogPoster_Poster::strip_shortcodes_and_tags($post->post_excerpt);
     if ($post_excerpt_tmp) {
         $post_excerpt_manual = $post_excerpt_tmp;
     }
     $post_content[] = $post_excerpt_manual;
     if ($post_excerpt_manual != '') {
         $post_content[] = $post_excerpt_manual;
     } else {
         $post_excerpt = MicroblogPoster_Poster::shorten_content($post_content_actual, $shortcode_excerpt_max_length, '.');
         $post_content[] = $post_excerpt;
     }
     $author = '';
     if (!function_exists('get_user_by')) {
         require_once ABSPATH . WPINC . '/pluggable.php';
     }
     $user_ID = get_current_user_id();
     $loggedin_user = get_user_by('id', $user_ID);
     $author_tmp = $loggedin_user->display_name;
     if ($author_tmp) {
         $author = $author_tmp;
     }
     $post_content[] = $author;
     $post_content_first_words = MicroblogPoster_Poster::clean_up_and_shorten_content($post_content_actual, $shortcode_firstwords_max_length, ' ');
     $post_content[] = $post_content_first_words;
     $post_content_twitter = $post_content;
     $post_content_twitter[3] = $shortened_permalink_twitter;
     $tags = "";
     $posttags = get_the_tags($post_ID);
     if ($posttags) {
         foreach ($posttags as $tag) {
             $tags .= $tag->slug . ',';
         }
     }
     $tags = rtrim($tags, ',');
     $dash = 0;
     if (isset($_POST['mbp_control_dashboard_microblogposter']) && trim($_POST['mbp_control_dashboard_microblogposter']) == '1') {
         $dash = 1;
     }
     $mp = array();
     $mp['val'] = 0;
     $mp['type'] = '';
     @ini_set('max_execution_time', '0');
     MicroblogPoster_Poster::update_twitter($mp, $dash, $update, $post_content_twitter, $post_ID);
     MicroblogPoster_Poster::update_plurk($mp, $dash, $update, $post_content, $post_ID);
     MicroblogPoster_Poster::update_delicious($mp, $dash, $post_title, $permalink, $tags, $post_content, $post_ID);
     MicroblogPoster_Poster::update_friendfeed($mp, $dash, $post_title, $permalink, $post_content, $post_ID);
     MicroblogPoster_Poster::update_facebook($mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_lkn, $featured_image_src_thumbnail);
     MicroblogPoster_Poster::update_diigo($mp, $dash, $post_title, $permalink, $tags, $post_content, $post_ID);
     MicroblogPoster_Poster::update_linkedin($mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_lkn, $featured_image_src_medium);
     MicroblogPoster_Poster::update_tumblr($mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_tmb);
     MicroblogPoster_Poster::update_blogger($mp, $dash, $update, $post_content, $post_ID, $post_title, $permalink, $post_content_actual_tmb);
     MicroblogPoster_Poster::update_instapaper($mp, $dash, $post_title, $permalink, $post_content, $post_ID);
     MicroblogPoster_Poster::maintain_logs();
 }