GithubSearchBridge.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class GithubSearchBridge extends BridgeAbstract {
  3. const MAINTAINER = 'corenting';
  4. const NAME = 'Github Repositories Search';
  5. const URI = 'https://github.com/';
  6. const CACHE_TIMEOUT = 600; // 10min
  7. const DESCRIPTION = 'Returns a specified repositories search (sorted by recently updated)';
  8. const PARAMETERS = array( array(
  9. 's' => array(
  10. 'type' => 'text',
  11. 'name' => 'Search query'
  12. )
  13. ));
  14. public function collectData(){
  15. $params = array('utf8' => '✓',
  16. 'q' => urlencode($this->getInput('s')),
  17. 's' => 'updated',
  18. 'o' => 'desc',
  19. 'type' => 'Repositories');
  20. $url = self::URI . 'search?' . http_build_query($params);
  21. $html = getSimpleHTMLDOM($url)
  22. or returnServerError('Error while downloading the website content');
  23. foreach($html->find('div.repo-list-item') as $element) {
  24. $item = array();
  25. $uri = $element->find('h3 a', 0)->href;
  26. $uri = substr(self::URI, 0, -1) . $uri;
  27. $item['uri'] = $uri;
  28. $title = $element->find('h3', 0)->plaintext;
  29. $item['title'] = $title;
  30. if (count($element->find('p')) == 2) {
  31. $content = $element->find('p', 0)->innertext;
  32. } else{
  33. $content = '';
  34. }
  35. $item['content'] = $content;
  36. $date = $element->find('relative-time', 0)->datetime;
  37. $item['timestamp'] = strtotime($date);
  38. $this->items[] = $item;
  39. }
  40. }
  41. }