<commit_before><?php

if (class_exists('WMobilePack')):

    if (is_single() || is_page() || is_category()):

        // The mobile web app paths will be set relative to the home url
        $mobile_url = home_url();
        $is_visible = false;

        // Load config json
        if (WMobilePack_Options::get_setting('premium_active') == 1 && WMobilePack_Options::get_setting('premium_api_key') != '') {

            $premium_manager = new WMobilePack_Premium();
            $arr_config_premium = $premium_manager->get_premium_config();

            // Check if we have a valid subdomain linked to the Premium theme
            if ($arr_config_premium !== null && isset($arr_config_premium['domain_name']) && filter_var('http://' . $arr_config_premium['domain_name'], FILTER_VALIDATE_URL)) {
                $mobile_url = "http://" . $arr_config_premium['domain_name'];
            }
        }

        if (is_single()){

            // Read inactive categories
            $inactive_categories = WMobilePack_Options::get_setting('inactive_categories');

            // Read post categories
            $post_categories = get_the_category();

            // Check if the post belongs to a visible category
            $is_visible = false;
            $visible_category = null;

            foreach ($post_categories as $post_category){

                if (!in_array($post_category->cat_ID, $inactive_categories)) {
                    $is_visible = true;
                    $mobile_url .= "/#article/".get_the_ID();
                    break;
                }
            }

        } elseif (is_page()) {

            $page_id = get_the_ID();
            $inactive_pages = WMobilePack_Options::get_setting('inactive_pages');

            if (!in_array($page_id, $inactive_pages)){

                $is_visible = true;

                $mobile_url .= "/#page/".$page_id;
            }

        } elseif (is_category()) {

            $category_name = single_cat_title("", false);

            if ($category_name){

                $category_obj = get_term_by('name', $category_name, 'category');

                if ($category_obj && isset($category_obj->slug) && isset($category_obj->term_id) && is_numeric($category_obj->term_id)){

                    $category_id = $category_obj->term_id;

                    // check if the category is active / inactive before displaying it
                    $inactive_categories = WMobilePack_Options::get_setting('inactive_categories');

                    if (!in_array($category_id, $inactive_categories)){

                        $is_visible = true;

                        $mobile_url .= "/#category/".$category_obj->slug.'/'.$category_id;
                    }
                }
            }
        }

        if ($is_visible):
?>
            <link rel="alternate" media="only screen and (max-width: 640px)" href="<?php echo $mobile_url;?>" />
<?php<commit_msg>Exclude pages with inactive ancestors from rel alternate<commit_after><?php

if (class_exists('WMobilePack')):

    if (is_single() || is_page() || is_category()):

        // The mobile web app paths will be set relative to the home url
        $mobile_url = home_url();
        $is_visible = false;

        // Load config json
        if (WMobilePack_Options::get_setting('premium_active') == 1 && WMobilePack_Options::get_setting('premium_api_key') != '') {

            $premium_manager = new WMobilePack_Premium();
            $arr_config_premium = $premium_manager->get_premium_config();

            // Check if we have a valid subdomain linked to the Premium theme
            if ($arr_config_premium !== null && isset($arr_config_premium['domain_name']) && filter_var('http://' . $arr_config_premium['domain_name'], FILTER_VALIDATE_URL)) {
                $mobile_url = "http://" . $arr_config_premium['domain_name'];
            }
        }

        if (is_single()){

            // Read inactive categories
            $inactive_categories = WMobilePack_Options::get_setting('inactive_categories');

            // Read post categories
            $post_categories = get_the_category();

            // Check if the post belongs to a visible category
            $is_visible = false;
            $visible_category = null;

            foreach ($post_categories as $post_category){

                if (!in_array($post_category->cat_ID, $inactive_categories)) {
                    $is_visible = true;
                    $mobile_url .= "/#article/".get_the_ID();
                    break;
                }
            }

        } elseif (is_page()) {

            $page_id = get_the_ID();
            $inactive_pages = WMobilePack_Options::get_setting('inactive_pages');

            if (!in_array($page_id, $inactive_pages)){

				$page_ancestors = get_post_ancestors($page_id);

				// check if the page's ancestors are all visible
				if (count(array_intersect($page_ancestors, $inactive_pages)) == 0){

					$is_visible = true;

                	$mobile_url .= "/#page/".$page_id;
				}
            }

        } elseif (is_category()) {

            $category_name = single_cat_title("", false);

            if ($category_name){

                $category_obj = get_term_by('name', $category_name, 'category');

                if ($category_obj && isset($category_obj->slug) && isset($category_obj->term_id) && is_numeric($category_obj->term_id)){

                    $category_id = $category_obj->term_id;

                    // check if the category is active / inactive before displaying it
                    $inactive_categories = WMobilePack_Options::get_setting('inactive_categories');

                    if (!in_array($category_id, $inactive_categories)){

                        $is_visible = true;

                        $mobile_url .= "/#category/".$category_obj->slug.'/'.$category_id;
                    }
                }
            }
        }

        if ($is_visible):
?>
            <link rel="alternate" media="only screen and (max-width: 640px)" href="<?php echo $mobile_url;?>" />
<?php
{'fraction_non_alphanumeric': 0.1257010887495876, 'fraction_numerical': 0.0014846585285384361, 'mean_word_length': 2.0284715284715285, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7033753', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1651, 'n_words': 336}