*/
class Tweeper {
- private static $userAgent = "Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J)";
+ private static $userAgent = "Mozilla/5.0";
private static $maxConnectionTimeout = 5;
private static $maxConnectionRetries = 5;
/**
* Get the contents from a URL.
*/
- private static function getUrlContents($url) {
+ private static function getUrlContents($url, $user_agent = NULL) {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_HEADER => FALSE,
CURLOPT_COOKIEFILE => "",
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => ['Accept-language: en'],
- CURLOPT_USERAGENT => Tweeper::$userAgent,
+ CURLOPT_USERAGENT => isset($user_agent) ? $user_agent : Tweeper::$userAgent,
]);
$contents = Tweeper::curlExec($ch);
curl_close($ch);
/**
* Get the headers from a URL.
*/
- private static function getUrlInfo($url) {
+ private static function getUrlInfo($url, $user_agent = NULL) {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_HEADER => TRUE,
// Follow http redirects to get the real URL.
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
- CURLOPT_USERAGENT => Tweeper::$userAgent,
+ CURLOPT_USERAGENT => isset($user_agent) ? $user_agent : Tweeper::$userAgent,
]);
$ret = Tweeper::curlExec($ch);
return NULL;
}
- $html = Tweeper::getUrlContents($src_url);
+ // Override User-Agent for twitter.com to force it to serve the mobile UI.
+ if ($host == "twitter.com") {
+ $user_agent = "Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J)";
+ }
+ else {
+ $user_agent = NULL;
+ }
+
+ $html = Tweeper::getUrlContents($src_url, $user_agent);
if (FALSE === $html) {
trigger_error("Failed to retrieve $src_url", E_USER_WARNING);
return NULL;