1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
<?php /** * Common theme functions * * @package WordPress * @subpackage Twenty_Nineteen * @since Twenty Nineteen 1.5 */
/** * Determines if post thumbnail can be displayed. */ function twentynineteen_can_show_post_thumbnail() { return apply_filters( 'twentynineteen_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() ); }
/** * Returns true if image filters are enabled on the theme options. */ function twentynineteen_image_filters_enabled() { return 0 !== get_theme_mod( 'image_filter', 1 ); }
/** * Returns the size for avatars used in the theme. */ function twentynineteen_get_avatar_size() { return 60; }
/** * Returns true if comment is by author of the post. * * @see get_comment_class() */ function twentynineteen_is_comment_by_post_author( $comment = null ) { if ( is_object( $comment ) && $comment->user_id > 0 ) { $user = get_userdata( $comment->user_id ); $post = get_post( $comment->comment_post_ID ); if ( ! empty( $user ) && ! empty( $post ) ) { return $comment->user_id === $post->post_author; } } return false; }
/** * Returns information about the current post's discussion, with cache support. */ function twentynineteen_get_discussion_data() { static $discussion, $post_id;
$current_post_id = get_the_ID(); if ( $current_post_id === $post_id ) { return $discussion; /* If we have discussion information for post ID, return cached object */ } else { $post_id = $current_post_id; }
$comments = get_comments( array( 'post_id' => $current_post_id, 'orderby' => 'comment_date_gmt', 'order' => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings ยป Discussion. */ 'status' => 'approve', 'number' => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */ ) );
$authors = array(); foreach ( $comments as $comment ) { $authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email; }
$authors = array_unique( $authors ); $discussion = (object) array( 'authors' => array_slice( $authors, 0, 6 ), /* Six unique authors commenting on the post. */ 'responses' => get_comments_number( $current_post_id ), /* Number of responses. */ );
return $discussion; }
/** * Converts HSL to HEX colors. */ function twentynineteen_hsl_hex( $h, $s, $l, $to_hex = true ) {
$h /= 360; $s /= 100; $l /= 100;
$r = $l; $g = $l; $b = $l; $v = ( $l <= 0.5 ) ? ( $l * ( 1.0 + $s ) ) : ( $l + $s - $l * $s );
if ( $v > 0 ) { $m = $l + $l - $v; $sv = ( $v - $m ) / $v; $h *= 6.0; $sextant = floor( $h ); $fract = $h - $sextant; $vsf = $v * $sv * $fract; $mid1 = $m + $vsf; $mid2 = $v - $vsf;
switch ( $sextant ) { case 0: $r = $v; $g = $mid1; $b = $m; break; case 1: $r = $mid2; $g = $v; $b = $m; break; case 2: $r = $m; $g = $v; $b = $mid1; break; case 3: $r = $m; $g = $mid2; $b = $v; break; case 4: $r = $mid1; $g = $m; $b = $v; break; case 5: $r = $v; $g = $m; $b = $mid2; break; } }
$r = round( $r * 255, 0 ); $g = round( $g * 255, 0 ); $b = round( $b * 255, 0 );
if ( $to_hex ) {
$r = ( $r < 15 ) ? '0' . dechex( $r ) : dechex( $r ); $g = ( $g < 15 ) ? '0' . dechex( $g ) : dechex( $g ); $b = ( $b < 15 ) ? '0' . dechex( $b ) : dechex( $b );
return "#$r$g$b";
}
return "rgb($r, $g, $b)"; }
|