2018-04-15 14:13:10 +03:00
|
|
|
<?php
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
class FDroidBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const MAINTAINER = 'Mitsukarenai';
|
|
|
|
const NAME = 'F-Droid Bridge';
|
|
|
|
const URI = 'https://f-droid.org/';
|
|
|
|
const CACHE_TIMEOUT = 60 * 60 * 4; // 4 hours
|
|
|
|
const DESCRIPTION = 'Returns latest added/updated apps on the open-source Android apps repository F-Droid';
|
2018-04-15 14:13:10 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
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
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function getIcon()
|
|
|
|
{
|
2023-10-01 21:46:51 +03:00
|
|
|
return self::URI . 'assets/favicon.ico';
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2018-10-26 19:07:34 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
private function getTimestamp($url)
|
|
|
|
{
|
|
|
|
$curlOptions = [
|
2023-10-01 21:46:51 +03:00
|
|
|
CURLOPT_CUSTOMREQUEST => 'HEAD',
|
|
|
|
CURLOPT_NOBODY => true,
|
2022-07-01 16:10:30 +03:00
|
|
|
];
|
2023-10-01 21:46:51 +03:00
|
|
|
$reponse = getContents($url, [], $curlOptions, true);
|
2024-07-31 18:30:06 +03:00
|
|
|
$lastModified = $reponse->getHeader('last-modified');
|
2023-10-01 21:46:51 +03:00
|
|
|
$timestamp = strtotime($lastModified ?? 'today');
|
2022-07-01 16:10:30 +03:00
|
|
|
return $timestamp;
|
|
|
|
}
|
2022-01-24 14:36:49 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$url = self::URI;
|
|
|
|
$html = getSimpleHTMLDOM($url);
|
2018-04-15 14:13:10 +03:00
|
|
|
|
2022-07-01 16:10:30 +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
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
switch ($this->getInput('u')) {
|
|
|
|
case 'updated':
|
|
|
|
$html_widget = $html->find('div.sidebar-widget', 5);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$html_widget = $html->find('div.sidebar-widget', 6);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-15 14:13:10 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
// and now extracting app info from the selected widget (and yeah turns out icons are of heterogeneous sizes)
|
2018-04-15 14:13:10 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
foreach ($html_widget->find('a') as $element) {
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
$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']);
|
|
|
|
$item['summary'] = $element->find('span.package-summary', 0)->plaintext;
|
|
|
|
$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'];
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2018-04-15 14:13:10 +03:00
|
|
|
}
|