core = $core; $this->improve = new improve($core); $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 = $this->core->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(); } } } $this->core->blog->settings->improve->put('preferences', serialize($preferences), 'string', null, true, true); dcPage::addSuccessNotice(__('Configuration successfully updated')); return true; } return false; } private function comboModules(): array { $allow_distrib = (bool) $this->core->blog->settings->improve->allow_distrib; $official = [ 'plugin' => explode(',', DC_DISTRIB_PLUGINS), 'theme' => explode(',', DC_DISTRIB_THEMES), ]; if (!isset($this->core->themes)) { $this->core->themes = new dcThemes($this->core); $this->core->themes->loadModules($this->core->blog->themes_path, null); } $combo_modules = []; $modules = $this->type == 'plugin' ? $this->core->plugins->getModules() : $this->core->themes->getModules(); foreach ($modules as $id => $m) { if (!$m['root_writable'] || !$allow_distrib && in_array($id, $official[$this->type])) { continue; } $combo_modules[__($m['name'])] = $id; } dcUtils::lexicalKeySort($combo_modules); return array_merge([__('Select a module') => '-'], $combo_modules); } private function doAction(): void { $log_id = ''; $done = $this->setPreferences(); if (!empty($_POST['fix'])) { if (empty($_POST['actions'])) { dcPage::addWarningNotice(__('No action selected')); } elseif ($this->module == '-') { dcPage::addWarningNotice(__('No module selected')); } else { try { $time = $this->improve->fixModule( $this->type, $this->module, $this->type == 'plugin' ? $this->core->plugins->getModules($this->module) : $this->core->themes->getModules($this->module), $_POST['actions'] ); $log_id = $this->improve->writeLogs(); $this->core->blog->triggerBlog(); if ($this->improve->hasLog('error')) { $notice = ['type' => 'error', 'msg' => __('Fix of "%s" complete in %s secondes with errors')]; } elseif ($this->improve->hasLog('warning')) { $notice = ['type' => 'warning', 'msg' => __('Fix of "%s" complete in %s secondes with warnings')]; } elseif ($this->improve->hasLog('success')) { $notice = ['type' => 'success', 'msg' => __('Fix of "%s" complete in %s secondes')]; } else { $notice = ['type' => 'success', 'msg' => __('Fix of "%s" complete in %s secondes without messages')]; } dcPage::addNotice($notice['type'], sprintf($notice['msg'], $this->module, $time)); $done = true; } catch (Exception $e) { $this->core->error->add($e->getMessage()); $done = false; } } } if ($done) { $this->core->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'] ?? $this->core->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']) && !$this->core->blog->settings->improve->nodetails) { $logs = $this->improve->parseLogs((int) $_REQUEST['upd']); if (!empty($logs)) { echo '