Guides/Fixups

* fix urls in user menu
 * strip anchors from tooltip title
 * prevent line breaks in description
 * make only in english info popup modular
This commit is contained in:
Sarjuuk
2023-05-11 14:37:34 +02:00
parent 0e9ca3ff90
commit bc3ba23162
12 changed files with 35 additions and 14 deletions

View File

@@ -677,7 +677,7 @@ class User
if ($guides = DB::Aowow()->select('SELECT `id`, `title`, `url` FROM ?_guides WHERE `userId` = ?d AND `status` <> ?d', self::$id, GUIDE_STATUS_ARCHIVED))
{
// fix url
array_walk($guides, fn(&$x) => $x['url'] = '/?guide='.($x['url'] ?? $x['id']));
array_walk($guides, fn(&$x) => $x['url'] = '?guide='.($x['url'] ?? $x['id']));
$result = $guides;
}

View File

@@ -18,6 +18,10 @@ class SimpleXML extends SimpleXMLElement
trait TrRequestData
{
// const in trait supported in php8.2+
public static $PATTERN_TEXT_LINE = '/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui';
public static $PATTERN_TEXT_BLOB = '/[\x00-\x09\x0B-\x1F\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui';
private $filtered = false;
private function initRequestData() : void
@@ -61,7 +65,7 @@ trait TrRequestData
return $val === ''; // parameter is expected to be empty
}
public static function checkInt(string $val) : int
private static function checkInt(string $val) : int
{
if (preg_match('/^-?\d+$/', $val))
return intVal($val);
@@ -112,13 +116,13 @@ trait TrRequestData
private static function checkTextLine(string $val) : string
{
// trim non-printable chars
return preg_replace('/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui', '', $val);
return preg_replace(self::$PATTERN_TEXT_LINE, '', $val);
}
private static function checkTextBlob(string $val) : string
{
// trim non-printable chars
return preg_replace('/[\x00-\x09\x0B-\x1F\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui', '', $val);
return preg_replace(self::$PATTERN_TEXT_BLOB, '', $val);
}
}

View File

