'.$string.''; $xml = simplexml_load_string($string); $list = $xml->xpath("//@href"); $urls = array(); foreach ($list as $l) { $arr = $l['href']; $urls[] = trim(str_replace('href=',"",str_replace('"',"",$arr->asXML()))); } return $urls; } //We modify the post finding all external urls and shortening them. Then we replace those urls with their respective short urls. function anveto_generateShortUrls($content) { $apikey = get_option('anveto-urlshorternerKey'); $shorteninternal = get_option('anveto-shortenInternalLinks'); $ignore = array("anve.to"); if ($shorteninternal != "internalLinks") { $domain_name = preg_replace('/^www\./', '', $_SERVER['SERVER_NAME']); $ignore[] = $domain_name; } if (strlen($apikey) > 1) { $urls = anveto_getUrls($content); foreach ($urls as $url) { $found = false; foreach ($ignore as $ign) { if (strpos($url, $ign) !== false) { $found = true; } } if (!$found) { $shorturl = anveto_shortenURL($url, $apikey); if (strlen($shorturl) > 1) { $content = str_replace("href=\"".$url, "href=\"".$shorturl, $content); } } } } return $content; } function anveto_shortenerMenu() { add_menu_page('Anve.to URL Shorterner', 'Anve.to', 'administrator', __FILE__, 'anveto_settingsPage', plugins_url('/images/icon.png', __FILE__)); add_action('admin_init', 'Anveto_registerSettings'); } function Anveto_registerSettings() { register_setting('anveto-settingsGroup', 'anveto-urlshorternerKey'); register_setting('anveto-settingsGroup', 'anveto-shortenInternalLinks'); } function anveto_settingsPage() { ?>
This plugin will automatically create short urls for all of your outgoing links when you create or edit a post. If you have an older post that you would like to shorten your links for then simply edit the post and it should update the links.