wp/wp-content/plugins/portfolio/bws_menu/deactivation-form.php
changeset 16 a86126ab1dd4
parent 12 d8a8807227e4
child 19 3d72ae0968f4
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    15  */
    15  */
    16 if ( ! function_exists( 'bws_add_deactivation_feedback_dialog_box' ) ) {
    16 if ( ! function_exists( 'bws_add_deactivation_feedback_dialog_box' ) ) {
    17 	function bws_add_deactivation_feedback_dialog_box() {
    17 	function bws_add_deactivation_feedback_dialog_box() {
    18 		global $bstwbsftwppdtplgns_active_plugins;
    18 		global $bstwbsftwppdtplgns_active_plugins;
    19 		if ( empty( $bstwbsftwppdtplgns_active_plugins ) )
    19 		if ( empty( $bstwbsftwppdtplgns_active_plugins ) )
    20 			return;
    20 			return;		
       
    21 
       
    22 		$contact_support_template = __( 'Need help? We are ready to answer your questions.', 'bestwebsoft' ) . ' <a href="https://support.bestwebsoft.com/hc/en-us/requests/new" target="_blank">' . __( 'Contact Support', 'bestwebsoft' ) . '</a>';
       
    23 
       
    24 		$reasons = array(
       
    25 			array(
       
    26 				'id'                => 'NOT_WORKING',
       
    27 				'text'              => __( 'The plugin is not working', 'bestwebsoft' ),
       
    28 				'input_type'        => 'textarea',
       
    29 				'input_placeholder' => esc_attr__( "Kindly share what didn't work so we can fix it in future updates...", 'bestwebsoft' )
       
    30 			),
       
    31 			array(
       
    32 				'id'                => 'DIDNT_WORK_AS_EXPECTED',
       
    33 				'text'              => __( "The plugin didn't work as expected", 'bestwebsoft' ),
       
    34 				'input_type'        => 'textarea',
       
    35 				'input_placeholder' => esc_attr__( 'What did you expect?', 'bestwebsoft' )
       
    36 			),
       
    37 			array(
       
    38 				'id'                => 'SUDDENLY_STOPPED_WORKING',
       
    39 				'text'              => __( 'The plugin suddenly stopped working', 'bestwebsoft' ),
       
    40 				'input_type'        => '',
       
    41 				'input_placeholder' => '',
       
    42 				'internal_message'  => $contact_support_template
       
    43 			),
       
    44 			array(
       
    45 				'id'                => 'BROKE_MY_SITE',
       
    46 				'text'              => __( 'The plugin broke my site', 'bestwebsoft' ),
       
    47 				'input_type'        => '',
       
    48 				'input_placeholder' => '',
       
    49 				'internal_message'  => $contact_support_template
       
    50 			),
       
    51 			array(
       
    52 				'id'                => 'COULDNT_MAKE_IT_WORK',
       
    53 				'text'              => __( "I couldn't understand how to get it work", 'bestwebsoft' ),
       
    54 				'input_type'        => '',
       
    55 				'input_placeholder' => '',
       
    56 				'internal_message'  => $contact_support_template
       
    57 			),
       
    58 			array(
       
    59 				'id'                => 'FOUND_A_BETTER_PLUGIN',
       
    60 				'text'              => __( 'I found a better plugin', 'bestwebsoft' ),
       
    61 				'input_type'        => 'textfield',
       
    62 				'input_placeholder' => esc_attr__( "What's the plugin name?", 'bestwebsoft' )
       
    63 			),
       
    64 			array(
       
    65 				'id'                => 'GREAT_BUT_NEED_SPECIFIC_FEATURE',
       
    66 				'text'              => __( "The plugin is great, but I need specific feature that you don't support", 'bestwebsoft' ),
       
    67 				'input_type'        => 'textarea',
       
    68 				'input_placeholder' => esc_attr__( 'What feature?', 'bestwebsoft' )
       
    69 			),
       
    70 			array(
       
    71 				'id'                => 'NO_LONGER_NEEDED',
       
    72 				'text'              => __( 'I no longer need the plugin', 'bestwebsoft' ),
       
    73 				'input_type'        => '',
       
    74 				'input_placeholder' => ''
       
    75 			),
       
    76 			array(
       
    77 				'id'                => 'TEMPORARY_DEACTIVATION',
       
    78 				'text'              => __( "It's a temporary deactivation, I'm just debugging an issue", 'bestwebsoft' ),
       
    79 				'input_type'        => '',
       
    80 				'input_placeholder' => ''
       
    81 			),
       
    82 			array(
       
    83 				'id'                => 'OTHER',
       
    84 				'text'              => __( 'Other', 'bestwebsoft' ),
       
    85 				'input_type'        => 'textfield',
       
    86 				'input_placeholder' => ''
       
    87 			)				
       
    88 		);
       
    89 
       
    90 		$modal_html = '<div class="bws-modal bws-modal-deactivation-feedback">
       
    91 	    	<div class="bws-modal-dialog">
       
    92 	    		<div class="bws-modal-body">
       
    93 	    			<h2>' . __( 'Quick Feedback', 'bestwebsoft' ) . '</h2>
       
    94 	    			<div class="bws-modal-panel active">
       
    95 	    				<p>' . __( 'If you have a moment, please let us know why you are deactivating', 'bestwebsoft' ) . ":</p><ul>";
       
    96 
       
    97 		foreach ( $reasons as $reason ) {
       
    98 			$list_item_classes = 'bws-modal-reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
       
    99 
       
   100 			if ( ! empty( $reason['internal_message'] ) ) {
       
   101 				$list_item_classes .= ' has-internal-message';
       
   102 				$reason_internal_message = $reason['internal_message'];
       
   103 			} else {
       
   104 				$reason_internal_message = '';
       
   105 			}
       
   106 
       
   107 			$modal_html .= '<li class="' . $list_item_classes . '" data-input-type="' . $reason['input_type'] . '" data-input-placeholder="' . $reason['input_placeholder'] . '">
       
   108 				<label>
       
   109 					<span>
       
   110 						<input type="radio" name="selected-reason" value="' . $reason['id'] . '"/>
       
   111 					</span>
       
   112 					<span>' . $reason['text'] . '</span>
       
   113 				</label>
       
   114 				<div class="bws-modal-internal-message">' . $reason_internal_message . '</div>
       
   115 			</li>';
       
   116 		}
       
   117 		$modal_html .= '</ul>
       
   118 		    				<label class="bws-modal-anonymous-label">
       
   119 			    				<input type="checkbox" />' .
       
   120 								__( 'Send website data and allow to contact me back', 'bestwebsoft' ) .
       
   121 							'</label>
       
   122 						</div>
       
   123 					</div>
       
   124 					<div class="bws-modal-footer">
       
   125 						<a href="#" class="button button-primary bws-modal-button-deactivate disabled">' . __( 'Submit and Deactivate', 'bestwebsoft' ) . '</a>
       
   126 						<a href="#" class="bws-modal-skip-link">' . __( 'Skip and Deactivate', 'bestwebsoft' ) . '</a>
       
   127 						<span class="bws-modal-processing hidden">' . __( 'Processing', 'bestwebsoft' ) . '...</span>
       
   128 						<div class="clear"></div>
       
   129 					</div>
       
   130 				</div>
       
   131 			</div>';
       
   132 
       
   133 		$script = '';
    21 
   134 
    22 		foreach ( $bstwbsftwppdtplgns_active_plugins as $basename => $plugin_data ) {
   135 		foreach ( $bstwbsftwppdtplgns_active_plugins as $basename => $plugin_data ) {
    23 
   136 
    24 			$slug = dirname( $basename );
   137 			$slug = dirname( $basename );
    25 			$plugin_id = sanitize_title( $plugin_data['Name'] );
   138 			$plugin_id = sanitize_title( $plugin_data['Name'] );
    26 
   139 
    27 			$contact_support_template = __( 'Need help? We are ready to answer your questions.', 'bestwebsoft' ) . ' <a href="https://support.bestwebsoft.com/hc/en-us/requests/new" target="_blank">' . __( 'Contact Support', 'bestwebsoft' ) . '</a>';
   140 			$script .= "(function($) {
    28 
   141 					var modalHtml = " . json_encode( $modal_html ) . ",
    29 			$reasons = array(
   142 					    \$modal                = $( modalHtml ),
    30 				array(
   143 					    \$deactivateLink       = $( '#the-list .active[data-plugin=\"" . $basename . "\"] .deactivate a' ),
    31 					'id'                => 'NOT_WORKING',
   144 						\$anonymousFeedback    = \$modal.find( '.bws-modal-anonymous-label' ),
    32 					'text'              => __( 'The plugin is not working', 'bestwebsoft' ),
       
    33 					'input_type'        => 'textarea',
       
    34 					'input_placeholder' => __( "Kindly share what didn't work so we can fix it in future updates...", 'bestwebsoft' )
       
    35 				),
       
    36 				array(
       
    37 					'id'                => 'DIDNT_WORK_AS_EXPECTED',
       
    38 					'text'              => __( "The plugin didn't work as expected", 'bestwebsoft' ),
       
    39 					'input_type'        => 'textarea',
       
    40 					'input_placeholder' => __( 'What did you expect?', 'bestwebsoft' )
       
    41 				),
       
    42 				array(
       
    43 					'id'                => 'SUDDENLY_STOPPED_WORKING',
       
    44 					'text'              => __( 'The plugin suddenly stopped working', 'bestwebsoft' ),
       
    45 					'input_type'        => '',
       
    46 					'input_placeholder' => '',
       
    47 					'internal_message'  => $contact_support_template
       
    48 				),
       
    49 				array(
       
    50 					'id'                => 'BROKE_MY_SITE',
       
    51 					'text'              => __( 'The plugin broke my site', 'bestwebsoft' ),
       
    52 					'input_type'        => '',
       
    53 					'input_placeholder' => '',
       
    54 					'internal_message'  => $contact_support_template
       
    55 				),
       
    56 				array(
       
    57 					'id'                => 'COULDNT_MAKE_IT_WORK',
       
    58 					'text'              => __( "I couldn't understand how to get it work", 'bestwebsoft' ),
       
    59 					'input_type'        => '',
       
    60 					'input_placeholder' => '',
       
    61 					'internal_message'  => $contact_support_template
       
    62 				),
       
    63 				array(
       
    64 					'id'                => 'FOUND_A_BETTER_PLUGIN',
       
    65 					'text'              => __( 'I found a better plugin', 'bestwebsoft' ),
       
    66 					'input_type'        => 'textfield',
       
    67 					'input_placeholder' => __( "What's the plugin name?", 'bestwebsoft' )
       
    68 				),
       
    69 				array(
       
    70 					'id'                => 'GREAT_BUT_NEED_SPECIFIC_FEATURE',
       
    71 					'text'              => __( "The plugin is great, but I need specific feature that you don't support", 'bestwebsoft' ),
       
    72 					'input_type'        => 'textarea',
       
    73 					'input_placeholder' => __( 'What feature?', 'bestwebsoft' )
       
    74 				),
       
    75 				array(
       
    76 					'id'                => 'NO_LONGER_NEEDED',
       
    77 					'text'              => __( 'I no longer need the plugin', 'bestwebsoft' ),
       
    78 					'input_type'        => '',
       
    79 					'input_placeholder' => ''
       
    80 				),
       
    81 				array(
       
    82 					'id'                => 'TEMPORARY_DEACTIVATION',
       
    83 					'text'              => __( "It's a temporary deactivation, I'm just debugging an issue", 'bestwebsoft' ),
       
    84 					'input_type'        => '',
       
    85 					'input_placeholder' => ''
       
    86 				),
       
    87 				array(
       
    88 					'id'                => 'OTHER',
       
    89 					'text'              => __( 'Other', 'bestwebsoft' ),
       
    90 					'input_type'        => 'textfield',
       
    91 					'input_placeholder' => ''
       
    92 				)				
       
    93 			);
       
    94 
       
    95 			$reasons_list_items_html = '';
       
    96 
       
    97 			foreach ( $reasons as $reason ) {
       
    98 				$list_item_classes = 'bws-modal-reason' . ( ! empty( $reason['input_type'] ) ? ' has-input' : '' );
       
    99 
       
   100 				if ( ! empty( $reason['internal_message'] ) ) {
       
   101 					$list_item_classes .= ' has-internal-message';
       
   102 					$reason_internal_message = $reason['internal_message'];
       
   103 				} else {
       
   104 					$reason_internal_message = '';
       
   105 				}
       
   106 
       
   107 				$reasons_list_items_html .= '<li class="' . $list_item_classes . '" data-input-type="' . $reason['input_type'] . '" data-input-placeholder="' . $reason['input_placeholder'] . '">
       
   108 					<label>
       
   109 						<span>
       
   110 							<input type="radio" name="selected-reason" value="' . $reason['id'] . '"/>
       
   111 						</span>
       
   112 						<span>' . $reason['text'] . '</span>
       
   113 					</label>
       
   114 					<div class="bws-modal-internal-message">' . $reason_internal_message . '</div>
       
   115 				</li>';
       
   116 			} ?>
       
   117 			<script type="text/javascript">
       
   118 				(function($) {
       
   119 					var modalHtml =
       
   120 						    '<div class="bws-modal bws-modal-deactivation-feedback">'
       
   121 						    + '	<div class="bws-modal-dialog">'
       
   122 						    + '		<div class="bws-modal-body">'
       
   123 						    + '		    <h2><?php _e( 'Quick Feedback', 'bestwebsoft' ); ?></h2>'
       
   124 						    + '			<div class="bws-modal-panel active"><p><?php _e( 'If you have a moment, please let us know why you are deactivating', 'bestwebsoft' ); ?>:</p><ul>' + <?php echo json_encode( $reasons_list_items_html ); ?> + '</ul>'
       
   125 						    + '         <label class="bws-modal-anonymous-label">'
       
   126 							+ '				<input type="checkbox" />'
       
   127 							+ '				<?php _e( 'Send website data and allow to contact me back', 'bestwebsoft' ); ?>'
       
   128 							+ '			</label>'
       
   129 						    + '			</div>'
       
   130 						    + '		</div>'
       
   131 						    + '		<div class="bws-modal-footer">'
       
   132 						    + '			<a href="#" class="button button-primary bws-modal-button-deactivate"></a>'
       
   133 						    + '			<div class="clear"></div>'
       
   134 						    + '		</div>'
       
   135 						    + '	</div>'
       
   136 						    + '</div>',
       
   137 					    $modal                = $( modalHtml ),
       
   138 					    $deactivateLink       = $( '#the-list .active[data-plugin="<?php echo $basename; ?>"] .deactivate a' ),
       
   139 						$anonymousFeedback    = $modal.find( '.bws-modal-anonymous-label' ),
       
   140 						selectedReasonID      = false;
   145 						selectedReasonID      = false;
   141 
   146 
   142 					/* WP added data-plugin attr after 4.5 version/ In prev version was id attr */
   147 					/* WP added data-plugin attr after 4.5 version/ In prev version was id attr */
   143 					if ( 0 == $deactivateLink.length )
   148 					if ( 0 == \$deactivateLink.length )
   144 						$deactivateLink = $( '#the-list .active#<?php echo $plugin_id; ?> .deactivate a' );
   149 						\$deactivateLink = $( '#the-list .active#" . $plugin_id . " .deactivate a' );
   145 
   150 
   146 					$modal.appendTo( $( 'body' ) );
   151 					\$modal.appendTo( $( 'body' ) );
   147 
   152 
   148 					BwsModalRegisterEventHandlers();
   153 					BwsModalRegisterEventHandlers();
   149 					
   154 					
   150 					function BwsModalRegisterEventHandlers() {
   155 					function BwsModalRegisterEventHandlers() {
   151 						$deactivateLink.click( function( evt ) {
   156 						\$deactivateLink.click( function( evt ) {
   152 							evt.preventDefault();
   157 							evt.preventDefault();
   153 
   158 
   154 							/* Display the dialog box.*/
   159 							/* Display the dialog box.*/
   155 							BwsModalReset();
   160 							BwsModalReset();
   156 							$modal.addClass( 'active' );
   161 							\$modal.addClass( 'active' );
   157 							$( 'body' ).addClass( 'has-bws-modal' );
   162 							$( 'body' ).addClass( 'has-bws-modal' );
   158 						});
   163 						});
   159 
   164 
   160 						$modal.on( 'input propertychange', '.bws-modal-reason-input input', function() {
   165 						\$modal.on( 'input propertychange', '.bws-modal-reason-input input', function() {
   161 							if ( ! BwsModalIsReasonSelected( 'OTHER' ) ) {
   166 							if ( ! BwsModalIsReasonSelected( 'OTHER' ) ) {
   162 								return;
   167 								return;
   163 							}
   168 							}
   164 
   169 
   165 							var reason = $( this ).val().trim();
   170 							var reason = $( this ).val().trim();
   166 
   171 
   167 							/* If reason is not empty, remove the error-message class of the message container to change the message color back to default. */
   172 							/* If reason is not empty, remove the error-message class of the message container to change the message color back to default. */
   168 							if ( reason.length > 0 ) {
   173 							if ( reason.length > 0 ) {
   169 								$modal.find( '.message' ).removeClass( 'error-message' );
   174 								\$modal.find( '.message' ).removeClass( 'error-message' );
   170 								BwsModalEnableDeactivateButton();
   175 								BwsModalEnableDeactivateButton();
   171 							}
   176 							}
   172 						});
   177 						});
   173 
   178 
   174 						$modal.on( 'blur', '.bws-modal-reason-input input', function() {
   179 						\$modal.on( 'blur', '.bws-modal-reason-input input', function() {
   175 							var $userReason = $( this );
   180 							var \$userReason = $( this );
   176 
   181 
   177 							setTimeout( function() {
   182 							setTimeout( function() {
   178 								if ( ! BwsModalIsReasonSelected( 'OTHER' ) ) {
   183 								if ( ! BwsModalIsReasonSelected( 'OTHER' ) ) {
   179 									return;
   184 									return;
   180 								}
   185 								}
   181 
       
   182 								/**
       
   183                                  *
       
   184                                  * @todo Remove after 01.01.2020
       
   185                                  * This code need to be removed after WordPress letter "[WordPress Plugin Directory] Notice: Captcha by BestWebSoft" from 04.09.2019 by kdo
       
   186                                  *
       
   187                                  */
       
   188 								/* If reason is empty, add the error-message class to the message container to change the message color to red. */
       
   189 								/*if ( 0 === $userReason.val().trim().length ) {
       
   190 									$modal.find( '.message' ).addClass( 'error-message' );
       
   191 									BwsModalDisableDeactivateButton();
       
   192 								}*/
       
   193 							}, 150 );
   186 							}, 150 );
   194 						});
   187 						});
   195 
   188 
   196 						$modal.on( 'click', '.bws-modal-footer .button', function( evt ) {
   189 						\$modal.on( 'click', '.bws-modal-footer .bws-modal-skip-link', function( evt ) {
   197 							evt.preventDefault();
   190 							evt.preventDefault();
       
   191 							
       
   192 							/* If no selected reason, just deactivate the plugin. */
       
   193 							window.location.href = \$deactivateLink.attr( 'href' );
       
   194 							return;
       
   195 						});
       
   196 
       
   197 						\$modal.on( 'click', '.bws-modal-footer .button', function( evt ) {
       
   198 							evt.preventDefault();
   198 
   199 
   199 							if ( $( this ).hasClass( 'disabled' ) ) {
   200 							if ( $( this ).hasClass( 'disabled' ) ) {
   200 								return;
   201 								return;
   201 							}
   202 							}
   202 
   203 
   203 							var _parent = $( this ).parents( '.bws-modal:first' ),
   204 							var _parent = $( this ).parents( '.bws-modal:first' ),
   204 								_this = $( this );
   205 								_this =  $( this );
   205 
   206 
   206 							if ( _this.hasClass( 'allow-deactivate' ) ) {
   207 							var \$radio = \$modal.find( 'input[type=\"radio\"]:checked' );
   207 								var $radio = $modal.find( 'input[type="radio"]:checked' );
   208 
   208 
   209 							if ( 0 === \$radio.length ) {
   209 								if ( 0 === $radio.length ) {
   210 								/* If no selected reason */
   210 									/* If no selected reason, just deactivate the plugin. */
   211 								BwsModalDisableDeactivateButton();
   211 									window.location.href = $deactivateLink.attr( 'href' );
   212 								return;
   212 									return;
   213 							}
       
   214 
       
   215 							var \$selected_reason = \$radio.parents( 'li:first' ),
       
   216 							    \$input = \$selected_reason.find( 'textarea, input[type=\"text\"]' ),
       
   217 							    userReason = ( 0 !== \$input.length ) ? \$input.val().trim() : '';
       
   218 
       
   219 							var is_anonymous = ( \$anonymousFeedback.find( 'input' ).is( ':checked' ) ) ? 0 : 1;
       
   220 
       
   221 							$.ajax({
       
   222 								url       : ajaxurl,
       
   223 								method    : 'POST',
       
   224 								data      : {
       
   225 									'action'			: 'bws_submit_uninstall_reason_action',
       
   226 									'plugin'			: '" . $basename . "',
       
   227 									'reason_id'			: \$radio.val(),
       
   228 									'reason_info'		: userReason,
       
   229 									'is_anonymous'		: is_anonymous,
       
   230 									'bws_ajax_nonce'	: '" . wp_create_nonce( 'bws_ajax_nonce' ) . "'
       
   231 								},
       
   232 								beforeSend: function() {
       
   233 									_parent.find( '.bws-modal-footer .button' ).hide();
       
   234 									_parent.find( '.bws-modal-footer .bws-modal-processing' ).show();
       
   235 								},
       
   236 								complete  : function( message ) {
       
   237 									/* Do not show the dialog box, deactivate the plugin. */
       
   238 									window.location.href = \$deactivateLink.attr( 'href' );
   213 								}
   239 								}
   214 
   240 							});
   215 								var $selected_reason = $radio.parents( 'li:first' ),
   241 						});
   216 								    $input = $selected_reason.find( 'textarea, input[type="text"]' ),
   242 
   217 								    userReason = ( 0 !== $input.length ) ? $input.val().trim() : '';
   243 						\$modal.on( 'click', 'input[type=\"radio\"]', function() {
   218 
   244 							var \$selectedReasonOption = $( this );
   219 								/**
       
   220 								 *
       
   221 								 * @todo Remove after 01.01.2020
       
   222 								 * This code need to be removed after WordPress letter "[WordPress Plugin Directory] Notice: Captcha by BestWebSoft" from 04.09.2019 by kdo
       
   223 								 *
       
   224 								 */
       
   225 								/*if ( BwsModalIsReasonSelected( 'OTHER' ) && '' === userReason ) {
       
   226 									return;
       
   227 								}*/
       
   228 
       
   229 								var is_anonymous = ( $anonymousFeedback.find( 'input' ).is( ':checked' ) ) ? 0 : 1;
       
   230 
       
   231 								$.ajax({
       
   232 									url       : ajaxurl,
       
   233 									method    : 'POST',
       
   234 									data      : {
       
   235 										'action'			: 'bws_submit_uninstall_reason_action',
       
   236 										'plugin'			: '<?php echo $basename; ?>',
       
   237 										'reason_id'			: $radio.val(),
       
   238 										'reason_info'		: userReason,
       
   239 										'is_anonymous'		: is_anonymous,
       
   240 										'bws_ajax_nonce'	: '<?php echo wp_create_nonce( 'bws_ajax_nonce' ); ?>'
       
   241 									},
       
   242 									beforeSend: function() {
       
   243 										_parent.find( '.bws-modal-footer .button' ).addClass( 'disabled' );
       
   244 										_parent.find( '.bws-modal-footer .button-secondary' ).text( '<?php _e( 'Processing', 'bestwebsoft' ); ?>' + '...' );
       
   245 									},
       
   246 									complete  : function( message ) {
       
   247 										/* Do not show the dialog box, deactivate the plugin. */
       
   248 										window.location.href = $deactivateLink.attr( 'href' );
       
   249 									}
       
   250 								});
       
   251 							} else if ( _this.hasClass( 'bws-modal-button-deactivate' ) ) {
       
   252 								/* Change the Deactivate button's text and show the reasons panel. */
       
   253 								_parent.find( '.bws-modal-button-deactivate' ).addClass( 'allow-deactivate' );
       
   254 								BwsModalShowPanel();
       
   255 							}
       
   256 						});
       
   257 
       
   258 						$modal.on( 'click', 'input[type="radio"]', function() {
       
   259 							var $selectedReasonOption = $( this );
       
   260 
   245 
   261 							/* If the selection has not changed, do not proceed. */
   246 							/* If the selection has not changed, do not proceed. */
   262 							if ( selectedReasonID === $selectedReasonOption.val() )
   247 							if ( selectedReasonID === \$selectedReasonOption.val() )
   263 								return;
   248 								return;
   264 
   249 
   265 							selectedReasonID = $selectedReasonOption.val();
   250 							selectedReasonID = \$selectedReasonOption.val();
   266 
   251 
   267 							$anonymousFeedback.show();
   252 							\$anonymousFeedback.show();
   268 
   253 
   269 							var _parent = $( this ).parents( 'li:first' );
   254 							var _parent = $( this ).parents( 'li:first' );
   270 
   255 
   271 							$modal.find( '.bws-modal-reason-input' ).remove();
   256 							\$modal.find( '.bws-modal-reason-input' ).remove();
   272 							$modal.find( '.bws-modal-internal-message' ).hide();
   257 							\$modal.find( '.bws-modal-internal-message' ).hide();
   273 							$modal.find( '.bws-modal-button-deactivate' ).text( '<?php _e( 'Submit and Deactivate', 'bestwebsoft' ); ?>' );
       
   274 
   258 
   275 							BwsModalEnableDeactivateButton();
   259 							BwsModalEnableDeactivateButton();
   276 
   260 
   277 							if ( _parent.hasClass( 'has-internal-message' ) ) {
   261 							if ( _parent.hasClass( 'has-internal-message' ) ) {
   278 								_parent.find( '.bws-modal-internal-message' ).show();
   262 								_parent.find( '.bws-modal-internal-message' ).show();
   279 							}
   263 							}
   280 
   264 
   281 							if (_parent.hasClass('has-input')) {
   265 							if (_parent.hasClass('has-input')) {
   282 								var reasonInputHtml = '<div class="bws-modal-reason-input"><span class="message"></span>' + ( ( 'textfield' === _parent.data( 'input-type' ) ) ? '<input type="text" />' : '<textarea rows="5" maxlength="200"></textarea>' ) + '</div>';
   266 								var reasonInputHtml = '<div class=\"bws-modal-reason-input\"><span class=\"message\"></span>' + ( ( 'textfield' === _parent.data( 'input-type' ) ) ? '<input type=\"text\" />' : '<textarea rows=\"5\" maxlength=\"200\"></textarea>' ) + '</div>';
   283 
   267 
   284 								_parent.append( $( reasonInputHtml ) );
   268 								_parent.append( $( reasonInputHtml ) );
   285 								_parent.find( 'input, textarea' ).attr( 'placeholder', _parent.data( 'input-placeholder' ) ).focus();
   269 								_parent.find( 'input, textarea' ).attr( 'placeholder', _parent.data( 'input-placeholder' ) ).focus();
   286 
   270 
   287 								if ( BwsModalIsReasonSelected( 'OTHER' ) ) {
   271 								if ( BwsModalIsReasonSelected( 'OTHER' ) ) {
   288 									$modal.find( '.message' ).text( '<?php _e( 'Please tell us the reason so we can improve it.', 'bestwebsoft' ); ?>' ).show();
   272 									\$modal.find( '.message' ).text( '" . __( 'Please tell us the reason so we can improve it.', 'bestwebsoft' ) . "' ).show();
   289 									/**
       
   290 									 *
       
   291 									 * @todo Remove after 01.01.2020
       
   292 									 * This code need to be removed after WordPress letter "[WordPress Plugin Directory] Notice: Captcha by BestWebSoft" from 04.09.2019 by kdo
       
   293 									 *
       
   294 									 */
       
   295 									//BwsModalDisableDeactivateButton();
       
   296 								}
   273 								}
   297 							}
   274 							}
   298 						});
   275 						});
   299 
   276 
   300 						/* If the user has clicked outside the window, cancel it. */
   277 						/* If the user has clicked outside the window, cancel it. */
   301 						$modal.on( 'click', function( evt ) {
   278 						\$modal.on( 'click', function( evt ) {
   302 							var $target = $( evt.target );
   279 							var \$target = $( evt.target );
   303 
   280 
   304 							/* If the user has clicked anywhere in the modal dialog, just return. */
   281 							/* If the user has clicked anywhere in the modal dialog, just return. */
   305 							if ( $target.hasClass( 'bws-modal-body' ) || $target.hasClass( 'bws-modal-footer' ) ) {
   282 							if ( \$target.hasClass( 'bws-modal-body' ) || \$target.hasClass( 'bws-modal-footer' ) ) {
   306 								return;
   283 								return;
   307 							}
   284 							}
   308 
   285 
   309 							/* If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. */
   286 							/* If the user has not clicked the close button and the clicked element is inside the modal dialog, just return. */
   310 							if ( ! $target.hasClass( 'bws-modal-button-close' ) && ( $target.parents( '.bws-modal-body' ).length > 0 || $target.parents( '.bws-modal-footer' ).length > 0 ) ) {
   287 							if ( ! \$target.hasClass( 'bws-modal-button-close' ) && ( \$target.parents( '.bws-modal-body' ).length > 0 || \$target.parents( '.bws-modal-footer' ).length > 0 ) ) {
   311 								return;
   288 								return;
   312 							}
   289 							}
   313 
   290 
   314 							/* Close the modal dialog */
   291 							/* Close the modal dialog */
   315 							$modal.removeClass( 'active' );
   292 							\$modal.removeClass( 'active' );
   316 							$( 'body' ).removeClass( 'has-bws-modal' );
   293 							$( 'body' ).removeClass( 'has-bws-modal' );
   317 
   294 
   318 							return false;
   295 							return false;
   319 						});
   296 						});
   320 					}
   297 					}
   321 
   298 
   322 					function BwsModalIsReasonSelected( reasonID ) {
   299 					function BwsModalIsReasonSelected( reasonID ) {
   323 						/* Get the selected radio input element.*/
   300 						/* Get the selected radio input element.*/
   324 						return ( reasonID == $modal.find('input[type="radio"]:checked').val() );
   301 						return ( reasonID == \$modal.find('input[type=\"radio\"]:checked').val() );
   325 					}
   302 					}
   326 
   303 
   327 					function BwsModalReset() {
   304 					function BwsModalReset() {
   328 						selectedReasonID = false;
   305 						selectedReasonID = false;						
   329 
       
   330 						BwsModalEnableDeactivateButton();
       
   331 
   306 
   332 						/* Uncheck all radio buttons.*/
   307 						/* Uncheck all radio buttons.*/
   333 						$modal.find( 'input[type="radio"]' ).prop( 'checked', false );
   308 						\$modal.find( 'input[type=\"radio\"]' ).prop( 'checked', false );
   334 
   309 
   335 						/* Remove all input fields ( textfield, textarea ).*/
   310 						/* Remove all input fields ( textfield, textarea ).*/
   336 						$modal.find( '.bws-modal-reason-input' ).remove();
   311 						\$modal.find( '.bws-modal-reason-input' ).remove();
   337 
   312 
   338 						$modal.find( '.message' ).hide();
   313 						\$modal.find( '.message' ).hide();
   339 
       
   340 						/**
       
   341 						 *
       
   342 						 * @todo Remove after 01.01.2020
       
   343 						 * This code need to be removed after WordPress letter "[WordPress Plugin Directory] Notice: Captcha by BestWebSoft" from 04.09.2019 by kdo
       
   344 						 *
       
   345 						 */
       
   346 						//$anonymousFeedback.find( 'input' ).prop( 'checked', true );
       
   347 
   314 
   348 						/* Hide, since by default there is no selected reason.*/
   315 						/* Hide, since by default there is no selected reason.*/
   349 						$anonymousFeedback.hide();
   316 						\$anonymousFeedback.hide();
   350 
   317 
   351 						var $deactivateButton = $modal.find( '.bws-modal-button-deactivate' );
   318 						BwsModalDisableDeactivateButton();
   352 
   319 
   353 						$deactivateButton.addClass( 'allow-deactivate' );
       
   354 						BwsModalShowPanel();
   320 						BwsModalShowPanel();
   355 					}
   321 					}
   356 
   322 
   357 					function BwsModalEnableDeactivateButton() {
   323 					function BwsModalEnableDeactivateButton() {
   358 						$modal.find( '.bws-modal-button-deactivate' ).removeClass( 'disabled' );
   324 						\$modal.find( '.bws-modal-button-deactivate' ).removeClass( 'disabled' ).show();
       
   325 						\$modal.find( '.bws-modal-processing' ).hide();
   359 					}
   326 					}
   360 
   327 
   361 					function BwsModalDisableDeactivateButton() {
   328 					function BwsModalDisableDeactivateButton() {
   362 						$modal.find( '.bws-modal-button-deactivate' ).addClass( 'disabled' );
   329 						\$modal.find( '.bws-modal-button-deactivate' ).addClass( 'disabled' );
   363 					}
   330 					}
   364 
   331 
   365 					function BwsModalShowPanel() {
   332 					function BwsModalShowPanel() {
   366 						$modal.find( '.bws-modal-panel' ).addClass( 'active' );
   333 						\$modal.find( '.bws-modal-panel' ).addClass( 'active' );
   367 						/* Update the deactivate button's text */
   334 					}
   368 						$modal.find( '.bws-modal-button-deactivate' ).text( '<?php _e( 'Skip and Deactivate', 'bestwebsoft' ); ?>' );
   335 				})(jQuery);";
   369 					}
   336 		}
   370 				})(jQuery);
   337 
   371 			</script>
   338 		/* add script in FOOTER */
   372 		<?php }
   339 		wp_register_script( 'bws-deactivation-feedback-dialog-boxes', '', array( 'jquery' ), false, true );
       
   340 		wp_enqueue_script( 'bws-deactivation-feedback-dialog-boxes' );
       
   341 		wp_add_inline_script( 'bws-deactivation-feedback-dialog-boxes', sprintf( $script ) );		
   373 	}
   342 	}
   374 }
   343 }
   375 
   344 
   376 /**
   345 /**
   377  * Called after the user has submitted his reason for deactivating the plugin.
   346  * Called after the user has submitted his reason for deactivating the plugin.
   382 	function bws_submit_uninstall_reason_action() {
   351 	function bws_submit_uninstall_reason_action() {
   383 		global $bstwbsftwppdtplgns_options, $wp_version, $bstwbsftwppdtplgns_active_plugins, $current_user;
   352 		global $bstwbsftwppdtplgns_options, $wp_version, $bstwbsftwppdtplgns_active_plugins, $current_user;
   384 
   353 
   385 		wp_verify_nonce( $_REQUEST['bws_ajax_nonce'], 'bws_ajax_nonce' );
   354 		wp_verify_nonce( $_REQUEST['bws_ajax_nonce'], 'bws_ajax_nonce' );
   386 
   355 
   387 		$reason_id = isset( $_REQUEST['reason_id'] ) ? stripcslashes( esc_html( $_REQUEST['reason_id'] ) ) : '';
   356 		$reason_id = isset( $_REQUEST['reason_id'] ) ? stripcslashes( sanitize_text_field( $_REQUEST['reason_id'] ) ) : '';
   388 		$basename = isset( $_REQUEST['plugin'] ) ? stripcslashes( esc_html( $_REQUEST['plugin'] ) ) : '';
   357 		$basename = isset( $_REQUEST['plugin'] ) ? stripcslashes( sanitize_text_field( $_REQUEST['plugin'] ) ) : '';
   389 
   358 
   390 		if ( empty( $reason_id ) || empty( $basename ) ) {
   359 		if ( empty( $reason_id ) || empty( $basename ) ) {
   391 			exit;
   360 			exit;
   392 		}
   361 		}
   393 
   362 
   394 		$reason_info = isset( $_REQUEST['reason_info'] ) ? stripcslashes( esc_html( $_REQUEST['reason_info'] ) ) : '';
   363 		$reason_info = isset( $_REQUEST['reason_info'] ) ? stripcslashes( sanitize_text_field( $_REQUEST['reason_info'] ) ) : '';
   395 		if ( ! empty( $reason_info ) ) {
   364 		if ( ! empty( $reason_info ) ) {
   396 			$reason_info = substr( $reason_info, 0, 255 );
   365 			$reason_info = substr( $reason_info, 0, 255 );
   397 		}
   366 		}
   398 		$is_anonymous = isset( $_REQUEST['is_anonymous'] ) && 1 == $_REQUEST['is_anonymous'];
   367 		$is_anonymous = isset( $_REQUEST['is_anonymous'] ) && 1 == $_REQUEST['is_anonymous'];
   399 
   368 
   419 
   388 
   420 			$options['email'] = $current_user->data->user_email;
   389 			$options['email'] = $current_user->data->user_email;
   421 		}
   390 		}
   422 
   391 
   423 		/* send data */
   392 		/* send data */
   424 		$raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/products-statistics/deactivation-feedback/', array(
   393 		$raw_response = wp_remote_post( 'https://bestwebsoft.com/wp-content/plugins/products-statistics/deactivation-feedback/', array(
   425 			'method'  => 'POST',
   394 			'method'  => 'POST',
   426 			'body'    => $options,
   395 			'body'    => $options,
   427 			'timeout' => 15,
   396 			'timeout' => 15,
   428 		) );
   397 		) );
   429 
   398