| @@ -1,307 +1,307 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Class ProfileTemplate. | |
| 4 | - * | |
| 5 | - * @since 4.2.7.2 | |
| 6 | - * @version 1.0.0 | |
| 7 | - */ | |
| 8 | - | |
| 9 | -namespace LearnPress\TemplateHooks\Profile; | |
| 10 | - | |
| 11 | -use LearnPress\Helpers\Singleton; | |
| 12 | -use LearnPress\Helpers\Template; | |
| 13 | -use LearnPress\Models\UserModel; | |
| 14 | -use LP_Profile; | |
| 15 | -use LP_Settings; | |
| 16 | -use Throwable; | |
| 17 | - | |
| 18 | -class ProfileTemplate { | |
| 19 | - use Singleton; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * ProfileTemplate constructor. | |
| 23 | - * @since 4.2.7.2 | |
| 24 | - * @version 1.0.0 | |
| 25 | - */ | |
| 26 | - public function init() { | |
| 27 | - } | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * HTML cover image. | |
| 31 | - * | |
| 32 | - * @param UserModel $user | |
| 33 | - * | |
| 34 | - * @return string | |
| 35 | - * @return string | |
| 36 | - * @since 4.2.7.2 | |
| 37 | - * @version 1.0.1 | |
| 38 | - */ | |
| 39 | - public function html_cover_image( UserModel $user ): string { | |
| 40 | - $html = ''; | |
| 41 | - | |
| 42 | - try { | |
| 43 | - $cover_image_url = $user->get_cover_image_url(); | |
| 44 | - $profile = LP_Profile::instance( $user->get_id() ); | |
| 45 | - $current_section = $profile->get_current_section(); | |
| 46 | - $html_btn_to_edit_cover_image = ''; | |
| 47 | - $cover_image_dimensions = LP_Settings::get_option( | |
| 48 | - 'cover_image_dimensions', | |
| 49 | - array( | |
| 50 | - 'width' => 1290, | |
| 51 | - 'height' => 250, | |
| 52 | - ) | |
| 53 | - ); | |
| 54 | - | |
| 55 | - if ( $user->get_id() === get_current_user_id() ) { | |
| 56 | - $html_btn_to_edit_cover_image = sprintf( | |
| 57 | - '<a class="lp-btn-to-edit-cover-image" href="%s" data-section-correct="%d">+ %s</a>', | |
| 58 | - $profile->get_tab_link( 'settings', 'cover-image' ), | |
| 59 | - $current_section === 'cover-image' ? 1 : 0, | |
| 60 | - __( 'edit cover image', 'learnpress' ) | |
| 61 | - ); | |
| 62 | - } | |
| 63 | - | |
| 64 | - $section = apply_filters( | |
| 65 | - 'learn-press/profile/html-cover-image', | |
| 66 | - [ | |
| 67 | - 'wrapper' => sprintf( | |
| 68 | - '<div class="lp-user-cover-image_background %s" style="%s">', | |
| 69 | - empty( $cover_image_url ) ? 'lp-hidden' : '', | |
| 70 | - sprintf( 'background-image: url(%s);', $cover_image_url ) | |
| 71 | - ), | |
| 72 | - 'image' => sprintf( | |
| 73 | - '<img src="%s" alt="%s" decoding="async" />', | |
| 74 | - $cover_image_url, | |
| 75 | - __( 'Cover image', 'learnpress' ) | |
| 76 | - ), | |
| 77 | - 'btn-edit' => $html_btn_to_edit_cover_image, | |
| 78 | - 'wrapper_end' => '</div>', | |
| 79 | - ], | |
| 80 | - $user | |
| 81 | - ); | |
| 82 | - | |
| 83 | - $html = Template::combine_components( $section ); | |
| 84 | - } catch ( Throwable $e ) { | |
| 85 | - error_log( __METHOD__ . ': ' . $e->getMessage() ); | |
| 86 | - } | |
| 87 | - | |
| 88 | - return $html; | |
| 89 | - } | |
| 90 | - | |
| 91 | - /** | |
| 92 | - * HTML upload edit cover image. | |
| 93 | - * | |
| 94 | - * @param UserModel $user | |
| 95 | - * | |
| 96 | - * @return string | |
| 97 | - * @since 4.2.8.2 | |
| 98 | - * @version 1.0.0 | |
| 99 | - */ | |
| 100 | - public function html_upload_cover_image( UserModel $user ): string { | |
| 101 | - $html = ''; | |
| 102 | - | |
| 103 | - try { | |
| 104 | - $cover_image_url = $user->get_cover_image_url(); | |
| 105 | - $cover_image_dimensions = LP_Settings::get_option( | |
| 106 | - 'cover_image_dimensions', | |
| 107 | - array( | |
| 108 | - 'width' => 1290, | |
| 109 | - 'height' => 250, | |
| 110 | - ) | |
| 111 | - ); | |
| 112 | - | |
| 113 | - $class_hide = 'lp-hidden'; | |
| 114 | - | |
| 115 | - $section_img_empty_info = [ | |
| 116 | - 'wrapper' => '<div class="lp-cover-image-empty__info">', | |
| 117 | - 'top' => sprintf( | |
| 118 | - '<div class="lp-cover-image-empty__info__top">%s%s</div>', | |
| 119 | - '<span class="lp-icon-file-image"></span>', | |
| 120 | - __( 'Drag and drop or click here to choose image', 'learnpress' ) | |
| 121 | - ), | |
| 122 | - 'bottom' => sprintf( | |
| 123 | - '<div class="lp-cover-image-empty__info__bottom">%s</div>', | |
| 124 | - sprintf( | |
| 125 | - __( 'Accepted file types: JPG, PNG %1$d x %2$d (px)', 'learnpress' ), | |
| 126 | - $cover_image_dimensions['width'], | |
| 127 | - $cover_image_dimensions['height'] | |
| 128 | - ) | |
| 129 | - ), | |
| 130 | - 'wrapper_end' => '</div>', | |
| 131 | - ]; | |
| 132 | - $html_img_empty = apply_filters( | |
| 133 | - 'learn-press/profile/html-cover-image-empty', | |
| 134 | - [ | |
| 135 | - 'wrapper' => sprintf( | |
| 136 | - '<div class="lp-cover-image-empty %s">', | |
| 137 | - empty( $cover_image_url ) ? '' : $class_hide | |
| 138 | - ), | |
| 139 | - 'info' => Template::combine_components( $section_img_empty_info ), | |
| 140 | - 'input_file' => sprintf( | |
| 141 | - '<input type="file" class="%s" name="lp-cover-image-file" accept="%s" />', | |
| 142 | - 'lp-cover-image-file', | |
| 143 | - 'image/png, image/jpeg, image/webp' | |
| 144 | - ), | |
| 145 | - 'wrapper_end' => '</div>', | |
| 146 | - ], | |
| 147 | - $user | |
| 148 | - ); | |
| 149 | - | |
| 150 | - $html_img_preview = sprintf( | |
| 151 | - '<img class="lp-cover-image-preview %s" src="%s" alt="%s" decoding="async" />', | |
| 152 | - empty( $cover_image_url ) ? $class_hide : '', | |
| 153 | - $cover_image_url, | |
| 154 | - __( 'Cover image', 'learnpress' ) | |
| 155 | - ); | |
| 156 | - | |
| 157 | - $section_img = [ | |
| 158 | - 'wrapper' => '<div class="lp-user-cover-image__display">', | |
| 159 | - 'image_empty' => Template::combine_components( $html_img_empty ), | |
| 160 | - 'image_preview' => $html_img_preview, | |
| 161 | - 'wrapper_end' => '</div>', | |
| 162 | - ]; | |
| 163 | - | |
| 164 | - $section_btn = [ | |
| 165 | - 'wrapper' => '<div class="lp-user-cover-image__buttons">', | |
| 166 | - 'input_action' => '<input type="hidden" name="action" value="upload" />', | |
| 167 | - 'choose_file' => sprintf( | |
| 168 | - '<button class="lp-button lp-btn-choose-cover-image %s">%s</button>', | |
| 169 | - empty( $cover_image_url ) ? $class_hide : '', | |
| 170 | - __( 'Replace', 'learnpress' ) | |
| 171 | - ), | |
| 172 | - 'save_btn' => sprintf( | |
| 173 | - '<button class="lp-button lp-btn-save-cover-image %s">%s</button>', | |
| 174 | - $class_hide, | |
| 175 | - __( 'Save', 'learnpress' ) | |
| 176 | - ), | |
| 177 | - 'cancel' => sprintf( | |
| 178 | - '<button class="lp-button lp-btn-cancel-cover-image %s">%s</button>', | |
| 179 | - $class_hide, | |
| 180 | - __( 'Cancel', 'learnpress' ) | |
| 181 | - ), | |
| 182 | - 'remove' => sprintf( | |
| 183 | - '<button class="lp-button lp-btn-remove-cover-image %s">%s</button>', | |
| 184 | - empty( $cover_image_url ) ? $class_hide : '', | |
| 185 | - __( 'Remove', 'learnpress' ) | |
| 186 | - ), | |
| 187 | - 'wrapper_end' => '</div>', | |
| 188 | - ]; | |
| 189 | - | |
| 190 | - $section = apply_filters( | |
| 191 | - 'learn-press/profile/html-upload-cover-image', | |
| 192 | - [ | |
| 193 | - 'wrapper' => '<form class="lp-user-cover-image" enctype="multipart/form-data" method="post">', | |
| 194 | - 'image' => Template::combine_components( $section_img ), | |
| 195 | - 'buttons' => Template::combine_components( $section_btn ), | |
| 196 | - 'wrapper_end' => '</form>', | |
| 197 | - ], | |
| 198 | - $user | |
| 199 | - ); | |
| 200 | - | |
| 201 | - $html = Template::combine_components( $section ); | |
| 202 | - } catch ( Throwable $e ) { | |
| 203 | - error_log( __METHOD__ . ': ' . $e->getMessage() ); | |
| 204 | - return ''; | |
| 205 | - } | |
| 206 | - | |
| 207 | - return $html; | |
| 208 | - } | |
| 209 | - | |
| 210 | - /** | |
| 211 | - * HTML upload avatar image. | |
| 212 | - * | |
| 213 | - * @param UserModel $user | |
| 214 | - * | |
| 215 | - * @return string | |
| 216 | - * @since 4.2.8.2 | |
| 217 | - * @version 1.0.0 | |
| 218 | - */ | |
| 219 | - public function html_upload_avatar( UserModel $user ): string { | |
| 220 | - $html = ''; | |
| 221 | - | |
| 222 | - try { | |
| 223 | - $class_hide = 'lp-hidden'; | |
| 224 | - $avatar_image_url = $user->get_upload_avatar_src(); | |
| 225 | - | |
| 226 | - $html_img_preview = sprintf( | |
| 227 | - '<img class="lp-avatar-image %s" src="%s" alt="%s" decoding="async" />', | |
| 228 | - empty( $avatar_image_url ) ? $class_hide : '', | |
| 229 | - $avatar_image_url, | |
| 230 | - __( 'Avatar image', 'learnpress' ) | |
| 231 | - ); | |
| 232 | - $html_img_empty = [ | |
| 233 | - 'start' => sprintf( | |
| 234 | - '<form class="lp_avatar__form %s">', | |
| 235 | - empty( $avatar_image_url ) ? '' : $class_hide | |
| 236 | - ), | |
| 237 | - 'label' => '<label for="avatar-file">', | |
| 238 | - 'div' => '<div class="learnpress_avatar__form__upload">', | |
| 239 | - 'upload' => sprintf( | |
| 240 | - '<span>%s</span>', | |
| 241 | - __( 'Upload Avatar', 'learnpress' ) | |
| 242 | - ), | |
| 243 | - 'input' => sprintf( | |
| 244 | - '<input type="file" id="avatar-file" class="%s" name="lp-avatar-file" accept="%s" />', | |
| 245 | - 'lp-avatar-file lp-hidden', | |
| 246 | - 'image/png, image/jpeg, image/webp' | |
| 247 | - ), | |
| 248 | - 'div_end' => '</div>', | |
| 249 | - 'label_end' => '</label>', | |
| 250 | - 'end' => '</form>', | |
| 251 | - ]; | |
| 252 | - | |
| 253 | - $section_img = [ | |
| 254 | - 'wrapper' => '<div class="lp-user-avatar-image__display" style="width: 250px;height:250px">', | |
| 255 | - 'image_empty' => Template::combine_components( $html_img_empty ), | |
| 256 | - 'image_preview' => $html_img_preview, | |
| 257 | - 'wrapper_end' => '</div>', | |
| 258 | - ]; | |
| 259 | - | |
| 260 | - $section_btn = [ | |
| 261 | - 'wrapper' => '<div class="lp-user-avatar__buttons">', | |
| 262 | - 'input_action' => '<input type="hidden" name="action" value="upload" />', | |
| 263 | - 'choose_file' => sprintf( | |
| 264 | - '<button class="lp-button lp-btn-choose-avatar %s">%s</button>', | |
| 265 | - empty( $avatar_image_url ) ? $class_hide : '', | |
| 266 | - __( 'Replace', 'learnpress' ) | |
| 267 | - ), | |
| 268 | - 'save_btn' => sprintf( | |
| 269 | - '<button class="lp-button lp-btn-save-avatar %s">%s</button>', | |
| 270 | - $class_hide, | |
| 271 | - __( 'Save', 'learnpress' ) | |
| 272 | - ), | |
| 273 | - 'cancel' => sprintf( | |
| 274 | - '<button class="lp-button lp-btn-cancel-avatar %s">%s</button>', | |
| 275 | - $class_hide, | |
| 276 | - __( 'Cancel', 'learnpress' ) | |
| 277 | - ), | |
| 278 | - 'remove' => sprintf( | |
| 279 | - '<button class="lp-button lp-btn-remove-avatar %s">%s</button>', | |
| 280 | - empty( $avatar_image_url ) ? $class_hide : '', | |
| 281 | - __( 'Remove', 'learnpress' ) | |
| 282 | - ), | |
| 283 | - 'wrapper_end' => '</div>', | |
| 284 | - ]; | |
| 285 | - | |
| 286 | - $section = apply_filters( | |
| 287 | - 'learn-press/profile/html-upload-avatar', | |
| 288 | - [ | |
| 289 | - 'wrapper' => '<div id="learnpress-avatar-upload">', | |
| 290 | - 'image' => Template::combine_components( $section_img ), | |
| 291 | - 'buttons' => Template::combine_components( $section_btn ), | |
| 292 | - 'wrapper_end' => '</div>', | |
| 293 | - ], | |
| 294 | - $user | |
| 295 | - ); | |
| 296 | - | |
| 297 | - $html = Template::combine_components( $section ); | |
| 298 | - } catch ( Throwable $e ) { | |
| 299 | - $html .= Template::print_message( | |
| 300 | - $e->getMessage(), | |
| 301 | - 'error', | |
| 302 | - false | |
| 303 | - ); | |
| 304 | - } | |
| 305 | - return $html; | |
| 306 | - } | |
| 307 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Class ProfileTemplate. | |
| 4 | + * | |
| 5 | + * @since 4.2.7.2 | |
| 6 | + * @version 1.0.0 | |
| 7 | + */ | |
| 8 | + | |
| 9 | +namespace LearnPress\TemplateHooks\Profile; | |
| 10 | + | |
| 11 | +use LearnPress\Helpers\Singleton; | |
| 12 | +use LearnPress\Helpers\Template; | |
| 13 | +use LearnPress\Models\UserModel; | |
| 14 | +use LP_Profile; | |
| 15 | +use LP_Settings; | |
| 16 | +use Throwable; | |
| 17 | + | |
| 18 | +class ProfileTemplate { | |
| 19 | + use Singleton; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * ProfileTemplate constructor. | |
| 23 | + * @since 4.2.7.2 | |
| 24 | + * @version 1.0.0 | |
| 25 | + */ | |
| 26 | + public function init() { | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * HTML cover image. | |
| 31 | + * | |
| 32 | + * @param UserModel $user | |
| 33 | + * | |
| 34 | + * @return string | |
| 35 | + * @return string | |
| 36 | + * @since 4.2.7.2 | |
| 37 | + * @version 1.0.1 | |
| 38 | + */ | |
| 39 | + public function html_cover_image( UserModel $user ): string { | |
| 40 | + $html = ''; | |
| 41 | + | |
| 42 | + try { | |
| 43 | + $cover_image_url = $user->get_cover_image_url(); | |
| 44 | + $profile = LP_Profile::instance( $user->get_id() ); | |
| 45 | + $current_section = $profile->get_current_section(); | |
| 46 | + $html_btn_to_edit_cover_image = ''; | |
| 47 | + $cover_image_dimensions = LP_Settings::get_option( | |
| 48 | + 'cover_image_dimensions', | |
| 49 | + array( | |
| 50 | + 'width' => 1290, | |
| 51 | + 'height' => 250, | |
| 52 | + ) | |
| 53 | + ); | |
| 54 | + | |
| 55 | + if ( $user->get_id() === get_current_user_id() ) { | |
| 56 | + $html_btn_to_edit_cover_image = sprintf( | |
| 57 | + '<a class="lp-btn-to-edit-cover-image" href="%s" data-section-correct="%d">+ %s</a>', | |
| 58 | + $profile->get_tab_link( 'settings', 'cover-image' ), | |
| 59 | + $current_section === 'cover-image' ? 1 : 0, | |
| 60 | + __( 'edit cover image', 'learnpress' ) | |
| 61 | + ); | |
| 62 | + } | |
| 63 | + | |
| 64 | + $section = apply_filters( | |
| 65 | + 'learn-press/profile/html-cover-image', | |
| 66 | + [ | |
| 67 | + 'wrapper' => sprintf( | |
| 68 | + '<div class="lp-user-cover-image_background %s" style="%s">', | |
| 69 | + empty( $cover_image_url ) ? 'lp-hidden' : '', | |
| 70 | + sprintf( 'background-image: url(%s);', $cover_image_url ) | |
| 71 | + ), | |
| 72 | + 'image' => sprintf( | |
| 73 | + '<img src="%s" alt="%s" decoding="async" />', | |
| 74 | + $cover_image_url, | |
| 75 | + __( 'Cover image', 'learnpress' ) | |
| 76 | + ), | |
| 77 | + 'btn-edit' => $html_btn_to_edit_cover_image, | |
| 78 | + 'wrapper_end' => '</div>', | |
| 79 | + ], | |
| 80 | + $user | |
| 81 | + ); | |
| 82 | + | |
| 83 | + $html = Template::combine_components( $section ); | |
| 84 | + } catch ( Throwable $e ) { | |
| 85 | + error_log( __METHOD__ . ': ' . $e->getMessage() ); | |
| 86 | + } | |
| 87 | + | |
| 88 | + return $html; | |
| 89 | + } | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * HTML upload edit cover image. | |
| 93 | + * | |
| 94 | + * @param UserModel $user | |
| 95 | + * | |
| 96 | + * @return string | |
| 97 | + * @since 4.2.8.2 | |
| 98 | + * @version 1.0.0 | |
| 99 | + */ | |
| 100 | + public function html_upload_cover_image( UserModel $user ): string { | |
| 101 | + $html = ''; | |
| 102 | + | |
| 103 | + try { | |
| 104 | + $cover_image_url = $user->get_cover_image_url(); | |
| 105 | + $cover_image_dimensions = LP_Settings::get_option( | |
| 106 | + 'cover_image_dimensions', | |
| 107 | + array( | |
| 108 | + 'width' => 1290, | |
| 109 | + 'height' => 250, | |
| 110 | + ) | |
| 111 | + ); | |
| 112 | + | |
| 113 | + $class_hide = 'lp-hidden'; | |
| 114 | + | |
| 115 | + $section_img_empty_info = [ | |
| 116 | + 'wrapper' => '<div class="lp-cover-image-empty__info">', | |
| 117 | + 'top' => sprintf( | |
| 118 | + '<div class="lp-cover-image-empty__info__top">%s%s</div>', | |
| 119 | + '<span class="lp-icon-file-image"></span>', | |
| 120 | + __( 'Drag and drop or click here to choose image', 'learnpress' ) | |
| 121 | + ), | |
| 122 | + 'bottom' => sprintf( | |
| 123 | + '<div class="lp-cover-image-empty__info__bottom">%s</div>', | |
| 124 | + sprintf( | |
| 125 | + __( 'Accepted file types: JPG, PNG %1$d x %2$d (px)', 'learnpress' ), | |
| 126 | + $cover_image_dimensions['width'], | |
| 127 | + $cover_image_dimensions['height'] | |
| 128 | + ) | |
| 129 | + ), | |
| 130 | + 'wrapper_end' => '</div>', | |
| 131 | + ]; | |
| 132 | + $html_img_empty = apply_filters( | |
| 133 | + 'learn-press/profile/html-cover-image-empty', | |
| 134 | + [ | |
| 135 | + 'wrapper' => sprintf( | |
| 136 | + '<div class="lp-cover-image-empty %s">', | |
| 137 | + empty( $cover_image_url ) ? '' : $class_hide | |
| 138 | + ), | |
| 139 | + 'info' => Template::combine_components( $section_img_empty_info ), | |
| 140 | + 'input_file' => sprintf( | |
| 141 | + '<input type="file" class="%s" name="lp-cover-image-file" accept="%s" />', | |
| 142 | + 'lp-cover-image-file', | |
| 143 | + 'image/png, image/jpeg, image/webp' | |
| 144 | + ), | |
| 145 | + 'wrapper_end' => '</div>', | |
| 146 | + ], | |
| 147 | + $user | |
| 148 | + ); | |
| 149 | + | |
| 150 | + $html_img_preview = sprintf( | |
| 151 | + '<img class="lp-cover-image-preview %s" src="%s" alt="%s" decoding="async" />', | |
| 152 | + empty( $cover_image_url ) ? $class_hide : '', | |
| 153 | + $cover_image_url, | |
| 154 | + __( 'Cover image', 'learnpress' ) | |
| 155 | + ); | |
| 156 | + | |
| 157 | + $section_img = [ | |
| 158 | + 'wrapper' => '<div class="lp-user-cover-image__display">', | |
| 159 | + 'image_empty' => Template::combine_components( $html_img_empty ), | |
| 160 | + 'image_preview' => $html_img_preview, | |
| 161 | + 'wrapper_end' => '</div>', | |
| 162 | + ]; | |
| 163 | + | |
| 164 | + $section_btn = [ | |
| 165 | + 'wrapper' => '<div class="lp-user-cover-image__buttons">', | |
| 166 | + 'input_action' => '<input type="hidden" name="action" value="upload" />', | |
| 167 | + 'choose_file' => sprintf( | |
| 168 | + '<button class="lp-button lp-btn-choose-cover-image %s">%s</button>', | |
| 169 | + empty( $cover_image_url ) ? $class_hide : '', | |
| 170 | + __( 'Replace', 'learnpress' ) | |
| 171 | + ), | |
| 172 | + 'save_btn' => sprintf( | |
| 173 | + '<button class="lp-button lp-btn-save-cover-image %s">%s</button>', | |
| 174 | + $class_hide, | |
| 175 | + __( 'Save', 'learnpress' ) | |
| 176 | + ), | |
| 177 | + 'cancel' => sprintf( | |
| 178 | + '<button class="lp-button lp-btn-cancel-cover-image %s">%s</button>', | |
| 179 | + $class_hide, | |
| 180 | + __( 'Cancel', 'learnpress' ) | |
| 181 | + ), | |
| 182 | + 'remove' => sprintf( | |
| 183 | + '<button class="lp-button lp-btn-remove-cover-image %s">%s</button>', | |
| 184 | + empty( $cover_image_url ) ? $class_hide : '', | |
| 185 | + __( 'Remove', 'learnpress' ) | |
| 186 | + ), | |
| 187 | + 'wrapper_end' => '</div>', | |
| 188 | + ]; | |
| 189 | + | |
| 190 | + $section = apply_filters( | |
| 191 | + 'learn-press/profile/html-upload-cover-image', | |
| 192 | + [ | |
| 193 | + 'wrapper' => '<form class="lp-user-cover-image" enctype="multipart/form-data" method="post">', | |
| 194 | + 'image' => Template::combine_components( $section_img ), | |
| 195 | + 'buttons' => Template::combine_components( $section_btn ), | |
| 196 | + 'wrapper_end' => '</form>', | |
| 197 | + ], | |
| 198 | + $user | |
| 199 | + ); | |
| 200 | + | |
| 201 | + $html = Template::combine_components( $section ); | |
| 202 | + } catch ( Throwable $e ) { | |
| 203 | + error_log( __METHOD__ . ': ' . $e->getMessage() ); | |
| 204 | + return ''; | |
| 205 | + } | |
| 206 | + | |
| 207 | + return $html; | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** | |
| 211 | + * HTML upload avatar image. | |
| 212 | + * | |
| 213 | + * @param UserModel $user | |
| 214 | + * | |
| 215 | + * @return string | |
| 216 | + * @since 4.2.8.2 | |
| 217 | + * @version 1.0.0 | |
| 218 | + */ | |
| 219 | + public function html_upload_avatar( UserModel $user ): string { | |
| 220 | + $html = ''; | |
| 221 | + | |
| 222 | + try { | |
| 223 | + $class_hide = 'lp-hidden'; | |
| 224 | + $avatar_image_url = $user->get_upload_avatar_src(); | |
| 225 | + | |
| 226 | + $html_img_preview = sprintf( | |
| 227 | + '<img class="lp-avatar-image %s" src="%s" alt="%s" decoding="async" />', | |
| 228 | + empty( $avatar_image_url ) ? $class_hide : '', | |
| 229 | + $avatar_image_url, | |
| 230 | + __( 'Avatar image', 'learnpress' ) | |
| 231 | + ); | |
| 232 | + $html_img_empty = [ | |
| 233 | + 'start' => sprintf( | |
| 234 | + '<form class="lp_avatar__form %s">', | |
| 235 | + empty( $avatar_image_url ) ? '' : $class_hide | |
| 236 | + ), | |
| 237 | + 'label' => '<label for="avatar-file">', | |
| 238 | + 'div' => '<div class="learnpress_avatar__form__upload">', | |
| 239 | + 'upload' => sprintf( | |
| 240 | + '<span>%s</span>', | |
| 241 | + __( 'Upload Avatar', 'learnpress' ) | |
| 242 | + ), | |
| 243 | + 'input' => sprintf( | |
| 244 | + '<input type="file" id="avatar-file" class="%s" name="lp-avatar-file" accept="%s" />', | |
| 245 | + 'lp-avatar-file lp-hidden', | |
| 246 | + 'image/png, image/jpeg, image/webp' | |
| 247 | + ), | |
| 248 | + 'div_end' => '</div>', | |
| 249 | + 'label_end' => '</label>', | |
| 250 | + 'end' => '</form>', | |
| 251 | + ]; | |
| 252 | + | |
| 253 | + $section_img = [ | |
| 254 | + 'wrapper' => '<div class="lp-user-avatar-image__display" style="width: 250px;height:250px">', | |
| 255 | + 'image_empty' => Template::combine_components( $html_img_empty ), | |
| 256 | + 'image_preview' => $html_img_preview, | |
| 257 | + 'wrapper_end' => '</div>', | |
| 258 | + ]; | |
| 259 | + | |
| 260 | + $section_btn = [ | |
| 261 | + 'wrapper' => '<div class="lp-user-avatar__buttons">', | |
| 262 | + 'input_action' => '<input type="hidden" name="action" value="upload" />', | |
| 263 | + 'choose_file' => sprintf( | |
| 264 | + '<button class="lp-button lp-btn-choose-avatar %s">%s</button>', | |
| 265 | + empty( $avatar_image_url ) ? $class_hide : '', | |
| 266 | + __( 'Replace', 'learnpress' ) | |
| 267 | + ), | |
| 268 | + 'save_btn' => sprintf( | |
| 269 | + '<button class="lp-button lp-btn-save-avatar %s">%s</button>', | |
| 270 | + $class_hide, | |
| 271 | + __( 'Save', 'learnpress' ) | |
| 272 | + ), | |
| 273 | + 'cancel' => sprintf( | |
| 274 | + '<button class="lp-button lp-btn-cancel-avatar %s">%s</button>', | |
| 275 | + $class_hide, | |
| 276 | + __( 'Cancel', 'learnpress' ) | |
| 277 | + ), | |
| 278 | + 'remove' => sprintf( | |
| 279 | + '<button class="lp-button lp-btn-remove-avatar %s">%s</button>', | |
| 280 | + empty( $avatar_image_url ) ? $class_hide : '', | |
| 281 | + __( 'Remove', 'learnpress' ) | |
| 282 | + ), | |
| 283 | + 'wrapper_end' => '</div>', | |
| 284 | + ]; | |
| 285 | + | |
| 286 | + $section = apply_filters( | |
| 287 | + 'learn-press/profile/html-upload-avatar', | |
| 288 | + [ | |
| 289 | + 'wrapper' => '<div id="learnpress-avatar-upload">', | |
| 290 | + 'image' => Template::combine_components( $section_img ), | |
| 291 | + 'buttons' => Template::combine_components( $section_btn ), | |
| 292 | + 'wrapper_end' => '</div>', | |
| 293 | + ], | |
| 294 | + $user | |
| 295 | + ); | |
| 296 | + | |
| 297 | + $html = Template::combine_components( $section ); | |
| 298 | + } catch ( Throwable $e ) { | |
| 299 | + $html .= Template::print_message( | |
| 300 | + $e->getMessage(), | |
| 301 | + 'error', | |
| 302 | + false | |
| 303 | + ); | |
| 304 | + } | |
| 305 | + return $html; | |
| 306 | + } | |
| 307 | +} | |