<?

//************* TESTING *******************************************//

    // Display errors
        // error_reporting(E_ERROR | E_PARSE | E_COMPILE_ERROR);
        // ini_set('display_errors',1);
        // ini_set('display_startup_errors',1);
        // ini_set('log_errors',1);
        // ini_set('error_log',get_stylesheet_directory().'/debug.txt');


//************* BASIC WP ADDITIONS ********************************//

    // Allow SVG upload with extra security since an SVG is technically code

        // Allow SVG upload safely
        function allow_svg_upload($mimes){
            $mimes['svg'] = 'image/svg+xml';
            return $mimes;
        }
        add_filter('upload_mimes','allow_svg_upload');

        // Fix WP filetype check for SVGs
        function fix_svg_filetype_check($data,$file,$filename,$mimes){
            $ext = strtolower(pathinfo($filename,PATHINFO_EXTENSION));
            if($ext === 'svg'):
                $data['ext']  = 'svg';
                $data['type'] = 'image/svg+xml';
            endif;
            return $data;
        }
        add_filter('wp_check_filetype_and_ext','fix_svg_filetype_check',10,4);

        // Sanitize SVGs safely before saving
        function sanitize_svg($file){
            $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
            if($ext !== 'svg') return $file;

            if(!file_exists($file['tmp_name'])) return $file;

            libxml_use_internal_errors(true);
            $svg_content = file_get_contents($file['tmp_name']);
            if(!$svg_content) return $file;

            $dom = new DOMDocument();
            try{
                $dom->loadXML($svg_content, LIBXML_NONET | LIBXML_NOERROR | LIBXML_NOWARNING);

                // Remove <script> elements
                while(($scripts = $dom->getElementsByTagName('script'))->length > 0):
                    $scripts->item(0)->parentNode->removeChild($scripts->item(0));
                endwhile;

                // Remove event attributes
                $xpath = new DOMXPath($dom);
                foreach($xpath->query('//@*[starts-with(name(), "on")]') as $attr):
                    $attr->ownerElement->removeAttributeNode($attr);
                endforeach;

                // Save back to temp file
                $dom->save($file['tmp_name']);
            } catch (Exception $e){
                // If SVG is malformed, just skip sanitization
                return $file;
            }
            return $file;
        }
        add_filter('wp_handle_upload_prefilter', 'sanitize_svg');

        // Admin preview CSS for SVGs
        function fix_svg(){
            echo '<style type="text/css">.attachment-266x266,.thumbnail img{width:100%!important;height:auto!important;}</style>';
        }
        add_action('admin_head','fix_svg');


//************* ITEMS BELOW ARE SPECIFIC TO THE THEME *************//

    // Enqueue files as needed
        function wpdocs_theme_name_scripts(){
            wp_enqueue_style('jBox-css',get_stylesheet_directory_uri().'/jBox.all.min.css');
            wp_enqueue_script('jBox-js',get_stylesheet_directory_uri().'/jBox.all.min.js',array(),'1.0.0',true);
        }
        add_action('wp_enqueue_scripts','wpdocs_theme_name_scripts');

    // Shortcode to display the current year
        function display_current_year(){
            return date('Y');
        }
        add_shortcode('year','display_current_year');


/* /////////// SUMMARY ////////////////
• Only do what is necessary for Home, Transplant Division, and Referral form pages.
• Update php
• Make footer year dynamic
• Activate auto-updates
//////////////////////////////////// */<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://axiva.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://axiva.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://axiva.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://axiva.com/wp-sitemap-posts-us_portfolio-1.xml</loc></sitemap><sitemap><loc>https://axiva.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://axiva.com/wp-sitemap-taxonomies-us_portfolio_category-1.xml</loc></sitemap></sitemapindex>
