PluginProbe
Gridable / trunk
Gridable vtrunk
1.2.12 1.2.11 trunk 0.1.0 0.5.0 1.0.0 1.1.0 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9
gridable / admin / class-gridable-admin.php

class-gridable-admin.php in Gridable trunk, at admin/class-gridable-admin.php

183 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * The admin-specific functionality of the plugin.
9 *
10 * @link https://pixelgrade.com
11 * @since 1.0.0
12 *
13 * @package Gridable
14 * @subpackage Gridable/admin
15 */
16
17 /**
18 * The admin-specific functionality of the plugin.
19 *
20 * Defines the plugin name, version, and two examples hooks for how to
21 * enqueue the admin-specific stylesheet and JavaScript.
22 *
23 * @package Gridable
24 * @subpackage Gridable/admin
25 * @author Pixelgrade <contact@pixelgrade.com>
26 */
27 class Gridable_Admin {
28
29 /**
30 * The ID of this plugin.
31 *
32 * @since 1.0.0
33 * @access private
34 * @var string $gridable The ID of this plugin.
35 */
36 private $gridable;
37
38 /**
39 * The version of this plugin.
40 *
41 * @since 1.0.0
42 * @access private
43 * @var string $version The current version of this plugin.
44 */
45 private $version;
46
47 /**
48 * Initialize the class and set its properties.
49 *
50 * @since 1.0.0
51 *
52 * @param string $gridable The name of this plugin.
53 * @param string $version The version of this plugin.
54 */
55 public function __construct( $gridable, $version ) {
56 $this->gridable = $gridable;
57 $this->version = $version;
58 }
59
60 public function add_media_button( $editor_id ) {
61 // Setup the icon - currently using a dashicon
62 $icon = '<span class="wp-media-buttons-icon dashicons dashicons-layout" style="font-size:16px;margin-top:-2px;"></span>';
63
64 printf( '<a href="#" class="button gridable-insert-row-button" id="%s" data-editor="%s" title="%s">%s %s</a>',
65 esc_attr( 'gridable-add-row-button-' . $editor_id ),
66 esc_attr( $editor_id ),
67 esc_attr__( 'Add Row', 'gridable' ),
68 wp_kses( $icon, array(
69 'span' => array(
70 'class' => true,
71 'style' => true,
72 ),
73 ) ),
74 esc_html__( 'Add Row', 'gridable' )
75 );
76
77 /**
78 * Enqueue the editor script only when there is an editor on page.
79 * We ditch `admin_enqueue_scripts` intentionally since the editor can appear on non-edit pages like theme options
80 */
81 wp_register_script( 'select2', plugin_dir_url( __FILE__ ) . 'js/select2.min.js', array( 'jquery' ), $this->version, true );
82
83 wp_enqueue_script( 'gridable-add-row-button', plugin_dir_url( __FILE__ ) . 'js/add-row-button.js', array(
84 'backbone',
85 'jquery',
86 'media-editor',
87 'media-views',
88 'quicktags',
89 'shortcode',
90 'wp-color-picker',
91 'wp-util',
92 'select2',
93 ), $this->version, true );
94
95 wp_register_style( 'select2', plugin_dir_url( __FILE__ ) . 'css/select2.css', array(), $this->version );
96
97 wp_enqueue_style( 'gridable-admin-style', plugin_dir_url( __FILE__ ) . 'css/admin-style.css', array(
98 'wp-color-picker',
99 'select2',
100 ), $this->version, false );
101
102 wp_localize_script( 'gridable-add-row-button', 'gridable_editor_params', array(
103 'new_column_content' => esc_html__( 'Content', 'gridable' ),
104 ) );
105
106 wp_localize_script( 'gridable-add-row-button', 'gridable_row_options', apply_filters( 'gridable_row_options', array(
107 'cols_nr' => array(
108 'default' => 2,
109 ),
110 ) ) );
111
112 wp_localize_script( 'gridable-add-row-button', 'gridable_column_options', apply_filters( 'gridable_column_options', array(
113 'size' => array(
114 'default' => 6,
115 ),
116 ) ) );
117
118 global $editor_styles;
119 if ( ! empty( $editor_styles ) && is_array( $editor_styles ) ) {
120 $editor_styles = array_merge( $editor_styles, array(
121 plugin_dir_url( __FILE__ ) . 'css/editor-style.css',
122 ) );
123 } else {
124 $editor_styles = array(
125 plugin_dir_url( __FILE__ ) . 'css/editor-style.css',
126 );
127 }
128 }
129
130 public function print_tinymce_templates() {
131 $row_classes = array(
132 'gridable',
133 'gridable--grid',
134 'grid',
135 );
136 $col_classes = array(
137 'grid__item',
138 ); ?>
139 <script type="text/html" id="tmpl-gridable-grider-row"><section contenteditable="false" class="{{data.classes}} <?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', apply_filters( 'gridable_mce_sh_row_classes', $row_classes ) ) ) ); ?>" {{{data.atts}}} data-gridable-row="1" data-mce-resize="false" data-mce-placeholder="1">{{{data.content}}}</section></script>
140 <script type="text/html" id="tmpl-gridable-grider-col"><section unselectable="true" contenteditable="true" class="{{data.classes}} <?php echo esc_attr( implode( ' ', array_map( 'sanitize_html_class', apply_filters( 'gridable_mce_sh_col_classes', $col_classes ) ) ) ); ?>" {{{data.atts}}} data-mce-resize="false" data-mce-placeholder="1">{{{data.content}}}</section></script>
141 <?php
142 do_action( 'gridable_print_row_options_templates' );
143 do_action( 'gridable_print_column_options_templates' );
144 }
145
146 public function add_tinymce_plugin( $plugin_array ) {
147 $plugin_array['gridable'] = plugin_dir_url( __FILE__ ) . 'js/gridable.js';
148
149 return $plugin_array;
150 }
151
152 public function change_tinymce_settings( $settings ) {
153 if ( ! empty( $settings['tinymce'] ) ) {
154 if ( ! is_array( $settings['tinymce'] ) ) {
155 $settings['tinymce'] = array();
156 }
157 // We need to disable keeping the scroll position when switching between Visual and Text mode
158 // due to the fact that this functionality relies on some inline spans that get autop'd
159 // and result in certain cases in &nbsp; characters. Making a solid Regex for this is very tricky.
160 $settings['tinymce']['wp_keep_scroll_position'] = false;
161 }
162
163 return $settings;
164 }
165
166 public function styles_scripts() { ?>
167 <script type="text/javascript">
168 window.gridable_params = window.gridable_params || {};
169 window.gridable_params.l10n = <?php echo wp_json_encode( apply_filters( 'gridable_editor_l10n_labels', array(
170 'remove_row' => esc_html__( 'Remove Row', 'gridable' ),
171 'remove_column' => esc_html__( 'Remove Column', 'gridable' ),
172 'edit_row' => esc_html__( 'Edit Row Options', 'gridable' ),
173 'edit_column' => esc_html__( 'Edit Column Options', 'gridable' ),
174 'add_column' => esc_html__( 'Add Column', 'gridable' ),
175 'new_column_content' => esc_html__( 'Content', 'gridable' ),
176 'column' => esc_html__( 'Column', 'gridable' ),
177 'row' => esc_html__( 'Row', 'gridable' ),
178 ) ) ); ?>;
179 </script>
180 <?php
181 }
182 }
183