. // }}} namespace Plugin\Oomox; use App\Core\DB\DB; use App\Core\Event; use App\Core\Modules\Plugin; use App\Core\Router\RouteLoader; use App\Util\Common; use App\Util\Exception\NotFoundException; use App\Util\Exception\RedirectException; use App\Util\Exception\ServerException; use App\Util\Formatting; use Plugin\Oomox\Controller as C; use Symfony\Component\HttpFoundation\Request; /** * Profile Color plugin main class * * @package GNUsocial * @category Oomox * * @author Eliseu Amaro * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ class Oomox extends Plugin { /** * Map URLs to actions * * @return bool hook value; true means continue processing, false means stop */ public function onAddRoute(RouteLoader $r): bool { $r->connect('settings_oomox', 'settings/oomox', [Controller\Oomox::class, 'oomoxSettings']); return Event::next; } /** * @throws RedirectException * @throws ServerException */ public function onPopulateProfileSettingsTabs(Request $request, array &$tabs): bool { $tabs[] = [ 'title' => 'Theme colours', 'desc' => 'Change the theme colours.', 'controller' => C\Oomox::oomoxSettings($request), ]; return Event::next; } public function onOverrideStylesheet(string $original_stylesheet, string &$response) { $check_user = !\is_null(Common::user()); if ($check_user && $original_stylesheet === 'assets/default_theme/css/root.css') { $actor_id = Common::actor()->getId(); try { $oomox_table = DB::findOneBy('oomox', ['actor_id' => $actor_id]); } catch (NotFoundException $e) { return Event::next; } $res[] = Formatting::twigRenderFile('/oomox/root_override.css.twig', ['oomox' => $oomox_table]); return Event::stop; } return Event::next; } }