mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 10:02:02 -04:00
Resolve Google Groups URL redirects
This commit is contained in:
parent
9b959e3eda
commit
7aa610168d
1 changed files with 19 additions and 0 deletions
|
@ -218,6 +218,25 @@ final class Project{
|
||||||
$this->DiscussionUrl = null;
|
$this->DiscussionUrl = null;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
if(preg_match('|^https://groups\.google\.com/d/msgid/|iu', $this->DiscussionUrl)){
|
||||||
|
// This URL links to a message which will perform some HTTP redirects to resolve to the actual thread URL.
|
||||||
|
// Resolve that URL before continuing.
|
||||||
|
$curl = curl_init();
|
||||||
|
|
||||||
|
curl_setopt($curl, CURLOPT_HEADER, true);
|
||||||
|
curl_setopt($curl, CURLOPT_NOBODY, true);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||||||
|
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $this->DiscussionUrl);
|
||||||
|
curl_exec($curl);
|
||||||
|
|
||||||
|
/** @var string $url */
|
||||||
|
$url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
|
||||||
|
|
||||||
|
$this->DiscussionUrl = $url;
|
||||||
|
}
|
||||||
|
|
||||||
if(preg_match('|^https://groups\.google\.com/g/standardebooks/|iu', $this->DiscussionUrl)){
|
if(preg_match('|^https://groups\.google\.com/g/standardebooks/|iu', $this->DiscussionUrl)){
|
||||||
// Get the base thread URL in case we were passed a URL with a specific message or query string.
|
// Get the base thread URL in case we were passed a URL with a specific message or query string.
|
||||||
$this->DiscussionUrl = preg_replace('|^(https://groups\.google\.com/g/standardebooks/c/[^/]+).*|iu', '\1', $this->DiscussionUrl);
|
$this->DiscussionUrl = preg_replace('|^(https://groups\.google\.com/g/standardebooks/c/[^/]+).*|iu', '\1', $this->DiscussionUrl);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue