| 1 |
<?php |
| 2 |
/** |
| 3 |
* The App details file |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace Extendify\Library; |
| 7 |
|
| 8 |
use Extendify\Library\Plugin; |
| 9 |
|
| 10 |
/** |
| 11 |
* Controller for handling various app data |
| 12 |
*/ |
| 13 |
class App |
| 14 |
{ |
| 15 |
|
| 16 |
/** |
| 17 |
* Plugin name |
| 18 |
* |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
public static $name = ''; |
| 22 |
|
| 23 |
/** |
| 24 |
* Plugin slug |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
public static $slug = ''; |
| 29 |
|
| 30 |
/** |
| 31 |
* Plugin version |
| 32 |
* |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
public static $version = ''; |
| 36 |
|
| 37 |
/** |
| 38 |
* Plugin API REST version |
| 39 |
* |
| 40 |
* @var string |
| 41 |
*/ |
| 42 |
public static $apiVersion = 'v1'; |
| 43 |
|
| 44 |
/** |
| 45 |
* Plugin text domain |
| 46 |
* |
| 47 |
* @var string |
| 48 |
*/ |
| 49 |
public static $textDomain = ''; |
| 50 |
|
| 51 |
/** |
| 52 |
* Plugin environment |
| 53 |
* |
| 54 |
* @var string |
| 55 |
*/ |
| 56 |
public static $environment = ''; |
| 57 |
|
| 58 |
/** |
| 59 |
* The partner plugin/theme |
| 60 |
* |
| 61 |
* @var string |
| 62 |
*/ |
| 63 |
public static $sdkPartner = ''; |
| 64 |
|
| 65 |
/** |
| 66 |
* Host plugin |
| 67 |
* |
| 68 |
* @var string |
| 69 |
*/ |
| 70 |
public static $requiredCapability = 'upload_files'; |
| 71 |
|
| 72 |
/** |
| 73 |
* Plugin config |
| 74 |
* |
| 75 |
* @var array |
| 76 |
*/ |
| 77 |
public static $config = []; |
| 78 |
|
| 79 |
/** |
| 80 |
* Process the readme file to get version and name |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public function __construct() |
| 85 |
{ |
| 86 |
// Set the "partner" plugin/theme here with a fallback to support the previous plugin implementation. |
| 87 |
self::$sdkPartner = isset($GLOBALS['extendify_sdk_partner']) ? $GLOBALS['extendify_sdk_partner'] : ''; |
| 88 |
if (!self::$sdkPartner && isset($GLOBALS['extendifySdkSourcePlugin'])) { |
| 89 |
self::$sdkPartner = $GLOBALS['extendifySdkSourcePlugin']; |
| 90 |
} |
| 91 |
|
| 92 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 93 |
$readme = file_get_contents(dirname(__DIR__) . '/readme.txt'); |
| 94 |
|
| 95 |
preg_match('/=== (.+) ===/', $readme, $matches); |
| 96 |
self::$name = $matches[1]; |
| 97 |
self::$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', self::$name), '-')); |
| 98 |
|
| 99 |
preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches); |
| 100 |
self::$version = $matches[1]; |
| 101 |
|
| 102 |
// An easy way to check if we are in dev mode is to look for a dev specific file. |
| 103 |
$isDev = is_readable(EXTENDIFY_PATH . 'node_modules') || is_readable(EXTENDIFY_PATH . '.devbuild'); |
| 104 |
self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION'; |
| 105 |
|
| 106 |
self::$textDomain = Plugin::getPluginInfo('TextDomain', self::$slug); |
| 107 |
|
| 108 |
// Add the config. |
| 109 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 110 |
$config = file_get_contents(dirname(__DIR__) . '/config.json'); |
| 111 |
self::$config = json_decode($config, true); |
| 112 |
} |
| 113 |
} |
| 114 |
|