PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.4.2
Post Views Counter v1.4.2
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
213 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 number of columns in post_views table.
105 *
106 * @global object $wpdb
107 *
108 * @return int
109 */
110 public function get_number_of_columns() {
111 global $wpdb;
112
113 // get number of columns
114 return (int) $wpdb->get_var( "SELECT COUNT(*) AS result FROM information_schema.columns WHERE table_schema = '" . $wpdb->dbname . "' AND table_name = '" . $wpdb->prefix . "post_views'" );
115 }
116
117 /**
118 * Get color scheme.
119 *
120 * @global array $_wp_admin_css_colors
121 *
122 * @return string
123 */
124 public function get_current_scheme_color( $default_color = '' ) {
125 // get color scheme global
126 global $_wp_admin_css_colors;
127
128 // set default color;
129 $color = '#2271b1';
130
131 if ( ! empty( $_wp_admin_css_colors ) ) {
132 // get current admin color scheme name
133 $current_color_scheme = get_user_option( 'admin_color' );
134
135 if ( empty( $current_color_scheme ) )
136 $current_color_scheme = 'fresh';
137
138 $wp_scheme_colors = [
139 'coffee' => 2,
140 'ectoplasm' => 2,
141 'ocean' => 2,
142 'sunrise' => 2,
143 'midnight' => 3,
144 'blue' => 3,
145 'modern' => 1,
146 'light' => 1,
147 'fresh' => 2
148 ];
149
150 // one of default wp schemes?
151 if ( array_key_exists( $current_color_scheme, $wp_scheme_colors ) ) {
152 $color_number = $wp_scheme_colors[$current_color_scheme];
153
154 // color exists?
155 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] ) )
156 $color = $_wp_admin_css_colors[$current_color_scheme]->colors[$color_number];
157 }
158 }
159
160 return $color;
161 }
162
163 /**
164 * Convert HEX to RGB color.
165 *
166 * @param string $color
167 * @return bool|array
168 */
169 public function hex2rgb( $color ) {
170 if ( ! is_string( $color ) )
171 return false;
172
173 // with hash?
174 if ( $color[0] === '#' )
175 $color = substr( $color, 1 );
176
177 if ( sanitize_hex_color_no_hash( $color ) !== $color )
178 return false;
179
180 // 6 hex digits?
181 if ( strlen( $color ) === 6 )
182 list( $r, $g, $b ) = [ $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ];
183 // 3 hex digits?
184 elseif ( strlen( $color ) === 3 )
185 list( $r, $g, $b ) = [ $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ];
186 else
187 return false;
188
189 return [ 'r' => hexdec( $r ), 'g' => hexdec( $g ), 'b' => hexdec( $b ) ];
190 }
191
192 /**
193 * Get default color.
194 *
195 * @return array
196 */
197 public function get_colors() {
198 // get current color scheme
199 $color = $this->get_current_scheme_color();
200
201 // convert it to rgb
202 $color = $this->hex2rgb( $color );
203
204 // invalid color?
205 if ( $color === false ) {
206 // set default color
207 $color = [ 'r' => 34, 'g' => 113, 'b' => 177 ];
208 }
209
210 return $color;
211 }
212 }
213