snippet = $_POST['code']; $snip->description = $_POST['description']; $snip->lang = $_POST['lang']; $cs = MTrackChangeset::begin("snippet:?", $snip->description); $snip->save($cs); //$cs->setObject("snippet:$snip->snid"); $cs->commit(); header("Location: {$ABSWEB}snippet.php/$snip->snid"); exit; } $pi = mtrack_get_pathinfo(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $snip = new MTrack_Snippet; $snip->description = $_POST['description']; $snip->lang = $_POST['lang']; $snip->snippet = $_POST['code']; } elseif (strlen($pi)) { $snip = MTrack_Snippet::loadById($pi); if (!$snip) { throw new Exception("Invalid snippet ID"); } } else { $snip = null; } if ($snip) { $lang = $snip->lang; $code = $snip->snippet; $desc = $snip->description; mtrack_head("Snippet $pi"); } else { $lang = ''; $code = 'Enter your snippet here'; $desc = 'Enter a descriptive message here; you may use wiki syntax'; mtrack_head("New Snippet"); } echo ""; /* collect recent snippets */ $recent = MTrackDB::q('select snid, description, who, changedate from snippets left join changes on snippets.updated = changes.cid order by changes.changedate desc limit 10')->fetchAll(PDO::FETCH_OBJ); echo <<Snippets are a way to share text or code fragments

HTML; if (MTrackACL::hasAllRights('Snippets', 'create')) { echo <<New Snippet
HTML; } echo <<Recent Snippets HTML; foreach ($recent as $s) { $url = "{$ABSWEB}snippet.php/$s->snid"; $sum = MTrackWiki::format_to_oneliner($s->description); $who = mtrack_username($s->who, array('no_image' => true)); $when = mtrack_date($s->changedate); echo << $sum
$when by $who
view snippet HTML; } echo "
"; if (MTrackACL::hasAllRights('Snippets', 'create') && (!$snip || $_SERVER['REQUEST_METHOD'] == 'POST')) { echo "
"; echo "\n"; echo MTrack_SyntaxHighlight::getLangSelect('lang', $lang); echo "

"; echo "\n"; echo "\n"; echo "
"; } if ($snip) { echo "
"; echo "

Snippet

"; if ($snip->created) { $created = MTrackChangeset::get($snip->created); } else { $created = new stdclass; } echo "", mtrack_username($created->who, array('no_name' => true, 'size' => 48)), ""; echo "Created: ", mtrack_date($created->when), " by ", mtrack_username($created->who, array('no_image' => true)), "
\n"; echo "Link to this snippet
"; echo MTrackWiki::format_to_html($snip->description); echo "

"; echo MTrack_SyntaxHighlight::getSchemeSelect(); echo MTrack_SyntaxHighlight::highlightSource($code, $lang, null, true); echo "
"; } else if (!MTrackACL::hasAllRights('Snippets', 'create')) { echo "

You do not have rights to create snippets

"; } echo "
"; mtrack_foot();