loadHTML($buffer, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $dom->loadHTML($buffer); // Remove Empty Headings if ( $adarelief_emptyheadings ) { $domwasneeded = true; for ($ir = 1; $ir <= 6; $ir++) { $headings = $dom->getElementsByTagName('h'.$ir); for ($i = $headings->length; --$i >= 0; ) { $heading = $headings->item($i); if (str_ireplace(array(' ',' ','-','_'), '', trim(htmlentities(wp_strip_all_tags($heading->nodeValue)))) == "") { $img = $heading->getElementsByTagName('img')->item(0); if (!isset($img) || $img->getAttribute('alt') == "") { adarelief_DOMRemove($heading); } } } } } // END Empty Headings // Fix Missing Form Labels --DOM-- if ( $adarelief_addlabels ) { $domwasneeded = true; // EMPTY LABELS $labels = $dom->getElementsByTagName('label'); for ($i = $labels->length; --$i >= 0; ) { $label = $labels->item($i); if ( $label->nodeValue == '') $label->parentNode->removeChild($label); } // END EMPTY LABELS } // PRO Fix Missing Form Labels --DOM-- // PRO END MISSING FORM LABELS // Fix target Blank --DOM-- if ( $adarelief_remtargetblank ) { $domwasneeded = true; $alllinks = $dom->getElementsByTagName('a'); foreach ($alllinks as $theadalink) { if ( strtolower($theadalink->getAttribute('target')) == strtolower("_blank")) { $theadalinkaria = $theadalink->getAttribute('aria-label'); if (strpos(strtolower($theadalinkaria), 'new window') === false) { $theadalinkaria .= ' (Opens in New Window)'; $theadalink->setAttribute('aria-label', $theadalinkaria); } } } } // End Target Blank // Add Lang --DOM-- if ( $adarelief_lang ) { $adarelief_langcode = get_option( 'adarelief_langcode'); if($adarelief_langcode != "") { $domwasneeded = true; $html = $dom->getElementsByTagName('html'); foreach ($html as $htmlcode) { if ($htmlcode->getAttribute('lang') == "" and $htmlcode->getAttribute('xml:lang') == "") $htmlcode->setAttribute('lang', $adarelief_langcode); } } } // END Lang if ($domwasneeded) { $buffer = $dom->saveHTML(); } // DO SOME REVOLUTION SLIDER FIXES if ($adarelief_revsliddup) { $buffer = str_replace( 'Oops...', 'Oops...', $buffer ); $buffer = str_replace( 'jQuery(sliderID).show().html(err); } }', 'jQuery(sliderID).show().html(err); } }', $buffer ); } return $buffer; } function adarelief_change_justified_text($content){ $content = preg_replace( '/(text-)?align:\s?justify/i', 'text-align: '.'left', $content ); return $content; } function adarelief_make_alttags ( $buffer ) { $adarelief_imgdec = get_option('adarelief_imgdec'); // Get The Page Title preg_match('/(.*?)\<\/title>/i',$buffer, $artitletouse); // Get All Images preg_match_all('/<img (.*?)\>/i',$buffer, $matches); $adanr = 0; foreach($matches[0] as $data ) { $adanr++; // This is used to Fix the Closeing Images Alt Texts // No Alt if (!strpos( $data, 'alt=' )) { // The image has title? if (strpos( $data, 'title="' ) ) { preg_match('/title="(.*?)"/i',$data, $arimgtitle); $datanew = $data; $imgwithalt = '<img alt="' . $arimgtitle[1] . ' ' . $adanr . '" '; $datanew = str_replace( '<img ', $imgwithalt , $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else { // Check to find title $datanew = $data; $imgwithalt = '<img alt="' . $artitletouse[1] . ' ' . $adanr . '" '; $datanew = str_replace( '<img ', $imgwithalt , $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } } else if (strpos( $data, 'alt=""' ) ) { // We Can Keep Decorative? if (!$adarelief_imgdec) { // The image has title? if (strpos( $data, 'title="' ) ) { preg_match('/title="(.*?)"/i',$data, $arimgtitle); $datanew = $data; $imgwithalt = '<img alt="' . $arimgtitle[1] . ' ' . $adanr . '" '; $datanew = str_replace( 'alt=""', '' , $datanew ); $datanew = str_replace( '<img ', $imgwithalt , $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ($artitletouse[1] != '') { // Check to find title $datanew = $data; $imgwithalt = '<img alt="' . $artitletouse[1] . ' ' . $adanr. '" '; $datanew = str_replace( 'alt=""', '' , $datanew ); $datanew = str_replace( '<img ', $imgwithalt , $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else { // Just Decorative $datanew = $data; $imgwithalt = '<img alt="' . 'A Decorative Photo' . ' ' . $adanr. '" '; $datanew = str_replace( 'alt=""', '' , $datanew ); $datanew = str_replace( '<img ', $imgwithalt , $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } } // End Decorative Subroutine } } return $buffer; } function adarelief_make_emptylinks ( $buffer ) { // Our Compatibility improvements $adarelief_avada = get_option('adarelief_avada'); $adarelief_kallyas = get_option('adarelief_kallyas'); $adarelief_highend = get_option('adarelief_highend'); $adarelief_camping = get_option('adarelief_camping'); // Camping by Nexus Themes Compatibility if ($adarelief_camping) { require_once ( ADARELIEF_PATH . 'lib/3rdparty/camping.php'); $buffer = adarelief_camping_work ( $buffer ); } preg_match_all('/<a\s[^>]+>(.*?)<\/a>/i',$buffer, $matches); foreach($matches[0] as $data ) { preg_match('/<a\s[^>]+>(.*?)<\/a>/i',$data, $matches1); // HighEnd Theme Compatibility if ( $adarelief_highend ) { $buffer = str_replace( '<i class="hb-moon-facebook"></i>', '<i class="hb-moon-facebook"><span class="screen-reader-text">Facebook</span></i>', $buffer ); $buffer = str_replace( '<a class="mobile-menu-close"><i class="hb-icon-x"></i></a>', '<a class="mobile-menu-close"><i class="hb-icon-x"><span class="screen-reader-text">Mobile Menu Close</span></i></a>', $buffer ); $buffer = str_replace( '<i class="icon-bars"></i>', '<i class="icon-bars"><span class="screen-reader-text">Mobile Menu Close</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-icon-x"></i>', '<i class="hb-icon-x"><span class="screen-reader-text">Close Fancy Search</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-facebook"></i>', '<i class="hb-moon-facebook"><span class="screen-reader-text">Facebook</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-twitter"></i>', '<i class="hb-moon-twitter"><span class="screen-reader-text">Twitter</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-feed-2"></i>', '<i class="hb-moon-feed-2"><span class="screen-reader-text">Feed</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-foursquare"></i>', '<i class="hb-moon-foursquare"><span class="screen-reader-text">Foursquare</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-instagram"></i>', '<i class="hb-moon-instagram"><span class="screen-reader-text">Instagram</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-linkedin"></i>', '<i class="hb-moon-linkedin"><span class="screen-reader-text">Linkedin</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-pinterest"></i>', '<i class="hb-moon-pinterest"><span class="screen-reader-text">Pinterest</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-yelp"></i>', '<i class="hb-moon-yelp"><span class="screen-reader-text">Yelp</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-vimeo"></i>', '<i class="hb-moon-vimeo"><span class="screen-reader-text">Vimeo</span></i>', $buffer ); $buffer = str_replace( '<i class="icon-tripadvisor"></i>', '<i class="icon-tripadvisor"><span class="screen-reader-text">TripAdvisor</span></i>', $buffer ); $buffer = str_replace( '<i class="hb-moon-youtube"></i>', '<i class="hb-moon-youtube"><span class="screen-reader-text">Youtube</span></i>', $buffer ); } // END Highend Compatibility // Combatibility with Call&Book Mobile Bar Plugin if (strpos( $matches1[0], '<span class="callbook-icona-busta-lettera"></span>' ) ) { $datanew = $data; $datanew = str_replace( '<span class="callbook-icona-busta-lettera"></span>', '<span class="callbook-icona-busta-lettera"><span class="screen-reader-text">Send Email</span></span></i>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } // Kallyas Compatibility if (strpos( $matches1[1], 'glyphicon glyphicon-menu-left' ) ) { if ( $adarelief_kallyas ) { $datanew = $data; $datanew = str_replace( 'class="glyphicon glyphicon-menu-left"></span>', 'class="glyphicon glyphicon-menu-left"><span class="screen-reader-text">Slider Go Left</span></span>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } } if (strpos( $matches1[1], 'glyphicon glyphicon-menu-right' ) ) { if ( $adarelief_kallyas ) { $datanew = $data; $datanew = str_replace( 'class="glyphicon glyphicon-menu-right"></span>', 'class="glyphicon glyphicon-menu-right"><span class="screen-reader-text">Slider Go Right</span></span>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } } // End Kallyas Compatibility // Has something inside? // Do all the rest if (!strpos( $matches1[1], 'aria-label' ) ) { // We Don't Do anything if Aria Label is present // TO ADD EXTRACTION TEXTS FROM ARIA or TITLE $datanew = $data; $datanew = str_replace( '></i>', '><span class="screen-reader-text">Link </span></i>', $datanew ); //$datanew = str_replace( '></i>', ' aria-label="This is a link"></i>', $datanew ); //$datanew = str_replace( 'href=', 'aria-label="This is a link" href=', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } if (!strpos( $matches1[0], 'aria-label' ) ) { // We Don't Do anything if Aria Label is present // TO ADD EXTRACTION TEXTS FROM ARIA or TITLE $datanew = $data; //$datanew = str_replace( '></a>', '><span class="screen-reader-text">Link </span></a>', $datanew ); $datanew = str_replace( '></i>', '><span class="screen-reader-text">Link </span></i>', $datanew ); //$datanew = str_replace( '></i>', ' aria-label="This is a link"></i>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } /* if ((!strpos( $matches1[0], 'aria-label' ) ) AND ($matches1[1] != '')) { preg_match('/<span\s[^>]+>(.*?)<\/span>/i',$data, $matches2); if ($matches2[1] == '' ) { $datanew = $data; $datanew = str_replace( 'href=', 'aria-label="This is a link" href=', $datanew ); //$datanew = str_replace( '<a class="mobile-menu-close"><i class="hb-icon-x"></i></a>', '<a class="mobile-menu-close"><i class="hb-icon-x"><span class="screen-reader-text">Mobile Menu Close</span></i></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } } */ // HighEnd Theme Compatibility if ( $adarelief_highend ) { if (strpos( $matches1[0], '<a class="mobile-menu-close"><i class="hb-icon-x"></i></a>' ) ) { $datanew = $data; $datanew = str_replace( '<a class="mobile-menu-close"><i class="hb-icon-x"></i></a>', '<a class="mobile-menu-close"><i class="hb-icon-x"><span class="screen-reader-text">Mobile Menu Close</span></i></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } } if ( $matches1[1] == '' ) { // Avada Compatibility if ( $adarelief_avada ) { if (strpos( $data, 'tfs-scroll-down-indicator' ) ) { $datanew = $data; $datanew = str_replace( '></a>', '><span class="screen-reader-text">Scroll Down</span></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } if (strpos( $data, 'fusion-page-load-link"></a>' ) ) { $datanew = $data; $datanew = str_replace( 'fusion-page-load-link"></a>', 'fusion-page-load-link"><span class="screen-reader-text">Page Load Link</span></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } } // Kallyas Compatibility else if ( $adarelief_kallyas ) { if (strpos( $data, 'zn-res-trigger zn-header-icon' ) ) { $datanew = $data; $datanew = str_replace( '<a href="#" class="zn-res-trigger zn-header-icon"></a>', '<a href="#" class="zn-res-trigger zn-header-icon"><span class="screen-reader-text">Menu Trigger</span></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } } // LETS ADD SOME SOCIAL PRE-DEFAULTS if ((strpos( $data, 'facebook' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="Facebook"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'twitter' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="Twitter"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'foursquare' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="foursquare"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'google' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="google"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'instagram' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="instagram"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'linkedin' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="linkedin"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'pinterest' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="pinterest"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'youtube' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="youtube"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'vimeo' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="vimeo"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } else if ((strpos( $data, 'yelp' ) ) AND (!strpos( $data, 'aria-label' ) ) ) { $datanew = $data; $datanew = str_replace( '></a>', ' aria-label="yelp"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); } // Do all the rest else if (!strpos( $data, 'aria-label' ) ) { // We Don't Do anything if Aria Label is present // TO ADD EXTRACTION TEXTS FROM ARIA or TITLE $datanew = $data; // $datanew = str_replace( '></a>', '><span class="screen-reader-text">Link </span></a>', $datanew ); $datanew = str_replace( '></a>', ' aria-label="This is a link"></a>', $datanew ); $buffer = str_replace( $data, $datanew, $buffer ); // Other Empty links to come } } } // Code For Google Recaptcha Empty Label // $buffer = str_replace( 'CAPTCHA</label>', 'CAPTCHA</label><label style="display:none" for="g-recaptcha-response">Google response:</label>', $buffer ); return $buffer; } // PRO START SEARCH - REPLACE FUNCTION // PRO END SEARCH - REPLACE FUNCTION // PRO BROKEN ARIA MENU // END BROKEN ARIA MENU function adarelief_make_emptyheadings ( $buffer ) { preg_match_all('|<h([1-6])(.*?)><\/h([1-6])>|i',$buffer, $matches); foreach($matches as $data ) { //if (( $data[2] == '' ) || ( $data[2] == null )){ // Let's Remove the Empty Headings $buffer = str_replace( $data, '', $buffer ); // } } return $buffer; } function adarelief_rem_noscript ( $buffer ) { preg_match_all('/<noscript>(.*?)<\/noscript>/is',$buffer, $matches, PREG_SET_ORDER, 0); foreach($matches as $data ) { $buffer = str_replace( $data ,'', $buffer ); } return $buffer; } function adarelief_make_emptyheadings2 ( $buffer ) { // replace tags without images for ($i = 1; $i <= 6; $i++) { $buffer = preg_replace( '#<h'.$i.'(\s)*(class=("|\')(\w|\s)*("|\'))*>(\n|\s|\r)*(<\w*>(\s)*</\w*>)*(\s)*( |\s)*</h'.$i.'>#is', '', $buffer ); //$buffer = preg_replace( '#<h'.$i.'(\s)*(class=("|\')(\w|\s)*("|\'))*>(\n|\s|\r)*(<\w*>(\s)*</\w*>)*(\s)*( |\s)*</h'.$i.'>#is', '', $content ); // replace tags with images inside //$content = preg_replace( '/<h'.$i.'(\s)*(class=("|\')(\w|\s)*("|\'))*>(\s| )*(<a(\s|\w|[[:punct:]])[^><]*>)*(\s| )*(<img(\s|\w|[[:punct:]])[^><]*(\/)*>(<\/img>)*(?!\w))(\s| )*(<\/a>)*(\s| )*<\/h'.$i.'>/is', '$7$10$15', $content); } return $buffer; } function adarelief_remove_autoplay($content){ $adarelief_avada = get_option('adarelief_avada'); if ( $adarelief_avada ) { // If Avada fix Fusion Slider $content= str_ireplace('data-autoplay="1"', 'data-autoplay="0"', $content); $content= str_ireplace('data-autoplay="yes"', 'data-autoplay="no"', $content); } // The Rest $content= str_ireplace('autostart="true"', "", $content); $content= str_ireplace("autostart='true'", "", $content); $content= str_ireplace('&autoPlay=true', "", $content); $content= str_ireplace('&autoPlay=true', "", $content); $content = preg_replace('/<param(\s)*name=(\'|")+(autoplay)(\'|")+(\/)*(\s)*value=(\'|")+(true)(\'|")+(\s*\/*>)(<\/param>)*/i','', $content); $content= str_ireplace('autoPlay="autoplay"', "", $content); $content= str_ireplace('autoplay=""', "", $content); $content= str_ireplace("autoplay=''", "", $content); $content= str_ireplace("autoPlay='autoplay'", "", $content); $content= str_ireplace('autoPlay="1"', "", $content); $content= str_ireplace("autoPlay='1'", "", $content); //$content = preg_replace('/(<audio+.+)((\s)((\S)+=("|\')(\w|\s|-|_)*("|\'))*(\s))*(autoplay)+(((\s)*((\S)+=("|\')(\w|\s|-|_)*("|\'))*(\s)*)*>)/i','$1$11', $content); //$content = preg_replace('/(<video+.+)((\s)((\S)+=("|\')(\w|\s|-|_)*("|\'))*(\s))*(autoplay)+(((\s)*((\S)+=("|\')(\w|\s|-|_)*("|\'))*(\s)*)*>)/i','$1$11', $content); return $content; } /*********************************************************************************** // Remove nodes but leave children **********************************************************************************/ function adarelief_DOMRemove(DOMNode $from) { $sibling = $from->firstChild; if($sibling){ do { $next = $sibling->nextSibling; $from->parentNode->insertBefore($sibling, $from); } while ($sibling = $next); } $from->parentNode->removeChild($from); } // THE FUNCTION function adarelief_domTextReplace( $search, $replace, DOMNode &$domNode, $isRegEx = false ) { if ( $domNode->hasChildNodes() ) { $children = array(); // since looping through a DOM being modified is a bad idea we prepare an array: foreach ( $domNode->childNodes as $child ) { $children[] = $child; } foreach ( $children as $child ) { if ( $child->nodeType === XML_TEXT_NODE ) { $oldText = $child->wholeText; if ( $isRegEx ) { $newText = preg_replace( $search, $replace, $oldText ); } else { $newText = str_replace( $search, $replace, $oldText ); } $newTextNode = $domNode->ownerDocument->createTextNode( $newText ); $domNode->replaceChild( $newTextNode, $child ); } else { adarelief_domTextReplace( $search, $replace, $child, $isRegEx ); } } } }