Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward with asterisk #572

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions lib/yrewrite/forward.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

Check warning on line 1 in lib/yrewrite/forward.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: yoda_style

Check warning on line 1 in lib/yrewrite/forward.php

View workflow job for this annotation

GitHub Actions / php-cs-fixer

Found violation(s) of type: no_trailing_whitespace_in_comment

/**
* YREWRITE Addon.
*
* @author [email protected]
*
*
* @package redaxo\yrewrite
*/

Expand Down Expand Up @@ -32,7 +30,7 @@
public static function getForward($params)
{
// Url wurde von einer anderen Extension bereits gesetzt
if (isset($params['subject']) && '' != $params['subject']) {
if (isset($params['subject']) && $params['subject'] != '') {
return $params['subject'];
}

Expand All @@ -52,8 +50,13 @@
}

$pUrl = urldecode($p['url']);
/** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/8125 */
if ($pUrl !== $url && $pUrl . '/' !== $url) {
$wildcardPos = strpos($pUrl, '*');
if ($wildcardPos !== false) {
$baseUrl = substr($pUrl, 0, $wildcardPos);
if (substr($url, 0, $wildcardPos) !== $baseUrl) {
continue;
}
} elseif ($pUrl !== $url && $pUrl . '/' !== $url) {

Check failure on line 59 in lib/yrewrite/forward.php

View workflow job for this annotation

GitHub Actions / psalm

RedundantCondition

lib/yrewrite/forward.php:59:23: RedundantCondition: Type lowercase-string for $url is never =non-empty-string (see https://psalm.dev/122)

Check failure on line 59 in lib/yrewrite/forward.php

View workflow job for this annotation

GitHub Actions / psalm

RedundantCondition

lib/yrewrite/forward.php:59:41: RedundantCondition: non-empty-string can never contain lowercase-string (see https://psalm.dev/122)
continue;
}

Expand All @@ -67,20 +70,20 @@
}
}

if ('article' == $p['type'] && ($art = rex_article::get($p['article_id'], $p['clang']))) {
if ($p['type'] == 'article' && ($art = rex_article::get($p['article_id'], $p['clang']))) {
$forward_url = rex_getUrl($p['article_id'], $p['clang']);
} elseif ('media' == $p['type'] && ($media = rex_media::get($p['media']))) {
} elseif ($p['type'] == 'media' && ($media = rex_media::get($p['media']))) {
$forward_url = rex_url::media($p['media']);
} elseif ('extern' == $p['type'] && '' != $p['extern']) {
} elseif ($p['type'] == 'extern' && $p['extern'] != '') {
$forward_url = $p['extern'];
}

if ('' != $forward_url) {
if ($forward_url != '') {
$matchingParams = count($p['params'] ?? []);
}
}

if ('' != $forward_url) {
if ($forward_url != '') {
header('HTTP/1.1 '.self::$movetypes[$p['movetype']]);
header('Location: ' . $forward_url);
exit;
Expand Down Expand Up @@ -110,7 +113,7 @@
$row['url'] = mb_strtolower($url[0]);

if (isset($url[1])) {
/** @phpstan-ignore-next-line */
/** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/8125 */

Check failure on line 116 in lib/yrewrite/forward.php

View workflow job for this annotation

GitHub Actions / psalm

UnusedPsalmSuppress

lib/yrewrite/forward.php:116:37: UnusedPsalmSuppress: This suppression is never used (see https://psalm.dev/207)
parse_str($url[1], $row['params']);
}
}
Expand Down
2 changes: 1 addition & 1 deletion pages/forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
$yform->setValueField('choice', ['status', $this->i18n('forward_status'), $this->i18n('forward_active').'=1,'.$this->i18n('forward_inactive').'=0']);
$yform->setValueField('choice', ['domain_id', $this->i18n('domain'), 'select id,domain as name from '.rex::getTable('yrewrite_domain') . ' ORDER BY name']);
$yform->setValueField('text', ['url', $this->i18n('forward_url'), 'notice' => '<small>'.$this->i18n('forward_url_info').'</small>']);
$yform->setValidateField('preg_match', ['url', '@^[%_\.+\-\w]+[/%_\.+\,\-\w]*(?<!\/)(?:\?.+)?$@u', $this->i18n('warning_chars')]);
$yform->setValidateField('preg_match', ['url', '@^[%_\.+\-\w]+[/%_\.+\,\-\w]*(?<!\/)(?:\?.+)?\*?$@u', $this->i18n('warning_chars')]);
// $this->i18n('warning_noslash')
$yform->setValidateField('size_range', ['url', 1, 255, $this->i18n('warning_nottolong')]);
$yform->setValidateField('empty', ['url', $this->i18n('forward_enter_url')]);
Expand Down
Loading