Skip to content

Commit

Permalink
Merge pull request #41 from Freemius/develop
Browse files Browse the repository at this point in the history
Added anonymous mode and featured plugin icon filter.
  • Loading branch information
vovafeldman committed Apr 5, 2016
2 parents b77dc8c + 50cec91 commit c8bc960
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 52 deletions.
14 changes: 13 additions & 1 deletion includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class Freemius extends Freemius_Abstract {
*/
private $_enable_anonymous;

/**
* @since 1.7.5
* @var bool Hints the SDK if plugin should run in anonymous mode (only adds feedback form).
*/
private $_anonymous_mode;

/**
* @since 1.0.8
* @var bool Hints the SDK if the plugin has any paid plans.
Expand Down Expand Up @@ -1724,6 +1730,11 @@ function dynamic_init( array $plugin_info ) {
'failed_connect_api_first',
'failed_connect_api',
) );

if ( $this->_anonymous_mode ) {
// Simulate anonymous mode.
$this->_is_anonymous = true;
}
}
}

Expand Down Expand Up @@ -1952,6 +1963,7 @@ private function parse_settings( &$plugin_info ) {
$this->_has_paid_plans = $this->get_bool_option( $plugin_info, 'has_paid_plans', true );
$this->_is_org_compliant = $this->get_bool_option( $plugin_info, 'is_org_compliant', true );
$this->_enable_anonymous = $this->get_bool_option( $plugin_info, 'enable_anonymous', true );
$this->_anonymous_mode = $this->get_bool_option( $plugin_info, 'anonymous_mode', false );
$this->_permissions = $this->get_option( $plugin_info, 'permissions', array() );
}

Expand Down Expand Up @@ -3056,7 +3068,7 @@ function _activate_plugin_event_hook() {
$this->_storage->is_plugin_new_install = empty( $this->_storage->plugin_last_version );
}

if ( $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
if ( ! $this->_anonymous_mode && $this->has_api_connectivity( WP_FS__DEV_MODE ) ) {
// Store hint that the plugin was just activated to enable auto-redirection to settings.
add_option( "fs_{$this->_slug}_activated", true );
}
Expand Down
5 changes: 3 additions & 2 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
exit;
}

$this_sdk_version = '1.1.7.4';
$this_sdk_version = '1.1.7.5';

#region SDK Selection Logic --------------------------------------------------------------------

Expand Down Expand Up @@ -207,12 +207,13 @@
* fs_uninstall_confirmation_message_{plugin_slug}
* fs_pending_activation_message_{plugin_slug}
* fs_is_submenu_visible_{plugin_slug}
* fs_plugin_icon_{plugin_slug}
*
* --------------------------------------------------------
*
* Freemius actions collection:
*
* fs_after_license_loaded_{plugin_slug}
* fs_after_license_loaded_{plugin_slug}
* fs_after_license_change_{plugin_slug}
* fs_after_plans_sync_{plugin_slug}
*
Expand Down
108 changes: 59 additions & 49 deletions templates/plugin-icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,80 @@
$slug = $VARS['slug'];
$fs = freemius( $slug );

global $fs_active_plugins;
/**
* @since 1.7.5
*/
$local_path = $fs->apply_filters( 'plugin_icon', false );

if ( is_string( $local_path ) ) {
$icons = array( $local_path );
} else {
global $fs_active_plugins;

$img_dir = WP_FS__DIR_IMG;
$img_dir = WP_FS__DIR_IMG;

if ( 1 < count( $fs_active_plugins->plugins ) ) {
foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
if ( $data->plugin_path == $fs->get_plugin_basename() ) {
$img_dir = WP_PLUGIN_DIR . '/' . $sdk_path . '/assets/img';
break;
if ( 1 < count( $fs_active_plugins->plugins ) ) {
foreach ( $fs_active_plugins->plugins as $sdk_path => &$data ) {
if ( $data->plugin_path == $fs->get_plugin_basename() ) {
$img_dir = WP_PLUGIN_DIR . '/' . $sdk_path . '/assets/img';
break;
}
}
}
}

$icons = glob( fs_normalize_path( $img_dir . '/icon.*' ) );
if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
$icon_found = false;
$local_path = fs_normalize_path( $img_dir . '/icon.png' );
$have_write_permissions = is_writable( fs_normalize_path( $img_dir ) );
$icons = glob( fs_normalize_path( $img_dir . '/icon.*' ) );
if ( ! is_array( $icons ) || 0 === count( $icons ) ) {
$icon_found = false;
$local_path = fs_normalize_path( $img_dir . '/icon.png' );
$have_write_permissions = is_writable( fs_normalize_path( $img_dir ) );

if ( WP_FS__IS_LOCALHOST && $fs->is_org_repo_compliant() && $have_write_permissions ) {
/**
* IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
*
* This code will only be executed once during the testing
* of the plugin in a local environment. The plugin icon file WILL
* already exist in the assets folder when the plugin is deployed to
* the repository.
*/
$suffixes = array(
'-128x128.png',
'-128x128.jpg',
'-256x256.png',
'-256x256.jpg',
'.svg',
);
if ( WP_FS__IS_LOCALHOST && $fs->is_org_repo_compliant() && $have_write_permissions ) {
/**
* IMPORTANT: THIS CODE WILL NEVER RUN AFTER THE PLUGIN IS IN THE REPO.
*
* This code will only be executed once during the testing
* of the plugin in a local environment. The plugin icon file WILL
* already exist in the assets folder when the plugin is deployed to
* the repository.
*/
$suffixes = array(
'-128x128.png',
'-128x128.jpg',
'-256x256.png',
'-256x256.jpg',
'.svg',
);

$base_url = 'https://plugins.svn.wordpress.org/' . $slug . '/assets/icon';
$base_url = 'https://plugins.svn.wordpress.org/' . $slug . '/assets/icon';

foreach ( $suffixes as $s ) {
$headers = get_headers( $base_url . $s );
if ( strpos( $headers[0], '200' ) ) {
$local_path = fs_normalize_path( $img_dir . '/icon.' . substr( $s, strpos( $s, '.' ) + 1 ) );
fs_download_image( $base_url . $s, $local_path );
$icon_found = true;
break;
foreach ( $suffixes as $s ) {
$headers = get_headers( $base_url . $s );
if ( strpos( $headers[0], '200' ) ) {
$local_path = fs_normalize_path( $img_dir . '/icon.' . substr( $s, strpos( $s, '.' ) + 1 ) );
fs_download_image( $base_url . $s, $local_path );
$icon_found = true;
break;
}
}
}
}

if ( ! $icon_found ) {
// No icons found, fallback to default icon.
if ( $have_write_permissions ) {
// If have write permissions, copy default icon.
copy( fs_normalize_path( $img_dir . '/plugin-icon.png' ), $local_path );
} else {
// If doesn't have write permissions, use default icon path.
$local_path = fs_normalize_path( $img_dir . '/plugin-icon.png' );
if ( ! $icon_found ) {
// No icons found, fallback to default icon.
if ( $have_write_permissions ) {
// If have write permissions, copy default icon.
copy( fs_normalize_path( $img_dir . '/plugin-icon.png' ), $local_path );
} else {
// If doesn't have write permissions, use default icon path.
$local_path = fs_normalize_path( $img_dir . '/plugin-icon.png' );
}
}
}

$icons = array( $local_path );
$icons = array( $local_path );
}
}

$relative_url = fs_img_url( substr( $icons[0], strlen( fs_normalize_path( $img_dir ) ) ), $img_dir );
$icon_dir = dirname( $icons[0] );
$relative_url = fs_img_url( substr( $icons[0], strlen( $icon_dir ) ), $icon_dir );
?>
<div class="fs-plugin-icon">
<img src="<?php echo $relative_url ?>"/>
Expand Down

0 comments on commit c8bc960

Please sign in to comment.