/** * filter() * * @param array $anchor * @return array $anchor **/ function filter($anchor) { # disable in feeds if (is_feed()) { return $anchor; } # ignore local urls if (external_links::is_local_url($anchor['attr']['href'])) { return $anchor; } # no icons for images $is_image = (bool) preg_match("/^\\s*<\\s*img\\s.+?>\\s*\$/is", $anchor['body']); $o = external_links::get_options(); if (!in_array('external', $anchor['attr']['class'])) { $anchor['attr']['class'][] = 'external'; } if (!$is_image && $o['icon'] && !in_array('external_icon', $anchor['attr']['class']) && !in_array('no_icon', $anchor['attr']['class']) && !in_array('noicon', $anchor['attr']['class'])) { $anchor['attr']['class'][] = 'external_icon'; } if ($o['nofollow'] && !function_exists('strip_nofollow') && !in_array('nofollow', $anchor['attr']['rel']) && !in_array('follow', $anchor['attr']['rel'])) { $anchor['attr']['rel'][] = 'nofollow'; } if ($o['target'] && empty($anchor['attr']['target'])) { $anchor['attr']['target'] = '_blank'; } return $anchor; }
/** * edit_options() * * @return void **/ function edit_options() { echo '<div class="wrap">' . "\n" . '<form method="post" action="">'; wp_nonce_field('external_links'); $options = external_links::get_options(); if ($options['nofollow'] && function_exists('strip_nofollow')) { echo "<div class=\"error\">\n" . "<p>" . __('Note: Your rel=nofollow preferences is being ignored because the dofollow plugin is enabled on your site.', 'external-links') . "</p>\n" . "</div>\n"; } screen_icon(); echo '<h2>' . __('External Links Settings', 'external-links') . '</h2>' . "\n"; echo '<table class="form-table">' . "\n"; echo '<tr>' . "\n" . '<th scope="row">' . __('Apply Globally', 'external-links') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="global"' . checked($options['global'], true, false) . ' />' . ' ' . __('Apply these settings to all outbound links, including those in sidebars, rather than to those in posts and comments.', 'external-links') . '</label>' . '</td>' . "\n" . '</tr>' . "\n"; echo '<tr>' . "\n" . '<th scope="row">' . __('Add Icons', 'external-links') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="icon"' . checked($options['icon'], true, false) . ' />' . ' ' . __('Mark outbound links with an icon.', 'external-links') . '</label>' . '<br />' . "\n" . __('Note: You can override this behavior by adding a class="no_icon" to individual links.', 'external-links') . '</td>' . "\n" . '</tr>' . "\n"; echo '<tr>' . "\n" . '<th scope="row">' . __('Add No Follow', 'external-links') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="nofollow"' . checked($options['nofollow'], true, false) . ' />' . ' ' . __('Add a rel=nofollow attribute to outbound links.', 'external-links') . '</label>' . '<br />' . "\n" . __('Note: You can override this behavior by adding a rel="follow" to individual links.', 'external-links') . '</td>' . "\n" . '</tr>' . "\n"; echo '<tr>' . "\n" . '<th scope="row">' . __('Open in New Windows', 'external-links') . '</th>' . "\n" . '<td>' . '<label>' . '<input type="checkbox" name="target"' . checked($options['target'], true, false) . ' />' . ' ' . __('Open outbound links in new windows.', 'external-links') . '</label>' . '<br />' . "\n" . __('Note: Some usability experts discourage this, claiming that <a href="http://www.useit.com/alertbox/9605.html">this can damage your visitors\' trust</a> towards your site. Others highlight that computer-illiterate users do not always know how to use the back button, and encourage the practice for that reason.', 'external-links') . '</td>' . "\n" . '</tr>' . "\n"; echo '</table>' . "\n"; echo '<p class="submit">' . '<input type="submit"' . ' value="' . esc_attr(__('Save Changes', 'external-links')) . '"' . ' />' . '</p>' . "\n"; echo '</form>' . "\n" . '</div>' . "\n"; }