3 * every class extends this...
7 class MTrackWeb extends HTML_FlexyFramework_Page
9 var $template = 'wiki.html';
10 var $priorities = array();
11 var $severities = array();
12 var $link = false; // the link handler..
14 function hasPerm($what, $cando) {
15 // our whole perm logic sits in here....
17 // here's how it works
18 // a) anonymous users - not authenticated.
19 // - can see projects that are in *PUBLIC project "MTrack.Repos", "S"
20 // - can see bugs that are in *PUBLIC project "MTrack.Issue", "S"
21 // - can see bugs that are in *PUBLIC project "MTrack.Wiki", "S"
22 if (!$this->authUser) {
24 in_array( $what , array( 'MTrack.Repos', 'MTrack.Issue', 'MTrack.Wiki'))) {
25 return true; // not a diffinative answer...
30 return $this->authUser->hasPerm($what, $cando);
33 function projectPerm($project_id, $what, $cando)
38 $p = DB_DataObject::factory('Projects');
40 if (!$this->authUser) {
41 if ($p->code != '*PUBLIC') {
42 return false; // only public projects
47 // all permissions to view public stuff.
50 if (!$au->hasPerm($what, $cando)) {
54 if ($au->company()->comptype == 'OWNER') {
56 if ($au->hasPerm('Projects_All', $cando)) { // they can do what they like on all projects.
59 // return $p->hasPerm($what, $cando);
61 // otherwise they have to be a team member of that project.
63 $pd = DB_DataObject::factory('ProjectDirectory');
64 $pd->project_id = $project_id;
65 $pd->user_id = $this->authUser->id;
77 function getAuthUser()
79 $u = DB_DataObject::factory('Person');
83 return $u->getAuthUser();
86 * base getAuth allows everyone in..
91 $this->registerClasses(); // to be destroyed??
93 $ff = HTML_FlexyFramework::get();
98 // default timezone first..
99 $ff = HTML_FlexyFramework::get();
100 if (isset($ff->MTrack['timezone'])) {
101 date_default_timezone_set($ff->MTrack['timezone']);
104 //MTrackConfig::boot(); // eak.. .remove me...
106 $this->authUser = DB_DataObject::factory('Person')->getAuthUser();
107 if (!$this->authUser) {
108 return true; // we do allow people in this far..
112 // timezone setting... -- this may be a good addon to our core person class.
114 if (!empty($this->authUser->timezone)) {
115 date_default_timezone_set($this->authUser->timezone);
121 return true; // anyone at present..
123 function get($loc='')
127 die ("invalid location". htmlspecialchars($loc));
129 if (!$this->authUser) {
131 return HTML_FlexyFramework::run('Wiki');
133 return HTML_FlexyFramework::run('Wiki/Today');
138 header("Status: 404 Not Found");
143 function initOptions()
147 $q = MTrackDB::q('select priorityname, value from priorities');
149 foreach ($q->fetchAll() as $row) {
150 $this->priorities[$row[0]] = $row[1];
152 $q = MTrackDB::q('select sevname, ordinal from severities');
154 foreach ($q->fetchAll() as $row) {
155 $this->severities[$row[0]] = $row[1];
160 function registerClasses()
162 require_once 'MTrack/Wiki.php';
163 require_once 'MTrack/Wiki/Item.php';
164 require_once 'MTrack/Milestone.php';
165 //require_once 'MTrack/Report.php';
166 //require_once 'MTrack/SearchDB.php';
167 //require_once 'MTrack/Watch.php';
168 //require_once 'MTrack/CommitChecker.php';
171 require_once 'MTrackWeb/LinkHandler.php';
172 require_once 'MTrack/Wiki/HTMLFormatter.php';
174 $this->link = new MTrackWeb_LinkHandler();
175 MTrack_Wiki_HTMLFormatter::registerLinkHandler($this->link);
178 $r = DB_DataObject::factory('mtrack_repos');
179 $r->get('shortname', 'wiki'); // default wiki?
180 MTrack_Wiki_Item::$repo = $r->impl();
184 //MTrack_Wiki::register_macro('MilestoneSummary', array('MTrack_Milestone', 'macro_MilestoneSummary'));
185 // MTrack_Wiki::register_macro('BurnDown', array('MTrack_Milestone', 'macro_BurnDown'));
186 //MTrack_Wiki::register_macro('RunReport', array('MTrack_Report', 'macro_RunReport')); << fixme how are we to hanlde this..
187 //MTrack_Wiki::register_macro('TicketQuery', array('MTrack_Report', 'macro_TicketQuery'));
188 MTrack_Wiki::register_macro('IncludeWikiPage', array('MTrack_Wiki', 'macro_IncludeWiki'));
189 MTrack_Wiki::register_macro('IncludeHelpPage', array('MTrack_Wiki', 'macro_IncludeHelp'));
190 MTrack_Wiki::register_macro('Comment', array('MTrack_Wiki', 'macro_comment'));
191 MTrack_Wiki::register_processor('comment', array('MTrack_Wiki', 'processor_comment'));
192 MTrack_Wiki::register_processor('html', array('MTrack_Wiki', 'processor_html'));
193 MTrack_Wiki::register_processor('dataset', array('MTrack_Wiki', 'processor_dataset'));
196 //MTrackACL::registerAncestry('milestone', 'Roadmap');
197 //MTrackACL::registerAncestry('report', 'Reports');
198 //MTrackACL::registerAncestry('snippet', 'Snippets');
199 //MTrackACL::registerAncestry('repo', 'Browser');
200 //MTrackACL::registerAncestry('enum', 'Enumerations');
201 //MTrackACL::registerAncestry("component", 'Components');
202 //MTrackACL::registerAncestry("project", 'Projects');
203 //MTrackACL::registerAncestry("ticket", "Tickets");
204 //MTrackACL::registerAncestry('wiki', array('MTrack_Wiki_Item', '_get_parent_for_acl'));
206 //MTrackSearchDB::register_indexer('ticket', array('MTrackIssue', 'index_issue'));
207 //MTrackSearchDB::register_indexer('wiki', array('MTrack_Wiki_Item', 'index_item'));
211 //MTrackWatch::registerEventTypes('ticket', array( 'ticket' => 'Tickets' ));
212 //MTrackWatch::registerEventTypes('milestone', array( 'ticket' => 'Tickets', 'changeset' => 'Code changes' ));
213 //MTrackWatch::registerEventTypes('repo', array( 'ticket' => 'Tickets', 'changeset' => 'Code changes' ));
215 // should this get registered here??
216 //MTrackCommitChecker::addCheck('Wiki');
225 /// FIXME - we should allow upload of a favion...
226 $ff = HTML_FlexyFramework::get();
232 /* renders the attachment list for a given object */
233 // was Attachments::render
234 // move it to MTrackWebAttachemnt...
236 function attachmentsToHtml($object)
238 if (is_object($object)) {
239 $object = $object->toIdString(); // eg. ticket:1
241 $atts = MTrackDB::q('
242 select * from attachments
243 left join changes on (attachments.cid = changes.cid)
244 where attachments.object = ? order by changedate, filename',
245 $object)->fetchAll(PDO::FETCH_ASSOC);
247 if (count($atts) == 0) return '';
251 $html = "<div class='attachment-list'><b>Attachments</b><ul>";
252 foreach ($atts as $row) {
253 $url = "{$this->baseURL}/Attachment/$object/". $row['cid'] . '/' . $row['filename'];
255 $html .= "<li><a class='attachment'" .
257 "$row[filename]</a> ($row[size]) added by " .
258 $this->link->username($row['who'], array(
261 " " . $this->link->date($row['changedate']);
262 require_once 'MTrack/Attachment.php';
263 list($width, $height) = getimagesize(MTrackAttachment::local_path($row['hash']));
264 if ($width + $height) {
265 /* limit maximum size */
266 if ($width > $max_dim) {
267 $height *= $max_dim / $width;
270 if ($height > $max_dim) {
271 $width *= $max_dim / $height;
274 $html .= "<br><a href='$url'><img src='$url' width='$width' border='0' height='$height'></a>";
279 $html .= "</ul></div>";