| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Freemius |
| 4 |
* @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 |
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 6 |
* @since 1.0.6 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
class FS_Plan_Manager { |
| 14 |
/** |
| 15 |
* @var FS_Plan_Manager |
| 16 |
*/ |
| 17 |
private static $_instance; |
| 18 |
|
| 19 |
/** |
| 20 |
* @return FS_Plan_Manager |
| 21 |
*/ |
| 22 |
static function instance() { |
| 23 |
if ( ! isset( self::$_instance ) ) { |
| 24 |
self::$_instance = new FS_Plan_Manager(); |
| 25 |
} |
| 26 |
|
| 27 |
return self::$_instance; |
| 28 |
} |
| 29 |
|
| 30 |
private function __construct() { |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* @param FS_Plugin_License[] $licenses |
| 35 |
* |
| 36 |
* @return bool |
| 37 |
*/ |
| 38 |
function has_premium_license( $licenses ) { |
| 39 |
if ( is_array( $licenses ) ) { |
| 40 |
/** |
| 41 |
* @var FS_Plugin_License[] $licenses |
| 42 |
*/ |
| 43 |
foreach ( $licenses as $license ) { |
| 44 |
if ( ! $license->is_utilized() && $license->is_features_enabled() ) { |
| 45 |
return true; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Check if plugin has any paid plans. |
| 55 |
* |
| 56 |
* @author Vova Feldman (@svovaf) |
| 57 |
* @since 1.0.7 |
| 58 |
* |
| 59 |
* @param FS_Plugin_Plan[] $plans |
| 60 |
* |
| 61 |
* @return bool |
| 62 |
*/ |
| 63 |
function has_paid_plan( $plans ) { |
| 64 |
if ( ! is_array( $plans ) || 0 === count( $plans ) ) { |
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* @var FS_Plugin_Plan[] $plans |
| 70 |
*/ |
| 71 |
for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { |
| 72 |
if ( ! $plans[ $i ]->is_free() ) { |
| 73 |
return true; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
return false; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Check if plugin has any free plan, or is it premium only. |
| 82 |
* |
| 83 |
* Note: If no plans configured, assume plugin is free. |
| 84 |
* |
| 85 |
* @author Vova Feldman (@svovaf) |
| 86 |
* @since 1.0.7 |
| 87 |
* |
| 88 |
* @param FS_Plugin_Plan[] $plans |
| 89 |
* |
| 90 |
* @return bool |
| 91 |
*/ |
| 92 |
function has_free_plan( $plans ) { |
| 93 |
if ( ! is_array( $plans ) || 0 === count( $plans ) ) { |
| 94 |
return true; |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* @var FS_Plugin_Plan[] $plans |
| 99 |
*/ |
| 100 |
for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { |
| 101 |
if ( $plans[ $i ]->is_free() ) { |
| 102 |
return true; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
return false; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Find all plans that have trial. |
| 111 |
* |
| 112 |
* @author Vova Feldman (@svovaf) |
| 113 |
* @since 1.0.9 |
| 114 |
* |
| 115 |
* @param FS_Plugin_Plan[] $plans |
| 116 |
* |
| 117 |
* @return FS_Plugin_Plan[] |
| 118 |
*/ |
| 119 |
function get_trial_plans( $plans ) { |
| 120 |
$trial_plans = array(); |
| 121 |
|
| 122 |
if ( is_array( $plans ) && 0 < count( $plans ) ) { |
| 123 |
/** |
| 124 |
* @var FS_Plugin_Plan[] $plans |
| 125 |
*/ |
| 126 |
for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { |
| 127 |
if ( $plans[ $i ]->has_trial() ) { |
| 128 |
$trial_plans[] = $plans[ $i ]; |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
return $trial_plans; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Check if plugin has any trial plan. |
| 138 |
* |
| 139 |
* @author Vova Feldman (@svovaf) |
| 140 |
* @since 1.0.9 |
| 141 |
* |
| 142 |
* @param FS_Plugin_Plan[] $plans |
| 143 |
* |
| 144 |
* @return bool |
| 145 |
*/ |
| 146 |
function has_trial_plan( $plans ) { |
| 147 |
if ( ! is_array( $plans ) || 0 === count( $plans ) ) { |
| 148 |
return true; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* @var FS_Plugin_Plan[] $plans |
| 153 |
*/ |
| 154 |
for ( $i = 0, $len = count( $plans ); $i < $len; $i ++ ) { |
| 155 |
if ( $plans[ $i ]->has_trial() ) { |
| 156 |
return true; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
return false; |
| 161 |
} |
| 162 |
} |