mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-25 10:56:18 +03:00
[ImgsedBridge] Fix and improvements (#3710)
* [ImgsedBridge] Fix and improvements - Display an error if the user doesn't select at least an content type to display - Unsplit the regular expression to make the URL of imgsed.com work too - Remove the "hour part" of the publication date : the website shows only the number of days if the content is older than one day * [ImgsedBridge] Fix and improvements Fix syntax * [ImgsedBridge] Fix and improvements - Fix TEST_DETECT_PARAMETERS - change detectParameters regular expression to match more instagram.com URLs * [ImgsedBridge] Fix and improvements - Fix date parsing for interval 'a day' * lint --------- Co-authored-by: Dag <me@dvikan.no>
This commit is contained in:
parent
7273a05f02
commit
0c92cf32d4
1 changed files with 22 additions and 4 deletions
|
@ -36,6 +36,12 @@ class ImgsedBridge extends BridgeAbstract
|
|||
],
|
||||
]
|
||||
];
|
||||
const TEST_DETECT_PARAMETERS = [
|
||||
'https://www.instagram.com/instagram/' => ['context' => 'Username', 'u' => 'instagram', 'post' => 'on', 'story' => 'on', 'tagged' => 'on'],
|
||||
'https://instagram.com/instagram/' => ['context' => 'Username', 'u' => 'instagram', 'post' => 'on', 'story' => 'on', 'tagged' => 'on'],
|
||||
'https://imgsed.com/instagram/' => ['context' => 'Username', 'u' => 'instagram', 'post' => 'on', 'story' => 'on', 'tagged' => 'on'],
|
||||
'https://www.imgsed.com/instagram/' => ['context' => 'Username', 'u' => 'instagram', 'post' => 'on', 'story' => 'on', 'tagged' => 'on'],
|
||||
];
|
||||
|
||||
public function getURI()
|
||||
{
|
||||
|
@ -213,9 +219,16 @@ HTML,
|
|||
{
|
||||
$date = date_create();
|
||||
$dateString = str_replace(' ago', '', $content);
|
||||
// Special case : 'a day' is not a valid interval in PHP, so replace it with it's PHP equivalenbt : '1 day'
|
||||
if ($dateString == 'a day') {
|
||||
$dateString = '1 day';
|
||||
}
|
||||
|
||||
$relativeDate = date_interval_create_from_date_string($dateString);
|
||||
if ($relativeDate) {
|
||||
date_sub($date, $relativeDate);
|
||||
// As the relative interval has the precision of a day for date older than 24 hours, we can remove the hour of the date, as it is not relevant
|
||||
date_time_set($date, 0, 0, 0, 0);
|
||||
} else {
|
||||
$this->logger->info(sprintf('Unable to parse date string: %s', $dateString));
|
||||
}
|
||||
|
@ -244,7 +257,13 @@ HTML,
|
|||
if ($this->getInput('tagged')) {
|
||||
$types[] = 'Tags';
|
||||
}
|
||||
|
||||
// If no content type is selected, this bridge does nothing, so we return an error
|
||||
if (count($types) == 0) {
|
||||
returnClientError('You must select at least one of the content type : Post, Stories or Tags !');
|
||||
}
|
||||
$typesText = $types[0] ?? '';
|
||||
|
||||
if (count($types) > 1) {
|
||||
for ($i = 1; $i < count($types) - 1; $i++) {
|
||||
$typesText .= ', ' . $types[$i];
|
||||
|
@ -262,10 +281,9 @@ HTML,
|
|||
$params = [
|
||||
'post' => 'on',
|
||||
'story' => 'on',
|
||||
'tagged' => 'on'
|
||||
'tagged' => 'on',
|
||||
];
|
||||
$regex = '/^http(s|):\/\/((www\.|)(instagram.com)\/([a-zA-Z0-9_\.]{1,30})\/(reels\/|tagged\/|)
|
||||
|(www\.|)(imgsed.com)\/(stories\/|tagged\/|)([a-zA-Z0-9_\.]{1,30})\/)/';
|
||||
$regex = '/^http(s|):\/\/((www\.|)(instagram.com)\/([a-zA-Z0-9_\.]{1,30})(\/reels\/|\/tagged\/|\/|)|(www\.|)(imgsed.com)\/(stories\/|tagged\/|)([a-zA-Z0-9_\.]{1,30})\/)/';
|
||||
if (preg_match($regex, $url, $matches) > 0) {
|
||||
$params['context'] = 'Username';
|
||||
// Extract detected domain using the regex
|
||||
|
@ -273,7 +291,7 @@ HTML,
|
|||
if ($domain == 'imgsed.com') {
|
||||
$params['u'] = $matches[10];
|
||||
return $params;
|
||||
} else if ($domain == 'instagram.com') {
|
||||
} elseif ($domain == 'instagram.com') {
|
||||
$params['u'] = $matches[5];
|
||||
return $params;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue