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