public function testGetMimeType() { $files = array('whatever.php' => 'application/x-httpd-php', 'whatever.pht' => 'application/x-httpd-php', 'README' => 'text/plain'); foreach ($files as $file => $mime) { $m = IDF_Views_Source::getMimeType($file); $this->assertEqual($mime, $m[0]); } }
function callbackEmbeddedDoc($m) { $scm = IDF_Scm::get($this->request->project); $view_source = new IDF_Views_Source(); $match = array('dummy', $this->request->project->shortname); $match[] = isset($m[2]) ? $m[2] : $scm->getMainBranch(); $match[] = $m[1]; $res = $view_source->getFile($this->request, $match); if ($res->status_code != 200) { return $m[0]; } $info = pathinfo($m[1]); $fileinfo = array($res->headers['Content-Type'], $m[1], isset($info['extension']) ? $info['extension'] : 'bin'); if (!IDF_Views_Source::isText($fileinfo)) { return $m[0]; } return $res->content; }
public function viewAttachment($request, $match) { $prj = $request->project; $attach = Pluf_Shortcuts_GetObjectOr404('IDF_IssueFile', $match[2]); $prj->inOr404($attach->get_comment()->get_issue()); // If one cannot see the attachement, redirect to the // getAttachment view. $info = IDF_Views_Source::getMimeType($attach->filename); if (!IDF_Views_Source::isText($info)) { return $this->getAttachment($request, $match); } // Now we want to look at the file but with links back to the // issue. $file = IDF_Views_Source::highLight($info, file_get_contents(Pluf::f('upload_issue_path') . '/' . $attach->attachment)); $title = sprintf(__('View %s'), $attach->filename); return Pluf_Shortcuts_RenderToResponse('idf/issues/attachment.html', array('attachment' => $attach, 'page_title' => $title, 'comment' => $attach->get_comment(), 'issue' => $attach->get_comment()->get_issue(), 'file' => $file), $request); }
public function renderCompared($chunks, $filename) { $fileinfo = IDF_Views_Source::getMimeType($filename); $pretty = ''; if (IDF_Views_Source::isSupportedExtension($fileinfo[2])) { $pretty = ' prettyprint'; } $out = ''; $cc = 1; $i = 0; foreach ($chunks as $chunk) { foreach ($chunk as $line) { $line1 = ' '; $line2 = ' '; $line[2] = strlen($line[2]) ? self::padLine(Pluf_esc($line[2])) : ' '; if ($line[0] and $line[1]) { $class = 'diff-c'; $line1 = $line2 = $line[2]; } elseif ($line[0]) { $class = 'diff-r'; $line1 = $line[2]; } else { $class = 'diff-a'; $line2 = $line[2]; } $out .= sprintf('<tr class="diff-line"><td class="diff-lc">%s</td><td class="%s mono%s"><code>%s</code></td><td class="diff-lc">%s</td><td class="%s mono%s"><code>%s</code></td></tr>' . "\n", $line[0], $class, $pretty, $line1, $line[1], $class, $pretty, $line2); } if (count($chunks) > $cc) { $out .= '<tr class="diff-next"><td>...</td><td> </td><td>...</td><td> </td></tr>' . "\n"; } $cc++; $i++; } return Pluf_Template::markSafe($out); }