-
Notifications
You must be signed in to change notification settings - Fork 3
/
mediatheque.php
155 lines (132 loc) · 3.19 KB
/
mediatheque.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* Plugin Name: MediaThèque
* Plugin URI: https://imathi.eu/tag/mediatheque/
* Description: Une gestion alternative des media dans WordPress, pour tous.
* Version: 1.4.0-alpha
* Requires at least: 4.7
* Tested up to: 5.3
* License: GNU/GPL 2
* Author: imath
* Author URI: https://imathi.eu/
* Text Domain: mediatheque
* Domain Path: /languages/
* Network: True
* GitHub Plugin URI: https://github.com/imath/mediatheque/
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'MediaTheque' ) ) :
/**
* Main plugin's class
*
* @package mediatheque
*
* @since 1.0.0
*/
final class MediaTheque {
/**
* Plugin's main instance
*
* @var object
*/
protected static $instance;
/**
* Initialize the plugin
*
* @since 1.0.0
*/
private function __construct() {
$this->globals();
$this->inc();
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function start() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Setups plugin's globals
*
* @since 1.0.0
*/
private function globals() {
// Version
$this->version = '1.4.0-alpha';
// Domain
$this->domain = 'mediatheque';
// Base name
$this->file = __FILE__;
$this->basename = plugin_basename( $this->file );
// Path and URL
$this->dir = plugin_dir_path( $this->file );
$this->url = plugin_dir_url ( $this->file );
$this->js_url = trailingslashit( $this->url . 'js' );
$this->assets_url = trailingslashit( $this->url . 'assets' );
$this->inc_dir = trailingslashit( $this->dir . 'inc' );
$this->templates = trailingslashit( $this->dir . 'templates' );
$this->personal_avatars = array();
$this->user_media_oembeds = array();
$this->template_tags = new stdClass;
}
/**
* Includes plugin's needed files
*
* @since 1.0.0
*/
private function inc() {
spl_autoload_register( array( $this, 'autoload' ) );
require( $this->inc_dir . 'options.php' );
require( $this->inc_dir . 'users.php' );
require( $this->inc_dir . 'functions.php' );
require( $this->inc_dir . 'media.php' );
require( $this->inc_dir . 'templates.php' );
require( $this->inc_dir . 'upgrade.php' );
if ( mediatheque_use_personal_avatar() ) {
require( $this->inc_dir . 'avatars.php' );
}
if ( is_admin() ) {
require( $this->inc_dir . 'settings.php' );
}
// Last but not least!
require( $this->inc_dir . 'hooks.php' );
}
/**
* Class Autoload function
*
* @since 1.0.0
*
* @param string $class The class name.
*/
public function autoload( $class ) {
$name = str_replace( '_', '-', strtolower( $class ) );
if ( false === strpos( $name, $this->domain ) ) {
return;
}
$path = $this->inc_dir . "classes/class-{$name}.php";
// Sanity check.
if ( ! file_exists( $path ) ) {
return;
}
require $path;
}
}
endif;
/**
* Boot the plugin.
*
* @since 1.0.0
*/
function mediatheque() {
return MediaTheque::start();
}
add_action( 'plugins_loaded', 'mediatheque', 5 );