forked from buddydev/mediapress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mediapress.php
658 lines (534 loc) · 12.8 KB
/
mediapress.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
<?php
/**
* Plugin Name: MediaPress
* Version: 1.0 Beta 1
* Author: Brajesh Singh
* Plugin URI: http://buddydev.com/mediapress/
* Author URI: http://buddydev.com
* Description: MediaPress is the most powerful media plugin for BuddyPress. It allows uploading images(photos), videos, audios, documents
* and can be used to add any type of content. It has a well defined api to allow extending the plugin.
* License: GPL2 or above
*/
define( 'MPP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'MPP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
/**
* The main MediaPress Singleton class
* you can access the singleton instance using mediapress() function
*
* @see mediapress()
*
* Life begins here
*
*/
class MediaPress {
/**
*
* Private instace of the MediaPress class
*
* @var MediaPress
*/
private static $instance;
/**
* We keep any extra data here to pass around
*
* @var array mof mixed data
*/
private $data = array();
/**
* file system absolute path to the mediapress plugin eg. /home/xyz/public_html/wp-content/plugins/mediapress/
*
* @var string
*/
private $plugin_path;
/**
* Absolute url to the mediapress plugin directory e.g http://example.com/wp-content/plugins/mediapress/
*
* @var string
*/
private $plugin_url;
/**
* relative path to this plugin
*
* @var string
*/
private $basename;
/**
* List of assets k=>v pair where k: asset identifier, v = url
*
* @var array
*/
private $assets = array();
/**
*
* @var MPP_Gallery_Query
*/
public $the_gallery_query; //main gallery query
/**
*
* @var MPP_Media_Query
*/
public $the_media_query; //main media query
/**
* Current Gallery object is stored here
*
* @var MPP_Gallery
*/
public $current_gallery;
/**
* Current Media Object is stored here
*
* @var MPP_Media
*/
public $current_media;
/**
* Not Used
*
* @var MPP_Comment_Query
*/
public $the_comment_query;
public $current_comment;
/**
*
* @var MPP_Status[] array of status objects
*/
public $statuses = array();
/**
*
* @var MPP_Status[] array of status objects which are valid for gallery
*/
public $gallery_statuses = array();
/**
*
* @var MPP_Status[] array of status objects which are valid for Media
*/
public $media_statuses = array();
/**
*
* @var MPP_Component[] array of Component objects where keys are component identifier
*/
public $components = array();
/**
*
* @var MPP_Type[] array of Media|Gallery type object
*/
public $types = array();
/**
* There are the statuses which are allowed by site admin
*
* @var MPP_Status[] array of status objects
*/
public $active_statuses = array();
/**
* Array of components which are allowed to have a gallery
*
* @var MPP_Component[] array of Component objects where keys are component identifier
*/
public $active_components = array();
/**
* Array of types allowed for the gallery
*
* @var MPP_Type[] array of Media|Gallery type object
*/
public $active_types = array();
/**
* An array of registered storage managers
*
* @var MPP_Storage_Manager[]
*/
public $storage_managers = array();
/**
*
* @var MPP_Media_View
*/
public $media_views;
/**
* Multi dimensional array to store the media size specific details
*
* @var mixed
*/
public $media_sizes = array();
//screen identifiers
public $is_gallery_home = false;
/**
* We keep the probable current action here and later move to $action if validated
*
* Do not use it in your plugins
*
* @var type
*/
private $temp_action = '';//it should be the action if validated but we can not say that with confident yet 100%. Fo checking current action, please use get_action
/**
*
* @var string current action manage/edit etc
*/
private $action = '';
/**
* Current edit action only valid if the main action is edit/manage
*
* @var string
*/
private $edit_action = '';
/**
* Action variable stack, we use it to provide consistency for all components
*
* @var type
*/
private $action_variables = array();
/**
* Which object type is ebing edited, gallery or media?
*
* @var string
*/
private $editing_item_type = '';//gallery|media
/**
* Restricted media slugs
*
* @var array()
*/
private $restricted_media_slugs = array( 'edit', 'delete', 'publish', 'reorder', 'manage', 'gallery' );
/**
* Contains gallery/media admin menus
*
* @var MPP_Menu[]
*/
private $menus = array(); // $menus['gallery'], $menus['media']
private function __construct() {
$this->basename = basename( MPP_PLUGIN_DIR ) . '/' . basename( __FILE__ );
$this->core_init();
}
/**
* Factory method to generate/access singleton instance
*
* @return MediaPress
*/
public static function get_instance() {
if ( ! isset( self::$instance ) )
self::$instance = new self();
return self::$instance;
}
public function core_init() {
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->plugin_url = plugin_dir_url( __FILE__ );
add_action( 'bp_include', array( $this, 'load_core' ) );
add_action( 'bp_include', array( $this, 'load_textdomain' ) );
add_action( 'init', array( $this, 'init' ), 2 );
}
public function load_core() {
$files = array(
'core/common/feedback.php',
'core/common/common.sql.php',
'core/common/functions.php',
'core/common/init.php',
'core/common/query-gallery.php',
'core/common/query-media.php',
'core/post-type.php',
'core/common/taxonomy.php',
'core/common/class-menu-manager.php',
'core/common/class-features.php',
'core/gallery/class-gallery.php',
'core/gallery/conditionals.php',
'core/gallery/cover-templates.php',
'core/gallery/functions.php',
'core/gallery/link-template.php',
'core/gallery/meta.php',
'core/gallery/screen.php',
'core/gallery/template-tags.php',
'core/gallery/hooks.php',
'core/gallery/actions.php',
'core/media/functions.php',
'core/media/meta.php',
'core/media/class-media.php',
'core/media/template-tags.php',
'core/media/link-templates.php',
'core/media/actions.php',
'core/media/cover-template.php',
//media viewer
'core/media/views/media-view-base.php',
'core/media/views/media-view-doc.php', //for doc files
'core/media/views/media-view-video.php', //for video files
'core/media/views/media-view-audio.php', //for audio files
//api
'core/api/api.php',
'core/hooks.php',
//user
'core/users/meta.php',
'core/users/hooks.php',
//activity
'core/activity/functions.php',
'core/activity/actions.php',
'core/activity/template.php',
'core/activity/hooks.php',
//comment
'core/comments/functions.php',
'core/comments/template-tags.php',
//component loader
'loader.php',
'assets/script-loader.php',
'core/ajax.php',
'core/template-helpers.php',
'core/permissions.php',
//storage related
'core/storage/functions.php',
'core/storage/space-stats.php',
'core/storage/storage-manager.php',
'core/storage/local-storage.php',
'core/shortcodes/functions.php',
'core/shortcodes/gallery-list.php',
'core/shortcodes/media-list.php',
'core/widgets/functions.php',
'core/widgets/widget-gallery.php',
'core/widgets/widget-media.php',
//extensions
'modules/groups/loader.php',
//theme compat
'core/theme-compat.php'
);
if( is_admin() )
$files[] = 'admin/init.php';
$bp_files = array();
$files = array_merge( $files, $bp_files );
$path = $this->get_path();
foreach ( $files as $file )
require_once $path . $file;
do_action( 'mpp_loaded' );
}
public function init() {
//allow to hook
do_action( 'mpp_init' );
}
public function load_textdomain() {
$locale = apply_filters( 'mpp_textdomain_get_locale', get_locale() );
$mofile_default = '';
// if load .mo file
if ( ! empty( $locale ) ) {
$mofile_default = sprintf( '%slanguages/%s.mo', $this->plugin_path, $locale );
$mofile = apply_filters( 'mpp_textdomain_mofile', $mofile_default );
if ( is_readable( $mofile ) ) {
// make sure file exists, and is readable
load_textdomain( 'mediapress', $mofile );
}
}
}
/**
* Get the url of the MediaPress plugin directory
*
* @return string
*/
public function get_url() {
return $this->plugin_url;
}
/**
* Get the absolute path to the mediapress plugin directory
*
* @return string
*/
public function get_path() {
return $this->plugin_path;
}
/**
* Get the relative path of this file from the plugins directory e.g mediapress/mediapress.php
* @return type
*/
public function get_basename() {
return $this->basename;
}
/**
* Get the url of an asset
*
* @param type $key
* @return string
*/
public function get_asset( $key ) {
if ( isset( $this->assets[ $key ] ) )
return $this->assets[ $key ];
return ''; //empty
}
/**
* Add an asset to our cached collection
*
* @param type $key unique key for the asset
* @param type $asset_url
* @return string asset url
*/
public function add_asset( $key, $asset_url ) {
$this->assets[ $key ] = $asset_url;
return $asset_url;
}
/**
* Set current action
*
* @param type $action
* @return string
*/
public function set_action( $action ) {
$this->action = $action;
return $this->action;
}
/**
* Get current acion
*
* @return type
*/
public function get_action() {
return $this->action;
}
/**
* Check for current action
*
* @param type $action
* @return type
*/
public function is_action( $action ) {
return $this->get_action() == $action;
}
/**
* Set action variables array
*
* @param array $av
*/
public function set_action_variables( $av = array() ) {
$this->action_variables = $av;
}
/**
* Get action variables array
*
* @return array
*/
public function get_action_variables() {
return $this->action_variables;
}
/**
* Get an action varibale by position
*
* @param type $pos
*/
public function get_action_variable( $pos = 0 ) {
isset( $this->action_variables[$pos] )? $this->action_variables[$pos] : '';
}
/**
* Set the current probably happening action
*
* @internal sets temporary action
* @param type $action
*/
public function _set_temp_action( $action ) {
$this->temp_action = $action;
}
/**
* For Internal Use
* get the current probable action
*
*/
public function _get_temp_action( ) {
return $this->temp_action ;
}
/**
* Set edit action
*
* @param string $action
*/
public function set_edit_action( $action ) {
$this->edit_action = $action;
}
/**
* Get edit action
*
* @return string
*/
public function get_edit_action() {
return $this->edit_action;
}
/**
* Check if the given edit action is
*
* @param type $action
* @return type
*/
public function is_edit_action( $action ) {
return $this->edit_action == $action ;
}
/**
* Set current editing object type
* Bad choice of name, I know
* Suggest a better name if you can!
*
* @param string $type mpp_get_gallery_post_type() or mpp_get_media_post_type()
*/
public function set_editing( $type ) {
$this->editing_item_type = $type;
}
/**
* Get the object type being edited now
*
* @return string 'media'|'gallery'
*/
public function get_editing() {
$this->editing_item_type = $type;
}
/**
* Check if the current object being edited is of given type
*
* @param type $type
* @return type
*/
public function is_editing( $type ) {
return $type == $this->editing_item_type;
}
/**
* Get the given MPP_Menu object by the menu name
*
* @param string media|gallery
* @return MPP_Menu
*/
public function get_menu( $type ) {
return $this->menus[ $type ];
}
/**
* Add menu for the Gallery/media
*
* @param string $type
* @param MPP_Menu $menu
*/
public function add_menu( $type, $menu ) {
$this->menus[ $type ] = $menu;
}
/**
* Store some arbitrary data
* most of the time we use to pass the things around methods like a global
*
* @param type $type
* @param type $data
*/
public function add_data( $type, $data ) {
$this->data[$type] = $data;
}
/**
* Get the arbitrary data stored by the key
*
* @param type $type
* @return boolean
*/
public function get_data( $type ) {
if( isset( $this->data[$type] ) )
return $this->data[$type];
return false;
}
/**
* Reset the data set for this key
*
* @param type $type
*/
public function reset_data( $type ) {
unset( $this->data[$type] );
}
}
/**
* A shortcut function to allow access to the singleton instance of the mediapress
*
* @return MediaPress
*/
function mediapress() {
return MediaPress::get_instance();
}
//initialize
mediapress();