PluginProbe
FV Player 8 / trunk
FV Player 8 vtrunk
trunk 8.0.18 8.0.19 8.0.20 8.0.21 8.0.25 8.0.27 8.1 8.1.3
fv-player / models / linode-object-storage-browser.class.php

linode-object-storage-browser.class.php in FV Player 8 trunk, at models/linode-object-storage-browser.class.php

145 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if( !class_exists('FV_Player_Linode_Object_Storage_Browser') && class_exists('FV_Player_Media_Browser') ) :
8
9 class FV_Player_Linode_Object_Storage_Browser extends FV_Player_Media_Browser {
10
11 function init() {
12 if( $this->isSetUpCorrectly() ) {
13 global $fv_wp_flowplayer_ver;
14 wp_enqueue_script( 'fv-player-linode-browser', flowplayer::get_plugin_url().'/js/linode-object-storage.js', array( 'flowplayer-browser-base' ), $fv_wp_flowplayer_ver );
15 wp_localize_script( 'fv-player-linode-browser', 'fv_player_linode_object_storage', array(
16 'nonce' => wp_create_nonce( $this->ajax_action_name ),
17 )
18 );
19 }
20 }
21
22 function decode_link_components( $link ) {
23 $url_components = wp_parse_url($link);
24 $link = str_replace( $url_components['path'], urldecode($url_components['path']), $link );
25
26 return $link;
27 }
28
29 function get_custom_domain_url( $link, $bucket, $custom_domain ) {
30 // TODO: check and implement custom domain URLs - replace link with Custom Domain URL, if we have one
31 return $link;
32 }
33
34 // Legacy
35 function init_for_gutenberg() {}
36
37 function get_s3_client() {
38 global $fv_fp, $FV_Player_Linode_Object_Storage;
39
40 // instantiate the S3 client with AWS credentials
41 $endpoint = 'https://' . $FV_Player_Linode_Object_Storage->get_endpoint();
42
43 $region = $FV_Player_Linode_Object_Storage->get_region();
44
45 $secret = $fv_fp->_get_option(array('linode_object_storage','secret'));
46 $key = $fv_fp->_get_option(array('linode_object_storage','key'));
47
48 $credentials = new Aws\Credentials\Credentials( $key, $secret );
49
50 return Aws\S3\S3Client::factory( array(
51 'credentials' => $credentials,
52 'region' => $region,
53 'version' => 'latest',
54 'endpoint' => $endpoint,
55 'use_aws_shared_config_files' => false
56 ) );
57 }
58
59 function get_formatted_assets_data() {
60 if( !isset($_POST['nonce']) || !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), $this->ajax_action_name ) ) {
61 return array(
62 'items' => array(),
63 'name' => '/',
64 'path' => '/',
65 'type' => 'folder',
66 'err' => 'Invalid nonce'
67 );
68 }
69
70 $this->include_aws_sdk();
71 global $fv_fp, $s3Client;
72
73 $bucket = $fv_fp->_get_option(array('linode_object_storage','space'));
74 //$domain = $fv_fp->_get_option(array('linode_object_storage','space'));
75
76 $output = $this->get_output();
77
78 // instantiate the S3 client with AWS credentials
79 $s3Client = $this->get_s3_client();
80
81 try {
82
83 list( $request_path, $paged, $date_format ) = $this->get_metadata( $s3Client, $bucket );
84
85 list($output, $sum_up ) = $this->get_output_items( $output, $s3Client, $request_path, $paged, $date_format, $bucket );
86
87 } catch ( Aws\S3\Exception\S3Exception $e ) {
88 //echo $e->getMessage() . "\n";
89 $err = $e->getMessage();
90 $output = array(
91 'items' => array(),
92 'name' => '/',
93 'path' => '/',
94 'type' => 'folder'
95 );
96 }
97
98 // sorting by date, descending
99 // TODO: Make this an interface option? How to handle it for paged listings, like on Vimeo?
100 function FV_Player_Linode_Object_Storage_Browser_date_compare($a, $b) {
101 $t1 = strtotime($a['LastModified']);
102 $t2 = strtotime($b['LastModified']);
103 return $t1 - $t2;
104 }
105
106 usort($output['items'], 'FV_Player_Linode_Object_Storage_Browser_date_compare');
107
108 $output['items'] = array_reverse($output['items']);
109
110 $json_final = array(
111 'items' => $output
112 );
113
114 if (isset($err) && $err) {
115 $json_final['err'] = $err;
116 }
117
118 return $json_final;
119 }
120
121 function load_assets() {
122 $json_final = $this->get_formatted_assets_data();
123
124 wp_send_json( $json_final );
125 wp_die();
126 }
127
128 public function isSetUpCorrectly() {
129 global $fv_fp;
130
131 return (
132 $fv_fp->_get_option(array('linode_object_storage','endpoint'))
133 && $fv_fp->_get_option(array('linode_object_storage','secret'))
134 && $fv_fp->_get_option(array('linode_object_storage','key'))
135 && $fv_fp->_get_option(array('linode_object_storage','space'))
136 );
137 }
138
139 }
140
141 global $FV_Player_Linode_Object_Storage_Browser;
142 $FV_Player_Linode_Object_Storage_Browser = new FV_Player_Linode_Object_Storage_Browser( 'wp_ajax_load_linode_object_storage_assets' );
143
144 endif;
145