Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions inc/class-shortcode-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ public function register_shortcode_ui( $shortcode_tag, $args = array() ) {
$args['shortcode_tag'] = $shortcode_tag;
$this->shortcodes[ $shortcode_tag ] = $args;

// filter the attrs to decode fields with escape=true
add_filter( "shortcode_atts_{$shortcode_tag}", function( $out, $pairs, $atts ) use ( $args ) {

$fields = Shortcode_UI_Fields::get_instance()->get_fields();

foreach ( $args['attrs'] as $attr ) {
if ( ! $fields[ $attr['type'] ]['escape'] ) {
continue;
}
$out[ $attr['attr'] ] = rawurldecode( $out[ $attr['attr'] ] );
}

return $out;
}, 1, 3 );

}

public function get_shortcodes() {
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/class-shortcode-ui-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class Shortcode_UI_Fields {
private $field_defaults = array(
'template' => 'shortcode-ui-field-text',
'view' => 'editAttributeField',
'escape' => false,
);

// Field Settings.
private $fields = array(
'text' => array(),
'textarea' => array(
'template' => 'shortcode-ui-field-textarea',
'escape' => true,
),
'url' => array(
'template' => 'shortcode-ui-field-url',
Expand Down
11 changes: 10 additions & 1 deletion js-tests/build/specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe( "Shortcode Attribute Model", function() {
type: 'text',
value: 'test value',
description: 'test description',
escape: false,
meta: {
placeholder: 'test placeholder'
}
Expand Down Expand Up @@ -73,7 +74,7 @@ describe( "Shortcode Model", function() {
label: 'Attribute',
type: 'text',
value: 'test value',
placeholder: 'test placeholder',
placeholder: 'test placeholder'
}
],
inner_content: {
Expand Down Expand Up @@ -359,6 +360,7 @@ var ShortcodeAttribute = Backbone.Model.extend({
type: '',
value: '',
description: '',
escape: false,
meta: {
placeholder: '',
}
Expand Down Expand Up @@ -443,6 +445,13 @@ Shortcode = Backbone.Model.extend({
return;
}

var type = attr.get( 'type' );

// Encode textareas incase HTML
if ( shortcodeUIFieldData[ type ] && shortcodeUIFieldData[ type ].escape ) {
attr.set( 'value', encodeURIComponent( decodeURIComponent( attr.get( 'value' ) ) ) );
}

attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );

} );
Expand Down
1 change: 1 addition & 0 deletions js-tests/src/shortcodeAttributeModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe( "Shortcode Attribute Model", function() {
type: 'text',
value: 'test value',
description: 'test description',
escape: false,
meta: {
placeholder: 'test placeholder'
}
Expand Down
2 changes: 1 addition & 1 deletion js-tests/src/shortcodeModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe( "Shortcode Model", function() {
label: 'Attribute',
type: 'text',
value: 'test value',
placeholder: 'test placeholder',
placeholder: 'test placeholder'
}
],
inner_content: {
Expand Down
8 changes: 8 additions & 0 deletions js/build/field-attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ var ShortcodeAttribute = Backbone.Model.extend({
type: '',
value: '',
description: '',
escape: false,
meta: {
placeholder: '',
}
Expand Down Expand Up @@ -298,6 +299,13 @@ Shortcode = Backbone.Model.extend({
return;
}

var type = attr.get( 'type' );

// Encode textareas incase HTML
if ( shortcodeUIFieldData[ type ] && shortcodeUIFieldData[ type ].escape ) {
attr.set( 'value', encodeURIComponent( decodeURIComponent( attr.get( 'value' ) ) ) );
}

attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );

} );
Expand Down
8 changes: 8 additions & 0 deletions js/build/field-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var ShortcodeAttribute = Backbone.Model.extend({
type: '',
value: '',
description: '',
escape: false,
meta: {
placeholder: '',
}
Expand Down Expand Up @@ -169,6 +170,13 @@ Shortcode = Backbone.Model.extend({
return;
}

var type = attr.get( 'type' );

// Encode textareas incase HTML
if ( shortcodeUIFieldData[ type ] && shortcodeUIFieldData[ type ].escape ) {
attr.set( 'value', encodeURIComponent( decodeURIComponent( attr.get( 'value' ) ) ) );
}

attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );

} );
Expand Down
20 changes: 13 additions & 7 deletions js/build/shortcode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var ShortcodeAttribute = Backbone.Model.extend({
type: '',
value: '',
description: '',
escape: false,
meta: {
placeholder: '',
}
Expand Down Expand Up @@ -202,6 +203,13 @@ Shortcode = Backbone.Model.extend({
return;
}

var type = attr.get( 'type' );

// Encode textareas incase HTML
if ( shortcodeUIFieldData[ type ] && shortcodeUIFieldData[ type ].escape ) {
attr.set( 'value', encodeURIComponent( decodeURIComponent( attr.get( 'value' ) ) ) );
}

attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );

} );
Expand Down Expand Up @@ -715,16 +723,14 @@ var EditShortcodeForm = wp.Backbone.View.extend({
return;
}

var templateData = {
value: attr.get('value'),
attr_raw: {
name: attr.get('value')
}
}

var viewObjName = shortcodeUIFieldData[ type ].view;
var tmplName = shortcodeUIFieldData[ type ].template;

// decode textareas / html
if ( shortcodeUIFieldData[ type ].escape ) {
attr.set( 'value', decodeURIComponent( attr.get( 'value' ) ) );
}

var view = new sui.views[viewObjName]( { model: attr } );
view.template = wp.media.template( tmplName );
view.shortcode = t.model;
Expand Down
1 change: 1 addition & 0 deletions js/src/models/shortcode-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var ShortcodeAttribute = Backbone.Model.extend({
type: '',
value: '',
description: '',
escape: false,
meta: {
placeholder: '',
}
Expand Down
7 changes: 7 additions & 0 deletions js/src/models/shortcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ Shortcode = Backbone.Model.extend({
return;
}

var type = attr.get( 'type' );

// Encode textareas incase HTML
if ( shortcodeUIFieldData[ type ] && shortcodeUIFieldData[ type ].escape ) {
attr.set( 'value', encodeURIComponent( decodeURIComponent( attr.get( 'value' ) ) ) );
}

attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );

} );
Expand Down
12 changes: 5 additions & 7 deletions js/src/views/edit-shortcode-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ var EditShortcodeForm = wp.Backbone.View.extend({
return;
}

var templateData = {
value: attr.get('value'),
attr_raw: {
name: attr.get('value')
}
}

var viewObjName = shortcodeUIFieldData[ type ].view;
var tmplName = shortcodeUIFieldData[ type ].template;

// decode textareas / html
if ( shortcodeUIFieldData[ type ].escape ) {
attr.set( 'value', decodeURIComponent( attr.get( 'value' ) ) );
}

var view = new sui.views[viewObjName]( { model: attr } );
view.template = wp.media.template( tmplName );
view.shortcode = t.model;
Expand Down