From 16cb63b05910055c31dca821c86f2eb815da99e3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 12 May 2026 19:02:03 +0000
Subject: [PATCH] =Attempt to stop queue.js from constantly running poll cycle if the status is 429
---
inc/meta/Form.php | 123 +++++++++++++++++++++++-----------------
1 files changed, 71 insertions(+), 52 deletions(-)
diff --git a/inc/meta/Form.php b/inc/meta/Form.php
index 57bdd85..99a128b 100644
--- a/inc/meta/Form.php
+++ b/inc/meta/Form.php
@@ -88,8 +88,11 @@
// Helper Methods
// ─────────────────────────────────────────────────────────────
- public static function fieldWrap(string $name, string $content, array $config): string
+ public static function fieldWrap(string $name, string $content, array $config, bool $col = false): string
{
+ if (!array_key_exists('type', $config)) {
+ jvbDump('No type set for '.$name.' with config: '.print_r($config, true));
+ }
$classes = static::buildClasses($config);
$datasets = static::buildDatasets($config);
@@ -107,7 +110,7 @@
$output .= static::buildCharacterLimit($config);
$output .= static::buildLabel($name, $config);
if (!array_key_exists('skipInput', $config)) {
- $output .= static::buildInput($content);
+ $output .= static::buildInput($content, $col);
} else {
$output .= $content;
}
@@ -211,14 +214,15 @@
return '';
}
- public static function buildInput(string $content):string
+ public static function buildInput(string $content, bool $col = false):string
{
return sprintf(
- '<div class="field-input-wrapper">
+ '<div class="wrapper row%s">
%s
- <span class="validation-icon success" hidden aria-hidden="true">%s</span>
- <span class="validation-icon error" hidden aria-hidden="true">%s</span>
+ <span class="validation success" hidden aria-hidden="true">%s</span>
+ <span class="validation error" hidden aria-hidden="true">%s</span>
</div><span class="validation-message" hidden role="alert"></span>',
+ $col ? ' col' : '',
$content,
jvbIcon('check-circle'),
jvbIcon('x-circle')
@@ -464,14 +468,16 @@
$checked = filter_var($value, FILTER_VALIDATE_BOOLEAN);
$input = sprintf(
- '<label class="toggle-switch row">
+ '<label class="switch row">
<input type="checkbox" value="1"%s%s />
<div class="slider"></div>
+ %s
<span class="toggle-label">%s</span>
</label>',
static::inputAttrs($name, $config),
$checked ? ' checked' : '',
- array_key_exists('required', $config) && $config['required']===true ? '<span class="required" aria-label="required">*</span>' : ''
+ array_key_exists('required', $config) && $config['required']===true ? '<span class="required" aria-label="required">*</span>' : '',
+ $config['label']??''
);
unset($config['label']);
@@ -585,10 +591,15 @@
? '<span class="required" aria-label="required">*</span>' : ''
);
+
foreach ($options as $optValue => $optConfig) {
+ $class = '';
if (is_array($optConfig)) {
$optLabel = $optConfig['label'] ?? $optValue;
$optIcon = $optConfig['icon'] ?? null;
+ if ($optIcon) {
+ $class = ' class="btn"';
+ }
$optDisabled = !empty($optConfig['disabled']) ? ' disabled' : '';
} else {
$optLabel = $optConfig;
@@ -603,11 +614,12 @@
$optId = esc_attr($idPrefix . $name . '-' . $optValue);
$radios .= sprintf(
- '<input type="radio" name="%s" id="%s" value="%s"%s%s%s />
+ '<input type="radio" name="%s" id="%s" value="%s"%s%s%s%s />
<label class="radio-option" for="%s" title="%s">%s</label>',
esc_attr($name),
$optId,
esc_attr($optValue),
+ $class,
checked($value, $optValue, false),
$optDisabled,
$inputClass,
@@ -629,7 +641,7 @@
//File Type
'subtype' => 'image', //'image', 'video', 'document', 'any'
'accepted' => null, //null = use subtype defaults, or define an array of specific MIME types
- //Upload Behavious
+ //Upload Behaviours
'multiple' => false, //single or multiple uploads
'limit' => 15, //Max number of uploads (0 = unlimited)
'mode' => 'direct', // 'direct' or 'selection' TODO: unneeded?
@@ -638,7 +650,8 @@
'max_size' => null, //override default size limits
'convert' => 'webp', //Image conversion format
'quality' => 90, //Conversion quality
- 'inputData' => []
+ 'inputData' => [],
+ 'data' => []
];
$config = array_merge($defaults, $config);
@@ -648,7 +661,7 @@
return '';
}
$validate = [
- 'subtype' => ['image', 'video', 'document', 'any'],
+ 'subtype' => ['image', 'video', 'document', 'any','timeline'],
'mode' => ['direct', 'selection'],
'destination'=> ['meta', 'post', 'post_group']
];
@@ -665,7 +678,9 @@
//Add upload config to the datasets (handled by fieldWrap())
$attrs = ['subtype', 'mode', 'destination', 'max_size'];
foreach ($attrs as $attr) {
- $config['data'][$attr] = $config[$attr];
+ if (array_key_exists($attr, $config)) {
+ $config['data'][$attr] = $config[$attr];
+ }
}
$config['data']['upload-field'] = '';
$config['data']['type'] = $config['multiple'] ? 'gallery' : 'single';
@@ -685,7 +700,13 @@
$attachmentIds = static::parseIds($value);
+
$input = sprintf(
+ '<input type="hidden" name="%s" value="%s">',
+ esc_attr($name),
+ esc_attr(!empty($attachmentIds) ? implode(',', $attachmentIds) : '')
+ );
+ $input .= sprintf(
'<div class="file-upload-container">
<div class="file-upload-wrapper">
<input type="file"
@@ -740,11 +761,6 @@
$input .= '</div>'; // closes .file-upload-container
- $input .= sprintf(
- '<input type="hidden" name="%s" value="%s">',
- esc_attr($name),
- esc_attr(!empty($attachmentIds) ? implode(',', $attachmentIds) : '')
- );
unset($config['description']);
unset($config['label']);
@@ -757,7 +773,7 @@
<div class="preview-actions">
<div class="selection-controls">
<div class="selected">
- <div class="field">
+ <div class="field checkbox">
<input type="checkbox" id="select-all-uploads" data-select-all data-selects="item-grid" name="select-all-uploads">
<label for="select-all-uploads">
Select All
@@ -833,8 +849,8 @@
{
return sprintf(
'<div class="item-actions row btw">
- <div class="radio-button">
- <input type="radio" class="featured btn" name="featured" id="featured%d" hidden>
+ <div class="btn">
+ <input type="radio" class="featured btn" name="featured" id="featured%s" hidden>
<label for="featured">
%s%s<span class="screen-reader-text">Set as featured image</span>
</label>
@@ -900,12 +916,12 @@
'label' => 'Video Caption',
'data' => ['id' => $ID]
],
- 'image-description' => [
- 'type' => 'textarea',
- 'value' => $description,
- 'label' => 'Video Description',
- 'data' => ['id' => $ID]
- ]
+// 'image-description' => [
+// 'type' => 'textarea',
+// 'value' => $description,
+// 'label' => 'Video Description',
+// 'data' => ['id' => $ID]
+// ]
]
];
@@ -968,12 +984,12 @@
'label' => 'File Caption',
'data' => ['id' => $ID]
],
- 'image-description' => [
- 'type' => 'textarea',
- 'value' => $description,
- 'label' => 'File Description',
- 'data' => ['id' => $ID]
- ]
+// 'image-description' => [
+// 'type' => 'textarea',
+// 'value' => $description,
+// 'label' => 'File Description',
+// 'data' => ['id' => $ID]
+// ]
]
];
@@ -986,9 +1002,9 @@
return $out;
}
- public static function renderImagePreview(?int $ID = null, ?array $additionalFields = null):string
+ public static function renderImagePreview(?int $ID = null, ?array $additionalFields = null, bool $isTemplate = false):string
{
- $out = static::renderUploadItemStart($ID);
+ $out = static::renderUploadItemStart($ID, $isTemplate);
//add image preview
if ($ID) {
$out .= jvbFormatImage($ID, 'tiny', 'medium');
@@ -1030,30 +1046,30 @@
'label' => 'Image Caption',
'data' => ['id' => $ID]
],
- 'image-description' => [
- 'type' => 'textarea',
- 'value' => $description,
- 'label' => 'Image Description',
- 'data' => ['id' => $ID]
- ]
+// 'image-description' => [
+// 'type' => 'textarea',
+// 'value' => $description,
+// 'label' => 'Image Description',
+// 'data' => ['id' => $ID]
+// ]
]
];
$out .= static::render('image_data', '', $fields);
-
- $out .= static::renderUploadItemMetaEnd();
if ($additionalFields) {
$out .= static::additionalFields($additionalFields);
}
+ $out .= static::renderUploadItemMetaEnd();
return $out;
}
protected static function additionalFields(array $fields):string
{
- $out = '';
+ $out = '<details class="fields"><summary>'.jvbDashIcon('edit').'Edit Fields</summary>';
foreach ($fields as $name => $config) {
$out .= static::render($name, '', $config);
}
+ $out .= '</details>';
return $out;
}
@@ -1128,6 +1144,9 @@
protected static function getAcceptedTypesLabel(array $config):string
{
+ if (!array_key_exists('subtype', $config) || $config['subtype'] === 'timeline') {
+ $config['subtype'] = 'image';
+ }
$labels = [
'image' => 'JPG, JPEG, PNG, GIF, or WEBP',
'video' => 'MP4, WEBM, or MOV',
@@ -1179,7 +1198,7 @@
'type' => $config['subtype'],
], $config);
- $registrar = Registrar::getInstance($config['subtype']);
+ $registrar = Registrar::getInstance($config[$config['subtype']]);
$icon = jvbDefaultIcon();
if ($registrar){
$icon = $registrar->getIcon()??jvbDefaultIcon();
@@ -1205,7 +1224,7 @@
}
$plural = static::getPlural($config);
$input .= sprintf(
- '<div class="selected-items row" role="region" aria-label="Selected %s"></div>',
+ '<div class="selected-items row start" role="region" aria-label="Selected %s"></div>',
$plural[1]??''
);
@@ -1494,7 +1513,7 @@
$input .= static::render($newName, '', $fieldConfig);
}
$input .= sprintf(
- '<button type="button" class="button add-tag">%s<span>%s</span></button></div>',
+ '<button type="button" class="button add-tag">%s<span>%s</span></button>',
jvbIcon('plus'),
$config['add_label']??'Add'
);
@@ -1512,7 +1531,7 @@
unset($config['label']);
- return static::fieldWrap($name, $input, $config);
+ return static::fieldWrap($name, $input, $config, true);
}
protected static function renderTagItems(array $fields, mixed $value, string $name, string $tagFormat):string
{
@@ -1597,8 +1616,8 @@
{
$fields = $config['fields'] ?? [];
$rows = is_array($value) ? $value : [];
- if(array_key_exists('row_label', $config)) {
- $config['data']['label'] = esc_attr($config['row_label']);
+ if(array_key_exists('add_label', $config)) {
+ $config['data']['label'] = esc_attr($config['add_label']);
}
$input = sprintf(
@@ -1672,8 +1691,8 @@
$fields = $config['fields'] ?? [];
$values = is_array($value) ? $value : [];
- $wrapper = (array_key_exists('wrap', $config)) ? 'details' : 'fieldset';
- $legend = (array_key_exists('wrap', $config)) ? 'summary' : 'legend';
+ $wrapper = (array_key_exists('wrap', $config) && $config['wrap'] === 'details') ? 'details' : 'fieldset';
+ $legend = (array_key_exists('wrap', $config) && $config['wrap'] === 'details') ? 'summary' : 'legend';
$output = sprintf(
'<%s><%s>%s</%s>'
--
Gitblit v1.10.0