2013-10-29 09:26:48 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* RssBridgeInstagram
|
|
|
|
* Returns the newest photos
|
|
|
|
*
|
|
|
|
* @name Instagram Bridge
|
|
|
|
* @description Returns the newest images
|
|
|
|
* @use1(u="username")
|
|
|
|
*/
|
|
|
|
class InstagramBridge extends BridgeAbstract{
|
|
|
|
|
|
|
|
private $request;
|
|
|
|
|
|
|
|
public function collectData(array $param){
|
|
|
|
$html = '';
|
|
|
|
if (isset($param['u'])) { /* user timeline mode */
|
|
|
|
$this->request = $param['u'];
|
|
|
|
$text = file_get_contents('http://instagram.com/'.urlencode($this->request)) or $this->returnError('Could not request Instagram.', 404);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->returnError('You must specify a Instagram username (?u=...).', 400);
|
|
|
|
}
|
|
|
|
|
2013-10-29 10:40:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
$image = '"(\w+)":\{"url":"(http:[^"]+)","width":(\d+),"height":(\d+)\}';
|
2013-10-29 09:26:48 +01:00
|
|
|
|
2013-10-29 10:40:31 +01:00
|
|
|
if (preg_match_all('/"created_time":"(\d+)"\s*,\s*"images":\{'.$image.','.$image.','.$image.'\}/', $text, $matches))
|
2013-10-29 09:26:48 +01:00
|
|
|
{
|
|
|
|
foreach($matches[0] as $key => $dummy)
|
|
|
|
{
|
2013-10-29 10:40:31 +01:00
|
|
|
$timestamp = (int) $matches[1][$key];
|
|
|
|
$images = array();
|
|
|
|
|
|
|
|
$pos = 2;
|
|
|
|
for($i = 0; $i < 3; $i++)
|
|
|
|
{
|
|
|
|
$imagetype = $matches[$pos++][$key];
|
|
|
|
|
|
|
|
$images[$imagetype] = array(
|
|
|
|
'url' => stripslashes($matches[$pos++][$key]),
|
|
|
|
'width' => (int) $matches[$pos++][$key],
|
|
|
|
'height' => (int) $matches[$pos++][$key]
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2013-10-29 09:26:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
$item = new \Item();
|
2013-10-29 10:40:31 +01:00
|
|
|
$item->uri = $images['standard_resolution']['url'];
|
|
|
|
$item->content = '<img src="' . htmlentities($images['standard_resolution']['url']) . '" width="'.$images['standard_resolution']['width'].'" height="'.$images['standard_resolution']['height'].'" />';
|
|
|
|
$item->title = basename($images['standard_resolution']['url']);
|
|
|
|
$item->timestamp = $timestamp;
|
2013-10-29 09:26:48 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(){
|
|
|
|
return (!empty($this->request) ? $this->request .' - ' : '') .'Instagram Bridge';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI(){
|
|
|
|
return 'http://instagram.com/';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
|
|
|
return 21600; // 6 hours
|
|
|
|
}
|
|
|
|
}
|