From 88586381e71bf824a871fa14a17c843bd60d74c2 Mon Sep 17 00:00:00 2001 From: Corentin Garcia Date: Sat, 25 Mar 2017 12:24:00 +0100 Subject: [PATCH] [GithubSearchBridge] Added github search bridge (#500) * [GithubSearchBridge] Added github search bridge, only repos search atm --- bridges/GithubSearchBridge.php | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 bridges/GithubSearchBridge.php diff --git a/bridges/GithubSearchBridge.php b/bridges/GithubSearchBridge.php new file mode 100644 index 0000000..3763ee8 --- /dev/null +++ b/bridges/GithubSearchBridge.php @@ -0,0 +1,51 @@ + array( + 'type' => 'text', + 'name' => 'Search query' + ) + )); + + public function collectData(){ + $params = array('utf8' => '✓', + 'q' => urlencode($this->getInput('s')), + 's' => 'updated', + 'o' => 'desc', + 'type' => 'Repositories'); + $url = self::URI . 'search?' . http_build_query($params); + + $html = getSimpleHTMLDOM($url) + or returnServerError('Error while downloading the website content'); + + foreach($html->find('div.repo-list-item') as $element){ + $item = array(); + + $uri = $element->find('h3 a', 0)->href; + $uri = substr(self::URI, 0, -1) . $uri; + $item['uri'] = $uri; + + $title = $element->find('h3', 0)->plaintext; + $item['title'] = $title; + + if (count($element->find('p')) == 2){ + $content = $element->find('p', 0)->innertext; + } + else{ + $content = ''; + } + $item['content'] = $content; + + $date = $element->find('relative-time', 0)->datetime; + $item['timestamp'] = strtotime($date); + + $this->items[] = $item; + } + } +}