| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Helper Functions. |
| 5 |
* |
| 6 |
* @link https://plugins360.com |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package Automatic_YouTube_Gallery |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly |
| 13 |
if ( ! defined( 'WPINC' ) ) { |
| 14 |
die; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Build gallery HTML output. |
| 19 |
* |
| 20 |
* @since 1.0.0 |
| 21 |
* @param array $args An array of gallery options. |
| 22 |
* @return mixed |
| 23 |
*/ |
| 24 |
function ayg_build_gallery( $args ) { |
| 25 |
// Vars |
| 26 |
$fields = ayg_get_editor_fields(); |
| 27 |
$defaults = array(); |
| 28 |
|
| 29 |
foreach ( $fields as $key => $value ) { |
| 30 |
foreach ( $value['fields'] as $field ) { |
| 31 |
$defaults[ $field['name'] ] = $field['value']; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
$attributes = shortcode_atts( $defaults, $args ); |
| 36 |
|
| 37 |
$attributes['uid'] = ayg_get_uniqid(); |
| 38 |
|
| 39 |
$attributes['columns'] = min( 12, (int) $attributes['columns'] ); |
| 40 |
if ( empty( $attributes['columns'] ) ) { |
| 41 |
$attributes['columns'] = 3; |
| 42 |
} |
| 43 |
|
| 44 |
$attributes['limit'] = min( 500, (int) $attributes['limit'] ); |
| 45 |
if ( empty( $attributes['limit'] ) ) { |
| 46 |
$attributes['limit'] = 500; |
| 47 |
} |
| 48 |
|
| 49 |
$attributes['per_page'] = min( 50, (int) $attributes['per_page'] ); |
| 50 |
if ( empty( $attributes['per_page'] ) ) { |
| 51 |
$attributes['per_page'] = 50; |
| 52 |
} |
| 53 |
|
| 54 |
$source_type = sanitize_text_field( $attributes['type'] ); |
| 55 |
if ( 'livestream' == $source_type ) { |
| 56 |
$attributes['livestream'] = $attributes['channel']; |
| 57 |
} |
| 58 |
|
| 59 |
// Get Videos |
| 60 |
$api_params = array( |
| 61 |
'type' => $source_type, |
| 62 |
'src' => sanitize_text_field( $attributes[ $source_type ] ), |
| 63 |
'order' => sanitize_text_field( $attributes['order'] ), // applicable only when type=search |
| 64 |
'maxResults' => $attributes['per_page'], |
| 65 |
'cache' => (int) $attributes['cache'] |
| 66 |
); |
| 67 |
|
| 68 |
$api_params = apply_filters( 'ayg_youtube_api_request_params', $api_params, $args ); |
| 69 |
|
| 70 |
$youtube_api = new AYG_YouTube_API(); |
| 71 |
$response = $youtube_api->query( $api_params ); |
| 72 |
|
| 73 |
// Process output |
| 74 |
if ( ! isset( $response->error ) ) { |
| 75 |
// Enqueue dependencies |
| 76 |
wp_enqueue_style( AYG_SLUG . '-public' ); |
| 77 |
wp_enqueue_script( AYG_SLUG . '-public' ); |
| 78 |
|
| 79 |
// Gallery |
| 80 |
$videos = array(); |
| 81 |
|
| 82 |
if ( isset( $response->videos ) ) { |
| 83 |
$videos = $response->videos; |
| 84 |
} |
| 85 |
|
| 86 |
// Pagination |
| 87 |
if ( isset( $response->page_info ) ) { |
| 88 |
$attributes = array_merge( $attributes, $api_params, $response->page_info ); |
| 89 |
} |
| 90 |
|
| 91 |
// Theme |
| 92 |
$theme = 'classic'; |
| 93 |
|
| 94 |
if ( 'video' == $source_type ) { |
| 95 |
$theme = 'single'; |
| 96 |
} elseif ( 'livestream' == $source_type ) { |
| 97 |
$theme = 'livestream'; |
| 98 |
} else { |
| 99 |
if ( 1 == count( $videos ) ) { |
| 100 |
$theme = 'single'; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
// Output |
| 105 |
ob_start(); |
| 106 |
include ayg_get_template( AYG_DIR . "public/templates/theme-{$theme}.php", $attributes['theme'] ); |
| 107 |
return ob_get_clean(); |
| 108 |
} else { |
| 109 |
return '<p class="ayg-error">' . $response->error_message . '</p>'; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Get default plugin settings. |
| 115 |
* |
| 116 |
* @since 1.6.4 |
| 117 |
* @return array $defaults Array of plugin settings. |
| 118 |
*/ |
| 119 |
function ayg_get_default_settings() { |
| 120 |
$defaults = array( |
| 121 |
'ayg_general_settings' => array( |
| 122 |
'api_key' => '', |
| 123 |
'development_mode' => 1 |
| 124 |
), |
| 125 |
'ayg_gallery_settings' => array( |
| 126 |
'theme' => 'classic', |
| 127 |
'columns' => 3, |
| 128 |
'per_page' => 12, |
| 129 |
'thumb_ratio' => 56.25, |
| 130 |
'thumb_title' => 1, |
| 131 |
'thumb_title_length' => 0, |
| 132 |
'thumb_excerpt' => 1, |
| 133 |
'thumb_excerpt_length' => 75, |
| 134 |
'pagination' => 1, |
| 135 |
'pagination_type' => 'more' |
| 136 |
), |
| 137 |
'ayg_player_settings' => array( |
| 138 |
'player_ratio' => 56.25, |
| 139 |
'player_title' => 1, |
| 140 |
'player_description' => 1, |
| 141 |
'autoplay' => 0, |
| 142 |
'autoadvance' => 1, |
| 143 |
'loop' => 0, |
| 144 |
'controls' => 1, |
| 145 |
'modestbranding' => 1, |
| 146 |
'cc_load_policy' => 0, |
| 147 |
'iv_load_policy' => 0, |
| 148 |
'hl' => '', |
| 149 |
'cc_lang_pref' => '' |
| 150 |
), |
| 151 |
'ayg_livestream_settings' => array( |
| 152 |
'fallback_message' => __( 'Sorry, but the channel is not currently streaming live content. Please check back later.', 'automatic-youtube-gallery' ) |
| 153 |
), |
| 154 |
'ayg_privacy_settings' => array( |
| 155 |
'cookie_consent' => 0, |
| 156 |
'consent_message' => __( 'Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.', 'automatic-youtube-gallery' ), |
| 157 |
'button_label' => __( 'Accept', 'automatic-youtube-gallery' ) |
| 158 |
) |
| 159 |
); |
| 160 |
|
| 161 |
return $defaults; |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Get editor fields. |
| 166 |
* |
| 167 |
* @since 1.0.0 |
| 168 |
* @return array Array of fields. |
| 169 |
*/ |
| 170 |
function ayg_get_editor_fields() { |
| 171 |
$fields = array( |
| 172 |
'source' => array( |
| 173 |
'label' => __( 'General', 'automatic-youtube-gallery' ), |
| 174 |
'fields' => array( |
| 175 |
array( |
| 176 |
'name' => 'type', |
| 177 |
'label' => __( 'Source Type', 'automatic-youtube-gallery' ), |
| 178 |
'description' => '', |
| 179 |
'type' => 'select', |
| 180 |
'options' => array( |
| 181 |
'playlist' => __( 'Playlist', 'automatic-youtube-gallery' ), |
| 182 |
'channel' => __( 'Channel', 'automatic-youtube-gallery' ), |
| 183 |
'username' => __( 'Username', 'automatic-youtube-gallery' ), |
| 184 |
'search' => __( 'Search Keywords', 'automatic-youtube-gallery' ), |
| 185 |
'video' => __( 'Single Video', 'automatic-youtube-gallery' ), |
| 186 |
'livestream' => __( 'Livestream', 'automatic-youtube-gallery' ), |
| 187 |
'videos' => __( 'Custom Videos List', 'automatic-youtube-gallery' ) |
| 188 |
), |
| 189 |
'value' => 'playlist', |
| 190 |
'sanitize_callback' => 'sanitize_key' |
| 191 |
), |
| 192 |
array( |
| 193 |
'name' => 'playlist', |
| 194 |
'label' => __( 'YouTube Playlist ID (or) URL', 'automatic-youtube-gallery' ), |
| 195 |
'description' => sprintf( '%s: https://www.youtube.com/playlist?list=XXXXXXXXXX', __( 'Example', 'automatic-youtube-gallery' ) ), |
| 196 |
'type' => 'url', |
| 197 |
'value' => '', |
| 198 |
'sanitize_callback' => 'sanitize_text_field' |
| 199 |
), |
| 200 |
array( |
| 201 |
'name' => 'channel', |
| 202 |
'label' => __( 'YouTube Channel ID (or) a YouTube Video URL from the Channel', 'automatic-youtube-gallery' ), |
| 203 |
'description' => sprintf( '%s: https://www.youtube.com/channel/XXXXXXXXXX', __( 'Example', 'automatic-youtube-gallery' ) ), |
| 204 |
'type' => 'url', |
| 205 |
'value' => '', |
| 206 |
'sanitize_callback' => 'sanitize_text_field' |
| 207 |
), |
| 208 |
array( |
| 209 |
'name' => 'username', |
| 210 |
'label' => __( 'YouTube Account Username', 'automatic-youtube-gallery' ), |
| 211 |
'description' => sprintf( '%s: SanRosh', __( 'Example', 'automatic-youtube-gallery' ) ), |
| 212 |
'type' => 'text', |
| 213 |
'value' => '', |
| 214 |
'sanitize_callback' => 'sanitize_text_field' |
| 215 |
), |
| 216 |
array( |
| 217 |
'name' => 'search', |
| 218 |
'label' => __( 'Search Keywords', 'automatic-youtube-gallery' ), |
| 219 |
'description' => sprintf( '%s: Cartoon (space:AND , -:NOT , |:OR)', __( 'Example', 'automatic-youtube-gallery' ) ), |
| 220 |
'type' => 'text', |
| 221 |
'value' => '', |
| 222 |
'sanitize_callback' => 'sanitize_text_field' |
| 223 |
), |
| 224 |
array( |
| 225 |
'name' => 'video', |
| 226 |
'label' => __( 'YouTube Video ID (or) URL', 'automatic-youtube-gallery' ), |
| 227 |
'description' => sprintf( '%s: https://www.youtube.com/watch?v=XXXXXXXXXX', __( 'Example', 'automatic-youtube-gallery' ) ), |
| 228 |
'type' => 'url', |
| 229 |
'value' => '', |
| 230 |
'sanitize_callback' => 'sanitize_text_field' |
| 231 |
), |
| 232 |
array( |
| 233 |
'name' => 'videos', |
| 234 |
'label' => __( 'YouTube Video IDs (or) URLs', 'automatic-youtube-gallery' ), |
| 235 |
'description' => sprintf( '%s: https://www.youtube.com/watch?v=XXXXXXXXXX', __( 'Example', 'automatic-youtube-gallery' ) ), |
| 236 |
'type' => 'textarea', |
| 237 |
'placeholder' => __( 'Enter one video per line', 'automatic-youtube-gallery' ), |
| 238 |
'value' => '', |
| 239 |
'sanitize_callback' => 'sanitize_text_field' |
| 240 |
), |
| 241 |
array( |
| 242 |
'name' => 'order', |
| 243 |
'label' => __( 'Order Videos by', 'automatic-youtube-gallery' ), |
| 244 |
'description' => '', |
| 245 |
'type' => 'select', |
| 246 |
'options' => array( |
| 247 |
'date' => __( 'Date', 'automatic-youtube-gallery' ), |
| 248 |
'rating' => __( 'Rating', 'automatic-youtube-gallery' ), |
| 249 |
'relevance' => __( 'Relevance', 'automatic-youtube-gallery' ), |
| 250 |
'title' => __( 'Title', 'automatic-youtube-gallery' ), |
| 251 |
'viewCount' => __( 'View Count', 'automatic-youtube-gallery' ) |
| 252 |
), |
| 253 |
'value' => 'relevance', |
| 254 |
'sanitize_callback' => 'sanitize_key' |
| 255 |
), |
| 256 |
array( |
| 257 |
'name' => 'limit', |
| 258 |
'label' => __( 'Number of Videos', 'automatic-youtube-gallery' ), |
| 259 |
'description' => __( 'Specifies the maximum number of videos that will appear in this gallery. Set to 0 for the maximum amount (500).', 'automatic-youtube-gallery' ), |
| 260 |
'type' => 'number', |
| 261 |
'min' => 0, |
| 262 |
'max' => 500, |
| 263 |
'value' => 0, |
| 264 |
'sanitize_callback' => 'intval' |
| 265 |
), |
| 266 |
array( |
| 267 |
'name' => 'cache', |
| 268 |
'label' => __( 'Cache Duration', 'automatic-youtube-gallery' ), |
| 269 |
'description' => __( 'Specifies how frequently we should check your YouTube source for new videos/updates.', 'automatic-youtube-gallery' ), |
| 270 |
'type' => 'select', |
| 271 |
'options' => array( |
| 272 |
'900' => __( '15 minutes', 'automatic-youtube-gallery' ), |
| 273 |
'1800' => __( '30 minutes', 'automatic-youtube-gallery' ), |
| 274 |
'3600' => __( '1 Hour', 'automatic-youtube-gallery' ), |
| 275 |
'86400' => __( '1 Day', 'automatic-youtube-gallery' ), |
| 276 |
'604800' => __( '1 Week', 'automatic-youtube-gallery' ), |
| 277 |
'2419200' => __( ' 1Month', 'automatic-youtube-gallery' ) |
| 278 |
), |
| 279 |
'value' => 86400, |
| 280 |
'sanitize_callback' => 'intval' |
| 281 |
) |
| 282 |
) |
| 283 |
), |
| 284 |
'gallery' => array( |
| 285 |
'label' => __( 'Gallery (optional)', 'automatic-youtube-gallery' ), |
| 286 |
'fields' => ayg_get_gallery_settings_fields() |
| 287 |
), |
| 288 |
'player' => array( |
| 289 |
'label' => __( 'Player (optional)', 'automatic-youtube-gallery' ), |
| 290 |
'fields' => ayg_get_player_settings_fields() |
| 291 |
) |
| 292 |
); |
| 293 |
|
| 294 |
return apply_filters( 'ayg_editor_fields', $fields ); |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* Get gallery settings fields. |
| 299 |
* |
| 300 |
* @since 1.0.0 |
| 301 |
* @return array $fields Array of fields. |
| 302 |
*/ |
| 303 |
function ayg_get_gallery_settings_fields() { |
| 304 |
$gallery_settings = get_option( 'ayg_gallery_settings' ); |
| 305 |
|
| 306 |
$fields = array( |
| 307 |
array( |
| 308 |
'name' => 'theme', |
| 309 |
'label' => __( 'Select Theme (Layout)', 'automatic-youtube-gallery' ), |
| 310 |
'description' => ( ayg_fs()->is_not_paying() ? sprintf( __( '<a href="%s">Upgrade Pro</a> for more themes (Inline, Popup, Slider, Playlist).', 'automatic-youtube-gallery' ), esc_url( ayg_fs()->get_upgrade_url() ) ) : '' ), |
| 311 |
'type' => 'select', |
| 312 |
'options' => array( |
| 313 |
'classic' => __( 'Classic', 'automatic-youtube-gallery' ) |
| 314 |
), |
| 315 |
'value' => $gallery_settings['theme'], |
| 316 |
'sanitize_callback' => 'sanitize_key' |
| 317 |
), |
| 318 |
array( |
| 319 |
'name' => 'columns', |
| 320 |
'label' => __( 'Columns', 'automatic-youtube-gallery' ), |
| 321 |
'description' => __( 'Enter the number of columns you like to have in the gallery. Maximum of 12.', 'automatic-youtube-gallery' ), |
| 322 |
'type' => 'number', |
| 323 |
'min' => 0, |
| 324 |
'max' => 12, |
| 325 |
'value' => $gallery_settings['columns'], |
| 326 |
'sanitize_callback' => 'intval' |
| 327 |
), |
| 328 |
array( |
| 329 |
'name' => 'per_page', |
| 330 |
'label' => __( 'Videos per Page', 'automatic-youtube-gallery' ), |
| 331 |
'description' => __( 'Enter the number of videos to show per page. Maximum of 50.', 'automatic-youtube-gallery' ), |
| 332 |
'type' => 'number', |
| 333 |
'min' => 0, |
| 334 |
'max' => 50, |
| 335 |
'value' => $gallery_settings['per_page'], |
| 336 |
'sanitize_callback' => 'intval' |
| 337 |
), |
| 338 |
array( |
| 339 |
'name' => 'thumb_ratio', |
| 340 |
'label' => __( 'Image Height (Ratio)', 'automatic-youtube-gallery' ), |
| 341 |
'description' => __( 'Select the ratio value used to calculate the image height in the gallery thumbnails.', 'automatic-youtube-gallery' ), |
| 342 |
'type' => 'radio', |
| 343 |
'options' => array( |
| 344 |
'56.25' => '16:9', |
| 345 |
'75' => '4:3' |
| 346 |
), |
| 347 |
'value' => $gallery_settings['thumb_ratio'], |
| 348 |
'sanitize_callback' => 'floatval' |
| 349 |
), |
| 350 |
array( |
| 351 |
'name' => 'thumb_title', |
| 352 |
'label' => __( 'Show Video Title', 'automatic-youtube-gallery' ), |
| 353 |
'description' => __( 'Check this option to show the video title in each gallery item.', 'automatic-youtube-gallery' ), |
| 354 |
'type' => 'checkbox', |
| 355 |
'value' => $gallery_settings['thumb_title'], |
| 356 |
'sanitize_callback' => 'intval' |
| 357 |
), |
| 358 |
array( |
| 359 |
'name' => 'thumb_title_length', |
| 360 |
'label' => __( 'Video Title Length', 'automatic-youtube-gallery' ), |
| 361 |
'description' => __( 'Enter the number of characters you like to show in the title. Set 0 to show the whole title.', 'automatic-youtube-gallery' ), |
| 362 |
'type' => 'number', |
| 363 |
'min' => 0, |
| 364 |
'max' => 500, |
| 365 |
'value' => $gallery_settings['thumb_title_length'], |
| 366 |
'sanitize_callback' => 'intval' |
| 367 |
), |
| 368 |
array( |
| 369 |
'name' => 'thumb_excerpt', |
| 370 |
'label' => __( 'Show Video Excerpt (Short Description)', 'automatic-youtube-gallery' ), |
| 371 |
'description' => __( 'Check this option to show the short description of a video in each gallery item.', 'automatic-youtube-gallery' ), |
| 372 |
'type' => 'checkbox', |
| 373 |
'value' => $gallery_settings['thumb_excerpt'], |
| 374 |
'sanitize_callback' => 'intval' |
| 375 |
), |
| 376 |
array( |
| 377 |
'name' => 'thumb_excerpt_length', |
| 378 |
'label' => __( 'Video Excerpt Length', 'automatic-youtube-gallery' ), |
| 379 |
'description' => __( 'Enter the number of characters you like to have in the video excerpt. Set 0 to show the whole description.', 'automatic-youtube-gallery' ), |
| 380 |
'type' => 'number', |
| 381 |
'min' => 0, |
| 382 |
'max' => 500, |
| 383 |
'value' => $gallery_settings['thumb_excerpt_length'], |
| 384 |
'sanitize_callback' => 'intval' |
| 385 |
), |
| 386 |
array( |
| 387 |
'name' => 'pagination', |
| 388 |
'label' => __( 'Pagination', 'automatic-youtube-gallery' ), |
| 389 |
'description' => __( 'Check this option to show the pagination.', 'automatic-youtube-gallery' ), |
| 390 |
'type' => 'checkbox', |
| 391 |
'value' => $gallery_settings['pagination'], |
| 392 |
'sanitize_callback' => 'intval' |
| 393 |
), |
| 394 |
array( |
| 395 |
'name' => 'pagination_type', |
| 396 |
'label' => __( 'Pagination Type', 'automatic-youtube-gallery' ), |
| 397 |
'type' => 'select', |
| 398 |
'options' => array( |
| 399 |
'more' => __( 'More Button', 'automatic-youtube-gallery' ), |
| 400 |
'pager' => __( 'Pager', 'automatic-youtube-gallery' ) |
| 401 |
|
| 402 |
), |
| 403 |
'value' => $gallery_settings['pagination_type'], |
| 404 |
'sanitize_callback' => 'sanitize_key' |
| 405 |
) |
| 406 |
); |
| 407 |
|
| 408 |
return apply_filters( 'ayg_gallery_settings_fields', $fields ); |
| 409 |
} |
| 410 |
|
| 411 |
/** |
| 412 |
* Get video description to show on top of the player. |
| 413 |
* |
| 414 |
* @since 1.0.0 |
| 415 |
* @param stdClass $video YouTube video object. |
| 416 |
* @param int $words_count Number of words to show by default. |
| 417 |
* @return string Video description. |
| 418 |
*/ |
| 419 |
function ayg_get_player_description( $video, $words_count = 30 ) { |
| 420 |
$description = $video->description; |
| 421 |
|
| 422 |
$words_array = explode( ' ', strip_tags( $description ) ); |
| 423 |
if ( count( $words_array ) > $words_count ) { |
| 424 |
$words_array[ $words_count ] = '<span class="ayg-player-description-dots">...</span></span><span class="ayg-player-description-more">' . $words_array[ $words_count ]; |
| 425 |
|
| 426 |
$description = '<span class="ayg-player-description-less">' . implode( ' ', $words_array ) . '</span>'; |
| 427 |
$description .= '<a href="javascript:void(0);" class="ayg-player-description-toggle-btn">[+] ' . __( 'Show More', 'automatic-youtube-gallery' ) . '</a>'; |
| 428 |
} |
| 429 |
|
| 430 |
$description = nl2br( $description ); |
| 431 |
$description = make_clickable( $description ); |
| 432 |
|
| 433 |
return apply_filters( 'ayg_player_description', $description, $video, $words_count ); |
| 434 |
} |
| 435 |
|
| 436 |
/** |
| 437 |
* Get player settings fields. |
| 438 |
* |
| 439 |
* @since 1.0.0 |
| 440 |
* @return array $fields Array of fields. |
| 441 |
*/ |
| 442 |
function ayg_get_player_settings_fields() { |
| 443 |
$player_settings = get_option( 'ayg_player_settings' ); |
| 444 |
|
| 445 |
$fields = array( |
| 446 |
array( |
| 447 |
'name' => 'player_ratio', |
| 448 |
'label' => __( 'Player Height (Ratio)', 'automatic-youtube-gallery' ), |
| 449 |
'description' => __( 'Select the ratio value used to calculate the player height.', 'automatic-youtube-gallery' ), |
| 450 |
'type' => 'radio', |
| 451 |
'options' => array( |
| 452 |
'56.25' => '16:9', |
| 453 |
'75' => '4:3' |
| 454 |
), |
| 455 |
'value' => $player_settings['player_ratio'], |
| 456 |
'sanitize_callback' => 'floatval' |
| 457 |
), |
| 458 |
array( |
| 459 |
'name' => 'player_title', |
| 460 |
'label' => __( 'Show Video Title', 'automatic-youtube-gallery' ), |
| 461 |
'description' => __( 'Check this option to show the current playing video title on the bottom of the player.', 'automatic-youtube-gallery' ), |
| 462 |
'type' => 'checkbox', |
| 463 |
'value' => $player_settings['player_title'], |
| 464 |
'sanitize_callback' => 'intval' |
| 465 |
), |
| 466 |
array( |
| 467 |
'name' => 'player_description', |
| 468 |
'label' => __( 'Show Video Description', 'automatic-youtube-gallery' ), |
| 469 |
'description' => __( 'Check this option to show the current playing video description on the bottom of the player.', 'automatic-youtube-gallery' ), |
| 470 |
'type' => 'checkbox', |
| 471 |
'value' => $player_settings['player_description'], |
| 472 |
'sanitize_callback' => 'intval' |
| 473 |
), |
| 474 |
array( |
| 475 |
'name' => 'autoplay', |
| 476 |
'label' => __( 'Autoplay', 'automatic-youtube-gallery' ), |
| 477 |
'description' => __( 'Specifies whether the initial video will automatically start to play when the player loads.', 'automatic-youtube-gallery' ), |
| 478 |
'type' => 'checkbox', |
| 479 |
'value' => $player_settings['autoplay'], |
| 480 |
'sanitize_callback' => 'intval' |
| 481 |
), |
| 482 |
array( |
| 483 |
'name' => 'autoadvance', |
| 484 |
'label' => __( 'Autoplay Next Video', 'automatic-youtube-gallery' ), |
| 485 |
'description' => __( 'Specifies whether to play the next video in the list automatically after previous one end.', 'automatic-youtube-gallery' ), |
| 486 |
'type' => 'checkbox', |
| 487 |
'value' => $player_settings['autoadvance'], |
| 488 |
'sanitize_callback' => 'intval' |
| 489 |
), |
| 490 |
array( |
| 491 |
'name' => 'loop', |
| 492 |
'label' => __( 'Loop', 'automatic-youtube-gallery' ), |
| 493 |
'description' => __( 'In the case of a single video player, plays the initial video again and again. In the case of a gallery, plays the entire list in the gallery and then starts again at the first video.', 'automatic-youtube-gallery' ), |
| 494 |
'type' => 'checkbox', |
| 495 |
'value' => $player_settings['loop'], |
| 496 |
'sanitize_callback' => 'intval' |
| 497 |
), |
| 498 |
array( |
| 499 |
'name' => 'controls', |
| 500 |
'label' => __( 'Show Player Controls', 'automatic-youtube-gallery' ), |
| 501 |
'description' => __( 'Uncheck this option to hide the video player controls.', 'automatic-youtube-gallery' ), |
| 502 |
'type' => 'checkbox', |
| 503 |
'value' => $player_settings['controls'], |
| 504 |
'sanitize_callback' => 'intval' |
| 505 |
), |
| 506 |
array( |
| 507 |
'name' => 'modestbranding', |
| 508 |
'label' => __( 'Hide YouTube Logo', 'automatic-youtube-gallery' ), |
| 509 |
'description' => __( "Lets you prevent the YouTube logo from displaying in the control bar. Note that a small YouTube text label will still display in the upper-right corner of a paused video when the user's mouse pointer hovers over the player.", 'automatic-youtube-gallery' ), |
| 510 |
'type' => 'checkbox', |
| 511 |
'value' => $player_settings['modestbranding'], |
| 512 |
'sanitize_callback' => 'intval' |
| 513 |
), |
| 514 |
array( |
| 515 |
'name' => 'cc_load_policy', |
| 516 |
'label' => __( 'Force Closed Captions', 'automatic-youtube-gallery' ), |
| 517 |
'description' => __( 'Show captions by default, even if the user has turned captions off. The default behavior is based on user preference.', 'automatic-youtube-gallery' ), |
| 518 |
'type' => 'checkbox', |
| 519 |
'value' => $player_settings['cc_load_policy'], |
| 520 |
'sanitize_callback' => 'intval' |
| 521 |
), |
| 522 |
array( |
| 523 |
'name' => 'iv_load_policy', |
| 524 |
'label' => __( 'Show Annotations', 'automatic-youtube-gallery' ), |
| 525 |
'description' => __( 'Choose whether to show annotations or not.', 'automatic-youtube-gallery' ), |
| 526 |
'type' => 'checkbox', |
| 527 |
'value' => $player_settings['iv_load_policy'], |
| 528 |
'sanitize_callback' => 'intval' |
| 529 |
), |
| 530 |
array( |
| 531 |
'name' => 'hl', |
| 532 |
'label' => __( 'Player Language', 'automatic-youtube-gallery' ), |
| 533 |
'description' => sprintf( |
| 534 |
__( 'Specifies the player\'s interface language. Set the field\'s value to an <a href="%s" target="_blank">ISO 639-1 two-letter language code.</a>', 'automatic-youtube-gallery' ), |
| 535 |
'http://www.loc.gov/standards/iso639-2/php/code_list.php' |
| 536 |
), |
| 537 |
'type' => 'text', |
| 538 |
'value' => $player_settings['hl'], |
| 539 |
'sanitize_callback' => 'sanitize_text_field' |
| 540 |
), |
| 541 |
array( |
| 542 |
'name' => 'cc_lang_pref', |
| 543 |
'label' => __( 'Default Captions Language', 'automatic-youtube-gallery' ), |
| 544 |
'description' => sprintf( |
| 545 |
__( 'Specifies the default language that the player will use to display captions. Set the field\'s value to an <a href="%s" target="_blank">ISO 639-1 two-letter language code.</a>', 'automatic-youtube-gallery' ), |
| 546 |
'http://www.loc.gov/standards/iso639-2/php/code_list.php' |
| 547 |
), |
| 548 |
'type' => 'text', |
| 549 |
'value' => $player_settings['cc_lang_pref'], |
| 550 |
'sanitize_callback' => 'sanitize_text_field' |
| 551 |
) |
| 552 |
); |
| 553 |
|
| 554 |
return $fields; |
| 555 |
} |
| 556 |
|
| 557 |
/** |
| 558 |
* Get filtered php template file path. |
| 559 |
* |
| 560 |
* @since 1.0.0 |
| 561 |
* @param array $template PHP file path. |
| 562 |
* @param string $theme Automatic YouTube Gallery Theme. |
| 563 |
* @return string Filtered file path. |
| 564 |
*/ |
| 565 |
function ayg_get_template( $template, $theme = '' ) { |
| 566 |
return apply_filters( 'ayg_load_template', $template, $theme ); |
| 567 |
} |
| 568 |
|
| 569 |
/** |
| 570 |
* Get unique ID. |
| 571 |
* |
| 572 |
* @since 1.0.0 |
| 573 |
* @return string Unique ID. |
| 574 |
*/ |
| 575 |
function ayg_get_uniqid() { |
| 576 |
global $ayg_uniqid; |
| 577 |
|
| 578 |
if ( ! $ayg_uniqid ) { |
| 579 |
$ayg_uniqid = 0; |
| 580 |
} |
| 581 |
|
| 582 |
return uniqid() . ++$ayg_uniqid; |
| 583 |
} |
| 584 |
|
| 585 |
/** |
| 586 |
* Sanitize the integer inputs, accepts empty values. |
| 587 |
* |
| 588 |
* @since 1.0.0 |
| 589 |
* @param string|int $value Input value. |
| 590 |
* @return string|int Sanitized value. |
| 591 |
*/ |
| 592 |
function ayg_sanitize_int( $value ) { |
| 593 |
$value = intval( $value ); |
| 594 |
return ( 0 == $value ) ? '' : $value; |
| 595 |
} |
| 596 |
|
| 597 |
/** |
| 598 |
* Trims text to a certain number of characters. |
| 599 |
* |
| 600 |
* @since 2.0.0 |
| 601 |
* @param string $text Text to trim. |
| 602 |
* @param int $num_characters Number of characters. |
| 603 |
* @return string Trimmed text. |
| 604 |
*/ |
| 605 |
function ayg_trim_words( $text, $num_characters ) { |
| 606 |
$num_characters++; |
| 607 |
|
| 608 |
$original_text = $text; |
| 609 |
$text = ( $num_characters > 1 ) ? wp_strip_all_tags( $original_text, true ) : nl2br( $original_text ); |
| 610 |
|
| 611 |
if ( $num_characters > 1 && mb_strlen( $text ) > $num_characters ) { |
| 612 |
$subex = mb_substr( $text, 0, $num_characters - 5 ); |
| 613 |
$exwords = explode( ' ', $subex ); |
| 614 |
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) ); |
| 615 |
|
| 616 |
if ( $excut < 0 ) { |
| 617 |
$text = mb_substr( $subex, 0, $excut ); |
| 618 |
} else { |
| 619 |
$text = $subex; |
| 620 |
} |
| 621 |
|
| 622 |
$text .= '...'; |
| 623 |
} |
| 624 |
|
| 625 |
return apply_filters( 'ayg_trim_words', $text, $original_text, $num_characters ); |
| 626 |
} |
| 627 |
|
| 628 |
/** |
| 629 |
* Gallery HTML output. |
| 630 |
* |
| 631 |
* @since 1.0.0 |
| 632 |
* @param array $video YouTube video object. |
| 633 |
* @param array $attributes Array of user attributes. |
| 634 |
*/ |
| 635 |
function the_ayg_gallery_thumbnail( $video, $attributes ) { |
| 636 |
include ayg_get_template( AYG_DIR . 'public/templates/thumbnail.php' ); |
| 637 |
} |
| 638 |
|
| 639 |
/** |
| 640 |
* Pagination HTML output. |
| 641 |
* |
| 642 |
* @since 1.0.0 |
| 643 |
* @param array $attributes Array of user attributes. |
| 644 |
*/ |
| 645 |
function the_ayg_pagination( $attributes ) { |
| 646 |
if ( ! empty( $attributes['pagination'] ) ) { |
| 647 |
include ayg_get_template( AYG_DIR . 'public/templates/pagination.php' ); |
| 648 |
} |
| 649 |
} |