Assist
1 year ago
Draft
1 year ago
HelpCenter
1 year ago
Launch
1 year ago
Library
1 year ago
Shared
1 year ago
AdminPageRouter.php
1 year ago
Affiliate.php
2 years ago
ApiRouter.php
2 years ago
Config.php
1 year ago
Http.php
1 year ago
Insights.php
1 year ago
PartnerData.php
1 year ago
SiteSettings.php
1 year ago
Config.php
156 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The App details file |
| 4 | */ |
| 5 | |
| 6 | namespace Extendify; |
| 7 | |
| 8 | defined('ABSPATH') || die('No direct access.'); |
| 9 | |
| 10 | use Extendify\Shared\Services\Sanitizer; |
| 11 | |
| 12 | /** |
| 13 | * Controller for handling various app data |
| 14 | */ |
| 15 | class Config |
| 16 | { |
| 17 | |
| 18 | /** |
| 19 | * Plugin slug |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | public static $slug = 'extendify'; |
| 24 | |
| 25 | /** |
| 26 | * The JS/CSS asset manifest (with hashes) |
| 27 | * |
| 28 | * @var array |
| 29 | */ |
| 30 | public static $assetManifest = []; |
| 31 | |
| 32 | /** |
| 33 | * Plugin version |
| 34 | * |
| 35 | * @var string |
| 36 | */ |
| 37 | public static $version = ''; |
| 38 | |
| 39 | /** |
| 40 | * Plugin API REST version |
| 41 | * |
| 42 | * @var string |
| 43 | */ |
| 44 | public static $apiVersion = 'v1'; |
| 45 | |
| 46 | /** |
| 47 | * Partner Id |
| 48 | * |
| 49 | * @var string |
| 50 | */ |
| 51 | public static $partnerId = 'no-partner'; |
| 52 | |
| 53 | /** |
| 54 | * Whether there is a partner |
| 55 | * |
| 56 | * @var boolean |
| 57 | */ |
| 58 | public static $hasPartner = false; |
| 59 | |
| 60 | /** |
| 61 | * Whether to load Launch |
| 62 | * |
| 63 | * @var boolean |
| 64 | */ |
| 65 | public static $showLaunch = false; |
| 66 | |
| 67 | /** |
| 68 | * Plugin environment |
| 69 | * |
| 70 | * @var string |
| 71 | */ |
| 72 | public static $environment = ''; |
| 73 | |
| 74 | /** |
| 75 | * Host plugin |
| 76 | * |
| 77 | * @var string |
| 78 | */ |
| 79 | public static $requiredCapability = EXTENDIFY_REQUIRED_CAPABILITY; |
| 80 | |
| 81 | /** |
| 82 | * Plugin config |
| 83 | * |
| 84 | * @var array |
| 85 | */ |
| 86 | public static $config = []; |
| 87 | |
| 88 | /** |
| 89 | * Whether Launch was finished |
| 90 | * |
| 91 | * @var boolean |
| 92 | */ |
| 93 | public static $launchCompleted = false; |
| 94 | |
| 95 | /** |
| 96 | * Process the readme file to get version and name |
| 97 | * |
| 98 | * @return void |
| 99 | */ |
| 100 | public function __construct() |
| 101 | { |
| 102 | // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 103 | $readme = file_get_contents(EXTENDIFY_PATH . 'readme.txt'); |
| 104 | |
| 105 | preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches); |
| 106 | self::$version = $matches[1]; |
| 107 | |
| 108 | self::$assetManifest = wp_json_file_decode(EXTENDIFY_PATH . 'public/build/manifest.json', ['associative' => true]); |
| 109 | |
| 110 | if (!get_option('extendify_first_installed_version')) { |
| 111 | update_option('extendify_first_installed_version', Sanitizer::sanitizeText(self::$version)); |
| 112 | } |
| 113 | |
| 114 | // Here for backwards compatibility. |
| 115 | if (isset($GLOBALS['extendify_sdk_partner']) && $GLOBALS['extendify_sdk_partner']) { |
| 116 | self::$partnerId = $GLOBALS['extendify_sdk_partner']; |
| 117 | } |
| 118 | |
| 119 | // Always use the partner ID if set as a constant. |
| 120 | if (defined('EXTENDIFY_PARTNER_ID')) { |
| 121 | self::$partnerId = constant('EXTENDIFY_PARTNER_ID'); |
| 122 | } |
| 123 | |
| 124 | if (self::$partnerId && self::$partnerId !== 'no-partner') { |
| 125 | self::$hasPartner = true; |
| 126 | } |
| 127 | |
| 128 | // An easy way to check if we are in dev mode is to look for a dev specific file. |
| 129 | $isDev = is_readable(EXTENDIFY_PATH . '.devbuild'); |
| 130 | |
| 131 | self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION'; |
| 132 | self::$launchCompleted = (bool) get_option('extendify_onboarding_completed', false); |
| 133 | self::$showLaunch = $this->showLaunch(); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Conditionally load Extendify Launch. |
| 138 | * |
| 139 | * @return boolean |
| 140 | */ |
| 141 | private function showLaunch() |
| 142 | { |
| 143 | // Always show it for dev mode. |
| 144 | if (self::$environment === 'DEVELOPMENT') { |
| 145 | return true; |
| 146 | } |
| 147 | |
| 148 | // Currently we require a flag to be set. |
| 149 | if (!defined('EXTENDIFY_SHOW_ONBOARDING')) { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | return constant('EXTENDIFY_SHOW_ONBOARDING') === true; |
| 154 | } |
| 155 | } |
| 156 |