FDroidBridge.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. class FDroidBridge extends BridgeAbstract {
  3. const MAINTAINER = 'Mitsukarenai';
  4. const NAME = 'F-Droid Bridge';
  5. const URI = 'https://f-droid.org/';
  6. const CACHE_TIMEOUT = 60 * 60 * 2; // 2 hours
  7. const DESCRIPTION = 'Returns latest added/updated apps on the open-source Android apps repository F-Droid';
  8. const PARAMETERS = array( array(
  9. 'u' => array(
  10. 'name' => 'Widget selection',
  11. 'type' => 'list',
  12. 'required' => true,
  13. 'values' => array(
  14. 'Latest added apps' => 'added',
  15. 'Latest updated apps' => 'updated'
  16. )
  17. )
  18. ));
  19. public function collectData(){
  20. $url = self::URI;
  21. $html = getSimpleHTMLDOM($url)
  22. or returnServerError('Could not request F-Droid.');
  23. // targetting the corresponding widget based on user selection
  24. // "updated" is the 4th widget on the page, "added" is the 5th
  25. switch($this->getInput('u')) {
  26. case 'updated':
  27. $html_widget = $html->find('div.sidebar-widget', 4);
  28. break;
  29. default:
  30. $html_widget = $html->find('div.sidebar-widget', 5);
  31. break;
  32. }
  33. // and now extracting app info from the selected widget (and yeah turns out icons are of heterogeneous sizes)
  34. foreach($html_widget->find('a') as $element) {
  35. $item = array();
  36. $item['uri'] = self::URI . $element->href;
  37. $item['title'] = $element->find('h4', 0)->plaintext;
  38. $item['icon'] = $element->find('img', 0)->src;
  39. $item['summary'] = $element->find('span.package-summary', 0)->plaintext;
  40. $item['content'] = '
  41. <a href="'.$item['uri'].'">
  42. <img alt="" style="max-height:128px" src="'.$item['icon'].'">
  43. </a><br>'.$item['summary'];
  44. $this->items[] = $item;
  45. }
  46. }
  47. }