2014-09-30 13:32:53 +03:00
< ? php
2014-10-06 04:38:44 +03:00
2023-09-08 13:17:11 +03:00
# Add support for thumbnais
2014-10-06 04:38:44 +03:00
add_theme_support ( 'post-thumbnails' );
2019-06-18 15:33:32 +03:00
add_theme_support ( 'automatic-feed-links' );
2014-10-06 04:38:44 +03:00
2020-10-25 18:04:00 +02:00
add_filter ( 'the_excerpt' , 'shortcode_unautop' );
add_filter ( 'the_excerpt' , 'do_shortcode' );
2014-10-06 04:38:44 +03:00
2023-09-08 13:31:19 +03:00
function get_blog_slug () {
2023-10-16 20:49:00 +03:00
if ( ! is_multisite ()) {
// local development, non-multisite
return date ( 'Y' );
}
2023-09-08 13:31:19 +03:00
$blog_details = get_blog_details ();
return trim ( $blog_details -> path , '/' );
}
2020-10-31 10:34:37 +02:00
// OpenGraph image for FB/Twitter
function og_image ( $tags ) {
2023-09-08 13:31:19 +03:00
$blog_slug = get_blog_slug ();
2023-09-08 13:20:44 +03:00
2023-09-08 13:35:14 +03:00
$imagePath = __DIR__ . '/img/fb_preview_' . $blog_slug . '.jpg' ;
2020-10-31 10:34:37 +02:00
2023-09-08 13:17:11 +03:00
if ( file_exists ( $imagePath )) {
$imageUrl = esc_url ( 'https://www.openfest.org/wp-content/themes/initfest/img/' . basename ( $imagePath ));
list ( $width , $height ) = getimagesize ( $imagePath );
2020-10-31 10:34:37 +02:00
2023-09-08 13:17:11 +03:00
$tags [ 'og:image' ] = $imageUrl ;
$tags [ 'og:image:width' ] = $width ;
$tags [ 'og:image:height' ] = $height ;
$tags [ 'twitter:image' ] = $imageUrl ;
}
2020-10-31 10:34:37 +02:00
return $tags ;
}
add_filter ( 'jetpack_open_graph_tags' , 'og_image' );
2014-09-30 13:32:53 +03:00
register_nav_menus (
2014-10-04 17:31:15 +03:00
array ( 'main-menu' => __ ( 'Main Menu' , 'initfest' ),
2020-11-07 19:25:54 +02:00
'subnav-menu' => __ ( 'Sub Navigation' , 'initfest' ),
'stream-menu' => __ ( 'Stream Menu' , 'initfest' ),
2014-10-04 17:31:15 +03:00
'footer-openfest' => __ ( 'OpenFest' , 'initfest' ),
'footer-openfest' => __ ( 'OpenFest' , 'initfest' ),
'footer-schedule' => __ ( 'Schedule' , 'initfest' ),
'footer-others' => __ ( 'Others' , 'initfest' ),
'footer-followus' => __ ( 'Follow us in:' , 'initfest' ) )
2014-09-30 16:58:05 +03:00
);
2014-10-06 05:11:57 +03:00
# Register all shortcodes
function register_shortcodes (){
add_shortcode ( 'sh-latest-posts' , 'sh_latest_posts' );
add_shortcode ( 'sponsors' , 'sponsors_shortcode' );
2014-10-14 18:24:01 +03:00
add_shortcode ( 'partners' , 'partners_shortcode' );
2014-10-06 05:11:57 +03:00
add_shortcode ( 'transport' , 'transport_shortcode' );
2024-10-30 23:53:59 +02:00
add_shortcode ( 'stream-player' , 'stream_player_shortcode' );
2014-10-06 05:11:57 +03:00
}
add_action ( 'init' , 'register_shortcodes' );
2014-09-30 16:58:05 +03:00
function sh_latest_posts ( $atts ){
2018-05-23 23:01:48 +03:00
if ( of_get_lang () == 'bg' )
$ncat = " news-bg " ;
else
$ncat = " news " ;
$atts = array (
'cat' => $ncat ,
2014-10-04 17:31:15 +03:00
'label' => __ ( 'News' , 'initfest' )
2018-05-23 23:01:48 +03:00
);
2023-09-08 13:17:11 +03:00
2014-10-06 04:38:44 +03:00
$result = '<section class="content"><h3>' . $atts [ 'label' ] . ' | <small><a href="' . esc_url ( get_term_link ( $atts [ 'cat' ], 'category' )) . '">' . __ ( 'see all' , 'initfest' ) . '</a></small></h3><div class="grid">' ;
2023-09-08 13:17:11 +03:00
2014-10-18 16:57:10 +03:00
$news_args = array ( 'category_name' => 'news,news-bg' , 'numberposts' => 6 , 'lang' => of_get_lang () );
2023-09-08 13:17:11 +03:00
$news = new WP_Query ( $news_args );
2014-10-06 04:38:44 +03:00
2014-10-06 05:11:57 +03:00
ob_start ();
2014-10-06 04:38:44 +03:00
if ( $news -> have_posts () ) :
2014-10-18 16:57:10 +03:00
$i = 0 ;
while ( $news -> have_posts () && $i ++< 6 ) : $news -> the_post ();
2014-10-16 23:18:16 +03:00
?>
2014-10-17 09:39:11 +03:00
< div class = " col3 " >
2014-10-16 23:18:16 +03:00
< h4 >< a href = " <?php the_permalink(); ?> " >< ? php the_title (); ?> </a></h4>
< ? php the_excerpt (); ?>
< a class = " button " href = " <?php the_permalink(); ?> " >< ? php pll_e ( 'виж цялата новина' ); ?> </a>
</ div >
2023-09-08 13:17:11 +03:00
< ? php
2021-07-21 19:15:51 +03:00
# if ($i==3)
2014-10-18 16:57:10 +03:00
echo '</div></section><section class="content"><div class="grid">' ;
2014-10-16 23:18:16 +03:00
endwhile ;
2014-10-06 04:38:44 +03:00
endif ;
2014-10-04 17:31:15 +03:00
$result .= ob_get_contents ();
2014-10-06 04:38:44 +03:00
$result .= '</div></section>' ;
2014-10-04 17:31:15 +03:00
ob_end_clean ();
2023-09-08 13:17:11 +03:00
2014-10-04 17:31:15 +03:00
return $result ;
2023-09-08 13:17:11 +03:00
2014-10-04 16:38:17 +03:00
}
2014-10-06 05:11:57 +03:00
# Create shortcode for sponsors
function sponsors_shortcode () {
2014-10-07 16:17:21 +03:00
$result = '<h3>' . pll__ ( 'Спонсори' ) . '</h3>' ;
2014-10-06 05:11:57 +03:00
2023-09-08 13:17:11 +03:00
2014-10-14 19:26:14 +03:00
$sponsors_args = array ( 'post_type' => 'sponsors' , 'orderby' => 'rand' , 'nopaging' => 'true' );
2023-09-08 13:17:11 +03:00
$sponsors = new WP_Query ( $sponsors_args );
2014-10-06 05:11:57 +03:00
ob_start ();
2014-10-14 18:24:01 +03:00
if ( $sponsors -> have_posts () ) :
while ( $sponsors -> have_posts () ) : $sponsors -> the_post ();
2014-10-14 16:18:50 +03:00
$custom = get_post_custom ();
2014-10-14 18:24:01 +03:00
if ( empty ( $custom [ 'partner' ])) {
2014-10-16 10:14:34 +03:00
if ( ! empty ( $custom [ 'url' ])) {
2014-10-14 16:18:50 +03:00
echo '<a href="' . $custom [ 'url' ][ 0 ] . '" target=_blank alt="' . get_the_title () . '">' ;
}
2014-10-14 18:24:01 +03:00
if ( has_post_thumbnail () ) {
the_post_thumbnail ();
} else {
get_the_title ();
}
2014-10-14 16:18:50 +03:00
if ( ! empty ( $custom [ 'url' ])) {
echo '</a>' ;
}
2014-10-14 18:24:01 +03:00
}
endwhile ;
endif ;
2014-10-14 16:18:50 +03:00
2014-10-14 18:24:01 +03:00
$result .= ob_get_contents ();
ob_end_clean ();
return $result ;
}
# Create shortcode for partners
function partners_shortcode () {
$result = '<h3>' . pll__ ( 'Партньори' ) . '</h3>' ;
2023-09-08 13:17:11 +03:00
2014-10-14 19:26:14 +03:00
$sponsors_args = array ( 'post_type' => 'sponsors' , 'orderby' => 'rand' , 'nopaging' => 'true' );
2023-09-08 13:17:11 +03:00
$sponsors = new WP_Query ( $sponsors_args );
2014-10-14 18:24:01 +03:00
ob_start ();
if ( $sponsors -> have_posts () ) :
while ( $sponsors -> have_posts () ) : $sponsors -> the_post ();
$custom = get_post_custom ();
if ( ! empty ( $custom [ 'partner' ])) {
if ( ! empty ( $custom [ 'url' ])) {
echo '<a href="' . $custom [ 'url' ][ 0 ] . '" target=_blank alt="' . get_the_title () . '">' ;
}
if ( has_post_thumbnail () ) {
the_post_thumbnail ();
} else {
get_the_title ();
}
if ( ! empty ( $custom [ 'url' ])) {
echo '</a>' ;
}
}
endwhile ;
endif ;
2014-10-06 05:11:57 +03:00
$result .= ob_get_contents ();
ob_end_clean ();
return $result ;
}
2023-09-08 13:17:11 +03:00
# Create shortcode for transport methods
2014-10-06 05:11:57 +03:00
function transport_shortcode () {
2015-09-30 21:11:27 +03:00
$result = '<section class="content"><h3>' . pll__ ( 'Място' ) . ': ' . pll__ ( 'VENUE_LOCATION' ) . '</h3>' ;
2014-10-06 05:11:57 +03:00
$transport_args = array ( 'post_type' => 'transportation' );
2023-09-08 13:17:11 +03:00
$transport = new WP_Query ( $transport_args );
2014-10-06 05:11:57 +03:00
ob_start ();
if ( $transport -> have_posts () ) :
while ( $transport -> have_posts () ) : $transport -> the_post ();
?>
2014-10-07 14:52:34 +03:00
< h4 >< ? php the_title (); ?> </h4>
< p >< ? php the_content (); ?> </p>
2023-09-08 13:17:11 +03:00
< ? php
2014-10-06 05:11:57 +03:00
endwhile ;
endif ;
?>
</ section >
< ? php
2023-09-08 13:17:11 +03:00
//echo do_shortcode( '[ready_google_map id="2" map_language="en" align="center"]' );
2014-10-06 05:11:57 +03:00
$result .= ob_get_contents ();
ob_end_clean ();
return $result ;
}
2024-10-30 23:53:59 +02:00
function stream_player_shortcode ( $params = []) {
wp_enqueue_style ( 'video.js' , 'https://unpkg.com/video.js/dist/video-js.css' );
wp_enqueue_script ( 'video.js' , 'https://unpkg.com/video.js/dist/video.min.js' );
2024-10-30 23:59:09 +02:00
$params = array_merge ([
2024-10-30 23:53:59 +02:00
'host' => 'stream.openfest.org' ,
'track' => 'hall-a' ,
2024-10-30 23:59:09 +02:00
], $params );
2024-10-30 23:53:59 +02:00
$urlPrefix = 'https://' . $params [ 'host' ] . '/' ;
ob_start ();
?>
< video class = " video-js vjs-fill " controls data - setup = " { } " >
< source type = " application/x-mpegURL " src = " <?php echo $urlPrefix , 'hls/', $params['track'] ; ?>.m3u8 " ></ source >
< source type = " application/dash+xml " src = " <?php echo $urlPrefix , 'dash/', $params['track'] ; ?>.mpd " ></ source >
</ video >
< ? php
return ob_get_clean ();
}
2014-10-04 16:38:17 +03:00
# Create a custom post type for Sponsors
function create_sponsors_posttype () {
2014-10-04 17:31:15 +03:00
$labels = array (
'name' => __ ( 'Sponsors' ),
'singular_name' => __ ( 'Sponsor' ),
2014-10-05 03:32:43 +03:00
'menu_name' => __ ( 'Sponsors' ),
2014-10-04 17:31:15 +03:00
'all_items' => __ ( 'All Sponsors' ),
'view_item' => __ ( 'View Sponsor' ),
'add_new_item' => __ ( 'Add New Sponsor' ),
'add_new' => __ ( 'Add New' ),
'edit_item' => __ ( 'Edit Sponsor' ),
'update_item' => __ ( 'Update Sponsor' ),
'search_item' => __ ( 'Search Sponsor' ),
'not_found' => __ ( 'Not Found' ),
'not_found_in_trash' => __ ( 'Not Found In Trash' ),
);
2014-10-04 16:38:17 +03:00
2014-10-04 17:31:15 +03:00
$args = array (
'label' => __ ( 'sponsors' ),
'description' => __ ( 'Sponsors of OpenFest' ),
'labels' => $labels ,
'supports' => array ( 'title' , 'excerpt' , 'thumbnail' , 'custom-fields' , ),
'hierarchical' => false ,
'public' => true ,
'show_ui' => true ,
'show_in_menu' => true ,
'show_in_nav_menus' => true ,
'show_in_admin_bar' => true ,
'menu_position' => 5 ,
'can_export' => true ,
'has_archive' => true ,
'exclude_from_search' => false ,
'publicly_queryable' => true ,
'capability_type' => 'post' ,
);
2014-10-04 16:38:17 +03:00
2014-10-04 17:31:15 +03:00
register_post_type ( 'sponsors' , $args );
2014-10-04 16:38:17 +03:00
}
2014-10-10 17:25:34 +03:00
add_action ( 'init' , 'create_sponsors_posttype' );
2014-10-04 16:38:17 +03:00
2014-10-04 23:54:46 +03:00
2023-09-08 13:17:11 +03:00
# Create a custom post type for Speakers
2014-10-05 03:32:43 +03:00
function create_speakers_posttype () {
$labels = array (
'name' => __ ( 'Speakers' ),
'singular_name' => __ ( 'Speaker' ),
'menu_name' => __ ( 'Speakers' ),
'all_items' => __ ( 'All Speakers' ),
'view_item' => __ ( 'View Speaker' ),
'add_new_item' => __ ( 'Add New Speaker' ),
'add_new' => __ ( 'Add New' ),
'edit_item' => __ ( 'Edit Speaker' ),
'update_item' => __ ( 'Update Speaker' ),
'search_item' => __ ( 'Search Speaker' ),
'not_found' => __ ( 'Not Found' ),
'not_found_in_trash' => __ ( 'Not Found In Trash' ),
);
$args = array (
'label' => __ ( 'speakers' ),
'description' => __ ( 'Speakers on OpenFest' ),
'labels' => $labels ,
'supports' => array ( 'title' , 'excerpt' , 'thumbnail' , 'custom-fields' , ),
'hierarchical' => false ,
'public' => true ,
'show_ui' => true ,
'show_in_menu' => true ,
'show_in_nav_menus' => true ,
'show_in_admin_bar' => true ,
'menu_position' => 6 ,
'can_export' => true ,
'has_archive' => true ,
'exclude_from_search' => false ,
'publicly_queryable' => true ,
'capability_type' => 'post' ,
);
register_post_type ( 'speakers' , $args );
}
2014-10-10 17:25:34 +03:00
add_action ( 'init' , 'create_speakers_posttype' );
2014-10-05 03:32:43 +03:00
2023-09-08 13:17:11 +03:00
# Create a custom post type for Tranportation
2014-10-04 23:54:46 +03:00
function transportation_posttype () {
register_post_type ( 'transportation' ,
array (
'labels' => array (
'name' => __ ( 'Tranportation' ),
),
'public' => true ,
'has_archive' => true ,
'rewrite' => array ( 'slug' => 'transportation' ),
)
);
}
2014-10-07 17:02:23 +03:00
function openfest_home_page () {
2014-10-14 18:24:01 +03:00
if ( empty ( $wp )) { return is_front_page ();} ;
2014-10-07 17:02:23 +03:00
return ! ( $wp -> query_vars [ 'pagename' ] == 'home' || $wp -> query_vars [ 'pagename' ] == 'home-2' );
}
2014-10-09 21:23:38 +03:00
function of_get_lang () {
if ( function_exists ( " pll_current_language " ))
return pll_current_language ( 'slug' );
else
return 'bg' ;
}
function e_ ( $word ) {
if ( function_exists ( " pll_e " ))
return pll_e ( $word );
else
echo $word ;
}
2014-10-12 13:00:11 +03:00
function pn_get_attachment_id_from_url ( $attachment_url = '' ) {
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
global $wpdb ;
$attachment_id = false ;
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
// If there is no url, return.
if ( '' == $attachment_url )
return ;
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
// Get the upload directory paths
$upload_dir_paths = wp_upload_dir ();
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
// Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
if ( false !== strpos ( $attachment_url , $upload_dir_paths [ 'baseurl' ] ) ) {
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
// If this is the URL of an auto-generated thumbnail, get the URL of the original image
$attachment_url = preg_replace ( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i' , '' , $attachment_url );
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
// Remove the upload path base directory from the attachment URL
$attachment_url = str_replace ( $upload_dir_paths [ 'baseurl' ] . '/' , '' , $attachment_url );
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
// Finally, run a custom database query to get the attachment ID from the modified attachment URL
$attachment_id = $wpdb -> get_var ( $wpdb -> prepare ( " SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment' " , $attachment_url ) );
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
}
2023-09-08 13:17:11 +03:00
2014-10-12 13:00:11 +03:00
return $attachment_id ;
}
2014-10-04 23:54:46 +03:00
add_action ( 'init' , 'transportation_posttype' );
2014-10-07 16:17:21 +03:00
2014-10-09 21:23:38 +03:00
if ( function_exists ( " pll_register_string " )) {
pll_register_string ( 'Schedule' , 'Програма' );
pll_register_string ( 'Others' , 'Други' );
pll_register_string ( 'follow' , 'Последвайте ни в:' );
2015-09-30 21:11:27 +03:00
pll_register_string ( 'venue' , 'VENUE_LOCATION' );
2014-10-09 21:23:38 +03:00
pll_register_string ( 'venue_w' , 'Място' );
pll_register_string ( 'sponsors_w' , 'Спонсори' );
2014-10-14 18:24:01 +03:00
pll_register_string ( 'partners_w' , 'Партньори' );
2014-10-16 10:14:34 +03:00
pll_register_string ( 'speakers_w' , 'Лектори' );
2015-09-30 21:11:27 +03:00
pll_register_string ( 'time' , 'EVENT_TIME' );
2014-10-09 21:23:38 +03:00
pll_register_string ( 'publishedon' , 'Публикувано на' );
pll_register_string ( 'by_w' , 'От' );
pll_register_string ( 'see_whole_news' , 'виж цялата новина' );
pll_register_string ( 'news' , 'Новини' );
2014-10-26 10:50:22 +02:00
pll_register_string ( 'share_freedom' , 'Да споделим свободата' );
2014-10-13 16:37:45 +03:00
pll_register_string ( 'hall1' , 'София' );
pll_register_string ( 'hall2' , 'Варна' );
pll_register_string ( 'hall3' , 'G1' );
pll_register_string ( 'hall4' , 'Пловдив' );
pll_register_string ( 'hall5' , 'Бургас' );
2015-11-07 05:31:22 +02:00
pll_register_string ( 'bulgaria_hall' , 'BULGARIA_HALL' );
pll_register_string ( 'chamber_hall' , 'CHAMBER_HALL' );
pll_register_string ( 'music_hall' , 'MUSIC_HALL' );
pll_register_string ( 'low_quality' , 'LOW_QUALITY' );
pll_register_string ( 'normal_quality' , 'NORMAL_QUALITY' );
pll_register_string ( 'high_quality' , 'HIGH_QUALITY' );
2015-11-07 06:11:30 +02:00
pll_register_string ( 'all_streams' , 'ALL_STREAMS' );
2016-07-05 14:47:12 +03:00
pll_register_string ( 'tba' , 'TBA' );
2018-11-07 17:18:46 +02:00
pll_register_string ( 'feedback' , 'Submit feedback' );
2021-07-21 19:16:44 +03:00
pll_register_string ( 'about_event' , 'about_event' );
2024-10-24 23:43:03 +03:00
pll_register_string ( 'countdown_text_before' , 'countdown_text_before' );
pll_register_string ( 'countdown_text_after' , 'countdown_text_after' );
2024-10-24 23:38:56 +03:00
pll_register_string ( 'countdown_days' , 'countdown_days' );
pll_register_string ( 'countdown_hours' , 'countdown_hours' );
pll_register_string ( 'countdown_minutes' , 'countdown_minutes' );
2024-10-30 21:40:48 +02:00
pll_register_string ( 'after_event' , 'after_event' );
2024-10-30 22:05:30 +02:00
pll_register_string ( 'no_current_streams' , 'no_current_streams' );
2014-10-09 21:23:38 +03:00
}
2023-10-16 22:11:24 +03:00
add_filter ( 'wp_title' , 'wpdocs_hack_wp_title_for_home' );
/**
* Customize the title for the home page , if one is not set .
*
* @ param string $title The original title .
* @ return string The title to use .
*/
function wpdocs_hack_wp_title_for_home ( $title )
{
if ( empty ( $title ) && ( is_home () || is_front_page () ) ) {
$title = get_bloginfo ( 'name' ) . ' | ' . get_bloginfo ( 'description' );
} else {
$title = $title . get_bloginfo ( 'tagline' );
}
return $title ;
}