← All changes
|
vendor/codeinwp/themeisle-sdk/src/Modules/Dashboard_widget.php
+79
-36
3.0.0
→
trunk
View file →
| @@ -11,8 +11,9 @@ | ||
| 11 | 11 | |
| 12 | 12 | namespace ThemeisleSDK\Modules; |
| 13 | 13 | |
| 14 | 14 | use ThemeisleSDK\Common\Abstract_Module; |
| 15 | +use ThemeisleSDK\Loader; | |
| 15 | 16 | use ThemeisleSDK\Product; |
| 16 | 17 | |
| 17 | 18 | // Exit if accessed directly. |
| 18 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -75,13 +76,14 @@ | ||
| 75 | 76 | if ( apply_filters( 'themeisle_sdk_hide_dashboard_widget', false ) ) { |
| 76 | 77 | return; |
| 77 | 78 | } |
| 78 | 79 | $this->product = $product; |
| 79 | - $this->dashboard_name = apply_filters( 'themeisle_sdk_dashboard_widget_name', 'WordPress Guides/Tutorials' ); | |
| 80 | + $this->dashboard_name = apply_filters( 'themeisle_sdk_dashboard_widget_name', Loader::$labels['dashboard_widget']['title'] ); | |
| 80 | 81 | $this->feeds = apply_filters( |
| 81 | 82 | 'themeisle_sdk_dashboard_widget_feeds', |
| 82 | 83 | [ |
| 83 | 84 | 'https://themeisle.com/blog/feed', |
| 85 | + 'https://wpshout.com/feed', | |
| 84 | 86 | ] |
| 85 | 87 | ); |
| 86 | 88 | add_action( 'wp_dashboard_setup', array( &$this, 'add_widget' ) ); |
| 87 | 89 | add_action( 'wp_network_dashboard_setup', array( &$this, 'add_widget' ) ); |
| @@ -95,9 +97,9 @@ | ||
| 95 | 97 | * Add widget to the dashboard |
| 96 | 98 | * |
| 97 | 99 | * @return string|void |
| 98 | 100 | */ |
| 99 | - function add_widget() { | |
| 101 | + public function add_widget() { | |
| 100 | 102 | global $wp_meta_boxes; |
| 101 | 103 | if ( isset( $wp_meta_boxes['dashboard']['normal']['core']['themeisle'] ) ) { |
| 102 | 104 | return; |
| 103 | 105 | } |
| @@ -113,9 +115,9 @@ | ||
| 113 | 115 | |
| 114 | 116 | /** |
| 115 | 117 | * Render widget content |
| 116 | 118 | */ |
| 117 | - function render_dashboard_widget() { | |
| 119 | + public function render_dashboard_widget() { | |
| 118 | 120 | $this->setup_feeds(); |
| 119 | 121 | if ( empty( $this->items ) || ! is_array( $this->items ) ) { |
| 120 | 122 | return; |
| 121 | 123 | } |
| @@ -120,8 +122,12 @@ | ||
| 120 | 122 | return; |
| 121 | 123 | } |
| 122 | 124 | ?> |
| 123 | 125 | <style type="text/css"> |
| 126 | + #dashboard-widgets #themeisle .hndle { | |
| 127 | + padding-left: 39px; | |
| 128 | + } | |
| 129 | + | |
| 124 | 130 | #themeisle ul li.ti-dw-recommend-item { |
| 125 | 131 | padding-left: 7px; |
| 126 | 132 | border-top: 1px solid #eee; |
| 127 | 133 | margin-bottom: 0px; |
| @@ -130,9 +136,9 @@ | ||
| 130 | 136 | |
| 131 | 137 | #themeisle h2.hndle { |
| 132 | 138 | background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABbCAMAAADncTNAAAAAtFBMVEVHcEyAgIB/f3+xsbGgoaGBgYGCgoKKioqAgIC1tbW5ubnFx8iAgIDU1taBgYGCgoKAgIC0tLXW19jW2NiAgIC3uLiBgYHLzMy4uLhycnLW19d/f3/T1NW0tLTX19mVlZWvr6+BgYHl5eWKiottbW5JSUnW2Nm5ubnh4eHT1NWVlZVjY2N4eHh9fX6pqqq+v79PT0/39/fu7u7Nzc7Z2ttYWFgBAQHDw8P////JysoZGRk0NTZqJc/sAAAAIXRSTlMA0FL7/oEnEPL6eibivm9gwJya76/enFq2CXI+2lFAyM8GATmPAAADj0lEQVR4Xu2YaW/iOhSGAwRCWDosnXa6znjJvm8svf//f12TuARyhiR2pfnUR6gSEnr0+uT4xK7yRb755pvhHePli5K7Bfpkuhoq8ozRJdMH+WWha6Z3sqYparCSLRJqspjImVbANJU03cNMMpofAwQZCGsmpQYyFvVM0Q00OQ9koMl5IPcCoro+RA1Dt2Ea9n9eZ0+YHJLkgIl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% 50%; | |
| 140 | + background-position: 2% 50%; | |
| 135 | 141 | background-size: 25px; |
| 136 | 142 | } |
| 137 | 143 | |
| 138 | 144 | #themeisle .inside { |
| @@ -219,21 +225,23 @@ | ||
| 219 | 225 | ?> |
| 220 | 226 | <li class="ti-dw-feed-item"> |
| 221 | 227 | <a href=" |
| 222 | 228 | <?php |
| 223 | - echo add_query_arg( | |
| 224 | - array( | |
| 225 | - 'utm_source' => 'wpadmin', | |
| 226 | - 'utm_campaign' => 'feed', | |
| 227 | - 'utm_medium' => 'dashboard_widget', | |
| 228 | - ), | |
| 229 | - $item['link'] | |
| 229 | + echo esc_url( | |
| 230 | + add_query_arg( | |
| 231 | + array( | |
| 232 | + 'utm_source' => 'wpadmin', | |
| 233 | + 'utm_campaign' => 'feed', | |
| 234 | + 'utm_medium' => 'dashboard_widget', | |
| 235 | + ), | |
| 236 | + $item['link'] | |
| 237 | + ) | |
| 230 | 238 | ); |
| 231 | 239 | ?> |
| 232 | 240 | " target="_blank"> |
| 233 | 241 | <span class="ti-dw-date-container"><span |
| 234 | - class="ti-dw-day-container"><?php echo date( 'd', $item['date'] ); ?></span> <span | |
| 235 | - class="ti-dw-month-container"><?php echo substr( date( 'M', $item['date'] ), 0, 3 ); ?></span></span><?php echo $item['title']; ?> | |
| 242 | + class="ti-dw-day-container"><?php echo esc_attr( gmdate( 'd', $item['date'] ) ); ?></span> <span | |
| 243 | + class="ti-dw-month-container"><?php echo esc_attr( substr( gmdate( 'M', $item['date'] ), 0, 3 ) ); ?></span></span><?php echo esc_attr( $item['title'] ); ?> | |
| 236 | 244 | </a> |
| 237 | 245 | </li> |
| 238 | 246 | <?php |
| 239 | 247 | } |
| @@ -274,28 +282,30 @@ | ||
| 274 | 282 | } |
| 275 | 283 | ?> |
| 276 | 284 | <div class="ti-dw-footer"> |
| 277 | 285 | <span class="ti-dw-recommend-item "> |
| 278 | - <span class="ti-dw-recommend"><?php echo apply_filters( 'themeisle_sdk_dashboard_popular_label', sprintf( 'Popular %s', ucwords( $type ) ) ); ?> | |
| 286 | + <span class="ti-dw-recommend"><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_popular_label', sprintf( Loader::$labels['dashboard_widget']['popular'], ucwords( $type ) ) ) ); ?> | |
| 279 | 287 | : </span> |
| 280 | 288 | <?php |
| 281 | - echo trim( | |
| 282 | - str_replace( | |
| 283 | - array( | |
| 284 | - 'lite', | |
| 285 | - 'Lite', | |
| 286 | - '(Lite)', | |
| 287 | - '(lite)', | |
| 288 | - ), | |
| 289 | - '', | |
| 290 | - $recommend['name'] | |
| 289 | + echo esc_attr( | |
| 290 | + trim( | |
| 291 | + str_replace( | |
| 292 | + array( | |
| 293 | + 'lite', | |
| 294 | + 'Lite', | |
| 295 | + '(Lite)', | |
| 296 | + '(lite)', | |
| 297 | + ), | |
| 298 | + '', | |
| 299 | + $recommend['name'] | |
| 300 | + ) | |
| 291 | 301 | ) |
| 292 | 302 | ); |
| 293 | 303 | ?> |
| 294 | 304 | (<a class="thickbox open-plugin-details-modal" |
| 295 | - href="<?php echo $url . '&TB_iframe=true&width=600&height=500'; ?>"><?php echo apply_filters( 'themeisle_sdk_dashboard_install_label', 'Install' ); ?></a>) | |
| 305 | + href="<?php echo esc_url( $url . '&TB_iframe=true&width=600&height=500' ); ?>"><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_install_label', Loader::$labels['dashboard_widget']['install'] ) ); ?></a>) | |
| 296 | 306 | </span> |
| 297 | - <span class="ti-dw-powered-by"><span><?php echo apply_filters( 'themeisle_sdk_dashboard_widget_powered_by', esc_attr( sprintf( 'Powered by %s', $this->product->get_friendly_name() ) ) ); ?></span></span> | |
| 307 | + <span class="ti-dw-powered-by"><span><?php echo esc_attr( apply_filters( 'themeisle_sdk_dashboard_widget_powered_by', sprintf( Loader::$labels['dashboard_widget']['powered'], $this->product->get_friendly_name() ) ) ); ?></span></span> | |
| 298 | 308 | </div> |
| 299 | 309 | |
| 300 | 310 | <?php |
| 301 | 311 | |
| @@ -304,11 +314,40 @@ | ||
| 304 | 314 | /** |
| 305 | 315 | * Setup feed items. |
| 306 | 316 | */ |
| 307 | 317 | private function setup_feeds() { |
| 308 | - if ( false === ( $items_normalized = get_transient( 'themeisle_sdk_feed_items' ) ) ) { | |
| 318 | + if ( false === ( $items_normalized = get_transient( 'themeisle_sdk_feed_items' ) ) ) { //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure | |
| 319 | + // Do not force the feed for the items in the sdk feeds list. | |
| 320 | + // this prevents showing notices if another plugin will force all SimplePie feeds to load, instead it will | |
| 321 | + // use the regular SimplePie validation and abort early if the feed is not valid. | |
| 322 | + $sdk_feeds = $this->feeds; | |
| 323 | + add_action( | |
| 324 | + 'wp_feed_options', | |
| 325 | + function ( $feed, $url ) use ( $sdk_feeds ) { | |
| 326 | + if ( defined( 'TI_SDK_PHPUNIT' ) && true === TI_SDK_PHPUNIT ) { | |
| 327 | + return; | |
| 328 | + } | |
| 329 | + | |
| 330 | + if ( ! is_string( $url ) && in_array( $url, $sdk_feeds, true ) ) { | |
| 331 | + $feed->force_feed( false ); | |
| 332 | + | |
| 333 | + return; | |
| 334 | + } | |
| 335 | + if ( is_array( $url ) ) { | |
| 336 | + foreach ( $url as $feed_url ) { | |
| 337 | + if ( in_array( $feed_url, $sdk_feeds, true ) ) { | |
| 338 | + $feed->force_feed( false ); | |
| 339 | + | |
| 340 | + return; | |
| 341 | + } | |
| 342 | + } | |
| 343 | + } | |
| 344 | + }, | |
| 345 | + PHP_INT_MAX, | |
| 346 | + 2 | |
| 347 | + ); | |
| 309 | 348 | // Load SimplePie Instance. |
| 310 | - $feed = fetch_feed( $this->feeds ); | |
| 349 | + $feed = fetch_feed( $sdk_feeds ); | |
| 311 | 350 | // TODO report error when is an error loading the feed. |
| 312 | 351 | if ( is_wp_error( $feed ) ) { |
| 313 | 352 | return; |
| 314 | 353 | } |
| @@ -313,9 +352,13 @@ | ||
| 313 | 352 | return; |
| 314 | 353 | } |
| 315 | 354 | |
| 316 | 355 | $items = $feed->get_items( 0, 5 ); |
| 317 | - foreach ( (array) $items as $item ) { | |
| 356 | + $items = is_array( $items ) ? $items : []; | |
| 357 | + | |
| 358 | + $items_normalized = []; | |
| 359 | + | |
| 360 | + foreach ( $items as $item ) { | |
| 318 | 361 | $items_normalized[] = array( |
| 319 | 362 | 'title' => $item->get_title(), |
| 320 | 363 | 'date' => $item->get_date( 'U' ), |
| 321 | 364 | 'link' => $item->get_permalink(), |
| @@ -352,9 +395,9 @@ | ||
| 352 | 395 | |
| 353 | 396 | /** |
| 354 | 397 | * Contact the API and fetch the recommended plugins/themes |
| 355 | 398 | */ |
| 356 | - function recommend_plugin_or_theme() { | |
| 399 | + public function recommend_plugin_or_theme() { | |
| 357 | 400 | $products = $this->get_product_from_api(); |
| 358 | 401 | if ( ! is_array( $products ) ) { |
| 359 | 402 | $products = array(); |
| 360 | 403 | } |
| @@ -373,10 +416,10 @@ | ||
| 373 | 416 | * Fetch products from the recomended section. |
| 374 | 417 | * |
| 375 | 418 | * @return array|mixed The list of products to use in recomended section. |
| 376 | 419 | */ |
| 377 | - function get_product_from_api() { | |
| 378 | - if ( false === ( $products = get_transient( 'themeisle_sdk_products' ) ) ) { | |
| 420 | + public function get_product_from_api() { | |
| 421 | + if ( false === ( $products = get_transient( 'themeisle_sdk_products' ) ) ) { //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure | |
| 379 | 422 | $products = array(); |
| 380 | 423 | $all_themes = $this->get_themes_from_wporg( 'themeisle' ); |
| 381 | 424 | $all_plugins = $this->get_plugins_from_wporg( 'themeisle' ); |
| 382 | 425 | static $allowed_products = [ |
| @@ -428,10 +471,10 @@ | ||
| 428 | 471 | * @param string $author The author name. |
| 429 | 472 | * |
| 430 | 473 | * @return array The list of themes. |
| 431 | 474 | */ |
| 432 | - function get_themes_from_wporg( $author ) { | |
| 433 | - $products = wp_remote_get( | |
| 475 | + public function get_themes_from_wporg( $author ) { | |
| 476 | + $products = $this->safe_get( | |
| 434 | 477 | 'https://api.wordpress.org/themes/info/1.1/?action=query_themes&request[author]=' . $author . '&request[per_page]=30&request[fields][active_installs]=true' |
| 435 | 478 | ); |
| 436 | 479 | $products = json_decode( wp_remote_retrieve_body( $products ) ); |
| 437 | 480 | if ( is_object( $products ) ) { |
| @@ -449,10 +492,10 @@ | ||
| 449 | 492 | * @param string $author The author slug. |
| 450 | 493 | * |
| 451 | 494 | * @return array The list of plugins for the selected author. |
| 452 | 495 | */ |
| 453 | - function get_plugins_from_wporg( $author ) { | |
| 454 | - $products = wp_remote_get( | |
| 496 | + public function get_plugins_from_wporg( $author ) { | |
| 497 | + $products = $this->safe_get( | |
| 455 | 498 | 'https://api.wordpress.org/plugins/info/1.1/?action=query_plugins&request[author]=' . $author . '&request[per_page]=40&request[fields][active_installs]=true' |
| 456 | 499 | ); |
| 457 | 500 | $products = json_decode( wp_remote_retrieve_body( $products ) ); |
| 458 | 501 | if ( is_object( $products ) ) { |