diff --git a/assets/css/dist/admin.css b/assets/css/dist/admin.css new file mode 100644 index 0000000..c390e33 --- /dev/null +++ b/assets/css/dist/admin.css @@ -0,0 +1,26 @@ +/* +---------------------------------------------------------------- + +admin.css +Gravity Forms Administration Styles +For the Signature Add-On +https://www.gravityforms.com + +Gravity Forms is a Rocketgenius project +copyright 2008-2023 Rocketgenius Inc. +https://www.rocketgenius.com +this may not be re-distributed without the +express written permission of the author. + +NOTE: DO NOT EDIT THIS FILE! +THIS FILE IS REPLACED DURING AUTO UPGRADE +AND ANY CHANGES MADE HERE WILL BE OVERWRITTEN. + +---------------------------------------------------------------- +*/ + +.gform-admin .gform-compact-view .gf_signature_container { + display: none; +} + +/*# sourceMappingURL=admin.css.map */ diff --git a/assets/css/dist/admin.min.css b/assets/css/dist/admin.min.css new file mode 100644 index 0000000..835d320 --- /dev/null +++ b/assets/css/dist/admin.min.css @@ -0,0 +1 @@ +.gform-admin .gform-compact-view .gf_signature_container{display:none} \ No newline at end of file diff --git a/assets/css/dist/theme.css b/assets/css/dist/theme.css new file mode 100644 index 0000000..8d04573 --- /dev/null +++ b/assets/css/dist/theme.css @@ -0,0 +1,65 @@ +/* +---------------------------------------------------------------- + +theme.css +Gravity Forms Common Theme Styles +For the Signature Add-On +A simple shared set of styles for form themes for the frontend. +https://www.gravityforms.com + +Gravity Forms is a Rocketgenius project +copyright 2008-2022 Rocketgenius Inc. +https://www.rocketgenius.com +this may not be re-distributed without the +express written permission of the author. + +NOTE: DO NOT EDIT THIS FILE! +THIS FILE IS REPLACED DURING AUTO UPGRADE +AND ANY CHANGES MADE HERE WILL BE OVERWRITTEN. + +---------------------------------------------------------------- +*/ + +.gfield_signature_container { + max-width: 100%; + position: relative; +} + +.gfield_signature_container canvas { + max-width: 100%; + } + +.gfield_signature_image { + max-width: 100%; + position: relative; +} + +.gfield_signature_image img { + max-width: 100%; + } + +.gfield_signature_reset_container svg.gfield_signature_reset_icon, .gfield_signature_reset_container svg.gform_signature_locked_reset, .gfield_signature_image svg.gfield_signature_reset_icon, .gfield_signature_image svg.gform_signature_locked_reset { + cursor: pointer; + opacity: 0.7; + position: absolute; + top: 5px; + } + +.gfield_signature_reset_container svg.gfield_signature_reset_icon:hover, .gfield_signature_reset_container svg.gfield_signature_reset_icon:focus, .gfield_signature_reset_container svg.gform_signature_locked_reset:hover, .gfield_signature_reset_container svg.gform_signature_locked_reset:focus, .gfield_signature_image svg.gfield_signature_reset_icon:hover, .gfield_signature_image svg.gfield_signature_reset_icon:focus, .gfield_signature_image svg.gform_signature_locked_reset:hover, .gfield_signature_image svg.gform_signature_locked_reset:focus { + opacity: 1; + } + +.gfield_signature_reset_container svg.gfield_signature_reset_icon, .gfield_signature_image svg.gfield_signature_reset_icon { + left: calc(100% - 29px); + } + +.gfield_signature_reset_container svg.gform_signature_locked_reset, .gfield_signature_image svg.gform_signature_locked_reset { + display: none; + left: 5px; + } + +.gfield_signature_image svg.gform_signature_locked_reset { + display: block; +} + +/*# sourceMappingURL=theme.css.map */ diff --git a/assets/css/dist/theme.min.css b/assets/css/dist/theme.min.css new file mode 100644 index 0000000..46ebcbc --- /dev/null +++ b/assets/css/dist/theme.min.css @@ -0,0 +1 @@ +.gfield_signature_container{max-width:100%;position:relative}.gfield_signature_container canvas{max-width:100%}.gfield_signature_image{max-width:100%;position:relative}.gfield_signature_image img{max-width:100%}.gfield_signature_image svg.gfield_signature_reset_icon,.gfield_signature_image svg.gform_signature_locked_reset,.gfield_signature_reset_container svg.gfield_signature_reset_icon,.gfield_signature_reset_container svg.gform_signature_locked_reset{cursor:pointer;opacity:.7;position:absolute;top:5px}.gfield_signature_image svg.gfield_signature_reset_icon:focus,.gfield_signature_image svg.gfield_signature_reset_icon:hover,.gfield_signature_image svg.gform_signature_locked_reset:focus,.gfield_signature_image svg.gform_signature_locked_reset:hover,.gfield_signature_reset_container svg.gfield_signature_reset_icon:focus,.gfield_signature_reset_container svg.gfield_signature_reset_icon:hover,.gfield_signature_reset_container svg.gform_signature_locked_reset:focus,.gfield_signature_reset_container svg.gform_signature_locked_reset:hover{opacity:1}.gfield_signature_image svg.gfield_signature_reset_icon,.gfield_signature_reset_container svg.gfield_signature_reset_icon{left:calc(100% - 29px)}.gfield_signature_image svg.gform_signature_locked_reset,.gfield_signature_reset_container svg.gform_signature_locked_reset{display:none;left:5px}.gfield_signature_image svg.gform_signature_locked_reset{display:block} \ No newline at end of file diff --git a/change_log.txt b/change_log.txt new file mode 100644 index 0000000..aad4ffb --- /dev/null +++ b/change_log.txt @@ -0,0 +1,189 @@ +### 4.6 | 2023-11-16 +- Updated the signature field to be compatible with Compact View in Gravity Forms 2.8. +- Fixed a PHP 8.1 notice on form submission. + +### 4.5 | 2023-06-21 +- Fixed an issue that makes the signature reset button hard to press using mobile browsers. + +### 4.4 | 2023-01-18 +- Updated styles to work with the Orbital theme in Gravity Forms 2.7. +- Updated the location of reset icons and lock icon to provide better accessibility and better user experience. +- Updated the editor icon. +- Fixed an issue on the entry edit page that prevents the signature from being edited. + + +### 4.3 | 2022-06-15 +- Fixed an issue where the signature field has no width when used in multiple forms on a page. + + +### 4.2 | 2022-02-17 +- Fixed an issue where the signature field has no width when other form fields use conditional logic. +- Fixed an issue where the signature field does not work correctly for mobile/touch devices. +- Fixed an issue where the lock reset button is not hidden when clicking the signature reset button when a signature is present and the screen is resized. +- Fixed an issue where a conditionally-hidden signature field's width is not updated or responsive. +- API: Updated SuperSignature to version 1.5.0.4. + + +### 4.1 | 2021-09-01 +- Fixed JavaScript errors on the edit entry page that prevent the signature field from being edited. +- Fixed an issue that causes the signature field to throw a JavaScript error on the front-end when the data input doesn't exist. +- Fixed an issue where script tags are output above document head element. +- Fixed a fatal error which can occur when saving the signature in some hosting environments. + + +### 4.0 | 2020-09-23 +- Added security enhancements. +- Added the [gform_signature_url](https://docs.gravityforms.com/gform_signature_url/), [gform_signature_url_permission_granted](https://docs.gravityforms.com/gform_signature_url_permission_granted/), and [gform_signature_url_require_login](https://docs.gravityforms.com/gform_signature_url_require_login/) filters. +- Added support for Gravity Forms 2.5 + + +### 3.9 | 2020-05-18 +- Added translations for Hebrew, Hindi, Japanese, and Turkish. +- Added the label visibility and description placement settings to the field appearance tab. +- Updated Javascript files to use minified versions. +- Fixed signing issue with Windows touch devices. + + +### 3.8 | 2019-07-31 +- Added a check to GFSignature::display_signature() to only use mime_content_type() if the signature image file is local. +- Added security enhancements. +- Added the *[gform_signature_delete_file_pre_delete_entry](https://docs.gravityforms.com/gform_signature_delete_file_pre_delete_entry/)* filter to disable deletion of the signature file or trigger deletion at a later time. + + +### 3.7 | 2019-03-19 +- Fixed signature field not appearing on single page forms or multi-page forms embedded without AJAX. +- Fixed signature field disappearing on multi-page forms embedded via AJAX when rotating mobile device. +- Fixed extra lines added to signature when signing with Chrome on Android. +- Fixed issue where signature was clipped when rotating on mobile devices. + + +### 3.6 | 2018-12-18 +- Added responsive support to Signature field. +- Fixed fatal error when displaying the signature image on some servers. +- Fixed PHP warning message. +- Updated SuperSignature to version 1.5.0.3 and used unhexed version. + + +### 3.5 | 2018-04-09 +- Added security fixes. +- Added query parameter to return signature as transparent image. +- Added GPL to plugin header. +- Updated Plugin URI and Author URI to use https. + + +### 3.4 | 2018-01-29 +- Added compatibility with Gravity Forms 2.3. +- Updated IeModalFix init option to only be set for IE browsers; fixes issue with FireFox with 3+ paths on a signature. +- Fixed a JavaScript error which could occur in the form editor with Gravity Forms 2.3-beta. +- Fixed an issue where the field could be populated with the value from another form on the same page if both fields have the same ID. +- Fixed an issue where the signature file could remain after the entry was permanently deleted. + + +### 3.3 | 2016-10-26 +- Updated initialization options for signature to set different values based on MAC or PC to fix issues with touch not working. + + +### 3.2 | 2016-10-26 +- Updated field appearance settings label classes for consistency with GF2.0+. +- Fixed issue where signing with more than three lines corrupted the signature. +- Fixed a fatal error if Html2RGB() has already been defined by the theme or another plugin. + + +### 3.1 | 2016-06-16 +- Added the [gform_signature_init_options](https://docs.gravityforms.com/gform_signature_init_options) filter. +- Updated to include the ss_orig.js script in the footer. +- Updated the signature container markup to use the height from the init options. +- Updated script to be initialized via *get_form_inline_script_on_page_render()* rather than inline with the input markup. +- Fixed an issue when signing on a Windows touch machine with chrome. +- Fixed an issue with the required field validation when updating an existing entry outside the entry detail context e.g. from a Gravity Flow user input step. +- Fixed a JavaScript error which could occur when the signature init script is included on a page and the field input is not e.g. the Gravity Flow user input step when the field is not editable. +- Fixed an issue with the border width style in the admin and on the front-end for old IE. +- Fixed a JavaScript issue which affected multi-page AJAX enabled forms when loading the next page. + + +### 3.0 | 2016-04-14 +- Added support for Gravity Forms 2.0. +- Added GF_Field_Signature. +- Updated SuperSignature to version 1.5.0.8. +- Fixed an issue where the old signature file was not deleted when using the 'sign again' link. +- Fixed an issue where the signature files would remain when permanently deleting all the entries for a form. +- Fixed an issue which prevented the signature canvas being displayed after deleting the existing signature when editing an entry. +- Fixed some strings in the form editor which were untranslatable. +- Fixed an issue with the borderStyle setting. +- Updated to only include the deleteSignature script on the entry detail edit page. +- Updated location of Signature field settings so they are now located on the Appearance tab. +- Updated SuperSignature; fixing a vertical offset issue with the touch point/capture location when the WP admin bar is present on a mobile device. +- Removed Browser.php. + + +### 2.4 | 2016-01-06 +- Added drag and drop support to the field button in the form editor (GF 1.9). +- Added Spanish (es_ES) translation. +- Updated POT file. +- Updated GFSignature::maybe_save_signature() to public. +- Updated signature script to latest version. +- Fixed a fatal error if Browser.php was already included by another plugin. +- Fixed an issue with the delete signature confirmation message. +- Fixed signature appearing as a black image in some email clients. +- Fixed issue a JavaScript error in the form editor in some languages. +- Fixed issue with causing mixed content warning when Force SSL was enabled in the admin. +- Fixed issue when multiple Html2RGB() functions were defined. +- Fixed issue with folder path causing signature not to be saved correctly on same servers. + + +### 2.3 | 2014-10-16 +- Added function gf_signature to easily get a Signature instance. +- Added text domain/path to header. +- Added support for save and continue in Gravity Forms 1.9. +- Added new filter: *gform_signature_show_in_all_fields* + add_filter( 'gform_signature_show_in_all_fields', '__return_false' ); +- Updated protected functions to be public. +- Updated to have the file class-gf-signature.php and organized code into this file and signature.php. +- Updated version to use a variable. +- Updated to display signature image in {all_fields} tag. + + +### 2.2 | 2014-04-14 +- Updated Super Signature script to latest to resolve issues with Kindle Fire HD. +- Fixed issue with IE11 when using the latest version of the Super Signature script. + + +### 2.1 | 2014-01-31 +- Downgraded super signature script to previous version due to an issue with IE11. + + +### 2.0 | 2014-01-29 +- Added Add-On Framework integration. +- Updated super signature script to 1.5.0.2. +- Updated masked input JS library to 1.3.1. +- Fixed issue creating signature image when output buffer wasn't empty. +- Fixed issue with signature being deleted when editing the entry. + + +### 1.3 | 2013-03-07 +- Fixed issue with signature file name being displayed on the print page instead of the signature image. +- Updated signature script to version 1.3.0.0. + + +### 1.2 | 2012-09-13 +- Added ability to add a signature in the entry detail page when a signature does not already exist. + + +### 1.1 | 2012-08-30 +- Fixed issue with custom validation message not getting displayed. +- Fixed issue with signature URL not being created correctly when resending notifications. +- Fixed conflict with IE8. +- Fixed issues when signing on IE9. +- Fixed issue where editing entry resulted in removal of signature from lead. +- Updated edit entry functionality to support previewing, downloading and deleting signature from lead. + + +### 1.0 | 2012-07-02 +- Fixed issue when signing on IE 9. +- Fixed issue with jQuery being included in the ss_orig.js file. +- Added support for ManageWP. +- Fixed issue with signature files not being deleted when lead is deleted. +- Fixed duplicate field size setting. +- Updated field size setting to an open text input instead of a drop down. +- Fixed conflict with datepicker field. +- Fixed issue with multi-page forms where signature was not maintaining its value from page to page. diff --git a/class-gf-signature.php b/class-gf-signature.php new file mode 100644 index 0000000..49fcaa6 --- /dev/null +++ b/class-gf-signature.php @@ -0,0 +1,778 @@ +is_gravityforms_supported() && class_exists( 'GF_Field' ) ) { + require_once 'includes/class-gf-signature-image.php'; + require_once 'includes/class-gf-field-signature.php'; + add_action( 'parse_request', array( $this, 'display_signature' ) ); + } + } + + /** + * Handles hooks and loading of language files. + */ + public function init() { + parent::init(); + + add_filter( 'gform_merge_tag_filter', array( $this, 'merge_tag_filter' ), 10, 5 ); + add_action( 'gform_delete_lead', array( $this, 'delete_entry' ) ); + add_action( 'gform_delete_entries', array( $this, 'delete_entries' ), 10, 2 ); + add_action( 'gravityforms_cron', array( $this, 'add_index_file' ) ); + + } + + /** + * Initialize the admin specific hooks. + */ + public function init_admin() { + parent::init_admin(); + + add_filter( 'gform_tooltips', array( $this, 'tooltips' ) ); + add_action( 'gform_field_appearance_settings', array( $this, 'field_settings' ), 10, 2 ); + } + + /** + * Initialize the AJAX hooks. + */ + public function init_ajax() { + parent::init_ajax(); + + add_action( 'wp_ajax_gf_delete_signature', array( $this, 'ajax_delete_signature' ) ); + } + + // # SCRIPTS & STYLES ----------------------------------------------------------------------------------------------- + + /** + * Return the plugin's icon for the plugin/form settings menu. + * + * @since 3.9.1 + * + * @return string + */ + public function get_menu_icon() { + + return file_get_contents( $this->get_base_path() . '/images/menu-icon.svg' ); + + } + + /** + * Enqueue styles. + * + * @since 4.4 + * @return array $styles + */ + public function styles() { + + $base_url = $this->get_base_url(); + $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET['gform_debug'] ) ? '' : '.min'; + + $styles = array( + array( + 'handle' => 'gform_signature_editor_css', + 'src' => $base_url . "/assets/css/dist/admin{$min}.css", + 'version' => $this->_version, + 'enqueue' => array( + array( 'admin_page' => array( 'form_editor' ) ), + ) + ), + array( + 'handle' => 'gform_signature_foundation', + 'src' => $base_url . "/assets/css/dist/theme{$min}.css", + 'version' => $this->_version, + 'enqueue' => array( + array( $this, 'should_enqueue_frontend_script' ), + ), + ), + ); + + return array_merge( parent::styles(), $styles ); + } + + + /** + * Return the scripts which should be enqueued. + * + * @return array + */ + public function scripts() { + + $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || isset( $_GET['gform_debug'] ) ? '' : '.min'; + $form = $this->get_current_form(); + + $scripts = array( + array( + 'handle' => 'gform_masked_input', + 'enqueue' => array( + array( 'admin_page' => array( 'form_editor' ) ), + ) + ), + array( + 'handle' => 'super_signature_script', + 'src' => $this->get_base_url() . '/includes/super_signature/ss.js', + 'version' => $this->_version, + 'deps' => array( 'jquery' ), + 'in_footer' => true, + 'enqueue' => array( + array( $this, 'should_enqueue_frontend_script' ), + ), + ), + array( + 'handle' => 'super_signature_base64', + 'src' => $this->get_base_url() . '/includes/super_signature/base64.js', + 'version' => $this->get_version(), + 'enqueue' => array( + array( $this, 'should_enqueue_frontend_script' ), + ), + ), + array( + 'handle' => 'gform_signature_frontend', + 'src' => $this->get_base_url() . "/js/frontend{$min}.js", + 'version' => $this->get_version(), + 'deps' => array( 'jquery', 'super_signature_script', 'super_signature_base64' ), + 'in_footer' => true, + 'enqueue' => array( + array( $this, 'should_enqueue_frontend_script' ), + ), + 'strings' => array( + 'lockedReset' => wp_strip_all_tags( __( 'Reset to re-sign.', 'gravityformssignature' ) ), + ), + ), + array( + 'handle' => 'gform_signature_delete_signature', + 'src' => $this->get_base_url() . "/js/gfsignature_delete_signature{$min}.js", + 'version' => $this->get_version(), + 'deps' => array( 'jquery' ), + 'in_footer' => true, + 'enqueue' => array( + array( $this, 'should_enqueue_delete_script' ), + ), + 'strings' => array( + 'confirm_delete' => esc_html__( "Would you like to delete this file? 'Cancel' to stop. 'OK' to delete", 'gravityformssignature' ), + 'delete_nonce' => wp_create_nonce( 'gf_delete_signature' ), + 'form_id' => ! empty( $form['id'] ) ? absint( $form['id'] ) : false, + ), + ), + ); + + return array_merge( parent::scripts(), $scripts ); + } + + /** + * Frontend scripts should only be enqueued if we're not on a GF admin page and the form contains our field type. + * + * @since 4.4 + * + * @param array $form The current form object. + * + * @return bool + */ + public function should_enqueue_frontend_script( $form ) { + + $is_frontend = GFForms::get_page() === false; + $has_signature_field = ! rgempty( GFFormsModel::get_fields_by_type( $form, array( 'signature' ) ) ); + + return ( $is_frontend || $this->is_entry_edit() ) && $has_signature_field; + } + + /** + * Delete signature script should only be enqueued on the entry edit page on forms with a Signature field. + * + * @since 4.4 + * + * @param array $form The current form object. + * + * @return bool + */ + public function should_enqueue_delete_script( $form ) { + + $has_signature_field = ! rgempty( GFFormsModel::get_fields_by_type( $form, array( 'signature' ) ) ); + + return $this->is_entry_edit() && $has_signature_field; + } + + // # FIELD SETTINGS ------------------------------------------------------------------------------------------------- + + /** + * Add the tooltips for the field. + * + * @param array $tooltips An associative array of tooltips where the key is the tooltip name and the value is the tooltip. + * + * @return array + */ + public function tooltips( $tooltips ) { + $signature_tooltips = array( + 'signature_background_color' => '
=p;p++)n[p]=b[p+1].MathFunc2(b[p]).MathFunc3(3);for(p=0;1>=p;p++)h[p]=n[p+
+ 1].MathFunc2(n[p]).MathFunc3(2);b=this.eV(3,b,k);n=this.eV(2,n,k);h=this.eV(1,h,k);g=b.MathFunc2(g);h=n.dot(n)+g.dot(h);return 1E-5>Math.abs(h)?k:k-g.dot(n)/h},eV:function(b,g,k){g=g.slice();for(var n,h=1;h<=b;h++)for(n=0;n<=b-h;n++)g[n]=g[n].MathFunc3(1-k).MathFunc1(g[n+1].MathFunc3(k));return g[0]},cLP:function(b,g){for(var k=[0],n,h=b+1;h<=g;h++)k[h-b]=k[h-b-1]+this.points[h].MathFunc6(this.points[h-1]);h=1;for(n=g-b;h<=n;h++)k[h]/=k[n];return k},fM:function(b,g,k,n){for(var h=Math.floor((g-b+
+ 1)/2),p=0,r=b+1;r