2017-03-25 14:24:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class GithubSearchBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2017-03-25 14:24:00 +03:00
|
|
|
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 = [ [
|
|
|
|
's' => [
|
|
|
|
'type' => 'text',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'rss-bridge',
|
2017-03-25 14:24:00 +03:00
|
|
|
'name' => 'Search query'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2017-03-25 14:24:00 +03:00
|
|
|
]];
|
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$params = ['utf8' => '✓',
|
|
|
|
'q' => urlencode($this->getInput('s')),
|
|
|
|
's' => 'updated',
|
|
|
|
'o' => 'desc',
|
|
|
|
'type' => 'Repositories'];
|
|
|
|
$url = self::URI . 'search?' . http_build_query($params);
|
2019-04-05 11:59:30 +03:00
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($url);
|
2017-03-25 14:24:00 +03:00
|
|
|
|
2019-04-05 11:53:28 +03:00
|
|
|
foreach ($html->find('li.repo-list-item') as $element) {
|
2017-03-25 14:24:00 +03:00
|
|
|
$item = [];
|
|
|
|
|
2020-01-31 17:01:46 +03:00
|
|
|
$uri = $element->find('.f4 a', 0)->href;
|
2017-03-25 14:24:00 +03:00
|
|
|
$uri = substr(self::URI, 0, -1) . $uri;
|
|
|
|
$item['uri'] = $uri;
|
|
|
|
|
2020-01-31 17:01:46 +03:00
|
|
|
$title = $element->find('.f4', 0)->plaintext;
|
2017-03-25 14:24:00 +03:00
|
|
|
$item['title'] = $title;
|
|
|
|
|
2018-09-09 22:30:29 +03:00
|
|
|
// Description
|
2020-01-31 17:01:46 +03:00
|
|
|
if (count($element->find('p.mb-1')) != 0) {
|
|
|
|
$content = $element->find('p.mb-1', 0)->innertext;
|
2017-07-29 20:28:00 +03:00
|
|
|
} else {
|
2018-09-09 22:30:29 +03:00
|
|
|
$content = 'No description';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tags
|
|
|
|
$content = $content . '<br />';
|
|
|
|
$tags = $element->find('a.topic-tag');
|
|
|
|
$tags_array = [];
|
|
|
|
if (count($tags) != 0) {
|
2022-10-01 09:42:50 +03:00
|
|
|
$content = $content . 'Tags: ';
|
2018-09-09 22:30:29 +03:00
|
|
|
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 14:24:00 +03:00
|
|
|
}
|
|
|
|
|
2022-10-01 09:42:50 +03:00
|
|
|
// Programming language
|
|
|
|
if (count($element->find('span[itemprop=programmingLanguage]')) != 0) {
|
|
|
|
$language = $element->find('span[itemprop=programmingLanguage]', 0)->innertext;
|
|
|
|
|
|
|
|
$content = $content . '<br />';
|
|
|
|
$content = $content . 'Language: ' . $language;
|
|
|
|
}
|
|
|
|
|
2018-09-09 22:30:29 +03:00
|
|
|
$item['categories'] = $tags_array;
|
|
|
|
$item['content'] = $content;
|
2017-03-25 14:24:00 +03:00
|
|
|
$date = $element->find('relative-time', 0)->datetime;
|
|
|
|
$item['timestamp'] = strtotime($date);
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|