extension_type = EXTENSION_TYPE_PLUGIN; $this->module_name = $name = $this->getName(); $this->module_title = $this->getTitle(); $this->module_dir = $this->extension_path; $started = false; $actions = $this->isAdminPanel(); if ($actions) { foreach (['install', 'uninstall', 'enable', 'disable'] as $action) { $this->app->hookAdd('plugins.' . $action . '.' . $name, function () use ($action) { if ($action !== 'disable') { $this->refreshStatic(in_array($action, ['install', 'enable'])); } return $this->$action(); }, 4); } } $this->app->hookAdd('plugins.update.' . $name, function ($return, $context) { $this->refreshStatic(true); return $this->update($context); }, 4); $this->app->hookAdd('plugins.extend.' . $name, function ($obj, $testMode) use (&$started) { if (! $started && $this->isActive($testMode)) { $this->extend(); } }, 4); $this->app->hookAdd('plugins.start.' . $name, function ($obj, $testMode) use (&$started) { if (! $started && $this->isActive($testMode)) { $started = true; if ($this->isDebug()) { $this->refreshStatic(true); } $this->onBeforeStart(); $this->start(); } }, 4); } /** * Запуск плагина (если был установлен и включен) * @return void */ protected function start() { } /** * Запуск расширений классов - @see bff::classExtension * @return void */ protected function extend() { } /** * Установка плагина * Метод вызываемый при инсталяции плагина администратором * @return bool */ protected function install() { return true; } /** * Удаление плагина * Метод вызываемый при удалении плагина администратором * @return bool */ protected function uninstall() { return true; } /** * Установлен ли плагин * @return bool */ public function isInstalled() { return $this->plugin_installed; } /** * Включение плагина * Метод вызываемый при включении плагина администратором * @return bool */ protected function enable() { return true; } /** * Выключение плагина * Метод вызываемый при выключении плагина администратором * @return bool */ protected function disable() { return true; } /** * Обновление плагина * Метод вызываемый при обновлении плагина * @param array $context [ * 'version_from' => 'версия до обновления (X.X.X)', * 'version_to' => 'версия обновления (X.X.X)', * 'date' => 'дата обновления (d.m.Y)' * ] * @return bool */ protected function update(array $context) { return true; } /** * Включен ли плагин * @param bool|null $testMode проверяем включен ли плагин в режиме тестирования * @return bool */ public function isEnabled($testMode = null) { if ($testMode ?? Dev::extensionsTestMode()) { return $this->isTestmode(); } return $this->plugin_enabled; } /** * Плагин был установлен и включен * @param bool|null $testMode проверяем включен ли плагин в режиме тестирования * @return bool */ public function isActive($testMode = null) { return $this->isInstalled() && $this->isEnabled($testMode) && $this->isCompatible(); } /** * Внутренее название плагина * @return string */ public function getName() { return $this->plugin_name; } /** * Алиас внутреннего названия плагина * @return string */ public function getAlias() { return $this->plugin_alias; } /** * Видимое название плагина * @return string */ public function getTitle() { foreach ( [ $this->getSettings('plugin_title_' . $this->locale->current()), $this->plugin_title, ] as $title ) { if ($title && $title !== '?' && $title !== '{TITLE}') { return $title; } } return $this->getName(); } /** * Версия плагина * @return string */ public function getVersion() { return $this->plugin_version; } /** * Расписание запуска крон задач плагина: * [ * 'название публичного метода плагина' => ['period'=>'* * * * *'], * ... * ] * @return array */ public function cronSettings() { return []; } /** * Добавление пунктов меню в активную тему * @param \Theme $theme */ public function menu($theme) { } }