improve = new improve(); $this->type = $this->getType(); $this->module = $this->getModule(); $this->action = $this->getAction(); $this->doAction(); $this->displayPage(); } private function getType(): string { return $_REQUEST['type'] ?? 'plugin'; } private function getModule(): string { $module = $_REQUEST['module'] ?? ''; if (!in_array($module, $this->comboModules())) { $module = '-'; } return $module; } private function getAction(): ?action { return empty($_REQUEST['config']) ? null : $this->improve->module($_REQUEST['config']); } private function getPreference(): array { try { if (!empty($this->type)) { $preferences = dcCore::app()->blog->settings->improve->preferences; if (is_string($preferences)) { $preferences = unserialize($preferences); if (is_array($preferences)) { return array_key_exists($this->type, $preferences) ? $preferences[$this->type] : []; } } } } catch (Exception $e) { } return []; } private function setPreferences(): bool { if (!empty($_POST['save_preferences'])) { $preferences[$this->type] = []; if (!empty($_POST['actions'])) { foreach ($this->improve->modules() as $action) { if (in_array($this->type, $action->types()) && in_array($action->id(), $_POST['actions'])) { $preferences[$this->type][] = $action->id(); } } } dcCore::app()->blog->settings->improve->put('preferences', serialize($preferences), 'string', null, true, true); dcAdminNotices::addSuccessNotice(__('Configuration successfully updated')); return true; } return false; } private function comboModules(): array { $allow_distrib = (bool) dcCore::app()->blog->settings->improve->allow_distrib; $official = [ 'plugin' => explode(',', DC_DISTRIB_PLUGINS), 'theme' => explode(',', DC_DISTRIB_THEMES), ]; if (!(dcCore::app()->themes instanceof dcThemes)) { dcCore::app()->themes = new dcThemes(); dcCore::app()->themes->loadModules(dcCore::app()->blog->themes_path, null); } $combo_modules = []; $modules = self::getModules($this->type == 'plugin' ? 'plugins' : 'themes'); foreach ($modules as $id => $m) { if (!$m['root_writable'] || !$allow_distrib && in_array($id, $official[$this->type])) { continue; } $combo_modules[sprintf(__('%s (%s)'), __($m['name']), $id)] = $id; } dcUtils::lexicalKeySort($combo_modules); return array_merge([__('Select a module') => '-'], $combo_modules); } public static function getModules(string $type, ?string $id = null): ?array { $type = $type == 'themes' ? 'themes' : 'plugins'; $modules = array_merge(dcCore::app()->{$type}->getDisabledModules(), dcCore::app()->{$type}->getModules()); if (empty($id)) { return $modules; } elseif (array_key_exists($id, $modules)) { return $modules[$id]; } return null; } private function doAction(): void { $log_id = ''; $done = $this->setPreferences(); if (!empty($_POST['fix'])) { if (empty($_POST['actions'])) { dcAdminNotices::addWarningNotice(__('No action selected')); } elseif ($this->module == '-') { dcAdminNotices::addWarningNotice(__('No module selected')); } else { try { $time = $this->improve->fixModule( $this->type, $this->module, self::getModules($this->type == 'plugin' ? 'plugins' : 'themes', $this->module), $_POST['actions'] ); $log_id = $this->improve->writeLogs(); dcCore::app()->blog->triggerBlog(); if ($this->improve->hasLog('error')) { $notice = ['type' => dcAdminNotices::NOTICE_ERROR, 'msg' => __('Fix of "%s" complete in %s secondes with errors')]; } elseif ($this->improve->hasLog('warning')) { $notice = ['type' => dcAdminNotices::NOTICE_WARNING, 'msg' => __('Fix of "%s" complete in %s secondes with warnings')]; } elseif ($this->improve->hasLog('success')) { $notice = ['type' => dcAdminNotices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes')]; } else { $notice = ['type' => dcAdminNotices::NOTICE_SUCCESS, 'msg' => __('Fix of "%s" complete in %s secondes without messages')]; } dcAdminNotices::addNotice($notice['type'], sprintf($notice['msg'], $this->module, $time)); $done = true; } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); $done = false; } } } if ($done) { dcCore::app()->adminurl->redirect('admin.plugin.improve', ['type' => $this->type, 'module' => $this->module, 'upd' => $log_id]); } } private function displayPage(): void { $bc = empty($_REQUEST['config']) ? ($this->type == 'theme' ? __('Themes actions') : __('Plugins actions')) : __('Configure module'); echo '
' . __('Unknow module') . '
'; } else { $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.improve', ['type' => $this->type, 'config' => $this->action->id()]); $res = $this->action->configure($redir); echo '' . html::escapeHTML($this->action->description()) . '
'; } } private function displayActions(): void { echo ''; $combo_modules = $this->comboModules(); if (count($combo_modules) == 1) { echo ' '; } else { echo ''; if (!empty($_REQUEST['upd']) && !dcCore::app()->blog->settings->improve->nodetails) { $logs = $this->improve->parseLogs((int) $_REQUEST['upd']); if (!empty($logs)) { echo '