(Grav GitSync) Automatic Commit from GitSync

This commit is contained in:
GitSync
2026-06-14 00:27:27 +00:00
parent a2920f812d
commit 3c1bfda80f
2933 changed files with 491625 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
.gradle
build
out
+30
View File
@@ -0,0 +1,30 @@
# v1.0.4
## 12/11/2018
1. [](#bugfix)
* Update addInlineJs load order
# v1.0.3
## 2/24/2018
1. [](#new)
* Check that dependencies are enabled before loading
# v1.0.2
## 2/24/2018
1. [](#new)
* Check for dependencies before loading
# v1.0.1
## 2/14/2018
1. [](#new)
* Update bugs URL
* Update addAction signature
# v1.0.0
## 1/24/2018
1. [](#initial)
*
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 TwelveTone LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+27
View File
@@ -0,0 +1,27 @@
# Admin Media Move Plugin
The **Admin Media Move** Plugin is for [Grav CMS](http://github.com/getgrav/grav). A plugin which adds the option to move media files in the page bin to another page.
## Installation
Installing the Admin Media Move plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
### GPM Installation (Preferred)
The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's terminal (also called the command line). From the root of your Grav install type:
bin/gpm install admin-media-move
This will install the Admin Media Move plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/admin-media-move`.
### Manual Installation
To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `admin-media-move`. You can find these files on [GitHub](https://github.com) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
You should now have all the plugin files under
/your/site/grav/user/plugins/admin-media-move
> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav) and the [Admin](https://github.com/getgrav/grav-plugin-admin) plugin to operate.
## Usage
@@ -0,0 +1,234 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 TwelveTone LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Grav\Plugin;
use Grav\Common\Grav;
use Grav\Common\Plugin;
/**
* Class AdminMediaMovePlugin
* @package Grav\Plugin
*/
class AdminMediaMovePlugin extends Plugin
{
const ROUTE = '/admin-media-move';
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
public function getPath()
{
return '/' . trim($this->grav['admin']->base, '/') . '/' . trim(self::ROUTE, '/');
}
public function buildBaseUrl()
{
$ret = rtrim($this->grav['uri']->rootUrl(false), '/') . '/' . trim($this->getPath(), '/');
return $ret;
}
public function onPluginsInitialized()
{
if (!$this->isAdmin() || !$this->grav['user']->authenticated) {
return;
}
if ($this->grav['uri']->path() == $this->getPath()) {
return;
}
if (!self::_checkDependencies($this)) {
return;
}
$this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onPagesInitialized' => ['onTwigExtensions', 0],
]);
$this->grav['media-actions']->addAction([
'actionId' => "MediaMove",
'caption' => "Move",
'icon' => "arrows",
'handler' => function ($page, $mediaName, $payload) {
$destination_route = $payload['destination_route'];
if (!$destination_route || !$page || !$mediaName || !$payload) {
$this->outputError("Invalid input");
}
$basePath = $page->path() . DS;
$filePath = $basePath . $mediaName;
if (!file_exists($filePath)) {
$this->outputError("Media file not found");
}
// Locate the target page
$targetPage = $this->grav['pages']->find($destination_route);
if (!$targetPage) {
$this->outputError("Page for route $destination_route not found");
}
$path = $targetPage->path();
try {
rename($filePath, "$path/$mediaName");
$this->grav['log']->info("Moved media file '$mediaName' to '$path'");
} catch (\Exception $e) {
$this->outputError("Could not move file: " . $e);
}
$ret = [
"error" => false
];
// Redirects will not work for fetch, so send destination url in result
if (get($payload, "go", false)) {
// Get the admin edit-page url
//$url = $this->grav['twig']->twig->getExtension('Grav\Plugin\Admin\AdminTwigExtension')->getPageUrl($this, $targetPage);
$url = $this->grav['uri']->rootUrl(false) . "/admin/pages" . $targetPage->route();
$ret["destination_url"] = $url;
}
//header('HTTP/1.1 200 OK');
return $ret;
}
]);
}
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
public function onTwigExtensions()
{
$page = $this->grav['admin']->page(true);
if (!$page) {
return;
}
$modal_move = $this->grav['twig']->twig()->render('move-modal.twig.html', $this->config->get('plugins.admin-media-move.modal_move'));
$jsConfig_move = [
'MODAL' => $modal_move
];
$this->grav['assets']->addInlineJs('var ADMIN_ADDON_MEDIA_MOVE = ' . json_encode($jsConfig_move) . ';', -1000);
$this->grav['assets']->addJs('plugin://admin-media-move/assets/media_move_action.js', -1000, false);
}
public function outputError($msg)
{
header('HTTP/1.1 400 Bad Request');
die(json_encode(['error' => ['msg' => $msg]]));
}
/**
* Checks plugin dependencies. Call this after all plugins have been loaded and are enabled.
*
* @param $plugin
* @param $issues array Receives issues as strings. If null, grav['messages'] is used.
* @return bool true if dependencies are met.
*/
public static function _checkDependencies($plugin, &$issues = null)
{
$grav = Grav::instance();
$errors = 0;
$messages = $grav['messages'];
$plugins = $grav['plugins'];
$deps = $plugin->getBlueprint()->dependencies;
if ($deps) {
foreach ($deps as $dep) {
$name = $dep['name'];
if ($name === 'grav') {
//TODO check grav version
continue;
}
$version = $dep['version'];
if (!preg_match("#^([<>=]+)?(.*)#", $version, $m)) {
continue;
}
$compare = $m[1];
$version = $m[2];
if (!$compare) {
$compare = '=';
}
$found = $plugins->get($name);
if (!$found) {
$msg = "Missing Dependency: '$name'";
if (is_array($issues)) {
$issues[] = $msg;
} else {
$messages->add($msg, 'error');
}
$errors++;
continue;
}
if (!$grav['config']->get("plugins.$name.enabled")) {
//BUG admin should always be enabled if installed
if ($name !== 'admin') {
$msg = "Dependency Not Enabled: '$name'";
if (is_array($issues)) {
$issues[] = $msg;
} else {
$messages->add($msg, 'error');
}
$errors++;
continue;
}
}
$realVersion = $found->blueprints()->version;
if (!version_compare($realVersion, $version, $compare)) {
$msg = "Missing Dependency: '$name' $version";
if (is_array($issues)) {
$issues[] = $msg;
} else {
$messages->add($msg, 'error');
}
$errors++;
continue;
}
}
}
if ($errors > 0) {
$msg = "Plugin '$plugin->name' was not loaded due to dependency issues";
if (is_array($issues)) {
$issues[] = $msg;
} else {
$messages->add($msg, 'error');
}
}
return $errors === 0;
}
}
@@ -0,0 +1,44 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2018 TwelveTone LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
enabled: true
modal_move:
fields:
- type: section
title: "Move Media"
- type: text
label: Filename
name: file_name
readonly: true
- type: pages
label: Destination Page
name: destination_page
- type: text
label: Destination Route
name: destination_route
autofocus: on
@@ -0,0 +1,70 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 TwelveTone LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
// This must be in a function call for remodal to register it
$(function () {
$('body').append(ADMIN_ADDON_MEDIA_MOVE.MODAL);
});
function onMediaAction_MediaMove(actionId, mediaName, mediaElement) {
var modal = $.remodal.lookup[$('[data-remodal-id=modal-admin-media-move]').data('remodal')];
modal.open();
var $modal = modal.$modal;
// Populate fields
$('[name=file_name]', $modal).val(mediaName);
$('[name=destination_route]', $modal).val("");
$('[name=destination_page]', $modal).val("");
// Reset loading state
$('.loading', $modal).addClass('hidden');
$('.button', $modal).removeClass('hidden').css('visibility', 'visible');
$(document).off('click', '[data-remodal-id=modal-admin-media-move] .button');
$(document).on('click', '[data-remodal-id=modal-admin-media-move] .button', function (e) {
var destination_route = $('[name=destination_route]').val();
if (!destination_route) {
destination_route = $('[name=destination_page]').val();
}
if (destination_route) {
const payload = {
destination_route
};
if (e.target.name === 'move_and_go') {
payload.go = true;
}
const callback = function (result) {
if (result.error) {
alert(result.error.msg);
} else {
$(mediaElement).remove();
if (payload.go) {
window.location = result.result.destination_url;
}
}
};
submitMediaAction(actionId, mediaName, payload, callback, modal);
}
});
}
+55
View File
@@ -0,0 +1,55 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2018 TwelveTone LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
name: Admin Media Move
version: 1.0.4
description: Moves media from one page to another.
icon: plug
author:
name: TwelveTone LLC
email: info@twelvetone.tv
homepage: https://www.twelvetone.tv/docs/developer-tools/grav-plugins/grav-admin-media-move-plugin
keywords: grav, plugin, admin, media
bugs: https://github.com/Flamenco/grav-admin-media-move
docs: https://www.twelvetone.tv/docs/developer-tools/grav-plugins/grav-admin-media-move-plugin
license: MIT
dependencies:
- { name: grav, version: '>=1.0.0' }
- { name: admin, version: '>=1.0.0' }
- { name: admin-media-actions, version: '>=1.0.0' }
form:
validation: strict
fields:
enabled:
type: toggle
label: Plugin status
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
+17
View File
@@ -0,0 +1,17 @@
plugins {
id("com.github.hierynomus.license").version("0.14.0")
}
apply plugin:'java'
sourceSets {
grav {
resources {
srcDirs += "."
include "**/*.yaml"
include "**/*.php"
include "**/*.css"
include "**/*.js"
include "**/*.twig"
}
}
}
@@ -0,0 +1,23 @@
<div class="remodal" data-remodal-id="modal-admin-media-move" data-remodal-options="hashTracking: false">
<form method="post" onsubmit='return false;'>
{% for field in fields %}
{% if field.type %}
{% set value = data.value(field.name) %}
<div class="block block-{{field.type}}">
{% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
</div>
{% endif %}
{% endfor %}
<div class="form-field grid">Select a destination page or enter the destination page route.</div>
<div class="button-bar">
<div class="loading">
{{ "Moving" }}... <i class="fa fa-spinner fa-spin"></i>
</div>
<button class="button primary" style="visibility: hidden" name="move">{{ "Move" }}</button>
<button class="button" style="visibility: hidden" name="move_and_go">{{ "Move And Go" }}</button>
</div>
</form>
</div>