rel="external". Todos los enlaces que tengan el atributo external se abrirán en una nueva ventana. Searches the text for links outside of the domain of the blog and open them in a new window but in a accesible way.
Author: Cristian Eslava
Version: 1.1
Author URI: http://ceslava.com/blog/
*/
/* Descripción:
El objetivo de este plugin es hacer que todos los enlaces externos (es decir, los enlaces a dominios diferentes al nuestro) en nuestras entradas
(también en los comentarios si así lo queremos) se abran automáticamente en una nueva ventana del navegador. También esta funcionalidad
se aplica a los enlaces a imágenes dentro de nuestro dominio.
Accesible _blank añade el atributo rel=”external” y mediante javascript se abren en nuevas ventanas o pestañas. Para avisar a los usuarios se añade el atributo title a los enlaces externos con el texto “(se abre en nueva ventana)“, si title ya tiene contenido se añade a él.
Cumple las Pautas de Accesibilidad al Contenido en la Web (WCAG).
English:
This plugin searches the text for links outside of the domain of the blog and open them in a new window but in a accesible way. It adds the attribute rel=”external” and by javascript those external links are open in a new window.
It stands for Web Content Accessibility Guidelines.
*/
/* Importante: Este plugin es una simple modificación de
External Links New Window
(http://javimoya.com/blog/2006/10/25/plugin-wordpress-enlaces-externos-en-una-nueva-ventana/),
que añade la funcionalidad de poder
abrir enlaces externos en una nueva ventana.
El problema es que no era accesible, ya que el atributo atributo _blank no cumple los estándares W3C.
*/
/* Copyright 2008 Cristian Eslava (contacto: http://ceslava.com/blog/contacto)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Pon a false esta variable si deseas que los enlaces a imágenes de tu dominio
// no se les añada el target="_blank" (por defecto se abriran en una nueva ventana)
$txfx_elnw_images_target_blank = true;
function wp_elnw_get_domain_name_from_uri($uri){
preg_match("/^(http:\/\/)?([^\/]+)/i", $uri, $matches);
$host = $matches[2];
preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
return $matches[0];
}
function wp_elnw_es_imagen($uri) {
$cadena=strtolower($uri);
if ((strpos($cadena, '.jpg') > 0) || (strpos($cadena, '.gif') > 0) || (strpos($cadena, '.png') > 0))
{
return true;
}
return false;
}
function wp_elnw_parse_external_links($matches){
global $txfx_elnw_images_target_blank;
/* para mejorar el rendimiento se puede cambiar
wp_elnw_get_domain_name_from_uri($_SERVER["HTTP_HOST"])
por directamente el nombre del dominio (ejemplo: "ceslava.com") (con las comillas incluidas) */
if (($txfx_elnw_images_target_blank && wp_elnw_es_imagen($matches[3])) || ( wp_elnw_get_domain_name_from_uri($matches[3]) != wp_elnw_get_domain_name_from_uri($_SERVER["HTTP_HOST"]) )) {
return '' . $matches[5] . '';
} else {
return '' . $matches[5] . '';
}
}
function wp_elnw_external_links($text) {
$pattern = '/(.*?)<\/a>/i';
$text = preg_replace_callback($pattern,'wp_elnw_parse_external_links',$text);
return $text;
}
// filters have high priority to make sure that any markup plugins like Textile or Markdown have already created the HTML links
add_filter('the_content', 'wp_elnw_external_links', 999);
add_filter('the_excerpt', 'wp_elnw_external_links', 999);
// Descomentar esta linea si quiere que el filtro tambien se aplique a los comentarios
//add_filter('comment_text', 'wp_elnw_external_links', 999);
### add content actions and filters
function accblank_js() {
echo "\n".''."\n";
echo ''."\n";
echo ''."\n";
}
add_action('wp_head', 'accblank_js');
?>