Merge pull request #14737 from MrPetovan/bug/14131-dropzone-error

Account for calendar post edition in editpost()
This commit is contained in:
Tobias Diekershoff 2025-01-27 06:31:10 +01:00 committed by GitHub
commit 73fd2b23a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 64 additions and 57 deletions

View file

@ -86,7 +86,7 @@ class Temporal
$o .= '<optgroup label="' . DI::l10n()->t($continent) . '">'; $o .= '<optgroup label="' . DI::l10n()->t($continent) . '">';
} }
} }
$city = str_replace('_', ' ', DI::l10n()->t($city)); $city = str_replace('_', ' ', DI::l10n()->t($city));
$selected = (($value == $current) ? " selected=\"selected\" " : ""); $selected = (($value == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"$value\" $selected >$city</option>"; $o .= "<option value=\"$value\" $selected >$city</option>";
} }
@ -137,27 +137,29 @@ class Temporal
if ($dob < '0000-01-01') { if ($dob < '0000-01-01') {
$value = ''; $value = '';
$age = 0; $age = 0;
} elseif ($dob < '0001-00-00') { } elseif ($dob < '0001-00-00') {
$value = substr($dob, 5); $value = substr($dob, 5);
$age = 0; $age = 0;
} else { } else {
$value = DateTimeFormat::utc($dob, 'Y-m-d'); $value = DateTimeFormat::utc($dob, 'Y-m-d');
$age = self::getAgeByTimezone($value, $timezone); $age = self::getAgeByTimezone($value, $timezone);
} }
$tpl = Renderer::getMarkupTemplate("field_input.tpl"); $tpl = Renderer::getMarkupTemplate("field_input.tpl");
$o = Renderer::replaceMacros($tpl, $o = Renderer::replaceMacros(
$tpl,
[ [
'$field' => [ '$field' => [
'dob', 'dob',
DI::l10n()->t('Birthday:'), DI::l10n()->t('Birthday:'),
$value, $value,
intval($age) > 0 ? DI::l10n()->t('Age: ') . DI::l10n()->tt('%d year old', '%d years old', $age) : '', intval($age) > 0 ? DI::l10n()->t('Age: ') . DI::l10n()->tt('%d year old', '%d years old', $age) : '',
'', '',
'placeholder="' . DI::l10n()->t('YYYY-MM-DD or MM-DD') . '"' 'placeholder="' . DI::l10n()->t('YYYY-MM-DD or MM-DD') . '"'
]
] ]
]); );
return $o; return $o;
} }
@ -218,26 +220,28 @@ class Temporal
DateTime $maxDate, DateTime $maxDate,
DateTime $defaultDate = null, DateTime $defaultDate = null,
$label, $label,
string $id = 'datetimepicker', string $id = 'datetimepicker',
bool $pickdate = true, bool $pickdate = true,
bool $picktime = true, bool $picktime = true,
string $minfrom = '', string $minfrom = '',
string $maxfrom = '', string $maxfrom = '',
bool $required = false): string bool $required = false
{ ): string {
// First day of the week (0 = Sunday) // First day of the week (0 = Sunday)
$firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'first_day_of_week', 0); $firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'first_day_of_week') ?: 0;
$lang = DI::l10n()->toISO6391(DI::l10n()->getCurrentLang()); $lang = DI::l10n()->toISO6391(DI::l10n()->getCurrentLang());
// Check if the detected language is supported by the picker // Check if the detected language is supported by the picker
if (!in_array($lang, if (!in_array(
['ar', 'ro', 'id', 'bg', 'fa', 'ru', 'uk', 'en', 'el', 'de', 'nl', 'tr', 'fr', 'es', 'th', 'pl', 'pt', 'ch', 'se', 'kr', $lang,
'it', 'da', 'no', 'ja', 'vi', 'sl', 'cs', 'hu'])) { ['ar', 'ro', 'id', 'bg', 'fa', 'ru', 'uk', 'en', 'el', 'de', 'nl', 'tr', 'fr', 'es', 'th', 'pl', 'pt', 'ch', 'se', 'kr',
'it', 'da', 'no', 'ja', 'vi', 'sl', 'cs', 'hu']
)) {
$lang = 'en'; $lang = 'en';
} }
$o = ''; $o = '';
$dateformat = ''; $dateformat = '';
if ($pickdate) { if ($pickdate) {
@ -271,14 +275,14 @@ class Temporal
'placeholder="' . $readable_format . '"' 'placeholder="' . $readable_format . '"'
], ],
'$datetimepicker' => [ '$datetimepicker' => [
'minDate' => $minDate, 'minDate' => $minDate,
'maxDate' => $maxDate, 'maxDate' => $maxDate,
'defaultDate' => $defaultDate, 'defaultDate' => $defaultDate,
'dateformat' => $dateformat, 'dateformat' => $dateformat,
'firstDay' => $firstDay, 'firstDay' => $firstDay,
'lang' => $lang, 'lang' => $lang,
'minfrom' => $minfrom, 'minfrom' => $minfrom,
'maxfrom' => $maxfrom, 'maxfrom' => $maxfrom,
], ],
]); ]);
@ -309,7 +313,7 @@ class Temporal
$clock = $clock ?? new SystemClock(); $clock = $clock ?? new SystemClock();
$localtime = $posted_date . ' UTC'; $localtime = $posted_date . ' UTC';
$abs = strtotime($localtime); $abs = strtotime($localtime);
if ($abs === false) { if ($abs === false) {
return DI::l10n()->t('never'); return DI::l10n()->t('never');
@ -323,25 +327,25 @@ class Temporal
} }
$isfuture = false; $isfuture = false;
$etime = $now - $abs; $etime = $now - $abs;
if ($etime >= 0 && $etime < 1) { if ($etime >= 0 && $etime < 1) {
return $compare_time ? DI::l10n()->t('less than a second ago') : DI::l10n()->t('today'); return $compare_time ? DI::l10n()->t('less than a second ago') : DI::l10n()->t('today');
} }
if ($etime < 0){ if ($etime < 0) {
$etime = -$etime; $etime = -$etime;
$isfuture = true; $isfuture = true;
} }
$a = [ $a = [
12 * 30 * 24 * 60 * 60 => [DI::l10n()->t('year'), DI::l10n()->t('years')], 12 * 30 * 24 * 60 * 60 => [DI::l10n()->t('year'), DI::l10n()->t('years')],
30 * 24 * 60 * 60 => [DI::l10n()->t('month'), DI::l10n()->t('months')], 30 * 24 * 60 * 60 => [DI::l10n()->t('month'), DI::l10n()->t('months')],
7 * 24 * 60 * 60 => [DI::l10n()->t('week'), DI::l10n()->t('weeks')], 7 * 24 * 60 * 60 => [DI::l10n()->t('week'), DI::l10n()->t('weeks')],
24 * 60 * 60 => [DI::l10n()->t('day'), DI::l10n()->t('days')], 24 * 60 * 60 => [DI::l10n()->t('day'), DI::l10n()->t('days')],
60 * 60 => [DI::l10n()->t('hour'), DI::l10n()->t('hours')], 60 * 60 => [DI::l10n()->t('hour'), DI::l10n()->t('hours')],
60 => [DI::l10n()->t('minute'), DI::l10n()->t('minutes')], 60 => [DI::l10n()->t('minute'), DI::l10n()->t('minutes')],
1 => [DI::l10n()->t('second'), DI::l10n()->t('seconds')], 1 => [DI::l10n()->t('second'), DI::l10n()->t('seconds')],
]; ];
foreach ($a as $secs => $str) { foreach ($a as $secs => $str) {
@ -349,10 +353,9 @@ class Temporal
if ($d >= 1) { if ($d >= 1) {
$r = floor($d); $r = floor($d);
// translators - e.g. 22 hours ago, 1 minute ago // translators - e.g. 22 hours ago, 1 minute ago
if($isfuture){ if($isfuture) {
$format = DI::l10n()->t('in %1$d %2$s'); $format = DI::l10n()->t('in %1$d %2$s');
} } else {
else {
$format = DI::l10n()->t('%1$d %2$s ago'); $format = DI::l10n()->t('%1$d %2$s ago');
} }
@ -381,7 +384,7 @@ class Temporal
return 0; return 0;
} }
$birthdate = new DateTime($dob . ' 00:00:00', new DateTimeZone($timezone)); $birthdate = new DateTime($dob . ' 00:00:00', new DateTimeZone($timezone));
$currentDate = new DateTime('now', new DateTimeZone('UTC')); $currentDate = new DateTime('now', new DateTimeZone('UTC'));
$interval = $birthdate->diff($currentDate); $interval = $birthdate->diff($currentDate);
@ -451,7 +454,7 @@ class Temporal
'October', 'November', 'December' 'October', 'November', 'December'
]; ];
$thisyear = DateTimeFormat::localNow('Y'); $thisyear = DateTimeFormat::localNow('Y');
$thismonth = DateTimeFormat::localNow('m'); $thismonth = DateTimeFormat::localNow('m');
if (!$y) { if (!$y) {
$y = $thisyear; $y = $thisyear;
@ -461,11 +464,11 @@ class Temporal
$m = intval($thismonth); $m = intval($thismonth);
} }
$dn = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; $dn = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
$f = self::getFirstDayInMonth($y, $m); $f = self::getFirstDayInMonth($y, $m);
$l = self::getDaysInMonth($y, $m); $l = self::getDaysInMonth($y, $m);
$d = 1; $d = 1;
$dow = 0; $dow = 0;
$started = false; $started = false;
if (($y == $thisyear) && ($m == $thismonth)) { if (($y == $thisyear) && ($m == $thismonth)) {
@ -473,9 +476,9 @@ class Temporal
} }
$str_month = DI::l10n()->getDay($mtab[$m]); $str_month = DI::l10n()->getDay($mtab[$m]);
$o = '<table class="calendar' . $class . '">'; $o = '<table class="calendar' . $class . '">';
$o .= "<caption>$str_month $y</caption><tr>"; $o .= "<caption>$str_month $y</caption><tr>";
for ($a = 0; $a < 7; $a ++) { for ($a = 0; $a < 7; $a++) {
$o .= '<th>' . mb_substr(DI::l10n()->getDay($dn[$a]), 0, 3, 'UTF-8') . '</th>'; $o .= '<th>' . mb_substr(DI::l10n()->getDay($dn[$a]), 0, 3, 'UTF-8') . '</th>';
} }
@ -496,13 +499,13 @@ class Temporal
$o .= $day; $o .= $day;
} }
$d ++; $d++;
} else { } else {
$o .= '&nbsp;'; $o .= '&nbsp;';
} }
$o .= '</td>'; $o .= '</td>';
$dow ++; $dow++;
if (($dow == 7) && ($d <= $l)) { if (($dow == 7) && ($d <= $l)) {
$dow = 0; $dow = 0;
$o .= '</tr><tr>'; $o .= '</tr><tr>';
@ -510,7 +513,7 @@ class Temporal
} }
if ($dow) { if ($dow) {
for ($a = $dow; $a < 7; $a ++) { for ($a = $dow; $a < 7; $a++) {
$o .= '<td>&nbsp;</td>'; $o .= '<td>&nbsp;</td>';
} }
} }

View file

@ -270,11 +270,15 @@ function editpost(url) {
// To make dropzone fileupload work on editing a comment, we need to // To make dropzone fileupload work on editing a comment, we need to
// attach a new dropzone to modal // attach a new dropzone to modal
dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text'); if ($('#jot-text-wrap').length > 0) {
dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text');
}
modal.show(); modal.show();
$("#jot-popup").show(); $("#jot-popup").show();
linkPreview = $("#profile-jot-text").linkPreview(); if ($("#profile-jot-text").length > 0) {
linkPreview = $("#profile-jot-text").linkPreview();
}
} }
}); });
} }