10 |
--------------------------------------------------------------------------------
/templates/dirmaker.html:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/assets/folder.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/templates/display.php:
--------------------------------------------------------------------------------
1 |
4 |
5 |
8 |
9 |
19 |
--------------------------------------------------------------------------------
/templates/uploader.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
{{data.dropHelp}}
5 |
{{data.dropOr}}
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/js/display.min.js:
--------------------------------------------------------------------------------
1 | /*! mediatheque - v1.4.0-alpha - 2021-09-05 2:16:43 PM UTC - https://imathi.eu/tag/mediatheque */
2 |
3 | window.wp=window.wp||{},window.mediaTheque=window.mediaTheque||_.extend({},_.pick(window.wp,"Backbone","template")),function(e){mediaTheque.Models=mediaTheque.Models||{},mediaTheque.Collections=mediaTheque.Collections||{},mediaTheque.Views=mediaTheque.Views||{},mediaTheque.Display={init:function(){this.views=new Backbone.Collection,this.userMedia=new wp.api.collections.UserMedia,this.queryVars=new Backbone.Model,this.View=new mediaTheque.Views.Display({el:e("#mediatheque-container"),media:this.userMedia,queryVars:this.queryVars}).render()}},wp.api.loadPromise.done(function(){mediaTheque.Display.init()})}(jQuery);
--------------------------------------------------------------------------------
/templates/user-media-trail.html:
--------------------------------------------------------------------------------
1 | <# if ( data.avatar_urls ) { #>
2 |
3 | <# if ( data.avatar_urls[24] ) { #>
4 |
5 | <# } else { #>
6 | {{data.name}}
7 | <# } #>
8 |
9 | <# } else if ( data.position ) { #>
10 |
11 | <# if ( data.showLink ) { #>
12 | {{data.name}}
13 | <# } else { #>
14 | {{data.name}}
15 | <# } #>
16 |
17 | <# } else if ( data.showLink ) { #>
18 |
{{{data.title.rendered}}}
19 | <# } else { #>
20 |
{{{data.title.rendered}}}
21 | <# } #>
22 |
--------------------------------------------------------------------------------
/js/display.js:
--------------------------------------------------------------------------------
1 | /* global wp, _, mediaTheque */
2 |
3 | // Make sure the wp object exists.
4 | window.wp = window.wp || {};
5 | window.mediaTheque = window.mediaTheque || _.extend( {}, _.pick( window.wp, 'Backbone', 'template' ) );
6 |
7 | ( function( $ ) {
8 |
9 | mediaTheque.Models = mediaTheque.Models || {};
10 | mediaTheque.Collections = mediaTheque.Collections || {};
11 | mediaTheque.Views = mediaTheque.Views || {};
12 |
13 | mediaTheque.Display = {
14 | init: function() {
15 | this.views = new Backbone.Collection();
16 | this.userMedia = new wp.api.collections.UserMedia();
17 | this.queryVars = new Backbone.Model();
18 |
19 | this.View = new mediaTheque.Views.Display( {
20 | el: $( '#mediatheque-container' ),
21 | media: this.userMedia,
22 | queryVars: this.queryVars
23 | } ).render();
24 | }
25 | };
26 |
27 | wp.api.loadPromise.done( function() {
28 | mediaTheque.Display.init();
29 | } );
30 |
31 | } )( jQuery );
32 |
--------------------------------------------------------------------------------
/assets/uploader.min.css:
--------------------------------------------------------------------------------
1 | #drag-drop-area.supports-drag-drop{position:relative;top:auto;right:auto;left:auto;bottom:auto;padding-top:0;margin-top:0;border:4px dashed #b4b9be;margin-bottom:1em}#drag-drop-area.supports-drag-drop.drag-over{border:4px dashed #0073aa}#drag-drop-area .close{background-color:transparent;border:0;cursor:pointer;height:48px;position:absolute;right:0;text-align:center;top:0;width:50px;z-index:1}.drag-drop-inside{margin:2em 0}#drag-drop-area .drag-drop-inside p.drag-drop-info{display:none}#drag-drop-area.supports-drag-drop .drag-drop-inside p.drag-drop-info{display:block;font-size:12px;margin:.5em 0;text-align:center}p.drag-drop-buttons{text-align:center}p.drag-drop-buttons input[type=button]{display:inline-block!important}#drag-drop-area h2.drag-drop-info{display:none}#drag-drop-area.supports-drag-drop h2.drag-drop-info{display:block;font-size:20px;line-height:28px;font-weight:400;margin:0;text-align:center}#drag-drop-area:not( .supports-drag-drop ){position:relative;width:50%;margin:0 auto;border:1px solid #e5e5e5;box-shadow:0 1px 1px rgba(0,0,0,.04);background:#fff}
--------------------------------------------------------------------------------
/assets/block.min.css:
--------------------------------------------------------------------------------
1 | div.editor-block-list__block[data-type='mediatheque/usermedia'] .editor-block-list__block-edit [data-block]{clear:both;overflow:hidden}div.editor-block-list__block[data-type='mediatheque/usermedia'] .editor-block-list__block-edit [data-block] .wp-video-shortcode,div.editor-block-list__block[data-type='mediatheque/usermedia'] .editor-block-list__block-edit [data-block] img{display:block}div.editor-block-list__block[data-type='mediatheque/usermedia'] .editor-block-list__block-edit [data-block] .wp-video-shortcode.aligncenter,div.editor-block-list__block[data-type='mediatheque/usermedia'] .editor-block-list__block-edit [data-block] img.aligncenter{margin:0 auto}div.editor-block-list__block[data-type='mediatheque/usermedia'] .editor-block-list__block-edit [data-block] .mediatheque-file-link img{margin-right:1.5em}div.editor-block-list__block[data-type='mediatheque/usermedia'] .editor-block-list__block-edit [data-block] dl{margin-top:0}div.editor-block-list__block[data-type='mediatheque/usermedia'] .editor-block-list__block-edit [data-block] .wp-video{width:100%!important}div.editor-block-list__block[data-type='mediatheque/usermedia'] .wp-block-embed.is-loading{background:0 0}
--------------------------------------------------------------------------------
/js/manage.min.js:
--------------------------------------------------------------------------------
1 | /*! mediatheque - v1.4.0-alpha - 2021-09-05 2:16:43 PM UTC - https://imathi.eu/tag/mediatheque */
2 |
3 | window.wp=window.wp||{},window.mediaTheque=window.mediaTheque||_.extend({},_.pick(window.wp,"Backbone","template")),function(t){mediaTheque.Models=mediaTheque.Models||{},mediaTheque.Collections=mediaTheque.Collections||{},mediaTheque.Views=mediaTheque.Views||{},mediaTheque.App={init:function(e,i){this.views=new Backbone.Collection,this.users=new wp.api.collections.Users,this.userMedia=new wp.api.collections.UserMedia,this.toolbarItems=new Backbone.Collection,this.queryVars=new Backbone.Model,this.trailItems=new Backbone.Collection,this.overrides={url:e,file_data_name:"mediatheque_upload",headers:{"X-WP-Nonce":i}},this.rootView=new mediaTheque.Views.Root({el:t("#mediatheque-container"),users:this.users,media:this.userMedia,overrides:this.overrides,toolbarItems:this.toolbarItems,queryVars:this.queryVars,trailItems:this.trailItems}).render()}},wp.api.loadPromise.done(function(e){var i,t;e.get("apiRoot")&&e.get("versionString")&&(i=e.get("apiRoot")+e.get("versionString")+"user-media",(t=e.get("nonce"))||(t=mediaThequeSettings.restNonce,e.set("nonce",t))),mediaTheque.App.init(i,t)})}(jQuery);
--------------------------------------------------------------------------------
/templates/embed-user_media.php:
--------------------------------------------------------------------------------
1 |
16 |
>
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
39 |
40 |
41 |
2 |
{{ data.name }}
3 |
4 | <# } else if ( 'contenteditable' === data.type ) { #>
5 |
{{ data.name }}
6 |
<# if ( data.value ) { #>{{{ data.value }}}<# } #>
7 | <# } else if ( 'text' === data.type ) { #>
8 |
{{ data.name }}
9 |
10 | <# } else if ( 'checkbox' === data.type ) { #>
11 | <# if ( data.name ) { #>
12 |
{{ data.name }}
13 | <# } #>
14 |
15 |
checked="checked"<# } #>/>
16 |
{{ data.caption }}
17 | <# } else if ( 'list' === data.type && _.isArray( data.value ) && 0 < data.value.length ) { #>
18 |
{{ data.name }}
19 |
20 |
21 | <# for ( i in data.value ) { #>
22 |
23 | | {{{data.value[i].title}}} |
24 |
25 | <# if ( data.value[i].edit_link ) { #>
26 |
27 | <# } #>
28 | |
29 |
30 | <# } #>
31 |
32 |
33 | <# } else if ( 'submit' === data.type || 'reset' === data.type ) { #>
34 |
37 | <# } #>
38 |
--------------------------------------------------------------------------------
/templates/user-media.html:
--------------------------------------------------------------------------------
1 | <# if ( data.uploading ) { #>
2 |
7 | <# } else { #>
8 |
style="background-image:url( {{{data.background}}} );"<# } #>>
9 |
10 | <# if ( 'image' !== data.media_type ) { #>
11 | <# if ( data.media_icon ) { #>
12 |
13 | {{data.media_type}}
14 |
15 | <# } #>
16 |
17 |
{{{data.title.rendered}}}
18 | <# } #>
19 |
20 |
21 |
22 | <# if ( 'wp-editor' !== data.uiType ) { #>
23 |
40 | <# } #>
41 |
42 | <# if ( 'admin' === data.uiType ) { #>
43 |
44 | <# } #>
45 | <# } #>
46 |
--------------------------------------------------------------------------------
/js/manage.js:
--------------------------------------------------------------------------------
1 | /* global wp, _, mediaTheque, mediaThequeSettings */
2 |
3 | // Make sure the wp object exists.
4 | window.wp = window.wp || {};
5 | window.mediaTheque = window.mediaTheque || _.extend( {}, _.pick( window.wp, 'Backbone', 'template' ) );
6 |
7 | ( function( $ ) {
8 |
9 | mediaTheque.Models = mediaTheque.Models || {};
10 | mediaTheque.Collections = mediaTheque.Collections || {};
11 | mediaTheque.Views = mediaTheque.Views || {};
12 |
13 | mediaTheque.App = {
14 | init: function( restUrl, restNonce ) {
15 | this.views = new Backbone.Collection();
16 | this.users = new wp.api.collections.Users();
17 | this.userMedia = new wp.api.collections.UserMedia();
18 | this.toolbarItems = new Backbone.Collection();
19 | this.queryVars = new Backbone.Model();
20 | this.trailItems = new Backbone.Collection();
21 |
22 | this.overrides = {
23 | url: restUrl,
24 | 'file_data_name': 'mediatheque_upload',
25 | headers: {
26 | 'X-WP-Nonce' : restNonce
27 | }
28 | };
29 |
30 | this.rootView = new mediaTheque.Views.Root( {
31 | el: $( '#mediatheque-container' ),
32 | users: this.users,
33 | media: this.userMedia,
34 | overrides: this.overrides,
35 | toolbarItems: this.toolbarItems,
36 | queryVars: this.queryVars,
37 | trailItems: this.trailItems
38 | } ).render();
39 | }
40 | };
41 |
42 | wp.api.loadPromise.done( function( api ) {
43 | var restUrl, restNonce;
44 |
45 | if ( api.get( 'apiRoot' ) && api.get( 'versionString' ) ) {
46 | restUrl = api.get( 'apiRoot' ) + api.get( 'versionString' ) + 'user-media';
47 | restNonce = api.get( 'nonce' );
48 |
49 | // If Gutenberg is active, we have to set the nonce.
50 | if ( ! restNonce ) {
51 | restNonce = mediaThequeSettings.restNonce;
52 | api.set( 'nonce', restNonce );
53 | }
54 | }
55 |
56 | mediaTheque.App.init( restUrl, restNonce );
57 | } );
58 |
59 | } )( jQuery );
60 |
--------------------------------------------------------------------------------
/inc/hooks.php:
--------------------------------------------------------------------------------
1 | a{display:inline-block;margin:0 10px;padding:15px 0;border-bottom:4px solid #fff;color:#666;cursor:pointer}#mediatheque-container .filter-links .current{-webkit-box-shadow:none;box-shadow:none;border-bottom:4px solid #666;color:#23282d}#mediatheque-container .filter-links li>a:focus,#mediatheque-container .filter-links li>a:hover,#mediatheque-container .show-filters .filter-links a.current:focus,#mediatheque-container .show-filters .filter-links a.current:hover{color:#00a0d2}
--------------------------------------------------------------------------------
/inc/classes/class-mediatheque-settings.php:
--------------------------------------------------------------------------------
1 | settings_sections = apply_filters( 'mediatheque_get_settings_sections', array(
40 | 'settings_page_user-media-options' => array(
41 | 'title' => __( 'Options disponibles', 'mediatheque' ),
42 | 'callback' => 'mediatheque_settings_section_callback',
43 | ),
44 | ) );
45 |
46 | $this->settings_fields = apply_filters( 'mediatheque_get_settings_fields', array(
47 | 'settings_page_user-media-options' => array(
48 | 'mediatheque_capability' => array(
49 | 'title' => __( 'Capacités requises.', 'mediatheque' ),
50 | 'callback' => 'mediatheque_settings_field_capability',
51 | 'sanitize_callback' => 'mediatheque_sanitize_capability',
52 | ),
53 | 'mediatheque_mime_types' => array(
54 | 'title' => __( 'Types de fichier autorisés.', 'mediatheque' ),
55 | 'callback' => 'mediatheque_settings_field_mime_types',
56 | 'sanitize_callback' => 'mediatheque_sanitize_mime_types',
57 | ),
58 | 'mediatheque_personal_avatar' => array(
59 | 'title' => __( 'Images de profil.', 'mediatheque' ),
60 | 'callback' => 'mediatheque_settings_field_avatars',
61 | 'sanitize_callback' => 'absint',
62 | ),
63 | 'mediatheque_disable_on_front_end' => array(
64 | 'title' => __( 'Bouton MediaThèque en frontal.', 'mediatheque' ),
65 | 'callback' => 'mediatheque_settings_field_front_end_button',
66 | 'sanitize_callback' => 'absint',
67 | ),
68 | ),
69 | ) );
70 |
71 | // Register the settings once the Administration is inited.
72 | add_action( 'admin_init', array( $this, 'register_settings' ) );
73 | }
74 |
75 | /**
76 | * Register the MediaThèque settings.
77 | *
78 | * @since 1.0.0
79 | */
80 | public function register_settings() {
81 | // Add settings sections.
82 | foreach ( (array) $this->settings_sections as $ks => $section ) {
83 | if ( empty( $section['title'] ) || empty( $section['callback'] ) ) {
84 | continue;
85 | }
86 |
87 | // Add the section.
88 | add_settings_section( $ks, $section['title'], $section['callback'], $ks );
89 | }
90 |
91 | // Add settings fields
92 | foreach ( (array) $this->settings_fields as $section_id => $fields ) {
93 | // Check the section exists.
94 | if ( ! isset( $this->settings_sections[ $section_id ] ) ) {
95 | continue;
96 | }
97 |
98 | foreach ( $fields as $option => $field ) {
99 | if ( empty( $field['title'] ) || empty( $field['callback'] ) || empty( $field['sanitize_callback'] ) ) {
100 | continue;
101 | }
102 |
103 | if ( empty( $field['args'] ) ) {
104 | $field['args'] = array();
105 | }
106 |
107 | // Add the field
108 | add_settings_field( $option, $field['title'], $field['callback'], $section_id, $section_id, $field['args'] );
109 |
110 | // Register the setting
111 | register_setting( $section_id, $option, $field['sanitize_callback'] );
112 | }
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/inc/options.php:
--------------------------------------------------------------------------------
1 | 'exist',
121 | 'mediatheque_mime_types' => mediatheque_get_default_mime_types(),
122 | 'mediatheque_personal_avatar' => 1,
123 | 'mediatheque_disable_on_front_end' => 0,
124 | ) );
125 | }
126 |
--------------------------------------------------------------------------------
/mediatheque.php:
--------------------------------------------------------------------------------
1 | globals();
45 | $this->inc();
46 | }
47 |
48 | /**
49 | * Return an instance of this class.
50 | *
51 | * @since 1.0.0
52 | *
53 | * @return object A single instance of this class.
54 | */
55 | public static function start() {
56 |
57 | // If the single instance hasn't been set, set it now.
58 | if ( null == self::$instance ) {
59 | self::$instance = new self;
60 | }
61 |
62 | return self::$instance;
63 | }
64 |
65 | /**
66 | * Setups plugin's globals
67 | *
68 | * @since 1.0.0
69 | */
70 | private function globals() {
71 | // Version
72 | $this->version = '1.4.0-alpha';
73 |
74 | // Domain
75 | $this->domain = 'mediatheque';
76 |
77 | // Base name
78 | $this->file = __FILE__;
79 | $this->basename = plugin_basename( $this->file );
80 |
81 | // Path and URL
82 | $this->dir = plugin_dir_path( $this->file );
83 | $this->url = plugin_dir_url ( $this->file );
84 | $this->js_url = trailingslashit( $this->url . 'js' );
85 | $this->assets_url = trailingslashit( $this->url . 'assets' );
86 | $this->inc_dir = trailingslashit( $this->dir . 'inc' );
87 | $this->templates = trailingslashit( $this->dir . 'templates' );
88 | $this->personal_avatars = array();
89 | $this->user_media_oembeds = array();
90 | $this->template_tags = new stdClass;
91 | }
92 |
93 | /**
94 | * Includes plugin's needed files
95 | *
96 | * @since 1.0.0
97 | */
98 | private function inc() {
99 | spl_autoload_register( array( $this, 'autoload' ) );
100 |
101 | require( $this->inc_dir . 'options.php' );
102 | require( $this->inc_dir . 'users.php' );
103 | require( $this->inc_dir . 'functions.php' );
104 | require( $this->inc_dir . 'media.php' );
105 | require( $this->inc_dir . 'templates.php' );
106 | require( $this->inc_dir . 'upgrade.php' );
107 |
108 | if ( mediatheque_use_personal_avatar() ) {
109 | require( $this->inc_dir . 'avatars.php' );
110 | }
111 |
112 | if ( is_admin() ) {
113 | require( $this->inc_dir . 'settings.php' );
114 | }
115 |
116 | // Last but not least!
117 | require( $this->inc_dir . 'hooks.php' );
118 | }
119 |
120 | /**
121 | * Class Autoload function
122 | *
123 | * @since 1.0.0
124 | *
125 | * @param string $class The class name.
126 | */
127 | public function autoload( $class ) {
128 | $name = str_replace( '_', '-', strtolower( $class ) );
129 |
130 | if ( false === strpos( $name, $this->domain ) ) {
131 | return;
132 | }
133 |
134 | $path = $this->inc_dir . "classes/class-{$name}.php";
135 |
136 | // Sanity check.
137 | if ( ! file_exists( $path ) ) {
138 | return;
139 | }
140 |
141 | require $path;
142 | }
143 | }
144 |
145 | endif;
146 |
147 | /**
148 | * Boot the plugin.
149 | *
150 | * @since 1.0.0
151 | */
152 | function mediatheque() {
153 | return MediaTheque::start();
154 | }
155 | add_action( 'plugins_loaded', 'mediatheque', 5 );
156 |
--------------------------------------------------------------------------------
/inc/upgrade.php:
--------------------------------------------------------------------------------
1 | $option_value ) {
64 | add_network_option( 0, $option_name, $option_value );
65 | }
66 |
67 | /**
68 | * Trigger the 'mediatheque_install' action.
69 | *
70 | * @since 1.0.0
71 | */
72 | do_action( 'mediatheque_install' );
73 |
74 | } elseif ( mediatheque_is_upgrade() ) {
75 | /**
76 | * Trigger the 'mediatheque_upgrade' action.
77 | *
78 | * @since 1.0.0
79 | */
80 | do_action( 'mediatheque_upgrade', $db_version );
81 | }
82 |
83 | // Force rewrite rules to be refreshed
84 | if ( get_option( 'permalink_structure' ) ) {
85 | delete_option( 'rewrite_rules' );
86 | }
87 |
88 | if ( ! $is_main_site ) {
89 | restore_current_blog();
90 | }
91 |
92 | // Update the db version.
93 | update_network_option( 0, 'mediatheque_version', $db_version );
94 | }
95 | add_action( 'admin_init', 'mediatheque_upgrade', 999 );
96 |
97 | /**
98 | * Used to guide the user when new features are added.
99 | *
100 | * @since 1.0.0.
101 | */
102 | function mediatheque_get_pointers() {
103 | $pointers = array(
104 | 'user-media-permalinks' => array(
105 | 'title' => __( 'Modifiez la structure de vos permaliens.', 'mediatheque' ),
106 | 'content' => __( 'MediaThèque nécessite que la structure de vos permaliens soit différente que celle définie par défaut.', 'mediatheque' ),
107 | 'position' => 'bottom',
108 | ),
109 | 'menu-settings' => array(
110 | 'title' => __( 'Options des media utilisateurs', 'mediatheque' ),
111 | 'content' => __( 'Personnalisez les options des media utilisateurs depuis les réglages des media.', 'mediatheque' ),
112 | 'position' => 'bottom',
113 | ),
114 | 'menu-media' => array(
115 | 'title' => __( 'Gestion des media utilisateurs', 'mediatheque' ),
116 | 'content' => __( 'Vous pouvez gérer les media utilisateurs depuis le sous-menu de la bibliothèque de media correspondant.', 'mediatheque' ),
117 | 'position' => 'top',
118 | ),
119 | 'toplevel_page_user-media' => array(
120 | 'title' => __( 'Accédez à votre MediaThèque', 'mediatheque' ),
121 | 'content' => __( 'Vous pouvez ajouter, organiser et supprimer vos media utilisateurs depuis ce menu.', 'mediatheque' ),
122 | 'position' => 'top',
123 | ),
124 | );
125 |
126 | if ( is_multisite() ) {
127 | if ( is_super_admin() ) {
128 | $pointers['toplevel_page_user-media']['title'] = $pointers['menu-media']['title'];
129 | $pointers['toplevel_page_user-media']['content'] = __( 'Vous pouvez gérer les media de tous les utilisateurs depuis ce menu.', 'mediatheque' );
130 | unset( $pointers['menu-media'] );
131 | } else {
132 | $pointers['menu-media']['content'] = $pointers['toplevel_page_user-media']['content'];
133 | }
134 | }
135 |
136 | return $pointers;
137 | }
138 |
--------------------------------------------------------------------------------
/assets/editor.css:
--------------------------------------------------------------------------------
1 | /* Inside the WP Media Editor */
2 | .media-frame-content #mediatheque-container .wp-filter {
3 | margin-top: 0;
4 | border-top: none;
5 | border-left: none;
6 | border-right: none;
7 | width: 98%;
8 | }
9 |
10 | .media-frame-content #mediatheque-container #forms,
11 | .media-frame-content #mediatheque-container #media,
12 | .media-frame-content #mediatheque-container #trail {
13 | width: 95%;
14 | margin-right: auto;
15 | margin-left: auto;
16 | }
17 |
18 | .media-frame-content #mediatheque-container #media ul li.user-media {
19 | box-shadow: inset 0 0 15px rgba( 0, 0, 0, 0.1 ), inset 0 0 0 1px rgba( 0, 0, 0, 0.05 );
20 | background-color: #eee;
21 | background-image: none;
22 | cursor: pointer;
23 | }
24 |
25 | .media-frame-content #mediatheque-container #media ul li.user-media.dir .user-media-content {
26 | background-image: url( 'folder.svg' );
27 | background-size: 50%;
28 | background-repeat: no-repeat;
29 | background-position: center center;
30 | }
31 |
32 | .media-frame-content #mediatheque-container #media ul li.user-media div.user-media-content {
33 | min-height: 200px;
34 | }
35 |
36 | .media-frame-content #mediatheque-container #media ul li.user-media.selected {
37 | border: 8px inset #0073aa;
38 | outline: none;
39 | max-height: 184px;
40 | }
41 |
42 | .media-frame-content #mediatheque-container #media ul li.user-media.selected .user-media-content {
43 | min-width: 184px;
44 | min-height: 184px;
45 | }
46 |
47 | .media-frame.mediatheque-hide-menu .media-frame-title,
48 | .media-frame.mediatheque-hide-menu .media-frame-router,
49 | .media-frame.mediatheque-hide-menu .media-frame-toolbar,
50 | .media-frame.mediatheque-hide-menu .media-frame-content {
51 | left: 0;
52 | }
53 |
54 | .media-frame.mediatheque-hide-menu .media-frame-menu {
55 | display: none;
56 | }
57 |
58 | .media-frame .user-media-preferences .embed-media-settings {
59 | top: 0;
60 | }
61 |
62 | .media-frame .user-media-preferences .embed-media-settings .column-image,
63 | .media-frame .user-media-preferences .embed-media-settings .wp-video-holder,
64 | .media-frame .user-media-preferences .embed-audio-settings audio {
65 | float: right;
66 | margin-right: 1em;
67 | width: 48%;
68 | }
69 |
70 | .media-frame .user-media-preferences .embed-audio-settings audio,
71 | .media-frame #mediatheque-file-preferences .embed-media-settings {
72 | margin-top: 2em;
73 | }
74 |
75 | .media-frame .user-media-preferences .embed-media-settings .column-settings,
76 | .media-frame .user-media-preferences .embed-video-settings .setting-group,
77 | .media-frame .user-media-preferences .embed-video-settings .setting.align,
78 | .media-frame .user-media-preferences .embed-audio-settings .setting {
79 | float: left;
80 | margin-left: 1em;
81 | overflow: hidden;
82 | width: 48%;
83 | }
84 |
85 | .media-frame .user-media-preferences .embed-video-settings .setting.preload,
86 | .media-frame .user-media-preferences .embed-audio-settings .setting.preload {
87 | overflow: visible;
88 | }
89 |
90 | .media-frame .user-media-preferences .embed-media-settings .column-settings label,
91 | .media-modal .media-frame .user-media-preferences .embed-media-settings .column-settings .legend-inline {
92 | display: block;
93 | position: static;
94 | transform: inherit;
95 | margin: 0;
96 | line-height: 1.84615384;
97 | }
98 |
99 | .media-frame .user-media-preferences .embed-media-settings .column-image {
100 | margin-top: 2em;
101 | }
102 |
103 | .media-frame .user-media-preferences .media-embed .embed-video-settings .setting,
104 | .media-frame .user-media-preferences .media-embed .embed-video-settings .setting-group,
105 | .media-frame .user-media-preferences .media-embed .embed-audio-settings .setting {
106 | clear: none;
107 | }
108 |
109 | .user-media-preferences .embed-video-settings fieldset:first-of-type,
110 | .user-media-preferences .embed-audio-settings fieldset:first-of-type {
111 | display: none;
112 | }
113 |
114 | .user-media-preferences .embed-video-settings .media-embed .setting span {
115 | margin-left: 1em;
116 | }
117 |
118 | .user-media-preferences .media-embed .embed-video-settings .checkbox-setting,
119 | .user-media-preferences .media-embed .embed-audio-settings .checkbox-setting {
120 | float: none;
121 | display: block;
122 | }
123 |
124 | .media-frame #mediatheque-container #media ul li.user-media div.user-media-content h4 {
125 | background: none;
126 | }
127 |
128 | .media-frame-content #mediatheque-container #media li.notice {
129 | margin: 1em 0;
130 | }
131 |
--------------------------------------------------------------------------------
/js/block.min.js:
--------------------------------------------------------------------------------
1 | /*! mediatheque - v1.4.0-alpha - 2021-09-05 2:16:43 PM UTC - https://imathi.eu/tag/mediatheque */
2 |
3 | !function(s,o){var r=o.element.createElement,e=o.blocks.registerBlockType,l=o.editor.InspectorControls,d=o.editor.BlockControls,c=o.editor.AlignmentToolbar,u=o.components.Toolbar,m=o.components.PanelBody,b=r("svg",{key:"mediatheque-icon","aria-hidden":!0,role:"img",className:"dashicon mediatheque-icon",focusable:"false",width:"20",height:"20",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg"},[r("path",{key:"camera",d:"M 13 11 L 13 4 C 13 3.45 12.55 3 12 3 L 10.33 3 L 9 1 L 5 1 L 3.67 3 L 2 3 C 1.45 3 1 3.45 1 4 L 1 11 C 1 11.55 1.45 12 2 12 L 12 12 C 12.55 12 13 11.55 13 11 Z"}),r("path",{key:"sound",d:"M 14 6 L 19 6 L 19 16.5 C 19 17.88 17.88 19 16.5 19 C 15.12 19 14 17.88 14 16.5 C 14 15.12 15.12 14 16.5 14 C 16.67 14 16.84 14.02 17 14.05 L 17 9 L 14 9 L 14 6 Z"}),r("path",{key:"user-head",d:"M 7 4.5 C 8.38 4.5 9.5 5.62 9.5 7 C 9.5 8.38 8.38 9.5 7 9.5 C 5.62 9.5 4.5 8.38 4.5 7 C 4.5 5.62 5.62 4.5 7 4.5 Z",style:{fill:"rgb(255, 255, 255)"}}),r("path",{key:"user-body",d:"M 7.006 11.465 L 9.121 10.05 C 10.979 10.05 12.636 11.861 12.636 13.573 L 12.636 15.508 C 12.636 15.508 9.797 16.386 7.006 16.386 C 4.168 16.386 1.376 15.508 1.376 15.508 L 1.376 13.573 C 1.376 11.823 2.885 10.089 4.852 10.089 Z",style:{stroke:"rgb(255, 255, 255)"}})]);e("mediatheque/usermedia",{title:"MediaThèque",description:mediaThequeBlock.description,icon:function(){return b},category:"common",attributes:{link:{type:"string"},title:{type:"string"},alignment:{type:"string"}},edit:function(a){function i(e){s("#"+a.clientId).parent().find(".notice-error").remove(),s("#"+a.clientId).parent().removeClass("components-placeholder"),s("#"+a.clientId).before(e).remove()}var e,t=a.attributes.alignment,n=a.isSelected;return a&&a.attributes.link?a.attributes.title?[!!n&&r(l,{key:"controls"},[r(m,{key:"label",title:mediaThequeBlock.alignmentLabel},r(c,{key:"aligncontrol",value:t,onChange:function(e){a.setAttributes({alignment:e})}}))]),r("p",{key:"editable",className:"mediatheque-private",focus:n.toString(),style:{textAlign:t},onFocus:a.setFocus},r("a",{href:a.attributes.link},a.attributes.title))]:(a.attributes.userMediaFetched?"error"!==a.attributes.userMediaFetched&&window.setTimeout(function(){i(a.attributes.userMediaFetched)},500):(e=a.attributes.link,o.ajax.post("parse-embed",{post_ID:o.media.view.settings.post.id,type:"embed",shortcode:"[embed]"+e+"[/embed]"}).done(function(e){var t=!0;e.body?(t="A"===s(e.body).prop("tagName")?s(e.body).html():e.body,i(t)):a.setAttributes({link:!(t="error")}),a.setAttributes({userMediaFetched:t})}).fail(function(){a.setAttributes({userMediaFetched:"error"}),a.setAttributes({link:!1})})),r("div",{className:"components-placeholder"},[r("div",{id:a.clientId,key:"loading",className:"wp-block-embed is-loading"},r("span",{className:"spinner is-active"})),!!n&&r(d,{key:"controls"},r(u,{controls:[{icon:"edit",title:mediaThequeBlock.editTitle,onClick:function(){var i=o.media.embed.edit(a.attributes.link,!0);i.state("embed").props.on("change:url",function(e,t){t&&e.get("url")&&(i.state("embed").metadata=e.toJSON())}),i.state("embed").on("select",function(){var e=i.state("embed").metadata,t=s(".editor-block-list__block.is-selected .editor-block-list__block-edit [data-block]");e&&e.url!==a.attributes.link&&(t.addClass("components-placeholder").html(s("
").addClass("wp-block-embed is-loading").html(s("
").addClass("spinner is-active")).prop("id",a.clientId)),a.setAttributes({link:e.url,userMediaFetched:!1}))}),i.on("close",function(){i.detach()}),i.open()}}]}))])):r("div",{className:"components-placeholder"},[r("div",{key:"block-placeholder",className:"components-placeholder__label"},[b,r("label",{key:"block-label"},"MediaThèque")]),r("button",{key:"user-media-select-button",type:"button",id:a.clientId,className:"mediatheque-block button button-large",onClick:function(e){e.preventDefault();var i=s(e.currentTarget),e={frame:"post",state:"user-media",title:o.media.view.l10n.addMedia,isUserMediaOnly:!0,gutenbergBlock:!0};mediaThequeSettings.common.isUserMediaOnly=!0,mediaThequeSettings.params=_.omit(mediaThequeSettings.params,"dropzone"),o.media.editor.open(".gutenberg",e),s(".media-frame-uploader").css({display:"none"}),o.media.frame.on("select",function(){var e,t;i.data("link")&&!a.attributes.link&&(e=i.data("link"),(t=i.data("title"))?a.setAttributes({title:t,link:e,userMediaFetched:!0}):a.setAttributes({link:e,userMediaFetched:!1}))})}},mediaThequeBlock.insertBtn),"error"===a.attributes.userMediaFetched&&r("div",{className:"notice notice-alt notice-error",key:"user-media-error"},r("p",{className:null},mediaThequeBlock.genericError))])},save:function(e){if(e&&e.attributes.link&&"false"!==e.attributes.link)return e.attributes.title?r("p",{className:"mediatheque-private",style:{textAlign:e.attributes.alignment}},r("a",{href:e.attributes.link},e.attributes.title)):r("p",{},e.attributes.link)}})}(jQuery,window.wp||{});
--------------------------------------------------------------------------------
/assets/front.css:
--------------------------------------------------------------------------------
1 | body:not( .wp-admin ) .media-modal #mediatheque-container {
2 | background-color: #fff;
3 | }
4 |
5 | #mediatheque-container .postbox {
6 | position: relative;
7 | min-width: 255px;
8 | border: 1px solid #e5e5e5;
9 | -webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.04);
10 | box-shadow: 0 1px 1px rgba(0,0,0,0.04);
11 | background: #fff;
12 | }
13 |
14 | #mediatheque-container .postbox button.dashicons-no,
15 | #mediatheque-container .mediatheque-uploader-box button.dashicons-no {
16 | color: #555;
17 | padding: 0;
18 | }
19 |
20 | #mediatheque-container .notice,
21 | #mediatheque-container div.updated,
22 | #mediatheque-container div.error {
23 | background: #fff;
24 | border-left: 4px solid #fff;
25 | -webkit-box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 );
26 | box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 );
27 | margin: 5px 15px 2px;
28 | padding: 1px 12px;
29 | }
30 |
31 | #mediatheque-container .notice p,
32 | #mediatheque-container .notice-title,
33 | #mediatheque-container div.updated p,
34 | #mediatheque-container div.error p,
35 | #mediatheque-container .form-table td .notice p {
36 | margin: 0.5em 0;
37 | padding: 2px;
38 | }
39 |
40 | #mediatheque-container .error a {
41 | text-decoration: underline;
42 | }
43 |
44 | #mediatheque-container .updated a {
45 | padding-bottom: 2px;
46 | }
47 |
48 | #mediatheque-container .notice-alt {
49 | -webkit-box-shadow: none;
50 | box-shadow: none;
51 | }
52 |
53 | #mediatheque-container .notice-large {
54 | padding: 10px 20px;
55 | }
56 |
57 | #mediatheque-container .notice-title {
58 | display: inline-block;
59 | color: #23282d;
60 | font-size: 18px;
61 | }
62 |
63 | .wp-core-ui #mediatheque-container .notice.is-dismissible {
64 | padding-right: 38px;
65 | position: relative;
66 | }
67 |
68 | #mediatheque-container .notice-dismiss {
69 | position: absolute;
70 | top: 0;
71 | right: 1px;
72 | border: none;
73 | margin: 0;
74 | padding: 9px;
75 | background: none;
76 | color: #72777c;
77 | cursor: pointer;
78 | }
79 |
80 | #mediatheque-container .notice-dismiss:hover:before,
81 | #mediatheque-container .notice-dismiss:active:before,
82 | #mediatheque-container .notice-dismiss:focus:before {
83 | color: #c00;
84 | }
85 |
86 | #mediatheque-container .notice-dismiss:focus {
87 | outline: none;
88 | -webkit-box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8);
89 | box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8);
90 | }
91 |
92 | .ie8 #mediatheque-container .notice-dismiss:focus {
93 | outline: 1px solid #5b9dd9;
94 | }
95 |
96 | #mediatheque-container .notice-success,
97 | #mediatheque-container div.updated {
98 | border-left-color: #46b450;
99 | }
100 |
101 | #mediatheque-container .notice-success.notice-alt {
102 | background-color: #ecf7ed;
103 | }
104 |
105 | #mediatheque-container .notice-warning {
106 | border-left-color: #ffb900;
107 | }
108 |
109 | #mediatheque-container .notice-warning.notice-alt {
110 | background-color: #fff8e5;
111 | }
112 |
113 | #mediatheque-container .notice-error,
114 | #mediatheque-container div.error {
115 | border-left-color: #dc3232;
116 | }
117 |
118 | #mediatheque-container .notice-error.notice-alt {
119 | background-color: #fbeaea;
120 | }
121 |
122 | #mediatheque-container .notice-info {
123 | border-left-color: #00a0d2;
124 | }
125 |
126 | #mediatheque-container .notice-info.notice-alt {
127 | background-color: #e5f5fa;
128 | }
129 |
130 | /* Filter bar */
131 | #mediatheque-container .wp-filter {
132 | display: inline-block;
133 | position: relative;
134 | -webkit-box-sizing: border-box;
135 | -moz-box-sizing: border-box;
136 | box-sizing: border-box;
137 | margin: 12px 0 25px;
138 | padding: 0 10px;
139 | width: 100%;
140 | -webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.04);
141 | box-shadow: 0 1px 1px rgba(0,0,0,0.04);
142 | border: 1px solid #e5e5e5;
143 | background: #fff;
144 | color: #555;
145 | font-size: 13px;
146 | }
147 |
148 | #mediatheque-container .wp-filter a {
149 | text-decoration: none;
150 | }
151 |
152 | #mediatheque-container .filter-count {
153 | display: inline-block;
154 | vertical-align: middle;
155 | min-width: 4em;
156 | }
157 |
158 | #mediatheque-container .filter-items {
159 | float: left;
160 | }
161 |
162 | #mediatheque-container .filter-links {
163 | display: inline-block;
164 | margin: 0;
165 | }
166 |
167 | #mediatheque-container .filter-links li {
168 | display: inline-block;
169 | margin: 0;
170 | }
171 |
172 | #mediatheque-container .filter-links li > a {
173 | display: inline-block;
174 | margin: 0 10px;
175 | padding: 15px 0;
176 | border-bottom: 4px solid #fff;
177 | color: #666;
178 | cursor: pointer;
179 | }
180 |
181 | #mediatheque-container .filter-links .current {
182 | -webkit-box-shadow: none;
183 | box-shadow: none;
184 | border-bottom: 4px solid #666;
185 | color: #23282d;
186 | }
187 |
188 | #mediatheque-container .filter-links li > a:hover,
189 | #mediatheque-container .filter-links li > a:focus,
190 | #mediatheque-container .show-filters .filter-links a.current:hover,
191 | #mediatheque-container .show-filters .filter-links a.current:focus {
192 | color: #00a0d2;
193 | }
194 |
--------------------------------------------------------------------------------
/inc/avatars.php:
--------------------------------------------------------------------------------
1 | personal_avatars[ $user_media_id ][ $size ] ) ) {
40 | $personal_avatar = $mediatheque->personal_avatars[ $user_media_id ][ $size ];
41 | } else {
42 | $mediatheque->personal_avatars[ $user_media_id ][ $size ] = mediatheque_image_get_intermediate_size( $user_media_id, array( $size, $size ) );
43 | $personal_avatar = $mediatheque->personal_avatars[ $user_media_id ][ $size ];
44 | }
45 |
46 | if ( empty( $personal_avatar['url'] ) ) {
47 | return false;
48 | }
49 |
50 | return $personal_avatar['url'];
51 | }
52 |
53 | /**
54 | * Use the personal avatar url when available.
55 | *
56 | * @since 1.0.0
57 | *
58 | * @param array $args Default data.
59 | * @param mixed $id_or_email A user ID, email, a User, a Post or a Comment object.
60 | * @return array Avatar data.
61 | */
62 | function mediatheque_get_avatar_data( $args = array(), $id_or_email = null ) {
63 | if ( empty( $id_or_email ) ) {
64 | return $args;
65 | }
66 |
67 | if ( is_numeric( $id_or_email ) ) {
68 | $user = get_user_by( 'id', (int) $id_or_email );
69 | } else if ( is_a( $id_or_email, 'WP_User' ) ) {
70 | $user = $id_or_email;
71 | } else if ( is_a( $id_or_email, 'WP_Post' ) ) {
72 | $user = get_user_by( 'id', (int) $id_or_email->post_author );
73 | } else if ( is_a( $id_or_email, 'WP_Comment' ) ) {
74 | $user = get_user_by( 'id', (int) $id_or_email->user_id );
75 | } else if ( is_email( $id_or_email ) ) {
76 | $user = get_user_by( 'email', $id_or_email );
77 | }
78 |
79 | if ( empty( $user->ID ) ) {
80 | return $args;
81 | }
82 |
83 | $personal_avatar_id = $user->personal_avatar;
84 |
85 | if ( ! $personal_avatar_id ) {
86 | return $args;
87 | }
88 |
89 | $personal_avatar_url = mediatheque_get_personal_avatar( $personal_avatar_id, $args['size'] );
90 |
91 | if ( ! $personal_avatar_url ) {
92 | return $args;
93 | }
94 |
95 | return array_merge( $args, array( 'url' => $personal_avatar_url ) );
96 | }
97 | add_filter( 'pre_get_avatar_data', 'mediatheque_get_avatar_data', 10, 2 );
98 |
99 | /**
100 | * Restrict the User Media Status to Publish for Avatar selection.
101 | *
102 | * @since 1.0.0
103 | *
104 | * @param array $statuses The list of available User Media statuses.
105 | * @return array The list of available User Media statuses for the Avatar UI.
106 | */
107 | function mediatheque_avatar_user_media_statuses( $statuses = array() ) {
108 | return array_intersect_key( $statuses, array( 'publish' => true ) );
109 | }
110 |
111 | /**
112 | * Output a button on User's dashboard profile to select one of his User Media
113 | * and set it as his personal avatar.
114 | *
115 | * @since 1.0.0
116 | *
117 | * @param WP_User $user The current User object.
118 | * @return string HTML Output.
119 | */
120 | function mediatheque_profile_personal_avatar( $user = null ) {
121 | $message = '';
122 |
123 | if ( ! current_user_can( 'publish_user_uploads' ) ) {
124 | return;
125 | }
126 |
127 | if ( $user->personal_avatar ) {
128 | $message = sprintf(
129 | __( 'Pour supprimer votre avatar local, vous pouvez %s.', 'mediatheque' ),
130 | sprintf( '
%s', __( 'cliquer ici', 'mediatheque' ) )
131 | );
132 | }
133 |
134 | add_filter( 'mediatheque_media_statuses', 'mediatheque_avatar_user_media_statuses', 10, 1 );
135 | ?>
136 |
137 |
'personal_avatar',
141 | 'editor_btn_classes' => array( 'mediabrary-insert' ),
142 | 'editor_btn_text' => __( 'MediaThèque', 'mediatheque' ),
143 | 'editor_btn_dashicon' => false,
144 | 'echo' => false,
145 | 'media_type' => 'image',
146 | ) ),
147 | '' . $message . ''
148 | ); ?>
149 |
150 |
151 | role_names;
27 | $setting = mediatheque_get_required_cap();
28 |
29 | $caps = array(
30 | 'exist' => __( 'Utilisateur connecté', 'mediatheque' ),
31 | );
32 |
33 | if ( isset( $role_names['subscriber'] ) ) {
34 | $caps['read'] = translate_user_role( $role_names['subscriber'] );
35 | }
36 |
37 | if ( isset( $role_names['contributor'] ) ) {
38 | $caps['edit_posts'] = translate_user_role( $role_names['contributor'] );
39 | }
40 | ?>
41 |
50 |
51 | $translated_type ) {
83 | if ( 'code' === $k_type ) {
84 | continue;
85 | }
86 | ?>
87 |
113 |
142 |
/>
143 |
144 |
151 |
/>
152 |
153 |
' )
192 | .addClass( 'wp-block-embed is-loading' )
193 | .html( $('
' )
194 | .addClass( 'spinner is-active' )
195 | )
196 | .prop( 'id', props.clientId )
197 | );
198 |
199 | props.setAttributes( {
200 | link: data.url,
201 | userMediaFetched: false
202 | } );
203 | }
204 | } );
205 |
206 | frame.on( 'close', function() {
207 | frame.detach();
208 | } );
209 |
210 | frame.open();
211 | };
212 |
213 | // No User Media were inserted yet.
214 | if ( ! props || ! props.attributes.link ) {
215 | return el(
216 | 'div', {
217 | className: 'components-placeholder'
218 | }, [
219 | el(
220 | 'div', {
221 | key: 'block-placeholder',
222 | className: 'components-placeholder__label'
223 | }, [
224 | mediaThequeIcon,
225 | el(
226 | 'label', {
227 | key: 'block-label'
228 | }, 'MediaThèque'
229 | )
230 | ]
231 | ),
232 | el(
233 | 'button', {
234 | key: 'user-media-select-button',
235 | type: 'button',
236 | id: props.clientId,
237 | className: 'mediatheque-block button button-large',
238 | onClick:selectUserMedia
239 | }, mediaThequeBlock.insertBtn
240 | ),
241 | 'error' === props.attributes.userMediaFetched && el(
242 | 'div', {
243 | className: 'notice notice-alt notice-error',
244 | key: 'user-media-error'
245 | }, el( 'p', {
246 | className: null
247 | }, mediaThequeBlock.genericError )
248 | )
249 | ]
250 | );
251 |
252 | // It's a private User Media.
253 | } else if ( props.attributes.title ) {
254 | return [
255 | !! focus && el(
256 | InspectorControls,
257 | { key: 'controls' },
258 | [
259 | el( PanelBody, {
260 | key: 'label',
261 | title: mediaThequeBlock.alignmentLabel
262 | }, el(
263 | AlignmentToolbar,
264 | {
265 | key: 'aligncontrol',
266 | value: alignment,
267 | onChange: onChangeAlignment
268 | }
269 | ) )
270 | ]
271 | ),
272 | el(
273 | 'p', {
274 | key: 'editable',
275 | className: 'mediatheque-private',
276 | focus: focus.toString(),
277 | style: { textAlign: alignment },
278 | onFocus: props.setFocus
279 | }, el(
280 | 'a', {
281 | href: props.attributes.link
282 | },
283 | props.attributes.title
284 | )
285 | )
286 | ];
287 |
288 | // It's a public User Media, fetch the output.
289 | } else if ( ! props.attributes.userMediaFetched ) {
290 | requestUserMedia( props.attributes.link );
291 |
292 | // Wait a few milliseconds before outputting the User Media.
293 | } else if ( 'error' !== props.attributes.userMediaFetched ) {
294 | window.setTimeout( function() {
295 | outputUserMedia( props.attributes.userMediaFetched );
296 | }, 500 );
297 | }
298 |
299 | // Output the public User Media.
300 | return el(
301 | 'div', {
302 | className: 'components-placeholder'
303 | }, [
304 | el(
305 | 'div', {
306 | id: props.clientId,
307 | key: 'loading',
308 | className: 'wp-block-embed is-loading'
309 | }, el( 'span', {
310 | className: 'spinner is-active'
311 | } )
312 | ),
313 | !! focus && el(
314 | BlockControls,
315 | { key: 'controls' },
316 | el(
317 | EditToolbar,
318 | {
319 | controls: [
320 | {
321 | icon: 'edit',
322 | title: mediaThequeBlock.editTitle,
323 | onClick: onClickEdit
324 | }
325 | ]
326 | }
327 | )
328 | )
329 | ]
330 | );
331 | },
332 |
333 | save: function( props ) {
334 | if ( ! props || ! props.attributes.link || 'false' === props.attributes.link ) {
335 | return;
336 | }
337 |
338 | // Content to save for a Private User Media
339 | if ( props.attributes.title ) {
340 | return el(
341 | 'p', {
342 | className: 'mediatheque-private',
343 | style: { textAlign: props.attributes.alignment }
344 | }, el(
345 | 'a', {
346 | href: props.attributes.link
347 | },
348 | props.attributes.title
349 | )
350 | );
351 | }
352 |
353 | // Content to save for a Public User Media
354 | return el( 'p', {}, props.attributes.link );
355 | }
356 | } );
357 |
358 | } )( jQuery, window.wp || {} );
359 |
--------------------------------------------------------------------------------
/inc/users.php:
--------------------------------------------------------------------------------
1 | 'edit_user_upload',
23 | 'read_post' => 'read_user_upload',
24 | 'delete_post' => 'delete_user_upload',
25 | 'edit_posts' => 'edit_user_uploads',
26 | 'edit_others_posts' => 'edit_others_user_uploads',
27 | 'publish_posts' => 'publish_user_uploads',
28 | 'read_private_posts' => 'read_private_user_uploads',
29 | 'read' => 'read_user_upload',
30 | 'delete_posts' => 'delete_user_uploads',
31 | 'delete_private_posts' => 'delete_private_user_uploads',
32 | 'delete_published_posts' => 'delete_published_user_uploads',
33 | 'delete_others_posts' => 'delete_others_user_uploads',
34 | 'edit_private_posts' => 'edit_private_user_uploads',
35 | 'edit_published_posts' => 'edit_published_user_uploads',
36 | 'create_posts' => 'create_user_uploads',
37 | );
38 | }
39 |
40 | /**
41 | * Get the capabilities for the User media types.
42 | *
43 | * @since 1.0.0
44 | *
45 | * @return array The capabilities for the User media types.
46 | */
47 | function mediatheque_types_capabilities() {
48 | return array(
49 | 'manage_terms' => 'manage_upload_types',
50 | 'edit_terms' => 'edit_upload_types',
51 | 'delete_terms' => 'delete_upload_types',
52 | 'assign_terms' => 'assign_upload_types',
53 | );
54 | }
55 |
56 | /**
57 | * Get All capabilities for User Media Objects.
58 | *
59 | * @since 1.0.0
60 | *
61 | * @return array All capabilities for User Media Objects.
62 | */
63 | function mediatheque_get_all_caps() {
64 | return array_merge( mediatheque_capabilities(), mediatheque_types_capabilities() );
65 | }
66 |
67 | /**
68 | * Map capabilities for User Media
69 | *
70 | * @since 1.0.0
71 | *
72 | * @param array $caps Capabilities for meta capability
73 | * @param string $cap Capability name
74 | * @param int $user_id User id
75 | * @param mixed $args Arguments
76 | * @return array Actual capabilities for meta capability
77 | */
78 | function mediatheque_map_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
79 | if ( in_array( $cap, mediatheque_get_all_caps(), true ) ) {
80 | if ( $user_id ) {
81 | $required_cap = mediatheque_get_required_cap();
82 | $admin_caps = mediatheque_types_capabilities();
83 | unset( $admin_caps['assign_terms'] );
84 | $admin_caps = array_merge( $admin_caps, array(
85 | 'edit_user_uploads',
86 | 'edit_others_user_uploads',
87 | 'delete_user_uploads',
88 | 'delete_private_user_uploads',
89 | 'delete_published_user_uploads',
90 | 'delete_others_user_uploads',
91 | 'edit_private_user_uploads',
92 | 'edit_published_user_uploads',
93 | ) );
94 |
95 | $admin_cap = 'manage_options';
96 | if ( is_multisite() ) {
97 | $admin_cap = 'manage_network_options';
98 | }
99 |
100 | if ( in_array( $cap, $admin_caps, true ) ) {
101 | $caps = array( $admin_cap );
102 | } else {
103 | $caps = array( $required_cap );
104 | $manage_caps = array(
105 | 'edit_user_upload',
106 | 'delete_user_upload',
107 | );
108 |
109 | $author = 0;
110 | if ( ! empty( $args[0] ) ) {
111 | $author = get_post_field( 'post_author', $args[0] );
112 | }
113 |
114 | if ( in_array( $cap, $manage_caps, true ) && ( ! $author || (int) $author !== (int) $user_id ) ) {
115 | $caps = array( $admin_cap );
116 | }
117 | }
118 | }
119 |
120 | // Allow regular users to set the User Media display preference if WP Editor is used from front-end.
121 | } elseif ( wp_doing_ajax() && isset( $_POST['action'] ) && 'parse-embed' === $_POST['action'] ) {
122 | if ( $user_id && ! empty( $_POST['shortcode'] ) ) {
123 | $url = str_replace( array( '[embed]', '[/embed]' ), '', $_POST['shortcode'] );
124 |
125 | if ( 0 === strpos( $url, trailingslashit( network_site_url() ) . mediatheque_get_root_slug() ) ) {
126 | $caps = array( mediatheque_get_required_cap() );
127 | }
128 | }
129 | }
130 |
131 | /**
132 | * Filter here to edit the capabilities map.
133 | *
134 | * @since 1.0.0
135 | *
136 | * @param array $caps Capabilities for meta capability
137 | * @param string $cap Capability name
138 | * @param int $user_id User id
139 | * @param mixed $args Arguments
140 | */
141 | return apply_filters( 'mediatheque_map_meta_caps', $caps, $cap, $user_id, $args );
142 | }
143 |
144 | /**
145 | * Sanitize the disk usage or personal avatar id user meta.
146 | *
147 | * @since 1.0.0
148 | *
149 | * @param int $value The raw value of the disk usage user meta.
150 | * @param string $meta_key The user meta key.
151 | * @return int $value The sanitized disk usage user meta.
152 | */
153 | function mediatheque_meta_sanitize_value( $value = '', $meta_key = '' ) {
154 | if ( '_mediatheque_disk_usage' === $meta_key || 'personal_avatar' === $meta_key ) {
155 | $value = (int) $value;
156 | }
157 |
158 | return $value;
159 | }
160 |
161 | /**
162 | * Auth callback for the Personal avatar usermeta.
163 | *
164 | * @since 1.0.0
165 | *
166 | * @param boolean $auth True to allow edit. False otherwise.
167 | * @param string $meta_key The usermeta key.
168 | * @param integer $object_id The Object Id.
169 | * @param integer $user_id The User ID.
170 | * @return boolean True to allow edit. False otherwise.
171 | */
172 | function mediatheque_meta_auth_personal_avatar( $auth = false, $meta_key = '', $object_id = 0, $user_id = 0 ) {
173 | if ( 'personal_avatar' !== $meta_key ) {
174 | return $auth;
175 | }
176 |
177 | return ! empty( $object_id ) && ( (int) $object_id === (int) $user_id || is_super_admin() );
178 | }
179 |
180 | /**
181 | * Prepare the disk usage user meta for rest requests.
182 | *
183 | * @since 1.0.0
184 | *
185 | * @param mixed $value Meta value to prepare.
186 | * @param WP_REST_Request $request Rest request object.
187 | * @param array $args Options for the field.
188 | * @return string $value The prepared value.
189 | */
190 | function mediatheque_disk_usage_prepare( $value, WP_REST_Request $request, $args ) {
191 | return mediatheque_format_file_size( $value );
192 | }
193 |
194 | /**
195 | * Update a user's disk usage.
196 | *
197 | * @since 1.0.0
198 | *
199 | * @param int $user_id The ID of the user.
200 | * @param int $bytes The number of bytes to add to user's disk usage.
201 | * @return bool True on success, false otherwise.
202 | */
203 | function mediatheque_disk_usage_update( $user_id = 0, $bytes = 0, $remove = false ) {
204 | if ( empty( $user_id ) || empty( $bytes ) ) {
205 | return false;
206 | }
207 |
208 | $kilo_bytes = absint( $bytes / 1000 );
209 |
210 | // Do nothing if the file is less than a kilobyte.
211 | if ( ! $kilo_bytes ) {
212 | return true;
213 | }
214 |
215 | // Get the user's disk usage
216 | $disk_usage = (int) get_user_meta( $user_id, '_mediatheque_disk_usage', true );
217 |
218 | if ( $disk_usage ) {
219 | if ( true === $remove ) {
220 | $disk_usage = $disk_usage - $kilo_bytes;
221 | } else {
222 | $disk_usage = $disk_usage + $kilo_bytes;
223 | }
224 |
225 | } elseif ( true !== $remove ) {
226 | $disk_usage = $kilo_bytes;
227 | }
228 |
229 | // no negative disk usage!
230 | if ( $disk_usage < 0 ) {
231 | delete_user_meta( $user_id, '_mediatheque_disk_usage' );
232 |
233 | // Update user's disk usage.
234 | } else {
235 | update_user_meta( $user_id, '_mediatheque_disk_usage', absint( $disk_usage ) );
236 | }
237 |
238 | return true;
239 | }
240 |
241 | /**
242 | * Add an additionnal rest query params to users.
243 | *
244 | * @since 1.0.0
245 | *
246 | * @param array $query_params The query params for the users collection
247 | * @return array The query params for the users collection.
248 | */
249 | function mediatheque_additionnal_user_rest_param( $query_params = array() ) {
250 | return array_merge( $query_params, array(
251 | 'has_disk_usage' => array(
252 | 'description' => __( 'True pour limiter les résultats aux utilisateurs ayant soumis des fichiers.', 'mediatheque' ),
253 | 'type' => 'boolean',
254 | )
255 | ) );
256 | }
257 |
258 | /**
259 | * Prepare the disk usage user meta for rest requests.
260 | *
261 | * @since 1.0.0
262 | *
263 | * @param array $prepared_args The prepared params for the users collection.
264 | * @param WP_REST_Request $request Rest request object.
265 | * @return array $prepared_args The prepared params for the users collection.
266 | */
267 | function mediatheque_rest_user_query( $prepared_args, WP_REST_Request $request ) {
268 | if ( $request->get_param( 'has_disk_usage' ) ) {
269 | $capacity = 'list_users';
270 |
271 | if ( is_multisite() ) {
272 | $capacity = 'manage_network_users';
273 | }
274 |
275 | $headers = $request->get_headers();
276 | if ( ! empty( $headers['referer'] ) ) {
277 | $referer = array_shift( $headers['referer'] );
278 | $is_network_admin = 0 === strpos( $referer, network_admin_url() );
279 | }
280 |
281 | // Regular users/site admins can't browse or edit other users files.
282 | if ( ! current_user_can( $capacity ) || empty( $is_network_admin ) ) {
283 | return array_merge( $prepared_args, array( 'login' => '0' ) );
284 |
285 | // Authorized users can browse and edit other users files.
286 | } else {
287 | $p_args = array(
288 | 'meta_key' => '_mediatheque_disk_usage',
289 | 'meta_compare' => 'EXISTS',
290 | );
291 |
292 | // Reset the blog ID to 0 to get all network users.
293 | if ( ! empty( $is_network_admin ) ) {
294 | $p_args['blog_id'] = 0;
295 | }
296 |
297 | // We are only listing the users who uploaded at least one file.
298 | $prepared_args = array_merge( $prepared_args, $p_args );
299 |
300 | // Make sure the Admin has the meta set to include him in results.
301 | $user_id = get_current_user_id();
302 |
303 | $disk_usage = get_user_meta( $user_id, '_mediatheque_disk_usage', true );
304 | if ( ! is_numeric( $disk_usage ) ) {
305 | update_user_meta( $user_id, '_mediatheque_disk_usage', 0 );
306 | }
307 | }
308 | }
309 |
310 | return $prepared_args;
311 | }
312 |
313 | /**
314 | * Remove all user's data when removed from the site.
315 | *
316 | * NB: No reassign is performed for now, it would require to move files and directories
317 | * and to regenerate all user media metadata. A hook is available if you want to build
318 | * this reassign.
319 | *
320 | * @since 1.0.0
321 | *
322 | * @param integer $user_id The deleted user's ID.
323 | * @param integer $reassign The reassigned user's ID.
324 | */
325 | function mediatheque_delete_user_data( $user_id = 0, $reassign = 0 ) {
326 | if ( ! $user_id ) {
327 | return;
328 | }
329 |
330 | $is_main_site = mediatheque_is_main_site();
331 |
332 | if ( ! $is_main_site ) {
333 | switch_to_blog( get_current_network_id() );
334 | }
335 |
336 | $mediatheque_statuses = wp_list_pluck( mediatheque_get_post_statuses( 'all' ), 'name' );
337 |
338 | $d_user_media = get_posts( array(
339 | 'post_type' => 'user_media',
340 | 'author' => $user_id,
341 | 'nopaging' => true,
342 | 'no_found_rows' => true,
343 | 'post_status' => $mediatheque_statuses,
344 | ) );
345 |
346 | /**
347 | * Hook here to use your own way of dealing with user deletion.
348 | *
349 | * NB: $d_user_media is passed by reference, setting it to an empty array
350 | * within your function will shortcircuit the rest of the function.
351 | *
352 | * @param integer $user_id The deleted user's ID.
353 | * @param integer $reassign The reassigned user's ID.
354 | * @param array $d_user_media The User Media to delete.
355 | */
356 | do_action_ref_array( 'mediatheque_before_delete_user_data', array( $user_id, $reassign, &$d_user_media ) );
357 |
358 | if ( empty( $d_user_media ) ) {
359 | return;
360 | }
361 |
362 | foreach ( $d_user_media as $user_media ) {
363 | mediatheque_delete_media( $user_media );
364 | }
365 |
366 | $mediatheque_upload_dir = mediatheque_get_upload_dir();
367 |
368 | foreach ( $mediatheque_statuses as $status ) {
369 | $dirpath = $mediatheque_upload_dir['path'] . '/' . $status . '/' . $user_id;
370 |
371 | if ( ! is_dir( $dirpath ) ) {
372 | continue;
373 | }
374 |
375 | // Remove the empty directory
376 | @ rmdir( $dirpath );
377 | }
378 |
379 | if ( ! $is_main_site ) {
380 | restore_current_blog();
381 | }
382 | }
383 |
--------------------------------------------------------------------------------
/languages/mediatheque.pot:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2021 imath
2 | # This file is distributed under the GNU/GPL 2.
3 | msgid ""
4 | msgstr ""
5 | "Project-Id-Version: MediaThèque 1.4.0-alpha\n"
6 | "Report-Msgid-Bugs-To: https://github.com/imath/mediatheque/issues\n"
7 | "POT-Creation-Date: 2021-09-05 14:16:42+00:00\n"
8 | "MIME-Version: 1.0\n"
9 | "Content-Type: text/plain; charset=utf-8\n"
10 | "Content-Transfer-Encoding: 8bit\n"
11 | "PO-Revision-Date: 2021-MO-DA HO:MI+ZONE\n"
12 | "Last-Translator: imath