PluginProbe
OPcache Manager / 3.3.0
OPcache Manager v3.3.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.13.0 2.13.1 2.14.0 2.2.0 2.3.0 2.3.1 2.3.2 2.4.0 2.5.0 2.6.0 All 36 releases
opcache-manager / includes / libraries / class-libraries.php

class-libraries.php in OPcache Manager 3.3.0, at includes/libraries/class-libraries.php

259 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Libraries handling
4 *
5 * Handles all libraries (vendor) operations and versioning.
6 *
7 * @package Libraries
8 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
9 * @since 1.0.0
10 */
11
12 namespace OPcacheManager\Library;
13
14 use OPcacheManager\System\L10n;
15
16 /**
17 * Define the libraries functionality.
18 *
19 * Handles all libraries (vendor) operations and versioning.
20 *
21 * @package System
22 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
23 * @since 1.0.0
24 */
25 class Libraries {
26
27 /**
28 * The array of PSR-4 libraries used by the plugin.
29 *
30 * @since 1.0.0
31 * @access private
32 * @var array $libraries The PSR-4 libraries used by the plugin.
33 */
34 private static $psr4_libraries;
35
36 /**
37 * The array of mono libraries used by the plugin.
38 *
39 * @since 1.0.0
40 * @access private
41 * @var array $libraries The mono libraries used by the plugin.
42 */
43 private static $mono_libraries;
44
45 /**
46 * Initializes the class and set its properties.
47 *
48 * @since 1.0.0
49 */
50 public function __construct() {
51 self::init();
52 }
53
54 /**
55 * Defines all needed libraries.
56 *
57 * @since 1.0.0
58 */
59 public static function init() {
60 self::$psr4_libraries = [];
61 self::$psr4_libraries['feather'] = [
62 'name' => 'Feather',
63 'prefix' => 'Feather',
64 'base' => OPCM_VENDOR_DIR . 'feather/',
65 'version' => '4.24.1',
66 // phpcs:ignore
67 'author' => 'Cole Bemis',
68 'url' => 'https://feathericons.com',
69 'license' => 'mit',
70 'langs' => 'en',
71 ];
72 self::$psr4_libraries['markdown'] = [
73 'name' => 'Markdown Parser',
74 'prefix' => 'cebe\markdownparser',
75 'base' => OPCM_VENDOR_DIR . 'markdown/',
76 'version' => '1.2.1',
77 // phpcs:ignore
78 'author' => 'Carsten Brandt',
79 'url' => 'https://github.com/cebe/markdown',
80 'license' => 'mit',
81 'langs' => 'en',
82 ];
83 if ( function_exists( 'decalog_get_psr_log_version' ) ) {
84 $psrlog_version = decalog_get_psr_log_version();
85 } else {
86 $psrlog_version = 1;
87 }
88 self::$psr4_libraries['psr-03'] = [
89 'name' => 'PSR-3',
90 'prefix' => 'Psr\\Log',
91 'base' => OPCM_VENDOR_DIR . 'psr/log-v' . $psrlog_version . '/',
92 'version' => $psrlog_version . '.0.0',
93 'author' => 'PHP Framework Interop Group',
94 'url' => 'https://www.php-fig.org/',
95 'license' => 'mit',
96 'langs' => 'en',
97 ];
98 self::$psr4_libraries['psr-07'] = [
99 'name' => 'PSR-7',
100 'prefix' => 'Psr\\Http\\Message',
101 'base' => OPCM_VENDOR_DIR . 'psr/http-message/',
102 'version' => '2.0',
103 'author' => 'PHP Framework Interop Group',
104 'url' => 'https://www.php-fig.org/',
105 'license' => 'mit',
106 'langs' => 'en',
107 ];
108 self::$psr4_libraries['psr-18'] = [
109 'name' => 'PSR-18',
110 'prefix' => 'Psr\\Http\\Client',
111 'base' => OPCM_VENDOR_DIR . 'psr/http-client/',
112 'version' => '1.0.3',
113 'author' => 'PHP Framework Interop Group',
114 'url' => 'https://www.php-fig.org/',
115 'license' => 'mit',
116 'langs' => 'en',
117 ];
118 self::$psr4_libraries['decalog-sdk'] = [
119 'name' => 'DecaLog SDK',
120 'prefix' => 'DecaLog',
121 'base' => OPCM_VENDOR_DIR . 'decalog-sdk/',
122 'version' => '4.2.0',
123 'author' => 'Pierre Lannoy',
124 'url' => 'https://github.com/Pierre-Lannoy/wp-decalog-sdk',
125 'license' => 'mit',
126 'langs' => 'en',
127 ];
128 self::$mono_libraries = [];
129 }
130
131 /**
132 * Get PSR-4 libraries.
133 *
134 * @return array The list of defined PSR-4 libraries.
135 * @since 1.0.0
136 */
137 public static function get_psr4() {
138 return self::$psr4_libraries;
139 }
140
141 /**
142 * Get mono libraries.
143 *
144 * @return array The list of defined mono libraries.
145 * @since 1.0.0
146 */
147 public static function get_mono() {
148 return self::$mono_libraries;
149 }
150
151 /**
152 * Get the full license name.
153 *
154 * @param string $license The license id.
155 * @return string The full license name.
156 * @since 1.0.0
157 */
158 private function license_name( $license ) {
159 switch ( $license ) {
160 case 'mit':
161 $result = esc_html__( 'MIT license', 'opcache-manager' );
162 break;
163 case 'apl2':
164 $result = esc_html__( 'Apache license, version 2.0', 'opcache-manager' );
165 break;
166 case 'gpl2':
167 $result = esc_html__( 'GPL-2.0 license', 'opcache-manager' );
168 break;
169 case 'gpl3':
170 $result = esc_html__( 'GPL-3.0 license', 'opcache-manager' );
171 break;
172 default:
173 $result = esc_html__( 'unknown license', 'opcache-manager' );
174 break;
175 }
176 return $result;
177 }
178
179 /**
180 * Get the libraries list.
181 *
182 * @param array $attributes 'style' => 'html'.
183 * @return string The output of the shortcode, ready to print.
184 * @since 1.0.0
185 */
186 public function sc_get_list( $attributes ) {
187 $_attributes = shortcode_atts(
188 [
189 'style' => 'html',
190 ],
191 $attributes
192 );
193 $style = $_attributes['style'];
194 $result = '';
195 $list = [];
196 foreach ( array_merge( self::get_psr4(), self::get_mono() ) as $library ) {
197 $item = [];
198 $item['name'] = $library['name'];
199 $item['version'] = $library['version'];
200 $item['author'] = $library['author'];
201 $item['url'] = $library['url'];
202 $item['license'] = $this->license_name( $library['license'] );
203 $item['langs'] = L10n::get_language_markup( explode( ',', $library['langs'] ) );
204 $list[] = $item;
205 }
206 $item = [];
207 $item['name'] = 'Plugin Boilerplate';
208 $item['version'] = '1.0.0';
209 $item['author'] = 'Pierre Lannoy';
210 $item['url'] = 'https://github.com/Pierre-Lannoy/wp-' . 'plugin-' . 'boilerplate';
211 $item['license'] = $this->license_name( 'gpl3' );
212 $item['langs'] = L10n::get_language_markup( [ 'en' ] );
213 $list[] = $item;
214 $item = [];
215 $item['name'] = 'Date Range Picker';
216 $item['version'] = '3.0.5';
217 $item['author'] = 'Dan Grossman';
218 $item['url'] = 'https://github.com/dangrossman/daterangepicker';
219 $item['license'] = $this->license_name( 'mit' );
220 $item['langs'] = L10n::get_language_markup( [ 'en' ] );
221 $list[] = $item;
222 $item = [];
223 $item['name'] = 'Moment';
224 $item['version'] = '2.29.4';
225 $item['author'] = 'Tim Wood';
226 $item['url'] = 'https://github.com/moment/moment';
227 $item['license'] = $this->license_name( 'mit' );
228 $item['langs'] = L10n::get_language_markup( [ 'en' ] );
229 $list[] = $item;
230 $item['name'] = 'SVG-Loaders';
231 $item['version'] = '1.0.2';
232 $item['author'] = 'Sam Herbert';
233 $item['url'] = 'https://github.com/SamHerbert/SVG-Loaders';
234 $item['license'] = $this->license_name( 'mit' );
235 $item['langs'] = L10n::get_language_markup( [ 'en' ] );
236 $list[] = $item;
237 $item['name'] = 'Chartist-JS';
238 $item['version'] = '0.11.4';
239 $item['author'] = 'Gion Kunz';
240 $item['url'] = 'https://github.com/gionkunz/chartist-js';
241 $item['license'] = $this->license_name( 'mit' );
242 $item['langs'] = L10n::get_language_markup( [ 'en' ] );
243 $list[] = $item;
244 usort( $list, function ( $a, $b ) { return strcmp( strtolower( $a['name'] ), strtolower( $b['name'] ) );} );
245 if ( 'html' === $style ) {
246 $items = [];
247 foreach ( $list as $library ) {
248 /* translators: as in the sentence "Product W version X by author Y (license Z)" */
249 $items[] = sprintf( __( '<a href="%1$s">%2$s %3$s</a>%4$s by %5$s & contributors (%6$s)', 'opcache-manager' ), $library['url'], $library['name'], 'v' . $library['version'], $library['langs'], $library['author'], $library['license'] );
250 }
251 $result = implode( ', ', $items );
252 }
253 return $result;
254 }
255
256 }
257
258 Libraries::init();
259