| @@ -1,0 +1,72 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * @package VikBooking - Libraries | |
| 4 | + * @subpackage system | |
| 5 | + * @author E4J s.r.l. | |
| 6 | + * @copyright Copyright (C) 2018 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 | +/** | |
| 15 | + * Class used to provide support for TinyMCE editor. | |
| 16 | + * | |
| 17 | + * @since 1.0 | |
| 18 | + */ | |
| 19 | +class VikBookingTinyMCE | |
| 20 | +{ | |
| 21 | + /** | |
| 22 | + * Adds a button to the array of buttons for TinyMCE | |
| 23 | + * | |
| 24 | + * @param array $buttons | |
| 25 | + * | |
| 26 | + * @return array | |
| 27 | + */ | |
| 28 | + public static function addShortcodesButton($buttons) | |
| 29 | + { | |
| 30 | + $buttons[] = 'vbo-shortcodes'; | |
| 31 | + | |
| 32 | + return $buttons; | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Attaches the necessary scripts to handle the shortcode event | |
| 37 | + * | |
| 38 | + * @param array $plugin_array | |
| 39 | + * | |
| 40 | + * @return array | |
| 41 | + */ | |
| 42 | + public static function registerShortcodesScript($plugin_array) | |
| 43 | + { | |
| 44 | + // get shortcode model | |
| 45 | + $model = JModel::getInstance('vikbooking', 'shortcodes', 'admin'); | |
| 46 | + | |
| 47 | + // obtain a categorized shortcodes list | |
| 48 | + $shortcodes = array(); | |
| 49 | + | |
| 50 | + foreach ($model->all() as $s) | |
| 51 | + { | |
| 52 | + $title = JText::translate($s->title); | |
| 53 | + | |
| 54 | + if (!isset($shortcodes[$title])) | |
| 55 | + { | |
| 56 | + $shortcodes[$title] = array(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + $shortcodes[$title][] = $s; | |
| 60 | + } | |
| 61 | + | |
| 62 | + $document = JFactory::getDocument(); | |
| 63 | + | |
| 64 | + // register script to access JSON object | |
| 65 | + $document->addScriptDeclaration("var VIKBOOKING_SHORTCODES = " . json_encode($shortcodes) . ";"); | |
| 66 | + $document->addStyleSheet(VIKBOOKING_ADMIN_ASSETS_URI . 'css/tinymce-shortcodes.css'); | |
| 67 | + | |
| 68 | + $plugin_array['vbo-shortcodes'] = VIKBOOKING_ADMIN_ASSETS_URI . 'js/tinymce-shortcodes.js'; | |
| 69 | + | |
| 70 | + return $plugin_array; | |
| 71 | + } | |
| 72 | +} | |