}
connectedCallback() {
+ const allowedFileExtensions = this.dataset.fileExtensions || "";
+ if (allowedFileExtensions !== "") {
+ this.#element.accept = allowedFileExtensions;
+ }
+
const shadow = this.attachShadow({ mode: "open" });
shadow.append(this.#element);
time::after {
content: " (" attr(title) ")";
}
- }`,x.append(D)}m&&(this.#a.dateTime=p.toISOString(),this.#a.title=g.DateAndTime.format(p));let k;if(this.static)k=this.#a.title;else if(E<w.OneMinute)k=window.WoltLabLanguage.getPhrase("wcf.date.relative.now");else if(E<w.OneHour){let x=Math.trunc(E/w.OneMinute);k=g.Minutes.format(x*-1,"minute")}else if(E<w.TwelveHours){let x=Math.trunc(E/w.OneHour);k=g.Hours.format(x*-1,"hour")}else if(E<w.SixDays){let x=g.DayOfWeekAndTime.formatToParts(p);x[0].type==="weekday"?p.getTime()>t?k=this.#t(x,0):p.getTime()>a?k=this.#t(x,-1):k=x.map(W=>W.value).join(""):k=g.DateAndTime.format(p)}else k=g.Date.format(p);k=k.charAt(0).toUpperCase()+k.slice(1),this.#a.textContent=k}#t(m,p){return m.map(k=>k.type==="weekday"?g.TodayOrYesterday.format(p,"day"):k.value).join("")}}window.customElements.define("woltlab-core-date-time",q);let S=()=>{document.querySelectorAll("woltlab-core-date-time").forEach(h=>h.refresh(!1))},z,P=()=>{z=window.setInterval(()=>{l(),S()},6e4)};document.addEventListener("DOMContentLoaded",()=>P(),{once:!0}),document.addEventListener("visibilitychange",()=>{document.hidden?window.clearInterval(z):(S(),P())})}{class e extends HTMLElement{#e;constructor(){super(),this.#e=document.createElement("input"),this.#e.type="file",this.#e.addEventListener("change",()=>{let{files:i}=this.#e;if(!(i===null||i.length===0))for(let c of i){let t=new CustomEvent("shouldUpload",{cancelable:!0,detail:c});if(this.dispatchEvent(t),t.defaultPrevented)continue;let a=new CustomEvent("upload",{detail:c});this.dispatchEvent(a)}})}connectedCallback(){this.attachShadow({mode:"open"}).append(this.#e);let c=document.createElement("style");c.textContent=`
+ }`,x.append(D)}m&&(this.#a.dateTime=p.toISOString(),this.#a.title=g.DateAndTime.format(p));let k;if(this.static)k=this.#a.title;else if(E<w.OneMinute)k=window.WoltLabLanguage.getPhrase("wcf.date.relative.now");else if(E<w.OneHour){let x=Math.trunc(E/w.OneMinute);k=g.Minutes.format(x*-1,"minute")}else if(E<w.TwelveHours){let x=Math.trunc(E/w.OneHour);k=g.Hours.format(x*-1,"hour")}else if(E<w.SixDays){let x=g.DayOfWeekAndTime.formatToParts(p);x[0].type==="weekday"?p.getTime()>t?k=this.#t(x,0):p.getTime()>a?k=this.#t(x,-1):k=x.map(W=>W.value).join(""):k=g.DateAndTime.format(p)}else k=g.Date.format(p);k=k.charAt(0).toUpperCase()+k.slice(1),this.#a.textContent=k}#t(m,p){return m.map(k=>k.type==="weekday"?g.TodayOrYesterday.format(p,"day"):k.value).join("")}}window.customElements.define("woltlab-core-date-time",q);let S=()=>{document.querySelectorAll("woltlab-core-date-time").forEach(h=>h.refresh(!1))},z,P=()=>{z=window.setInterval(()=>{l(),S()},6e4)};document.addEventListener("DOMContentLoaded",()=>P(),{once:!0}),document.addEventListener("visibilitychange",()=>{document.hidden?window.clearInterval(z):(S(),P())})}{class e extends HTMLElement{#e;constructor(){super(),this.#e=document.createElement("input"),this.#e.type="file",this.#e.addEventListener("change",()=>{let{files:i}=this.#e;if(!(i===null||i.length===0))for(let c of i){let t=new CustomEvent("shouldUpload",{cancelable:!0,detail:c});if(this.dispatchEvent(t),t.defaultPrevented)continue;let a=new CustomEvent("upload",{detail:c});this.dispatchEvent(a)}})}connectedCallback(){let i=this.dataset.fileExtensions||"";i!==""&&(this.#e.accept=i),this.attachShadow({mode:"open"}).append(this.#e);let t=document.createElement("style");t.textContent=`
:host {
position: relative;
}
return 'com.woltlab.wcf.attachment';
}
+ public function getAllowedFileExtensions(array $context): array
+ {
+ // TODO: Properly validate the shape of `$context`.
+ $objectType = $context['objectType'] ?? '';
+ $objectID = \intval($context['objectID'] ?? 0);
+ $parentObjectID = \intval($context['parentObjectID'] ?? 0);
+ $tmpHash = $context['tmpHash'] ?? '';
+
+ $attachmentHandler = new AttachmentHandler($objectType, $objectID, $tmpHash, $parentObjectID);
+
+ return $attachmentHandler->getAllowedExtensions();
+ }
+
public function acceptUpload(string $filename, int $fileSize, array $context): FileProcessorPreflightResult
{
// TODO: Properly validate the shape of `$context`.
{
$endpoint = LinkHandler::getInstance()->getControllerLink(FileUploadPreflightAction::class);
+ $allowedFileExtensions = $fileProcessor->getAllowedFileExtensions($context);
+ if (\in_array('*', $allowedFileExtensions)) {
+ $allowedFileExtensions = '';
+ } else {
+ $allowedFileExtensions = \implode(
+ ',',
+ \array_map(
+ static fn (string $fileExtension) => ".{$fileExtension}",
+ $allowedFileExtensions
+ )
+ );
+ }
+
return \sprintf(
<<<'HTML'
<woltlab-core-file-upload
data-endpoint="%s"
data-type-name="%s"
data-context="%s"
+ data-file-extensions="%s"
></woltlab-core-file-upload>
HTML,
StringUtil::encodeHTML($endpoint),
StringUtil::encodeHTML($fileProcessor->getTypeName()),
StringUtil::encodeHTML(JSON::encode($context)),
+ StringUtil::encodeHTML($allowedFileExtensions),
);
}
}
*/
interface IFileProcessor
{
- public function getTypeName(): string;
-
public function acceptUpload(string $filename, int $fileSize, array $context): FileProcessorPreflightResult;
+
+ public function getAllowedFileExtensions(array $context): array;
+
+ public function getTypeName(): string;
}