2017-03-25 12:24:00 +01:00
|
|
|
<?php
|
|
|
|
class GithubSearchBridge extends BridgeAbstract {
|
|
|
|
|
|
|
|
const MAINTAINER = 'corenting';
|
|
|
|
const NAME = 'Github Repositories Search';
|
|
|
|
const URI = 'https://github.com/';
|
|
|
|
const CACHE_TIMEOUT = 600; // 10min
|
|
|
|
const DESCRIPTION = 'Returns a specified repositories search (sorted by recently updated)';
|
|
|
|
const PARAMETERS = array( array(
|
|
|
|
's' => 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);
|
2019-04-05 10:53:28 +02:00
|
|
|
|
2017-03-25 12:24:00 +01:00
|
|
|
$html = getSimpleHTMLDOM($url)
|
|
|
|
or returnServerError('Error while downloading the website content');
|
|
|
|
|
2019-04-05 10:53:28 +02:00
|
|
|
foreach($html->find('li.repo-list-item') as $element) {
|
2017-03-25 12:24:00 +01:00
|
|
|
$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;
|
|
|
|
|
2018-09-09 21:30:29 +02:00
|
|
|
// Description
|
|
|
|
if (count($element->find('p.d-inline-block')) != 0) {
|
|
|
|
$content = $element->find('p.d-inline-block', 0)->innertext;
|
2017-07-29 19:28:00 +02:00
|
|
|
} else{
|
2018-09-09 21:30:29 +02:00
|
|
|
$content = 'No description';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tags
|
|
|
|
$content = $content . '<br />';
|
|
|
|
$tags = $element->find('a.topic-tag');
|
|
|
|
$tags_array = array();
|
|
|
|
if (count($tags) != 0) {
|
|
|
|
$content = $content . 'Tags : ';
|
|
|
|
foreach($tags as $tag_element) {
|
|
|
|
$tag_link = 'https://github.com' . $tag_element->href;
|
|
|
|
$tag_name = trim($tag_element->innertext);
|
|
|
|
$content = $content . '<a href="' . $tag_link . '">' . $tag_name . '</a> ';
|
|
|
|
array_push($tags_array, $tag_element->innertext);
|
|
|
|
}
|
2017-03-25 12:24:00 +01:00
|
|
|
}
|
|
|
|
|
2018-09-09 21:30:29 +02:00
|
|
|
$item['categories'] = $tags_array;
|
|
|
|
$item['content'] = $content;
|
2017-03-25 12:24:00 +01:00
|
|
|
$date = $element->find('relative-time', 0)->datetime;
|
|
|
|
$item['timestamp'] = strtotime($date);
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|