InstagramBridge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. if('' === $script->innertext){
  19. continue;
  20. }
  21. $pos = strpos(trim($script->innertext), 'window._sharedData');
  22. if(0 !== $pos){
  23. continue;
  24. }
  25. $innertext = $script->innertext;
  26. break;
  27. }
  28. $json = trim(substr($innertext, $pos + 18), ' =;');
  29. $data = json_decode($json);
  30. $userMedia = $data->entry_data->ProfilePage[0]->user->media->nodes;
  31. foreach($userMedia as $media){
  32. $item = array();
  33. $item['uri'] = self::URI . 'p/' . $media->code . '/';
  34. $item['content'] = '<img src="' . htmlentities($media->display_src) . '" />';
  35. if (isset($media->caption)){
  36. $item['title'] = $media->caption;
  37. } else {
  38. $item['title'] = basename($media->display_src);
  39. }
  40. $item['timestamp'] = $media->date;
  41. $this->items[] = $item;
  42. }
  43. }
  44. public function getName(){
  45. return $this->getInput('u') . ' - Instagram Bridge';
  46. }
  47. public function getURI(){
  48. return self::URI . urlencode($this->getInput('u'));
  49. }
  50. }