PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.10
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.10
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / views / part-settings-custom-folders.php

part-settings-custom-folders.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.10, at views/part-settings-custom-folders.php

192 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
3
4 if ( ! imagify_can_optimize_custom_folders() ) {
5 return;
6 }
7
8 // Get folders, remove excluded ones, sort them, add labels.
9 $custom_folders = Imagify_Folders_DB::get_instance()->get_active_folders_column( 'path' );
10 $themes = array();
11
12 if ( $custom_folders ) {
13 $custom_folders = array_combine( $custom_folders, $custom_folders );
14 $custom_folders = array_map( array( 'Imagify_Files_Scan', 'remove_placeholder' ), $custom_folders );
15 $custom_folders = array_map( 'trailingslashit', $custom_folders );
16 $custom_folders = array_filter( $custom_folders, array( 'Imagify_Files_Scan', 'is_path_autorized' ) );
17 }
18
19 if ( $custom_folders ) {
20 $custom_folders = array_map( array( $this->filesystem, 'make_path_relative' ), $custom_folders );
21 $custom_folders = array_map( 'untrailingslashit', $custom_folders );
22 natcasesort( $custom_folders );
23 $custom_folders = array_map( 'trailingslashit', $custom_folders );
24
25 if ( isset( $custom_folders['{{ROOT}}/'] ) ) {
26 $custom_folders['{{ROOT}}/'] = __( 'Site\'s root', 'imagify' );
27 }
28 }
29
30 // Current used theme(s).
31 if ( ! is_network_admin() ) {
32 $current_theme = wp_get_theme();
33 $themes_not_added = array();
34
35 foreach ( array( $current_theme, $current_theme->parent() ) as $theme ) {
36 if ( ! $theme || ! $theme->exists() ) {
37 continue;
38 }
39
40 $theme_path = trailingslashit( $theme->get_stylesheet_directory() );
41
42 if ( ! Imagify_Files_Scan::is_path_forbidden( $theme_path ) ) {
43 $theme = array(
44 'name' => $theme->display( 'Name' ),
45 'path' => Imagify_Files_Scan::add_placeholder( $theme_path ),
46 'label' => $this->filesystem->make_path_relative( $theme_path ),
47 );
48
49 $themes[ $theme['path'] ] = $theme;
50 $added = false;
51 $rel_path = strtolower( $theme['label'] );
52
53 foreach ( $custom_folders as $path => $label ) {
54 if ( strpos( $rel_path, strtolower( $label ) ) === 0 ) {
55 $added = true;
56 break;
57 }
58 }
59
60 if ( ! $added ) {
61 $themes_not_added[] = $theme['path'];
62 }
63 }
64 }
65
66 $themes_count = count( $themes );
67 }
68 ?>
69 <div class="imagify-custom-folders-section">
70 <div class="imagify-col" id="custom-folders">
71 <h3 class="imagify-options-subtitle"><?php _e( 'Custom Folders', 'imagify' ); ?></h3>
72
73 <div id="imagify-custom-folders" class="hide-if-no-js imagify-mt2">
74
75 <?php if ( $themes ) { ?>
76 <div class="imagify-folder-themes-suggestion">
77 <div class="imagify-fts-header imagify-flex imagify-vcenter">
78 <span><i class="dashicons dashicons-info"></i></span>
79 <p>
80 <?php
81 $theme = reset( $themes );
82
83 /* translators: %s is a theme name. */
84 printf( __( 'You’re using %s', 'imagify' ), '<strong>' . $theme['name'] . '</strong>' );
85
86 if ( $themes_count > 1 ) {
87 $theme = end( $themes );
88 echo '<br>';
89 /* translators: %s is a theme name. */
90 printf( __( 'child theme of %s', 'imagify' ), '<strong>' . $theme['name'] . '</strong>' );
91 }
92 ?>
93 </p>
94 </div>
95
96 <div class="imagify-fts-content">
97 <?php
98 if ( ! $themes_not_added ) {
99 ?>
100 <p class="imagify-mb0"><?php echo _n( 'Your theme is already in the optimization process. All Good!', 'Your themes are already in the optimization process. All Good!', $themes_count, 'imagify' ); ?></p>
101 <?php
102 } elseif ( count( $themes_not_added ) !== $themes_count ) {
103 $theme = reset( $themes_not_added );
104 $theme = $themes[ $theme ];
105 ?>
106 <p><?php _e( 'Only one of your current themes is in the optimization process, would you like to also optimize the other one?', 'imagify' ); ?></p>
107
108 <button id="imagify-add-themes-to-custom-folder"
109 class="button imagify-button-clean imagify-add-themes" type="button"
110 data-theme="<?php echo esc_attr( $theme['path'] ) . '#///#' . esc_attr( $theme['label'] ); ?>">
111 <span class="dashicons dashicons-plus"></span>
112 <span class="button-text"><?php
113 /* translators: %s is a theme name. */
114 printf( __( 'Add %s to optimization', 'imagify' ), '<strong>' . $theme['name'] . '</strong>' );
115 ?></span>
116 </button>
117 <?php
118 } else {
119 foreach ( $themes as $path => $theme ) {
120 $themes[ $path ] = esc_attr( $theme['path'] ) . '#///#' . esc_attr( $theme['label'] );
121 }
122 ?>
123 <p><?php echo _n( 'Would you like to optimize your theme?', 'Would you like to optimize your themes?', $themes_count, 'imagify' ); ?></p>
124
125 <button id="imagify-add-themes-to-custom-folder"
126 class="button imagify-button-clean imagify-add-themes" type="button"
127 data-theme="<?php echo implode( '" data-theme-parent="', $themes ); ?>">
128 <span class="dashicons dashicons-plus"></span>
129 <span
130 class="button-text"><?php echo _n( 'Add the theme to optimization', 'Add the themes to optimization', $themes_count, 'imagify' ); ?></span>
131 </button>
132 <?php
133 }
134 ?>
135 </div>
136 </div>
137 <?php } ?>
138
139 <p class="imagify-kindof-title imagify-flex imagify-vcenter">
140 <span><?php _e( 'Select folders for optimization.', 'imagify' ); ?></span>
141 <span>
142 <button id="imagify-add-custom-folder"
143 class="button imagify-button-mini imagify-button-primary imagify-add-custom-folder"
144 type="button">
145 <span class="dashicons dashicons-plus"></span>
146 <span class="button-text"><?php _e( 'Add folders', 'imagify' ); ?></span>
147 </button>
148 <img class="imagify-loader" aria-hidden="true" alt="<?php esc_attr_e( 'Loading...', 'imagify' ); ?>" src="<?php echo esc_url( IMAGIFY_ASSETS_IMG_URL . 'loader-balls.svg' ); ?>" width="38" height="24"/>
149 </span>
150 </p>
151
152 <fieldset id="imagify-custom-folders-selected">
153 <?php
154 if ( $custom_folders ) {
155 foreach ( $custom_folders as $placeholder => $label ) {
156 $this->print_template( 'part-settings-row-custom-folder', array(
157 'value' => $placeholder,
158 'label' => $label,
159 ) );
160 }
161 }
162 ?>
163 </fieldset>
164
165 <p>
166 <?php
167 printf(
168 /* translators: 1 and 2 are <strong> opening and closing tags. */
169 __( '%1$sSelecting a folder will also optimize images in sub-folders.%2$s The only exception is "Site’s root": when selected, only images that are directly at the site’s root will be optimized (sub-folders can be selected separately).', 'imagify' ),
170 '<strong>',
171 '</strong>'
172 );
173 ?>
174 <br/>
175 <?php _e( 'Folders that are hidden in the folder selector window are excluded and will not be optimized even if a parent folder is selected.', 'imagify' ); ?>
176 </p>
177
178 <p class="imagify-success hidden"><?php _e( 'You changed your custom folder settings, don\'t forget to save your changes!', 'imagify' ); ?></p>
179
180 <script type="text/html" id="tmpl-imagify-custom-folder">
181 <?php
182 $this->print_template( 'part-settings-row-custom-folder', array(
183 'value' => '{{ data.value }}',
184 'label' => '{{ data.label }}',
185 ) );
186 ?>
187 </script>
188 </div>
189 </div>
190 </div>
191 <?php
192