|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Instagram.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 instragram.com Provider |
|
17
|
|
|
* @link https://instagram.com |
|
18
|
|
|
*/ |
|
19
|
|
|
class Instagram extends \Embera\Adapters\Service |
|
20
|
|
|
{ |
|
21
|
|
|
/** inline {@inheritdoc} */ |
|
22
|
|
|
protected $apiUrl = 'http://api.instagram.com/oembed?format=json'; |
|
23
|
|
|
|
|
24
|
|
|
/** inline {@inheritdoc} */ |
|
25
|
2 |
|
protected function validateUrl() |
|
26
|
|
|
{ |
|
27
|
2 |
|
$this->url->stripQueryString(); |
|
28
|
2 |
|
return (preg_match('~/p/([A-Za-z0-9-_]+)/?$~i', $this->url)); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** inline {@inheritdoc} */ |
|
32
|
2 |
|
protected function modifyResponse(array $response = array()) |
|
33
|
|
|
{ |
|
34
|
2 |
|
if (empty($response['html']) && !empty($response['url'])) { |
|
35
|
|
|
$extension = strtolower(pathinfo(parse_url($response['url'],PHP_URL_PATH),PATHINFO_EXTENSION)); |
|
36
|
|
|
if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) { |
|
37
|
|
|
$html = '<a href="' . $response['url'] . '" target="_blank">'; |
|
38
|
|
|
$html .= '<img class="instagram-oembed" src="' . $response['url'] . '" width="' . $response['width'] . '" height="' . $response['height'] . '" alt="' . htmlspecialchars($response['title'], ENT_QUOTES, 'UTF-8') . '" title="' . htmlspecialchars($response['title'], ENT_QUOTES, 'UTF-8') . '">'; |
|
39
|
|
|
$html .= '</a>'; |
|
40
|
|
|
$response['html'] = $html; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
2 |
|
return $response; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
?> |
|
|
|
|
|
|
49
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.