/** * Initialize the admin. * * @throws \RuntimeException */ protected function initializeAdmin() { $this->enable(['onTwigExtensions' => ['onTwigExtensions', 1000], 'onPagesInitialized' => ['onPagesInitialized', 1000], 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 1000], 'onTwigSiteVariables' => ['onTwigSiteVariables', 1000], 'onAssetsInitialized' => ['onAssetsInitialized', 1000], 'onTask.GPM' => ['onTaskGPM', 0], 'onAdminRegisterPermissions' => ['onAdminRegisterPermissions', 0], 'onOutputGenerated' => ['onOutputGenerated', 0]]); // Autoload classes require_once __DIR__ . '/vendor/autoload.php'; // Check for required plugins if (!$this->grav['config']->get('plugins.login.enabled') || !$this->grav['config']->get('plugins.form.enabled') || !$this->grav['config']->get('plugins.email.enabled')) { throw new \RuntimeException('One of the required plugins is missing or not enabled'); } // Initialize Admin Language if needed /** @var Language $language */ $language = $this->grav['language']; if ($language->enabled() && empty($this->grav['session']->admin_lang)) { $this->grav['session']->admin_lang = $language->getLanguage(); } // Decide admin template and route. $path = trim(substr($this->uri->route(), strlen($this->base)), '/'); if (empty($this->template)) { $this->template = 'dashboard'; } // Can't access path directly... if ($path && $path != 'register') { $array = explode('/', $path, 2); $this->template = array_shift($array); $this->route = array_shift($array); } // Initialize admin class. $this->admin = new Admin($this->grav, $this->admin_route, $this->template, $this->route); // And store the class into DI container. $this->grav['admin'] = $this->admin; // Double check we have system.yaml, site.yaml etc $config_path = $this->grav['locator']->findResource('user://config'); foreach ($this->admin->configurations() as $config_file) { $config_file = "{$config_path}/{$config_file}.yaml"; if (!file_exists($config_file)) { touch($config_file); } } // Get theme for admin $this->theme = $this->config->get('plugins.admin.theme', 'grav'); $assets = $this->grav['assets']; $translations = 'this.GravAdmin = this.GravAdmin || {}; if (!this.GravAdmin.translations) this.GravAdmin.translations = {}; ' . PHP_EOL . 'this.GravAdmin.translations.PLUGIN_ADMIN = {'; // Enable language translations $translations_actual_state = $this->config->get('system.languages.translations'); $this->config->set('system.languages.translations', true); $strings = ['EVERYTHING_UP_TO_DATE', 'UPDATES_ARE_AVAILABLE', 'IS_AVAILABLE_FOR_UPDATE', 'AND', 'IS_NOW_AVAILABLE', 'CURRENT', 'UPDATE_GRAV_NOW', 'TASK_COMPLETED', 'UPDATE', 'UPDATING_PLEASE_WAIT', 'GRAV_SYMBOLICALLY_LINKED', 'OF_YOUR', 'OF_THIS', 'HAVE_AN_UPDATE_AVAILABLE', 'UPDATE_AVAILABLE', 'UPDATES_AVAILABLE', 'FULLY_UPDATED', 'DAYS', 'PAGE_MODES', 'PAGE_TYPES', 'ACCESS_LEVELS', 'NOTHING_TO_SAVE', 'FILE_UNSUPPORTED', 'FILE_ERROR_ADD', 'FILE_ERROR_UPLOAD', 'DROP_FILES_HERE_TO_UPLOAD', 'DELETE', 'INSERT', 'UNDO', 'UNDO', 'REDO', 'HEADERS', 'BOLD', 'ITALIC', 'STRIKETHROUGH', 'SUMMARY_DELIMITER', 'LINK', 'IMAGE', 'BLOCKQUOTE', 'UNORDERED_LIST', 'ORDERED_LIST', 'EDITOR', 'PREVIEW', 'FULLSCREEN', 'MODULAR', 'NON_MODULAR', 'VISIBLE', 'NON_VISIBLE', 'ROUTABLE', 'NON_ROUTABLE', 'PUBLISHED', 'NON_PUBLISHED', 'PLUGINS', 'THEMES', 'ALL', 'FROM', 'TO', 'DROPZONE_CANCEL_UPLOAD', 'DROPZONE_CANCEL_UPLOAD_CONFIRMATION', 'DROPZONE_DEFAULT_MESSAGE', 'DROPZONE_FALLBACK_MESSAGE', 'DROPZONE_FALLBACK_TEXT', 'DROPZONE_FILE_TOO_BIG', 'DROPZONE_INVALID_FILE_TYPE', 'DROPZONE_MAX_FILES_EXCEEDED', 'DROPZONE_REMOVE_FILE', 'DROPZONE_RESPONSE_ERROR']; foreach ($strings as $string) { $separator = end($strings) === $string ? '' : ','; $translations .= '"' . $string . '": "' . $this->admin->translate('PLUGIN_ADMIN.' . $string) . '"' . $separator; } $translations .= '};'; // set the actual translations state back $this->config->set('system.languages.translations', $translations_actual_state); $assets->addInlineJs($translations); }