forked from bpiwowar/papercite
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpapercite_helpers.php
61 lines (53 loc) · 1.31 KB
/
papercite_helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Created by PhpStorm.
* User: sam
* Date: 25-03-2019
* Time: 12:53
*/
/**
* Flatten a multi-dimensional array (@see https://davidwalsh.name/flatten-nested-arrays-php)
*
* @param $array
* @param $return
*
* @return array
*/
function array_flatten( $array, $return ) {
for ( $x = 0; $x <= count( $array ); $x ++ ) {
if ( isset( $array[ $x ] ) && is_array( $array[ $x ] ) ) {
$return = array_flatten( $array[ $x ], $return );
} else {
if ( isset( $array[ $x ] ) ) {
$return[] = $array[ $x ];
}
}
}
return $return;
}
/**
* list all avaiable formatting files
*
* @param $format_type tpl or csl (default 'tpl')
*
* @return a list with the filenames without the extensions
*/
function papercite_list_formats( $format_type = 'tpl' ) {
$path = null;
switch ( $format_type ) {
case 'tpl':
$path = plugin_dir_path( __FILE__ ) . "/format";
break;
case 'csl':
// $path = plugin_dir_path( __FILE__ ) . "/vendor/citation-style-language/styles-distribution";
$path = plugin_dir_path( __FILE__ ) . "/" . CSL_STYLES_LOCATION;
break;
}
$formats_list = list_files( $path );
return array_map( function ( $tpl_filename ) {
return pathinfo( $tpl_filename, PATHINFO_FILENAME );
}, $formats_list );
}
function papercite_list_csl_formats() {
return papercite_list_formats( 'csl' );
}