Admin
1 week ago
Builder
13 hours ago
Customizer
1 week ago
Exceptions
5 months ago
Helpers
1 month ago
Integrations
1 week ago
Migrations
3 years ago
ReviewAlerts
1 week ago
Services
3 weeks ago
Settings
2 months ago
Support
2 months ago
Traits
5 months ago
Utils
3 weeks ago
AuthorizationStatusCheck.php
1 week ago
BusinessDataCache.php
5 months ago
Clear_Cache.php
2 months ago
Container.php
5 months ago
DisplayElements.php
1 month ago
Email_Notification.php
5 months ago
Error_Reporter.php
2 months ago
Feed.php
2 weeks ago
FeedCache.php
4 months ago
FeedCacheUpdater.php
2 months ago
FeedDisplay.php
1 week ago
Feed_Locator.php
5 months ago
Parser.php
3 weeks ago
PostAggregator.php
3 weeks ago
RemoteRequest.php
1 week ago
SBR_Education.php
2 months ago
SBR_Settings.php
5 months ago
ServiceContainer.php
2 weeks ago
SinglePostCache.php
2 weeks ago
TemplateRenderer.php
5 months ago
Tooltip_Wizard.php
2 months ago
Util.php
13 hours ago
DisplayElements.php
610 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SmashBalloon\Reviews\Common; |
| 4 | |
| 5 | class DisplayElements { |
| 6 | public static function get_style_for_setting($feed_id, $item, $settings) |
| 7 | { |
| 8 | $return = '#' . sbr_container_id($feed_id); |
| 9 | $additional = ''; |
| 10 | switch ($item) { |
| 11 | case '.sb-post-item': |
| 12 | $additional = ' ' . self::sb_post_item($settings); |
| 13 | break; |
| 14 | case '.sb-post-item-wrap': |
| 15 | $additional = ' ' . self::sb_post_item_wrap($settings); |
| 16 | break; |
| 17 | case '.sb-feed-header-heading': |
| 18 | $additional = ' ' . self::sb_feed_header_heading($settings); |
| 19 | break; |
| 20 | case '.sb-feed-header-btn': |
| 21 | $additional = ' ' . self::sb_feed_header_btn($settings); |
| 22 | break; |
| 23 | case '.sb-feed-header-btn:hover': |
| 24 | $additional = ' ' . self::sb_feed_header_btn_hover($settings); |
| 25 | break; |
| 26 | case '.sb-feed-header-rating': |
| 27 | $additional = ' ' . self::sb_feed_header_rating($settings); |
| 28 | break; |
| 29 | case '.sb-feed-header-rating-subtext': |
| 30 | $additional = ' ' . self::sb_feed_header_rating_subtext($settings); |
| 31 | break; |
| 32 | case '.sb-feed-header-rating-icons': |
| 33 | $additional = ' ' . self::sb_feed_header_rating_icons($settings); |
| 34 | break; |
| 35 | case '.sb-feed-header-bottom': |
| 36 | $additional = ' ' . self::sb_feed_header_bottom($settings); |
| 37 | break; |
| 38 | case '.sb-feed-header': |
| 39 | $additional = ' ' . self::sb_feed_header($settings); |
| 40 | break; |
| 41 | case '.sb-item-rating': |
| 42 | $additional = ' ' . self::sb_item_rating($settings); |
| 43 | break; |
| 44 | case '.sb-item-text': |
| 45 | $additional = ' ' . self::sb_item_text($settings); |
| 46 | break; |
| 47 | case '.sb-item-author-name': |
| 48 | $additional = ' ' . self::sb_item_author_name($settings); |
| 49 | break; |
| 50 | case '.sb-item-author-date': |
| 51 | $additional = ' ' . self::sb_item_author_date($settings); |
| 52 | break; |
| 53 | case '.sb-item-author-img': |
| 54 | $additional = ' ' . self::sb_item_author_img($settings); |
| 55 | break; |
| 56 | case '.sb-item-author-ctn': |
| 57 | $additional = ' ' . self::sb_item_author_ctn($settings); |
| 58 | break; |
| 59 | case '.sb-load-button': |
| 60 | $additional = ' ' . self::sb_load_button($settings); |
| 61 | break; |
| 62 | case '.sb-load-button:hover': |
| 63 | $additional = ' ' . self::sb_load_button_hover($settings); |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | if (! empty(trim($additional))) { |
| 68 | return $return . $additional . "\n"; |
| 69 | } |
| 70 | |
| 71 | return ''; |
| 72 | } |
| 73 | |
| 74 | public static function sb_post_item($settings) |
| 75 | { |
| 76 | $return = '.sb-post-item {'; |
| 77 | $extra = ''; |
| 78 | $props = array(); |
| 79 | if (! empty($settings['verticalSpacing'])) { |
| 80 | $props[] = 'margin-bottom: ' . (int) $settings['verticalSpacing'] . 'px;'; |
| 81 | } |
| 82 | if (! empty($settings['postStyle']) && $settings['postStyle'] === 'boxed') { |
| 83 | if (! empty($settings['boxedBoxShadow']) && ! empty($settings['boxedBoxShadow']['enabled'])) { |
| 84 | $props[] = 'box-shadow: ' . (int) $settings['boxedBoxShadow']['x'] . 'px ' . (int) $settings['boxedBoxShadow']['y'] . 'px ' . (int) $settings['boxedBoxShadow']['blur'] . 'px ' . (int) $settings['boxedBoxShadow']['spread'] . 'px ' . self::sanitize_color($settings['boxedBoxShadow']['color']) . ';'; |
| 85 | } |
| 86 | if (! empty($settings['boxedBorderRadius']) && ! empty($settings['boxedBorderRadius']['enabled'])) { |
| 87 | $props[] = 'border-radius: ' . (int) $settings['boxedBorderRadius']['radius'] . 'px;'; |
| 88 | } |
| 89 | if (! empty($settings['boxedBackgroundColor'])) { |
| 90 | $props[] = 'background: ' . self::sanitize_color($settings['boxedBackgroundColor']) . ';'; |
| 91 | } |
| 92 | if (! empty($settings['boxedBackgroundColor'])) { |
| 93 | $props[] = 'background: ' . self::sanitize_color($settings['boxedBackgroundColor']) . ';'; |
| 94 | } |
| 95 | if (! empty($settings['postStroke']) && ! empty($settings['postStroke']['enabled'])) { |
| 96 | $extra .= ' [data-post-style="boxed"] .sb-post-item { border: ' . (int) $settings['postStroke']['thickness'] . 'px solid ' . self::sanitize_color($settings['postStroke']['color']) . '; }' ; |
| 97 | } |
| 98 | } else { |
| 99 | if (! empty($settings['postStroke']) && ! empty($settings['postStroke']['enabled'])) { |
| 100 | $extra .= ' [data-post-style="regular"] .sb-post-item { border-bottom: ' . (int) $settings['postStroke']['thickness'] . 'px solid ' . self::sanitize_color($settings['postStroke']['color']) . '; }' ; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if (! empty($settings['postPadding'])) { |
| 105 | $prop_string = self::padding_and_margin_helper($settings['postPadding']); |
| 106 | $props[] = 'padding: ' . $prop_string; |
| 107 | } elseif (! empty($settings['layout']) && $settings['layout'] !== 'list') { |
| 108 | if (! empty($settings['horizontalSpacing'])) { |
| 109 | $prop_string = floor($settings['horizontalSpacing'] / 2) . 'px'; |
| 110 | |
| 111 | $props[] = 'padding: 0 ' . $prop_string . ' 0 ' . $prop_string; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | |
| 116 | $return .= implode('; ', $props) . '}' . $extra; |
| 117 | return $return; |
| 118 | } |
| 119 | |
| 120 | public static function sb_post_item_wrap($settings) |
| 121 | { |
| 122 | $return = '.sb-post-item-wrap {'; |
| 123 | |
| 124 | $props = array(); |
| 125 | if (! empty($settings['postStyle']) && $settings['postStyle'] === 'boxed') { |
| 126 | $props[] = 'padding: 0 5px'; |
| 127 | } else { |
| 128 | return ''; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | $return .= implode('; ', $props) . '}'; |
| 133 | return $return; |
| 134 | } |
| 135 | |
| 136 | public static function sb_feed_header_heading($settings) |
| 137 | { |
| 138 | $return = '.sb-feed-header-heading {'; |
| 139 | $props = array(); |
| 140 | if (! empty($settings['headingFont'])) { |
| 141 | if (! empty($settings['headingFont']['weight'])) { |
| 142 | $props[] = 'font-weight: ' . (int) $settings['headingFont']['weight']; |
| 143 | } |
| 144 | if (! empty($settings['headingFont']['size'])) { |
| 145 | $props[] = 'font-size: ' . (int) $settings['headingFont']['size'] . 'px'; |
| 146 | } |
| 147 | if (! empty($settings['headingFont']['height']) && $settings['headingFont']['height'] !== '100%') { |
| 148 | $props[] = 'height: ' . wp_strip_all_tags($settings['headingFont']['height']); |
| 149 | } |
| 150 | } |
| 151 | if (! empty($settings['headingColor'])) { |
| 152 | $props[] = 'color: ' . self::sanitize_color($settings['headingColor']); |
| 153 | } |
| 154 | if (! empty($settings['headerHeadingPadding'])) { |
| 155 | $props[] = 'padding: ' . (int)$settings['headerHeadingPadding'] . 'px'; |
| 156 | } |
| 157 | if (! empty($settings['headerHeadingMargin']['bottom'])) { |
| 158 | $props[] = 'margin-bottom: ' . (int) $settings['headerHeadingMargin']['bottom'] . 'px;'; |
| 159 | } |
| 160 | |
| 161 | $return .= implode('; ', $props) . '}'; |
| 162 | return $return; |
| 163 | } |
| 164 | |
| 165 | public static function sb_feed_header_btn($settings) |
| 166 | { |
| 167 | $return = '.sb-feed-header-btn {'; |
| 168 | |
| 169 | $props = array(); |
| 170 | if (! empty($settings['headerButtonFont'])) { |
| 171 | $this_setting = $settings['headerButtonFont']; |
| 172 | if (! empty($this_setting['weight'])) { |
| 173 | $props[] = 'font-weight: ' . (int) $this_setting['weight']; |
| 174 | } |
| 175 | if (! empty($this_setting['size'])) { |
| 176 | $props[] = 'font-size: ' . (int) $this_setting['size'] . 'px'; |
| 177 | } |
| 178 | if (! empty($this_setting['height'])) { |
| 179 | $props[] = 'line-height: ' . wp_strip_all_tags($this_setting['height']); |
| 180 | } |
| 181 | if (! empty($settings['headerButtonColor'])) { |
| 182 | $props[] = 'color: ' . self::sanitize_color($settings['headerButtonColor']); |
| 183 | } |
| 184 | if (! empty($settings['headerButtonBg'])) { |
| 185 | $props[] = 'background-color: ' . self::sanitize_color($settings['headerButtonBg']); |
| 186 | } |
| 187 | if (! empty($settings['headerButtonPadding'])) { |
| 188 | $prop_string = self::padding_and_margin_helper($settings['headerButtonPadding']); |
| 189 | |
| 190 | $props[] = 'padding: ' . $prop_string; |
| 191 | } |
| 192 | if (! empty($settings['headerButtonMargin'])) { |
| 193 | $prop_string = self::padding_and_margin_helper($settings['headerButtonMargin']); |
| 194 | |
| 195 | $props[] = 'margin: ' . $prop_string; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | $return .= implode('; ', $props) . '}'; |
| 200 | return $return; |
| 201 | } |
| 202 | |
| 203 | public static function sb_feed_header_btn_hover($settings) |
| 204 | { |
| 205 | $return = '.sb-feed-header-btn:hover {'; |
| 206 | |
| 207 | $props = array(); |
| 208 | if (! empty($settings['headerButtonFont'])) { |
| 209 | if (! empty($settings['headerButtonHoverColor'])) { |
| 210 | $props[] = 'color: ' . self::sanitize_color($settings['headerButtonHoverColor']); |
| 211 | } |
| 212 | if (! empty($settings['headerButtonHoverBg'])) { |
| 213 | $props[] = 'background-color: ' . self::sanitize_color($settings['headerButtonHoverBg']); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | $return .= implode('; ', $props) . '}'; |
| 218 | return $return; |
| 219 | } |
| 220 | |
| 221 | public static function sb_feed_header_rating($settings) |
| 222 | { |
| 223 | $return = '.sb-feed-header-rating {'; |
| 224 | |
| 225 | $props = array(); |
| 226 | if (! empty($settings['headerAvReviewColor'])) { |
| 227 | $props[] = 'color: ' . self::sanitize_color($settings['headerAvReviewColor']); |
| 228 | } |
| 229 | if (! empty($settings['headerAvReviewFont'])) { |
| 230 | $this_setting = $settings['headerAvReviewFont']; |
| 231 | if (! empty($this_setting['weight'])) { |
| 232 | $props[] = 'font-weight: ' . (int) $this_setting['weight']; |
| 233 | } |
| 234 | if (! empty($this_setting['size'])) { |
| 235 | $props[] = 'font-size: ' . (int) $this_setting['size'] . 'px'; |
| 236 | } |
| 237 | if (! empty($this_setting['height'])) { |
| 238 | $props[] = 'line-height: ' . wp_strip_all_tags($this_setting['height']); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | $return .= implode('; ', $props) . '}'; |
| 243 | return $return; |
| 244 | } |
| 245 | |
| 246 | public static function sb_feed_header_rating_subtext($settings) |
| 247 | { |
| 248 | $return = '.sb-feed-header-rating-subtext {'; |
| 249 | |
| 250 | $props = array(); |
| 251 | if (! empty($settings['headerAvReviewSubtextColor'])) { |
| 252 | $props[] = 'color: ' . self::sanitize_color($settings['headerAvReviewSubtextColor']); |
| 253 | } |
| 254 | if (! empty($settings['headerAvSubtextReviewFont'])) { |
| 255 | $this_setting = $settings['headerAvSubtextReviewFont']; |
| 256 | if (! empty($this_setting['weight'])) { |
| 257 | $props[] = 'font-weight: ' . (int) $this_setting['weight']; |
| 258 | } |
| 259 | if (! empty($this_setting['size'])) { |
| 260 | $props[] = 'font-size: ' . (int) $this_setting['size'] . 'px'; |
| 261 | } |
| 262 | if (! empty($this_setting['height'])) { |
| 263 | $props[] = 'line-height: ' . wp_strip_all_tags($this_setting['height']); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | $return .= implode('; ', $props) . '}'; |
| 268 | return $return; |
| 269 | } |
| 270 | |
| 271 | public static function sb_feed_header_rating_icons($settings) |
| 272 | { |
| 273 | $return = '.sb-feed-header-rating-icons {'; |
| 274 | |
| 275 | $props = array(); |
| 276 | if (! empty($settings['headerAvReviewIconColor'])) { |
| 277 | $props[] = 'color: ' . self::sanitize_color($settings['headerAvReviewIconColor']); |
| 278 | } |
| 279 | $return .= implode('; ', $props) . '}'; |
| 280 | return $return; |
| 281 | } |
| 282 | |
| 283 | public static function sb_feed_header_bottom($settings) |
| 284 | { |
| 285 | $return = '.sb-feed-header-bottom {'; |
| 286 | |
| 287 | $props = array(); |
| 288 | if (! empty($settings['headerAvReviewPadding'])) { |
| 289 | $prop_string = self::padding_and_margin_helper($settings['headerAvReviewPadding']); |
| 290 | |
| 291 | $props[] = 'padding: ' . $prop_string; |
| 292 | } |
| 293 | if (! empty($settings['headerAvReviewMargin'])) { |
| 294 | $prop_string = self::padding_and_margin_helper($settings['headerAvReviewMargin']); |
| 295 | |
| 296 | $props[] = 'margin: ' . $prop_string; |
| 297 | } |
| 298 | $return .= implode('; ', $props) . '}'; |
| 299 | return $return; |
| 300 | } |
| 301 | |
| 302 | public static function sb_feed_header($settings) |
| 303 | { |
| 304 | $return = '.sb-feed-header {'; |
| 305 | |
| 306 | $props = array(); |
| 307 | if (! empty($settings['headerPadding'])) { |
| 308 | $prop_string = self::padding_and_margin_helper($settings['headerPadding']); |
| 309 | |
| 310 | $props[] = 'padding: ' . $prop_string; |
| 311 | } |
| 312 | if (! empty($settings['headerMargin'])) { |
| 313 | $prop_string = self::padding_and_margin_helper($settings['headerMargin']); |
| 314 | |
| 315 | $props[] = 'margin: ' . $prop_string; |
| 316 | } |
| 317 | $return .= implode('; ', $props) . '}'; |
| 318 | return $return; |
| 319 | } |
| 320 | public static function sb_item_rating($settings) |
| 321 | { |
| 322 | $return = '.sb-item-rating {'; |
| 323 | |
| 324 | $props = array(); |
| 325 | if (! empty($settings['ratingIconColor'])) { |
| 326 | $props[] = 'color: ' . self::sanitize_color($settings['ratingIconColor']); |
| 327 | } |
| 328 | if (! empty($settings['ratingIconPadding'])) { |
| 329 | $prop_string = self::padding_and_margin_helper($settings['ratingIconPadding']); |
| 330 | $props[] = 'padding: ' . $prop_string; |
| 331 | } |
| 332 | if (! empty($settings['ratingIconMargin'])) { |
| 333 | $prop_string = self::padding_and_margin_helper($settings['ratingIconMargin']); |
| 334 | $props[] = 'margin: ' . $prop_string; |
| 335 | } |
| 336 | $return .= implode('; ', $props) . '}'; |
| 337 | return $return; |
| 338 | } |
| 339 | |
| 340 | public static function sb_item_text($settings) |
| 341 | { |
| 342 | $return = '.sb-item-text {'; |
| 343 | |
| 344 | $props = array(); |
| 345 | if (! empty($settings['paragraphColor'])) { |
| 346 | $props[] = 'color: ' . self::sanitize_color($settings['paragraphColor']); |
| 347 | } |
| 348 | if (! empty($settings['paragraphFont'])) { |
| 349 | $this_setting = $settings['paragraphFont']; |
| 350 | if (! empty($this_setting['weight'])) { |
| 351 | $props[] = 'font-weight: ' . (int) $this_setting['weight']; |
| 352 | } |
| 353 | if (! empty($this_setting['size'])) { |
| 354 | $props[] = 'font-size: ' . (int) $this_setting['size'] . 'px'; |
| 355 | } |
| 356 | if (! empty($this_setting['height'])) { |
| 357 | $props[] = 'line-height: ' . wp_strip_all_tags($this_setting['height']); |
| 358 | } |
| 359 | } |
| 360 | if (! empty($settings['paragraphPadding'])) { |
| 361 | $prop_string = self::padding_and_margin_helper($settings['paragraphPadding']); |
| 362 | $props[] = 'padding: ' . $prop_string; |
| 363 | } |
| 364 | if (! empty($settings['paragraphMargin'])) { |
| 365 | $prop_string = self::padding_and_margin_helper($settings['paragraphMargin']); |
| 366 | $props[] = 'margin: ' . $prop_string; |
| 367 | } |
| 368 | $return .= implode('; ', $props) . '}'; |
| 369 | return $return; |
| 370 | } |
| 371 | |
| 372 | public static function sb_item_author_name($settings) |
| 373 | { |
| 374 | $return = '.sb-item-author-name {'; |
| 375 | |
| 376 | $props = array(); |
| 377 | if (! empty($settings['authorNameColor'])) { |
| 378 | $props[] = 'color: ' . self::sanitize_color($settings['authorNameColor']); |
| 379 | } |
| 380 | if (! empty($settings['authorNameFont'])) { |
| 381 | $this_setting = $settings['authorNameFont']; |
| 382 | if (! empty($this_setting['weight'])) { |
| 383 | $props[] = 'font-weight: ' . (int) $this_setting['weight']; |
| 384 | } |
| 385 | if (! empty($this_setting['size'])) { |
| 386 | $props[] = 'font-size: ' . (int) $this_setting['size'] . 'px'; |
| 387 | } |
| 388 | if (! empty($this_setting['height'])) { |
| 389 | $props[] = 'line-height: ' . wp_strip_all_tags($this_setting['height']); |
| 390 | } |
| 391 | } |
| 392 | if (! empty($settings['authorNamePadding'])) { |
| 393 | $prop_string = self::padding_and_margin_helper($settings['authorNamePadding']); |
| 394 | $props[] = 'padding: ' . $prop_string; |
| 395 | } |
| 396 | if (! empty($settings['authorNameMargin'])) { |
| 397 | $prop_string = self::padding_and_margin_helper($settings['authorNameMargin']); |
| 398 | $props[] = 'margin: ' . $prop_string; |
| 399 | } |
| 400 | $return .= implode('; ', $props) . '}'; |
| 401 | return $return; |
| 402 | } |
| 403 | public static function sb_item_author_date($settings) |
| 404 | { |
| 405 | $return = '.sb-item-author-date {'; |
| 406 | |
| 407 | $props = array(); |
| 408 | if (! empty($settings['dateColor'])) { |
| 409 | $props[] = 'color: ' . self::sanitize_color($settings['dateColor']); |
| 410 | } |
| 411 | if (! empty($settings['dateFont'])) { |
| 412 | $this_setting = $settings['dateFont']; |
| 413 | if (! empty($this_setting['weight'])) { |
| 414 | $props[] = 'font-weight: ' . (int) $this_setting['weight']; |
| 415 | } |
| 416 | if (! empty($this_setting['size'])) { |
| 417 | $props[] = 'font-size: ' . (int) $this_setting['size'] . 'px'; |
| 418 | } |
| 419 | if (! empty($this_setting['height'])) { |
| 420 | $props[] = 'line-height: ' . wp_strip_all_tags($this_setting['height']); |
| 421 | } |
| 422 | } |
| 423 | if (! empty($settings['datePadding'])) { |
| 424 | $prop_string = self::padding_and_margin_helper($settings['datePadding']); |
| 425 | $props[] = 'padding: ' . $prop_string; |
| 426 | } |
| 427 | if (! empty($settings['dateMargin'])) { |
| 428 | $prop_string = self::padding_and_margin_helper($settings['dateMargin']); |
| 429 | $props[] = 'margin: ' . $prop_string; |
| 430 | } |
| 431 | $return .= implode('; ', $props) . '}'; |
| 432 | return $return; |
| 433 | } |
| 434 | |
| 435 | public static function sb_item_author_img($settings) |
| 436 | { |
| 437 | $return = '.sb-item-author-img {'; |
| 438 | |
| 439 | $props = array(); |
| 440 | if (! empty($settings['authorImageMargin'])) { |
| 441 | $prop_string = self::padding_and_margin_helper($settings['authorImageMargin']); |
| 442 | $props[] = 'margin: ' . $prop_string; |
| 443 | } |
| 444 | $return .= implode('; ', $props) . '}'; |
| 445 | |
| 446 | if (! empty($settings['authorImageBorderRadius'])) { |
| 447 | $return .= '.sb-item-author-img img {'; |
| 448 | |
| 449 | $return .= 'border-radius: ' . (int) $settings['authorImageBorderRadius'] . 'px;'; |
| 450 | $return .= '}'; |
| 451 | } |
| 452 | return $return; |
| 453 | } |
| 454 | |
| 455 | public static function sb_item_author_ctn($settings) |
| 456 | { |
| 457 | $return = '.sb-item-author-ctn {'; |
| 458 | |
| 459 | $props = array(); |
| 460 | if (! empty($settings['authorPadding'])) { |
| 461 | $prop_string = self::padding_and_margin_helper($settings['authorPadding']); |
| 462 | $props[] = 'padding: ' . $prop_string; |
| 463 | } |
| 464 | if (! empty($settings['authorMargin'])) { |
| 465 | $prop_string = self::padding_and_margin_helper($settings['authorMargin']); |
| 466 | $props[] = 'margin: ' . $prop_string; |
| 467 | } |
| 468 | $return .= implode('; ', $props) . '}'; |
| 469 | return $return; |
| 470 | } |
| 471 | |
| 472 | public static function sb_load_button($settings) |
| 473 | { |
| 474 | $return = '.sb-load-button {'; |
| 475 | |
| 476 | $props = array(); |
| 477 | if (! empty($settings['loadButtonFont'])) { |
| 478 | $this_setting = $settings['loadButtonFont']; |
| 479 | if (! empty($this_setting['weight'])) { |
| 480 | $props[] = 'font-weight: ' . (int) $this_setting['weight']; |
| 481 | } |
| 482 | if (! empty($this_setting['size'])) { |
| 483 | $props[] = 'font-size: ' . (int) $this_setting['size'] . 'px'; |
| 484 | } |
| 485 | if (! empty($this_setting['height'])) { |
| 486 | $props[] = 'line-height: ' . wp_strip_all_tags($this_setting['height']); |
| 487 | } |
| 488 | if (! empty($settings['loadButtonColor'])) { |
| 489 | $props[] = 'color: ' . self::sanitize_color($settings['loadButtonColor']); |
| 490 | } |
| 491 | if (! empty($settings['loadButtonBg'])) { |
| 492 | $props[] = 'background-color: ' . self::sanitize_color($settings['loadButtonBg']); |
| 493 | } |
| 494 | if (! empty($settings['loadButtonPadding'])) { |
| 495 | $prop_string = self::padding_and_margin_helper($settings['loadButtonPadding']); |
| 496 | |
| 497 | $props[] = 'padding: ' . $prop_string; |
| 498 | } |
| 499 | if (! empty($settings['loadButtonMargin'])) { |
| 500 | $prop_string = self::padding_and_margin_helper($settings['loadButtonMargin']); |
| 501 | |
| 502 | $props[] = 'margin: ' . $prop_string; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | $return .= implode('; ', $props) . '}'; |
| 507 | return $return; |
| 508 | } |
| 509 | |
| 510 | public static function sb_load_button_hover($settings) |
| 511 | { |
| 512 | $return = '.sb-load-button:hover {'; |
| 513 | |
| 514 | $props = array(); |
| 515 | if (! empty($settings['loadButtonFont'])) { |
| 516 | if (! empty($settings['loadButtonHoverColor'])) { |
| 517 | $props[] = 'color: ' . self::sanitize_color($settings['loadButtonHoverColor']); |
| 518 | } |
| 519 | if (! empty($settings['loadButtonHoverBg'])) { |
| 520 | $props[] = 'background-color: ' . self::sanitize_color($settings['loadButtonHoverBg']); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | $return .= implode('; ', $props) . '}'; |
| 525 | return $return; |
| 526 | } |
| 527 | |
| 528 | public static function padding_and_margin_helper($setting) |
| 529 | { |
| 530 | $prop_string = ''; |
| 531 | |
| 532 | $keys = array( 'top', 'right', 'bottom', 'left' ); |
| 533 | foreach ($keys as $key) { |
| 534 | if (! empty($setting[ $key ])) { |
| 535 | $prop_string .= intval($setting[ $key ]) . 'px '; |
| 536 | } else { |
| 537 | $prop_string .= '0 '; |
| 538 | } |
| 539 | } |
| 540 | return $prop_string; |
| 541 | } |
| 542 | |
| 543 | public static function sanitize_color($color) |
| 544 | { |
| 545 | if (empty($color) || is_array($color)) { |
| 546 | return 'rgba(0,0,0,0)'; |
| 547 | } |
| 548 | |
| 549 | if (false === strpos($color, 'rgba')) { |
| 550 | return sanitize_hex_color($color); |
| 551 | } |
| 552 | |
| 553 | $color = str_replace(' ', '', $color); |
| 554 | sscanf($color, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha); |
| 555 | return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; |
| 556 | } |
| 557 | |
| 558 | public static function get_star_icon() |
| 559 | { |
| 560 | // Mirrors customizer/sb-common/sb-customizer/assets/icons/star.svg so |
| 561 | // the frontend feed-header stars and the customizer admin preview |
| 562 | // render the same glyph at the same size. Previous version used the |
| 563 | // `popup-star.svg` path inside a 24x24 viewBox — the glyph only |
| 564 | // filled the inner ~20 units, so at width:18px the visible star was |
| 565 | // only ~15px (17% smaller than the customizer's 18px star). Path + |
| 566 | // viewBox below match star.svg exactly so width:18px renders 18px. |
| 567 | return '<svg viewBox="0 0 20 20" fill="currentColor"> |
| 568 | <path d="M10.0001 16.0074L14.8499 18.9407C15.7381 19.4783 16.8249 18.6836 16.5912 17.6786L15.3057 12.1626L19.5946 8.44634C20.3776 7.76853 19.9569 6.48303 18.9285 6.40122L13.2839 5.92208L11.0752 0.709949C10.6779 -0.236649 9.32225 -0.236649 8.92491 0.709949L6.71618 5.91039L1.07165 6.38954C0.043251 6.47134 -0.377459 7.75685 0.405529 8.43466L4.69444 12.1509L3.40893 17.6669C3.17521 18.6719 4.26204 19.4666 5.15021 18.929L10.0001 16.0074V16.0074Z"/> |
| 569 | </svg>'; |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * Get provider icon as inline SVG |
| 574 | * |
| 575 | * Reads the provider SVG file and returns its content for inline rendering. |
| 576 | * This matches the admin preview which uses inline SVGs via SbUtils.printIcon(). |
| 577 | * |
| 578 | * @since 2.5.0 |
| 579 | * @param string $provider Provider name (e.g., 'google', 'yelp', 'edd'). |
| 580 | * @return string Inline SVG markup or empty string if file not found. |
| 581 | */ |
| 582 | public static function get_provider_icon($provider) |
| 583 | { |
| 584 | // Sanitize provider name to prevent path traversal |
| 585 | $provider = sanitize_file_name($provider); |
| 586 | |
| 587 | // Build path to provider icon SVG |
| 588 | $icon_path = SBR_PLUGIN_DIR . 'assets/icons/' . $provider . '-provider.svg'; |
| 589 | |
| 590 | // Check if file exists and is readable |
| 591 | if (! file_exists($icon_path) || ! is_readable($icon_path)) { |
| 592 | // Fallback to google icon if provider icon not found |
| 593 | $icon_path = SBR_PLUGIN_DIR . 'assets/icons/google-provider.svg'; |
| 594 | if (! file_exists($icon_path) || ! is_readable($icon_path)) { |
| 595 | return ''; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | // Read SVG content |
| 600 | // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Reading local SVG file |
| 601 | $svg_content = file_get_contents($icon_path); |
| 602 | |
| 603 | if (false === $svg_content) { |
| 604 | return ''; |
| 605 | } |
| 606 | |
| 607 | return $svg_content; |
| 608 | } |
| 609 | } |
| 610 |