/** * Publish a new post to Facebook * @param Model_Blog_Post The post */ public function new_post(Model_Blog_Post $post) { $config = Kohana::$config->load('social.facebook'); // No configuration? if (empty($config) || empty($config['access_token'])) { return; } $message = strip_tags($post->content()); if (strlen($message) > self::POST_LENGTH) { $message = substr($message, 0, self::POST_LENGTH) . '...'; } $data = array('access_token' => $config['access_token'], 'message' => $post->title, 'link' => $post->url(true), 'picture' => 'http://example.com/', 'name' => $post->title, 'description' => $message); $data = http_build_query($data); $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => implode("\r\n", array('Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen($data), '')), 'user_agent' => 'Daniel15 Blog FacebookPost +dan.cx', 'content' => $data, 'ignore_errors' => true))); return file_get_contents(self::POST_URL, false, $context); }
/** * Publish a new post to Twitter * @param Model_Blog_Post The post */ public function new_post(Model_Blog_Post $post) { $config = Kohana::$config->load('social.twitter'); // No configuration? if (empty($config) || empty($config['consumer_key'])) { return; } $status = ''; if (strlen($post->title) > 0) { $status = $post->title . ' - '; } $status .= strip_tags($post->content()); if (strlen($status) > self::TWEET_LENGTH) { $status = substr($status, 0, self::TWEET_LENGTH) . '...'; } $status .= ' ' . $post->short_url(); $oauth = new OAuth($config['consumer_key'], $config['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $oauth->setToken($config['access_token'], $config['access_token_secret']); $oauth->fetch(self::UPDATE_URL, array('status' => $status), OAUTH_HTTP_METHOD_POST, array('User-Agent' => 'Daniel15 Blog TwitterPost')); }