Version Description
- Features: opening in a new window, set link icon, set "external", set "nofollow", set css-class
- Replaces external links by clean XHTML tags
- Internalization implemented (no language files yet)
=
Download this release
Release Info
| Developer | freelancephp |
| Plugin | |
| Version | 0.10 |
| Comparing to | |
| See all releases | |
Version 0.10
- images/external-1.png +0 -0
- images/external-10.png +0 -0
- images/external-11.png +0 -0
- images/external-2.png +0 -0
- images/external-3.png +0 -0
- images/external-4.png +0 -0
- images/external-5.png +0 -0
- images/external-6.png +0 -0
- images/external-7.png +0 -0
- images/external-8.png +0 -0
- images/external-9.png +0 -0
- images/icon.png +0 -0
- images/link-icon-example.png +0 -0
- js/external-links.js +31 -0
- readme.txt +46 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- wp-external-links.php +359 -0
images/external-1.png
ADDED
|
Binary file
|
images/external-10.png
ADDED
|
Binary file
|
images/external-11.png
ADDED
|
Binary file
|
images/external-2.png
ADDED
|
Binary file
|
images/external-3.png
ADDED
|
Binary file
|
images/external-4.png
ADDED
|
Binary file
|
images/external-5.png
ADDED
|
Binary file
|
images/external-6.png
ADDED
|
Binary file
|
images/external-7.png
ADDED
|
Binary file
|
images/external-8.png
ADDED
|
Binary file
|
images/external-9.png
ADDED
|
Binary file
|
images/icon.png
ADDED
|
Binary file
|
images/link-icon-example.png
ADDED
|
Binary file
|
js/external-links.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
| 1 |
+
// New Window Links Plugin
|
| 2 |
+
function setExternalLinks() {
|
| 3 |
+
var links = document.getElementsByTagName( 'a' ),
|
| 4 |
+
glob = window.globNewWindowLinks || {};
|
| 5 |
+
|
| 6 |
+
for ( var i = 0; i < links.length; i++ ){
|
| 7 |
+
var a = links[ i ],
|
| 8 |
+
href = a.href ? a.href.toLowerCase() : '',
|
| 9 |
+
rel = a.rel ? a.rel.toLowerCase() : '';
|
| 10 |
+
|
| 11 |
+
if ( a.href && ( rel.indexOf( 'external' ) > -1
|
| 12 |
+
|| ( href.indexOf( glob.baseUrl ) === -1 &&
|
| 13 |
+
( href.substr( 0, 7 ) == 'http://'
|
| 14 |
+
|| href.substr( 0, 8 ) == 'https://'
|
| 15 |
+
|| href.substr( 0, 6 ) == 'ftp://' ) ) ) ) {
|
| 16 |
+
|
| 17 |
+
// set target blank
|
| 18 |
+
a.target = '_blank';
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
if ( typeof jQuery == 'undefined' ) {
|
| 24 |
+
window.onload = function() {
|
| 25 |
+
setExternalLinks();
|
| 26 |
+
}
|
| 27 |
+
} else {
|
| 28 |
+
jQuery(function(){
|
| 29 |
+
setExternalLinks();
|
| 30 |
+
});
|
| 31 |
+
}
|
readme.txt
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
| 1 |
+
=== WP External Links ===
|
| 2 |
+
Contributors: freelancephp
|
| 3 |
+
Tags: links, external, new window, icon, target, _blank, _new, rel, nofollow, javascript, xhtml strict
|
| 4 |
+
Requires at least: 2.7.0
|
| 5 |
+
Tested up to: 3.1.0
|
| 6 |
+
Stable tag: 0.10
|
| 7 |
+
|
| 8 |
+
Manage the external links on your site: opening in a new window, set link icon, set "external", set "nofollow", set css-class.
|
| 9 |
+
|
| 10 |
+
== Description ==
|
| 11 |
+
|
| 12 |
+
Manage the external links on your site.
|
| 13 |
+
|
| 14 |
+
= Features =
|
| 15 |
+
* Opening external links in a new window
|
| 16 |
+
* Adding "external" and/or "nofollow" value to rel-attribute
|
| 17 |
+
* Choose an icon for external links
|
| 18 |
+
* Add a css Class-name
|
| 19 |
+
* Unobtrusive JavaScript method wich is XHTML Strict compliant
|
| 20 |
+
* Supports PHP4.3+ and up to latest WP version
|
| 21 |
+
|
| 22 |
+
Also see info at [FreelancePHP.net](http://www.freelancephp.net/wp-external-links-plugin)
|
| 23 |
+
|
| 24 |
+
== Installation ==
|
| 25 |
+
|
| 26 |
+
1. Upload `new-window-links.zip` to the `/wp-content/plugins/` directory or add the plugin with 'Add Plugins' in the admin menu
|
| 27 |
+
1. Be sure the plugin is activated in the Plugin-list
|
| 28 |
+
|
| 29 |
+
== Frequently Asked Questions ==
|
| 30 |
+
|
| 31 |
+
[Do you have a question? Please ask me](http://www.freelancephp.net/contact/)
|
| 32 |
+
|
| 33 |
+
== Screenshots ==
|
| 34 |
+
|
| 35 |
+
1. Admin Settings Page
|
| 36 |
+
1. Icon on the Site
|
| 37 |
+
|
| 38 |
+
== Changelog ==
|
| 39 |
+
|
| 40 |
+
= 0.10 =
|
| 41 |
+
* Features: opening in a new window, set link icon, set "external", set "nofollow", set css-class
|
| 42 |
+
* Replaces external links by clean XHTML <a> tags
|
| 43 |
+
* Internalization implemented (no language files yet)
|
| 44 |
+
|
| 45 |
+
== Other notes ==
|
| 46 |
+
* Title icon on Admin Options Page was made by [FatCow Web Hosting](http://www.fatcow.com/) taken form [iconfinder](http://findicons.com/icon/164579/link_go?id=427009)
|
screenshot-1.png
ADDED
|
Binary file
|
screenshot-2.png
ADDED
|
Binary file
|
wp-external-links.php
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
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â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
|
|
Â
|
| 1 |
+
<?php
|
| 2 |
+
/*
|
| 3 |
+
Plugin Name: WP External Links
|
| 4 |
+
Plugin URI: http://www.freelancephp.net/
|
| 5 |
+
Description: Manage the external links on your site: opening in a new window, set link icon, set "external", set "nofollow", set css-class.
|
| 6 |
+
Author: Victor Villaverde Laan
|
| 7 |
+
Version: 0.10
|
| 8 |
+
Author URI: http://www.freelancephp.net
|
| 9 |
+
License: Dual licensed under the MIT and GPL licenses
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Class WP_External_Links
|
| 14 |
+
* @category WordPress Plugins
|
| 15 |
+
*/
|
| 16 |
+
class WP_External_Links {
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Used as prefix for options entry and could be used as text domain (for translations)
|
| 20 |
+
* @var string
|
| 21 |
+
*/
|
| 22 |
+
var $domain = 'WP_External_Links';
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* @var string
|
| 26 |
+
*/
|
| 27 |
+
var $options_name = 'WP_External_Links_options';
|
| 28 |
+
|
| 29 |
+
/**
|
| 30 |
+
* @var array
|
| 31 |
+
*/
|
| 32 |
+
var $options = array(
|
| 33 |
+
'target_blank' => 1,
|
| 34 |
+
'external' => TRUE,
|
| 35 |
+
'nofollow' => TRUE,
|
| 36 |
+
'icon' => 1,
|
| 37 |
+
'class_name' => 'external-link',
|
| 38 |
+
);
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* PHP4 constructor
|
| 42 |
+
*/
|
| 43 |
+
function WP_External_Links() {
|
| 44 |
+
$this->__construct();
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* PHP5 constructor
|
| 49 |
+
*/
|
| 50 |
+
function __construct() {
|
| 51 |
+
// set option values
|
| 52 |
+
$this->_set_options();
|
| 53 |
+
|
| 54 |
+
// load text domain for translations
|
| 55 |
+
load_plugin_textdomain( $this->domain, dirname( __FILE__ ) . '/lang/', basename( dirname(__FILE__) ) . '/lang/' );
|
| 56 |
+
|
| 57 |
+
// add actions
|
| 58 |
+
add_action( 'init', array( $this, 'init' ), 10000 );
|
| 59 |
+
add_action( 'admin_init', array( $this, 'admin_init' ), 10000 );
|
| 60 |
+
add_action( 'admin_menu', array( $this, 'admin_menu' ), 10000 );
|
| 61 |
+
|
| 62 |
+
// add filters
|
| 63 |
+
add_action( 'wp', array( $this, 'wp' ), 10000 );
|
| 64 |
+
|
| 65 |
+
// set uninstall hook
|
| 66 |
+
if ( function_exists( 'register_deactivation_hook' ) )
|
| 67 |
+
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ));
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Callback wp
|
| 72 |
+
*/
|
| 73 |
+
function wp() {
|
| 74 |
+
if ( ! is_admin() && ! is_feed() ) {
|
| 75 |
+
ob_start( array( $this, 'filter_content' ) );
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Callback admin_menu
|
| 81 |
+
*/
|
| 82 |
+
function admin_menu() {
|
| 83 |
+
if ( function_exists( 'add_options_page' ) AND current_user_can( 'manage_options' ) ) {
|
| 84 |
+
// add options page
|
| 85 |
+
$page = add_options_page( 'External Links', 'External Links',
|
| 86 |
+
'manage_options', __FILE__, array( $this, 'options_page' ) );
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Callback init
|
| 92 |
+
*/
|
| 93 |
+
function init() {
|
| 94 |
+
if ( ! is_admin() ) {
|
| 95 |
+
// add wp_head for setting js vars and css style
|
| 96 |
+
add_action( 'wp_head', array( $this, 'wp_head' ) );
|
| 97 |
+
|
| 98 |
+
// set js file
|
| 99 |
+
if ( $this->options[ 'target_blank' ] == 2 ) {
|
| 100 |
+
wp_enqueue_script( 'external-links', plugins_url( 'js/external-links.js', __FILE__ ), array( 'jquery' ) );
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* Callback wp_head
|
| 107 |
+
*/
|
| 108 |
+
function wp_head() {
|
| 109 |
+
?>
|
| 110 |
+
<?php if ( $this->options[ 'target_blank' ] == 2 ): ?>
|
| 111 |
+
<!-- JS External Links Plugin -->
|
| 112 |
+
<script language="javascript">
|
| 113 |
+
/* <![CDATA[ */
|
| 114 |
+
var globNewWindowLinks = {
|
| 115 |
+
baseUrl: '<?php echo get_bloginfo( 'url' ) ?>',
|
| 116 |
+
class_name: '<?php echo $this->options[ 'class_name' ] ?>'
|
| 117 |
+
};
|
| 118 |
+
/* ]]> */
|
| 119 |
+
</script>
|
| 120 |
+
<!-- /JS External Links Plugin -->
|
| 121 |
+
<?php endif; ?>
|
| 122 |
+
<?php if ( $this->options[ 'class_name' ] AND $this->options[ 'icon' ] > 0 ): ?>
|
| 123 |
+
<!-- Style External Links Plugin -->
|
| 124 |
+
<style type="text/css">
|
| 125 |
+
.<?php echo $this->options[ 'class_name' ] ?> {
|
| 126 |
+
background: url( <?php echo plugins_url( 'images/external-'. $this->options[ 'icon' ] .'.png', __FILE__ ) ?> ) no-repeat right center;
|
| 127 |
+
padding-right: 15px;
|
| 128 |
+
};
|
| 129 |
+
</style>
|
| 130 |
+
<!-- /Style External Links Plugin -->
|
| 131 |
+
<?php endif; ?>
|
| 132 |
+
<?php
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/**
|
| 136 |
+
* Filter content
|
| 137 |
+
*/
|
| 138 |
+
function filter_content( $content ) {
|
| 139 |
+
$a_pattern = '/<[aA](.*?)>(.*?)<\/[aA][\s+]*>/i';
|
| 140 |
+
return preg_replace_callback( $a_pattern, array( $this, 'parse_link' ), $content );
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
function parse_link( $match ) {
|
| 144 |
+
$attrs = shortcode_parse_atts( $match[ 1 ] );
|
| 145 |
+
|
| 146 |
+
$href_tolower = strtolower( $attrs[ 'href' ] );
|
| 147 |
+
$rel_tolower = ( isset( $attrs[ 'rel' ] ) ) ? strtolower( $attrs[ 'rel' ] ) : '';
|
| 148 |
+
|
| 149 |
+
// check url
|
| 150 |
+
if ( isset( $attrs[ 'href' ] ) AND ( strpos( $rel_tolower, 'external' ) !== FALSE
|
| 151 |
+
OR ( strpos( $href_tolower, strtolower( get_bloginfo( 'url' ) ) ) === FALSE )
|
| 152 |
+
AND ( substr( $href_tolower, 0, 7 ) == 'http://'
|
| 153 |
+
OR substr( $href_tolower, 0, 8 ) == 'https://'
|
| 154 |
+
OR substr( $href_tolower, 0, 6 ) == 'ftp://' ) ) ){
|
| 155 |
+
// set rel="external" (when not already set)
|
| 156 |
+
if ( $this->options[ 'external' ] AND strpos( $rel_tolower, 'external' ) === FALSE ){
|
| 157 |
+
$attrs[ 'rel' ] = ( empty( $attrs[ 'rel' ] ) )
|
| 158 |
+
? 'external'
|
| 159 |
+
: $attrs[ 'rel' ] .' external';
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
// set rel="nofollow" when doesn't have "follow" (or already "nofollow")
|
| 163 |
+
if ( $this->options[ 'nofollow' ] AND strpos( $rel_tolower, 'follow' ) === FALSE ){
|
| 164 |
+
$attrs[ 'rel' ] = ( empty( $attrs[ 'rel' ] ) )
|
| 165 |
+
? 'nofollow'
|
| 166 |
+
: $attrs[ 'rel' ] .' nofollow';
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
// set class
|
| 170 |
+
if ( ! empty( $this->options[ 'class_name' ] ) AND ( empty( $attrs[ 'class' ] ) OR strpos( $attrs[ 'class' ], $this->options[ 'class_name' ] ) === FALSE ) ){
|
| 171 |
+
$attrs[ 'class' ] = ( empty( $attrs[ 'class' ] ) )
|
| 172 |
+
? $this->options[ 'class_name' ]
|
| 173 |
+
: $attrs[ 'class' ] .' '. $this->options[ 'class_name' ];
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
// set target="_blank"
|
| 177 |
+
if ( $this->options[ 'target_blank' ] == 1 )
|
| 178 |
+
$attrs[ 'target' ] = '_blank';
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
// create element code
|
| 183 |
+
$link = '<a ';
|
| 184 |
+
|
| 185 |
+
foreach ( $attrs AS $key => $value )
|
| 186 |
+
$link .= $key .'="'. $value .'" ';
|
| 187 |
+
|
| 188 |
+
// remove last space
|
| 189 |
+
$link = substr( $link, 0, -1 );
|
| 190 |
+
|
| 191 |
+
$link .= '>'. $match[ 2 ] .'</a>';
|
| 192 |
+
|
| 193 |
+
return $link;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
/**
|
| 197 |
+
* Callback admin_init
|
| 198 |
+
*/
|
| 199 |
+
function admin_init() {
|
| 200 |
+
// register settings
|
| 201 |
+
register_setting( $this->domain, $this->options_name );
|
| 202 |
+
|
| 203 |
+
// set dashboard postbox
|
| 204 |
+
wp_admin_css( 'dashboard' );
|
| 205 |
+
wp_enqueue_script( 'dashboard' );
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
/**
|
| 209 |
+
* Admin options page
|
| 210 |
+
*/
|
| 211 |
+
function options_page() {
|
| 212 |
+
?>
|
| 213 |
+
<div class="wrap">
|
| 214 |
+
<div class="icon32" id="icon-options-custom" style="background:url( <?php echo plugins_url( 'images/icon.png', __FILE__ ) ?> ) no-repeat 50% 50%"><br></div>
|
| 215 |
+
<h2>External Links</h2>
|
| 216 |
+
|
| 217 |
+
<form method="post" action="options.php">
|
| 218 |
+
<?php
|
| 219 |
+
settings_fields( $this->domain );
|
| 220 |
+
$this->_set_options();
|
| 221 |
+
$options = $this->options;
|
| 222 |
+
?>
|
| 223 |
+
|
| 224 |
+
<div class="postbox-container metabox-holder meta-box-sortables" style="width:69%;">
|
| 225 |
+
<div style="margin:0 5px;">
|
| 226 |
+
<div class="postbox">
|
| 227 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
|
| 228 |
+
<h3 class="hndle"><?php _e( 'Settings' ) ?></h3>
|
| 229 |
+
<div class="inside">
|
| 230 |
+
<fieldset class="options">
|
| 231 |
+
<h4><?php _e( 'External links', $this->domain ) ?></h4>
|
| 232 |
+
<table class="form-table">
|
| 233 |
+
<tr>
|
| 234 |
+
<th><?php _e( 'Open in new window', $this->domain ) ?></th>
|
| 235 |
+
<td><label><input type="radio" name="<?php echo $this->options_name ?>[target_blank]" value="0" <?php checked('0', (int) $options['target_blank']); ?> />
|
| 236 |
+
<span><?php _e( 'No, open external links in same window', $this->domain ) ?></span></label>
|
| 237 |
+
<br/><label><input type="radio" name="<?php echo $this->options_name ?>[target_blank]" value="1" <?php checked('1', (int) $options['target_blank']); ?> />
|
| 238 |
+
<span><?php _e( 'Yes, add <code>target="_blank"</code> to external links', $this->domain ) ?></span></label>
|
| 239 |
+
<br/><label><input type="radio" name="<?php echo $this->options_name ?>[target_blank]" value="2" <?php checked('2', (int) $options['target_blank']); ?> />
|
| 240 |
+
<span><?php _e( 'Yes, by using JavaScript (unobtrusive and XHTML Strict compliant)', $this->domain ) ?></span></label>
|
| 241 |
+
</td>
|
| 242 |
+
</tr>
|
| 243 |
+
<tr>
|
| 244 |
+
<th><?php _e( 'Add "external"', $this->domain ) ?></th>
|
| 245 |
+
<td><label><input type="checkbox" id="<?php echo $this->options_name ?>[external]" name="<?php echo $this->options_name ?>[external]" value="1" <?php checked('1', (int) $options['external']); ?> />
|
| 246 |
+
<span><?php _e( 'Automatically add "external" to the rel-attribute of external links <code>rel="external"</code>', $this->domain ) ?></span></label>
|
| 247 |
+
</td>
|
| 248 |
+
</tr>
|
| 249 |
+
<tr>
|
| 250 |
+
<th><?php _e( 'Add "nofollow"', $this->domain ) ?></th>
|
| 251 |
+
<td><label><input type="checkbox" id="<?php echo $this->options_name ?>[nofollow]" name="<?php echo $this->options_name ?>[nofollow]" value="1" <?php checked('1', (int) $options['nofollow']); ?> />
|
| 252 |
+
<span><?php _e( 'Automatically add "nofollow" to the rel-attribute of external links <code>rel="nofollow"</code> (except to links that already contain "follow")', $this->domain ) ?></span></label>
|
| 253 |
+
</td>
|
| 254 |
+
</tr>
|
| 255 |
+
</table>
|
| 256 |
+
|
| 257 |
+
<h4><?php _e( 'Styling', $this->domain ) ?></h4>
|
| 258 |
+
<table class="form-table">
|
| 259 |
+
<tr>
|
| 260 |
+
<th><?php _e( 'Classname', $this->domain ) ?></th>
|
| 261 |
+
<td><label><input type="text" id="<?php echo $this->options_name ?>[class_name]" name="<?php echo $this->options_name ?>[class_name]" value="<?php echo $options['class_name']; ?>" />
|
| 262 |
+
<span><?php _e( 'Add this classname to external links (or leave blank)', $this->domain ) ?></span></label></td>
|
| 263 |
+
</tr>
|
| 264 |
+
<tr>
|
| 265 |
+
<th><?php _e( 'Show icon', $this->domain ) ?>
|
| 266 |
+
</th>
|
| 267 |
+
<td>
|
| 268 |
+
<div style="width:74%;float:right"><?php _e( 'Icon Example:', $this->domain ) ?>
|
| 269 |
+
<br/>
|
| 270 |
+
<br/><img src="<?php echo plugins_url( 'images/link-icon-example.png', __FILE__ ) ?>" />
|
| 271 |
+
<br/>
|
| 272 |
+
<br/><span class="description"><?php _e( 'Note: icon only works if classname is given', $this->domain ) ?></span>
|
| 273 |
+
</div>
|
| 274 |
+
<div style="width:25%;float:left">
|
| 275 |
+
<label><input type="radio" name="<?php echo $this->options_name ?>[icon]" value="0" <?php checked('0', (int) $options['icon']); ?> />
|
| 276 |
+
<span><?php _e( 'No icon', $this->domain ) ?></span></label>
|
| 277 |
+
<?php for ( $x = 1; $x <= 11; $x++ ): ?>
|
| 278 |
+
<br/><label><input type="radio" name="<?php echo $this->options_name ?>[icon]" value="<?php echo $x ?>" <?php checked( $x, (int) $options['icon'] ); ?> />
|
| 279 |
+
<img src="<?php echo plugins_url( 'images/external-'. $x .'.png', __FILE__ ) ?>" /></label>
|
| 280 |
+
<?php endfor; ?>
|
| 281 |
+
</div>
|
| 282 |
+
</td>
|
| 283 |
+
</tr>
|
| 284 |
+
</table>
|
| 285 |
+
</fieldset>
|
| 286 |
+
<p class="submit">
|
| 287 |
+
<input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
|
| 288 |
+
</p>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
</div>
|
| 293 |
+
|
| 294 |
+
<div class="postbox-container metabox-holder meta-box-sortables" style="width:29%;">
|
| 295 |
+
<div style="margin:0 5px;">
|
| 296 |
+
<div class="postbox">
|
| 297 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
|
| 298 |
+
<h3 class="hndle"><?php _e( 'About' ) ?> WP External Links</h3>
|
| 299 |
+
<div class="inside">
|
| 300 |
+
<ul>
|
| 301 |
+
<li><a href="<?php echo plugins_url( 'readme.txt', __FILE__ ) ?>" target="_blank">readme.txt</a></li>
|
| 302 |
+
<li><a href="http://www.freelancephp.net/wp-external-links-plugin/" target="_blank"><?php _e( 'Plugin page on ', $this->domain ) ?> FreelancePHP.net</a></li>
|
| 303 |
+
<li><a href="http://wordpress.org/extend/plugins/wp-external-links/" target="_blank"><?php _e( 'Plugin page on ', $this->domain ) ?> WordPress.org</a></li>
|
| 304 |
+
<li><a href="http://www.freelancephp.net/contact/" target="_blank"><?php _e( 'Contact the author', $this->domain ) ?></a></li>
|
| 305 |
+
</ul>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
|
| 309 |
+
<div class="postbox">
|
| 310 |
+
<div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
|
| 311 |
+
<h3 class="hndle"><?php _e( 'Other Plugins', $this->domain ) ?></h3>
|
| 312 |
+
<div class="inside">
|
| 313 |
+
<ul>
|
| 314 |
+
<li><a href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/" target="_blank">WP Email Encoder Bundle</a></li>
|
| 315 |
+
</ul>
|
| 316 |
+
</div>
|
| 317 |
+
</div>
|
| 318 |
+
</div>
|
| 319 |
+
</div>
|
| 320 |
+
</form>
|
| 321 |
+
<div class="clear"></div>
|
| 322 |
+
</div>
|
| 323 |
+
<?php
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
/**
|
| 327 |
+
* Deactivation plugin method
|
| 328 |
+
*/
|
| 329 |
+
function deactivation() {
|
| 330 |
+
delete_option( $this->options_name );
|
| 331 |
+
unregister_setting( $this->domain, $this->options_name );
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
/**
|
| 335 |
+
* Set options from save values or defaults
|
| 336 |
+
*/
|
| 337 |
+
function _set_options() {
|
| 338 |
+
// set options
|
| 339 |
+
$saved_options = get_option( $this->options_name );
|
| 340 |
+
|
| 341 |
+
if ( ! empty( $saved_options ) ) {
|
| 342 |
+
// set saved option values
|
| 343 |
+
$this->options['target_blank'] = $saved_options['target_blank'];
|
| 344 |
+
$this->options['external'] = ! empty( $saved_options['external'] );
|
| 345 |
+
$this->options['nofollow'] = ! empty( $saved_options['nofollow'] );
|
| 346 |
+
$this->options['icon'] = $saved_options['icon'];
|
| 347 |
+
$this->options['class_name'] = $saved_options['class_name'];
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
|
| 351 |
+
} // end class WP_External_Links
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
/**
|
| 355 |
+
* Create WP_External_Links instance
|
| 356 |
+
*/
|
| 357 |
+
$WP_External_Links = new WP_External_Links;
|
| 358 |
+
|
| 359 |
+
?>
|
