| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentMail\Includes\Core; |
| 4 |
|
| 5 |
use ArrayAccess; |
| 6 |
use FluentMail\Includes\View\View; |
| 7 |
use FluentMail\Includes\Core\CoreTrait; |
| 8 |
use FluentMail\Includes\Core\Container; |
| 9 |
use FluentMail\Includes\Request\Request; |
| 10 |
use FluentMail\Includes\Response\Response; |
| 11 |
|
| 12 |
final class Application extends Container |
| 13 |
{ |
| 14 |
use CoreTrait; |
| 15 |
|
| 16 |
private $policyNamespace = 'FluentMail\App\Http\Policies'; |
| 17 |
|
| 18 |
private $handlerNamespace = 'FluentMail\App\Hooks\Handlers'; |
| 19 |
|
| 20 |
private $controllerNamespace = 'FluentMail\App\Http\Controllers'; |
| 21 |
|
| 22 |
public function __construct() |
| 23 |
{ |
| 24 |
$this->setApplicationInstance(); |
| 25 |
$this->registerPluginPathsAndUrls(); |
| 26 |
$this->registerFrameworkComponents(); |
| 27 |
$this->requireCommonFilesForRequest($this); |
| 28 |
|
| 29 |
load_plugin_textdomain('fluent-smtp', false, 'fluent-smtp/language/'); |
| 30 |
|
| 31 |
/* |
| 32 |
* We are adding fluent-smtp/fluent-smtp.php at the top to load the wp_mail at the very first |
| 33 |
* There has no other way to load a specific plugin at the first. |
| 34 |
*/ |
| 35 |
add_filter('pre_update_option_active_plugins', function ($plugins) { |
| 36 |
$index = array_search('fluent-smtp/fluent-smtp.php', $plugins); |
| 37 |
if ($index !== false) { |
| 38 |
if ($index === 0) { |
| 39 |
return $plugins; |
| 40 |
} |
| 41 |
unset($plugins[$index]); |
| 42 |
array_unshift($plugins, 'fluent-smtp/fluent-smtp.php'); |
| 43 |
} |
| 44 |
return $plugins; |
| 45 |
}); |
| 46 |
|
| 47 |
add_action('admin_notices', function () { |
| 48 |
if (!fluentMailCurrentUserCanManage()) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
$settings = get_option('fluentmail-settings'); |
| 53 |
|
| 54 |
if (!$settings || empty($settings['use_encrypt']) || empty($settings['test'])) { |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
$testData = fluentMailEncryptDecrypt($settings['test'], 'd'); |
| 59 |
|
| 60 |
if ($testData == 'test') { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
?> |
| 65 |
<div class="notice notice-warning fluentsmtp_urgent is-dismissible"> |
| 66 |
<p> |
| 67 |
<?php esc_html_e('FluentSMTP Plugin may not work properly. Looks like your Authentication unique keys and salts are changed.', 'fluent-smtp'); ?> <a href="<?php echo esc_url(admin_url('options-general.php?page=fluent-mail#/connections')); ?>"><b><?php esc_html_e('Reconfigure SMTP Settings', 'fluent-smtp'); ?></b></a> |
| 68 |
</p> |
| 69 |
</div> |
| 70 |
<?php |
| 71 |
}); |
| 72 |
} |
| 73 |
|
| 74 |
private function setApplicationInstance() |
| 75 |
{ |
| 76 |
static::setInstance($this); |
| 77 |
$this->instance('app', $this); |
| 78 |
$this->instance(__CLASS__, $this); |
| 79 |
} |
| 80 |
private function registerPluginPathsAndUrls() |
| 81 |
{ |
| 82 |
// Paths |
| 83 |
$this['path'] = FLUENTMAIL_PLUGIN_PATH; |
| 84 |
$this['path.app'] = FLUENTMAIL_PLUGIN_PATH . 'app/'; |
| 85 |
$this['path.hooks'] = FLUENTMAIL_PLUGIN_PATH . 'app/Hooks/'; |
| 86 |
$this['path.models'] = FLUENTMAIL_PLUGIN_PATH . 'app/models/'; |
| 87 |
$this['path.includes'] = FLUENTMAIL_PLUGIN_PATH . 'includes/'; |
| 88 |
$this['path.controllers'] = FLUENTMAIL_PLUGIN_PATH . 'app/Http/controllers/'; |
| 89 |
$this['path.views'] = FLUENTMAIL_PLUGIN_PATH . 'app/views/'; |
| 90 |
$this['path.admin.css'] = FLUENTMAIL_PLUGIN_PATH . 'assets/admin/css/'; |
| 91 |
$this['path.admin.js'] = FLUENTMAIL_PLUGIN_PATH . 'assets/admin/js/'; |
| 92 |
$this['path.public.css'] = FLUENTMAIL_PLUGIN_PATH . 'assets/public/css/'; |
| 93 |
$this['path.public.js'] = FLUENTMAIL_PLUGIN_PATH . 'assets/public/js/'; |
| 94 |
$this['path.assets'] = FLUENTMAIL_PLUGIN_PATH . 'assets/'; |
| 95 |
|
| 96 |
// Urls |
| 97 |
$this['url'] = FLUENTMAIL_PLUGIN_URL; |
| 98 |
$this['url.app'] = FLUENTMAIL_PLUGIN_URL . 'app/'; |
| 99 |
$this['url.assets'] = FLUENTMAIL_PLUGIN_URL . 'assets/'; |
| 100 |
$this['url.public.css'] = FLUENTMAIL_PLUGIN_URL . 'assets/public/css/'; |
| 101 |
$this['url.admin.css'] = FLUENTMAIL_PLUGIN_URL . 'assets/admin/css/'; |
| 102 |
$this['url.public.js'] = FLUENTMAIL_PLUGIN_URL . 'assets/public/js/'; |
| 103 |
$this['url.admin.js'] = FLUENTMAIL_PLUGIN_URL . 'assets/admin/js/'; |
| 104 |
$this['url.assets.images'] = FLUENTMAIL_PLUGIN_URL . 'assets/images/'; |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
private function registerFrameworkComponents() |
| 109 |
{ |
| 110 |
$this->bind('FluentMail\Includes\View\View', function ($app) { |
| 111 |
return new View($app); |
| 112 |
}); |
| 113 |
|
| 114 |
$this->alias('FluentMail\Includes\View\View', 'view'); |
| 115 |
|
| 116 |
$this->singleton('FluentMail\Includes\Request\Request', function ($app) { |
| 117 |
return new Request($app, $_GET, $_POST, $_FILES); |
| 118 |
}); |
| 119 |
|
| 120 |
$this->alias('FluentMail\Includes\Request\Request', 'request'); |
| 121 |
|
| 122 |
$this->singleton('FluentMail\Includes\Response\Response', function ($app) { |
| 123 |
return new Response($app); |
| 124 |
}); |
| 125 |
|
| 126 |
$this->alias('FluentMail\Includes\Response\Response', 'response'); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Require all the common files that needs to be loaded on each request |
| 131 |
* |
| 132 |
* @param Application $app [$app is being used inside required files] |
| 133 |
* @return void |
| 134 |
*/ |
| 135 |
private function requireCommonFilesForRequest($app) |
| 136 |
{ |
| 137 |
// Require Application Bindings |
| 138 |
require_once($app['path.app'] . '/Bindings.php'); |
| 139 |
|
| 140 |
// Require Global Functions |
| 141 |
require_once($app['path.app'] . '/Functions/helpers.php'); |
| 142 |
|
| 143 |
// Require Action Hooks |
| 144 |
require_once($app['path.app'] . '/Hooks/actions.php'); |
| 145 |
|
| 146 |
// Require Filter Hooks |
| 147 |
require_once($app['path.app'] . '/Hooks/filters.php'); |
| 148 |
|
| 149 |
// Require Routes |
| 150 |
if (is_admin()) { |
| 151 |
require_once($app['path.app'] . '/Http/routes.php'); |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|