2014-05-07 17:52:13 +10:00
|
|
|
<?php namespace System;
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
use App;
|
|
|
|
use Lang;
|
|
|
|
use Event;
|
|
|
|
use Config;
|
|
|
|
use Backend;
|
2014-10-16 19:49:00 +11:00
|
|
|
use Request;
|
2014-07-30 17:19:29 +10:00
|
|
|
use DbDongle;
|
2014-05-14 23:24:20 +10:00
|
|
|
use BackendMenu;
|
|
|
|
use BackendAuth;
|
|
|
|
use Twig_Environment;
|
2014-06-28 21:12:02 +10:00
|
|
|
use Twig_Loader_String;
|
2014-05-14 23:24:20 +10:00
|
|
|
use System\Classes\ErrorHandler;
|
2014-07-16 18:28:15 +10:00
|
|
|
use System\Classes\MarkupManager;
|
2014-05-14 23:24:20 +10:00
|
|
|
use System\Classes\PluginManager;
|
|
|
|
use System\Classes\SettingsManager;
|
|
|
|
use System\Twig\Engine as TwigEngine;
|
|
|
|
use System\Twig\Loader as TwigLoader;
|
2014-06-26 17:32:12 +10:00
|
|
|
use System\Twig\Extension as TwigExtension;
|
2014-07-30 17:19:29 +10:00
|
|
|
use System\Models\EventLog;
|
2014-07-04 18:47:46 +10:00
|
|
|
use System\Models\MailSettings;
|
|
|
|
use System\Models\MailTemplate;
|
2014-05-14 23:24:20 +10:00
|
|
|
use Backend\Classes\WidgetManager;
|
2014-05-07 17:52:13 +10:00
|
|
|
use October\Rain\Support\ModuleServiceProvider;
|
|
|
|
|
|
|
|
class ServiceProvider extends ModuleServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Register the service provider.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function register()
|
|
|
|
{
|
2014-05-14 23:24:20 +10:00
|
|
|
/*
|
|
|
|
* Register self
|
|
|
|
*/
|
2014-05-07 17:52:13 +10:00
|
|
|
parent::register('system');
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/*
|
2014-05-17 18:08:01 +02:00
|
|
|
* Register core providers
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
|
|
|
App::register('October\Rain\Config\ConfigServiceProvider');
|
|
|
|
App::register('October\Rain\Translation\TranslationServiceProvider');
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define path constants
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
if (!defined('PATH_APP')) {
|
|
|
|
define('PATH_APP', app_path());
|
|
|
|
}
|
|
|
|
if (!defined('PATH_BASE')) {
|
|
|
|
define('PATH_BASE', base_path());
|
|
|
|
}
|
|
|
|
if (!defined('PATH_PUBLIC')) {
|
|
|
|
define('PATH_PUBLIC', public_path());
|
|
|
|
}
|
|
|
|
if (!defined('PATH_STORAGE')) {
|
|
|
|
define('PATH_STORAGE', storage_path());
|
|
|
|
}
|
|
|
|
if (!defined('PATH_PLUGINS')) {
|
|
|
|
define('PATH_PLUGINS', base_path() . Config::get('cms.pluginsDir', '/plugins'));
|
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register singletons
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
App::singleton('string', function () {
|
|
|
|
return new \October\Rain\Support\Str;
|
|
|
|
});
|
|
|
|
App::singleton('backend.helper', function () {
|
|
|
|
return new \Backend\Classes\BackendHelper;
|
|
|
|
});
|
|
|
|
App::singleton('backend.menu', function () {
|
|
|
|
return \Backend\Classes\NavigationManager::instance();
|
|
|
|
});
|
|
|
|
App::singleton('backend.auth', function () {
|
|
|
|
return \Backend\Classes\AuthManager::instance();
|
|
|
|
});
|
2014-05-14 23:24:20 +10:00
|
|
|
|
2014-10-09 17:46:23 +11:00
|
|
|
/*
|
|
|
|
* Check for CLI or system/updates route and disable any plugin initialization
|
|
|
|
* @todo This should be moved to middleware
|
|
|
|
*/
|
|
|
|
$requestPath = \October\Rain\Router\Helper::normalizeUrl(\Request::path());
|
|
|
|
$systemPath = \October\Rain\Router\Helper::normalizeUrl(Config::get('cms.backendUri') . '/system/updates');
|
2014-10-18 11:58:50 +02:00
|
|
|
if (stripos($requestPath, $systemPath) === 0) {
|
2014-10-16 19:49:00 +11:00
|
|
|
PluginManager::$noInit = true;
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|
2014-10-16 19:49:00 +11:00
|
|
|
|
|
|
|
$updateCommands = ['october:up', 'october:update'];
|
2014-10-18 11:58:50 +02:00
|
|
|
if (App::runningInConsole() && count(array_intersect($updateCommands, Request::server('argv'))) > 0) {
|
2014-10-09 17:46:23 +11:00
|
|
|
PluginManager::$noInit = true;
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|
2014-10-09 17:46:23 +11:00
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/*
|
|
|
|
* Register all plugins
|
|
|
|
*/
|
|
|
|
$pluginManager = PluginManager::instance();
|
|
|
|
$pluginManager->registerAll();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Error handling for uncaught Exceptions
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
App::error(function (\Exception $exception, $httpCode) {
|
2014-05-14 23:24:20 +10:00
|
|
|
$handler = new ErrorHandler;
|
2014-09-20 17:56:59 +10:00
|
|
|
return $handler->handleException($exception, $httpCode);
|
2014-05-14 23:24:20 +10:00
|
|
|
});
|
|
|
|
|
2014-07-30 17:19:29 +10:00
|
|
|
/*
|
|
|
|
* Write all log events to the database
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
Event::listen('illuminate.log', function ($level, $message, $context) {
|
|
|
|
if (!DbDongle::hasDatabase()) {
|
2014-07-30 17:19:29 +10:00
|
|
|
return;
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|
2014-07-30 17:19:29 +10:00
|
|
|
|
2014-07-30 18:24:16 +10:00
|
|
|
EventLog::add($message, $level);
|
2014-07-30 17:19:29 +10:00
|
|
|
});
|
|
|
|
|
2014-06-06 23:13:48 +10:00
|
|
|
/*
|
2014-06-28 21:12:02 +10:00
|
|
|
* Register basic Twig
|
2014-06-06 23:13:48 +10:00
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
App::bindShared('twig', function ($app) {
|
2014-06-26 17:32:12 +10:00
|
|
|
$twig = new Twig_Environment(new TwigLoader(), ['auto_reload' => true]);
|
|
|
|
$twig->addExtension(new TwigExtension);
|
|
|
|
return $twig;
|
2014-06-06 23:13:48 +10:00
|
|
|
});
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/*
|
|
|
|
* Register .htm extension for Twig views
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
App::make('view')->addExtension('htm', 'twig', function () {
|
2014-06-06 23:13:48 +10:00
|
|
|
return new TwigEngine(App::make('twig'));
|
2014-05-14 23:24:20 +10:00
|
|
|
});
|
|
|
|
|
2014-06-28 21:12:02 +10:00
|
|
|
/*
|
|
|
|
* Register Twig that will parse strings
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
App::bindShared('twig.string', function ($app) {
|
2014-06-28 21:12:02 +10:00
|
|
|
$twig = $app['twig'];
|
|
|
|
$twig->setLoader(new Twig_Loader_String);
|
|
|
|
return $twig;
|
|
|
|
});
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/*
|
2014-07-30 17:19:29 +10:00
|
|
|
* Override system mailer with mail settings
|
2014-05-14 23:24:20 +10:00
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
Event::listen('mailer.beforeRegister', function () {
|
|
|
|
if (MailSettings::isConfigured()) {
|
2014-07-04 18:47:46 +10:00
|
|
|
MailSettings::applyConfigValues();
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
});
|
|
|
|
|
2014-06-06 23:13:48 +10:00
|
|
|
/*
|
|
|
|
* Override standard Mailer content with template
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
Event::listen('mailer.beforeAddContent', function ($mailer, $message, $view, $plain, $data) {
|
|
|
|
if (MailTemplate::addContentToMailer($message, $view, $data)) {
|
2014-07-04 19:13:34 +10:00
|
|
|
return false;
|
2014-10-18 11:58:50 +02:00
|
|
|
}
|
2014-06-06 23:13:48 +10:00
|
|
|
});
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/*
|
|
|
|
* Register other module providers
|
|
|
|
*/
|
|
|
|
foreach (Config::get('cms.loadModules', []) as $module) {
|
2014-10-18 11:58:50 +02:00
|
|
|
if (strtolower(trim($module)) == 'system') {
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-14 23:24:20 +10:00
|
|
|
App::register('\\' . $module . '\ServiceProvider');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register navigation
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
BackendMenu::registerCallback(function ($manager) {
|
2014-05-14 23:24:20 +10:00
|
|
|
$manager->registerMenuItems('October.System', [
|
|
|
|
'system' => [
|
|
|
|
'label' => 'system::lang.system.menu_label',
|
|
|
|
'icon' => 'icon-cog',
|
|
|
|
'url' => Backend::url('system/settings'),
|
2014-06-14 16:55:12 +02:00
|
|
|
'permissions' => ['backend.manage_users', 'system.*'],
|
2014-07-27 11:11:16 +11:00
|
|
|
'order' => 1000
|
2014-05-14 23:24:20 +10:00
|
|
|
]
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register report widgets
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
WidgetManager::instance()->registerReportWidgets(function ($manager) {
|
2014-05-14 23:24:20 +10:00
|
|
|
$manager->registerReportWidget('System\ReportWidgets\Status', [
|
2014-08-12 21:46:19 +01:00
|
|
|
'label' => 'backend::lang.dashboard.status.widget_title_default',
|
2014-05-14 23:24:20 +10:00
|
|
|
'context' => 'dashboard'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register permissions
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
BackendAuth::registerCallback(function ($manager) {
|
2014-05-14 23:24:20 +10:00
|
|
|
$manager->registerPermissions('October.System', [
|
2014-10-18 11:58:50 +02:00
|
|
|
'system.manage_settings' => [
|
|
|
|
'label' => 'system::lang.permissions.manage_system_settings',
|
|
|
|
'tab' => 'System'
|
|
|
|
],
|
|
|
|
'system.manage_updates' => [
|
|
|
|
'label' => 'system::lang.permissions.manage_software_updates',
|
|
|
|
'tab' => 'System'
|
|
|
|
],
|
|
|
|
'system.manage_mail_templates' => [
|
|
|
|
'label' => 'system::lang.permissions.manage_mail_templates',
|
|
|
|
'tab' => 'System'
|
|
|
|
],
|
2014-05-14 23:24:20 +10:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2014-07-16 18:28:15 +10:00
|
|
|
/*
|
|
|
|
* Register markup tags
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
MarkupManager::instance()->registerCallback(function ($manager) {
|
2014-07-16 18:28:15 +10:00
|
|
|
$manager->registerFunctions([
|
|
|
|
// Functions
|
|
|
|
'post' => 'post',
|
|
|
|
'link_to' => 'link_to',
|
|
|
|
'link_to_asset' => 'link_to_asset',
|
|
|
|
'link_to_route' => 'link_to_route',
|
|
|
|
'link_to_action' => 'link_to_action',
|
|
|
|
'asset' => 'asset',
|
|
|
|
'action' => 'action',
|
|
|
|
'url' => 'url',
|
|
|
|
'route' => 'route',
|
|
|
|
'secure_url' => 'secure_url',
|
|
|
|
'secure_asset' => 'secure_asset',
|
|
|
|
|
|
|
|
// Classes
|
|
|
|
'str_*' => ['Str', '*'],
|
|
|
|
'url_*' => ['URL', '*'],
|
|
|
|
'html_*' => ['HTML', '*'],
|
|
|
|
'form_*' => ['Form', '*'],
|
|
|
|
'form_macro' => ['Form', '__call'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$manager->registerFilters([
|
|
|
|
// Classes
|
|
|
|
'slug' => ['Str', 'slug'],
|
|
|
|
'plural' => ['Str', 'plural'],
|
|
|
|
'singular' => ['Str', 'singular'],
|
|
|
|
'finish' => ['Str', 'finish'],
|
|
|
|
'snake' => ['Str', 'snake'],
|
|
|
|
'camel' => ['Str', 'camel'],
|
|
|
|
'studly' => ['Str', 'studly'],
|
2014-10-11 12:31:14 +11:00
|
|
|
'trans' => ['Lang', 'get'],
|
|
|
|
'transchoice' => ['Lang', 'choice'],
|
2014-07-25 20:06:38 +10:00
|
|
|
'md' => ['October\Rain\Support\Markdown', 'parse'],
|
2014-07-16 18:28:15 +10:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2014-05-14 23:24:20 +10:00
|
|
|
/*
|
|
|
|
* Register settings
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
SettingsManager::instance()->registerCallback(function ($manager) {
|
2014-05-14 23:24:20 +10:00
|
|
|
$manager->registerSettingItems('October.System', [
|
2014-07-27 11:11:16 +11:00
|
|
|
'administrators' => [
|
|
|
|
'label' => 'backend::lang.user.menu_label',
|
|
|
|
'description' => 'backend::lang.user.menu_description',
|
2014-08-06 18:33:11 +10:00
|
|
|
'category' => SettingsManager::CATEGORY_SYSTEM,
|
2014-07-27 11:11:16 +11:00
|
|
|
'icon' => 'icon-users',
|
|
|
|
'url' => Backend::url('backend/users'),
|
|
|
|
'permissions' => ['backend.manage_users'],
|
|
|
|
'order' => 600
|
2014-06-06 21:38:34 +10:00
|
|
|
],
|
2014-07-27 11:11:16 +11:00
|
|
|
'updates' => [
|
|
|
|
'label' => 'system::lang.updates.menu_label',
|
|
|
|
'description' => 'system::lang.updates.menu_description',
|
2014-08-06 18:33:11 +10:00
|
|
|
'category' => SettingsManager::CATEGORY_SYSTEM,
|
2014-07-27 11:11:16 +11:00
|
|
|
'icon' => 'icon-cloud-download',
|
|
|
|
'url' => Backend::url('system/updates'),
|
|
|
|
'permissions' => ['system.manage_updates'],
|
|
|
|
'order' => 700
|
2014-07-30 17:19:29 +10:00
|
|
|
],
|
|
|
|
'event_logs' => [
|
|
|
|
'label' => 'system::lang.event_log.menu_label',
|
|
|
|
'description' => 'system::lang.event_log.menu_description',
|
2014-08-06 18:33:11 +10:00
|
|
|
'category' => SettingsManager::CATEGORY_LOGS,
|
2014-07-30 17:19:29 +10:00
|
|
|
'icon' => 'icon-exclamation-triangle',
|
|
|
|
'url' => Backend::url('system/eventlogs'),
|
|
|
|
'permissions' => ['system.access_event_logs'],
|
|
|
|
'order' => 800
|
|
|
|
],
|
|
|
|
'request_logs' => [
|
|
|
|
'label' => 'system::lang.request_log.menu_label',
|
|
|
|
'description' => 'system::lang.request_log.menu_description',
|
2014-08-06 18:33:11 +10:00
|
|
|
'category' => SettingsManager::CATEGORY_LOGS,
|
2014-07-30 17:19:29 +10:00
|
|
|
'icon' => 'icon-file-o',
|
|
|
|
'url' => Backend::url('system/requestlogs'),
|
|
|
|
'permissions' => ['system.access_request_logs'],
|
|
|
|
'order' => 800
|
|
|
|
],
|
2014-08-06 18:33:11 +10:00
|
|
|
'mail_settings' => [
|
|
|
|
'label' => 'system::lang.mail.menu_label',
|
|
|
|
'description' => 'system::lang.mail.menu_description',
|
|
|
|
'category' => SettingsManager::CATEGORY_MAIL,
|
|
|
|
'icon' => 'icon-envelope',
|
|
|
|
'class' => 'System\Models\MailSettings',
|
|
|
|
'order' => 400,
|
|
|
|
],
|
|
|
|
'mail_templates' => [
|
|
|
|
'label' => 'system::lang.mail_templates.menu_label',
|
|
|
|
'description' => 'system::lang.mail_templates.menu_description',
|
|
|
|
'category' => SettingsManager::CATEGORY_MAIL,
|
|
|
|
'icon' => 'icon-envelope-square',
|
|
|
|
'url' => Backend::url('system/mailtemplates'),
|
|
|
|
'order' => 500,
|
|
|
|
],
|
2014-05-14 23:24:20 +10:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register console commands
|
|
|
|
*/
|
|
|
|
$this->registerConsoleCommand('october.up', 'System\Console\OctoberUp');
|
|
|
|
$this->registerConsoleCommand('october.down', 'System\Console\OctoberDown');
|
|
|
|
$this->registerConsoleCommand('october.update', 'System\Console\OctoberUpdate');
|
2014-07-25 17:51:36 +10:00
|
|
|
$this->registerConsoleCommand('october.util', 'System\Console\OctoberUtil');
|
2014-05-14 23:24:20 +10:00
|
|
|
$this->registerConsoleCommand('plugin.install', 'System\Console\PluginInstall');
|
|
|
|
$this->registerConsoleCommand('plugin.remove', 'System\Console\PluginRemove');
|
|
|
|
$this->registerConsoleCommand('plugin.refresh', 'System\Console\PluginRefresh');
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Override clear cache command
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
App::bindShared('command.cache.clear', function ($app) {
|
2014-05-14 23:24:20 +10:00
|
|
|
return new \System\Console\CacheClear($app['cache'], $app['files']);
|
|
|
|
});
|
2014-07-24 15:19:00 +11:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register the sidebar for the System main menu
|
|
|
|
*/
|
2014-10-18 11:58:50 +02:00
|
|
|
BackendMenu::registerContextSidenavPartial(
|
|
|
|
'October.System',
|
|
|
|
'system',
|
|
|
|
'@/modules/system/partials/_system_sidebar.htm'
|
|
|
|
);
|
2014-05-07 17:52:13 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bootstrap the module events.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2014-05-14 23:24:20 +10:00
|
|
|
/*
|
|
|
|
* Boot plugins
|
|
|
|
*/
|
|
|
|
$pluginManager = PluginManager::instance();
|
|
|
|
$pluginManager->bootAll();
|
|
|
|
|
2014-05-07 17:52:13 +10:00
|
|
|
parent::boot('system');
|
|
|
|
}
|
|
|
|
}
|