-
Notifications
You must be signed in to change notification settings - Fork 3
/
video-central.php
874 lines (738 loc) · 29.4 KB
/
video-central.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
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
<?php
/*
Plugin Name: Video Central
Plugin URI: http://plugins.radiumthemes.com/video-central
Description: The Ultimate Video Manager for WordPress
Author: Franklin Gitonga
Version: 1.3.1
Author URI: http://radiumthemes.com/
License: GPL v2+
*/
//To add later
/**
* 1. Channels
* 2. Upload from frontend
* 3. User accounts
* 4. Subscriptions
* 5. Watch Later
* 6. Playlists - in progress
* 7. Choice of multiple players
* 8. E-commerce
* 9. Membership levels
* 10. JSON API
* 11. Cron for auto importing videos.
*/
/* Load all of the necessary class files for the plugin (files from the Radium liblary) */
spl_autoload_register( 'Video_Central::autoload' );
/**
* Init class for Video Central.
*
* Loads all of the necessary components for the radium Video plugin.
*
* @since 1.0.0
*
* @author Franklin Gitonga
*/
class Video_Central
{
/**
* Current version of the plugin.
*
* @since 1.0.0
*
* @var string
*/
public $version = '1.3.1';
/**
* Current db version of the plugin.
*
* @since 1.0.0
*
* @var string
*/
public $db_version = '1.1';
/** Magic *****************************************************************/
/**
* Video Central uses many variables, several of which can be filtered to
* customize the way it operates. Most of these variables are stored in a
* private array that gets updated with the help of PHP magic methods.
*
* This is a precautionary measure, to avoid potential errors produced by
* unanticipated direct manipulation of Video Central's run-time data.
*
* @see video_central::setup_globals()
*
* @var array
*/
private $data;
/** Not Magic *************************************************************/
/**
* @var mixed False when not logged in; WP_User object when logged in
*/
public $current_user = false;
/**
* @var obj Add-ons append to this (Akismet, BuddyPress, etc...)
*/
public $extend;
/**
* @var array Video views
*/
public $views = array();
/**
* @var array Overloads get_option()
*/
public $options = array();
/**
* Getter method for retrieving the object instance.
*
* @since 1.0.0
*/
public static function instance()
{
// Store the instance locally to avoid private static replication
static $instance = null;
// Only run these methods if they haven't been ran previously
if (null === $instance) {
$instance = new self();
$instance->setup_globals();
$instance->includes();
$instance->setup_actions();
}
// Always return the instance
return $instance;
}
/** Magic Methods *********************************************************/
/**
* A dummy constructor to prevent Video Central from being loaded more than once.
*
* @since 1.0.0
* @see video_central::instance()
* @see video_central();
*/
private function __construct()
{ /* Do nothing here */
}
/**
* A dummy magic method to prevent Video Central from being cloned.
*
* @since 1.0.0
*/
public function __clone()
{
_doing_it_wrong(__FUNCTION__, __( 'Cheatin’ huh?', 'video_central' ), '1.0' );
}
/**
* A dummy magic method to prevent Video Central from being unserialized.
*
* @since 1.0.0
*/
public function __wakeup()
{
_doing_it_wrong(__FUNCTION__, __( 'Cheatin’ huh?', 'video_central' ), '1.0' );
}
/**
* Magic method for checking the existence of a certain custom field.
*
* @since 1.0.0
*/
public function __isset( $key)
{
return isset( $this->data[$key]);
}
/**
* Magic method for getting Video Central variables.
*
* @since 1.0.0
*/
public function __get( $key)
{
return isset( $this->data[$key]) ? $this->data[$key] : null;
}
/**
* Magic method for setting Video Central variables.
*
* @since 1.0.0
*/
public function __set( $key, $value)
{
$this->data[$key] = $value;
}
/**
* Magic method for unsetting Video Central variables.
*
* @since 1.0.0
*/
public function __unset( $key)
{
if ( isset( $this->data[$key] ) ) {
unset( $this->data[$key]);
}
}
/**
* Magic method to prevent notices and errors from invalid method calls.
*
* @since 1.0.0
*/
public function __call( $name = '', $args = array() )
{
unset( $name, $args );
return;
}
/** Private Methods *******************************************************/
/**
* Set some smart defaults to class variables. Allow some of them to be
* filtered to allow for early overriding.
*
* @since 1.0.0
*
* @uses plugin_dir_path() To generate Video Central plugin path
* @uses plugin_dir_url() To generate Video Central plugin url
* @uses apply_filters() Calls various filters
*/
private function setup_globals()
{
/* Paths *************************************************************/
// Setup some base path and URL information
$this->file = __FILE__;
$this->basename = apply_filters( 'video_central_plugin_basenname', plugin_basename( $this->file ) );
$this->plugin_dir = apply_filters( 'video_central_plugin_dir_path', plugin_dir_path( $this->file ) );
$this->plugin_url = apply_filters( 'video_central_plugin_dir_url', plugin_dir_url( $this->file ) );
// core assets
$this->core_assets_dir = apply_filters( 'video_central_core_assets_dir', trailingslashit( $this->plugin_dir . 'assets' ) );
$this->core_assets_url = apply_filters( 'video_central_core_assets_url', trailingslashit( $this->plugin_url.'assets' ) );
// Includes
$this->includes_dir = apply_filters( 'video_central_includes_dir', trailingslashit( $this->plugin_dir . 'includes' ) );
$this->includes_url = apply_filters( 'video_central_includes_url', trailingslashit( $this->plugin_url.'includes' ) );
// Languages
$this->lang_dir = apply_filters( 'video_central_lang_dir', trailingslashit( $this->plugin_dir . 'languages' ) );
// Templates
$this->themes_dir = apply_filters( 'video_central_themes_dir', trailingslashit( $this->plugin_dir . 'templates' ) );
$this->themes_url = apply_filters( 'video_central_themes_url', trailingslashit( $this->plugin_url.'templates' ) );
/* Identifiers *******************************************************/
// Post type identifiers
$this->video_post_type = apply_filters( 'video_central_videos_post_type', 'video' );
$this->video_tag_tax_id = apply_filters( 'video_central_videos_tag_tax_id', 'video_tag' );
$this->video_cat_tax_id = apply_filters( 'video_central_videos_cat_tax_id', 'video_category' );
$this->playlist_post_type = apply_filters( 'video_central_playlists_post_type', 'playlist' );
// Status identifiers
$this->spam_status_id = apply_filters( 'video_central_spam_post_status', 'spam' );
$this->closed_status_id = apply_filters( 'video_central_closed_post_status', 'closed' );
$this->public_status_id = apply_filters( 'video_central_public_post_status', 'publish' );
$this->pending_status_id = apply_filters( 'video_central_pending_post_status', 'pending' );
$this->private_status_id = apply_filters( 'video_central_private_post_status', 'private' );
$this->hidden_status_id = apply_filters( 'video_central_hidden_post_status', 'hidden' );
$this->trash_status_id = apply_filters( 'video_central_trash_post_status', 'trash' );
$this->search_id = apply_filters( 'video_central_search_id', 'video_search' );
$this->user_id = apply_filters( 'video_central_user_id', 'video_user' );
$this->view_id = apply_filters( 'video_central_view_id', 'video_view' );
/* Queries ***********************************************************/
$this->current_view_id = 0; // Current view id
$this->current_video_id = 0; // Current video id
$this->video_query = new WP_Query(); // Main video query
$this->playlist_query = new WP_Query(); // Main playlist query
$this->search_query = new WP_Query(); // Main search query
/* Theme Compat ******************************************************/
$this->theme_compat = new stdClass(); // Base theme compatibility class
$this->filters = new stdClass(); // Used when adding/removing filters
$this->admin = new StdClass(); // Used by admin
/* Misc **************************************************************/
$this->providers = array();
$this->domain = 'video_central'; // Unique identifier for retrieving translated strings
$this->extend = new stdClass(); // Plugins add data here
$this->errors = new WP_Error(); // Feedback
}
/**
* Include required files.
*
* @since 1.0.0
*
* @uses is_admin() If in WordPress admin, load additional file
*/
private function includes()
{
/** Core **************************************************************/
require $this->includes_dir . 'core/sub-actions.php';
require $this->includes_dir . 'core/functions.php';
require $this->includes_dir . 'core/options.php';
require $this->includes_dir . 'core/update.php';
require $this->includes_dir . 'core/capabilities.php';
require $this->includes_dir . 'core/template-functions.php';
require $this->includes_dir . 'core/template-loader.php';
require $this->includes_dir . 'core/theme-compat.php';
/** Components ********************************************************/
// Common
require $this->includes_dir . 'common/functions.php';
require $this->includes_dir . 'common/template.php';
//images
require $this->includes_dir . 'modules/import/thumbnail.php';
require $this->includes_dir . 'modules/resize.php';
// Videos
require $this->includes_dir . 'videos/class.posttype.php';
require $this->includes_dir . 'videos/capabilities.php';
require $this->includes_dir . 'videos/functions.php';
require $this->includes_dir . 'videos/template.php';
require $this->includes_dir . 'videos/metaboxes.php';
// Player
require $this->includes_dir . 'player/functions.php';
require $this->includes_dir . 'player/template.php';
// Search
require $this->includes_dir . 'search/functions.php';
require $this->includes_dir . 'search/template.php';
// Users
require $this->includes_dir . 'users/capabilities.php';
require $this->includes_dir . 'users/functions.php';
require $this->includes_dir . 'users/template.php';
// require( $this->includes_dir . 'users/options.php' );
// playlist
require $this->includes_dir . 'playlist/class.posttype.php';
require $this->includes_dir . 'playlist/class.ajax.php';
require $this->includes_dir . 'playlist/class.editplaylist.php';
require $this->includes_dir . 'playlist/functions.php';
require $this->includes_dir . 'playlist/template.php';
require $this->includes_dir . 'playlist/metaboxes.php';
// Likes
require $this->includes_dir . 'modules/likes/functions.php';
require $this->includes_dir . 'modules/likes/ajax.php';
// Widgets
require $this->includes_dir . 'widgets/widget-categories.php';
require $this->includes_dir . 'widgets/widget-featured.php';
require $this->includes_dir . 'widgets/widget-popular.php';
require $this->includes_dir . 'widgets/widget-recent.php';
require $this->includes_dir . 'widgets/widget-search.php';
require $this->includes_dir . 'widgets/widget-tags.php';
/** Hooks *************************************************************/
require $this->includes_dir . 'core/actions.php';
require $this->includes_dir . 'core/filters.php';
// Woosidebars integration
require $this->includes_dir . 'modules/third-party/class.woosidebars.integration.php';
// Visual Composer
require $this->includes_dir . 'modules/third-party/visual-composer/functions.php';
require $this->includes_dir . 'modules/third-party/visual-composer/integrate.php';
/* Admin *************************************************************/
if ( is_admin() ) :
// Quick admin check and load if needed
require $this->includes_dir . 'admin/admin.php';
require $this->includes_dir . 'admin/actions.php';
require $this->includes_dir . 'admin/fields.php';
// Check that 'class-wp-list-table.php' is available
if ( ! class_exists( 'WP_List_Table' ) ) :
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
endif;
// Metaboxes
include_once $this->includes_dir . 'modules/metaboxes/loader.php';
// Modules (Modules can run as 'independent' plugins to enhance or add features)
include_once $this->includes_dir . 'modules/import/options.php';
include_once $this->includes_dir . 'modules/import/video/class.settings.php';
include_once $this->includes_dir . 'modules/import/video/class.thumbnails-providers.php';
include_once $this->includes_dir . 'modules/import/video/class.wizard.php';
include_once $this->includes_dir . 'modules/import/video/class.importer.php';
// Import youtube videos
include_once $this->includes_dir . 'modules/import/youtube/functions.php';
include_once $this->includes_dir . 'modules/import/youtube/class.api-query.php';
include_once $this->includes_dir . 'modules/import/youtube/class.importer.php';
include_once $this->includes_dir . 'modules/import/youtube/class.auto.importer.php';
include_once $this->includes_dir . 'modules/import/youtube/class.thumbnails.php';
include_once $this->includes_dir . 'modules/import/youtube/class.wizard.php';
include_once $this->includes_dir . 'modules/import/youtube/class.list-table.php';
// Import youtube videos
//include_once $this->includes_dir . 'modules/import/vimeo/functions.php';
//include_once $this->includes_dir . 'modules/import/vimeo/class.importer.php';
//include_once $this->includes_dir . 'modules/import/vimeo/class.importer-data.php';
include_once $this->includes_dir . 'modules/import/vimeo/class.thumbnails.php';
//include_once $this->includes_dir . 'modules/import/vimeo/class.wizard.php';
//include_once $this->includes_dir . 'modules/import/vimeo/class.list-table.php';
else :
// frontend includes
endif;
}
/**
* Constructor. Hooks all interactions into correct areas to start
* the class.
*
* @since 1.0.0
*/
public function setup_actions()
{
// Add actions to plugin activation and deactivation hooks
add_action( 'activate_' . $this->basename, 'video_central_activation' );
add_action( 'deactivate_' . $this->basename, 'video_central_deactivation' );
// If Video Central is being deactivated, do not add any actions
if ( video_central_is_deactivation( $this->basename ) ) {
return;
}
// Array of Video Central core actions
$actions = array(
'init_classes', // Load plugin classes
'setup_theme', // Setup the default theme compatibility
'register_views', // Register the views (popular, latest)
'register_theme_packages', // Register bundled theme packages (templates/default)
'register_shortcodes', // Register shortcodes
'load_textdomain', // Load textdomain (video_central)
'enqueue_scripts',
'add_rewrite_tags', // Add rewrite tags (search)
'add_rewrite_rules', // Generate rewrite rules (paged|search)
'add_permastructs', // Add permalink structures (|search)
);
// Add the actions
foreach ( $actions as $class_action) {
add_action( 'video_central_' . $class_action, array( $this, $class_action ), 5 );
}
// All Video Central actions are setup (includes video-central-core-hooks.php)
do_action_ref_array( 'video_central_after_setup_actions', array( &$this ) );
//Add Page Templates
add_action( 'after_setup_theme', array( 'Radium_Video_Template', 'get_instance' ) ); // Load late for filters to work
}
/**
* Registers a plugin activation hook to make sure the current WordPress
* version is suitable (>= 3.3.1) for use.
*
* @since 1.0.0
*
* @global int $wp_version The current version of this particular WP instance
*/
public function activation()
{
global $wp_version;
if (version_compare( $wp_version, '3.0.0', '<' ) ) {
deactivate_plugins( plugin_basename(__FILE__ ) );
wp_die(printf( __( 'Sorry, but your version of WordPress, <strong>%s</strong>, does not meet the Video Central\'s required version of <strong>3.3.1</strong> to run properly. The plugin has been deactivated. <a href="%s">Click here to return to the Dashboard</a>', 'video_central' ), $wp_version, admin_url() ));
}
}
/**
* Loads the plugin classes.
*
* @since 1.0.0
*/
public function init_classes()
{
/* Load the plugin */
new Video_Central_Video_Posttype();
new Radium_MediaElements_Shortcode();
new Video_Central_Playlist_Posttype();
new Video_Central_Playlist_Ajax();
new Video_Central_Map_Shortcode();
// Only run certain processes in the admin.
if ( is_admin() ) :
$this->metaboxes = new Video_Central_Metaboxes_Loader();
$this->metaboxes->init();
// $this->playlist_admin = new Video_Central_Playlist_Admin();
new Video_Central_Playlist_EditPlaylist();
$this->import_thumbnails = new Video_Central_Import_Thumbnails();
//$this->auto_import_youtube = new Video_Central_Youtube_Auto_Importer;
new Video_Central_Likes_Ajax();
endif;
}
/**
* loads the frontend core assets.
*
* @since 1.0.0
*/
public function enqueue_scripts()
{
if ( ! is_video_central() ) {
return;
}
//video js (http://videojs.com)
wp_enqueue_script( 'video-central-player', $this->core_assets_url . 'frontend/js/video-js.js', array( 'jquery' ), $this->version, true);
//custom css files
wp_enqueue_style( 'video-central-player-style', $this->core_assets_url.'frontend/css/video-js.css', array(), $this->version);
}
/**
* Registers the widget with WordPress.
*
* @since 1.0.0
*/
public function widget()
{
register_widget( 'Radium_Video_Widget' );
}
/**
* Register bundled theme packages.
*
* Note that since we currently have complete control over video-central-themes and
* the video-central-theme-compat folders, it's fine to hardcode these here. If at a
* later date we need to automate this, and API will need to be built.
*
* @since 1.0.0
*/
public function register_theme_packages()
{
// Register the default theme compatibility package
video_central_register_theme_package(array(
'id' => 'default',
'name' => __( 'Videos Default', 'video_central' ),
'version' => $this->version,
'dir' => trailingslashit( $this->themes_dir . 'default' ),
'url' => trailingslashit( $this->themes_url.'default' ),
) );
// Register the basic theme stack. This is really dope.
video_central_register_template_stack( 'get_stylesheet_directory', 10);
video_central_register_template_stack( 'get_template_directory', 12);
video_central_register_template_stack( 'video_central_get_theme_compat_dir', 14);
}
/**
* Setup the default Video Central theme compatibility location.
*
* @since 1.0.0
*/
public function setup_theme()
{
// Bail if something already has this under control
if (!empty( $this->theme_compat->theme ) ) {
return;
}
// Setup the theme package to use for compatibility
video_central_setup_theme_compat(video_central_get_theme_package_id() );
}
/**
* Register the Video Central views.
*
* @since 1.0.0
*
* @uses video_central_register_view() To register the views
*/
public static function register_views()
{
// Popular videos
video_central_register_view(
'popular', __( 'Most popular videos', 'video_central' ),
apply_filters( 'video_central_register_view_popular', array(
'meta_key' => '_video_central_video_views_count',
'max_num_pages' => 1,
'orderby' => 'meta_value_num',
'show_stickies' => false,
) )
);
// Latest videos
video_central_register_view(
'latest', __( 'Latest videos', 'video_central' ),
apply_filters( 'video_central_register_view_latest', array(
'max_num_pages' => 1,
'orderby' => 'date',
'show_stickies' => false,
) )
);
// Latest videos
video_central_register_view(
'featured', __( 'Featured videos', 'video_central' ),
apply_filters( 'video_central_register_view_featured', array(
'meta_key' => '_video_central_featured_video',
'max_num_pages' => 1,
'orderby' => 'meta_value_num date',
'show_stickies' => false,
) )
);
}
/**
* Register the Video Central shortcodes.
*
* @since 1.0.0
*
* @uses Radium_Video_Shortcodes
*/
public function register_shortcodes()
{
$this->shortcodes = new Radium_Video_Shortcodes();
}
/**
* Load the translation file for current language. Checks the languages
* folder inside the Video Central plugin first, and then the default WordPress
* languages folder.
*
* Note that custom translation files inside the Video Central plugin folder
* will be removed on Video Central updates. If you're creating custom
* translation files, please use the global language folder.
*
* @since 1.0.0
*
* @uses apply_filters() Calls 'plugin_locale' with {@link get_locale()} value
* @uses load_textdomain() To load the textdomain
*/
public function load_textdomain()
{
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), $this->domain);
$mofile = $locale.'.mo';
// Setup paths to current locale file
$mofile_local = $this->lang_dir.$mofile;
$mofile_global = WP_LANG_DIR.'/plugins/video-central/' . $mofile;
// Look in global /wp-content/languages/video-central folder
load_textdomain( $this->domain, $mofile_global);
// Look in local /wp-content/plugins/video-central/ folder
load_textdomain( $this->domain, $mofile_local);
// Look in global /wp-content/languages/plugins/
load_plugin_textdomain( $this->domain);
}
/** Custom Rewrite Rules **************************************************/
/**
* Add the Video Central-specific rewrite tags.
*
* @since 1.0.0
*
* @uses add_rewrite_tag() To add the rewrite tags
*/
public static function add_rewrite_tags()
{
add_rewrite_tag( '%'.video_central_get_view_rewrite_id().'%', '([^/]+)' ); // View Page tag
add_rewrite_tag( '%'.video_central_get_search_rewrite_id().'%', '([^/]+)' ); // Search Results tag
}
/**
* Add Video Central-specific rewrite rules for uri's that are not
* setup for us by way of custom post types or taxonomies. This includes:
* - Front-end editing
* - Video views
* - User profiles.
*
* @since 1.0.0
*/
public static function add_rewrite_rules()
{
/* Setup *************************************************************/
// Add rules to top or bottom?
$priority = 'top';
// Archive Slugs
$search_slug = video_central_get_search_slug();
// Tertiary Slugs
$paged_slug = video_central_get_paged_slug();
$view_slug = video_central_get_view_slug();
// Unique rewrite ID's
$paged_id = video_central_get_paged_rewrite_id();
$search_id = video_central_get_search_rewrite_id();
$view_id = video_central_get_view_rewrite_id();
// Rewrite rule matches used repeatedly below
$root_rule = '/([^/]+)/?$';
$paged_rule = '/([^/]+)/' . $paged_slug.'/?([0-9]{1,})/?$';
// Search rules (without slug check)
$search_root_rule = '/?$';
$search_paged_rule = '/' . $paged_slug.'/?([0-9]{1,})/?$';
// Video-View Pagination|Feed|View
add_rewrite_rule( $view_slug.$paged_rule, 'index.php?' . $view_id.'=$matches[1]&' . $paged_id.'=$matches[2]', $priority);
add_rewrite_rule( $view_slug.$root_rule, 'index.php?' . $view_id.'=$matches[1]', $priority);
// Search All
add_rewrite_rule( $search_slug.$search_paged_rule, 'index.php?' . $paged_id.'=$matches[1]', $priority);
add_rewrite_rule( $search_slug.$search_root_rule, 'index.php?' . $search_id, $priority);
}
/**
* Add permalink structures for new archive-style destinations.
*
* - Users
* - Video Views
* - Search
*
* @since 1.0.0
*/
public static function add_permastructs()
{
// Get unique ID's
$user_id = video_central_get_user_rewrite_id();
$view_id = video_central_get_view_rewrite_id();
$search_id = video_central_get_search_rewrite_id();
// Get root slugs
$user_slug = video_central_get_user_slug();
$view_slug = video_central_get_view_slug();
$search_slug = video_central_get_search_slug();
// User Permastruct
add_permastruct( $user_id, $user_slug.'/%' . $user_id.'%', array(
'with_front' => false,
'ep_mask' => EP_NONE,
'paged' => false,
'feed' => false,
'forcomments' => false,
'walk_dirs' => true,
'endpoints' => false,
) );
// Video View Permastruct
add_permastruct( $view_id, $view_slug.'/%' . $view_id.'%', array(
'with_front' => false,
'ep_mask' => EP_NONE,
'paged' => false,
'feed' => false,
'forcomments' => false,
'walk_dirs' => true,
'endpoints' => false,
) );
// Search Permastruct
add_permastruct( $user_id, $search_slug.'/%' . $search_id.'%', array(
'with_front' => false,
'ep_mask' => EP_NONE,
'paged' => true,
'feed' => false,
'forcomments' => false,
'walk_dirs' => true,
'endpoints' => false,
) );
}
/**
* PSR-0 compliant autoloader to load classes as needed.
*
* @since 1.0.0
*
* @param string $classname The name of the class
*/
public static function autoload( $classname)
{
if ( 'Radium' !== mb_substr( $classname, 0, 6 ) ) {
return;
}
$filename = dirname(__FILE__).DIRECTORY_SEPARATOR.str_replace( '_', DIRECTORY_SEPARATOR, $classname).'.php';
if (file_exists( $filename ) ) {
require $filename;
}
}
/**
* Getter method for retrieving the url.
*
* @since 1.0.0
*/
public static function get_url()
{
return plugins_url( '', __FILE__);
}
/**
* Getter method for retrieving the url.
*
* @since 1.0.0
*/
public static function get_dir()
{
return plugin_dir_path(__FILE__);
}
/**
* Getter method for retrieving the main plugin filepath.
*
* @since 1.0.0
*/
public static function get_file()
{
return self::$file;
}
}
/**
* The main function responsible for returning the one true Video Central Instance
* to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $video_central = video_central(); ?>
*
* @since 1.0.0
*
* @return The one true Video Central Instance
*/
function video_central() {
$instance = Video_Central::instance();
return $instance;
}
/**
* Hook Video_Central early onto the 'plugins_loaded' action.
*
* This gives all other plugins the chance to load before Video Central, to get their
* actions, filters, and overrides setup without Video_Central being in the way.
*/
if (defined( 'VIDEO_CENTRAL_LATE_LOAD' ) ) {
add_action( 'plugins_loaded', 'video_central', (int) VIDEO_CENTRAL_LATE_LOAD);
} else {
video_central();
}
// End class