|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Vvveb |
| 5 | + * |
| 6 | + * Copyright (C) 2023 Ziadin Givan |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +/* |
| 24 | +Name: Insert Footer Header Scripts |
| 25 | +Slug: insert-scripts |
| 26 | +Category: tools |
| 27 | +Url: https://www.vvveb.com |
| 28 | +Description: Insert footer and header scripts such as analytics or widgets. |
| 29 | +Thumb: insert-scripts.svg |
| 30 | +Author: givanz |
| 31 | +Version: 0.1 |
| 32 | +Author url: https://www.vvveb.com |
| 33 | +Settings: /admin/?module=plugins/insert-scripts/settings |
| 34 | +*/ |
| 35 | + |
| 36 | +use function Vvveb\__; |
| 37 | +use Vvveb\System\Core\View; |
| 38 | +use Vvveb\System\Event; |
| 39 | + |
| 40 | +if (! defined('V_VERSION')) { |
| 41 | + die('Invalid request!'); |
| 42 | +} |
| 43 | + |
| 44 | +class InsertScriptsPlugin { |
| 45 | + function admin() { |
| 46 | + // add admin menu item |
| 47 | + $admin_path = \Vvveb\adminPath(); |
| 48 | + Event::on('Vvveb\Controller\Base', 'init-menu', __CLASS__, function ($menu) use ($admin_path) { |
| 49 | + $menu['plugins']['items']['insert-scripts'] = [ |
| 50 | + 'name' => __('Insert scripts'), |
| 51 | + 'url' => $admin_path . '?module=plugins/insert-scripts/settings', |
| 52 | + 'icon-img' => PUBLIC_PATH . 'plugins/insert-scripts/insert-scripts.svg', |
| 53 | + ]; |
| 54 | + |
| 55 | + return [$menu]; |
| 56 | + }, 20); |
| 57 | + } |
| 58 | + |
| 59 | + function app() { |
| 60 | + //don't add scripts if the page is open in the editor |
| 61 | + if (Vvveb\isEditor()) { |
| 62 | + return; |
| 63 | + } |
| 64 | + $view = View::getInstance(); |
| 65 | + $template = $view->getTemplateEngineInstance(); |
| 66 | + $view->plugins = $view->plugins ?? []; |
| 67 | + $options = Vvveb\get_setting('insert-scripts', ['header', 'footer']); |
| 68 | + $view->plugins['insert-scripts'] = $options ?? []; |
| 69 | + $template->loadTemplateFile(__DIR__ . '/app/template/common.tpl'); |
| 70 | + //$template->addTemplatePath(__DIR__ . '/../app/template/'); |
| 71 | + } |
| 72 | + |
| 73 | + function __construct() { |
| 74 | + if (APP == 'admin') { |
| 75 | + $this->admin(); |
| 76 | + } else { |
| 77 | + if (APP == 'app') { |
| 78 | + $this->app(); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +$insertScriptsPlugin = new InsertScriptsPlugin(); |
0 commit comments