@@ -103,25 +103,24 @@ public function handler() {
103103 }
104104
105105 if ( $ processed ) {
106-
107106 if ( is_wp_error ( $ errors ) ) {
108- echo aui ()->alert (
109- array ( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
110- 'type ' => 'error ' ,
111- ' class ' => ' text-center ' ,
112- ' content ' => wp_kses_post ( $ errors -> get_error_message () ),
113- )
114- );
115- } elseif ( $ redirect ) {
107+ aui ()->alert (
108+ array (
109+ 'type ' => 'error ' ,
110+ ' content ' => wp_kses_post ( $ errors -> get_error_message () )
111+ ),
112+ true
113+ );
114+ } else if ( $ redirect ) {
116115 wp_safe_redirect ( $ redirect );
117116 exit ();
118- } else {
119- echo aui ()->alert (
120- array ( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
121- 'type ' => 'success ' ,
122- ' class ' => ' text-center ' ,
123- ' content ' => wp_kses_post ( $ message ),
124- )
117+ } else {
118+ aui ()->alert (
119+ array (
120+ 'type ' => 'success ' ,
121+ ' content ' => wp_kses_post ( $ message )
122+ ),
123+ true
125124 );
126125 }
127126 }
@@ -197,6 +196,7 @@ public function process_upload_submit( $data = array(), $files = array(), $type
197196 */
198197 public function process_image_crop ( $ data = array (), $ type = 'avatar ' , $ unlink_prev_img = false ) {
199198 global $ wpdb ;
199+
200200 if ( ! is_user_logged_in () ) {
201201 return false ;
202202 }
@@ -205,6 +205,27 @@ public function process_image_crop( $data = array(), $type = 'avatar', $unlink_p
205205 return ;
206206 }
207207
208+ $ image_url = ! empty ( $ data ['uwp_crop ' ] ) ? esc_url ( $ data ['uwp_crop ' ] ) : '' ;
209+
210+ if ( empty ( $ image_url ) ) {
211+ return new WP_Error ( 'empty_image ' , __ ( 'Upload valid image. ' , 'userswp ' ) );
212+ }
213+
214+ // Ensure we have a valid URL with an allowed meme type.
215+ $ image_url = $ this ->normalize_url ( $ image_url );
216+
217+ $ content_url = str_replace ( array ( 'https:// ' , 'http:// ' ) , '' , untrailingslashit ( WP_CONTENT_URL ) );
218+ $ _image_url = str_replace ( array ( 'https:// ' , 'http:// ' ), '' , $ image_url );
219+ if ( strpos ( $ _image_url , $ content_url ) !== 0 ) {
220+ return new WP_Error ( 'invalid_image ' , __ ( 'Invalid image url. ' , 'userswp ' ) );
221+ }
222+
223+ $ filetype = wp_check_filetype ( $ image_url );
224+
225+ if ( empty ( $ filetype ['ext ' ] ) ) {
226+ return new WP_Error ( 'invalid_image ' , __ ( 'Invalid image type. ' , 'userswp ' ) );
227+ }
228+
208229 // If is current user's profile (profile.php)
209230 if ( is_admin () && defined ( 'IS_PROFILE_PAGE ' ) && IS_PROFILE_PAGE ) {
210231 $ user_id = get_current_user_id ();
@@ -216,19 +237,6 @@ public function process_image_crop( $data = array(), $type = 'avatar', $unlink_p
216237 $ user_id = get_current_user_id ();
217238 }
218239
219- // Ensure we have a valid URL with an allowed meme type.
220- $ image_url = $ this ->normalize_url ( esc_url ( $ data ['uwp_crop ' ] ) );
221- $ filetype = wp_check_filetype ( $ image_url );
222-
223- $ errors = new WP_Error ();
224- if ( empty ( $ image_url ) || empty ( $ filetype ['ext ' ] ) ) {
225- $ errors ->add ( 'something_wrong ' , __ ( 'Something went wrong. Please contact site admin. ' , 'userswp ' ) );
226- }
227-
228- if ( $ errors ->has_errors () ) {
229- return $ errors ;
230- }
231-
232240 // Retrieve current thumbnail.
233241 $ current_field = 'avatar ' === $ type ? 'avatar_thumb ' : 'banner_thumb ' ;
234242 $ current_thumbnail = $ this ->normalize_url ( uwp_get_usermeta ( $ user_id , $ current_field , '' ) );
@@ -253,11 +261,12 @@ public function process_image_crop( $data = array(), $type = 'avatar', $unlink_p
253261 $ name = sanitize_file_name ( pathinfo ( $ image_path , PATHINFO_FILENAME ) ); //file name without extension
254262 $ thumb_image_name = $ name . $ thumb_postfix . '. ' . $ ext ;
255263 $ thumb_image_location = str_replace ( $ name . '. ' . $ ext , $ thumb_image_name , $ image_path );
264+
256265 //Get the new coordinates to crop the image.
257- $ x = $ data ['x ' ];
258- $ y = $ data ['y ' ];
259- $ w = $ data ['w ' ];
260- $ h = $ data ['h ' ];
266+ $ x = $ data ['uwpx ' ];
267+ $ y = $ data ['uwpy ' ];
268+ $ w = $ data ['uwpw ' ];
269+ $ h = $ data ['uwph ' ];
261270 //Scale the image based on cropped width setting
262271 $ scale = $ full_width / $ w ;
263272 //$scale = 1; // no scaling
0 commit comments