PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.5
VikBooking Hotel Booking Engine & PMS v1.6.5
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / libraries / system / gutenberg.php

gutenberg.php in VikBooking Hotel Booking Engine & PMS 1.6.5, at libraries/system/gutenberg.php

83 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 Gutenberg editor.
16 *
17 * @since 1.0.17
18 */
19 class VikBookingGutenberg
20 {
21 /**
22 * Attaches the necessary scripts to handle the shortcode event.
23 *
24 * @return void
25 */
26 public static function registerShortcodesScript()
27 {
28 /**
29 * Make sure Gutenberg is up and running to avoid
30 * any Fatal Error, as the register_block_type()
31 * function may be not available on old instances.
32 */
33 if (!function_exists('register_block_type'))
34 {
35 return false;
36 }
37
38 // register the script that contains all the JS functions used
39 // to implement a new block for Gutenberg editor
40 wp_register_script(
41 'vikbooking-gutenberg-shortcodes',
42 VIKBOOKING_ADMIN_ASSETS_URI . 'js/gutenberg-shortcodes.js',
43 array('wp-blocks', 'wp-element', 'wp-i18n')
44 );
45
46 // register the style that contains all the CSS rules used
47 // to stylize the blocks for Gutenberg editor
48 wp_register_style(
49 'vikbooking-gutenberg-shortcodes',
50 VIKBOOKING_ADMIN_ASSETS_URI . 'css/gutenberg-shortcodes.css',
51 array()
52 );
53
54 // create a new block type, which must provide the script and the
55 // style we defined in the previous piece of code (script/style ID)
56 register_block_type('vikbooking/gutenberg-shortcodes', array(
57 'editor_script' => 'vikbooking-gutenberg-shortcodes',
58 'editor_style' => 'vikbooking-gutenberg-shortcodes',
59 ));
60
61 // get shortcode model
62 $model = JModel::getInstance('vikbooking', 'shortcodes', 'admin');
63
64 // obtain a categorized shortcodes list
65 $shortcodes = array();
66
67 foreach ($model->all() as $s)
68 {
69 $title = JText::translate($s->title);
70
71 if (!isset($shortcodes[$title]))
72 {
73 $shortcodes[$title] = array();
74 }
75
76 $shortcodes[$title][] = $s;
77 }
78
79 // register script to access JSON object
80 JFactory::getDocument()->addScriptDeclaration("var VIKBOOKING_SHORTCODES_BLOCK = " . json_encode($shortcodes) . ";");
81 }
82 }
83