mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-14 20:21:14 +03:00
[FDroid] cache up, add timestamp extraction
- increase caching from 2 to 4 hours - using cURL, extract Last-Modified header of app icons and use as item timestamp Test warning: F-Droid response time is quite slow even on static assets, the additional requests might impact bridge performance further
This commit is contained in:
parent
018fd1c8f2
commit
e9f871ce68
1 changed files with 28 additions and 1 deletions
|
@ -4,7 +4,7 @@ class FDroidBridge extends BridgeAbstract {
|
|||
const MAINTAINER = 'Mitsukarenai';
|
||||
const NAME = 'F-Droid Bridge';
|
||||
const URI = 'https://f-droid.org/';
|
||||
const CACHE_TIMEOUT = 60 * 60 * 2; // 2 hours
|
||||
const CACHE_TIMEOUT = 60 * 60 * 4; // 4 hours
|
||||
const DESCRIPTION = 'Returns latest added/updated apps on the open-source Android apps repository F-Droid';
|
||||
|
||||
const PARAMETERS = array( array(
|
||||
|
@ -22,6 +22,32 @@ class FDroidBridge extends BridgeAbstract {
|
|||
return self::URI . 'assets/favicon.ico?v=8j6PKzW9Mk';
|
||||
}
|
||||
|
||||
private function getTimestamp($url) {
|
||||
$curlOptions = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_NOBODY => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 19,
|
||||
CURLOPT_TIMEOUT => 19,
|
||||
);
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, $curlOptions);
|
||||
$curlHeaders = curl_exec($ch);
|
||||
$curlError = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if(!empty($curlError))
|
||||
return FALSE;
|
||||
$curlHeaders = explode("\n",$curlHeaders);
|
||||
$timestamp=FALSE;
|
||||
foreach($curlHeaders as $header) {
|
||||
if(strpos($header, 'Last-Modified') !== FALSE) {
|
||||
$timestamp = str_replace('Last-Modified: ', '', $header);
|
||||
$timestamp = strtotime($timestamp);
|
||||
}
|
||||
}
|
||||
return $timestamp;
|
||||
}
|
||||
|
||||
public function collectData(){
|
||||
$url = self::URI;
|
||||
$html = getSimpleHTMLDOM($url);
|
||||
|
@ -45,6 +71,7 @@ class FDroidBridge extends BridgeAbstract {
|
|||
$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'] = '
|
||||
<a href="' . $item['uri'] . '">
|
||||
|
|
Loading…
Add table
Reference in a new issue