1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-28 18:40:15 +02:00

fix: various small fixes (#3580)

This commit is contained in:
Dag
2023-07-31 20:43:18 +02:00
committed by GitHub
parent 8b6eecea25
commit 7e4807530e
8 changed files with 35 additions and 14 deletions

View File

@@ -23,8 +23,9 @@ class FeedReducerBridge extends FeedExpander
public function collectData()
{
if (preg_match('#^http(s?)://#i', $this->getInput('url'))) {
$this->collectExpandableDatas($this->getInput('url'));
$url = $this->getInput('url');
if (preg_match('#^http(s?)://#i', $url)) {
$this->collectExpandableDatas($url);
} else {
throw new Exception('URI must begin with http(s)://');
}
@@ -35,7 +36,7 @@ class FeedReducerBridge extends FeedExpander
$filteredItems = [];
$intPercentage = (int)preg_replace('/[^0-9]/', '', $this->getInput('percentage'));
foreach ($this->items as $thisItem) {
foreach ($this->items as $item) {
// The URL is included in the hash:
// - so you can change the output by adding a local-part to the URL
// - so items with the same URI in different feeds won't be correlated
@@ -43,13 +44,13 @@ class FeedReducerBridge extends FeedExpander
// $pseudoRandomInteger will be a 16 bit unsigned int mod 100.
// This won't be uniformly distributed 1-100, but should be close enough.
$pseudoRandomInteger = unpack(
'S', // unsigned 16-bit int
hash('sha256', $thisItem['uri'] . '::' . $this->getInput('url'), true)
)[1] % 100;
$data = $item['uri'] . '::' . $this->getInput('url');
$hash = hash('sha256', $data, true);
// S = unsigned 16-bit int
$pseudoRandomInteger = unpack('S', $hash)[1] % 100;
if ($pseudoRandomInteger < $intPercentage) {
$filteredItems[] = $thisItem;
$filteredItems[] = $item;
}
}