|
4 | 4 | } // Exit if accessed directly
|
5 | 5 |
|
6 | 6 |
|
| 7 | +class DT_Storage { |
| 8 | + |
| 9 | + /** |
| 10 | + * @return object|null |
| 11 | + */ |
| 12 | + private static function get_connection(){ |
| 13 | + $media_connection_id = dt_get_option( 'dt_media_connection_id' ); |
| 14 | + if ( empty( $media_connection_id ) ) { |
| 15 | + return null; |
| 16 | + } |
| 17 | + return Disciple_Tools_Media_API::fetch_option_connection_obj( $media_connection_id ); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * @return bool |
| 22 | + */ |
| 23 | + public static function is_enabled(): bool { |
| 24 | + $connection = self::get_connection(); |
| 25 | + return !empty( $connection ) && isset( $connection->enabled ) && $connection->enabled; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @param string $key |
| 30 | + * @return string |
| 31 | + */ |
| 32 | + public static function get_file_url( string $key ): string { |
| 33 | + $connection = self::get_connection(); |
| 34 | + if ( !empty( $connection ) ) { |
| 35 | + return dt_media_connections_obj_url( null, $connection->id, $key, [ 'keep_alive' => '+24 hours' ] ); |
| 36 | + } |
| 37 | + return ''; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @param string $key_prefix like 'users', 'contacts', 'comments |
| 42 | + * @param array $upload |
| 43 | + * @param string $existing_key |
| 44 | + * @return false|mixed |
| 45 | + */ |
| 46 | + public static function upload_file( string $key_prefix = '', array $upload = [], string $existing_key = '' ){ |
| 47 | + $key_prefix = trailingslashit( $key_prefix ); |
| 48 | + $connection = self::get_connection(); |
| 49 | + $args = [ |
| 50 | + 'auto_generate_key' => empty( $existing_key ), |
| 51 | + 'include_extension' => empty( $existing_key ), |
| 52 | + 'default_key' => $existing_key |
| 53 | + ]; |
| 54 | + if ( !empty( $connection ) ) { |
| 55 | + return dt_media_connections_obj_upload( null, $connection->id, $key_prefix, $upload, $args ); |
| 56 | + } |
| 57 | + return false; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
7 | 64 | add_filter( 'dt_media_connection_types', 'dt_media_connection_types', 10, 1 );
|
8 | 65 | function dt_media_connection_types( $connection_types ) {
|
9 | 66 | foreach ( Disciple_Tools_Media_API::list_supported_connection_types() as $key => $type ) {
|
|
0 commit comments