Skip to content

Commit 5e4ca41

Browse files
committed
Created UrlJsRedirect class due to links redirecting by javascript instead of http headers
1 parent 64e4b6c commit 5e4ca41

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Embed/Url.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function __wakeup () {
4848
* Resolve the possible redirects for this url (for example bit.ly or any other url shortcutter)
4949
*/
5050
private function resolve () {
51+
UrlJsRedirect::resolve($this);
52+
5153
$connection = curl_init();
5254

5355
curl_setopt_array($connection, array(
@@ -532,8 +534,10 @@ private function buildUrl ($maintainCache = false) {
532534
if (isset($this->info['host'])) {
533535
$url .= $this->info['host'];
534536
}
535-
536-
$url .= '/'.$this->getPath();
537+
538+
if (($path = $this->getPath())) {
539+
$url .= '/'.$path;
540+
}
537541

538542
if (isset($this->info['file'])) {
539543
$url .= '/'.$this->info['file'];

Embed/UrlJsRedirect.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Class to manipulate urls
4+
*/
5+
namespace Embed;
6+
7+
class UrlJsRedirect {
8+
protected static $urls = array(
9+
'google' => 'https?://www.google.com/url*'
10+
);
11+
12+
public static function resolve (Url $Url) {
13+
foreach (static::$urls as $method => $matches) {
14+
if ($Url->match($matches)) {
15+
static::$method($Url);
16+
17+
return true;
18+
}
19+
}
20+
21+
return false;
22+
}
23+
24+
protected static function google (Url $Url) {
25+
if (($url = $Url->getParameter('url'))) {
26+
$Url->setUrl($url);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)