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-columns.php
237 lines
| 1 | <?php |
| 2 | /* |
| 3 | * FooGallery Admin Columns class |
| 4 | */ |
| 5 | |
| 6 | if ( ! class_exists( 'FooGallery_Admin_Columns' ) ) { |
| 7 | |
| 8 | class FooGallery_Admin_Columns { |
| 9 | |
| 10 | private $include_clipboard_script = false; |
| 11 | private $_foogallery = false; |
| 12 | |
| 13 | public function __construct() { |
| 14 | add_filter( 'manage_edit-' . FOOGALLERY_CPT_GALLERY . '_columns', array( $this, 'gallery_custom_columns' ) ); |
| 15 | add_action( 'manage_posts_custom_column', array( $this, 'gallery_custom_column_content' ) ); |
| 16 | add_action( 'admin_footer', array( $this, 'include_clipboard_script' ) ); |
| 17 | } |
| 18 | |
| 19 | public function gallery_custom_columns( $columns ) { |
| 20 | return array_slice( $columns, 0, 1, true ) + |
| 21 | array( 'icon' => '' ) + |
| 22 | array_slice( $columns, 1, null, true ) + |
| 23 | array( |
| 24 | FOOGALLERY_CPT_GALLERY . '_template' => __( 'Layout', 'foogallery' ), |
| 25 | FOOGALLERY_CPT_GALLERY . '_count' => __( 'Media', 'foogallery' ), |
| 26 | FOOGALLERY_CPT_GALLERY . '_shortcode' => __( 'Shortcode', 'foogallery' ), |
| 27 | FOOGALLERY_CPT_GALLERY . '_usage' => __( 'Usage', 'foogallery' ), |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | private function get_local_gallery( $post ) { |
| 32 | if ( false === $this->_foogallery ) { |
| 33 | $this->_foogallery = FooGallery::get( $post ); |
| 34 | } else if ( $this->_foogallery->ID !== $post->ID) { |
| 35 | $this->_foogallery = FooGallery::get( $post ); |
| 36 | } |
| 37 | |
| 38 | return $this->_foogallery; |
| 39 | } |
| 40 | |
| 41 | public function gallery_custom_column_content( $column ) { |
| 42 | global $post; |
| 43 | |
| 44 | switch ( $column ) { |
| 45 | case FOOGALLERY_CPT_GALLERY . '_template': |
| 46 | $gallery = $this->get_local_gallery( $post ); |
| 47 | echo esc_html( $gallery->gallery_template_name() ); |
| 48 | break; |
| 49 | case FOOGALLERY_CPT_GALLERY . '_count': |
| 50 | $gallery = $this->get_local_gallery( $post ); |
| 51 | echo esc_html( $gallery->image_count() ); |
| 52 | break; |
| 53 | case FOOGALLERY_CPT_GALLERY . '_shortcode': |
| 54 | $gallery = $this->get_local_gallery( $post ); |
| 55 | $shortcode = $gallery->shortcode(); |
| 56 | |
| 57 | $copy_label = __( 'Copy shortcode', 'foogallery' ); |
| 58 | |
| 59 | echo '<div class="foogallery-shortcode-wrapper">'; |
| 60 | echo '<input type="text" readonly="readonly" value="' . esc_attr( $shortcode ) . '" class="foogallery-shortcode foogallery-shortcode-input" />'; |
| 61 | echo '<button type="button" class="button button-small foogallery-shortcode-button" data-shortcode="' . esc_attr( $shortcode ) . '" aria-label="' . esc_attr( $copy_label ) . '">'; |
| 62 | echo '<span class="dashicons dashicons-clipboard" aria-hidden="true"></span>'; |
| 63 | echo '<span class="screen-reader-text">' . esc_html( $copy_label ) . '</span>'; |
| 64 | echo '</button>'; |
| 65 | echo '</div>'; |
| 66 | |
| 67 | $this->include_clipboard_script = true; |
| 68 | |
| 69 | break; |
| 70 | case 'icon': |
| 71 | $gallery = $this->get_local_gallery( $post ); |
| 72 | $html_img = foogallery_find_featured_attachment_thumbnail_html( $gallery, array( |
| 73 | 'width' => 60, |
| 74 | 'height' => 60, |
| 75 | 'force_use_original_thumb' => true |
| 76 | ) ); |
| 77 | if ( $html_img ) { |
| 78 | echo $html_img; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 79 | } |
| 80 | break; |
| 81 | case FOOGALLERY_CPT_GALLERY . '_usage': |
| 82 | $gallery = $this->get_local_gallery( $post ); |
| 83 | $posts = $gallery->find_usages(); |
| 84 | if ( $posts && count( $posts ) > 0 ) { |
| 85 | echo '<ul class="ul-disc">'; |
| 86 | foreach ( $posts as $post ) { |
| 87 | echo edit_post_link( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 88 | $post->post_title, '<li>', '</li>', $post->ID ); |
| 89 | } |
| 90 | echo '</ul>'; |
| 91 | } else { |
| 92 | esc_html_e( 'Not used!', 'foogallery' ); |
| 93 | } |
| 94 | break; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | public function include_clipboard_script() { |
| 99 | if ( $this->include_clipboard_script ) { ?> |
| 100 | <style> |
| 101 | .foogallery-shortcode-wrapper { |
| 102 | display: flex; |
| 103 | align-items: center; |
| 104 | gap: 6px; |
| 105 | } |
| 106 | |
| 107 | .foogallery-shortcode-input { |
| 108 | max-width: 100%; |
| 109 | } |
| 110 | |
| 111 | .foogallery-shortcode-button { |
| 112 | display: none !important; |
| 113 | align-items: center; |
| 114 | justify-content: center; |
| 115 | width: 20px; |
| 116 | height: 25px; |
| 117 | min-width: 30px; |
| 118 | padding: 0 !important; |
| 119 | background: #f8fbff; |
| 120 | border: 1px solid #aaa !important; |
| 121 | color: #aaa !important; |
| 122 | box-shadow: none; |
| 123 | transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease; |
| 124 | cursor: pointer; |
| 125 | } |
| 126 | |
| 127 | .foogallery-shortcode-button .dashicons { |
| 128 | font-size: 16px; |
| 129 | line-height: 1; |
| 130 | width: 16px; |
| 131 | height: 16px; |
| 132 | pointer-events: none; |
| 133 | } |
| 134 | |
| 135 | .foogallery-shortcode-message { |
| 136 | margin: 6px 0 0; |
| 137 | } |
| 138 | |
| 139 | @media screen and (max-width: 960px) { |
| 140 | .foogallery-shortcode-button { |
| 141 | display: inline-flex !important; |
| 142 | } |
| 143 | |
| 144 | .column-foogallery_shortcode .foogallery-shortcode-wrapper { |
| 145 | |
| 146 | } |
| 147 | |
| 148 | .column-foogallery_shortcode .foogallery-shortcode-input { |
| 149 | position: absolute; |
| 150 | width: 1px; |
| 151 | height: 1px; |
| 152 | padding: 0; |
| 153 | margin: -1px; |
| 154 | border: 0; |
| 155 | clip: rect(0, 0, 0, 0); |
| 156 | clip-path: inset(50%); |
| 157 | overflow: hidden; |
| 158 | } |
| 159 | } |
| 160 | </style> |
| 161 | <script> |
| 162 | jQuery(function($) { |
| 163 | var copiedMessage = '<?php echo esc_js( __( 'Shortcode copied to clipboard :)', 'foogallery' ) ); ?>'; |
| 164 | var messageTimeout; |
| 165 | |
| 166 | function showCopyMessage($trigger) { |
| 167 | if (messageTimeout) { |
| 168 | clearTimeout(messageTimeout); |
| 169 | } |
| 170 | |
| 171 | $('.foogallery-shortcode-message').remove(); |
| 172 | |
| 173 | var $wrapper = $trigger.closest('.foogallery-shortcode-wrapper'); |
| 174 | var $message = $('<p class="foogallery-shortcode-message"></p>').text(copiedMessage); |
| 175 | |
| 176 | if ($wrapper.length) { |
| 177 | $wrapper.after($message); |
| 178 | } else { |
| 179 | $trigger.after($message); |
| 180 | } |
| 181 | |
| 182 | messageTimeout = setTimeout(function () { |
| 183 | $message.fadeOut(200, function () { |
| 184 | $(this).remove(); |
| 185 | }); |
| 186 | }, 2500); |
| 187 | } |
| 188 | |
| 189 | function copyShortcode(shortcode, onSuccess) { |
| 190 | if (navigator.clipboard && navigator.clipboard.writeText) { |
| 191 | navigator.clipboard.writeText(shortcode).then(onSuccess).catch(fallbackCopy); |
| 192 | } else { |
| 193 | fallbackCopy(); |
| 194 | } |
| 195 | |
| 196 | function fallbackCopy() { |
| 197 | var $temp = $('<textarea class="foogallery-shortcode-hidden"></textarea>'); |
| 198 | $temp.val(shortcode) |
| 199 | .attr('readonly', 'readonly') |
| 200 | .css({ position: 'absolute', left: '-9999px', top: '0' }); |
| 201 | $('body').append($temp); |
| 202 | $temp[0].select(); |
| 203 | |
| 204 | try { |
| 205 | if (document.execCommand('copy')) { |
| 206 | onSuccess(); |
| 207 | } |
| 208 | } catch (err) { |
| 209 | console.log('Oops, unable to copy!'); |
| 210 | } |
| 211 | |
| 212 | $temp.remove(); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | $('.foogallery-shortcode-input').on('click', function () { |
| 217 | var $input = $(this); |
| 218 | $input[0].select(); |
| 219 | copyShortcode($input.val(), function () { |
| 220 | showCopyMessage($input); |
| 221 | }); |
| 222 | }); |
| 223 | |
| 224 | $('.foogallery-shortcode-button').on('click', function () { |
| 225 | var $button = $(this); |
| 226 | copyShortcode($button.data('shortcode'), function () { |
| 227 | showCopyMessage($button); |
| 228 | }); |
| 229 | }); |
| 230 | }); |
| 231 | </script> |
| 232 | <?php |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 |