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 / view-features.php
foogallery / includes / admin Last commit date
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
view-features.php
407 lines
1 <?php
2
3 /**
4 * Get the FooGallery plugin instance.
5 *
6 * @return FooGallery_Plugin The plugin instance.
7 */
8 $instance = FooGallery_Plugin::get_instance();
9
10 /**
11 * Create an instance of the FooGallery Extensions API.
12 *
13 * @var FooGallery_Extensions_API $api The Extensions API instance.
14 */
15 $api = new FooGallery_Extensions_API();
16
17 /**
18 * Filter extensions based on user selection (active, inactive, lightbox, premium).
19 *
20 * @var string $status_filter The selected status filter.
21 */
22 $status_filter = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all';
23
24
25 /**
26 * Get all extensions for view.
27 *
28 * @var array $extensions An array of extensions data.
29 */
30 $extensions = $api->get_all_for_view();
31
32 /**
33 * Flag indicating whether there are errors.
34 *
35 * @var bool $has_errors True if there are errors; otherwise, false.
36 */
37 $has_errors = false;
38
39 /**
40 * Show message flag.
41 *
42 * @var string $show_message Flag to indicate if a message should be shown.
43 */
44 $show_message = safe_get_from_request( 'show_message' );
45
46 if ( 'yes' === $show_message ) {
47 /**
48 * Result retrieved from a transient key.
49 *
50 * @var array|null $result The result retrieved from a transient key or null if not found.
51 */
52 $result = get_transient( FOOGALLERY_EXTENSIONS_MESSAGE_TRANSIENT_KEY );
53
54 if ( $result === false ) {
55 $result = null;
56 }
57 }
58
59 /**
60 * Total count of extensions.
61 *
62 * @var int $total_count The total count of extensions.
63 */
64 $total_count = count( $extensions );
65
66 /**
67 * Count of active extensions.
68 *
69 * @var int $active_count The count of active extensions.
70 */
71 $active_count = count( array_filter( $extensions, function ( $extension ) {
72 return isset( $extension['is_active'] ) && $extension['is_active'];
73 } ) );
74
75 /**
76 * Count of inactive extensions.
77 *
78 * @var int $inactive_count The count of inactive extensions.
79 */
80 $inactive_count = count( array_filter( $extensions, function ( $extension ) {
81 return isset( $extension['is_active'] ) && !$extension['is_active'];
82 } ) );
83
84 /**
85 * Count of extensions with 'Premium' category.
86 *
87 * @var int $premium_count The count of extensions with 'Premium' category.
88 */
89 $premium_count = count( array_filter( $extensions, function ( $extension ) {
90 return in_array( 'Premium', $extension['categories'] );
91 } ) );
92 ?>
93
94 <style>
95 .foogallery-text {
96 font-size: 18px;
97 margin: 10px 0;
98 }
99 /* Define the column widths */
100
101 .column-name {
102 width: 30%;
103 }
104
105 .column-description {
106 width: 60%;
107 }
108
109 .dashicons {
110 font-size: 24px;
111 vertical-align: middle;
112 }
113 .tablenav.top {
114 display:none;
115 }
116 </style>
117 <div class="wrap foogallery-features">
118 <h2>
119 <?php printf( esc_html__( '%s Features', 'foogallery' ), esc_html( foogallery_plugin_name() ) ); ?>
120 <span class="spinner"></span>
121 </h2>
122
123 <?php
124 if ( isset( $result ) ) { ?>
125 <div class="foogallery-message-<?php echo esc_attr( $result['type'] ); ?>">
126 <p><?php echo esc_html( $result['message'] ); ?></p>
127 </div>
128 <?php } ?>
129 <hr />
130 </div>
131
132 <div style="display: flex; justify-content: space-between; align-items: center;">
133 <div class="foogallery-status-tabs">
134 <?php
135 $status_tabs = array(
136 'all' => __( 'All', 'foogallery' ),
137 'active' => __( 'Active', 'foogallery' ),
138 'inactive' => __( 'Inactive', 'foogallery' ),
139 'premium' => __( 'Premium', 'foogallery' ),
140 );
141
142 foreach ( $status_tabs as $status_key => $status_label ) {
143 $is_current = $status_filter === $status_key ? 'current' : '';
144 $text_color = $is_current ? 'color: black;' : 'color: blue;';
145 $status_url = add_query_arg( array( 'status' => $status_key ), foogallery_admin_features_url() );
146
147 echo "<a href='" . esc_url( $status_url ) . "' class='foogallery-status-tab " . esc_attr( $is_current ) . "' style='text-decoration: none; " . esc_attr( $text_color ) . "'>" . esc_html( $status_label ) . " (";
148 if ( $status_key === 'all' ) {
149 echo absint( $total_count );
150 } elseif ( $status_key === 'active' ) {
151 echo absint( $active_count );
152 } elseif ( $status_key === 'inactive' ) {
153 echo absint( $inactive_count );
154 } elseif ( $status_key === 'premium' ) {
155 echo absint( $premium_count );
156 }
157 echo ")</a>";
158 if ( $status_key !== 'premium' ) {
159 echo ' | ';
160 }
161 }
162 ?>
163 </div>
164
165 <form method="get">
166 <input type="hidden" name="post_type" value="foogallery" />
167 <input type="hidden" name="page" value="foogallery-features" />
168 <div style="display:flex; justify-content:space-evenly; align-items:center;">
169
170 <p>
171 <label for="tag-filter"><?php esc_html_e( 'Filter by Tag:', 'foogallery' ); ?></label>
172 <select id="tag-filter" name="tag">
173 <option value="all"><?php esc_html_e( 'All Tags', 'foogallery' ); ?></option>
174 <?php
175 // Get all unique tags from extensions data.
176 $all_tags = array();
177 foreach ( $extensions as $extension ) {
178 if ( isset( $extension['tags'] ) ) {
179 foreach ( $extension['tags'] as $tag ) {
180 if ( !in_array( $tag, $all_tags ) ) {
181 $all_tags[] = $tag;
182 }
183 }
184 }
185 }
186
187 // Output options for each tag.
188 foreach ( $all_tags as $tag ) {
189 $selected = isset( $_GET['tag'] ) && $_GET['tag'] === $tag ? 'selected' : '';
190 echo '<option value="' . esc_attr( $tag ) . '" " . esc_attr( $selected ) . ">' . esc_html( $tag ) . '</option>';
191 }
192 ?>
193 </select>
194 </p>
195
196 <p class="search-box">
197 <label class="screen-reader-text" for="extension-search-input">
198 <?php esc_html_e( 'Search Extensions', 'foogallery' ); ?>:</label>
199 <input type="search" id="extension-search-input" placeholder="Search features..."
200 name="s" value="<?php echo esc_attr( isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '' ); ?>" />
201 </p>
202 </div>
203
204 </form>
205
206 </div>
207
208 <?php
209 if ( $status_filter !== 'all' ) {
210 $extensions = array_filter( $extensions, function ( $extension ) use ( $status_filter ) {
211 if ( $status_filter === 'premium' ) {
212 return in_array( 'Premium', $extension['categories'] );
213 } elseif ( $status_filter === 'active' ) {
214 return isset( $extension['is_active'] ) && $extension['is_active'];
215 } elseif ( $status_filter === 'inactive' ) {
216 return isset( $extension['is_active'] ) && !$extension['is_active'];
217 }
218 return false;
219 } );
220 }
221
222 if ( isset( $_GET['tag'] ) && $_GET['tag'] !== 'all' ) {
223 $tag_to_filter = sanitize_text_field( $_GET['tag'] );
224 $extensions = array_filter( $extensions, function ( $extension ) use ( $tag_to_filter ) {
225 return in_array( $tag_to_filter, $extension['tags'] );
226 } );
227 }
228
229
230 // Define sortable columns.
231 $sortable_columns = array(
232 'name' => 'Name',
233 );
234
235 /**
236 * Class FooGallery_Features_List_Table
237 *
238 * Custom table class to display FooGallery features in the WordPress admin.
239 */
240 class FooGallery_Features_List_Table extends WP_List_Table {
241
242 /**
243 * @var array $extensions An array of extensions data.
244 */
245 private $extensions;
246
247 /**
248 * FooGallery_Features_List_Table constructor.
249 *
250 * @param array $extensions An array of extensions data.
251 */
252 public function __construct( $extensions ) {
253 parent::__construct( array(
254 'singular' => 'extension',
255 'plural' => 'extensions',
256 'ajax' => false,
257 ) );
258
259 $this->extensions = $extensions;
260 }
261
262 /**
263 * Prepare the items for the table to display.
264 */
265 public function prepare_items() {
266 $columns = $this->get_columns();
267 $hidden = array();
268 $sortable = $this->get_sortable_columns();
269
270 $this->_column_headers = array( $columns, $hidden, $sortable );
271
272 // Apply search filter
273 $search = isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
274 if ( ! empty( $search ) ) {
275 $this->extensions = array_filter( $this->extensions, function ( $extension ) use ( $search ) {
276 return stripos( $extension['title'], $search ) !== false || stripos( $extension['description'], $search ) !== false;
277 } );
278 }
279
280 // Apply sorting
281 $orderby = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : 'name';
282 $order = isset( $_GET['order'] ) && in_array( $_GET['order'], [ 'asc', 'desc' ] ) ? $_GET['order'] : 'asc';
283
284 if ( $orderby === 'name' ) {
285 usort( $this->extensions, function ( $a, $b ) use ( $order ) {
286 $result = strcmp( $a['title'], $b['title'] );
287 return $order === 'asc' ? $result : -$result;
288 } );
289 }
290
291 $this->items = $this->extensions;
292 }
293
294 /**
295 * Define the columns for the table.
296 *
297 * @return array An array of column names and labels.
298 */
299 public function get_columns() {
300 return array(
301 'name' => 'Name',
302 'description' => 'Description',
303 );
304 }
305
306
307 /**
308 * Render the default column output.
309 *
310 * @param array $item The item being displayed.
311 * @param string $column_name The name of the current column.
312 *
313 * @return mixed The rendered column content.
314 */
315 public function column_default( $item, $column_name ) {
316 switch ( $column_name ) {
317 case 'name':
318 $upgrade = isset( $item['source'] ) && 'upgrade' === $item['source'];
319 $downloaded = isset( $item['downloaded'] ) && true === $item['downloaded'];
320 $is_active = isset( $item['is_active'] ) && true === $item['is_active'];
321 $has_errors = isset( $item['has_errors'] ) && true === $item['has_errors'];
322 $actions = '';
323 if ( array_key_exists( 'actions_disabled', $item ) && $item['actions_disabled'] === true ) {
324 //Do nothing - there should be no actions.
325 } elseif ( $upgrade ) {
326 $actions .= '<a href="' . esc_url( foogallery_fs()->checkout_url( WP_FS__PERIOD_ANNUALLY, true ) ) . '">' . __( 'Start FREE Trial', 'foogallery' ) . '</a>';
327 } elseif ( !$downloaded ) {
328 $base_url = add_query_arg( array( 'extension' => $item['slug'], '_wpnonce' => wp_create_nonce( 'foogallery_extension_action' ) ) );
329 $download_url = add_query_arg( 'action', 'download', $base_url );
330 $actions .= '<a href="' . esc_url( $download_url ) . '">' . __( 'Download', 'foogallery' ) . '</a>';
331 } elseif ( $is_active ) {
332 $base_url = add_query_arg( array( 'extension' => $item['slug'], '_wpnonce' => wp_create_nonce( 'foogallery_extension_action' ) ) );
333 $deactivate_url = add_query_arg( 'action', 'deactivate', $base_url );
334 $actions .= '<a href="' . esc_url( $deactivate_url ) . '">' . __( 'Deactivate', 'foogallery' ) . '</a>';
335 } else {
336 $base_url = add_query_arg( array( 'extension' => $item['slug'], '_wpnonce' => wp_create_nonce( 'foogallery_extension_action' ) ) );
337 $activate_url = add_query_arg( 'action', 'activate', $base_url );
338 $actions .= '<a href="' . esc_url( $activate_url ) . '">' . __( 'Activate', 'foogallery' ) . '</a>';
339 }
340
341 // Include the icon
342 $icon = '<span class="dashicons ' . $item['dashicon'] . '" style="margin-right: 10px;"></span>';
343
344 return $icon . ' <strong>' . $item['title'] . '</strong><br>' . ' <div style="margin-left: 35px;">' . $actions .'</div>';
345
346 case 'description':
347 $external_link = '';
348 if ( array_key_exists( 'external_link_url', $item ) && array_key_exists( 'external_link_text', $item ) ) {
349 $external_link = '<br><a href="' . esc_url( $item['external_link_url'] ) . '" target="_blank">' . esc_html( $item['external_link_text'] ) . '</a>';
350 }
351
352 return $item['description'] . $external_link;
353
354 default:
355 return isset( $item[ $column_name ] ) ? $item[ $column_name ] : '';
356 }
357 }
358
359
360 /**
361 * Define sortable columns for the table.
362 *
363 * @return array An array of sortable column names.
364 */
365 public function get_sortable_columns() {
366 return array(
367 'name' => array( 'name', true ),
368 );
369 }
370 }
371
372 $extensions_table = new FooGallery_Features_List_Table( $extensions );
373 $extensions_table->prepare_items();
374 $extensions_table->display();
375 ?>
376
377 <script>
378 const searchInput = document.getElementById( 'extension-search-input' );
379 const extensionsTable = document.querySelector( '.wp-list-table' );
380 const tagFilter = document.getElementById( 'tag-filter' );
381
382 searchInput.addEventListener( 'input', function () {
383 const searchTerm = searchInput.value.toLowerCase();
384 Array.from( extensionsTable.querySelectorAll( 'tbody tr' ) ).forEach( function ( row ) {
385 const titleCell = row.querySelector( 'td.column-name' );
386 if ( titleCell ) {
387 const titleText = titleCell.textContent.toLowerCase();
388 if ( titleText.includes( searchTerm ) ) {
389 row.style.display = '';
390 } else {
391 row.style.display = 'none';
392 }
393 }
394 } );
395 } );
396
397 function reloadPageWithFilter() {
398 const selectedTag = tagFilter.value;
399 const currentUrl = window.location.href;
400 const url = new URL( currentUrl );
401 url.searchParams.set( 'tag', selectedTag );
402 window.location.href = url.toString();
403 }
404
405 tagFilter.addEventListener( 'change', reloadPageWithFilter );
406 </script>
407