|
2 | 2 |
|
3 | 3 | /** |
4 | 4 | ** get_avatar.php |
5 | | - ** @version 1.1 |
| 5 | + ** @version 1.2 |
6 | 6 | ** @since 1.0 |
7 | 7 | ** @author en0ndev |
8 | 8 | */ |
|
26 | 26 |
|
27 | 27 | $usr = new WP_User; |
28 | 28 | $current_user = $usr->wp_get_current_user(); |
| 29 | +$get__commenter__indx__bfr = null; |
| 30 | +$get__commenter__indx__aft = null; |
| 31 | +$get__commenter__indx__vrf = 0; |
| 32 | +$get__commenter__indx = 0; |
| 33 | + |
| 34 | +function cpa__start__values() |
| 35 | +{ |
| 36 | + global $current_user, $get__commenter__indx; |
| 37 | + $get__commenter__indx = (!get_user_meta($current_user->ID, 'custom_profile_avatar')[0]) ? ((!is_admin()) ? -1 : -2) : 0; |
| 38 | +} |
| 39 | +add_action("init", "cpa__start__values"); |
29 | 40 |
|
30 | 41 | function cpa__get__old($id) |
31 | 42 | { |
@@ -65,6 +76,19 @@ function cpa__get__value() |
65 | 76 | return 0; |
66 | 77 | } |
67 | 78 |
|
| 79 | +function compare__comment__id($a, $b) |
| 80 | +{ |
| 81 | + //echo $a->comment_ID . " " . $b->comment_ID; |
| 82 | + if ($a->comment_ID == $b->comment_ID) { |
| 83 | + return 0; |
| 84 | + } |
| 85 | + return ($a->comment_ID < $b->comment_ID) ? -1 : 1; |
| 86 | +} |
| 87 | + |
| 88 | +if (!function_exists('get_current_screen')) { |
| 89 | + require_once ABSPATH . '/wp-admin/includes/screen.php'; |
| 90 | +} |
| 91 | + |
68 | 92 | if (!function_exists('get_avatar')) { |
69 | 93 | function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args = null) |
70 | 94 | { |
@@ -130,18 +154,148 @@ function get_avatar($id_or_email, $size = 96, $default = '', $alt = '', $args = |
130 | 154 | $usr = get_userdata($user); |
131 | 155 | $roles = $usr->roles; |
132 | 156 |
|
133 | | - //echo $roles[0]; |
| 157 | + global $post; |
| 158 | + global $get__commenter__indx, $get__commenter__indx__bfr, $get__commenter__indx__aft, $get__commenter__indx__vrf; |
| 159 | + |
| 160 | + $comments__author__id__array = array(); |
| 161 | + $comments__id__array = array(); |
| 162 | + |
| 163 | + if (is_single() || is_page() || is_singular()) { |
| 164 | + $get__comments = get_comments(array('post_id' => $post->ID)); |
| 165 | + usort($get__comments, 'compare__comment__id'); |
| 166 | + } else if (is_admin() && isset($_GET['user_id'])) { |
| 167 | + $get__comments = get_comments(array('user_id' => $_GET['user_id'])); |
| 168 | + } else { |
| 169 | + $get__comments = get_comments(); |
| 170 | + } |
| 171 | + |
| 172 | + $get__parent__id__arr = array(); |
| 173 | + foreach ($get__comments as $get__comment) { |
| 174 | + array_push($get__parent__id__arr, $get__comment->comment_parent); |
| 175 | + } |
| 176 | + $get__parent__id__arr__cln = $get__parent__id__arr; |
| 177 | + |
| 178 | + $indx__getting__comments = 0; |
| 179 | + foreach ($get__comments as $get__comment) { |
| 180 | + |
| 181 | + $comment__id = $get__comment->comment_ID; |
| 182 | + $comment__author__id = get_comment($comment__id)->user_id; |
| 183 | + |
| 184 | + $get__comment__parent_id = get_comment($comment__id)->comment_parent; |
| 185 | + $pos__for__arr = array_search($get__comment__parent_id, $comments__id__array); |
| 186 | + |
| 187 | + if ($get__comment__parent_id < 1 || (!is_single() && !is_page() && !is_singular())) { |
| 188 | + |
| 189 | + array_push($comments__id__array, $comment__id); |
| 190 | + array_push($comments__author__id__array, $comment__author__id); |
| 191 | + } else { |
| 192 | + |
| 193 | + if (is_single() || is_page() || is_singular()) { |
| 194 | + |
| 195 | + $get__parent__id__arr__del = array_search($get__comment__parent_id, $get__parent__id__arr); |
| 196 | + $get__parent__id__arr__cnt = array_count_values($get__parent__id__arr)[$get__comment__parent_id]; |
| 197 | + $get__parent__id__arr__cln__cnt = array_count_values($get__parent__id__arr__cln)[$get__comment__parent_id]; |
| 198 | + |
| 199 | + if ($get__parent__id__arr__cln__cnt > 1) { |
| 200 | + |
| 201 | + $gttng__pos = $get__parent__id__arr__cln__cnt - $get__parent__id__arr__cnt + 1; |
| 202 | + |
| 203 | + $comments__author__id__array = array_merge(array_slice($comments__author__id__array, 0, $pos__for__arr + $gttng__pos), array($comment__author__id), array_slice($comments__author__id__array, $pos__for__arr + $gttng__pos)); |
| 204 | + |
| 205 | + $comments__id__array = array_merge(array_slice($comments__id__array, 0, $pos__for__arr + $gttng__pos), array($comment__id), array_slice($comments__id__array, $pos__for__arr + $gttng__pos)); |
| 206 | + |
| 207 | + unset($get__parent__id__arr[$get__parent__id__arr__del]); |
| 208 | + } else { |
| 209 | + |
| 210 | + $comments__author__id__array = array_merge(array_slice($comments__author__id__array, 0, $pos__for__arr + 1), array($comment__author__id), array_slice($comments__author__id__array, $pos__for__arr + 1)); |
| 211 | + |
| 212 | + $comments__id__array = array_merge(array_slice($comments__id__array, 0, $pos__for__arr + 1), array($comment__id), array_slice($comments__id__array, $pos__for__arr + 1)); |
| 213 | + } |
| 214 | + } else { |
| 215 | + $comments__author__id__array = array_merge(array_slice($comments__author__id__array, 0, $pos__for__arr + 1), array($comment__author__id), array_slice($comments__author__id__array, $pos__for__arr + 1)); |
| 216 | + |
| 217 | + $comments__id__array = array_merge(array_slice($comments__id__array, 0, $pos__for__arr + 1), array($comment__id), array_slice($comments__id__array, $pos__for__arr + 1)); |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | + $indx__getting__comments++; |
| 222 | + } |
| 223 | + |
| 224 | + $commenter__user = get_userdata($comments__author__id__array[$get__commenter__indx]); |
| 225 | + $commenter__role = $commenter__user->roles; |
| 226 | + |
| 227 | + |
| 228 | + $spcfc__admn__pg = 0; |
| 229 | + if (is_admin() && (get_current_screen()->id === "edit-comments" || get_current_screen()->id === "dashboard")) { |
| 230 | + $spcfc__admn__pg = 1; |
| 231 | + } |
| 232 | + |
| 233 | + if (is_admin() && $_GET["paged"] > 1 && get_current_screen()->id === "edit-comments" && ($_GET["paged"] - 1) * 20 > $get__commenter__indx) { |
| 234 | + $chng__pos = $_GET["paged"]; |
| 235 | + $get__commenter__indx = 0; |
| 236 | + while ($chng__pos > 1) { |
| 237 | + $get__commenter__indx += (!is_admin()) ? 20 : 19; |
| 238 | + $chng__pos--; |
| 239 | + } |
| 240 | + } |
134 | 241 |
|
135 | 242 | if (get_user_meta($usr__id, 'custom_profile_avatar')[0] && (get_option("custom_profile_avatar__options__permissions")[$roles[0]] == "on" || $roles[0] == "administrator")) { |
136 | 243 | $custom__avatar = get_user_meta($usr__id, 'custom_profile_avatar')[0]; |
137 | 244 | } else if (get_user_meta($id_or_email, 'custom_profile_avatar')[0] && (get_option("custom_profile_avatar__options__permissions")[$roles[0]] == "on" || $roles[0] == "administrator")) { |
138 | 245 | $custom__avatar = get_user_meta($id_or_email, 'custom_profile_avatar')[0]; |
| 246 | + } else if (get_user_meta($comments__author__id__array[$get__commenter__indx], 'custom_profile_avatar')[0] && (get_option("custom_profile_avatar__options__permissions")[$commenter__role[0]] == "on" || $commenter__role[0] == "administrator") && (is_single() || is_page() || is_singular() || $spcfc__admn__pg == 1)) { |
| 247 | + |
| 248 | + $custom__avatar = get_user_meta($comments__author__id__array[$get__commenter__indx], 'custom_profile_avatar')[0]; |
| 249 | + |
| 250 | + if (is_single() || is_page() || is_singular() || get_current_screen()->id === "dashboard") { |
| 251 | + |
| 252 | + $get__commenter__indx++; |
| 253 | + } else { |
| 254 | + $get__commenter__indx__bfr = $get__commenter__indx; |
| 255 | + |
| 256 | + if ($get__commenter__indx > 0) { |
| 257 | + |
| 258 | + if (($get__commenter__indx__bfr % 2 != 0 && $get__commenter__indx__aft % 2 == 0) || $get__commenter__indx__vrf == 0) { |
| 259 | + $get__commenter__indx__vrf = 1; |
| 260 | + } else { |
| 261 | + $get__commenter__indx__vrf = 0; |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + if ($get__commenter__indx__vrf != 1) { |
| 266 | + $get__commenter__indx++; |
| 267 | + } |
| 268 | + |
| 269 | + $get__commenter__indx__aft = $get__commenter__indx; |
| 270 | + } |
139 | 271 | } else { |
140 | 272 | $url = $args['url']; |
141 | 273 | if (!$url || is_wp_error($url)) { |
142 | 274 | return false; |
143 | 275 | } |
144 | 276 | $custom__avatar = $url; |
| 277 | + |
| 278 | + if (is_single() || is_page() || is_singular() || get_current_screen()->id === "dashboard") { |
| 279 | + |
| 280 | + $get__commenter__indx++; |
| 281 | + } else { |
| 282 | + $get__commenter__indx__bfr = $get__commenter__indx; |
| 283 | + |
| 284 | + if ($get__commenter__indx > 0) { |
| 285 | + |
| 286 | + if (($get__commenter__indx__bfr % 2 != 0 && $get__commenter__indx__aft % 2 == 0) || $get__commenter__indx__vrf == 0) { |
| 287 | + $get__commenter__indx__vrf = 1; |
| 288 | + } else { |
| 289 | + $get__commenter__indx__vrf = 0; |
| 290 | + } |
| 291 | + } |
| 292 | + |
| 293 | + if ($get__commenter__indx__vrf != 1) { |
| 294 | + $get__commenter__indx++; |
| 295 | + } |
| 296 | + |
| 297 | + $get__commenter__indx__aft = $get__commenter__indx; |
| 298 | + } |
145 | 299 | } |
146 | 300 |
|
147 | 301 | $class = array('avatar', 'avatar-' . (int) $args['size'], 'photo'); |
|
0 commit comments