default.php
3 days ago
default_api.php
3 days ago
default_api_basic.php
3 days ago
default_api_users.php
3 days ago
default_backup.php
3 days ago
default_backup_basic.php
3 days ago
default_customizer.php
3 days ago
default_customizer_addcss.php
3 days ago
default_customizer_form.php
3 days ago
default_customizer_preview.php
3 days ago
default_customizer_toolbar.php
3 days ago
default_webhooks.php
3 days ago
default_webhooks_basic.php
3 days ago
index.html
3 days ago
default_customizer.php
128 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | // create object to pass to the hook, so that external plugins |
| 15 | // can extend the appearance of any additional tab |
| 16 | $setup = new stdClass; |
| 17 | $setup->icons = array(); |
| 18 | |
| 19 | $tabs = array(); |
| 20 | |
| 21 | foreach ($this->customizerTree as $nodeName => $nodeLevels) |
| 22 | { |
| 23 | $tab_lang_key = 'VAP_CUSTOMIZER_TAB_' . strtoupper($nodeName); |
| 24 | |
| 25 | // attempt to translate tab label |
| 26 | $tab_label = JText::translate($tab_lang_key); |
| 27 | |
| 28 | if ($tab_label === $tab_lang_key) |
| 29 | { |
| 30 | // prettify default name |
| 31 | $tab_label = ucfirst($nodeName); |
| 32 | } |
| 33 | |
| 34 | $this->customizerNode = $nodeLevels; |
| 35 | $tabs[$tab_label] = $this->loadTemplate('customizer_form'); |
| 36 | |
| 37 | switch ($nodeName) |
| 38 | { |
| 39 | case 'calendar': |
| 40 | $setup->icons[$tab_label] = 'fas fa-calendar-alt'; |
| 41 | break; |
| 42 | |
| 43 | case 'timeline': |
| 44 | $setup->icons[$tab_label] = 'fas fa-clock'; |
| 45 | break; |
| 46 | |
| 47 | case 'button': |
| 48 | $setup->icons[$tab_label] = 'fas fa-square'; |
| 49 | break; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // add tab to write custom CSS code |
| 54 | $tabs['VAP_CUSTOMIZER_TAB_ADDITIONALCSS'] = $this->loadTemplate('customizer_addcss'); |
| 55 | $setup->icons['VAP_CUSTOMIZER_TAB_ADDITIONALCSS'] = 'fas fa-code'; |
| 56 | |
| 57 | /** |
| 58 | * Trigger event to display custom HTML. |
| 59 | * In case it is needed to include any additional fields, |
| 60 | * it is possible to create a plugin and attach it to an event |
| 61 | * called "onDisplayViewConfigappCustomizer". The event method receives the |
| 62 | * view instance as argument. |
| 63 | * |
| 64 | * @since 1.7.2 |
| 65 | */ |
| 66 | $forms = $this->onDisplayView('Customizer', $setup); |
| 67 | |
| 68 | // create display data |
| 69 | $data = array(); |
| 70 | $data['id'] = 4; |
| 71 | $data['active'] = $this->selectedTab == $data['id']; |
| 72 | $data['tabs'] = array_merge($tabs, $forms); |
| 73 | $data['setup'] = $setup; |
| 74 | $data['hook'] = 'Customizer'; |
| 75 | $data['suffix'] = 'app'; |
| 76 | |
| 77 | $data['before'] = $this->loadTemplate('customizer_toolbar'); |
| 78 | $data['after'] = $this->loadTemplate('customizer_preview'); |
| 79 | |
| 80 | // render configuration pane with apposite layout |
| 81 | echo JLayoutHelper::render('configuration.tabview', $data); |
| 82 | |
| 83 | JText::script('VAP_CUSTOMIZER_RESTORE_FACTORY_SETTINGS'); |
| 84 | ?> |
| 85 | |
| 86 | <script> |
| 87 | (function($) { |
| 88 | 'use strict'; |
| 89 | |
| 90 | // get default customizer settings |
| 91 | const defaultSettings = <?php echo json_encode($this->customizerModel->getItem()); ?>; |
| 92 | |
| 93 | $(function() { |
| 94 | $('.restore-customizer-settings').on('click', function() { |
| 95 | // ask for a confirmation before to proceed |
| 96 | const r = confirm(Joomla.JText._('VAP_CUSTOMIZER_RESTORE_FACTORY_SETTINGS')); |
| 97 | |
| 98 | if (!r) { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | // find all fields related to the clicked button |
| 103 | const fields = $(this).closest('.config-fieldset-body').find('[name^="customizer["]'); |
| 104 | |
| 105 | fields.each(function() { |
| 106 | // extract CSS var from name |
| 107 | const match = $(this).attr('name').match(/^customizer\[(.*?)\]$/); |
| 108 | const key = match[1]; |
| 109 | |
| 110 | if (!defaultSettings.hasOwnProperty(key)) { |
| 111 | // var not found... |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | let value = defaultSettings[key]; |
| 116 | |
| 117 | if (key.match(/-(?:color|background|border)$/)) { |
| 118 | value = value.replace(/^#/, ''); |
| 119 | } |
| 120 | |
| 121 | // restore original value |
| 122 | $(this).val(value).trigger('change'); |
| 123 | }); |
| 124 | }); |
| 125 | }); |
| 126 | })(jQuery); |
| 127 | </script> |
| 128 |