2022-05-12 03:22:16 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
class FDroidRepoBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'F-Droid Repository Bridge';
|
|
|
|
const URI = 'https://f-droid.org/';
|
|
|
|
const DESCRIPTION = 'Query any F-Droid Repository for its latest updates.';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
const ITEM_LIMIT = 50;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
const PARAMETERS = [
|
|
|
|
'global' => [
|
|
|
|
'url' => [
|
|
|
|
'name' => 'Repository URL',
|
|
|
|
'title' => 'Usually ends with /repo/',
|
|
|
|
'required' => true,
|
2024-04-05 12:31:30 +03:00
|
|
|
'exampleValue' => 'https://molly.im/fdroid/foss/fdroid/repo'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2022-05-12 03:22:16 +03:00
|
|
|
],
|
|
|
|
'Latest Updates' => [
|
|
|
|
'sorting' => [
|
|
|
|
'name' => 'Sort By',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'Latest added apps' => 'added',
|
|
|
|
'Latest updated apps' => 'lastUpdated'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2022-05-12 03:22:16 +03:00
|
|
|
],
|
|
|
|
'locale' => [
|
|
|
|
'name' => 'Locale',
|
|
|
|
'defaultValue' => 'en-US'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
2022-05-12 03:22:16 +03:00
|
|
|
],
|
|
|
|
'Follow Package' => [
|
|
|
|
'package' => [
|
|
|
|
'name' => 'Package Identifier',
|
|
|
|
'required' => true,
|
2024-04-05 12:31:30 +03:00
|
|
|
'exampleValue' => 'im.molly.app'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2022-05-12 03:22:16 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
// Stores repo information
|
|
|
|
private $repo;
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-08-06 23:46:28 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
2024-04-04 18:43:07 +03:00
|
|
|
$this->repo = $this->fetchData();
|
2022-08-06 23:46:28 +03:00
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'Latest Updates':
|
|
|
|
$this->getAllUpdates();
|
|
|
|
break;
|
|
|
|
case 'Follow Package':
|
|
|
|
$this->getPackage($this->getInput('package'));
|
|
|
|
break;
|
|
|
|
default:
|
2024-04-04 18:43:07 +03:00
|
|
|
throw new \Exception('Unimplemented Context (collectData)');
|
2022-08-06 23:46:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-04 18:43:07 +03:00
|
|
|
private function fetchData()
|
2022-05-12 03:22:16 +03:00
|
|
|
{
|
|
|
|
$url = $this->getURI();
|
2024-04-05 18:39:38 +03:00
|
|
|
$json = getContents($url . '/index-v1.json');
|
2024-04-04 18:43:07 +03:00
|
|
|
$data = Json::decode($json);
|
2022-05-12 03:22:16 +03:00
|
|
|
return $data;
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
private function getAllUpdates()
|
|
|
|
{
|
|
|
|
$apps = $this->repo['apps'];
|
|
|
|
usort($apps, function ($a, $b) {
|
|
|
|
return $b[$this->getInput('sorting')] <=> $a[$this->getInput('sorting')];
|
|
|
|
});
|
|
|
|
$apps = array_slice($apps, 0, self::ITEM_LIMIT);
|
|
|
|
foreach ($apps as $app) {
|
|
|
|
$latest = reset($this->repo['packages'][$app['packageName']]);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
if (isset($app['localized'])) {
|
|
|
|
// Try provided locale, then en-US, then any
|
|
|
|
$lang = $app['localized'];
|
|
|
|
$lang = $lang[$this->getInput('locale')] ?? $lang['en-US'] ?? reset($lang);
|
|
|
|
} else {
|
|
|
|
$lang = [];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
$item = [];
|
|
|
|
$item['uri'] = $this->getURI() . '/' . $latest['apkName'];
|
|
|
|
$item['title'] = $lang['name'] ?? $app['packageName'];
|
|
|
|
$item['title'] .= ' ' . $latest['versionName'];
|
|
|
|
$item['timestamp'] = date(DateTime::ISO8601, (int) ($app['lastUpdated'] / 1000));
|
|
|
|
if (isset($app['authorName'])) {
|
|
|
|
$item['author'] = $app['authorName'];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2022-05-12 03:22:16 +03:00
|
|
|
if (isset($app['categories'])) {
|
|
|
|
$item['categories'] = $app['categories'];
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
// Adding Content
|
|
|
|
$icon = $app['icon'] ?? '';
|
|
|
|
if (!empty($icon)) {
|
|
|
|
$icon = $this->getURI() . '/icons-320/' . $icon;
|
|
|
|
$item['enclosures'] = [$icon];
|
|
|
|
$icon = '<img src="' . $icon . '">';
|
|
|
|
}
|
|
|
|
$summary = $lang['summary'] ?? $app['summary'] ?? '';
|
|
|
|
$description = markdownToHtml(trim($lang['description'] ?? $app['description'] ?? 'None'));
|
|
|
|
$whatsNew = markdownToHtml(trim($lang['whatsNew'] ?? 'None'));
|
2024-04-04 18:43:07 +03:00
|
|
|
$website = $this->createAnchor($lang['webSite'] ?? $app['webSite'] ?? $app['authorWebSite'] ?? null);
|
|
|
|
$source = $this->createAnchor($app['sourceCode'] ?? null);
|
|
|
|
$issueTracker = $this->createAnchor($app['issueTracker'] ?? null);
|
2022-05-12 03:22:16 +03:00
|
|
|
$license = $app['license'] ?? 'None';
|
|
|
|
$item['content'] = <<<EOD
|
|
|
|
{$icon}
|
|
|
|
<p>{$summary}</p>
|
|
|
|
<h1>Description</h1>
|
|
|
|
{$description}
|
|
|
|
<h1>What's New</h1>
|
|
|
|
{$whatsNew}
|
|
|
|
<h1>Information</h1>
|
|
|
|
<p>Website: {$website}</p>
|
|
|
|
<p>Source Code: {$source}</p>
|
|
|
|
<p>Issue Tracker: {$issueTracker}</p>
|
|
|
|
<p>license: {$app['license']}</p>
|
|
|
|
EOD;
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
private function getPackage($package)
|
|
|
|
{
|
|
|
|
if (!isset($this->repo['packages'][$package])) {
|
2024-04-04 18:43:07 +03:00
|
|
|
throw new \Exception('Invalid Package Name');
|
2022-05-12 03:22:16 +03:00
|
|
|
}
|
|
|
|
$package = $this->repo['packages'][$package];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-05-12 03:22:16 +03:00
|
|
|
$count = self::ITEM_LIMIT;
|
|
|
|
foreach ($package as $version) {
|
|
|
|
$item = [];
|
|
|
|
$item['uri'] = $this->getURI() . '/' . $version['apkName'];
|
|
|
|
$item['title'] = $version['versionName'];
|
|
|
|
$item['timestamp'] = date(DateTime::ISO8601, (int) ($version['added'] / 1000));
|
2024-04-04 18:43:07 +03:00
|
|
|
$item['uid'] = (string) $version['versionCode'];
|
2022-05-12 03:22:16 +03:00
|
|
|
$size = round($version['size'] / 1048576, 1); // Bytes -> MB
|
|
|
|
$sdk_link = 'https://developer.android.com/studio/releases/platforms';
|
|
|
|
$item['content'] = <<<EOD
|
|
|
|
<p>size: {$size}MB</p>
|
|
|
|
<p>Minimum SDK: {$version['minSdkVersion']}
|
|
|
|
(<a href="{$sdk_link}">SDK to Android Version List</a>)</p>
|
|
|
|
<p>hash ({$version['hashType']}): {$version['hash']}</p>
|
|
|
|
EOD;
|
|
|
|
$this->items[] = $item;
|
|
|
|
if (--$count <= 0) {
|
|
|
|
break;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2022-05-12 03:22:16 +03:00
|
|
|
}
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2024-04-04 18:43:07 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
if (empty($this->queriedContext)) {
|
|
|
|
return parent::getURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
$url = rtrim($this->getInput('url'), '/');
|
|
|
|
if (strstr($url, '?', true)) {
|
|
|
|
return strstr($url, '?', true);
|
|
|
|
} else {
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
if (empty($this->queriedContext)) {
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $this->repo['repo']['name'];
|
|
|
|
switch ($this->queriedContext) {
|
|
|
|
case 'Latest Updates':
|
|
|
|
return $name;
|
|
|
|
case 'Follow Package':
|
|
|
|
return $this->getInput('package') . ' - ' . $name;
|
|
|
|
default:
|
|
|
|
throw new \Exception('Unimplemented Context (getName)');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createAnchor($url)
|
2022-05-12 03:22:16 +03:00
|
|
|
{
|
|
|
|
if (empty($url)) {
|
|
|
|
return null;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2024-04-04 18:43:07 +03:00
|
|
|
return sprintf('<a href="%s">%s</a>', $url, $url);
|
2022-05-12 03:22:16 +03:00
|
|
|
}
|
|
|
|
}
|