InstagramBridge.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class InstagramBridge extends BridgeAbstract{
  3. const MAINTAINER = "pauder";
  4. const NAME = "Instagram Bridge";
  5. const URI = "http://instagram.com/";
  6. const DESCRIPTION = "Returns the newest images";
  7. const PARAMETERS = array( array(
  8. 'u'=>array(
  9. 'name'=>'username',
  10. 'required'=>true
  11. )
  12. ));
  13. public function collectData(){
  14. $html = getSimpleHTMLDOM($this->getURI())
  15. or returnServerError('Could not request Instagram.');
  16. $innertext = null;
  17. foreach($html->find('script') as $script)
  18. {
  19. if ('' === $script->innertext) {
  20. continue;
  21. }
  22. $pos = strpos(trim($script->innertext), 'window._sharedData');
  23. if (0 !== $pos)
  24. {
  25. continue;
  26. }
  27. $innertext = $script->innertext;
  28. break;
  29. }
  30. $json = trim(substr($innertext, $pos+18), ' =;');
  31. $data = json_decode($json);
  32. $userMedia = $data->entry_data->ProfilePage[0]->user->media->nodes;
  33. foreach($userMedia as $media)
  34. {
  35. $item = array();
  36. $item['uri'] = self::URI.'p/'.$media->code.'/';
  37. $item['content'] = '<img src="' . htmlentities($media->display_src) . '" />';
  38. if (isset($media->caption))
  39. {
  40. $item['title'] = $media->caption;
  41. } else {
  42. $item['title'] = basename($media->display_src);
  43. }
  44. $item['timestamp'] = $media->date;
  45. $this->items[] = $item;
  46. }
  47. }
  48. public function getName(){
  49. return $this->getInput('u') .' - Instagram Bridge';
  50. }
  51. public function getURI(){
  52. return self::URI.urlencode($this->getInput('u'));
  53. }
  54. }