baseURL = $ff->cli ? $ff->MTrackCLI['baseURL'] : $ff->page->baseURL;
}
/**
* opts
* [display] = text to display
*
*/
function ticket($no, $extras=array())
{
if ($no instanceof DB_DataObject) {
$tkt = $no;
} else if (is_string($no) || is_int($no)) {
static $cache = array();
if ($no[0] == '#') {
$no = substr($no, 1);
}
if (!isset($cache[$no])) {
$tkt = DB_DataOBject::Factory('mtrack_ticket');
$tkt->get($no);
$cache[$no] = $tkt;
} else {
$tkt = $cache[$no];
}
} else {
// FIXME: hinted data from reports
$tkt = new stdClass;
$tkt->id = $no['ticket'];
$tkt->summary = $no['summary'];
$tkt->status = '';
if (isset($no['state'])) {
$tkt->status = $no['state'];
} elseif (isset($no['status'])) {
$tkt->status = $no['status'];
} elseif (isset($no['__status__'])) {
$tkt->status = $no['__status__'];
}
}
if ($tkt == NULL) {
$tkt = new stdClass;
$tkt->id = $no;
$tkt->summary = 'No such ticket';
$tkt->status = 'No such ticket';
}
$html = "id;
if (isset($extras['#'])) {
$anchor = '#' . $extras['#'];
} else {
$anchor = '';
}
$html .= "' href=\"{$this->baseURL}/Ticket/$ident$anchor\">";
if (isset($extras['display'])) {
$html .= htmlspecialchars($extras['display']);
} else {
$html .= '#' . htmlspecialchars($ident);
}
$html .= "";
return $html;
}
function milestone( $id, $label = '')
{
// silly but we assume target is urlencoded???...
$ms = DB_DataObjecT::factory('mtrack_milestone');
if (empty($label)) {
if (empty($id) || !$ms->get($id)) {
return '???';
}
} else {
$ms->id = $id;
$ms->name = $label;
}
return ''.
htmlspecialchars(urldecode($ms->name)) .
'';
}
function help($target, $label, $anchor = '')
{
// escape anchor???
$target .= !empty($anchor) ? "#$anchor" : '';
return '' . htmlspecialchars($label) . '';
}
function username($target, $opts=array())
{
if (is_object($target)) {
$person = $target;
$target = $person->id;
} else {
$person = DB_DataObject::factory('Person');
$person->get($target);
}
if (is_string($opts)) {
parse_str($opts, $opts);
}
//print_r($opts);
//print_R($person);
if (!$person->id) {
// we did not find the ysers...
// we currently ignore all the formating....
return '' .
htmlspecialchars($target).
'';
}
/* WHY?
if (!ctype_alnum($username)) {
$target = "{$ABSWEB}user.php?user=" . urlencode($username);
if (isset($opts['edit'])) {
$target .= '&edit=1';
}
}
*/
$open_a =
'';
$dispname = $person->name;
//$dispname = preg_match("/^([^+]*)(\+.*)?@(.*)$/", $target) ? $target : $person->id;
$size = empty($opts['size']) ? 24 : (int) $opts['size'];
// var_dump($opts);
$ret =
(!empty($opts['no_image']) ? '' : ($open_a .
'
')) .
// at this point the old code tries to chop it...
// I'm not sure that is a great idea....
(!empty($opts['no_name']) ? '' : ($open_a . htmlspecialchars($dispname) . ''));
//var_dump( htmlspecialchars($ret));
return $ret;
}
function browse($target, $label)
{
return ''.
htmlspecialchars($label) .
'';
}
function log($target, $label) // what does this do...
{
return ''.
htmlspecialchars($label) .
'';
}
function branch($branch, $repo = null)
{
return "" . htmlspecialchars($branch) . "";
}
function changeset($cs, $repo = null)
{
$display = substr($cs, 0, 12);
if (empty($repo)) {
$repo = MTrack_Repo::loadByChangeSet($cs);
}
if (is_string($repo)) {
$repo = MTrack_Repo::loadByName($rep);
}
if (!is_a($repo, 'MTrack_Repo')) {
$repo = MTrack_Repo::defaultRepo();
}
$p = $repo->getBrowseRootName() . '/'. $cs;
return '[' . substr($cs, 0, 12) . ']';
}
function wiki($pagename, $extras = array())
{
return htmlspecialchars($pagename);
if ($pagename instanceof MTrack_Wiki_Item) {
$wiki = $pagename;
} else if (is_string($pagename)) {
$wiki = new MTrack_Wiki_Item($pagename);
if (!$wiki->file) {
$wiki = false;
}
} else {
// FIXME: hinted data from reports
throw new Exception("FIXME: wiki");
}
if ($wiki) {
$pagename = $wiki->pagename;
}
$pagename .= empty( $extras['#']) ? '' : '#' . $extras['#'];
return ''.
htmlspecialchars(empty($extras['display']) ? $pagename : $extras['display']) .
'';
}
// all these are prtty much the same..
function query($target, $label)
{
return ''.
htmlspecialchars($label) .
'';
}
function report($target, $label)
{
return ''.
htmlspecialchars($label) .
'';
}
// technically not a link....
function date($tstring, $show_full = false)
{
/* database time is always relative to UTC */
$d = date_create($tstring, new DateTimeZone('UTC'));
if (!is_object($d)) {
throw new Exception("could not represent $tstring as a datetime object");
}
$iso8601 = $d->format(DateTime::W3C);
/* but we want to render relative to user prefs */
date_timezone_set($d, new DateTimeZone(date_default_timezone_get()));
$full = $d->format('D, M d Y H:i');
if (!$show_full) {
return "$full";
}
return "$full $full";
}
}