diff --git a/CHANGELOG.md b/CHANGELOG.md index 00eb50f..537383f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v1.1.8 +## 01/28/2022 + +1. [](#new) + * Require **Grav 1.7.29** +3. [](#improved) + * Made path handling unicode-safe, use new `Utils::basename()` and `Utils::pathinfo()` everywhere + # v1.1.7 ## 01/03/2022 diff --git a/README.md b/README.md index 4b91278..976355f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The **Flex Objects** Plugin is for [Grav CMS](https://github.com/getgrav/grav). ## System Requirements -Plugin requires **Grav** v1.7.19 or later version in order to run. Additionally you need **Form Plugin** v5.1.0 and optionally **Admin Plugin** v1.10.19 or later version. +Plugin requires **Grav** v1.7.25 or later version in order to run. Additionally you need **Form Plugin** v5.1.0 and optionally **Admin Plugin** v1.10.25 or later version. ## Installation diff --git a/admin/templates/flex-objects/types/default/configure.html.twig b/admin/templates/flex-objects/types/default/configure.html.twig index 4495527..2d72493 100644 --- a/admin/templates/flex-objects/types/default/configure.html.twig +++ b/admin/templates/flex-objects/types/default/configure.html.twig @@ -16,7 +16,7 @@ {%- if title_config.template -%} {{- include(template_from_string(title_config.template, 'configure title template')) -}} {%- else -%} - {{- directory.title }} {{ 'PLUGIN_ADMIN.CONFIGURATION'|tu -}} + {{- directory.title|tu }} - {{ 'PLUGIN_ADMIN.CONFIGURATION'|tu -}} {% endif %} {%- endset %} diff --git a/admin/templates/flex-objects/types/default/edit.html.twig b/admin/templates/flex-objects/types/default/edit.html.twig index b14310d..ecab064 100644 --- a/admin/templates/flex-objects/types/default/edit.html.twig +++ b/admin/templates/flex-objects/types/default/edit.html.twig @@ -64,7 +64,7 @@ {% if allowed and user.authorize('admin.super') %} {% if directory and object or action == 'add' %} {% set save_location = object.getStorageFolder() ?? directory.getStorageFolder() %} -
{{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: {{ url(save_location, false, true)|trim('/') }} {{ not object.exists ? '[NEW]' }}
+
{{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: {{ url(save_location, false, true)|trim('/') }} {{ not object.exists ? '[' ~ 'PLUGIN_FLEX_OBJECTS.NEW'|tu|upper ~ ']' }}
{% endif %} {% endif %} {% if object.exists and form.flash.exists %} diff --git a/admin/templates/flex-objects/types/default/list.html.twig b/admin/templates/flex-objects/types/default/list.html.twig index 3da6805..c9532d1 100644 --- a/admin/templates/flex-objects/types/default/list.html.twig +++ b/admin/templates/flex-objects/types/default/list.html.twig @@ -40,7 +40,7 @@ {%- if title_config.template -%} {{- include(template_from_string(title_config.template, 'configure title template')) -}} {%- else -%} - {{- directory.title -}} + {{- directory.title|tu -}} {% endif %} {%- endset %} diff --git a/admin/templates/flex-objects/types/default/titlebar/edit.html.twig b/admin/templates/flex-objects/types/default/titlebar/edit.html.twig index c0b0de6..b209e44 100644 --- a/admin/templates/flex-objects/types/default/titlebar/edit.html.twig +++ b/admin/templates/flex-objects/types/default/titlebar/edit.html.twig @@ -35,7 +35,7 @@

{% if allowed %} - {{ not object.exists ? '[NEW]' }} {{ title }} + {{ not object.exists ? '[' ~ 'PLUGIN_FLEX_OBJECTS.NEW'|tu|upper ~ ']' }} {{ title|tu }} {% else %} {{ 'PLUGIN_ADMIN.ERROR'|tu }} diff --git a/admin/templates/flex-objects/types/default/titlebar/preview.html.twig b/admin/templates/flex-objects/types/default/titlebar/preview.html.twig index d50cbe7..6b7bad7 100644 --- a/admin/templates/flex-objects/types/default/titlebar/preview.html.twig +++ b/admin/templates/flex-objects/types/default/titlebar/preview.html.twig @@ -19,7 +19,7 @@

{% if allowed %} - {{ "PLUGIN_ADMIN.PREVIEW"|tu }}: {{ not object.exists ? '[NEW]' }} {{ title }} + {{ "PLUGIN_ADMIN.PREVIEW"|tu }}: {{ not object.exists ? '[' ~ 'PLUGIN_FLEX_OBJECTS.NEW'|tu|upper ~ ']' }} {{ title }} {% else %} {{ 'PLUGIN_ADMIN.ERROR'|tu }} diff --git a/admin/templates/flex-objects/types/pages/edit.html.twig b/admin/templates/flex-objects/types/pages/edit.html.twig index baf5c87..a370b87 100644 --- a/admin/templates/flex-objects/types/pages/edit.html.twig +++ b/admin/templates/flex-objects/types/pages/edit.html.twig @@ -89,7 +89,7 @@ {% if allowed and user.authorize('admin.super') %}
{% set save_location = object.getStorageFolder() ?: directory.getStorageFolder() %} - {{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: {{ url(save_location, false, true)|trim('/') }} {{ not object.exists ? '[NEW]' }} (type: {{ (form.getValue('name') ?: 'default') }}) + {{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: {{ url(save_location, false, true)|trim('/') }} {{ not object.exists ? '[' ~ 'PLUGIN_FLEX_OBJECTS.NEW'|tu|upper ~ ']' }} (type: {{ (form.getValue('name') ?: 'default') }})
{% endif %} {% if object.exists and form.flash.exists %} diff --git a/admin/templates/forms/fields/flex-objects/flex-objects.html.twig b/admin/templates/forms/fields/flex-objects/flex-objects.html.twig index 92db6dc..ea0ad6a 100644 --- a/admin/templates/forms/fields/flex-objects/flex-objects.html.twig +++ b/admin/templates/forms/fields/flex-objects/flex-objects.html.twig @@ -60,7 +60,7 @@ {% set translation = (grav.twig.twig.filters['tu'] is defined ? text|tu : text|t)|trim %} - {{ directory.title }} + {{ directory.title|tu }} {% endfor %} {% else %} diff --git a/blueprints.yaml b/blueprints.yaml index 3464d13..a951a32 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Flex Objects slug: flex-objects type: plugin -version: 1.1.7 +version: 1.1.8 description: Flex Objects plugin allows you to manage Flex Objects in Grav Admin. icon: list-alt author: @@ -14,7 +14,7 @@ docs: https://github.com/trilbymedia/grav-plugin-flex-objects/blob/develop/READM license: MIT dependencies: - - { name: grav, version: '>=1.7.25' } + - { name: grav, version: '>=1.7.29' } - { name: form, version: '>=5.1.0' } form: diff --git a/classes/Controllers/MediaController.php b/classes/Controllers/MediaController.php index 6680bea..0c7f844 100644 --- a/classes/Controllers/MediaController.php +++ b/classes/Controllers/MediaController.php @@ -115,7 +115,7 @@ public function taskMediaUpload(): ResponseInterface $media = $object->getMedia(); $media->add($filename, $medium); - $basename = str_replace(['@3x', '@2x'], '', pathinfo($filename, PATHINFO_BASENAME)); + $basename = str_replace(['@3x', '@2x'], '', Utils::pathinfo($filename, PATHINFO_BASENAME)); if (isset($media[$basename])) { $metadata = $media[$basename]->metadata() ?: []; } @@ -132,6 +132,43 @@ public function taskMediaUpload(): ResponseInterface return $this->createJsonResponse($response); } + public function taskMediaUploadMeta(): ResponseInterface + { + $this->checkAuthorization('media.create'); + + $object = $this->getObject(); + if (null === $object) { + throw new RuntimeException('Not Found', 404); + } + + if (!method_exists($object, 'checkUploadedMediaFile')) { + throw new RuntimeException('Not Found', 404); + } + + // Get updated object from Form Flash. + $flash = $this->getFormFlash($object); + if ($flash->exists()) { + $object = $flash->getObject() ?? $object; + $object->update([], $flash->getFilesByFields()); + } + + // Get field and data for the uploaded media. + $field = $this->getPost('field'); + $data = $this->getPost('data'); + $filename = Utils::basename($data['name']); + + $response = [ + 'code' => 200, + 'status' => 'success', + 'message' => $this->translate('PLUGIN_ADMIN.FILE_UPLOADED_SUCCESSFULLY'), + 'field' => $field, + 'filename' => $filename, + 'metadata' => $data + ]; + + return $this->createJsonResponse($response); + } + /** * @return ResponseInterface */ @@ -207,7 +244,7 @@ public function taskMediaCopy(): ResponseInterface $metadata = []; $include_metadata = $this->grav['config']->get('system.media.auto_metadata_exif', false); if ($include_metadata) { - $basename = str_replace(['@3x', '@2x'], '', pathinfo($filename, PATHINFO_BASENAME)); + $basename = str_replace(['@3x', '@2x'], '', Utils::pathinfo($filename, PATHINFO_BASENAME)); $media = $object->getMedia(); if (isset($media[$basename])) { $metadata = $media[$basename]->metadata() ?: []; diff --git a/classes/Flex.php b/classes/Flex.php index 32f2c5a..0914e88 100644 --- a/classes/Flex.php +++ b/classes/Flex.php @@ -65,7 +65,7 @@ public function __construct(FlexInterface $flex, array $types) // Backwards compatibility to v1.0.0-rc.3 $blueprint = $legacy[$blueprint] ?? $blueprint; - $type = basename((string)$blueprint, '.yaml'); + $type = Utils::basename((string)$blueprint, '.yaml'); if ($type) { $this->managed[] = $type; } @@ -238,7 +238,7 @@ public function getBlueprints(): array $directories = []; $all = Folder::all('blueprints://flex-objects', $params); foreach ($all as $url) { - $type = basename($url, '.yaml'); + $type = Utils::basename($url, '.yaml'); $directory = new FlexDirectory($type, $url); if ($directory->getConfig('hidden') !== true) { $directories[$type] = $directory; diff --git a/cli/FlexConvertDataCommand.php b/cli/FlexConvertDataCommand.php index c5bb993..879601c 100644 --- a/cli/FlexConvertDataCommand.php +++ b/cli/FlexConvertDataCommand.php @@ -3,6 +3,7 @@ namespace Grav\Plugin\Console; use Exception; +use Grav\Common\Utils; use Grav\Common\Yaml; use Grav\Console\ConsoleCommand; use Symfony\Component\Console\Input\InputOption; @@ -51,7 +52,7 @@ protected function serve(): int $out_raw = null; $in = $input->getOption('in'); - $in_parts = pathinfo($in); + $in_parts = Utils::pathinfo($in); $in_extension = $in_parts['extension']; $out_extension = $input->getOption('out'); diff --git a/flex-objects.php b/flex-objects.php index 58070ab..4b77c89 100644 --- a/flex-objects.php +++ b/flex-objects.php @@ -9,6 +9,7 @@ use Grav\Common\Page\Types; use Grav\Common\Plugin; use Grav\Common\User\Interfaces\UserInterface; +use Grav\Common\Utils; use Grav\Events\FlexRegisterEvent; use Grav\Events\PermissionsRegisterEvent; use Grav\Events\PluginsLoadedEvent; @@ -479,7 +480,7 @@ protected function registerDirectories(\Grav\Framework\Flex\Flex $flex, array $t foreach ($types as $blueprint) { // Backwards compatibility to v1.0.0-rc.3 $blueprint = $map[$blueprint] ?? $blueprint; - $type = basename((string)$blueprint, '.yaml'); + $type = Utils::basename((string)$blueprint, '.yaml'); if (!$type) { continue; } diff --git a/languages/de.yaml b/languages/de.yaml index 4988e18..eab9634 100644 --- a/languages/de.yaml +++ b/languages/de.yaml @@ -14,6 +14,17 @@ PLUGIN_FLEX_OBJECTS: CSV: "CSV" PARENTS: "Eltern" + CONTROLLER: + TASK_DELETE_SUCCESS: 'Eintrag erfolgreich gelöscht' + TASK_DELETE_FAILURE: 'Löschen des Eintrags fehlgeschlagen: %s' + TASK_NEW_FOLDER_SUCCESS: 'Ordner erfolgreich angelegt' + TASK_COPY_SUCCESS: 'Kopie erfolgreich angelegt' + TASK_COPY_FAILURE: 'Kopieren des Eintrags fehlgeschlagen: %s' + TASK_SAVE_SUCCESS: 'Eintrag erfolgreich gespeichert' + TASK_SAVE_FAILURE: 'Speichern des Eintrags fehlgeschlagen: %s' + TASK_CONFIGURE_SUCCESS: 'Konfiguration erfolgreich gespeichert' + TASK_CONFIGURE_FAILURE: 'Speichern der Konfiguration fehlgeschlagen: %s' + ACTION: CREATE_NEW: Neuen Eintrag anlegen EDIT_ITEM: Eintrag bearbeiten @@ -57,4 +68,4 @@ PLUGIN_FLEX_OBJECTS: BLUEPRINT_NO_LIST_TEMPLATE: "Bitte leg für diesen Typ ein Template an flex-objects/types/%s/list.html.twig" LIST_EMPTY: "Keine Einträge vorhanden." LIST_EMPTY_ADD: "Keine Einträge vorhanden. Klicke den Hinzufügen Button um einen Eintrag anzulegen." - NO_FLEX_DIRECTORIES: "Keine Flex Verzeichnisse erkannt" \ No newline at end of file + NO_FLEX_DIRECTORIES: "Keine Flex Verzeichnisse erkannt" diff --git a/languages/en.yaml b/languages/en.yaml index c761a77..1110b92 100644 --- a/languages/en.yaml +++ b/languages/en.yaml @@ -5,7 +5,7 @@ PLUGIN_FLEX_OBJECTS: TITLE: Flex Objects TYPES_TITLE: Directories AFTER_SAVE: After Save… - LIST_INFO: 'Displaying {from} to {to} out of {total} records' + LIST_INFO: "Displaying {from} to {to} out of {total} records" EMPTY_RESULT: The requested query returns no result USE_BUILT_IN_CSS: "Use built in CSS" @@ -13,21 +13,23 @@ PLUGIN_FLEX_OBJECTS: DIRECTORIES: "Directories" CSV: "CSV" PARENTS: "Parents" + NEW: "New" CONTROLLER: - TASK_DELETE_SUCCESS: 'Entry deleted successfully' - TASK_DELETE_FAILURE: 'Failed to delete entry: %s' - TASK_NEW_FOLDER_SUCCESS: 'Folder created successfully' - TASK_COPY_SUCCESS: 'Copy created successfully' - TASK_COPY_FAILURE: 'Failed to create copy: %s' - TASK_SAVE_SUCCESS: 'Entry saved successfully' - TASK_SAVE_FAILURE: 'Failed to save entry: %s' - TASK_CONFIGURE_SUCCESS: 'Configuration saved successfully' - TASK_CONFIGURE_FAILURE: 'Failed to save configuration: %s' + TASK_DELETE_SUCCESS: "Entry deleted successfully" + TASK_DELETE_FAILURE: "Failed to delete entry: %s" + TASK_NEW_FOLDER_SUCCESS: "Folder created successfully" + TASK_COPY_SUCCESS: "Copy created successfully" + TASK_COPY_FAILURE: "Failed to create copy: %s" + TASK_SAVE_SUCCESS: "Entry saved successfully" + TASK_SAVE_FAILURE: "Failed to save entry: %s" + TASK_CONFIGURE_SUCCESS: "Configuration saved successfully" + TASK_CONFIGURE_FAILURE: "Failed to save configuration: %s" ACTION: CREATE_NEW: Create New Item EDIT_ITEM: Edit Item + LIST_ITEMS: "List Items" LIST_ITEM: List Items DELETE_N: "Delete" # In some languages 'delete OBJECT' may need a special declination REALLY_DELETE: "Are you sure you want to permanently delete the %s?" @@ -35,7 +37,6 @@ PLUGIN_FLEX_OBJECTS: ADVANCED_OPTIONS: "Advanced Options" APPLY_FILTERS: "Apply Filters" RESET_FILTERS: "Reset to Defaults" - LIST_ITEMS: "List Items" FILTER: PAGE_ATTRIBUTES: "Page Attributes" @@ -68,5 +69,5 @@ PLUGIN_FLEX_OBJECTS: BLUEPRINT_NO_LIST_ADVISE: "Please add list of fields to blueprints file." BLUEPRINT_NO_LIST_TEMPLATE: "Please create template file for the type in flex-objects/types/%s/list.html.twig" LIST_EMPTY: "There are currently no entries." - LIST_EMPTY_ADD: "There are currently no entries, click the Add button to create a new one…" - NO_FLEX_DIRECTORIES: "No Flex Directories detected" \ No newline at end of file + LIST_EMPTY_ADD: "There are currently no entries. Click the Add button to create a new one…" + NO_FLEX_DIRECTORIES: "No Flex Directories detected" diff --git a/languages/es.yaml b/languages/es.yaml new file mode 100644 index 0000000..df62fd6 --- /dev/null +++ b/languages/es.yaml @@ -0,0 +1,73 @@ +PLUGIN_FLEX_OBJECTS: + PLUGIN_NAME: "Flex Objects" + PLUGIN_DESCRIPTION: "El plugin Flex Objects permite manejar Objetos Flex en Grav Admin." + + TITLE: Flex Objects + TYPES_TITLE: Directorios + AFTER_SAVE: "Después de guardar…" + LIST_INFO: "Mostrando de {from} a {to} de {total} registros" + EMPTY_RESULT: The requested query returns no result + + USE_BUILT_IN_CSS: "Usar CSS incorporado" + EXTRA_ADMIN_TWIG_PATH: "Ruta extra de twig para Admin" + DIRECTORIES: "Directorios" + CSV: "CSV" + PARENTS: "Madres" + NEW: Nuevo + + CONTROLLER: + TASK_DELETE_SUCCESS: "Entrada eliminada exitosamente" + TASK_DELETE_FAILURE: "Falla al eliminar la entrada: %s" + TASK_NEW_FOLDER_SUCCESS: "Carpeta creada exitosamente" + TASK_COPY_SUCCESS: "Copia creada exitosamente" + TASK_COPY_FAILURE: "Falla al crear la copia: %s" + TASK_SAVE_SUCCESS: "Entrada guardada exitosamente" + TASK_SAVE_FAILURE: "Falla al guardar la entrada: %s" + TASK_CONFIGURE_SUCCESS: "Configuración gardada exitosamente" + TASK_CONFIGURE_FAILURE: "Falla al guardar la configuración: %s" + + ACTION: + CREATE_NEW: "Crear nuevo ítem" + EDIT_ITEM: "Editar ítem" + LIST_ITEMS: "Listar ítems" + LIST_ITEM: "Listar ítem" + DELETE_N: "Eliminar" + REALLY_DELETE: "¿Realmente quieres eliminar %s permanentemente?" + SEARCH_PLACEHOLDER: "Buscar…" + ADVANCED_OPTIONS: "Opciones avazadas" + APPLY_FILTERS: "Aplicar filtros" + RESET_FILTERS: "Restablecer filtros" + + FILTER: + PAGE_ATTRIBUTES: "Atributos de página" + PAGE_TYPES: "Tipos de página" + MODULAR_TYPES: "Tipos de módulo" + + LANGUAGE: + USING_DEFAULT: "Usando archivo de idioma Predeterminado." + UNUSED_DEFAULT: "También existe un archvivo de idioma Predeterminado." + USING_OVERRIDE: "Usando el idioma de remplazo %s." + NOT_TRANSLATED_YET: "¡Esta página aún no ha sido traducida a %s!" + NO_FALLBACK_FOUND: "No se han encontrado traducciones de apoyo." + FALLING_BACK: "Retrocediendo a %s." + + STATE: + LOADING: "Cargando…" + CREATED_SUCCESSFULLY: "Creado exitosamente" + UPDATED_SUCCESSFULLY: "Actualizado exitosamente" + DELETED_SUCCESSFULLY: "Eliminado exitosamente" + EDITING_DRAFT: "Estás editando un borrador." + NOT_CREATED_YET: "Esta página no existe hasta que se guarde." + + ERROR: + BAD_DIRECTORY: "Directorio errado" + PAGE_NOT_FOUND: "Página no encontrada" + PAGE_NOT_EXIST: "¡Uy! Parece que esta página no existe." + PAGE_FORBIDDEN: "¡Uy! Parece que no tienes permiso para ver esta página." + LAYOUT_NOT_FOUND: "Maquetación de objeto '%s' no encontrada." + BLUEPRINT_NO_LIST: "Plano para %s no define campos mostrados ni remplazo de página de lista." + BLUEPRINT_NO_LIST_ADVISE: "Por favor agrega una lista de campos para el archivo de planos." + BLUEPRINT_NO_LIST_TEMPLATE: "Por favor crea un archivo de plantilla para el tipo en flex-objects/types/%s/list.html.twig" + LIST_EMPTY: "No hay entradas por el momento." + LIST_EMPTY_ADD: "No hay entradas por el momento. Da clic en el botón Agregar para crear una nueva…" + NO_FLEX_DIRECTORIES: "No se detectan Directorios Flex" diff --git a/yarn.lock b/yarn.lock index 8ed4cc9..2a61d15 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1884,9 +1884,9 @@ flatted@^3.1.0: integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA== follow-redirects@^1.14.0: - version "1.14.4" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379" - integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g== + version "1.14.7" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685" + integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ== fs.realpath@^1.0.0: version "1.0.0" @@ -2368,9 +2368,9 @@ nanocolors@^0.1.5: integrity sha512-2pvTw6vYRaBLGir2xR7MxaJtyWkrn+C53EpW8yPotG+pdAwBvt0Xwk4VJ6VHLY0aLthVZPvDfm9TdZvrvAm5UQ== nanoid@^3.1.25: - version "3.1.25" - resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.25.tgz#09ca32747c0e543f0e1814b7d3793477f9c8e152" - integrity sha512-rdwtIXaXCLFAQbnfqDRnI6jaRHp9fTcYBjtFKE8eezcZ7LuLjhUaQGNeMXf1HmRoCH32CLz6XwX0TtxEOS/A3Q== + version "3.2.0" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.2.0.tgz#62667522da6673971cca916a6d3eff3f415ff80c" + integrity sha512-fmsZYa9lpn69Ad5eDn7FMcnnSR+8R34W9qJEijxYhTbfOWzr22n1QxCMzXLK+ODyW2973V3Fux959iQoUxzUIA== natural-compare@^1.4.0: version "1.4.0"