function share($post) { if (self::debug()) { self::log(sprintf("share(%s)", is_object($post) ? $post->post_title : $post)); } if (!is_object($post)) { $post = get_post($post); } if (!in_array($post->post_type, self::supported_post_types())) { return false; } $posted = $error = false; if ($meta = $this->can_post_on_facebook($post)) { // determine if this should be delayed if ($meta['delay_length']) { self::log("Sharing of this post has been delayed {$meta['delay_length']} {$meta['delay_unit']}({$post->ID})"); $time = strtotime("+{$meta['delay_length']} {$meta['delay_unit']}", current_time('timestamp')); update_post_meta($post->ID, self::META_SCHEDULED, $time); $meta['delay_length'] = 0; update_post_meta($post->ID, self::META, $meta); return false; } if (!empty($meta['append_link'])) { if ($meta['message']) { $meta['message'] .= ' - '; } $meta['message'] .= $this->get_permalink($post->ID); } try { // flush the fb cache if (apply_filters('sp_auto_flush_fb', true)) { $poke = self::api('/', 'POST', array('id' => $meta['link'], 'scrape' => 'true')); } // no targets? error. if (!$meta['targets'] && !self::is_business()) { throw new Exception("No publishing Targets selected."); } // first, should we post to the wall? if (self::is_business() || in_array('wall', $meta['targets'])) { $result = self::api(self::me('id') . '/links', 'POST', array('name' => $meta['name'], 'message' => $meta['message'], 'description' => $meta['description'], 'picture' => $meta['picture'], 'link' => $this->get_permalink($post->ID))); self::log(sprintf("posted to the wall: %s", serialize($result))); // store the ID and published date for queuing $result['published'] = time(); $result['message'] = $meta['message']; add_post_meta($post->ID, Sharepress::META_RESULT, $result); } // next, fire the sharepress_post action // the pro version picks this up do_action('sharepress_post', $meta, $post); $this->success($post, $meta); delete_post_meta($post->ID, self::META_SCHEDULED); $posted = true; } catch (Exception $e) { self::err(sprintf("Exception thrown while in share: %s", print_r($e->getResult(), true))); $this->error($post, $meta, $e); $error = true; } } if ($twitter_meta = $this->can_post_on_twitter($post)) { $client = new SharePress_TwitterClient(get_option(self::OPTION_SETTINGS)); $tweet = sprintf('%s %s', $post->post_title, $this->get_bitly_link($post)); if ($hash_tag = trim($twitter_meta['hash_tag'])) { $tweet .= ' ' . $hash_tag; } $result = $client->post($tweet); SharePress::log(sprintf("Tweet Result for Post #{$post->ID}: %s", json_encode($result))); add_post_meta($post->ID, Sharepress::META_TWITTER_RESULT, $result); $posted = true; } if ($posted && !$error) { // success: update_post_meta($post->ID, self::META_POSTED, gmdate('Y-m-d H:i:s')); } }