|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Sketchfab.php |
|
4
|
|
|
* |
|
5
|
|
|
* @package Providers |
|
6
|
|
|
* @author Michael Pratt <[email protected]> |
|
7
|
|
|
* @link http://www.michael-pratt.com/ |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Embera\Providers; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The sketchfab.com Provider |
|
17
|
|
|
* @link http://sketchfab.com |
|
18
|
|
|
*/ |
|
19
|
|
|
class Sketchfab extends \Embera\Adapters\Service |
|
20
|
|
|
{ |
|
21
|
|
|
/** inline {@inheritdoc} */ |
|
22
|
|
|
protected $apiUrl = 'https://sketchfab.com/oembed'; |
|
23
|
|
|
|
|
24
|
|
|
/** inline {@inheritdoc} */ |
|
25
|
2 |
|
protected function validateUrl() |
|
26
|
|
|
{ |
|
27
|
2 |
|
$this->url->stripLastSlash(); |
|
28
|
|
|
|
|
29
|
|
|
return ( |
|
30
|
2 |
|
preg_match('~sketchfab\.com/models/(?:[^/]+)$~i', $this->url) || |
|
31
|
2 |
|
preg_match('~sketchfab\.com/(?:[^/]+)/folders/(?:[^/]+)$~i', $this->url) |
|
32
|
2 |
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** inline {@inheritdoc} */ |
|
36
|
2 |
|
protected function normalizeUrl() |
|
37
|
|
|
{ |
|
38
|
2 |
|
$this->url->stripWWW(); |
|
39
|
2 |
|
$this->url->convertToHttps(); |
|
40
|
|
|
|
|
41
|
|
|
// old urls |
|
42
|
2 |
|
if (preg_match('~sketchfab\.com/show/([^/]+)/?$~i', $this->url, $matches)) { |
|
43
|
2 |
|
$this->url = new \Embera\Url('https://sketchfab.com/models/' . $matches[1]); |
|
44
|
2 |
|
} else if (preg_match('~(/embed/?)$~', $this->url)) { |
|
45
|
2 |
|
$this->url = new \Embera\Url(preg_replace('~(/embed/?)$~', '', $this->url)); |
|
|
|
|
|
|
46
|
2 |
|
} |
|
47
|
2 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** inline {@inheritdoc} */ |
|
50
|
2 |
|
protected function modifyResponse(array $response = array()) |
|
51
|
|
|
{ |
|
52
|
2 |
|
if (!empty($response['html'])) { |
|
53
|
2 |
|
$response['html'] = preg_replace('~<p(.*)>(.*)</p>~is', '', $response['html']); |
|
54
|
2 |
|
} |
|
55
|
|
|
|
|
56
|
2 |
|
return $response; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** inline {@inheritdoc} */ |
|
60
|
2 |
|
public function fakeResponse() |
|
61
|
|
|
{ |
|
62
|
2 |
|
if (preg_match('~sketchfab\.com/(?:[^/]+)/folders/([^/]+)$~i', $this->url, $m)) { |
|
63
|
1 |
|
$url = 'https://sketchfab.com/playlists/embed?folder=' . $m['1']; |
|
64
|
1 |
|
} else { |
|
65
|
1 |
|
$url = str_replace('/show/', '/embed/', $this->url) . '/embed'; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return array( |
|
69
|
2 |
|
'type' => 'rich', |
|
70
|
2 |
|
'provider_name' => 'Sketchfab', |
|
71
|
2 |
|
'provider_url' => 'http://sketchfab.com', |
|
72
|
2 |
|
'html' => '<iframe width="{width}" height="{height}" src="' . $url . '" frameborder="0" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>' |
|
73
|
2 |
|
); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
?> |
|
|
|
|
|
|
78
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.