Browse Source

[Pinterest] Add implementation for user/board

The data is no longer provided in HTML upon request,
but rather encoded as JSON in a SCRIPT section and
decoded via Javascript on the client side. The bridge
now decodes the data and returns valid feeds again.
logmanoriginal 7 years ago
parent
commit
c3a1cbe98a
1 changed files with 22 additions and 0 deletions
  1. 22 0
      bridges/PinterestBridge.php

+ 22 - 0
bridges/PinterestBridge.php

@@ -70,6 +70,28 @@ class PinterestBridge extends BridgeAbstract {
 				$item['title'] = $img->getAttribute('alt');
 				$this->items[] = $item;
 			}
+		} elseif($this->queriedContext === 'By username and board'){
+			$container = $html->find('SCRIPT[type="application/ld+json"]', 0)
+				or $this->returnServerError('Unable to find data container!');
+
+			$json = json_decode($container->innertext, true);
+
+			foreach($json['itemListElement'] as $element){
+				$item = array();
+
+				$item['uri'] = $element['item']['sharedContent']['author']['url'];
+				$item['title'] = $element['item']['name'];
+				$item['author'] = $element['item']['user']['name'];
+				$item['timestamp'] = strtotime($element['item']['datePublished']);
+				$item['content'] = <<<EOD
+<a href="{$item['uri']}">
+	<img src="{$element['item']['image']}">
+</a>
+<p>{$element['item']['text']}</p>
+EOD;
+
+				$this->items[] = $item;
+			}
 		}
 	}