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