class-admin-notice-custom-css.php
7 months ago
class-admin-notices.php
7 months ago
class-admin.php
7 months ago
class-attachment-fields.php
7 months ago
class-columns.php
7 months ago
class-demo-content.php
7 months ago
class-extensions.php
7 months ago
class-gallery-attachment-modal.php
7 months ago
class-gallery-datasources.php
7 months ago
class-gallery-editor.php
7 months ago
class-gallery-metabox-fields.php
7 months ago
class-gallery-metabox-items.php
7 months ago
class-gallery-metabox-settings-helper.php
7 months ago
class-gallery-metabox-settings.php
7 months ago
class-gallery-metabox-template.php
7 months ago
class-gallery-metaboxes.php
7 months ago
class-menu.php
7 months ago
class-pro-promotion.php
7 months ago
class-settings.php
7 months ago
class-silent-installer-skin.php
7 months ago
class-trial-mode.php
7 months ago
demo-content-galleries.php
7 months ago
demo-content-images.php
7 months ago
index.php
11 years ago
pro-features.php
7 months ago
view-features.php
7 months ago
view-help-demos.php
7 months ago
view-help-getting-started.php
7 months ago
view-help-pro.php
7 months ago
view-help.php
7 months ago
view-system-info.php
7 months ago
class-gallery-editor.php
330 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 esc_url( 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"> |
| 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"> |
| 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"> |
| 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_admin_referer( 'foogallery_load_galleries', 'foogallery_load_galleries' ) ) { |
| 250 | echo $this->get_galleries_html_for_modal(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML generated by internal method |
| 251 | } |
| 252 | die(); |
| 253 | } |
| 254 | |
| 255 | function get_galleries_html_for_modal() { |
| 256 | $galleries = foogallery_get_all_galleries(); |
| 257 | |
| 258 | ob_start(); |
| 259 | |
| 260 | foreach ( $galleries as $gallery ) { |
| 261 | $img_src = foogallery_find_featured_attachment_thumbnail_src( $gallery, array( |
| 262 | 'width' => get_option( 'thumbnail_size_w' ), |
| 263 | 'height' => get_option( 'thumbnail_size_h' ), |
| 264 | 'force_use_original_thumb' => true |
| 265 | ) ); |
| 266 | $images = $gallery->image_count(); |
| 267 | $title = empty( $gallery->name ) ? |
| 268 | sprintf( __( '%s #%s', 'foogallery' ), foogallery_plugin_name(), $gallery->ID ) : |
| 269 | $gallery->name; |
| 270 | ?> |
| 271 | <li class="foogallery-pile"> |
| 272 | <div class="foogallery-gallery-select" data-foogallery-id="<?php echo esc_attr( $gallery->ID ); ?>"> |
| 273 | <div style="display: table;"> |
| 274 | <div style="display: table-cell; vertical-align: middle; text-align: center;"> |
| 275 | <img src="<?php echo esc_url( $img_src ); ?>"/> |
| 276 | <h3> |
| 277 | <?php echo esc_html( $title ); ?> |
| 278 | <span><?php echo esc_html( $images ); ?></span> |
| 279 | </h3> |
| 280 | </div> |
| 281 | </div> |
| 282 | </div> |
| 283 | </li> |
| 284 | <?php } ?> |
| 285 | <li class="foogallery-pile"> |
| 286 | <div class="foogallery-gallery-select foogallery-add-gallery"> |
| 287 | <a href="<?php echo esc_url( foogallery_admin_add_gallery_url() ); ?>" target="_blank" class="thumbnail" style="display: table;"> |
| 288 | <span></span> |
| 289 | <div class="foogallery-gallery-select-inner" > |
| 290 | <h3><?php esc_html_e( 'Add New Gallery', 'foogallery' ); ?></h3> |
| 291 | </div> |
| 292 | </a> |
| 293 | </div> |
| 294 | </li> |
| 295 | <?php |
| 296 | |
| 297 | return ob_get_clean(); |
| 298 | } |
| 299 | |
| 300 | function ajax_get_gallery_info() { |
| 301 | |
| 302 | $nonce = sanitize_text_field( safe_get_from_request( 'nonce' ) ); |
| 303 | |
| 304 | wp_verify_nonce( $nonce, 'foogallery-timymce-nonce' ); |
| 305 | |
| 306 | $id = intval( safe_get_from_request( 'foogallery_id' ) ); |
| 307 | |
| 308 | $gallery = FooGallery::get_by_id( $id ); |
| 309 | |
| 310 | $image_src = foogallery_find_featured_attachment_thumbnail_src( $gallery, array( |
| 311 | 'width' => get_option( 'thumbnail_size_w' ), |
| 312 | 'height' => get_option( 'thumbnail_size_h' ), |
| 313 | 'force_use_original_thumb' => true |
| 314 | ) ); |
| 315 | |
| 316 | $json_array = array( |
| 317 | 'id' => $id, |
| 318 | 'name' => $gallery->name, |
| 319 | 'count' => $gallery->image_count(), |
| 320 | 'src' => $image_src, |
| 321 | ); |
| 322 | |
| 323 | header( 'Content-type: application/json' ); |
| 324 | echo json_encode( $json_array ); |
| 325 | |
| 326 | die(); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 |