Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
376 lines (326 loc) · 14.4 KB
/
Copy pathfunctions.php
File metadata and controls
376 lines (326 loc) · 14.4 KB
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
<?php
/**
* Theme functions and definitions
*
* @package jw_mymo
*/
if ( ! function_exists( 'jw_mymo_setup' ) ) {
/**
* Setup theme.
*/
function jw_mymo_setup() {
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Let WordPress manage the document title.
add_theme_support( 'title-tag' );
// Enable support for Post Thumbnails on posts and pages.
add_theme_support( 'post-thumbnails' );
// Switch default core markup for search form, comment form, and comments to output valid HTML5.
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
)
);
// Load theme textdomain.
load_theme_textdomain( 'jw_mymo', get_template_directory() . '/languages' );
// Add support for core custom logo.
add_theme_support(
'custom-logo',
array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
)
);
}
}
add_action( 'after_setup_theme', 'jw_mymo_setup' );
/**
* Enqueue scripts and styles.
*/
function jw_mymo_scripts() {
wp_enqueue_style( 'jw-mymo-style', get_template_directory_uri() . '/assets/css/style.css', array(), filemtime( get_template_directory() . '/assets/css/style.css' ) );
wp_enqueue_script( 'jw-mymo-auth', get_template_directory_uri() . '/assets/js/auth.js', array(), filemtime( get_template_directory() . '/assets/js/auth.js' ), true );
wp_enqueue_script( 'jw-mymo-search', get_template_directory_uri() . '/assets/js/search.js', array(), filemtime( get_template_directory() . '/assets/js/search.js' ), true );
wp_enqueue_script( 'jw-mymo-popular', get_template_directory_uri() . '/assets/js/popular.js', array(), filemtime( get_template_directory() . '/assets/js/popular.js' ), true );
wp_localize_script(
'jw-mymo-search',
'jwMymoSearch',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
)
);
wp_localize_script(
'jw-mymo-popular',
'jwMymoPopular',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
)
);
wp_localize_script(
'jw-mymo-auth',
'jwMymoAuth',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
)
);
wp_enqueue_script( 'jw-mymo-bookmark', get_template_directory_uri() . '/assets/js/bookmark.js', array(), filemtime( get_template_directory() . '/assets/js/bookmark.js' ), true );
wp_localize_script(
'jw-mymo-bookmark',
'jwMymoBookmark',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'ajax-bookmark-nonce' ),
'isLoggedIn' => is_user_logged_in() ? true : false,
'i18n' => array(
'addToList' => esc_html__( 'Add to List', 'jw_mymo' ),
'addedToList' => esc_html__( 'Added to List', 'jw_mymo' ),
),
)
);
if ( is_singular( 'movie' ) ) {
wp_enqueue_script( 'jw-mymo-rating', get_template_directory_uri() . '/assets/js/rating.js', array( 'jquery' ), filemtime( get_template_directory() . '/assets/js/rating.js' ), true );
wp_localize_script(
'jw-mymo-rating',
'jwMymoRating',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'ajax-rating-nonce' ),
)
);
}
// Enqueue movie player script on single movie pages.
if ( is_singular( 'movie' ) ) {
wp_enqueue_script( 'jwplayer', get_template_directory_uri() . '/src/js/jwplayer-8.9.3.js', array(), filemtime( get_template_directory() . '/src/js/jwplayer-8.9.3.js' ), true );
wp_enqueue_script( 'jw-mymo-movie-player', get_template_directory_uri() . '/assets/js/movie-player.js', array( 'jquery', 'jwplayer' ), filemtime( get_template_directory() . '/assets/js/movie-player.js' ), true );
wp_localize_script(
'jw-mymo-movie-player',
'jwMymoPlayer',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'ajax-player-nonce' ),
'movieId' => get_the_ID(),
)
);
wp_localize_script(
'jw-mymo-movie-player',
'mymo_cfg',
array(
'toggle_light' => esc_html__( 'Toggle Light', 'jw_mymo' ),
'resize_player' => esc_html__( 'Resize Player', 'jw_mymo' ),
'error_code_224003' => esc_html__( '(Error Code: 224003)', 'jw_mymo' ),
'error_loading' => esc_html__( 'Error loading player: ', 'jw_mymo' ),
'error_server' => esc_html__( 'An error occurred while communicating with the server.', 'jw_mymo' ),
'error_general' => esc_html__( 'An error occurred. Please try again.', 'jw_mymo' ),
)
);
}
// Owl Carousel
wp_enqueue_style( 'owl-carousel-style', 'https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css', array(), '2.3.4' );
wp_enqueue_style( 'owl-carousel-theme', 'https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.min.css', array(), '2.3.4' );
wp_enqueue_script( 'owl-carousel-script', 'https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js', array( 'jquery' ), '2.3.4', true );
wp_enqueue_script( 'jw-mymo-slider', get_template_directory_uri() . '/assets/js/slider.js', array( 'jquery', 'owl-carousel-script' ), filemtime( get_template_directory() . '/assets/js/slider.js' ), true );
wp_enqueue_script( 'jw-mymo-mobile-menu', get_template_directory_uri() . '/assets/js/mobile-menu.js', array(), filemtime( get_template_directory() . '/assets/js/mobile-menu.js' ), true );
}
add_action( 'wp_enqueue_scripts', 'jw_mymo_scripts' );
/**
* Register Navigation Menus
*/
function jw_mymo_register_menus() {
register_nav_menus(
array(
'main-menu' => esc_html__( 'Primary Menu', 'jw_mymo' ),
)
);
}
add_action( 'init', 'jw_mymo_register_menus' );
/**
* Custom Walker for Tailwind CSS Menu
*/
class MyMo_Walker_Nav_Menu extends Walker_Nav_Menu {
/**
* Start el.
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $id Current item ID.
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
if ( in_array( 'menu-item-has-children', $classes, true ) ) {
$classes[] = 'relative group flex items-center';
}
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= '<li' . $id . $class_names . '>';
$atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
if ( 0 === $depth ) {
$atts['class'] = 'hover:text-brand-accent transition-colors flex items-center';
} else {
$atts['class'] = 'block px-4 py-2 text-sm text-gray-200 hover:bg-brand-dark hover:text-brand-accent whitespace-nowrap rounded-md';
}
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
$title = apply_filters( 'the_title', $item->title, $item->ID );
$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
$item_output = $args->before;
$item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . $title . $args->link_after;
if ( in_array( 'menu-item-has-children', $classes, true ) && 0 === $depth ) {
$item_output .= '<svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>';
}
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
/**
* Start lvl.
*
* @param string $output Used to append additional content (passed by reference).
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<div class=\"absolute z-10 left-0 pt-2 w-max hidden group-hover:block top-full\">\n";
$output .= "$indent<div class=\"rounded-md shadow-lg bg-brand-gray ring-1 ring-black ring-opacity-5\">\n";
$output .= "$indent<ul class=\"p-2 grid grid-cols-3 gap-2\" role=\"menu\" aria-orientation=\"vertical\">\n";
}
/**
* End lvl.
*
* @param string $output Used to append additional content (passed by reference).
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function end_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "$indent</ul>\n";
$output .= "$indent</div>\n";
$output .= "$indent</div>\n";
}
}
require_once get_template_directory() . '/inc/widgets.php';
require_once get_template_directory() . '/inc/widgets/popular-movies.php';
require_once get_template_directory() . '/inc/widgets/hero.php';
require_once get_template_directory() . '/inc/widgets/movies-list.php';
/**
* Load AJAX Auth
*/
require_once get_template_directory() . '/inc/ajax-auth.php';
require_once get_template_directory() . '/inc/ajax-search.php';
require_once get_template_directory() . '/inc/ajax-player.php';
require_once get_template_directory() . '/inc/ajax-popular.php';
require_once get_template_directory() . '/inc/ajax-rating.php';
require_once get_template_directory() . '/inc/ajax-report.php';
require_once get_template_directory() . '/inc/ajax-bookmark.php';
require_once get_template_directory() . '/inc/rewrite.php';
require_once get_template_directory() . '/inc/tgm-config.php';
/**
* Get servers for a movie.
*
* @param int $movie_id Movie ID.
* @return array
*/
function jw_mymo_get_movie_servers( $movie_id ) {
global $wpdb;
$table_servers = $wpdb->prefix . 'jw_video_servers';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$servers = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_servers} WHERE movie_id = %d ORDER BY id ASC", $movie_id ) );
return $servers ? $servers : array();
}
/**
* Get files for a server.
*
* @param int $server_id Server ID.
* @return array
*/
function jw_mymo_get_server_files( $server_id ) {
global $wpdb;
$table_files = $wpdb->prefix . 'jw_video_files';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$files = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table_files} WHERE server_id = %d ORDER BY display_order ASC, id ASC", $server_id ) );
return $files ? $files : array();
}
class MyMo_Walker_Nav_Menu_Mobile extends Walker_Nav_Menu {
/**
* Start el.
*
* @param string $output Used to append additional content (passed by reference).
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $id Current item ID.
*/
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
if ( in_array( 'menu-item-has-children', $classes, true ) ) {
$classes[] = 'relative';
}
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= '<li' . $id . $class_names . '>';
$atts = array();
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
$atts['class'] = 'block py-2 text-base text-gray-300 hover:text-brand-accent transition-colors flex justify-between items-center';
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
$attributes = '';
foreach ( $atts as $attr => $value ) {
if ( ! empty( $value ) ) {
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}
$title = apply_filters( 'the_title', $item->title, $item->ID );
$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );
$item_output = $args->before;
$item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . $title . $args->link_after;
if ( in_array( 'menu-item-has-children', $classes, true ) ) {
$item_output .= '<button class="mobile-submenu-toggle focus:outline-none"><svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg></button>';
}
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
/**
* Start lvl.
*
* @param string $output Used to append additional content (passed by reference).
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul class=\"hidden pl-4 py-2 space-y-2 border-l border-gray-700 ml-2\">\n";
}
}