public static function Fetch($echo = false)
 {
     if ($echo) {
         echo "Fetching updates from Twitter...<br />";
     }
     $twitter_updates = SocialMediaTwitter::Fetch($echo);
     /*if ($echo) echo "Fetching updates from Facebook...<br />";
     		$facebook_updates	= SocialMediaFacebook::Fetch();
     		if ($echo) echo "Fetching updates from LinkedIn...<br />";
     		$linkedin_updates	= SocialMediaLinkedIn::Fetch();*/
     $linkedin_updates = array();
     $facebook_updates = array();
     if (false === $twitter_updates) {
         $twitter_updates = array();
     }
     //If errors happen, don't let them
     if (false === $facebook_updates) {
         $facebook_updates = array();
     }
     //interrupt the array_merge operation.
     if (false === $linkedin_updates) {
         $linkedin_updates = array();
     }
     $updates = array_merge($twitter_updates, $facebook_updates, $linkedin_updates);
     if ($echo) {
         echo count($updates) > 0 ? "Writing " . count($updates) . " updates to the database...<br />" : 'No updates to write to the database.<br />';
     }
     /**
      * @var SocialMediaImporterInterface $importer
      */
     foreach (ClassInfo::implementorsOf('SocialMediaImporterInterface') as $importer) {
         $importer::ImportUpdates($updates);
     }
 }
 private function ToTwitter()
 {
     $link = $this->owner->AbsoluteLink();
     if (mb_strlen($this->plaintext) > self::TwitterMaxStatusLength - mb_strlen($link) - 1) {
         $length = self::TwitterMaxStatusLength - mb_strlen($link);
         $truncate = mb_substr($this->plaintext, 0, $length - 4) . '... ';
         $content = $truncate . $link;
     } else {
         $content = $this->plaintext . ' ' . $link;
     }
     $data = SocialMediaTwitter::Connection()->post('statuses/update', array('status' => $content, 'trim_user' => true));
     if (SocialMediaTwitter::Error()) {
         return false;
     }
     $this->owner->TwitterID = $data->id;
     return true;
 }
 public static function Connection()
 {
     if (self::$connection) {
         return self::$connection;
     }
     $config = self::config();
     $consumer_key = $config->consumer_key;
     $consumer_secret = $config->consumer_secret;
     $oauth_token = $config->oauth_token;
     $oauth_token_secret = $config->oauth_token_secret;
     if (empty($consumer_key) || empty($consumer_secret) || empty($oauth_token) || empty($oauth_token_secret)) {
         throw new Exception(__METHOD__ . '(): Twitter credentials do not exist in the configuration.');
     }
     self::$connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
     self::$connection->setTimeouts(30, 30);
     //Test the connection
     $response = self::$connection->get('account/verify_credentials');
     if (self::Error()) {
         throw new Exception(__METHOD__ . '(): Connection failed. ' . self::ErrorMessage($response));
     }
     return self::$connection;
 }