PluginProbe ʕ •ᴥ•ʔ
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel / trunk
Photo Gallery by FooGallery : Responsive Image Gallery, Masonry Gallery & Carousel vtrunk
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-metabox-template.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 8 months ago class-admin-notices.php 8 months ago class-admin.php 8 months ago class-attachment-fields.php 8 months ago class-columns.php 8 months ago class-demo-content.php 8 months ago class-extensions.php 8 months ago class-gallery-attachment-modal.php 8 months ago class-gallery-datasources.php 8 months ago class-gallery-editor.php 8 months ago class-gallery-metabox-fields.php 8 months ago class-gallery-metabox-items.php 8 months ago class-gallery-metabox-settings-helper.php 8 months ago class-gallery-metabox-settings.php 8 months ago class-gallery-metabox-template.php 8 months ago class-gallery-metaboxes.php 8 months ago class-menu.php 8 months ago class-pro-promotion.php 8 months ago class-settings.php 8 months ago class-silent-installer-skin.php 8 months ago class-trial-mode.php 8 months ago demo-content-galleries.php 8 months ago demo-content-images.php 8 months ago index.php 12 years ago pro-features.php 8 months ago view-features.php 8 months ago view-help-demos.php 8 months ago view-help-getting-started.php 8 months ago view-help-pro.php 8 months ago view-help.php 8 months ago view-system-info.php 8 months ago
class-gallery-metabox-template.php
134 lines
1 <?php
2 /**
3 * Class to handle adding the Template metabox to a gallery
4 */
5
6 // TODO : remove phpcs:disable comment and work through plugin check warnings.
7
8
9 if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Template' ) ) {
10
11 class FooGallery_Admin_Gallery_MetaBox_Template {
12
13 /**
14 * FooGallery_Admin_Gallery_MetaBox_Template constructor.
15 */
16 function __construct() {
17 add_action( 'add_meta_boxes_' . FOOGALLERY_CPT_GALLERY, array( $this, 'add_template_metabox' ), 6 );
18
19 //enqueue assets for the new settings tabs
20 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
21 }
22
23 public function add_template_metabox( $post ) {
24 add_meta_box(
25 'foogallery_template',
26 __( 'Gallery Layout', 'foogallery' ),
27 array( $this, 'render_gallery_template_metabox' ),
28 FOOGALLERY_CPT_GALLERY,
29 'normal',
30 'high'
31 );
32 }
33
34 /**
35 * Render the template metabox
36 */
37 public function render_gallery_template_metabox( $post ) {
38 $gallery = foogallery_admin_get_current_gallery( $post );
39
40 $gallery_templates = foogallery_gallery_templates();
41 $current_gallery_template = foogallery_default_gallery_template();
42 if ( ! empty( $gallery->gallery_template ) ) {
43 $current_gallery_template = $gallery->gallery_template;
44 }
45
46 $message = __( 'Once you are happy with your selected layout, you can minimize this section to save space', 'foogallery' );
47 $hide_help = 'on' == foogallery_get_setting( 'hide_gallery_template_help' );
48 if ( $hide_help ) {
49 $message = '';
50 }
51
52 // Allow SVG tags for icons (wp_kses_post doesn't support SVG)
53 $svg_allowed = array(
54 'svg' => array(
55 'viewbox' => true,
56 'viewBox' => true,
57 'xmlns' => true,
58 'width' => true,
59 'height' => true,
60 'class' => true,
61 ),
62 'g' => array(
63 'transform' => true,
64 'class' => true,
65 ),
66 'rect' => array(
67 'x' => true,
68 'y' => true,
69 'width' => true,
70 'height' => true,
71 'class' => true,
72 ),
73 'polygon' => array(
74 'points' => true,
75 'class' => true,
76 ),
77 'circle' => array(
78 'cx' => true,
79 'cy' => true,
80 'r' => true,
81 'class' => true,
82 ),
83 'path' => array(
84 'd' => true,
85 'class' => true,
86 ),
87 'polyline' => array(
88 'points' => true,
89 'class' => true,
90 ),
91 );
92
93 ?>
94 <div class="foogallery-template-card-selector" data-metabox-message="<?php echo esc_attr( $message ); ?>">
95 <div class="foogallery-template-cards-container">
96 <?php foreach ( $gallery_templates as $template ) {
97 $selected_class = ( $current_gallery_template === $template['slug'] ) ? 'selected' : '';
98 $extra_class = $template['class'] ?? '';
99 $extra_html = $template['html'] ?? '';
100 ?>
101 <div class="foogallery-template-card <?php echo esc_attr( $selected_class ); ?> <?php echo esc_attr( $extra_class ); ?>"
102 data-template="<?php echo esc_attr( $template['slug'] ); ?>">
103 <?php echo wp_kses( $template['icon'], $svg_allowed ); ?>
104 <h4><?php echo esc_html( $template['name'] ); ?></h4>
105 <?php echo wp_kses_post( $extra_html ); ?>
106 </div>
107 <?php } ?>
108 </div>
109
110 <!-- Keep the hidden select for form submission -->
111 <input type="hidden" id="FooGallerySettings_GalleryTemplate" name="<?php echo esc_attr( FOOGALLERY_META_TEMPLATE ); ?>" value="<?php echo esc_attr( $current_gallery_template ); ?>" />
112 </div>
113 <?php
114 }
115
116 /***
117 * Enqueue the assets needed by the template metabox
118 * @param $hook_suffix
119 */
120 function enqueue_assets( $hook_suffix ){
121 if( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) {
122 $screen = get_current_screen();
123
124 if ( is_object( $screen ) && FOOGALLERY_CPT_GALLERY === $screen->post_type ){
125
126 // Register, enqueue scripts and styles here
127 wp_enqueue_script( 'foogallery-admin-template', FOOGALLERY_URL . 'js/foogallery.admin.template.js', array('jquery'), FOOGALLERY_VERSION );
128 wp_enqueue_style( 'foogallery-admin-template', FOOGALLERY_URL . 'css/foogallery.admin.template.css', array(), FOOGALLERY_VERSION );
129 }
130 }
131 }
132 }
133 }
134