From 3c9860de43e55aeae474dee84ead8c382c165f1b Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Sun, 15 Apr 2018 13:13:10 +0200 Subject: [PATCH] [FDroid] new bridge --- bridges/FDroidBridge.php | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 bridges/FDroidBridge.php diff --git a/bridges/FDroidBridge.php b/bridges/FDroidBridge.php new file mode 100644 index 0000000..0208504 --- /dev/null +++ b/bridges/FDroidBridge.php @@ -0,0 +1,51 @@ + array( + 'name' => 'Widget selection', + 'type' => 'list', + 'required' => true, + 'values' => array( + 'Latest added apps' => 'added', + 'Latest updated apps' => 'updated' + ) + ) + )); + + public function collectData(){ + $url = self::URI; + $html = getSimpleHTMLDOM($url) + or returnServerError('Could not request F-Droid.'); + + // targetting the corresponding widget based on user selection + // "updated" is the 4th widget on the page, "added" is the 5th ← this is pretty sensitive to them adding/shuffling around website widgets + + switch($this->getInput('u')) { + case 'updated': + $html_widget = $html->find('div.sidebar-widget', 4); + break; + default: + $html_widget = $html->find('div.sidebar-widget', 5); + break; + } + + // and now extracting app info from the selected widget (and yeah turns out icons are of heterogeneous sizes) + + foreach($html_widget->find('a') as $element) { + $item = array(); + $item['uri'] = self::URI . $element->href; + $item['title'] = $element->find('h4', 0)->plaintext; + $item['icon'] = $element->find('img', 0)->src; + $item['summary'] = $element->find('span.package-summary', 0)->plaintext; + $item['content'] = '
'.$item['summary']; + $this->items[] = $item; + } + } +}