4 * This handles link creation for the wiki..
6 * it get's registered by MTrackWeb as the link handler..
9 //require_once 'MTrack/Interface/WikiLinkHandler.php';
12 class MTrackWeb_LinkHandler //implements MTrack_Interface_WikiLinkHandler
14 function MTrackWeb_LinkHandler()
16 $ff = HTML_FlexyFramework::get();
18 $this->baseURL = $ff->cli ? $ff->MTrackCLI['baseURL'] : $ff->page->baseURL;
25 * [display] = text to display
28 function ticket($no, $extras=array())
31 if ($no instanceof DB_DataObject) {
33 } else if (is_string($no) || is_int($no)) {
34 static $cache = array();
40 if (!isset($cache[$no])) {
41 $tkt = DB_DataOBject::Factory('mtrack_ticket');
49 // FIXME: hinted data from reports
51 $tkt->id = $no['ticket'];
52 $tkt->summary = $no['summary'];
55 if (isset($no['state'])) {
56 $tkt->status = $no['state'];
57 } elseif (isset($no['status'])) {
58 $tkt->status = $no['status'];
59 } elseif (isset($no['__status__'])) {
60 $tkt->status = $no['__status__'];
67 $tkt->summary = 'No such ticket';
68 $tkt->status = 'No such ticket';
70 $html = "<a class='ticketlink";
71 if ($tkt->status == 'closed') {
72 $html .= ' completed';
77 if (isset($extras['#'])) {
78 $anchor = '#' . $extras['#'];
82 $html .= "' href=\"{$this->baseURL}/Ticket/$ident$anchor\">";
83 if (isset($extras['display'])) {
84 $html .= htmlspecialchars($extras['display']);
86 $html .= '#' . htmlspecialchars($ident);
92 function milestone( $id, $label = '')
94 // silly but we assume target is urlencoded???...
95 $ms = DB_DataObjecT::factory('mtrack_milestone');
97 if (empty($id) || !$ms->get($id)) {
106 return '<span class="milestone' .
107 (($ms->deleted || $ms->completed) ? ' completed' : '') .
108 '"><a href="'. $this->baseURL . '/Milestone/'. $ms->id.'">'.
109 htmlspecialchars(urldecode($ms->name)) .
113 function help($target, $label, $anchor = '')
117 $target .= !empty($anchor) ? "#$anchor" : '';
119 return '<a class="wikilink"
120 href="'.$this->baseURL . '/Help/' . htmlspecialchars($target) .
121 '">' . htmlspecialchars($label) . '</a>';
124 function username($target, $opts=array())
126 if (is_object($target)) {
128 $target = $person->id;
130 $person = DB_DataObject::factory('core_person');
131 $person->get($target);
134 if (is_string($opts)) {
135 parse_str($opts, $opts);
141 // we did not find the ysers...
142 // we currently ignore all the formating....
144 href="'. $this->baseURL .'/User/'. urlencode($target) . '" class="userlink">' .
145 htmlspecialchars($target).
149 if (!ctype_alnum($username)) {
150 $target = "{$ABSWEB}user.php?user=" . urlencode($username);
151 if (isset($opts['edit'])) {
152 $target .= '&edit=1';
159 '<a title="' . htmlspecialchars($person->name) . '"
161 $this->baseURL .'/User/'.
162 urlencode($person->id) .
163 (empty($opts['edit']) ? '' : '?edit=1') .
166 (isset($opts['class']) ? ' ' . $opts['class'] : '') .
169 $dispname = $person->name;
170 //$dispname = preg_match("/^([^+]*)(\+.*)?@(.*)$/", $target) ? $target : $person->id;
173 $size = empty($opts['size']) ? 24 : (int) $opts['size'];
176 (!empty($opts['no_image']) ? '' : ($open_a .
177 '<img class="gravatar"
178 width="' . $size . '" height="' . $size . '"
179 src="' . $this->baseURL . '/Avatar.png?u=' .
180 urlencode($person->id) . '&s='. $size . '">
183 // at this point the old code tries to chop it...
184 // I'm not sure that is a great idea....
185 (!empty($opts['no_name']) ? '' : ($open_a . htmlspecialchars($dispname) . '</a>'));
186 //var_dump( htmlspecialchars($ret));
190 function browse($target, $label)
192 return '<a href="'. $this->baseURL . '/Browse/'. htmlspecialchars($target) .'">'.
193 htmlspecialchars($label) .
196 function log($target, $label) // what does this do...
198 return '<a href="'. $this->baseURL . '/Log/'. htmlspecialchars($target) .'">'.
199 htmlspecialchars($label) .
203 function branch($branch, $repo = null)
205 return "<span class='branchname'>" . htmlspecialchars($branch) . "</span>";
211 function changeset($cs, $repo = null)
213 $display = substr($cs, 0, 12);
215 $repo = MTrack_Repo::loadByChangeSet($cs);
217 if (is_string($repo)) {
218 $repo = MTrack_Repo::loadByName($rep);
220 if (!is_a($repo, 'MTrack_Repo')) {
221 $repo = MTrack_Repo::defaultRepo();
223 $p = $repo->getBrowseRootName() . '/'. $cs;
226 return '<a class="changesetlink"
227 href="'. $this->baseURL . '/Changeset/'. htmlspecialchars($p) .'">[' . substr($cs, 0, 12) . ']</a>';
231 function wiki($pagename, $extras = array())
233 return htmlspecialchars($pagename);
234 if ($pagename instanceof MTrack_Wiki_Item) {
236 } else if (is_string($pagename)) {
237 $wiki = new MTrack_Wiki_Item($pagename);
242 // FIXME: hinted data from reports
243 throw new Exception("FIXME: wiki");
247 $pagename = $wiki->pagename;
249 $pagename .= empty( $extras['#']) ? '' : '#' . $extras['#'];
251 return '<a class="wikilink"
252 href="'.$this->baseURL . '/Wiki/'. htmlspecialchars($pagename) .'">'.
253 htmlspecialchars(empty($extras['display']) ? $pagename : $extras['display']) .
257 // all these are prtty much the same..
258 function query($target, $label)
261 return '<a href="'. $this->baseURL . '/Query/'. htmlspecialchars($target) .'">'.
262 htmlspecialchars($label) .
265 function report($target, $label)
267 return '<a href="'. $this->baseURL . '/Report/'. htmlspecialchars($target) .'">'.
268 htmlspecialchars($label) .
272 // technically not a link....
273 function date($tstring, $show_full = false)
275 /* database time is always relative to UTC */
276 $d = date_create($tstring, new DateTimeZone('UTC'));
277 if (!is_object($d)) {
278 throw new Exception("could not represent $tstring as a datetime object");
280 $iso8601 = $d->format(DateTime::W3C);
281 /* but we want to render relative to user prefs */
282 date_timezone_set($d, new DateTimeZone(date_default_timezone_get()));
283 $full = $d->format('D, M d Y H:i');
286 return "<abbr title=\"$iso8601\" class='timeinterval'>$full</abbr>";
289 return "<abbr title='$iso8601' class='timeinterval'>$full</abbr> <span class='fulldate'>$full</span>";