Skip to content

Commit

Permalink
Merge branch 'release/1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 23, 2015
2 parents c8c9b93 + 1996b7f commit 626d687
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 22 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# v1.0.4
## 12/22/2015

1. [](#improved)
* Improved File input field for admin
* Restore file inputs functionality and process form via JS if no inputs found
1. [](#bugfix)
* Fix for the image preview in the file field on multi-lang sites
* Fix problem in form code introduced by fix to allow file uploads
* Fix redirect in deleting page media

# v1.0.3
## 12/20/2015

Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Admin Panel
version: 1.0.3
version: 1.0.4
description: Adds an advanced administration panel to manage your site
icon: empire
author:
Expand Down Expand Up @@ -83,7 +83,7 @@ form:
0: Disabled
validate:
type: bool
help: Show the beta warning message on the dashboard
help: Show the "Found an issue? Please report it on GitHub." message.

enable_auto_updates_check:
type: toggle
Expand Down
86 changes: 86 additions & 0 deletions classes/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Grav\Common\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Collection;
use Grav\Common\Plugin;
use Grav\Common\Theme;
use Grav\Common\User\User;
use Grav\Common\Utils;
use Grav\Common\Backup\ZipBackup;
Expand Down Expand Up @@ -1402,6 +1404,90 @@ protected function taskSaveas() {
return true;
}

/**
* Determine if the user can edit media
*
* @return bool True if the media action is allowed
*/
protected function canEditMedia()
{
$type = 'media';
if (!$this->authorizeTask('edit media', ['admin.' . $type, 'admin.super'])) {
return false;
}
return true;
}

/**
* Handles removing a media file
*
* @return bool True if the action was performed
*/
public function taskRemoveMedia()
{
if (!$this->canEditMedia()) {
return false;
}

$filename = base64_decode($this->route);
$file = File::instance($filename);
$resultRemoveMedia = false;
$resultRemoveMediaMeta = true;

if ($file->exists()) {
$resultRemoveMedia = $file->delete();

$metaFilePath = $filename . '.meta.yaml';
$metaFilePath = str_replace('@3x', '', $metaFilePath);
$metaFilePath = str_replace('@2x', '', $metaFilePath);

if (is_file($metaFilePath)) {
$metaFile = File::instance($metaFilePath);
$resultRemoveMediaMeta = $metaFile->delete();
}
}

if ($resultRemoveMedia && $resultRemoveMediaMeta) {
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REMOVE_SUCCESSFUL'), 'info');
} else {
$this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.REMOVE_FAILED'), 'error');
}

$this->post = array('_redirect' => 'media');
return true;
}

/**
* Handle deleting a file from a blueprint
*
* @return bool True if the action was performed.
*/
protected function taskRemoveFileFromBlueprint()
{
$uri = $this->grav['uri'];
$this->taskRemoveMedia();

$field = $uri->param('field');
$blueprint = $uri->param('blueprint');
$this->grav['config']->set($blueprint . '.' . $field, '');
if (substr($blueprint, 0, 7) == 'plugins') {
Plugin::saveConfig(substr($blueprint, 8));
}
if (substr($blueprint, 0, 6) == 'themes') {
Theme::saveConfig(substr($blueprint, 7));
}

$redirect = base64_decode($uri->param('redirect'));
$route = $this->grav['config']->get('plugins.admin.route');

if (substr($redirect, 0, strlen($route)) == $route) {
$redirect = substr($redirect, strlen($route) + 1);
}

$this->post = array('_redirect' => $redirect);
return true;
}

/**
* Prepare and return POST data.
*
Expand Down
4 changes: 3 additions & 1 deletion languages/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,6 @@ PLUGIN_ADMIN:
TWIG_UMASK_FIX: "Umask Fix"
TWIG_UMASK_FIX_HELP: "By default Twig creates cached files as 0755, fix switches this to 0775"
CACHE_PERMS: "Cache Permissions"
CACHE_PERMS_HELP: "Default cache folder perms. Usually 0755 or 0775 depending on setup"
CACHE_PERMS_HELP: "Default cache folder perms. Usually 0755 or 0775 depending on setup"
REMOVE_SUCCESSFUL: "Remove Successful"
REMOVE_FAILED: "Remove Failed"
11 changes: 7 additions & 4 deletions themes/grav/js/forms/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@
this.form = $(el);
this.form.data('grav-form-instance', this);
this.form.on('submit', function (e) {
this.submit(this.ajax);
e.preventDefault();
return false;
if (Form.findElements(this.form, 'input[type="file"]', '', false).length == 0) {
//Only process the form if it does not contain file elements, otherwise we cannot get $_FILES correctly
this.submit(this.ajax);
e.preventDefault();
return false;
}
}.bind(this));

this.scanned = false;
Expand Down Expand Up @@ -295,7 +298,7 @@
parent = input.parent('[data-grav-disabled]'),
value = input.val();

if (input.is(':disabled') || (parent && parent.data('grav-disabled') == 'true') || e.attr('type') != 'file') { return; }
if (input.is(':disabled') || (parent && parent.data('grav-disabled') == 'true')) { return; }

if (name) {
values[name] = value;
Expand Down
25 changes: 10 additions & 15 deletions themes/grav/templates/forms/fields/file/file.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,23 @@
Use the "pagemediaselect" type instead.
{% else %}
{% if value %}
{% if files.showuploaded == true %}
{% if files.showuploadedpreview %}
<img src="{{ base_url_relative_frontend == '/' ? '/' : base_url_relative_frontend ~ '/'}}{{ value }}" />
{% else %}
{{ value|replace({(files.destination ~ '/'): ''}) }}
{% endif %}

{% if files.ispluginconfig %}
<a href="{{ uri.addNonce('/admin/media/' ~ base64_encode(base_path ~ '/' ~ value) ~ '/task' ~ config.system.param_sep ~ 'removeFileFromPluginConfig' ~ '/plugin_name' ~ config.system.param_sep ~ files.pluginname ~ '/field_name' ~ config.system.param_sep ~ files.name ~ '/redirect' ~ config.system.param_sep ~ base64_encode(uri.path), 'admin-form', 'admin-nonce') }}">
<i class="fa fa-close"></i>
</a>
{% endif %}
{% endif %}
<img src="{{ uri.rootUrl == '/' ? '/' : uri.rootUrl ~ '/'}}{{ value }}" alt="{{ value|replace({(files.destination ~ '/'): ''}) }}" />
<a href="{{ uri.addNonce(base_url_relative ~
'/media/' ~ base64_encode(base_path ~ '/' ~ value) ~
'/task' ~ config.system.param_sep ~ 'removeFileFromBlueprint' ~
'/blueprint' ~ config.system.param_sep ~ files.blueprint ~
'/field' ~ config.system.param_sep ~ files.name ~
'/redirect' ~ config.system.param_sep ~ base64_encode(uri.path), 'admin-form', 'admin-nonce') }}">
<i class="fa fa-close"></i>
</a>
{% endif %}

<div class="form-input-wrapper {{ field.size }}">
<input
{# required attribute structures #}
name="{{ (scope ~ field.name)|fieldName ~ (files.multiple ? '[]' : '[]') }}"
name="{{ (scope ~ field.name)|fieldName ~ '[]' }}"
{% block input_attributes %}
type="file"
{% if files.multiple %}multiple="multiple"{% endif %}
{% if files.accept %}accept="{{ files.accept|join(',') }}"{% endif %}
{{ parent() }}
{% endblock %}
Expand Down

0 comments on commit 626d687

Please sign in to comment.