ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

content.php (10520B)


      1 <?php
      2 
      3 require_once get_template_directory() . "/inc/header-options/content-options/content-type.php";
      4 require_once get_template_directory() . "/inc/header-options/content-options/inner-pages.php";
      5 require_once get_template_directory() . "/inc/header-options/content-options/title.php";
      6 require_once get_template_directory() . "/inc/header-options/content-options/subtitle.php";
      7 materialis_require("/inc/header-options/content-options/subtitle2.php");
      8 require_once get_template_directory() . "/inc/header-options/content-options/buttons.php";
      9 
     10 
     11 function materialis_customize_register_options_header_content_settings_group()
     12 {
     13     materialis_add_options_group(array(
     14         "materialis_front_page_header_title_options"    => array(
     15             // section, prefix, priority
     16             "header_background_chooser",
     17             "header",
     18             6,
     19         ),
     20         "materialis_front_page_header_subtitle_options" => array(
     21             "header_background_chooser",
     22             "header",
     23             6,
     24         ),
     25         "materialis_front_page_header_buttons_options"  => array(
     26             "header_background_chooser",
     27             "header",
     28             6,
     29         ),
     30 
     31         "materialis_front_page_header_content_options" => array(
     32             "header_background_chooser",
     33             "header",
     34             5,
     35         ),
     36 
     37         "materialis_inner_pages_header_content_options" => array(
     38             "header_image",
     39             "inner_header",
     40             9,
     41         ),
     42     ));
     43 }
     44 
     45 add_action("materialis_customize_register_options", 'materialis_customize_register_options_header_content_settings_group');
     46 
     47 
     48 if ( ! function_exists("materialis_print_header_content")) {
     49     function materialis_print_header_content()
     50     {
     51         do_action("materialis_print_header_content");
     52     }
     53 }
     54 
     55 function materialis_get_media_types()
     56 {
     57     return apply_filters('materialis_media_type_choices', array(
     58         "image" => esc_html__("Image", "materialis"),
     59     ));
     60 }
     61 
     62 function materialis_get_partial_types()
     63 {
     64     return apply_filters('materialis_header_content_partial', array(
     65         "content-on-center" => esc_html__("Text on center", "materialis"),
     66         "content-on-right"  => esc_html__("Text on right", "materialis"),
     67         "content-on-left"   => esc_html__("Text on left", "materialis"),
     68         "media-on-left"     => esc_html__("Text with media on left", "materialis"),
     69         "media-on-right"    => esc_html__("Text with media on right", "materialis"),
     70     ));
     71 }
     72 
     73 function materialis_get_front_page_header_media_and_partial()
     74 {
     75     $partial   = materialis_get_theme_mod('header_content_partial', materialis_mod_default('header_content_partial'));
     76     $mediaType = materialis_get_theme_mod('header_content_media', 'image');
     77 
     78     if ( ! array_key_exists($partial, materialis_get_partial_types())) {
     79         $partial = materialis_mod_default('header_content_partial');
     80     }
     81 
     82     if ( ! array_key_exists($mediaType, materialis_get_media_types())) {
     83         $mediaType = 'image';
     84     }
     85 
     86     return array(
     87         'partial' => $partial,
     88         'media'   => $mediaType,
     89     );
     90 
     91 }
     92 
     93 function materialis_print_front_page_header_content()
     94 {
     95     $headerContent = materialis_get_front_page_header_media_and_partial();
     96     $partial       = $headerContent['partial'];
     97     $classes       = apply_filters('materialis_header_description_classes', array($partial, "gridContainer"));
     98 
     99     do_action('materialis_before_front_page_header_content');
    100 
    101     ?>
    102 
    103     <div class="header-description <?php echo esc_attr(implode(" ", $classes)); ?>">
    104         <?php get_template_part('template-parts/header/hero', $partial); ?>
    105     </div>
    106 
    107     <?php
    108 
    109     do_action('materialis_after_front_page_header_content');
    110 }
    111 
    112 function materialis_print_header_media_frame($media)
    113 {
    114     $frame_type = materialis_get_theme_mod('header_content_frame_type', "border");
    115     if ($frame_type === "none") {
    116         echo $media;
    117 
    118         return;
    119     }
    120 
    121 
    122     $frame_width  = intval(materialis_get_theme_mod('header_content_frame_width', "100"));
    123     $frame_height = intval(materialis_get_theme_mod('header_content_frame_height', "100"));
    124 
    125     $frame_offset_left = intval(materialis_get_theme_mod('header_content_frame_offset_left', "-13"));
    126     $frame_offset_top  = intval(materialis_get_theme_mod('header_content_frame_offset_top', "10"));
    127     $frame_over_image  = materialis_get_theme_mod('header_content_frame_show_over_image', false);
    128     $frame_color       = materialis_get_theme_mod('header_content_frame_color', "rgba(255,255,255,0.726)");
    129     $frame_thickness   = intval(get_theme_mod('header_content_frame_thickness', 11));
    130     $frame_shadow      = materialis_get_theme_mod('header_content_frame_shadow', true);
    131     $frame_hide        = materialis_get_theme_mod('header_content_frame_hide_on_mobile', true);
    132 
    133     $z_index = $frame_over_image ? 1 : -1;
    134 
    135     $style = "transform:translate($frame_offset_left%, $frame_offset_top%);";
    136     $style .= "width:{$frame_width}%;height:{$frame_height}%;";
    137     $style .= "{$frame_type}-color:{$frame_color};";
    138     $style .= "z-index:$z_index;";
    139 
    140     if ($frame_type == "border") {
    141         $style .= "border-width:{$frame_thickness}px;";
    142     }
    143 
    144     $classes = "overlay-box-offset  offset-" . $frame_type . " ";
    145 
    146     if ($frame_shadow) {
    147         $classes .= "mdc-elevation--z4 ";
    148     }
    149 
    150     if ($frame_hide) {
    151         $classes .= "hide-xs ";
    152     }
    153 
    154     $headerContent = materialis_get_front_page_header_media_and_partial();
    155     $partial       = $headerContent['partial'];
    156     
    157     $style_overlay = '';
    158     if ($headerContent['partial'] == 'media-on-top')
    159     {
    160         $style_overlay = 'margin-bottom:' . abs($frame_offset_top) . '%';
    161     }
    162     
    163     if ($headerContent['partial'] == 'media-on-bottom')
    164     {
    165         $style_overlay = 'margin-top:' . abs($frame_offset_top) . 'px';
    166     }
    167 
    168     $align = "";
    169     if (in_array($partial, array("media-on-right", "media-on-left"))) {
    170         $align = "end-sm";
    171     }
    172     ?>
    173     <div class="flexbox center-xs <?php echo $align; ?> middle-xs">
    174         <div class="overlay-box"  style="<?php echo esc_attr($style_overlay); ?>">
    175             <div class="<?php echo esc_attr($classes); ?>" style="<?php echo esc_attr($style); ?>"></div>
    176             <?php echo $media; ?>
    177         </div>
    178     </div>
    179     <?php
    180 }
    181 
    182 function materialis_print_header_media_image($mediaType)
    183 {
    184     if ($mediaType == "image") {
    185         $roundImage   = materialis_get_theme_mod('header_content_image_rounded', false);
    186         $extraClasses = "";
    187         if (intval($roundImage)) {
    188             $extraClasses .= " round";
    189         }
    190 
    191         $image = materialis_get_theme_mod('header_content_image', get_template_directory_uri() . "/assets/images/media-image-default.jpg");
    192 
    193         $customizerLink = "";
    194 
    195         if (materialis_is_customize_preview()) {
    196             $customizerLink = "data-type=\"group\" data-focus-control=\"header_content_image\"";
    197         }
    198 
    199         if (is_numeric($image)) {
    200             $image = wp_get_attachment_image_src(absint($image), 'full', false);
    201             if ($image) {
    202                 list($src, $width, $height) = $image;
    203                 $image = $src;
    204             } else {
    205                 $image = "#";
    206             }
    207         }
    208 
    209         if ( ! empty($image)) {
    210             $image = sprintf('<img class="homepage-header-image %2$s" %3$s src="%1$s"/>', esc_url($image), esc_attr($extraClasses), $customizerLink);
    211             materialis_print_header_media_frame($image);
    212         }
    213     }
    214 }
    215 
    216 add_action("materialis_print_header_media", 'materialis_print_header_media_image');
    217 
    218 if ( ! function_exists('materialis_print_header_media')) {
    219     function materialis_print_header_media()
    220     {
    221         $headerContent = materialis_get_front_page_header_media_and_partial();
    222         $mediaType     = $headerContent['media'];
    223 
    224         do_action('materialis_print_header_media', $mediaType);
    225 
    226     }
    227 }
    228 
    229 add_action('materialis_after_front_page_header_content', 'materialis_print_default_after_header_content');
    230 add_action('materialis_after_inner_page_header_content', 'materialis_print_default_after_header_content');
    231 
    232 function materialis_get_header_top_spacing_script()
    233 {
    234     ob_start();
    235     ?>
    236     <script>
    237         (function ($) {
    238             function setHeaderTopSpacing() {
    239                 $('.header-wrapper .header,.header-wrapper .header-homepage').css({
    240                     'padding-top': $('.header-top').height()
    241                 });
    242 
    243              setTimeout(function() {
    244                   var headerTop = document.querySelector('.header-top');
    245                   var headers = document.querySelectorAll('.header-wrapper .header,.header-wrapper .header-homepage');
    246 
    247                   for (var i = 0; i < headers.length; i++) {
    248                       var item = headers[i];
    249                       item.style.paddingTop = headerTop.getBoundingClientRect().height + "px";
    250                   }
    251 
    252                     var languageSwitcher = document.querySelector('.materialis-language-switcher');
    253 
    254                     if(languageSwitcher){
    255                         languageSwitcher.style.top = "calc( " +  headerTop.getBoundingClientRect().height + "px + 1rem)" ;
    256                     }
    257                     
    258                 }, 100);
    259 
    260             }
    261 
    262             jQuery(window).on('resize orientationchange', setHeaderTopSpacing);
    263             window.materialisSetHeaderTopSpacing = setHeaderTopSpacing
    264 
    265         })(jQuery);
    266     </script>
    267     <?php
    268 
    269     $content = ob_get_clean();
    270     $content = strip_tags($content);
    271 
    272     return $content;
    273 }
    274 
    275 add_action('wp_enqueue_scripts', 'materialis_enqueue_header_top_spacing_script', 40);
    276 function materialis_enqueue_header_top_spacing_script()
    277 {
    278     wp_add_inline_script('jquery', materialis_get_header_top_spacing_script());
    279 }
    280 
    281 function materialis_print_default_after_header_content()
    282 {
    283     //  execute top spacing script as soon as possible to prevent repositioning flicker
    284     ?>
    285     <script>
    286 		if (window.materialisSetHeaderTopSpacing) {
    287 			window.materialisSetHeaderTopSpacing();
    288 		}
    289     </script>
    290     <?php
    291 }
    292 
    293 
    294 add_action('wp_head', 'materialis_print_background_content_color', PHP_INT_MAX);
    295 
    296 function materialis_print_background_content_color()
    297 {
    298 
    299     ?>
    300     <style data-name="background-content-colors">
    301         .materialis-front-page .content.blog-page,
    302         .materialis-inner-page .page-content,
    303         .materialis-inner-page .content,
    304         .materialis-front-page.materialis-content-padding .page-content {
    305             background-color: #<?php echo sanitize_hex_color_no_hash( get_background_color() ); ?>;
    306         }
    307     </style>
    308     <?php
    309 }