PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.4.7
Post Views Counter v1.4.7
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / includes / class-functions.php
post-views-counter / includes Last commit date
class-admin.php 2 years ago class-columns.php 2 years ago class-counter.php 2 years ago class-crawler-detect.php 2 years ago class-cron.php 2 years ago class-dashboard.php 2 years ago class-frontend.php 2 years ago class-functions.php 2 years ago class-query.php 2 years ago class-settings-api.php 2 years ago class-settings.php 2 years ago class-update.php 2 years ago class-widgets.php 2 years ago functions.php 2 years ago
class-functions.php
199 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 /**
7 * Post_Views_Counter_Functions class.
8 *
9 * @class Post_Views_Counter_Functions
10 */
11 class Post_Views_Counter_Functions {
12
13 /**
14 * Class constructor.
15 *
16 * @return void
17 */
18 public function __construct() {}
19
20 /**
21 * Get post types available for counting.
22 *
23 * @return array
24 */
25 public function get_post_types() {
26 $post_types = [];
27
28 // get public post types
29 foreach ( get_post_types( [ 'public' => true ], 'objects', 'and' ) as $key => $post_type ) {
30 $post_types[$key] = $post_type->labels->name;
31 }
32
33 // remove bbPress replies
34 if ( class_exists( 'bbPress' ) && isset( $post_types['reply'] ) )
35 unset( $post_types['reply'] );
36
37 // filter post types
38 $post_types = apply_filters( 'pvc_available_post_types', $post_types );
39
40 // sort post types alphabetically
41 asort( $post_types, SORT_STRING );
42
43 return $post_types;
44 }
45
46 /**
47 * Get all user roles.
48 *
49 * @global object $wp_roles
50 *
51 * @return array
52 */
53 public function get_user_roles() {
54 global $wp_roles;
55
56 $roles = [];
57
58 foreach ( apply_filters( 'editable_roles', $wp_roles->roles ) as $role => $details ) {
59 $roles[$role] = translate_user_role( $details['name'] );
60 }
61
62 // sort user roles alphabetically
63 asort( $roles, SORT_STRING );
64
65 return $roles;
66 }
67
68 /**
69 * Get taxonomies available for counting.
70 *
71 * @param bool $mode
72 * @return array
73 */
74 public function get_taxonomies( $mode = 'labels' ) {
75 // get public taxonomies
76 $taxonomies = get_taxonomies(
77 [
78 'public' => true
79 ],
80 $mode === 'keys' ? 'names' : 'objects',
81 'and'
82 );
83
84 // only keys
85 if ( $mode === 'keys' )
86 $_taxonomies = array_keys( $taxonomies );
87 // objects
88 elseif ( $mode === 'objects' )
89 $_taxonomies = $taxonomies;
90 // labels
91 else {
92 $_taxonomies = [];
93
94 // prepare taxonomy labels
95 foreach ( $taxonomies as $name => $taxonomy ) {
96 $_taxonomies[$name] = $taxonomy->label;
97 }
98 }
99
100 return $_taxonomies;
101 }
102
103 /**
104 * Get color scheme.
105 *
106 * @global array $_wp_admin_css_colors
107 *
108 * @return string
109 */
110 public function get_current_scheme_color( $default_color = '' ) {
111 // get color scheme global
112 global $_wp_admin_css_colors;
113
114 // set default color;
115 $color = '#2271b1';
116
117 if ( ! empty( $_wp_admin_css_colors ) ) {
118 // get current admin color scheme name
119 $current_color_scheme = get_user_option( 'admin_color' );
120
121 if ( empty( $current_color_scheme ) )
122 $current_color_scheme = 'fresh';
123
124 $wp_scheme_colors = [
125 'coffee' => 2,
126 'ectoplasm' => 2,
127 'ocean' => 2,
128 'sunrise' => 2,
129 'midnight' => 3,
130 'blue' => 3,
131 'modern' => 1,
132 'light' => 1,
133 'fresh' => 2
134 ];
135
136 // one of default wp schemes?
137 if ( array_key_exists( $current_color_scheme, $wp_scheme_colors ) ) {
138 $color_number = $wp_scheme_colors[$current_color_scheme];
139
140 // color exists?
141 if ( isset( $_wp_admin_css_colors[$current_color_scheme] ) && property_exists( $_wp_admin_css_colors[$current_color_scheme], 'colors' ) && isset( $_wp_admin_css_colors[$current_color_scheme]->colors[$color_number] ) )
142 $color = $_wp_admin_css_colors[$current_color_scheme]->colors[$color_number];
143 }
144 }
145
146 return $color;
147 }
148
149 /**
150 * Convert HEX to RGB color.
151 *
152 * @param string $color
153 * @return bool|array
154 */
155 public function hex2rgb( $color ) {
156 if ( ! is_string( $color ) )
157 return false;
158
159 // with hash?
160 if ( $color[0] === '#' )
161 $color = substr( $color, 1 );
162
163 if ( sanitize_hex_color_no_hash( $color ) !== $color )
164 return false;
165
166 // 6 hex digits?
167 if ( strlen( $color ) === 6 )
168 list( $r, $g, $b ) = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ];
169 // 3 hex digits?
170 elseif ( strlen( $color ) === 3 )
171 list( $r, $g, $b ) = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ];
172 else
173 return false;
174
175 return [ 'r' => hexdec( $r ), 'g' => hexdec( $g ), 'b' => hexdec( $b ) ];
176 }
177
178 /**
179 * Get default color.
180 *
181 * @return array
182 */
183 public function get_colors() {
184 // get current color scheme
185 $color = $this->get_current_scheme_color();
186
187 // convert it to rgb
188 $color = $this->hex2rgb( $color );
189
190 // invalid color?
191 if ( $color === false ) {
192 // set default color
193 $color = [ 'r' => 34, 'g' => 113, 'b' => 177 ];
194 }
195
196 return $color;
197 }
198 }
199