module($_REQUEST['config']); } private static function getPreference(): array { try { if (!empty(self::$type)) { $preferences = dcCore::app()->blog->settings->get(Core::id())->get('preferences'); if (is_string($preferences)) { $preferences = unserialize($preferences); if (is_array($preferences)) { return array_key_exists(self::$type, $preferences) ? $preferences[self::$type] : []; } } } } catch (Exception $e) { } return []; } private static function setPreferences(): bool { if (!empty($_POST['save_preferences'])) { $preferences[self::$type] = []; if (!empty($_POST['actions'])) { foreach (self::$improve->modules() as $action) { if (in_array(self::$type, $action->types()) && in_array($action->id(), $_POST['actions'])) { $preferences[self::$type][] = $action->id(); } } } dcCore::app()->blog->settings->get(Core::id())->put('preferences', serialize($preferences), 'string', null, true, true); dcAdminNotices::addSuccessNotice(__('Configuration successfully updated')); return true; } return false; } private static function comboModules(): array { $allow_distrib = (bool) dcCore::app()->blog->settings->get(Core::id())->get('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(self::$type == 'plugin' ? 'plugins' : 'themes'); foreach ($modules as $id => $m) { if (!$m['root_writable'] || !$allow_distrib && in_array($id, $official[self::$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; } public static function process(): void { if (!self::$init) { return; } $log_id = ''; $done = self::setPreferences(); if (!empty($_POST['fix'])) { if (empty($_POST['actions'])) { dcAdminNotices::addWarningNotice(__('No action selected')); } elseif (self::$module == '-') { dcAdminNotices::addWarningNotice(__('No module selected')); } else { try { $time = self::$improve->fixModule( self::$type, self::$module, self::getModules(self::$type == 'plugin' ? 'plugins' : 'themes', self::$module), $_POST['actions'] ); $log_id = self::$improve->writeLogs(); dcCore::app()->blog->triggerBlog(); if (self::$improve->hasLog('error')) { $notice = ['type' => dcAdminNotices::NOTICE_ERROR, 'msg' => __('Fix of "%s" complete in %s secondes with errors')]; } elseif (self::$improve->hasLog('warning')) { $notice = ['type' => dcAdminNotices::NOTICE_WARNING, 'msg' => __('Fix of "%s" complete in %s secondes with warnings')]; } elseif (self::$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'], self::$module, $time)); $done = true; } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); $done = false; } } } if ($done) { dcCore::app()->adminurl->redirect('admin.plugin.' . Core::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]); } } public static function render(): void { if (!self::$init) { return; } $bc = empty($_REQUEST['config']) ? (self::$type == 'theme' ? __('Themes actions') : __('Plugins actions')) : __('Configure module'); echo '
' . __('Unknow module') . '
'; } else { $redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . Core::id(), ['type' => self::$type, 'config' => self::$action->id()]); $res = self::$action->configure($redir); echo '' . html::escapeHTML(self::$action->description()) . '
'; } } private static function displayActions(): void { echo ''; $combo_modules = self::comboModules(); if (count($combo_modules) == 1) { echo ' '; } else { echo ''; if (!empty($_REQUEST['upd']) && !dcCore::app()->blog->settings->get(Core::id())->get('nodetails')) { $logs = self::$improve->parseLogs((int) $_REQUEST['upd']); if (!empty($logs)) { echo '