Suport » Probleme și soluții » Validare xhtml la un plugin

  • Bya

    (@bya)


    Am o problema sper ca puteti sa am ajutati.
    Am un plugin Target Blank In Posts And Comments nu este valid xhtml.
    Daca implementez target=”_blank” da eroare.
    Eu folosesc onclic=”target=’_blank'” este valid xhtml.

    Error:

    there is no attribute „target”
    <a target=”_blank” href=”http://www.

    Cum as putea implementa onclic=”target=’_blank'” in loc de target=”_blank” ?
    Din fisierul .php codul sursa ar fi

    <?php
    function wp_getdomain( $url) {
    	if(stristr($url,'http')!=$url)$url = 'http://'.$url;
    	if(substr_count($url,'/')<3)$url .= '/';
    	$domain = substr($url,strpos($url,'//')+2,(strpos($url,'/',10)-strpos($url,'//')-2));
    	$domain_elements = explode('.',$domain);
    	array_pop($domain_elements); //the last element is never the value you want
    	$domainname = array_pop($domain_elements);
    	if($domainname == "co") $domainname = array_pop($domain_elements);
    	$domain = strtolower(stristr($domain,$domainname));
    	return $domain;
    }
    global $wptb_my_domain;
    $wptb_my_domain = wp_getdomain(get_option('siteurl'));
    
    function wptb_get_domain_name_from_uri($uri){
    	preg_match("/^(http:\/\/)?([^\/]+)/i", $uri, $matches);
    	$host = $matches[2];
    	preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
    	return $matches[0];
    }
    
    function wptb_has_no_target_blank($text)
    {
    	if ( preg_match("/target=[\"\'].*?blank.*?[\"\']/i", $text ) )
    		return false;
    	else
    		return true;
    }
    
    function wptb_inarray($needle, $array, $searchKey = false)
    {
       if ($searchKey) {
           foreach ($array as $key => $value)
               if (stristr($key, $needle)) {return $key;}
           }
       else {
           foreach ($array as $value)
               if (stristr($value, $needle)) {return $value;}
           }
       return '';
    }
    
    function wptb_parse_target_blank($matches)
    {global $wptb_my_domain;
    	//add in next line's array sites that you think do not deserve credit because they don't give it to other sites.
    	if ( 	!wptb_inarray(wptb_get_domain_name_from_uri($matches[3]), array($wptb_my_domain)) &&
    		  wptb_has_no_target_blank( $matches[1] ) &&
    		  wptb_has_no_target_blank( $matches[4] ) )
    	{
    		return '<a target="_blank" href="' . $matches[2] . '//' . $matches[3] . '" ' . $matches[1] . $matches[4] . '>' . $matches[5] . '</a>';
    	}
    	else
    	{
    		// Do nothing
    		return '<a href="' . $matches[2] . '//' . $matches[3] . '" ' . $matches[1] . $matches[4] . '>' . $matches[5] . '</a>';
    	}
    }
    
    function wptb_target_blank($text)
    {
    	$pattern = '/<a (.*?)href=[\"\'](.*?)\/\/(.*?)[\"\'](.*?)>(.*?)<\/a>/i';
    	$text = preg_replace_callback($pattern,'wptb_parse_target_blank',$text);
    	return $text;
    }
    
    add_filter('the_content', 'wptb_target_blank', 999);
    add_filter('the_excerpt', 'wptb_target_blank', 999);
    
    // delete this one if you don't want it run on comments
    add_filter('comment_text', 'wptb_target_blank', 999);
    add_filter('get_comment_author_link', 'wptb_target_blank', 999);
    
    ?>
Vizualizare 1 răspuns (din 1 în total)
  • S

    (@sushkov)

    xhtml nu mai suportă atributul target, acest lucru se poate remedia cu un mic hack în JavaScript.

Vizualizare 1 răspuns (din 1 în total)
  • Subiectul „Validare xhtml la un plugin” este închis pentru răspunsuri noi.