entities
10 years ago
managers
10 years ago
sdk
10 years ago
class-freemius-abstract.php
10 years ago
class-freemius.php
10 years ago
class-fs-api.php
10 years ago
class-fs-logger.php
10 years ago
class-fs-plugin-updater.php
10 years ago
class-fs-security.php
10 years ago
fs-core-functions.php
10 years ago
fs-plugin-functions.php
10 years ago
i18n.php
10 years ago
fs-plugin-functions.php
412 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package Freemius |
| 4 | * @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 6 | * @since 1.0.6 |
| 7 | */ |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Display plugin information in dialog box form. |
| 15 | * |
| 16 | * @since 2.7.0 |
| 17 | */ |
| 18 | function fs_install_plugin_information() { |
| 19 | global $tab; |
| 20 | |
| 21 | if ( empty( $_REQUEST['plugin'] ) ) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $args = array( |
| 26 | 'slug' => wp_unslash( $_REQUEST['plugin'] ), |
| 27 | 'is_ssl' => is_ssl(), |
| 28 | 'fields' => array( 'banners' => true, 'reviews' => true ) |
| 29 | ); |
| 30 | |
| 31 | if ( is_array( $args ) ) { |
| 32 | $args = (object) $args; |
| 33 | } |
| 34 | |
| 35 | if ( ! isset( $args->per_page ) ) { |
| 36 | $args->per_page = 24; |
| 37 | } |
| 38 | |
| 39 | if ( ! isset( $args->locale ) ) { |
| 40 | $args->locale = get_locale(); |
| 41 | } |
| 42 | |
| 43 | $api = apply_filters( 'fs_plugins_api', false, 'plugin_information', $args ); |
| 44 | |
| 45 | if ( is_wp_error( $api ) ) { |
| 46 | wp_die( $api ); |
| 47 | } |
| 48 | |
| 49 | $plugins_allowedtags = array( |
| 50 | 'a' => array( |
| 51 | 'href' => array(), |
| 52 | 'title' => array(), |
| 53 | 'target' => array(), |
| 54 | // Add image style for screenshots. |
| 55 | 'class' => array() |
| 56 | ), |
| 57 | 'style' => array(), |
| 58 | 'abbr' => array( 'title' => array() ), |
| 59 | 'acronym' => array( 'title' => array() ), |
| 60 | 'code' => array(), |
| 61 | 'pre' => array(), |
| 62 | 'em' => array(), |
| 63 | 'strong' => array(), |
| 64 | 'div' => array( 'class' => array() ), |
| 65 | 'span' => array( 'class' => array() ), |
| 66 | 'p' => array(), |
| 67 | 'ul' => array(), |
| 68 | 'ol' => array(), |
| 69 | 'li' => array( 'class' => array() ), |
| 70 | 'i' => array( 'class' => array() ), |
| 71 | 'h1' => array(), |
| 72 | 'h2' => array(), |
| 73 | 'h3' => array(), |
| 74 | 'h4' => array(), |
| 75 | 'h5' => array(), |
| 76 | 'h6' => array(), |
| 77 | 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array() ), |
| 78 | // 'table' => array(), |
| 79 | // 'td' => array(), |
| 80 | // 'tr' => array(), |
| 81 | // 'th' => array(), |
| 82 | // 'thead' => array(), |
| 83 | // 'tbody' => array(), |
| 84 | ); |
| 85 | |
| 86 | $plugins_section_titles = array( |
| 87 | 'description' => _x( 'Description', 'Plugin installer section title' ), |
| 88 | 'installation' => _x( 'Installation', 'Plugin installer section title' ), |
| 89 | 'faq' => _x( 'FAQ', 'Plugin installer section title' ), |
| 90 | 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), |
| 91 | 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), |
| 92 | 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), |
| 93 | 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), |
| 94 | 'features' => __fs( 'features-and-pricing' ), |
| 95 | ); |
| 96 | |
| 97 | // Sanitize HTML |
| 98 | // foreach ( (array) $api->sections as $section_name => $content ) { |
| 99 | // $api->sections[$section_name] = wp_kses( $content, $plugins_allowedtags ); |
| 100 | // } |
| 101 | |
| 102 | foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { |
| 103 | if ( isset( $api->$key ) ) { |
| 104 | $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | $_tab = esc_attr( $tab ); |
| 109 | |
| 110 | $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; // Default to the Description tab, Do not translate, API returns English. |
| 111 | if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { |
| 112 | $section_titles = array_keys( (array) $api->sections ); |
| 113 | $section = array_shift( $section_titles ); |
| 114 | } |
| 115 | |
| 116 | iframe_header( __( 'Plugin Install' ) ); |
| 117 | |
| 118 | $_with_banner = ''; |
| 119 | |
| 120 | // var_dump($api->banners); |
| 121 | if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { |
| 122 | $_with_banner = 'with-banner'; |
| 123 | $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; |
| 124 | $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; |
| 125 | ?> |
| 126 | <style type="text/css"> |
| 127 | #plugin-information-title.with-banner |
| 128 | { |
| 129 | background-image: url( <?php echo esc_url( $low ); ?> ); |
| 130 | } |
| 131 | |
| 132 | @media only screen and ( -webkit-min-device-pixel-ratio: 1.5 ) |
| 133 | { |
| 134 | #plugin-information-title.with-banner |
| 135 | { |
| 136 | background-image: url( <?php echo esc_url( $high ); ?> ); |
| 137 | } |
| 138 | } |
| 139 | </style> |
| 140 | <?php |
| 141 | } |
| 142 | |
| 143 | echo '<div id="plugin-information-scrollable">'; |
| 144 | echo "<div id='{$_tab}-title' class='{$_with_banner}'><div class='vignette'></div><h2>{$api->name}</h2></div>"; |
| 145 | echo "<div id='{$_tab}-tabs' class='{$_with_banner}'>\n"; |
| 146 | |
| 147 | foreach ( (array) $api->sections as $section_name => $content ) { |
| 148 | if ( 'reviews' === $section_name && ( empty( $api->ratings ) || 0 === array_sum( (array) $api->ratings ) ) ) { |
| 149 | continue; |
| 150 | } |
| 151 | |
| 152 | if ( isset( $plugins_section_titles[ $section_name ] ) ) { |
| 153 | $title = $plugins_section_titles[ $section_name ]; |
| 154 | } else { |
| 155 | $title = ucwords( str_replace( '_', ' ', $section_name ) ); |
| 156 | } |
| 157 | |
| 158 | $class = ( $section_name === $section ) ? ' class="current"' : ''; |
| 159 | $href = add_query_arg( array( 'tab' => $tab, 'section' => $section_name ) ); |
| 160 | $href = esc_url( $href ); |
| 161 | $san_section = esc_attr( $section_name ); |
| 162 | echo "\t<a name='$san_section' href='$href' $class>$title</a>\n"; |
| 163 | } |
| 164 | |
| 165 | echo "</div>\n"; |
| 166 | |
| 167 | ?> |
| 168 | <div id="<?php echo $_tab; ?>-content" class='<?php echo $_with_banner; ?>'> |
| 169 | <div class="fyi"> |
| 170 | <?php if ( isset( $api->plans ) ) : ?> |
| 171 | <div class="plugin-information-pricing"> |
| 172 | <?php foreach ($api->plans as $plan) : ?> |
| 173 | <h3 data-plan="<?php echo $plan->id ?>"><?php printf( __fs( 'x-plan' ), $plan->title ) ?></h3> |
| 174 | <ul> |
| 175 | <?php $billing_cycle = 'annual' ?> |
| 176 | <?php if ( 1 === count( $plan->pricing ) && 1 == $plan->pricing[0]->licenses ) : ?> |
| 177 | <?php $pricing = $plan->pricing[0] ?> |
| 178 | <li><label><?php _efs( 'price' ) ?>: $<?php |
| 179 | if ( isset( $pricing->annual_price ) ) { |
| 180 | echo $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' ); |
| 181 | $billing_cycle = 'annual'; |
| 182 | } else if ( isset( $pricing->monthly_price ) ) { |
| 183 | echo $pricing->monthly_price . ' / mo'; |
| 184 | $billing_cycle = 'monthly'; |
| 185 | } else if ( isset( $pricing->lifetime_price ) ) { |
| 186 | echo $pricing->lifetime_price; |
| 187 | $billing_cycle = 'lifetime'; |
| 188 | } |
| 189 | ?></label></li> |
| 190 | <?php else : ?> |
| 191 | <?php $first = true; |
| 192 | foreach ( $plan->pricing as $pricing ) : ?> |
| 193 | <li><label><input name="pricing-<?php echo $plan->id ?>" type="radio" |
| 194 | value="<?php echo $pricing->id ?>"<?php checked( $first, true ) ?>><?php |
| 195 | switch ( $pricing->licenses ) { |
| 196 | case '1': |
| 197 | _efs( 'license-single-site' ); |
| 198 | break; |
| 199 | case null: |
| 200 | _efs( 'license-unlimited' ); |
| 201 | break; |
| 202 | default: |
| 203 | printf( __fs( 'license-x-sites' ), $pricing->licenses ); |
| 204 | break; |
| 205 | } |
| 206 | ?> - $<?php |
| 207 | if ( isset( $pricing->annual_price ) ) { |
| 208 | echo $pricing->annual_price . ( $plan->is_block_features ? ' / year' : '' ); |
| 209 | $billing_cycle = 'annual'; |
| 210 | } else if ( isset( $pricing->monthly_price ) ) { |
| 211 | echo $pricing->monthly_price . ' / mo'; |
| 212 | $billing_cycle = 'monthly'; |
| 213 | } else if ( isset( $pricing->lifetime_price ) ) { |
| 214 | echo $pricing->lifetime_price; |
| 215 | $billing_cycle = 'lifetime'; |
| 216 | } |
| 217 | ?></label></li> |
| 218 | <?php $first = false; endforeach ?> |
| 219 | <?php endif ?> |
| 220 | </ul> |
| 221 | <?php echo ' <a class="button button-primary right" href="' . esc_url( add_query_arg( array( |
| 222 | 'plugin_id' => $plan->plugin_id, |
| 223 | 'plan_id' => $plan->id, |
| 224 | 'pricing_id' => $plan->pricing[0]->id, |
| 225 | 'billing_cycle' => $billing_cycle, |
| 226 | ), $api->checkout_link ) ) . '" target="_parent">' . __fs( 'purchase' ) . '</a>' ?> |
| 227 | </div> |
| 228 | <?php endforeach ?> |
| 229 | <?php wp_enqueue_script( 'jquery' ); ?> |
| 230 | <script type="text/javascript"> |
| 231 | (function ($) { |
| 232 | $('.plugin-information-pricing input[type=radio]').click(function () { |
| 233 | var checkout_url = '<?php echo esc_url_raw(add_query_arg(array( |
| 234 | 'plugin_id' => $plan->plugin_id, |
| 235 | 'billing_cycle' => $billing_cycle, |
| 236 | ), $api->checkout_link)) ?>&plan_id=' + |
| 237 | $(this).parents('.plugin-information-pricing').find('h3').attr('data-plan') + |
| 238 | '&pricing_id=' + $(this).val(); |
| 239 | |
| 240 | $('.plugin-information-pricing .button, #plugin-information-footer .button').attr('href', checkout_url); |
| 241 | }); |
| 242 | })(jQuery); |
| 243 | </script> |
| 244 | <?php endif ?> |
| 245 | <div> |
| 246 | <h3><?php _efs( 'details' ) ?></h3> |
| 247 | <ul> |
| 248 | <?php if ( ! empty( $api->version ) ) { ?> |
| 249 | <li><strong><?php _e( 'Version:' ); ?></strong> <?php echo $api->version; ?></li> |
| 250 | <?php } |
| 251 | if ( ! empty( $api->author ) ) { ?> |
| 252 | <li> |
| 253 | <strong><?php _e( 'Author:' ); ?></strong> <?php echo links_add_target( $api->author, '_blank' ); ?> |
| 254 | </li> |
| 255 | <?php } |
| 256 | if ( ! empty( $api->last_updated ) ) { ?> |
| 257 | <li><strong><?php _e( 'Last Updated:' ); ?></strong> <span |
| 258 | title="<?php echo $api->last_updated; ?>"> |
| 259 | <?php printf( __( '%s ago' ), human_time_diff( strtotime( $api->last_updated ) ) ); ?> |
| 260 | </span></li> |
| 261 | <?php } |
| 262 | if ( ! empty( $api->requires ) ) { ?> |
| 263 | <li> |
| 264 | <strong><?php _e( 'Requires WordPress Version:' ); ?></strong> <?php printf( __( '%s or higher' ), $api->requires ); ?> |
| 265 | </li> |
| 266 | <?php } |
| 267 | if ( ! empty( $api->tested ) ) { ?> |
| 268 | <li><strong><?php _e( 'Compatible up to:' ); ?></strong> <?php echo $api->tested; ?></li> |
| 269 | <?php } |
| 270 | if ( ! empty( $api->downloaded ) ) { ?> |
| 271 | <li> |
| 272 | <strong><?php _e( 'Downloaded:' ); ?></strong> <?php printf( _n( '%s time', '%s times', $api->downloaded ), number_format_i18n( $api->downloaded ) ); ?> |
| 273 | </li> |
| 274 | <?php } |
| 275 | if ( ! empty( $api->slug ) && empty( $api->external ) ) { ?> |
| 276 | <li><a target="_blank" |
| 277 | href="https://wordpress.org/plugins/<?php echo $api->slug; ?>/"><?php _e( 'WordPress.org Plugin Page »' ); ?></a> |
| 278 | </li> |
| 279 | <?php } |
| 280 | if ( ! empty( $api->homepage ) ) { ?> |
| 281 | <li><a target="_blank" |
| 282 | href="<?php echo esc_url( $api->homepage ); ?>"><?php _e( 'Plugin Homepage »' ); ?></a> |
| 283 | </li> |
| 284 | <?php } |
| 285 | if ( ! empty( $api->donate_link ) && empty( $api->contributors ) ) { ?> |
| 286 | <li><a target="_blank" |
| 287 | href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a> |
| 288 | </li> |
| 289 | <?php } ?> |
| 290 | </ul> |
| 291 | </div> |
| 292 | <?php if ( ! empty( $api->rating ) ) { ?> |
| 293 | <h3><?php _e( 'Average Rating' ); ?></h3> |
| 294 | <?php wp_star_rating( array( |
| 295 | 'rating' => $api->rating, |
| 296 | 'type' => 'percent', |
| 297 | 'number' => $api->num_ratings |
| 298 | ) ); ?> |
| 299 | <small><?php printf( _n( '(based on %s rating)', '(based on %s ratings)', $api->num_ratings ), number_format_i18n( $api->num_ratings ) ); ?></small> |
| 300 | <?php |
| 301 | } |
| 302 | |
| 303 | if ( ! empty( $api->ratings ) && array_sum( (array) $api->ratings ) > 0 ) { |
| 304 | foreach ( $api->ratings as $key => $ratecount ) { |
| 305 | // Avoid div-by-zero. |
| 306 | $_rating = $api->num_ratings ? ( $ratecount / $api->num_ratings ) : 0; |
| 307 | ?> |
| 308 | <div class="counter-container"> |
| 309 | <span class="counter-label"><a |
| 310 | href="https://wordpress.org/support/view/plugin-reviews/<?php echo $api->slug; ?>?filter=<?php echo $key; ?>" |
| 311 | target="_blank" |
| 312 | title="<?php echo esc_attr( sprintf( _n( 'Click to see reviews that provided a rating of %d star', 'Click to see reviews that provided a rating of %d stars', $key ), $key ) ); ?>"><?php printf( _n( '%d star', '%d stars', $key ), $key ); ?></a></span> |
| 313 | <span class="counter-back"> |
| 314 | <span class="counter-bar" style="width: <?php echo 92 * $_rating; ?>px;"></span> |
| 315 | </span> |
| 316 | <span class="counter-count"><?php echo number_format_i18n( $ratecount ); ?></span> |
| 317 | </div> |
| 318 | <?php |
| 319 | } |
| 320 | } |
| 321 | if ( ! empty( $api->contributors ) ) { |
| 322 | ?> |
| 323 | <h3><?php _e( 'Contributors' ); ?></h3> |
| 324 | <ul class="contributors"> |
| 325 | <?php |
| 326 | foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) { |
| 327 | if ( empty( $contrib_username ) && empty( $contrib_profile ) ) { |
| 328 | continue; |
| 329 | } |
| 330 | if ( empty( $contrib_username ) ) { |
| 331 | $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile ); |
| 332 | } |
| 333 | $contrib_username = sanitize_user( $contrib_username ); |
| 334 | if ( empty( $contrib_profile ) ) { |
| 335 | echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' />{$contrib_username}</li>"; |
| 336 | } else { |
| 337 | echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&s=36' width='18' height='18' />{$contrib_username}</a></li>"; |
| 338 | } |
| 339 | } |
| 340 | ?> |
| 341 | </ul> |
| 342 | <?php if ( ! empty( $api->donate_link ) ) { ?> |
| 343 | <a target="_blank" |
| 344 | href="<?php echo esc_url( $api->donate_link ); ?>"><?php _e( 'Donate to this plugin »' ); ?></a> |
| 345 | <?php } ?> |
| 346 | <?php } ?> |
| 347 | </div> |
| 348 | <div id="section-holder" class="wrap"> |
| 349 | <?php |
| 350 | if ( ! empty( $api->tested ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->tested ) ), $api->tested, '>' ) ) { |
| 351 | echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been tested with your current version of WordPress.' ) . '</p></div>'; |
| 352 | } else if ( ! empty( $api->requires ) && version_compare( substr( $GLOBALS['wp_version'], 0, strlen( $api->requires ) ), $api->requires, '<' ) ) { |
| 353 | echo '<div class="notice notice-warning"><p>' . '<strong>' . __( 'Warning:' ) . '</strong> ' . __( 'This plugin has not been marked as compatible with your version of WordPress.' ) . '</p></div>'; |
| 354 | } |
| 355 | |
| 356 | foreach ( (array) $api->sections as $section_name => $content ) { |
| 357 | $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); |
| 358 | $content = links_add_target( $content, '_blank' ); |
| 359 | |
| 360 | $san_section = esc_attr( $section_name ); |
| 361 | |
| 362 | $display = ( $section_name === $section ) ? 'block' : 'none'; |
| 363 | |
| 364 | echo "\t<div id='section-{$san_section}' class='section' style='display: {$display};'>\n"; |
| 365 | echo $content; |
| 366 | echo "\t</div>\n"; |
| 367 | } |
| 368 | echo "</div>\n"; |
| 369 | echo "</div>\n"; |
| 370 | echo "</div>\n"; // #plugin-information-scrollable |
| 371 | echo "<div id='$tab-footer'>\n"; |
| 372 | if ( ( current_user_can( 'install_plugins' ) || current_user_can( 'update_plugins' ) ) ) { |
| 373 | |
| 374 | if ( ! empty( $api->checkout_link ) && isset( $api->plans ) && 0 < is_array( $api->plans ) ) { |
| 375 | echo ' <a class="button button-primary right" href="' . esc_url( add_query_arg( array( |
| 376 | 'plugin_id' => $plan->plugin_id, |
| 377 | 'plan_id' => $plan->id, |
| 378 | 'pricing_id' => $plan->pricing[0]->id, |
| 379 | 'billing_cycle' => $billing_cycle, |
| 380 | ), $api->checkout_link ) ) . '" target="_parent">' . __fs( 'purchase' ) . '</a>'; |
| 381 | |
| 382 | // @todo Add Cart concept. |
| 383 | // echo ' <a class="button right" href="' . $status['url'] . '" target="_parent">' . __( 'Add to Cart' ) . '</a>'; |
| 384 | |
| 385 | } else if ( ! empty( $api->download_link ) ) { |
| 386 | $status = install_plugin_install_status( $api ); |
| 387 | switch ( $status['status'] ) { |
| 388 | case 'install': |
| 389 | if ( $status['url'] ) { |
| 390 | echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Now' ) . '</a>'; |
| 391 | } |
| 392 | break; |
| 393 | case 'update_available': |
| 394 | if ( $status['url'] ) { |
| 395 | echo '<a class="button button-primary right" href="' . $status['url'] . '" target="_parent">' . __( 'Install Update Now' ) . '</a>'; |
| 396 | } |
| 397 | break; |
| 398 | case 'newer_installed': |
| 399 | echo '<a class="button button-primary right disabled">' . sprintf( __( 'Newer Version (%s) Installed' ), $status['version'] ) . '</a>'; |
| 400 | break; |
| 401 | case 'latest_installed': |
| 402 | echo '<a class="button button-primary right disabled">' . __( 'Latest Version Installed' ) . '</a>'; |
| 403 | break; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | echo "</div>\n"; |
| 408 | |
| 409 | iframe_footer(); |
| 410 | exit; |
| 411 | } |
| 412 |