PluginProbe
Media Cloud Sync / 1.2.8
Media Cloud Sync v1.2.8
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
media-cloud-sync / includes / integrations / media-library.php

media-library.php in Media Cloud Sync 1.2.8, at includes/integrations/media-library.php

145 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Dudlewebs\WPMCS;
3
4 defined('ABSPATH') || exit;
5
6 class MediaLibrary {
7 private static $instance = null;
8 private $assets_url;
9 private $version;
10 private $token;
11
12 /**
13 * Admin constructor.
14 * @since 1.0.0
15 */
16 public function __construct() {
17 $this->assets_url = WPMCS_ASSETS_URL;
18 $this->version = WPMCS_VERSION;
19 $this->token = WPMCS_TOKEN;
20
21 // Initialize setup
22 $this->registerActions();
23 }
24
25 /**
26 * Register integration access
27 */
28 public function registerActions() {
29 /** IMAGE EDITOR COMPATIBILITY */
30 add_action( 'attachment_submitbox_misc_actions', array( $this, 'attachment_submitbox_metadata'),99 );
31 //Media Modal Ajax
32 add_action( 'wp_ajax_wpmcs_get_attachment_details', array( $this, 'ajax_get_attachment_details' ) );
33 }
34
35
36 /**
37 * Edit Image Meta In View Image
38 * @since 1.0.0
39 */
40 function attachment_submitbox_metadata( ) {
41 $post = get_post();
42 $attachment_id = $post->ID;
43
44 if (!Utils::is_ok_to_serve($attachment_id)) {
45 return;
46 }
47
48 $wpmcsItem = Item::instance();
49
50 $item = $wpmcsItem->get($attachment_id);
51
52 if (Utils::is_empty($item)) {
53 return;
54 }
55
56 $provider = $wpmcsItem->get_field($attachment_id, 'provider');
57 if($provider) {
58 $label = Schema::getServiceLabels($provider); ?>
59 <div class="misc-pub-section misc-pub-provider">
60 <?php esc_html_e( 'Provider :', 'media-cloud-sync' ); ?> <strong><?php echo esc_textarea(!empty($label) ? $label : $provider); ?></strong></a>
61 </div>
62 <?php
63 }
64
65 $region = $wpmcsItem->get_field($attachment_id, 'region');
66 if($region) { ?>
67 <div class="misc-pub-section misc-pub-provider">
68 <?php esc_html_e( 'Region :', 'media-cloud-sync' ); ?> <strong><?php echo esc_textarea($region); ?></strong></a>
69 </div>
70 <?php
71 }
72 $private = (int)$wpmcsItem->get_field($attachment_id, 'is_private');
73 ?>
74 <div class="misc-pub-section misc-pub-provider">
75 <?php esc_html_e( 'Access :', 'media-cloud-sync' ); ?> <strong><?php $private ? esc_html_e( 'Private', 'media-cloud-sync' ) : esc_html_e( 'Public', 'media-cloud-sync' ); ?></strong></a>
76 </div>
77 <?php
78 }
79
80
81 /**
82 * Function to get attachment details by ID
83 */
84 public function ajax_get_attachment_details() {
85 $result = array(
86 'status' => false,
87 'data' => array(),
88 'exclude' => false
89 );
90
91 if ( ! isset( $_POST['id'] ) ) {
92 wp_send_json_success( $result );
93 }
94
95 check_ajax_referer( 'get_media_provider_details', '_nonce' );
96
97 $id= intval( sanitize_text_field( $_POST['id'] ) );
98
99 // Return if extension not allowed
100 $path = get_attached_file( $id );
101 if(!Utils::is_extension_available($path)) {
102 $result['exclude'] = true;
103 wp_send_json_success( $result );
104 }
105
106 if (!Utils::is_ok_to_serve($id)) {
107 wp_send_json_success( $result );
108 }
109
110 $wpmcsItem = Item::instance();
111
112 $item = $wpmcsItem->get($id);
113
114 if (Utils::is_empty($item)) {
115 wp_send_json_success( $result );
116 }
117
118 $provider = $wpmcsItem->get_field($id, 'provider');
119 if($provider){
120 $label = Schema::getServiceLabels($provider);
121 $item['provider'] = !empty($label) ? $label : $provider;
122 }
123 $region = $wpmcsItem->get_field($id, 'region');
124 if($region){
125 $item['region'] = $region;
126 }
127 $item['private'] = $wpmcsItem->get_field($id, 'private');
128 if($item) {
129 $result= array(
130 'status' => true,
131 'data' => $item
132 );
133 }
134
135 wp_send_json_success( $result );
136 }
137
138
139 public static function instance(){
140 if (is_null(self::$instance)) {
141 self::$instance = new self();
142 }
143 return self::$instance;
144 }
145 }