@@ -3,6 +3,7 @@
class Lang
{
private static $timeUnits;
private static $lang;
private static $main;
private static $account;
private static $user;

View File

@@ -16,6 +16,7 @@ $lang = array(
'pl' => ["Jahre", "Monate", "Wochen", "Tage", "Stunden", "Minuten", "Sekunden", "Millisekunden"],
'ab' => ["J.", "M.", "W.", "Tag", "Std.", "Min.", "Sek.", "Ms."]
),
'lang' => ['Englisch', null, 'Französisch', 'Deutsch', 'Chinesisch', null, 'Spanisch', null, 'Russisch'],
'main' => array(
'name' => "Name",
'link' => "Link",
@@ -99,7 +100,7 @@ $lang = array(
),
// article & infobox
'englishOnly' => "Diese Seite ist nur in <b>Englisch</b> verfügbar.",
'langOnly' => "Diese Seite ist nur in <b>%s</b> verfügbar.",
// calculators
'preset' => "Vorlage",

View File

@@ -16,6 +16,7 @@ $lang = array(
'pl' => ["years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds"],
'ab' => ["yr", "mo", "wk", "day", "hr", "min", "sec", "ms"]
),
'lang' => ['English', null, 'French', 'German', 'Chinese', null, 'Spanish', null, 'Russian'],
'main' => array(
'name' => "name",
'link' => "Link",
@@ -99,7 +100,7 @@ $lang = array(
),
// article & infobox
'englishOnly' => "This page is only available in <b>English</b>.",
'langOnly' => "This page is only available in <b>%s</b>.",
// calculators
'preset' => "Preset",

View File

@@ -16,6 +16,7 @@ $lang = array(
'pl' => ["años", "meses", "semanas", "dias", "horas", "minutos", "segundos", "milisegundos"],
'ab' => ["año", "mes", "sem", "", "h", "min", "seg", "ms"]
),
'lang' => ['inglés', null, 'francés', 'alemán', 'chino', null, 'español', null, 'ruso'],
'main' => array(
'name' => "nombre",
'link' => "Enlace",
@@ -99,7 +100,7 @@ $lang = array(
),
// article & infobox
'englishOnly' => "Esta página sólo está disponible en <b>inglés</b>.",
'langOnly' => "Esta página sólo está disponible en <b>%s</b>.",
// calculators
'preset' => "Predet.",

View File

@@ -16,6 +16,7 @@ $lang = array(
'pl' => ["années", "mois", "semaines", "jours", "heures", "minutes", "secondes", "millisecondes"],
'ab' => ["an", "mo", "sem", "jour", "h", "min", "s", "ms"]
),
'lang' => ['anglais', null, 'français', 'allemand', 'chinois', null, 'espagnol', null, 'russe'],
'main' => array(
'name' => "nom",
'link' => "Lien",
@@ -99,7 +100,7 @@ $lang = array(
),
// article & infobox
'englishOnly' => "Cette page n'est disponible qu'en <b>anglais</b> pour le moment.",
'langOnly' => "Cette page n'est disponible qu'en <b>%s</b> pour le moment.",
// calculators
'preset' => "Prédéterminée",

View File

@@ -16,6 +16,7 @@ $lang = array(
'pl' => ["годы", "месяцы", "недели", "дн.", "часы", "мин", "секунды", "миллисекундах"],
'ab' => ["г.", "мес.", "нед.", "дн", "ч.", "мин", "сек.", "мс"]
),
'lang' => ["английском", null, "французском", "немецком", "китайском", null, "испанском", null, "русском"],
'main' => array(
'name' => "название",
'link' => "Ссылка",
@@ -99,7 +100,7 @@ $lang = array(
),
// article & infobox
'englishOnly' => "Эта страница доступна только на <b>английском</b> языке.",
'langOnly' => "Эта страница доступна только на <b>%s</b> языке.",
// calculators
'preset' => "Готовая таблица",

View File

@@ -16,6 +16,7 @@ $lang = array(
'pl' => ["", "", "", "", "小时", "分钟", "", "毫秒"],
'ab' => ["", "", "", "", "小时", "分钟", "", "毫秒"]
),
'lang' => ['英语', null, '法语', '德语', '中文', null, '西班牙语', null, '俄语'],
'main' => array(
'name' => "名字",
'link' => "链接",
@@ -99,7 +100,7 @@ $lang = array(
),
// article & infobox
'englishOnly' => "该页面仅以<b>英语</b>提供。",
'langOnly' => "该页面仅以<b>%s</b>提供。",
// calculators
'preset' => "预设",

View File

@@ -567,7 +567,7 @@ class GenericPage
$this->infobox = $article['quickInfo'];
if ($article['locale'] != User::$localeId)
$this->article['params']['prepend'] = '<div class="notice-box"><span class="icon-bubble">'.Lang::main('englishOnly').'</span></div>';
$this->article['params']['prepend'] = '<div class="notice-box"><span class="icon-bubble">'.Lang::main('langOnly', [Lang::lang($article['locale'])]).'</span></div>';
if (method_exists($this, 'postArticle')) // e.g. update variables in article
$this->postArticle();

View File

@@ -44,7 +44,7 @@ class GuidePage extends GenericPage
'submit' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkEmptySet'],
'title' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextLine'],
'name' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextLine'],
'description' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextBlob'],
'description' => ['filter' => FILTER_CALLBACK, 'options' => 'GuidePage::checkDescription'],
'changelog' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextBlob'],
'body' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextBlob'],
'locale' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkInt'],
@@ -521,7 +521,7 @@ class GuidePage extends GenericPage
$power = new StdClass();
if (!$this->subject->error)
{
$power->{'name_'.User::$localeString} = $this->name;
$power->{'name_'.User::$localeString} = strip_tags($this->name);
$power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip();
}
@@ -550,6 +550,16 @@ class GuidePage extends GenericPage
if ($this->subject?->getField('status') == GUIDE_STATUS_APPROVED)
DB::Aowow()->query('UPDATE ?_guides SET `views` = `views` + 1 WHERE `id` = ?d', $this->typeId);
}
protected static function checkDescription(string $str) : string
{
// run checkTextBlob and also replace \n => \s and \s+ => \s
$str = preg_replace(parent::$PATTERN_TEXT_BLOB, '', $str);
$str = strtr($str, ["\n" => ' ', "\r" => ' ']);
return preg_replace('/\s+/', ' ', trim($str));
}
}
?>

View File

@@ -652,7 +652,7 @@ var PageTemplate = new function()
$.each(g_user.guides, function(idx, guide)
{
var menuItem = [guide.id, guide.title, guide.url, [[guide.id, LANG.button_edit, '/?guide=edit&id=' + guide.id]]];
var menuItem = [guide.id, guide.title, guide.url, [[guide.id, LANG.button_edit, '?guide=edit&id=' + guide.id]]];
submenu.push(menuItem);
});