PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.1.36
Gallery : FooGallery v3.1.36
3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / admin / class-gallery-editor.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 2 months ago class-admin-notices.php 2 months ago class-admin.php 2 months ago class-attachment-fields.php 2 months ago class-columns.php 2 months ago class-demo-content.php 2 months ago class-extensions.php 2 months ago class-gallery-attachment-modal.php 2 months ago class-gallery-datasources.php 2 months ago class-gallery-editor.php 2 months ago class-gallery-metabox-fields.php 2 months ago class-gallery-metabox-items.php 2 months ago class-gallery-metabox-settings-helper.php 2 months ago class-gallery-metabox-settings.php 2 months ago class-gallery-metabox-template.php 2 months ago class-gallery-metaboxes.php 2 months ago class-menu.php 2 months ago class-pro-promotion.php 2 months ago class-settings.php 2 months ago class-silent-installer-skin.php 2 months ago class-trial-mode.php 2 months ago demo-content-galleries.php 2 months ago demo-content-images.php 2 months ago index.php 2 months ago pro-features.php 2 months ago view-features.php 2 months ago view-help-demos.php 2 months ago view-help-getting-started.php 2 months ago view-help-pro.php 2 months ago view-help.php 2 months ago view-system-info.php 2 months ago
class-gallery-editor.php
344 lines
1 <?php
2
3 /*
4 * FooGallery Admin Gallery MetaBoxes class
5 */
6
7 if ( ! class_exists( 'FooGallery_Admin_Gallery_Editor' ) ) {
8
9 class FooGallery_Admin_Gallery_Editor {
10
11 /**
12 * Primary class constructor.
13 */
14 public function __construct() {
15 //adds a media button to the editor
16 add_action( 'media_buttons', array( $this, 'add_media_button') );
17
18 //add a tinymce plugin
19 add_action( 'admin_head', array( $this, 'add_tinymce_plugin' ) );
20
21 // Ajax calls for showing all galleries in the modal
22 add_action( 'wp_ajax_foogallery_load_galleries', array( $this, 'ajax_galleries_html' ) );
23
24 add_action( 'wp_ajax_foogallery_tinymce_load_info', array( $this, 'ajax_get_gallery_info' ) );
25 }
26
27 private function should_hide_editor_button() {
28 return 'on' == foogallery_get_setting( 'hide_editor_button', false );
29 }
30
31 /**
32 * Adds a gallery insert button into the editor
33 *
34 * @param string $editor_id the instance id of the current editor
35 *
36 * @return string $buttons the amended media buttons
37 */
38 public function add_media_button( $editor_id ) {
39
40 if ( $this->should_hide_editor_button() ) {
41 return;
42 }
43
44 //render the gallery modal
45 add_action( 'admin_footer', array( $this, 'render_gallery_modal' ) );
46 add_action( 'wp_footer', array( $this, 'render_gallery_modal' ) );
47
48 $url = FOOGALLERY_URL . 'css/admin-foogallery-gallery-piles.css';
49 wp_enqueue_style( 'admin-foogallery-gallery-piles', $url, array(), FOOGALLERY_VERSION );
50
51 $foogallery = FooGallery_Plugin::get_instance();
52 $foogallery->register_and_enqueue_js( 'admin-foogallery-editor.js' );
53
54 ?>
55 <button type="button" class="button foogallery-modal-trigger"
56 title="<?php esc_attr_e( sprintf( __( 'Add Gallery From %s', 'foogallery' ), foogallery_plugin_name() ) ); ?>"
57 style="padding-left: .4em;"
58 data-editor="<?php esc_attr_e( $editor_id ); ?>">
59 <span class="wp-media-buttons-icon dashicons dashicons-format-gallery"></span> <?php echo esc_html( sprintf( __( 'Add %s', 'foogallery' ), foogallery_plugin_name() ) ); ?>
60 </button>
61 <?php
62 }
63
64 /**
65 * Adds our custom plugin to the tinyMCE editor
66 */
67 public function add_tinymce_plugin() {
68
69 // get out if we do not want to add the button
70 if ( $this->should_hide_editor_button() ) {
71 return;
72 }
73
74 // check user permissions
75 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
76 return;
77 }
78 // check if WYSIWYG is enabled
79 if ( 'true' == get_user_option( 'rich_editing' ) ) {
80 add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_js' ) );
81 add_filter( 'mce_css', array( $this, 'add_tinymce_css' ) );
82 add_action( 'admin_footer', array( $this, 'render_tinymce_nonce') );
83 }
84 }
85
86 /**
87 * Include a plugin script into the editor
88 * @param $plugin_array
89 *
90 * @return mixed
91 */
92 public function add_tinymce_js( $plugin_array ) {
93 $plugin_array['foogallery'] = FOOGALLERY_URL . 'js/admin-tinymce.js';
94 return $plugin_array;
95 }
96
97 /**
98 * Include a plugin script into the editor
99 * @param $mce_css
100 *
101 * @return string
102 */
103 public function add_tinymce_css( $mce_css ) {
104 if ( ! empty( $mce_css ) ) {
105 $mce_css .= ',';
106 }
107
108 $mce_css .= FOOGALLERY_URL . 'css/admin-tinymce.css'; // . urlencode( '?v=' + FOOGALLERY_VERSION );
109
110 return $mce_css;
111 }
112
113 /**
114 * Renders a nonce field that is used in our AJAX calls for the visual editor
115 */
116 public function render_tinymce_nonce() {
117 ?>
118 <input id="foogallery-timnymce-action-nonce" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'foogallery-timymce-nonce' ) ); ?>" />
119 <?php
120 }
121
122
123 /**
124 * Renders the gallery modal for use in the editor
125 */
126 public function render_gallery_modal() {
127
128 ?>
129 <style>
130 .foogallery-modal-reload-container {
131 display: inline-block;
132 margin-left: 10px;
133 }
134 .foogallery-modal-reload-container a.button {
135 margin-top:10px !important;
136 }
137 .foogallery-modal-reload-container a span {
138 margin-top: 3px;
139 }
140 .foogallery-modal-reload-container .spinner {
141 position: absolute;
142 top: 15px;
143 display: inline-block;
144 margin-left: 5px;
145 }
146
147 .foogallery-add-gallery {
148 background: #444;
149 }
150
151 .foogallery-add-gallery span::after {
152 background: #ddd;
153 -webkit-border-radius: 50%;
154 border-radius: 50%;
155 display: inline-block;
156 content: '\f132';
157 -webkit-font-smoothing: antialiased;
158 font: normal 75px/115px 'dashicons';
159 width: 100px;
160 height: 100px;
161 vertical-align: middle;
162 text-align: center;
163 color: #999;
164 position: absolute;
165 top: 40%;
166 left: 50%;
167 margin-left: -50px;
168 margin-top: -50px;
169 padding: 0;
170 text-shadow: none;
171 z-index: 4;
172 text-indent: -4px;
173 }
174
175 .foogallery-add-gallery:hover span::after {
176 background: #1E8CBE;
177 color: #444;
178 }
179
180 </style>
181 <?php wp_nonce_field( 'foogallery_load_galleries', 'foogallery_load_galleries', false ); ?>
182 <div class="foogallery-modal-wrapper" style="display: none;">
183 <div class="media-modal wp-core-ui">
184 <button type="button" class="media-modal-close"><span class="media-modal-icon"><span class="screen-reader-text">Close media panel</span></span></button>
185 <div class="media-modal-content">
186 <div class="media-frame wp-core-ui hide-menu hide-router foogallery-meta-wrap">
187 <div class="media-frame-title foogallery-modal-title">
188 <h1>
189 <?php esc_html_e( 'Choose a gallery to insert', 'foogallery' ); ?>
190 <div class="foogallery-modal-reload-container">
191 <div class="spinner"></div>
192 <a class="foogallery-modal-reload button" href="#"><span class="dashicons dashicons-update"></span> <?php esc_html_e( 'Reload', 'foogallery' ); ?></a>
193 </div>
194 </h1>
195 </div>
196 <div class="media-frame-content foogallery-modal-container">
197 <div class="attachments-browser">
198 <ul class="foogallery-attachment-container attachments" style="padding-left: 8px; top: 1em;">
199 <div class="foogallery-modal-loading"><?php esc_html_e( 'Loading galleries...', 'foogallery' ); ?></div>
200 </ul>
201 <!-- end .foogallery-meta -->
202 <div class="media-sidebar">
203 <div class="foogallery-modal-sidebar">
204 <h3><?php esc_html_e( 'Select A Gallery', 'foogallery' ); ?></h3>
205 <p>
206 <?php esc_html_e( 'Select a gallery by clicking it, and then click the "Insert Gallery" button to insert it into your content.', 'foogallery' ); ?>
207 </p>
208 <h3><?php esc_html_e( 'Add A Gallery', 'foogallery' ); ?></h3>
209 <p>
210 <?php esc_html_e( 'You can add a new gallery by clicking the "Add New Gallery" tile on the left. It will open in a new window.', 'foogallery' ); ?>
211 </p>
212 <p>
213 <?php esc_html_e( 'Once you have finished adding a gallery, come back to this dialog and click the "Reload" button to see your newly created gallery.', 'foogallery' ); ?>
214 </p>
215 </div>
216 <!-- end .foogallery-meta-sidebar -->
217 </div>
218 <!-- end .media-sidebar -->
219 </div>
220 <!-- end .attachments-browser -->
221 </div>
222 <!-- end .media-frame-content -->
223 <div class="media-frame-toolbar foogallery-modal-toolbar">
224 <div class="media-toolbar">
225 <div class="media-toolbar-secondary">
226 <a href="#" class="foogallery-modal-cancel button media-button button-large button-secondary media-button-insert" title="<?php esc_attr_e( 'Cancel', 'foogallery' ); ?>"><?php esc_html_e( 'Cancel', 'foogallery' ); ?></a>
227 </div>
228 <div class="media-toolbar-primary">
229 <a href="#" class="foogallery-modal-insert button media-button button-large button-primary media-button-insert" disabled="disabled"
230 title="<?php esc_attr_e( 'Insert Gallery', 'foogallery' ); ?>"><?php esc_html_e( 'Insert Gallery', 'foogallery' ); ?></a>
231 </div>
232 <!-- end .media-toolbar-primary -->
233 </div>
234 <!-- end .media-toolbar -->
235 </div>
236 <!-- end .media-frame-toolbar -->
237 </div>
238 <!-- end .media-frame -->
239 </div>
240 <!-- end .media-modal-content -->
241 </div>
242 <!-- end .media-modal -->
243 <div class="media-modal-backdrop"></div>
244 </div>
245 <?php
246 }
247
248 function ajax_galleries_html() {
249 if ( ! check_ajax_referer( 'foogallery_load_galleries', 'foogallery_load_galleries', false ) ) {
250 wp_send_json_error( __( 'Invalid security token.', 'foogallery' ), 403 );
251 }
252
253 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
254 wp_send_json_error( __( 'Insufficient permissions.', 'foogallery' ), 403 );
255 }
256
257 echo $this->get_galleries_html_for_modal(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML generated by internal method
258 wp_die( '', '', array( 'response' => null ) );
259 }
260
261 function get_galleries_html_for_modal() {
262 $galleries = foogallery_get_all_galleries();
263
264 ob_start();
265
266 foreach ( $galleries as $gallery ) {
267 $img_src = foogallery_find_featured_attachment_thumbnail_src( $gallery, array(
268 'width' => get_option( 'thumbnail_size_w' ),
269 'height' => get_option( 'thumbnail_size_h' ),
270 'force_use_original_thumb' => true
271 ) );
272 $images = $gallery->image_count();
273 $title = empty( $gallery->name ) ?
274 sprintf( __( '%s #%s', 'foogallery' ), foogallery_plugin_name(), $gallery->ID ) :
275 $gallery->name;
276 ?>
277 <li class="foogallery-pile">
278 <div class="foogallery-gallery-select" data-foogallery-id="<?php echo esc_attr( $gallery->ID ); ?>">
279 <div style="display: table;">
280 <div style="display: table-cell; vertical-align: middle; text-align: center;">
281 <img src="<?php echo esc_url( $img_src ); ?>"/>
282 <h3>
283 <?php echo esc_html( $title ); ?>
284 <span><?php echo esc_html( $images ); ?></span>
285 </h3>
286 </div>
287 </div>
288 </div>
289 </li>
290 <?php } ?>
291 <li class="foogallery-pile">
292 <div class="foogallery-gallery-select foogallery-add-gallery">
293 <a href="<?php echo esc_url( foogallery_admin_add_gallery_url() ); ?>" target="_blank" class="thumbnail" style="display: table;">
294 <span></span>
295 <div class="foogallery-gallery-select-inner" >
296 <h3><?php esc_html_e( 'Add New Gallery', 'foogallery' ); ?></h3>
297 </div>
298 </a>
299 </div>
300 </li>
301 <?php
302
303 return ob_get_clean();
304 }
305
306 function ajax_get_gallery_info() {
307 if ( ! check_ajax_referer( 'foogallery-timymce-nonce', 'nonce', false ) ) {
308 wp_send_json_error( __( 'Invalid security token.', 'foogallery' ) );
309 }
310
311 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
312 wp_send_json_error( __( 'Insufficient permissions.', 'foogallery' ) );
313 }
314
315 $id = absint( safe_get_from_request( 'foogallery_id' ) );
316 if ( ! $id ) {
317 wp_send_json_error( __( 'Invalid gallery ID.', 'foogallery' ) );
318 }
319
320 $gallery = FooGallery::get_by_id( $id );
321 if ( ! $gallery ) {
322 wp_send_json_error( __( 'Gallery not found.', 'foogallery' ) );
323 }
324
325 if ( ! current_user_can( 'edit_post', $gallery->ID ) ) {
326 wp_send_json_error( __( 'Insufficient permissions.', 'foogallery' ) );
327 }
328
329 $image_src = foogallery_find_featured_attachment_thumbnail_src( $gallery, array(
330 'width' => get_option( 'thumbnail_size_w' ),
331 'height' => get_option( 'thumbnail_size_h' ),
332 'force_use_original_thumb' => true,
333 ) );
334
335 wp_send_json_success( array(
336 'id' => $id,
337 'name' => $gallery->name,
338 'count' => $gallery->image_count(),
339 'src' => $image_src,
340 ) );
341 }
342 }
343 }
344