protected function updateTwitter($items) { // Get the user $users = new Users(); $shortUrl = new ShortUrl(); $user = $users->getUser($this->getUserID()); // Get twitter consumer tokens and user secrets $config = Zend_Registry::get("configuration"); $consumer_key = $config->twitter->consumer_key; $consumer_secret = $config->twitter->consumer_secret; // Get twitter credentials $properties = new Properties(array(Properties::KEY => $user->id)); $auth = $properties->getProperty('twitter_auth'); $services = $properties->getProperty('twitter_services'); $oauth_token = $properties->getProperty('twitter_oauth_token'); $oauth_token_secret = $properties->getProperty('twitter_oauth_token_secret'); if (!$consumer_key || !$consumer_secret || !$oauth_token || !$oauth_token_secret) { return; } $has_preamble = $properties->getProperty('preamble', true); // Return if not all conditions are met if (!$auth || !in_array($this->getID(), unserialize($services))) { return; } // Get an item $count = count($items); $data = new Data(); $source_id = $this->_source['id']; if ($count <= 3) { foreach($items as $id) { $item = $data->getItem($source_id, $id); $title = strip_tags($item->getTitle()); $service = $this->getServiceName(); if (($item->getType() == SourceItem::STATUS_TYPE ) && strlen($title) < 140) { $tweet = $title; } else { $preamble = $has_preamble ? $item->getPreamble() : ""; $tweet = $preamble . $title; $url = $users->getUrl($user->id, "s/" . $shortUrl->shorten($item->getSlug())); if (strlen($tweet) + strlen($url) > 140) { $tweet = substr($tweet, 0, 140 - strlen($url) - 5) . "... $url"; } else { $tweet = "$tweet $url"; } } try { $connection = new TwitterOAuth_Client($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret); $response = $connection->post('statuses/update', array('status' => $tweet)); } catch (Exception $e) {} } } else { $url = $users->getUrl($user->id); $tweet = sprintf($this->_update_tweet, $count, $url); try { $twitter = new Stuffpress_Services_Twitter($username, $password); $twitter->sendTweet($tweet); } catch (Exception $e) {} } }
protected function updateTwitter($items) { // Get the user $users = new Users(); $user = $users->getUser($this->getUserID()); // Get twitter credentials $properties = new Properties(array(Properties::KEY => $user->id)); $auth = $properties->getProperty('twitter_auth'); $services = $properties->getProperty('twitter_services'); $username = $properties->getProperty('twitter_username'); $password = $properties->getProperty('twitter_password'); $has_preamble = $properties->getProperty('preamble', true); // Return if not all conditions are met if (!$auth || !in_array($this->getID(), unserialize($services))) { return; } // Get an item $count = count($items); $data = new Data(); $source_id = $this->_source['id']; if ($count <= 3) { foreach ($items as $id) { $item = $data->getItem($source_id, $id); $title = strip_tags($item->getTitle()); $service = $this->getServiceName(); if ($item->getType() == SourceItem::STATUS_TYPE && strlen($title) < 140) { $tweet = $title; } else { $preamble = $has_preamble ? $item->getPreamble() : ""; $tweet = $preamble . $title; $url = $users->getUrl($user->id, "/entry/" . $item->getSlug()); if (strlen($tweet) + strlen($url) > 140) { $tweet = substr($tweet, 0, 140 - strlen($url) - 5) . "... {$url}"; } else { $tweet = "{$tweet} {$url}"; } } try { $twitter = new Stuffpress_Services_Twitter($username, $password); $twitter->sendTweet($tweet); } catch (Exception $e) { } } } else { $url = $users->getUrl($user->id); $tweet = sprintf($this->_update_tweet, $count, $url); try { $twitter = new Stuffpress_Services_Twitter($username, $password); $twitter->sendTweet($tweet); } catch (Exception $e) { } } }
private function notifyTwitter($item) { // Get twitter credentials $username = $this->_properties->getProperty('twitter_username'); $password = $this->_properties->getProperty('twitter_password'); $has_preamble = $this->_properties->getProperty('preamble', true); // Get item $preamble = $has_preamble ? $item->getPreamble() : ""; $title = $preamble . $item->getTitle(); // Assemble tweet depending on type if ($item->getType() == SourceItem::STATUS_TYPE && strlen($title) < 140) { $tweet = $title; } else { $users = new Users(); $url = $users->getUrl($this->_application->user->id, "/entry/" . $item->getSlug()); if (strlen($title) + strlen($url) > 140) { $tweet = substr($title, 0, 140 - strlen($url) - 5) . "... {$url}"; } else { $tweet = "{$title} {$url}"; } } try { $twitter = new Stuffpress_Services_Twitter($username, $password); $twitter->sendTweet($tweet); } catch (Exception $e) { // } }
private function notifyTwitter($item_id, $source_id) { // Get twitter credentials $username = $this->_properties->getProperty('twitter_username'); $password = $this->_properties->getProperty('twitter_password'); $preamble = $this->_properties->getProperty('preamble', true); // Get item $data = new Data(); $item = $data->getItem($source_id, $item_id); $pream = $preamble ? $item->getPreamble() : ""; $title = $pream . $item->getTitle(); // Assemble tweet depending on type if ($item->getType() == SourceItem::STATUS_TYPE && strlen($title) < 140) { $tweet = $title; } else { if (strlen($title) > 121) { $title = substr($title, 0, 117) . "[..]"; } $db_ShortUrls = new ShortUrls(); $hash = $db_ShortUrls->addUrlForItem($this->_user->id, $source_id, $item_id); $tweet = "{$title} http://st.tl/{$hash}"; } try { $twitter = new Stuffpress_Services_Twitter($username, $password); $twitter->sendTweet($tweet); } catch (Exception $e) { throw new Stuffpress_Exception("Twitter notification generated exception {$e}"); } }
private function notifyTwitter($item) { // Get twitter credentials $username = $this->_properties->getProperty('twitter_username'); $password = $this->_properties->getProperty('twitter_password'); $has_preamble = $this->_properties->getProperty('preamble', true); // Get item $item = $data->getItem($source_id, $item_id); $preamble = $has_preamble ? $item->getPreamble() : ""; $title = $preamble . $item->getTitle(); // Assemble tweet depending on type if ($item->getType() == SourceItem::STATUS_TYPE && strlen($title) < 140) { $tweet = $title; } else { if (strlen($title) > 121) { $title = substr($title, 0, 110) . "[..]"; } $db_ShortUrls = new ShortUrls(); //$hash = $db_ShortUrls->addUrlForItem($this->_application->user->id, $source_id, $item_id); $link = $this->getUrl($username, "/entry/" . $item->getSlug()); $tweet = "{$title} {$link}"; } try { $twitter = new Stuffpress_Services_Twitter($username, $password); $twitter->sendTweet($tweet); } catch (Exception $e) { // } }