Skip to content

Instantly share code, notes, and snippets.

@hugowetterberg
Created December 3, 2009 11:15
Show Gist options
  • Save hugowetterberg/248076 to your computer and use it in GitHub Desktop.
Save hugowetterberg/248076 to your computer and use it in GitHub Desktop.
Template for local tasks that preserves destination
<?php
$match = array();
if (preg_match('/<a\shref="([^"]+)"(\s([a-z]+)="([^"]+)")?>([^<]+)<\/a>/', $link, $match)) {
$parts = parse_url($match[1]);
$path = trim($parts['path'], '/');
$opt = array();
if (!empty($_GET['destination'])) {
$opt['query']['destination'] = $_GET['destination'];
}
if (!empty($match[3])) {
$opt['attributes'][$match[3]] = $match[4];
}
$link = l($match[5], $path, $opt);
}
print '<li '. ($active ? 'class="active" ' : '') .'>'. $link ."</li>\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment