Changeset 3320429
- Timestamp:
- 07/01/2025 08:38:44 AM (8 months ago)
- Location:
- jennystudio-identicons/trunk
- Files:
-
- 3 edited
-
jennystudio-identicons.php (modified) (7 diffs)
-
material-design-avatars/MDAvatars.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jennystudio-identicons/trunk/jennystudio-identicons.php
r3316518 r3320429 4 4 Plugin URI: https://www.becomingjenny.net 5 5 Description: Use the MDAvatars library to create Identicons avatars compatible with WordPress, BuddyPress, and bbPress 6 Version: 1. 26 Version: 1.3 7 7 Author: Brain1981 8 8 Author URI: https://blog.brain1981.com … … 19 19 20 20 /* replace buddypress default avatar*/ 21 function brain1981_buddypress_default_avatar_url( $avatar, $params ) {21 function jennystudio_buddypress_default_avatar_url( $avatar, $params ) { 22 22 $user_id = $params['item_id']; 23 23 $username = bp_core_get_user_displayname($user_id); 24 $avatar_md = new Md\MDAvatars($username, 256);25 $avatar_url = $avatar_md->Output2Base64( 256);24 $avatar_md = new Md\MDAvatars($username, 132); 25 $avatar_url = $avatar_md->Output2Base64(132); 26 26 return $avatar_url; 27 27 } 28 add_filter( 'bp_core_mysteryman_src', ' brain1981_buddypress_default_avatar_url',99,2 );29 add_filter( 'bp_core_default_avatar_user', ' brain1981_buddypress_default_avatar_url',99,2 );28 add_filter( 'bp_core_mysteryman_src', 'jennystudio_buddypress_default_avatar_url',99,2 ); 29 add_filter( 'bp_core_default_avatar_user', 'jennystudio_buddypress_default_avatar_url',99,2 ); 30 30 31 31 /* … … 35 35 buddypress: $id_or_email number, id, but skip user uploaded avatar 36 36 */ 37 function brain1981_site_get_avatar($avatar, $id_or_email, $size, $default, $alt){ 38 37 function jennystudio_site_get_avatar($avatar, $id_or_email, $size, $default, $alt){ 39 38 preg_match("/class='(.*)'/isU", htmlentities($avatar), $match1); 40 39 $class_str = $match1[0] ; 41 40 if(function_exists('bp_core_fetch_avatar')){ 42 $bpavatar_url = bp_core_fetch_avatar( array( 'item_id' => $id_or_email, 'no_grav' => true,'html'=> false ) ); 41 42 if ( is_numeric( $id_or_email ) ){ 43 $user_id = (int)$id_or_email; 44 } elseif ( is_a( $id_or_email, 'WP_Comment' ) ) { 45 $user_id = $id_or_email->user_id; 46 } elseif ( is_string( $id_or_email ) && is_email( $id_or_email ) ) { 47 //keep as email address 48 $user_id = $id_or_email; 49 } 50 51 $bpavatar_url = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'no_grav' => true,'html'=> false ) ); 43 52 if ( strlen($bpavatar_url) < 400 && strlen($bpavatar_url) > 70) { 44 /* 头像URL长度小于400表示是上传的头像*/53 /* those URLs for avatar less than 400 are uploaded images */ 45 54 return $avatar; 46 55 }else{ … … 59 68 }else{ 60 69 /* General Comment Area */ 61 $avatar_string = $id_or_email->comment_author; 62 if(!empty($avatar_string)){ 63 64 $username = $avatar_string; 65 70 if(!empty($id_or_email->comment_author)){ 71 $username = $id_or_email->comment_author; 66 72 }else{ 67 73 /* no user id*/ … … 69 75 $username = $user->display_name; 70 76 } 71 72 77 } 73 $avatar_md = new Md\MDAvatars($username, 256);74 $avatar_url = $avatar_md->Output2Base64( 256);78 $avatar_md = new Md\MDAvatars($username, 128); 79 $avatar_url = $avatar_md->Output2Base64(128); 75 80 $avatar_bg_idx = $avatar_md->charToFixedNumber(); 76 81 $avatar_md->Free(); … … 81 86 return $my_avatar; 82 87 } 83 add_filter('get_avatar', ' brain1981_site_get_avatar', 10, 5);88 add_filter('get_avatar', 'jennystudio_site_get_avatar', 10, 5); 84 89 85 90 … … 96 101 } 97 102 103 104 /* Add Setting fields on Discussion page*/ 105 //Register fields 106 function jennystudio_register_custom_discussion_color_field() { 107 register_setting( 108 'discussion', 109 'jennystudio_identicons_color_bg', 110 array( 111 'type' => 'string', 112 'sanitize_callback' => 'sanitize_hex_color', 113 'default' => '#dab118' 114 ) 115 ); 116 add_settings_field( 117 'jennystudio_identicons_color_bg', 118 __('Identicons Background Color', 'jennystudio-identicons'), 119 'jennystudio_render_color_picker_field_1', 120 'discussion', 121 'avatars' 122 ); 123 124 register_setting( 125 'discussion', 126 'jennystudio_identicons_color_font', 127 array( 128 'type' => 'string', 129 'sanitize_callback' => 'sanitize_hex_color', 130 'default' => '#dab118' 131 ) 132 ); 133 add_settings_field( 134 'jennystudio_identicons_color_font', 135 __('Identicons Font Color', 'jennystudio-identicons'), 136 'jennystudio_render_color_picker_field_2', 137 'discussion', 138 'avatars' 139 ); 140 } 141 add_action('admin_init', 'jennystudio_register_custom_discussion_color_field'); 142 143 144 //Render fields 145 function jennystudio_render_color_picker_field_1() { 146 $color = get_option('jennystudio_identicons_color_bg', '#dab118'); 147 ?> 148 <input type="text" 149 name="jennystudio_identicons_color_bg" 150 id="jennystudio_identicons_color_bg" 151 value="<?php echo esc_attr($color); ?>" 152 class="color-field" 153 data-default-color="#dab118" 154 data-alpha-enabled="true"> 155 156 <?php 157 } 158 function jennystudio_render_color_picker_field_2() { 159 $color = get_option('jennystudio_identicons_color_font', '#ffffff'); 160 ?> 161 <input type="text" 162 name="jennystudio_identicons_color_font" 163 id="jennystudio_identicons_color_font" 164 value="<?php echo esc_attr($color); ?>" 165 class="color-field" 166 data-default-color="#ffffff" 167 data-alpha-enabled="true"> 168 169 <?php 170 } 171 172 //Load necessary styles and scripts 173 function jennystudio_enqueue_color_picker_assets($hook) { 174 if ('options-discussion.php' !== $hook) { 175 return; 176 } 177 178 wp_enqueue_style('wp-color-picker'); 179 wp_enqueue_script('wp-color-picker'); 180 //Initial Color Picker 181 wp_add_inline_script('wp-color-picker', ' 182 jQuery(document).ready(function($) { 183 $(".color-field").wpColorPicker(); 184 185 $(".color-field").each(function() { 186 187 $(this).after(\'<button type="button" class="button wp-picker-clear button-small">Clear</button>\'); 188 189 $(this).next(".wp-picker-clear").on("click", function() { 190 $(this).prev(".color-field") 191 .val("") 192 .trigger("change") 193 .iris("color", ""); 194 }); 195 }); 196 }); 197 '); 198 } 199 add_action('admin_enqueue_scripts', 'jennystudio_enqueue_color_picker_assets'); 200 98 201 ?> -
jennystudio-identicons/trunk/material-design-avatars/MDAvatars.php
r3316518 r3320429 5 5 * Create material deisgn avatars for users just like Gmail or Messager in Android. 6 6 */ 7 7 8 namespace Md; 8 9 … … 75 76 public function charToFixedNumber(){ 76 77 return abs(crc32($this->CharFull)) % 256; 78 } 79 80 //hex color to rgb 81 public function hexToRgbObject($hex) { 82 // 去除可能存在的 # 号 83 $hex = ltrim($hex, '#'); 84 // 验证是否为3位或6位十六进制颜色值 85 if (!preg_match('/^([a-f0-9]{3}){1,2}$/i', $hex)) { 86 return false; 87 } 88 // 如果是3位缩写格式,则扩展为6位 89 if (strlen($hex) === 3) { 90 $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2]; 91 } 92 // 创建对象并设置属性 93 $rgb = new \stdClass(); 94 $rgb->r = hexdec(substr($hex, 0, 2)); 95 $rgb->g = hexdec(substr($hex, 2, 2)); 96 $rgb->b = hexdec(substr($hex, 4, 2)); 97 return $rgb; 77 98 } 78 99 … … 359 380 $MaterialDesignColor[$BackgroundColorIndex][2] 360 381 ); 382 383 $jennystudio_identicons_color_bg = get_option('jennystudio_identicons_color_bg'); 384 if(!empty($jennystudio_identicons_color_bg)){ 385 $BackgroundColor = imagecolorallocate($this->Avatar, 386 $this->hexToRgbObject($jennystudio_identicons_color_bg)->r, 387 $this->hexToRgbObject($jennystudio_identicons_color_bg)->g, 388 $this->hexToRgbObject($jennystudio_identicons_color_bg)->b 389 ); 390 } 391 361 392 //画一个居中圆形 362 393 imagefilledellipse($this->Avatar, … … 376 407 $FontColor = imagecolorallocate($this->Avatar, 96, 96, 96); 377 408 } 409 410 $jennystudio_identicons_color_font = get_option('jennystudio_identicons_color_font'); 411 if(!empty($jennystudio_identicons_color_font)){ 412 $FontColor = imagecolorallocate($this->Avatar, 413 $this->hexToRgbObject($jennystudio_identicons_color_font)->r, 414 $this->hexToRgbObject($jennystudio_identicons_color_font)->g, 415 $this->hexToRgbObject($jennystudio_identicons_color_font)->b 416 ); 417 } 418 378 419 379 420 if ($this->IsNotLetter) { -
jennystudio-identicons/trunk/readme.txt
r3317855 r3320429 3 3 Tags: avatars, identicon, buddypress, bbpress, custom-avatar 4 4 Requires at least: 5.2 5 Tested up to: 6.8 6 Stable tag: 1. 25 Tested up to: 6.8.1 6 Stable tag: 1.3 7 7 License: GPLv2 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 42 42 43 43 == Changelog == 44 = 1.3 = 45 * Added 2 setting fields on discussion page. Now avatar background color and font color are configurable. 46 44 47 = 1.2 = 45 * Fix Optimize and correct the occupancy ratio of Chinese avatar text and the background text color under light colors.48 * Fixed Optimize and correct the occupancy ratio of Chinese avatar text and the background text color under light colors.. 46 49 47 50 = 1.1 = 48 51 * Fixed BuddyPress avatar caching issue. 49 52 * Optimize Base64 generation performance. 50 * When modifying MDAvatars, the background color of the Avatar generated by the original library is random. After this plug-in is modified, the background color is fixed according to the user name string to avoid the problem of different colors each time it is refreshed 53 * When modifying MDAvatars, the background color of the Avatar generated by the original library is random. After this plug-in is modified, the background color is fixed according to the user name string to avoid the problem of different colors each time it is refreshed. 51 54 52 55 = 1.0 =
Note: See TracChangeset
for help on using the changeset viewer.