rss-bridge/bridges/FDroidBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.3 KiB
PHP
Raw Normal View History

2018-04-15 14:13:10 +03:00
<?php
class FDroidBridge extends BridgeAbstract
{
2018-04-15 14:13:10 +03:00
const MAINTAINER = 'Mitsukarenai';
const NAME = 'F-Droid Bridge';
const URI = 'https://f-droid.org/';
const CACHE_TIMEOUT = 60 * 60 * 4; // 4 hours
2018-04-15 14:13:10 +03:00
const DESCRIPTION = 'Returns latest added/updated apps on the open-source Android apps repository F-Droid';
const PARAMETERS = [ [
'u' => [
'name' => 'Widget selection',
'type' => 'list',
'values' => [
'Latest added apps' => 'added',
'Latest updated apps' => 'updated'
]
]
2018-04-15 14:13:10 +03:00
]];
public function getIcon()
{
return self::URI . 'assets/favicon.ico';
}
private function getTimestamp($url)
{
$curlOptions = [
CURLOPT_CUSTOMREQUEST => 'HEAD',
CURLOPT_NOBODY => true,
];
$reponse = getContents($url, [], $curlOptions, true);
$lastModified = $reponse['headers']['last-modified'][0] ?? null;
$timestamp = strtotime($lastModified ?? 'today');
return $timestamp;
}
2018-04-15 14:13:10 +03:00
public function collectData()
{
$url = self::URI;
$html = getSimpleHTMLDOM($url);
2018-04-15 14:13:10 +03:00
// targetting the corresponding widget based on user selection
// "updated" is the 5th widget on the page, "added" is the 6th
2018-04-15 14:13:10 +03:00
switch ($this->getInput('u')) {
case 'updated':
$html_widget = $html->find('div.sidebar-widget', 5);
2018-04-15 14:13:10 +03:00
break;
default:
$html_widget = $html->find('div.sidebar-widget', 6);
2018-04-15 14:13:10 +03:00
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 = [];
$item['uri'] = self::URI . $element->href;
$item['title'] = $element->find('h4', 0)->plaintext;
$item['icon'] = $element->find('img', 0)->src;
$item['timestamp'] = $this->getTimestamp($item['icon']);
2018-04-15 14:13:10 +03:00
$item['summary'] = $element->find('span.package-summary', 0)->plaintext;
2018-04-15 14:21:48 +03:00
$item['content'] = '
2018-11-05 14:55:58 +03:00
<a href="' . $item['uri'] . '">
<img alt="" style="max-height:128px" src="' . $item['icon'] . '">
</a><br>' . $item['summary'];
2018-04-15 14:13:10 +03:00
$this->items[] = $item;
}
}
}