| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <?php
- /**
- * Various filters and actions configuring some of the shortcodes
- *
- * @package vamtam/consulting
- */
- /**
- * class VamtamOverrides
- */
- class VamtamOverrides {
- /**
- * add filters
- */
- public static function filters() {
- add_filter( 'excerpt_length', array( __CLASS__, 'excerpt_length' ) );
- add_filter( 'excerpt_more', array( __CLASS__, 'excerpt_more' ) );
- add_filter( 'wp_trim_excerpt', array( __CLASS__, 'prepare_excerpt' ), 1, 2 );
- add_filter( 'wp_title', array( __CLASS__, 'wp_title' ) );
- wp_embed_register_handler( 'vamtam-swf', '#https?://[^\s]+?.swf$#i', array( __CLASS__, 'embed_handler_swf' ) );
- add_filter( 'pre_option_page_for_posts', '__return_zero' );
- add_filter( 'oembed_dataparse', array( __CLASS__, 'oembed_dataparse' ), 90, 3 );
- add_filter( 'nav_menu_css_class', array( __CLASS__, 'nav_menu_css_class' ), 10, 2 );
- add_filter( 'nav_menu_css_class', array( __CLASS__, 'nav_menu_css_class' ), 11, 2 );
- add_filter( 'megamenu_nav_menu_css_class', array( __CLASS__, 'nav_menu_css_class' ), 10, 2 );
- add_filter( 'megamenu_nav_menu_css_class', array( __CLASS__, 'nav_menu_css_class' ), 11, 2 );
- add_action( 'vamtam_body', array( __CLASS__, 'vamtam_splash_screen' ) );
- add_filter( 'wpcf7_form_elements', array( __CLASS__, 'shortcodes_in_cf7' ) );
- add_filter( 'pre_option_vamtam_header-layout', array( __CLASS__, 'header_layout' ) );
- add_action( 'loop_start', array( __CLASS__, 'jetpack_remove_share' ) );
- add_action( 'wp_footer', array( __CLASS__, 'post_siblings' ) );
- add_filter( 'vamtam_customizer_get_options_vamtam_theme', array( __CLASS__, 'customizer_get_options' ) );
- add_filter( 'widget_title', array( __CLASS__, 'widget_title' ), 10, 3 );
- add_filter( 'post_thumbnail_html', array( __CLASS__, 'post_thumbnail_html' ), 20, 5 );
- add_filter( 'vamtam_maybe_lazyload', array( __CLASS__, 'maybe_lazyload' ), 10, 4 );
- add_filter( 'jetpack_tiled_gallery_partial', array( __CLASS__, 'jetpack_tiled_gallery_partial' ), 10, 3 );
- add_filter( 'option_jetpack_active_modules', array( __CLASS__, 'jetpack_active_modules' ) );
- }
- /**
- * We have alternative implementations of some Jetpack modules which are better integrated with the theme
- */
- public static function jetpack_active_modules( $modules ) {
- return array_diff( $modules, [
- 'infinite-scroll',
- 'lazy-images',
- ] );
- }
- /**
- * Override Jetpack's tiled gallery template so that it supports our lazyload implementation
- */
- public static function jetpack_tiled_gallery_partial( $path, $name, $context ) {
- if ( $name === 'item' ) {
- return locate_template( 'templates/jetpack-tiled-gallery-item.php' );
- }
- return $path;
- }
- public static function post_thumbnail_html( $html, $post_ID, $post_thumbnail_id, $size, $attr ) {
- return self::maybe_lazyload( $html, $post_thumbnail_id, $size );
- }
- /**
- * [maybe_lazyload description]
- * @param string $html
- * @param int $image_id attachment id
- * @param string|array $size thumbnail name or [width, height] array
- * @return string
- */
- public static function maybe_lazyload( $html, $image_id, $size, $with_wrapper = true ) {
- if ( $html === '' || $GLOBALS['is_IE'] ) {
- return $html;
- }
- if ( is_array( $size ) ) {
- list( $width, $height ) = $size;
- } else {
- list( , $width, $height ) = wp_get_attachment_image_src( $image_id, $size );
- }
- $svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' . esc_attr( $width ) .' ' . esc_attr( $height ) .'" height="' . esc_attr( $height ) . 'px" width="' . esc_attr( $width ) . 'px"/>';
- $wrapped = '';
- if ( $with_wrapper ) {
- $wrapped .= '<div class="vamtam-responsive-wrapper">';
- }
- if ( apply_filters( 'vamtam_enable_image_lazyload', true ) ) {
- $new_srcset = 'srcset="data:image/svg+xml;utf8,' . esc_attr( str_replace( ' ', '%20', $svg ) ) . '"';
- $wrapped .= str_replace( 'srcset=', $new_srcset . ' data-srcset=', $html, $replacements );
- if ( $replacements === 0 ) {
- $wrapped = preg_replace( '/src="([^"]+)"/', 'src="$1" data-srcset="$1" ' . $new_srcset, $wrapped, 1 );
- }
- } else {
- $wrapped .= $html;
- }
- if ( $with_wrapper ) {
- $wrapped .= '</div>';
- }
- return $wrapped;
- }
- public static function widget_title( $title = '', $instance = null, $id_base = null ) {
- if ( ! is_null( $instance ) && $id_base === 'recent-posts' && empty( $instance['title'] ) ) {
- return '';
- }
- return $title;
- }
- public static function unlimited_image_sizes() {
- add_filter( 'wp_calculate_image_sizes', array( __CLASS__, 'wp_calculate_image_sizes' ), 10, 5 );
- }
- public static function limit_image_sizes() {
- remove_filter( 'wp_calculate_image_sizes', array( __CLASS__, 'wp_calculate_image_sizes' ), 10, 5 );
- }
- public static function wp_calculate_image_sizes( $sizes, $size, $image_src, $image_meta, $attachment_id ) {
- return '(min-width: 900px) 50vw, 100vw';
- }
- public static function post_siblings() {
- if ( VamtamTemplates::has_post_siblings_buttons() ) {
- get_template_part( 'templates/post-siblings-links' );
- }
- }
- public static function prepare_excerpt( $text = '', $raw_excerpt ) {
- if ( '' == $raw_excerpt ) {
- $text = get_the_content( '' );
- $text = VamtamTemplates::remove_outer_columns( $text );
- $text = strip_shortcodes( $text );
- /** This filter is documented in wp-includes/post-template.php */
- $text = apply_filters( 'the_content', $text );
- $text = str_replace( ']]>', ']]>', $text );
- $excerpt_length = apply_filters( 'excerpt_length', 40 );
- $excerpt_more = apply_filters( 'excerpt_more', ' […]' );
- $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
- }
- return $text;
- }
- public static function jetpack_remove_share() {
- remove_filter( 'the_content', 'sharing_display',19 );
- remove_filter( 'the_excerpt', 'sharing_display',19 );
- if ( class_exists( 'Jetpack_Likes' ) ) {
- remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 );
- }
- }
- public static function header_layout( $layout ) {
- $logo_type = rd_vamtam_get_option( 'header-logo-type' );
- if ( $logo_type === 'names' ) {
- return 'standard';
- }
- return $layout;
- }
- public static function wp_title( $title ) {
- if ( empty( $title ) && ( is_home() || is_front_page() ) ) {
- $description = get_bloginfo( 'description' );
- return get_bloginfo( 'name' ) . ( ! empty( $description ) ? ' | ' . $description : '' );
- }
- return $title;
- }
- /**
- * enable any shortcodes in CF7
- * @param string $form original html
- * @return string parsed with do_shortcode
- */
- public static function shortcodes_in_cf7( $form ) {
- return do_shortcode( vamtam_fix_shortcodes( $form ) );
- }
- /**
- * Show a splash screen on some pages
- */
- public static function vamtam_splash_screen() {
- $local = vamtam_post_meta( null, 'show-splash-screen-local', true );
- $enabled = $local === 'default' ? rd_vamtam_get_option( 'show-splash-screen' ) : vamtam_sanitize_bool( $local );
- $style = '';
- if ( ! $enabled ) {
- if ( ! is_customize_preview() ) {
- return;
- }
- $style = 'style="display: none"'; // we need the html for the customizer preview, but there is no need to show it on the first load
- }
- $logo = rd_vamtam_get_option( 'splash-screen-logo' );
- echo '<div class="vamtam-splash-screen" ' . $style . '>'; // xss ok
- echo '<div class="vamtam-splash-screen-progress-wrapper">';
- if ( ! empty( $logo ) ) {
- vamtam_url_to_image( $logo, 'full' );
- }
- echo '<div class="vamtam-splash-screen-progress"></div>
- </div>
- </div>';
- echo '<noscript><style>.vamtam-splash-screen { display: none !important }</style></noscript>';
- wp_enqueue_script( 'vamtam-splash-screen' );
- }
- /**
- * Remove unnecessary menu item classes
- *
- * @param array $classes current menu item classes
- * @param object $item menu item
- * @param object $args menu item args
- * @return array filtered classes
- */
- public static function nav_menu_css_class( $classes, $item ) {
- if ( isset( $item->url ) && strpos( $item->url, '#' ) !== false && ( $key = array_search( 'mega-current-menu-item', $classes ) ) !== false ) {
- unset( $classes[ $key ] );
- $classes[] = 'maybe-current-menu-item';
- $GLOBALS['vamtam_menu_had_hash'] = true;
- }
- if ( isset( $GLOBALS['vamtam_menu_had_hash'] ) && $GLOBALS['vamtam_menu_had_hash'] ) {
- $classes = array_diff( $classes, array( 'mega-current-menu-item', 'mega-current-menu-ancestor', 'mega-current-menu-parent' ) );
- }
- return $classes;
- }
- /**
- * Wrap oEmbeds in .vamtam-video-frame
- *
- * @param string $output original oembed output
- * @param object $data data from the oEmbed provider
- * @param string $url original embed url
- * @return string $output wrapped in additional html
- */
- public static function oembed_dataparse( $output, $data, $url ) {
- if ( $data->type == 'video' )
- return '<div class="vamtam-video-frame">' . $output . '</div>';
- return $output;
- }
- /**
- * Implements .swf oEmbeds
- *
- * @param array $matches preg_match matches
- * @param array $attr embed attributes
- * @param string $url embed url
- * @param array $rawattr raw attributes
- * @return string output html
- */
- public static function embed_handler_swf( $matches, $attr, $url, $rawattr ) {
- $embed = sprintf(
- '
- <div class="vamtam-video-frame">
- <object width="%2$s" height="%3$s" type="application/x-shockwave-flash" data="%1$s">
- <param name="movie" value="%1$s" />
- <param name="allowFullScreen" value="true" />
- <param name="allowscriptaccess" value="always" />
- <param name="wmode" value="transparent" />
- <embed src="%1$s" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="%2$s" height="%3$s" />
- </object>
- </div>',
- esc_attr( $matches[0] ),
- esc_attr( $attr['width'] ),
- esc_attr( $attr['height'] )
- );
- return apply_filters( 'vamtam_embed_swf', $embed, $matches, $attr, $url, $rawattr );
- }
- /**
- * Sets the excerpt length
- *
- * @param int $length original length
- * @return int excerpt length
- */
- public static function excerpt_length( $length ) {
- global $vamtam_loop_vars;
- if ( isset( $vamtam_loop_vars ) && $vamtam_loop_vars['news'] )
- return 15;
- return $length;
- }
- /**
- * Sets the excerpt ending
- *
- * @param string $more original ending
- * @return string excerpt ending
- */
- public static function excerpt_more( $more ) {
- return '...';
- }
- }
|