PluginProbe
WebberZone Top 10 — Popular Posts / 4.3.2
WebberZone Top 10 — Popular Posts v4.3.2
4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 All 117 releases
top-10 / includes / frontend / class-styles-handler.php

class-styles-handler.php in WebberZone Top 10 — Popular Posts 4.3.2, at includes/frontend/class-styles-handler.php

189 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Styles Handler class.
4 *
5 * @package WebberZone\Top_Ten\Frontend
6 */
7
8 namespace WebberZone\Top_Ten\Frontend;
9
10 use WebberZone\Top_Ten\Util\Hook_Registry;
11
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 /**
17 * Styles Handler Class.
18 *
19 * @since 3.3.0
20 */
21 class Styles_Handler {
22
23 /**
24 * Constructor class.
25 *
26 * @since 3.3.0
27 */
28 public function __construct() {
29 Hook_Registry::add_action( 'wp_head', array( $this, 'header' ) );
30 Hook_Registry::add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ) );
31 }
32
33 /**
34 * Function to add CSS to header.
35 *
36 * @since 1.9
37 */
38 public static function header() {
39
40 $custom_css = stripslashes( tptn_get_option( 'custom_css' ) );
41
42 // Add CSS to header.
43 if ( $custom_css ) {
44 echo '<style type="text/css">' . $custom_css . '</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
45 }
46 }
47
48 /**
49 * Enqueue styles.
50 */
51 public static function register_styles() {
52
53 $style_array = self::get_style();
54
55 if ( ! empty( $style_array['name'] ) ) {
56 $style = $style_array['name'];
57 $extra_css = $style_array['extra_css'];
58 $is_rtl = is_rtl();
59
60 wp_register_style(
61 "tptn-style-{$style}",
62 plugins_url( self::get_stylesheet_path( $style, $is_rtl ), TOP_TEN_PLUGIN_FILE ),
63 array(),
64 TOP_TEN_VERSION
65 );
66 wp_enqueue_style( "tptn-style-{$style}" );
67
68 if ( ! empty( $extra_css ) ) {
69 wp_add_inline_style( "tptn-style-{$style}", $extra_css );
70 }
71 }
72 }
73
74 /**
75 * Get stylesheet path accounting for minified and pro files.
76 *
77 * @since 4.2.0
78 *
79 * @param string $style Style name.
80 * @param bool $is_rtl Whether RTL stylesheet should be loaded.
81 *
82 * @return string
83 */
84 public static function get_stylesheet_path( $style, $is_rtl = false ) {
85
86 $base_path = 'includes/frontend/css/';
87 if ( false !== strpos( $style, '-pro' ) ) {
88 $base_path = 'includes/pro/frontend/css/';
89 }
90
91 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
92 $rtl = $is_rtl ? '-rtl' : '';
93
94 return "{$base_path}{$style}{$rtl}{$suffix}.css";
95 }
96
97 /**
98 * Get the current style for the popular posts.
99 *
100 * @since 3.0.0
101 * @since 3.2.0 Added parameter $style
102 *
103 * @param string $style Style parameter.
104 *
105 * @return array Contains two elements:
106 * 'name' holding style name and 'extra_css' to be added inline.
107 */
108 public static function get_style( $style = '' ) {
109
110 $style_array = array();
111 $thumb_width = tptn_get_option( 'thumb_width' );
112 $thumb_height = tptn_get_option( 'thumb_height' );
113 $width_value = absint( $thumb_width );
114 $height_value = absint( $thumb_height );
115
116 if ( ! $width_value ) {
117 $width_value = 1;
118 }
119
120 if ( ! $height_value ) {
121 $height_value = 1;
122 }
123 $aspect_ratio = sprintf( '%d / %d', $width_value, $height_value );
124 $tptn_style = ! empty( $style ) ? $style : tptn_get_option( 'tptn_styles' );
125
126 switch ( $tptn_style ) {
127 case 'left_thumbs':
128 $style_array['name'] = 'left-thumbs';
129 $style_array['extra_css'] = "
130 .tptn-left-thumbs {
131 --tptn-thumb-width: {$thumb_width}px;
132 --tptn-thumb-height: {$thumb_height}px;
133 --tptn-thumb-aspect-ratio: {$aspect_ratio};
134 }
135 .tptn-left-thumbs img.tptn_thumb {
136 width: min( var(--tptn-thumb-width), 100% );
137 height: var(--tptn-thumb-height);
138 max-height: var(--tptn-thumb-height);
139 aspect-ratio: var(--tptn-thumb-aspect-ratio);
140 object-fit: cover;
141 }
142 .tptn-left-thumbs li > a.tptn_link {
143 display: block;
144 flex: 0 0 auto;
145 align-self: flex-start;
146 padding: var(--tptn-thumb-frame-padding, 0.25rem );
147 border-width: var(--tptn-thumb-frame-border-width, 1px );
148 border-style: solid;
149 border-color: var(--tptn-thumb-border, #ccc );
150 border-radius: var(--tptn-border-radius, 8px );
151 box-shadow: var(--tptn-shadow, 0 2px 4px rgba(0, 0, 0, 0.15) );
152 transition: transform var(--tptn-transition, 0.2s ease), box-shadow var(--tptn-transition, 0.2s ease);
153 will-change: transform;
154 }
155 .tptn-left-thumbs ul li:hover > a.tptn_link {
156 transform: scale(1.03);
157 box-shadow: var(--tptn-shadow-hover, 0 4px 8px rgba(0, 0, 0, 0.2) );
158 }
159 .tptn-left-thumbs .tptn_title {
160 width: 100%;
161 }
162 ";
163 break;
164
165 case 'text_only':
166 $style_array['name'] = 'text-only';
167 $style_array['extra_css'] = '';
168 break;
169
170 default:
171 $style_array['name'] = '';
172 $style_array['extra_css'] = '';
173 break;
174 }
175
176 /**
177 * Filter the style array which contains the name and extra_css.
178 *
179 * @since 3.2.0
180 *
181 * @param array $style_array Style array containing name and extra_css.
182 * @param string $tptn_style Style name.
183 * @param int $thumb_width Thumbnail width.
184 * @param int $thumb_height Thumbnail height.
185 */
186 return apply_filters( 'tptn_get_style', $style_array, $tptn_style, $thumb_width, $thumb_height );
187 }
188 }
189