/** * Retrieve a retweeting user's timeline * @param array $retweeted_status * @param User $user_with_retweet */ private function fetchUserTimelineForRetweet($retweeted_status, $user_with_retweet) { $retweeted_status_id = $retweeted_status["post_id"]; $status_message = ""; if ($this->api->available && $this->api->available_api_calls_for_crawler > 0) { $stream_with_retweet = str_replace("[id]", $user_with_retweet->username, $this->api->cURL_source['user_timeline']); $args = array(); $args["count"] = 200; $args["include_rts"] = "true"; list($cURL_status, $twitter_data) = $this->api->apiRequest($stream_with_retweet, $args); if ($cURL_status == 200) { try { $count = 0; $tweets = $this->api->parseXML($twitter_data); if (count($tweets) > 0) { $pd = DAOFactory::getDAO('PostDAO'); foreach ($tweets as $tweet) { if (RetweetDetector::isRetweet($tweet['post_text'], $this->owner_object->username)) { $this->logger->logStatus("Retweet by " . $tweet['user_name'] . " found, " . substr($tweet['post_text'], 0, 50) . "... ", get_class($this)); if (RetweetDetector::isRetweetOfTweet($tweet["post_text"], $retweeted_status["post_text"])) { $tweet['in_retweet_of_post_id'] = $retweeted_status_id; $this->logger->logStatus("Retweet by " . $tweet['user_name'] . " of " . $this->owner_object->username . " original status ID found: " . $retweeted_status_id, get_class($this)); } else { $this->logger->logStatus("Retweet by " . $tweet['user_name'] . " of " . $this->owner_object->username . " original status ID NOT found: " . $retweeted_status["post_text"] . " NOT a RT of: " . $tweet["post_text"], get_class($this)); } } if ($pd->addPost($tweet, $user_with_retweet, $this->logger) > 0) { $count++; //expand and insert links contained in tweet $this->processTweetURLs($tweet); $this->user_dao->updateUser($user_with_retweet); } } $this->logger->logStatus(count($tweets) . " tweet(s) found in usertimeline via retweet for " . $user_with_retweet->username . " and {$count} saved", get_class($this)); } } catch (Exception $e) { $this->logger->logStatus($e->getMessage(), get_class($this)); $this->logger->logStatus('Could not parse timeline for retweets XML for ' . $user_with_retweet->username, get_class($this)); } } elseif ($cURL_status == 401) { //not authorized to see user timeline //don't set API to unavailable just because a private user retweeted $this->api->available = true; $status_message .= 'Not authorized to see ' . $user_with_retweet->username . "'s timeline;moving on."; } else { $status_message .= 'API returned error code ' . $cURL_status; } } else { $status_message .= 'Crawler API error: either call limit exceeded or API returned an error.'; } $this->logger->logStatus($status_message, get_class($this)); }
/** * Retrieve a retweeting user's timeline * @param array $retweeted_status * @param User $user_with_retweet */ private function fetchUserTimelineForRetweet($retweeted_status, $user_with_retweet) { $retweeted_status_id = $retweeted_status["post_id"]; $status_message = ""; if ($this->api->available && $this->api->available_api_calls_for_crawler > 0) { $stream_with_retweet = str_replace("[id]", $user_with_retweet->username, $this->api->cURL_source['user_timeline']); $args = array(); $count_arg = isset($this->twitter_options['tweet_count_per_call']) ? $this->twitter_options['tweet_count_per_call']->option_value : 100; $args['count'] = $count_arg; $args["include_rts"] = "true"; try { list($cURL_status, $twitter_data) = $this->api->apiRequest($stream_with_retweet, $args); } catch (APICallLimitExceededException $e) { return; } if ($cURL_status == 200) { $count = 0; $tweets = $this->api->parseXML($twitter_data); if (count($tweets) > 0) { $post_dao = DAOFactory::getDAO('PostDAO'); foreach ($tweets as $tweet) { // The parser now processes native retweet information for posts (and includes the // orig post in the parsed data if there was a RT). This method can now take advantage // of this additional processing. // If it was detected that this tweet was a native RT during parsing of the xml, the // 'in_retweet_of_post_id' value should already be set. If it is not set, go through the // usual procedure to try to find it. // This is just an efficiency fix, since if 'in_retweet_of_post_id' *is* set, it's not // going to be unset if the retweet detector doesn't pick up on anything. if (!isset($tweet['in_retweet_of_post_id']) || !$tweet['in_retweet_of_post_id']) { // then try to find rt -- otherwise, information already there if (RetweetDetector::isRetweet($tweet['post_text'], $this->user->username)) { $this->logger->logInfo("Retweet by " . $tweet['user_name'] . " found, " . substr($tweet['post_text'], 0, 50) . "... ", __METHOD__ . ',' . __LINE__); if (RetweetDetector::isRetweetOfTweet($tweet["post_text"], $retweeted_status["post_text"])) { $tweet['in_retweet_of_post_id'] = $retweeted_status_id; $this->logger->logInfo("Retweet by " . $tweet['user_name'] . " of " . $this->user->username . " original status ID found: " . $retweeted_status_id, __METHOD__ . ',' . __LINE__); } else { $this->logger->logInfo("Retweet by " . $tweet['user_name'] . " of " . $this->user->username . " original status ID NOT found: " . $retweeted_status["post_text"] . " NOT a RT of: " . $tweet["post_text"], __METHOD__ . ',' . __LINE__); } } } // an 'else' clause (if 'in_retweet_of_post_id' WAS set) can be used to log // diagnostic information. Leaving in as example for now. // else { // // $rtp = $tweet['retweeted_post']['content']; // $this->logger->logDebug("Post " . $tweet['post_id'] . //", " . $tweet['post_text'] . // " from " . $tweet['user_name'] . // " is rt of " . $tweet['in_retweet_of_post_id'],// . ", ". $rtp['post_text'], // __METHOD__.','.__LINE__); // } $inserted_post_key = $post_dao->addPost($tweet, $user_with_retweet, $this->logger); if ($inserted_post_key !== false) { $count++; //expand and insert links contained in tweet URLProcessor::processPostURLs($tweet['post_text'], $tweet['post_id'], 'twitter', $this->logger); $this->user_dao->updateUser($user_with_retweet); } } $this->logger->logInfo(count($tweets) . " tweet(s) found in usertimeline via retweet for " . $user_with_retweet->username . " and {$count} saved", __METHOD__ . ',' . __LINE__); } } elseif ($cURL_status == 401) { //not authorized to see user timeline //don't set API to unavailable just because a private user retweeted $this->api->available = true; $status_message .= 'Not authorized to see ' . $user_with_retweet->username . "'s timeline;moving on."; $this->logger->logInfo($status_message, __METHOD__ . ',' . __LINE__); } } }
/** * Retrieve a retweeting user's timeline * @param array $retweeted_status * @param User $user_with_retweet */ private function fetchUserTimelineForRetweet($retweeted_status, $user_with_retweet) { $retweeted_status_id = $retweeted_status["post_id"]; $status_message = ""; if ($this->api->available && $this->api->available_api_calls_for_crawler > 0) { $stream_with_retweet = str_replace("[id]", $user_with_retweet->username, $this->api->cURL_source['user_timeline']); $args = array(); $args["count"] = 200; $args["include_rts"]="true"; list($cURL_status, $twitter_data) = $this->api->apiRequest($stream_with_retweet, $args); if ($cURL_status == 200) { $count = 0; $tweets = $this->api->parseXML($twitter_data); if (count($tweets) > 0) { $pd = DAOFactory::getDAO('PostDAO'); foreach ($tweets as $tweet) { if (RetweetDetector::isRetweet($tweet['post_text'], $this->user->username)) { $this->logger->logInfo("Retweet by ".$tweet['user_name']. " found, ". substr($tweet['post_text'], 0, 50)."... ", __METHOD__.','.__LINE__); if ( RetweetDetector::isRetweetOfTweet($tweet["post_text"], $retweeted_status["post_text"]) ){ $tweet['in_retweet_of_post_id'] = $retweeted_status_id; $this->logger->logInfo("Retweet by ".$tweet['user_name']." of ". $this->user->username." original status ID found: ".$retweeted_status_id, __METHOD__.','.__LINE__); } else { $this->logger->logInfo("Retweet by ".$tweet['user_name']." of ". $this->user->username." original status ID NOT found: ". $retweeted_status["post_text"]." NOT a RT of: ". $tweet["post_text"], __METHOD__.','.__LINE__); } } if ($pd->addPost($tweet, $user_with_retweet, $this->logger) > 0) { $count++; //expand and insert links contained in tweet URLProcessor::processTweetURLs($this->logger, $tweet); $this->user_dao->updateUser($user_with_retweet); } } $this->logger->logInfo(count($tweets)." tweet(s) found in usertimeline via retweet for ". $user_with_retweet->username." and $count saved", __METHOD__.','.__LINE__); } } elseif ($cURL_status == 401) { //not authorized to see user timeline //don't set API to unavailable just because a private user retweeted $this->api->available = true; $status_message .= 'Not authorized to see '.$user_with_retweet->username."'s timeline;moving on."; $this->logger->logInfo($status_message, __METHOD__.','.__LINE__); } } }