<?php

if (! $object->action_url && ! $object->notes_url) {
    return;
}

$links = array();
$linkText = '<a href="%s" target="_blank">%s</a>';

if ($object->notes_url) {
    if (strpos($object->notes_url, "' ") === false) {
        $links[] = sprintf($linkText, $this->resolveMacros($object->notes_url, $object), 'Notes');
    } else {
        // TODO: We should find out document what's going on here. Looks strange :p
        foreach(explode("' ", $object->notes_url) as $url) {
            $url = strpos($url, "'") === 0 ? substr($url, 1) : $url;
            $url = strrpos($url, "'") === strlen($url) - 1 ? substr($url, 0, strlen($url) - 1) : $url;
            $links[] = sprintf($linkText, $this->resolveMacros($url, $object), 'Notes');
        }
    }
}
if ($object->action_url) {
    if (strpos($object->action_url, "' ") === false) {
        $links[] = sprintf($linkText, $this->resolveMacros($object->action_url, $object), 'Action');
    } else {
        // TODO: We should find out document what's going on here. Looks strange :p
        foreach(explode("' ", $object->action_url) as $url) {
            $url = strpos($url, "'") === 0 ? substr($url, 1) : $url;
            $url = strrpos($url, "'") === strlen($url) - 1 ? substr($url, 0, strlen($url) - 1) : $url;
            $links[] = sprintf($linkText, $this->resolveMacros($url, $object), 'Action');
        }
    }
}

?>
<tr>
  <th>Foreign URLs</th>
  <td><?= implode("\n ", $links) . "\n" ?></td>
</tr>
