PluginProbe
Media Cloud Sync / 1.0.2
Media Cloud Sync v1.0.2
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.0.2, at includes/integrations/media-library.php

143 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 global $wpmcsItem;
42 $post = get_post();
43 $attachment_id = $post->ID;
44
45 if (!Utils::is_ok_to_serve($attachment_id)) {
46 return;
47 }
48
49 $item = $wpmcsItem->get($attachment_id);
50
51 if (Utils::is_empty($item)) {
52 return;
53 }
54
55 $provider = $wpmcsItem->get_field($attachment_id, 'provider');
56 if($provider) {
57 $label = Schema::getServiceLabels($provider); ?>
58 <div class="misc-pub-section misc-pub-provider">
59 <?php esc_html_e( 'Provider :', 'media-cloud-sync' ); ?> <strong><?php echo esc_textarea(!empty($label) ? $label : $provider); ?></strong></a>
60 </div>
61 <?php
62 }
63
64 $region = $wpmcsItem->get_field($attachment_id, 'region');
65 if($region) { ?>
66 <div class="misc-pub-section misc-pub-provider">
67 <?php esc_html_e( 'Region :', 'media-cloud-sync' ); ?> <strong><?php echo esc_textarea($region); ?></strong></a>
68 </div>
69 <?php
70 }
71 $private = (int)$wpmcsItem->get_field($attachment_id, 'is_private');
72 ?>
73 <div class="misc-pub-section misc-pub-provider">
74 <?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>
75 </div>
76 <?php
77 }
78
79
80 /**
81 * Function to get attachment details by ID
82 */
83 public function ajax_get_attachment_details() {
84 $result = array(
85 'status' => false,
86 'data' => array(),
87 'exclude' => false
88 );
89
90 if ( ! isset( $_POST['id'] ) ) {
91 wp_send_json_success( $result );
92 }
93
94 check_ajax_referer( 'get_media_provider_details', '_nonce' );
95
96 $id= intval( sanitize_text_field( $_POST['id'] ) );
97 global $wpmcsItem;
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 $item = $wpmcsItem->get($id);
111
112 if (Utils::is_empty($item)) {
113 wp_send_json_success( $result );
114 }
115
116 $provider = $wpmcsItem->get_field($id, 'provider');
117 if($provider){
118 $label = Schema::getServiceLabels($provider);
119 $item['provider'] = !empty($label) ? $label : $provider;
120 }
121 $region = $wpmcsItem->get_field($id, 'region');
122 if($region){
123 $item['region'] = $region;
124 }
125 $item['private'] = $wpmcsItem->get_field($id, 'private');
126 if($item) {
127 $result= array(
128 'status' => true,
129 'data' => $item
130 );
131 }
132
133 wp_send_json_success( $result );
134 }
135
136
137 public static function instance(){
138 if (is_null(self::$instance)) {
139 self::$instance = new self();
140 }
141 return self::$instance;
142 }
143 }