PluginProbe
Image Source Control Lite – Show Image Credits and Captions / trunk
Image Source Control Lite – Show Image Credits and Captions vtrunk
3.12.0 3.11.0 trunk 1.1 1.1.1 1.1.2 1.1.2.1 1.1.3 1.10 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.2 1.2.0.1 1.2.0.2 1.2.0.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.4.1 1.3.5 All 110 releases
image-source-control-isc / includes / image-sources / utils.php

utils.php in Image Source Control Lite – Show Image Credits and Captions trunk, at includes/image-sources/utils.php

42 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ISC\Image_Sources;
4
5 /**
6 * Image Sources Utils
7 */
8 class Utils {
9 /**
10 * Transform the licenses from the options textfield into an array
11 *
12 * @param string $licences text with licenses.
13 * @return array|bool $new_licences array with licenses and license information or false if no array created.
14 */
15 public static function licences_text_to_array( $licences = '' ) {
16 if ( $licences === '' ) {
17 return false;
18 }
19 // split the text by line
20 $licences_array = preg_split( '/\r?\n/', trim( $licences ) );
21 if ( count( $licences_array ) === 0 ) {
22 return false;
23 }
24 // create the array with licence => url
25 $new_licences = [];
26 foreach ( $licences_array as $_licence ) {
27 if ( trim( $_licence ) !== '' ) {
28 $temp = explode( '|', $_licence );
29 $new_licences[ $temp[0] ] = [];
30 if ( isset( $temp[1] ) ) {
31 $new_licences[ $temp[0] ]['url'] = esc_url( $temp[1] );
32 }
33 }
34 }
35
36 if ( $new_licences === [] ) {
37 return false;
38 } else {
39 return $new_licences;
40 }
41 }
42 }