PluginProbe
bbPress / 2.6.19
bbPress v2.6.19
2.6.19 2.6.18 2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 All 74 releases
bbpress / includes / admin / tools / converter.php

converter.php in bbPress 2.6.19, at includes/admin/tools/converter.php

118 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * bbPress Converter
5 *
6 * Based on the hard work of Adam Ellis
7 *
8 * @package bbPress
9 * @subpackage Administration
10 */
11
12 // Exit if accessed directly
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Return an array of available converters
17 *
18 * @since 2.6.0 bbPress (r6448)
19 *
20 * @return array
21 */
22 function bbp_get_converters() {
23 static $files = array();
24
25 // Only hit the file system one time per page load
26 if ( empty( $files ) ) {
27
28 // Open the converter directory
29 $path = bbp_setup_converter()->converters_dir;
30 $curdir = opendir( $path );
31
32 // Look for the converter file in the converters directory
33 if ( false !== $curdir ) {
34 while ( $file = readdir( $curdir ) ) {
35 if ( stristr( $file, '.php' ) && stristr( $file, 'index' ) === false ) {
36 $name = preg_replace( '/.php/', '', $file );
37 if ( 'Example' !== $name ) {
38 $files[ $name ] = $path . $file;
39 }
40 }
41 }
42 }
43
44 // Close the directory
45 closedir( $curdir );
46
47 // Sort keys alphabetically, ignoring upper/lower casing
48 if ( ! empty( $files ) ) {
49 natcasesort( $files );
50 }
51 }
52
53 // Filter & return
54 return (array) apply_filters( 'bbp_get_converters', $files );
55 }
56
57 /**
58 * Check a source database table prefix before using it in converter queries.
59 *
60 * @since 2.6.19 bbPress (r7737)
61 *
62 * @param mixed $prefix Source database table prefix.
63 * @return bool Whether the prefix contains only valid table-prefix characters.
64 */
65 function bbp_is_valid_converter_prefix( $prefix ) {
66 return is_string( $prefix ) && ( 0 === preg_match( '|[^a-z0-9_]|i', $prefix ) );
67 }
68
69 /**
70 * This is a function that is purposely written to look like a "new" statement.
71 * It is basically a dynamic loader that will load in the platform conversion
72 * of your choice.
73 *
74 * @since 2.1.0 bbPress (r3816)
75 *
76 * @param string $platform Name of valid platform class.
77 *
78 * @return mixed Object if converter exists, null if not
79 */
80 function bbp_new_converter( $platform = '' ) {
81
82 // Default converter
83 $converter = null;
84
85 // Bail if no platform
86 if ( empty( $platform ) ) {
87 return $converter;
88 }
89
90 // Never build source-table queries with an invalid saved prefix.
91 if ( ! bbp_is_valid_converter_prefix( get_option( '_bbp_converter_db_prefix', '' ) ) ) {
92 return $converter;
93 }
94
95 // Get the available converters
96 $converters = bbp_get_converters();
97
98 // Get the converter file form converters array
99 $converter_file = isset( $converters[ $platform ] )
100 ? $converters[ $platform ]
101 : '';
102
103 // Try to create a new converter object
104 if ( ! empty( $converter_file ) ) {
105
106 // Try to include the converter
107 @include_once $converter_file;
108
109 // Try to instantiate the converter object
110 if ( class_exists( $platform ) ) {
111 $converter = new $platform();
112 }
113 }
114
115 // Filter & return
116 return apply_filters( 'bbp_new_converter', $converter, $platform );
117 }
118