function rich_snippets_shorten_url in Rich Snippets 7
Returns a shortened URL.
Parameters
string $url: The URL of the matching document or webpage.
Return value
string The shortened URL
1 call to rich_snippets_shorten_url()
- rich_snippets_preprocess_search_result in ./
rich_snippets.module - Implements hook_preprocess_HOOK() for theme_search_result().
File
- ./
rich_snippets.module, line 355 - Overrides the standard search results templates and CSS to display results similar to major search engines.
Code
function rich_snippets_shorten_url($url) {
$url_parts = parse_url($url);
$shortened = $url_parts['host'];
if (isset($url_parts['port'])) {
$shortened .= ':' . $url_parts['port'];
}
// Shorten longer paths.
if (!empty($url_parts['path'])) {
if (drupal_strlen($url_parts['path']) > 32) {
$shortened .= '/';
$ellipsis = t('...');
// Break the path into parts and get the last item in the path.
$path_parts = explode('/', trim($url_parts['path'], '/'));
$last_part = end($path_parts);
// Replace first part of path with ellipsis.
if (count($path_parts) > 1) {
$shortened .= $ellipsis . '/';
}
$shortened .= $last_part;
}
else {
// Append the entire path, it's short enough.
$shortened .= $url_parts['path'];
}
}
return $shortened;
}