[TwitterBridge] Optimise regular expression code (#1768)
* [TwitterBridge] Optimise regular expression code Optimise regular expression search code so adding new URLs is cleaner
This commit is contained in:
parent
47dc26c775
commit
d3455dd18a
1 changed files with 13 additions and 15 deletions
|
@ -424,24 +424,22 @@ EOD;
|
||||||
if($data === null || (time() - $refresh) > self::GUEST_TOKEN_EXPIRY) {
|
if($data === null || (time() - $refresh) > self::GUEST_TOKEN_EXPIRY) {
|
||||||
$twitterPage = getContents('https://twitter.com');
|
$twitterPage = getContents('https://twitter.com');
|
||||||
|
|
||||||
$jsMainRegex = '/(https:\/\/abs\.twimg\.com\/responsive-web\/web\/main\.[^\.]+\.js)/m';
|
$jsLink = false;
|
||||||
preg_match_all($jsMainRegex, $twitterPage, $jsMainMatches, PREG_SET_ORDER, 0);
|
$jsMainRegexArray = array(
|
||||||
if (!$jsMainMatches) {
|
'/(https:\/\/abs\.twimg\.com\/responsive-web\/web\/main\.[^\.]+\.js)/m',
|
||||||
$jsMainRegex = '/(https:\/\/abs\.twimg\.com\/responsive-web\/web_legacy\/main\.[^\.]+\.js)/m';
|
'/(https:\/\/abs\.twimg\.com\/responsive-web\/web_legacy\/main\.[^\.]+\.js)/m',
|
||||||
preg_match_all($jsMainRegex, $twitterPage, $jsMainMatches, PREG_SET_ORDER, 0);
|
'/(https:\/\/abs\.twimg\.com\/responsive-web\/client-web\/main\.[^\.]+\.js)/m',
|
||||||
|
'/(https:\/\/abs\.twimg\.com\/responsive-web\/client-web-legacy\/main\.[^\.]+\.js)/m',
|
||||||
|
);
|
||||||
|
foreach ($jsMainRegexArray as $jsMainRegex) {
|
||||||
|
if (preg_match_all($jsMainRegex, $twitterPage, $jsMainMatches, PREG_SET_ORDER, 0)) {
|
||||||
|
$jsLink = $jsMainMatches[0][0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!$jsMainMatches) {
|
if (!$jsLink) {
|
||||||
$jsMainRegex = '/(https:\/\/abs\.twimg\.com\/responsive-web\/client-web\/main\.[^\.]+\.js)/m';
|
|
||||||
preg_match_all($jsMainRegex, $twitterPage, $jsMainMatches, PREG_SET_ORDER, 0);
|
|
||||||
}
|
|
||||||
if (!$jsMainMatches) {
|
|
||||||
$jsMainRegex = '/(https:\/\/abs\.twimg\.com\/responsive-web\/client-web-legacy\/main\.[^\.]+\.js)/m';
|
|
||||||
preg_match_all($jsMainRegex, $twitterPage, $jsMainMatches, PREG_SET_ORDER, 0);
|
|
||||||
}
|
|
||||||
if (!$jsMainMatches) {
|
|
||||||
returnServerError('Could not locate main.js link');
|
returnServerError('Could not locate main.js link');
|
||||||
}
|
}
|
||||||
$jsLink = $jsMainMatches[0][0];
|
|
||||||
|
|
||||||
$jsContent = getContents($jsLink);
|
$jsContent = getContents($jsLink);
|
||||||
$apiKeyRegex = '/([a-zA-Z0-9]{59}%[a-zA-Z0-9]{44})/m';
|
$apiKeyRegex = '/([a-zA-Z0-9]{59}%[a-zA-Z0-9]{44})/m';
|
||||||
|
|
Loading…
Reference in a new issue