PluginProbe
Button Generator – Easily Create Custom Buttons with Icons and Analytics / 3.2
Button Generator – Easily Create Custom Buttons with Icons and Analytics v3.2
trunk 1.1.1 2.0 2.1 2.2 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.2 3.1.3 3.2 3.2.1 3.2.2 3.2.3 All 28 releases
button-generation / classes / Admin / DashboardHelper.php

DashboardHelper.php in Button Generator – Easily Create Custom Buttons with Icons and Analytics 3.2, at classes/Admin/DashboardHelper.php

99 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class DashboardHelper
5 *
6 * Helper class for managing the dashboard.
7 *
8 * @package WowPlugin
9 * @subpackage Admin
10 * @author Dmytro Lobov <dev@wow-company.com>, Wow-Company
11 * @copyright 2024 Dmytro Lobov
12 * @license GPL-2.0+
13 *
14 */
15
16 namespace ButtonGenerator\Admin;
17
18 defined( 'ABSPATH' ) || exit;
19
20 use ButtonGenerator\WOWP_Plugin;
21
22 class DashboardHelper {
23
24 public static function first_file( $folder ) {
25
26 $files = self::get_files( $folder );
27 if ( empty( $files ) ) {
28 return false;
29 }
30
31 return reset( $files )['file'];
32 }
33
34 public static function get_files( $folder ): array {
35 $scan_files = scandir( self::get_folder_path( $folder ) );
36 $files = [];
37 foreach ( $scan_files as $file ) {
38 if ( $file === '.' || $file === '..' || $file === 'index.php' ) {
39 continue;
40 }
41 $extension = pathinfo( $file, PATHINFO_EXTENSION );
42
43 $matches = explode( '.', $file );
44
45 if ( ! is_numeric( $matches[0] ) ) {
46 continue;
47 }
48
49 $file_name = self::get_file_name( $file, $folder );
50
51 $files[ $matches[0] ] = [ 'file' => $matches[1], 'name' => $file_name ];
52 }
53
54 return $files;
55 }
56
57 public static function get_file_name( $file, $folder ): string {
58
59 $file_path = self::get_folder_path( $folder ) . '/' . $file;
60 $file_data = get_file_data( $file_path, array( 'name' => 'Page Name' ) );
61
62 return $file_data['name'];
63
64 }
65
66 public static function get_folder_path( $folder ): string {
67 return WOWP_Plugin::dir() . 'admin/' . $folder;
68 }
69
70 public static function get_file( $current, $folder ) {
71 $files = scandir( self::get_folder_path( $folder ) );
72 foreach ( $files as $file ) {
73 $matches = explode( '.', $file );
74 if ( isset( $matches[1] ) && $matches[1] === $current ) {
75 return $file;
76 }
77 }
78
79 return false;
80 }
81
82 public static function search_value( $array, $value ): bool {
83
84 foreach ( $array as $item ) {
85 if ( is_array( $item ) ) {
86 if ( self::search_value( $item, $value ) ) {
87 return true;
88 }
89 } else {
90 if ( $item === $value ) {
91 return true;
92 }
93 }
94 }
95
96 return false;
97 }
98
99 }