diff --git a/bridges/TwitterEngineeringBridge.php b/bridges/TwitterEngineeringBridge.php new file mode 100644 index 00000000..f11caaa1 --- /dev/null +++ b/bridges/TwitterEngineeringBridge.php @@ -0,0 +1,62 @@ +Could not request ' . $this->getName() . ': ' . $item['uri'] . '

'; + return $item; + } + $article_html = defaultLinkTo($article_html, $this->getURI()); + + $article_body = $article_html->find('div.column.column-6', 0); + + // Remove elements that are not part of article content + $unwanted_selector = 'div.bl02-blog-post-text-masthead, div.tweet-error-text, div.bl13-tweet-template'; + foreach($article_body->find($unwanted_selector) as $found) { + $found->outertext = ''; + } + + // Set src for images + foreach($article_body->find('img') as $found) { + $found->setAttribute('src', $found->getAttribute('data-src')); + } + + $item['content'] = $article_body; + $item['timestamp'] = strtotime($article_html->find('span.b02-blog-post-no-masthead__date', 0)->innertext); + $item['categories'] = self::getCategoriesFromTags($article_html); + + return $item; + } + + private function getCategoriesFromTags($article_html){ + $tags_list_items = array($article_html->find('.post__tags > ul > li')); + $categories = array(); + + foreach($tags_list_items as $tag_list_item) { + foreach($tag_list_item as $tag) { + $categories[] = trim($tag->plaintext); + } + } + + return $categories; + } + + public function collectData(){ + $feed = static::URI . 'en_us/blog.rss'; + $this->collectExpandableDatas($feed); + } + + public function getName(){ + // Else the original feed returns "English (US)" as the title + return 'Twitter Engineering Blog'; + } +}