From d2bd6efa993761aa6dd1852a287e3a9eebf54f73 Mon Sep 17 00:00:00 2001 From: potreb <potreb@gmail.com> Date: Mon, 24 May 2021 10:08:53 +0200 Subject: [PATCH] scope: added new field --- composer.json | 12 ++++++ lang/pl_PL.mo | Bin 0 -> 1159 bytes lang/pl_PL.po | 44 +++++++++++++++++++ src/Field/ImageInputField.php | 19 ++++++++ templates/input-image.php | 79 ++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 lang/pl_PL.mo create mode 100644 lang/pl_PL.po create mode 100644 src/Field/ImageInputField.php create mode 100644 templates/input-image.php diff --git a/composer.json b/composer.json index 345bbde..6a79cb8 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "name": "wpdesk/wp-forms", + "description": "WP Forms", "authors": [ { "name": "Marcin", @@ -8,6 +9,10 @@ { "name": "Krzysiek", "email": "krzysiek@wpdesk.pl" + }, + { + "name": "Piotr Potrebka", + "email": "piotr.potrebka@wpdesk.pl" } ], "require": { @@ -31,6 +36,13 @@ }, "autoload-dev": { }, + "extra": { + "text-domain": "wp-forms", + "translations-folder": "lang", + "po-files": { + "pl_PL": "pl_PL.po" + } + }, "scripts": { "phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never", "phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage", diff --git a/lang/pl_PL.mo b/lang/pl_PL.mo new file mode 100644 index 0000000000000000000000000000000000000000..f621cb5cbf4b151eecddd0e12ca29f4eee4f51c7 GIT binary patch literal 1159 zcmca7#4?qEfq{XIfq_AWfq}t?fq{XWfq|h0B*?(Pu!4bsfro*CVI@?48v_G_7y|>t zWd;TYP6h^sR}2gcd<+Z>Ul<q|^qCnLm>D7Zjae8N#2FYE>{%EXq!}0(!dW2V#ViaA z><kPH^(+hwj8Hq67#J8>85kItp?na<0wSOo<Ti$&)ZF~CRE5mk#Pn2#;MByT<P3$h z{33-!g@U5|l+xr9wT#r9oXi4ihTznk)Z`L{{33<Wf}H%s6b0YZl*~ki;M5YR?$F{? zg_4ZSVuf6=L_kq~R%&vIu4jsFSZYymW`3TPLU@3JTYgb)F;{@UZcu7jCP-A*C9x#c zO2Np$$WYh7RM*Hv!O+0Uz+BtF$iRThC$YFhH>4;ruQ(^MB)`Z?As{oqq(~tkU%{pz zzoaNN$ss*AF*8RmIX~Bq%O^1}y)-dBRW~FxF&Ci}q%1p8!KMJDRS%*qI}w{kD}{ob z_y8X+Ur%3Ggrg1h47i;0^GZ_lN_0ai3sS8VN>VFI^b2wlGxMw!k~0#Eic?E$Lqptj zEfDHJPEJcL(sj*C&QHnAOSe+6NXjhXiqLgW%}XtU`XxU#C9_1qNY9unLN@@+(RE5J zPAy0*$*@w;)8h)rDJ@FO(FF&Yl|o(tm|JXXY^?xc+G^z4+8Qd@D;OwPDdedd8razy zDX6J|nKrg2Af^UL*ucinK%u4vEDlm*ps8T5V5nfFV5Dh{usS%uv?w{%8R8!+1&D{> z4)ac}EYB}WDfY=MF0oRGkGGCbwT{oTGSo4$j;{bw$=30yFh*X5l}WM=NG`QFIX<zZ zq$ob#8qQ2bFrgYiQW+(=IZ#z#CPWpO2~`!J7oV4(UjVYqIzF!g!ZC)}6Ca<Ko>~Hm z7>KZ;juDd2!09?5u_Qy+z)C?6tAwGILUB<tHYwMN<ebu!)D)0jExoK_ylM=s6v|Tb zQu2%NsxpG9iZ3WiP0OrEP2pk)EiOIUqL80dlvu?OTveK#m<7p#*(Ig$JQ!Y?l$lyo grI1saq)<>)m3nk`PG%M~zl9f<B$h+<L)9?=06$t($^ZZW literal 0 HcmV?d00001 diff --git a/lang/pl_PL.po b/lang/pl_PL.po new file mode 100644 index 0000000..9fcc8e9 --- /dev/null +++ b/lang/pl_PL.po @@ -0,0 +1,44 @@ +msgid "" +msgstr "" +"Project-Id-Version: WP Forms\n" +"POT-Creation-Date: 2021-05-24 10:07+0200\n" +"PO-Revision-Date: 2021-05-24 10:07+0200\n" +"Last-Translator: Piotr Po <potreb@gmail.com>\n" +"Language-Team: Piotr Potrebka <piotr.potrebka@gmail.com>\n" +"Language: pl_PL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.3\n" +"X-Poedit-Basepath: ..\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " +"|| n%100>=20) ? 1 : 2);\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: __;_e;_n:1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;esc_attr__;" +"esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c;_n_noop:1,2;" +"_nx_noop:3c,1,2;__ngettext_noop:1,2\n" +"X-Poedit-SearchPath-0: .\n" +"X-Poedit-SearchPath-1: src\n" +"X-Poedit-SearchPathExcluded-0: *.js\n" +"X-Poedit-SearchPathExcluded-1: vendor\n" +"X-Poedit-SearchPathExcluded-2: vendor_prefixed\n" + +#: templates/input-image.php:24 +msgid "Set image" +msgstr "Wstaw obraz" + +#: templates/input-image.php:29 +msgid "Remove image" +msgstr "Usuń obraz" + +#: templates/input-image.php:50 +msgid "Select or Upload Media" +msgstr "Wybierz lub prześlij media" + +#: templates/input-image.php:52 +msgid "Use this media" +msgstr "Wybierz" + +#: templates/product-select.php:13 +msgid "Search for a product…" +msgstr "Szukaj produktu…" diff --git a/src/Field/ImageInputField.php b/src/Field/ImageInputField.php new file mode 100644 index 0000000..dd4226c --- /dev/null +++ b/src/Field/ImageInputField.php @@ -0,0 +1,19 @@ +<?php + +namespace WPDesk\Forms\Field; + +class ImageInputField extends \WPDesk\Forms\Field\BasicField { + + public function __construct() { + parent::__construct(); + $this->set_default_value( '' ); + $this->set_attribute( 'type', 'text' ); + } + + /** + * @return string + */ + public function get_template_name() { + return 'input-image'; + } +} diff --git a/templates/input-image.php b/templates/input-image.php new file mode 100644 index 0000000..8b805c6 --- /dev/null +++ b/templates/input-image.php @@ -0,0 +1,79 @@ +<?php +/** + * @var \WPDesk\Forms\Field $field + * @var string $name_prefix + * @var string $value + */ +?> +<?php +$media_container_id = 'media_' . sanitize_key( $field->get_id() ); +?> +<div class="media-input-wrapper" id="<?php echo $media_container_id; ?>"> + <input type="hidden" class="image-field-value" value="<?php echo \esc_html( $value ); ?>" + name="<?php echo \esc_attr( $name_prefix ) . '[' . \esc_attr( $field->get_name() ) . ']'; ?>" + id="<?php echo \esc_attr( $field->get_id() ); ?>"/> + <div class="custom-img-container"> + <?php if ( $value ) : ?> + <img src="<?php echo $value ?>" alt="" width="100"/> + <?php endif; ?> + </div> + <p class="hide-if-no-js"> + <a class="upload-custom-img <?php if ( $value ) { + echo 'hidden'; + } ?>" href="<?php echo $value ?>"> + <?php _e( 'Set image', 'wp-forms' ) ?> + </a> + <a class="delete-custom-img <?php if ( ! $value ) { + echo 'hidden'; + } ?>" href="#"> + <?php _e( 'Remove image', 'wp-forms' ) ?> + </a> + </p> +</div> +<script> + jQuery( function ( $ ) { + var frame, + metaBox = $( '#<?php echo $media_container_id; ?>' ), + addImgLink = metaBox.find( '.upload-custom-img' ), + delImgLink = metaBox.find( '.delete-custom-img' ), + imgContainer = metaBox.find( '.custom-img-container' ), + imgIdInput = metaBox.find( '.image-field-value' ); + + addImgLink.on( 'click', function ( event ) { + event.preventDefault(); + if ( frame ) { + frame.open(); + return; + } + + frame = wp.media( { + title: <?php _e( 'Select or Upload Media', 'wp-forms' ); ?>, + button: { + text: <?php _e( 'Use this media', 'wp-forms' ); ?> + }, + library: { + type: ['image'] + }, + multiple: false + } ); + + frame.on( 'select', function () { + var attachment = frame.state().get( 'selection' ).first().toJSON(); + imgContainer.append( '<img src="' + attachment.url + '" alt="" width="100" />' ); + imgIdInput.val( attachment.url ); + addImgLink.addClass( 'hidden' ); + delImgLink.removeClass( 'hidden' ); + } ); + frame.open(); + } ); + + delImgLink.on( 'click', function () { + imgContainer.html( '' ); + addImgLink.removeClass( 'hidden' ); + delImgLink.addClass( 'hidden' ); + imgIdInput.val( '' ); + return false; + } ); + + } ); +</script> -- GitLab