function callbackEmbeddedDoc($m) { $scm = IDF_Scm::get($this->request->project); if (!$scm->isAvailable()) { return $m[0]; } $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_FileUtil::isText($fileinfo)) { return $m[0]; } return $res->content; }
public function tree($request, $match) { $scm = IDF_Scm::get($request->project); $commit = $match[2]; $request_file = $match[3]; if (substr($request_file, -1) == '/') { $request_file = substr($request_file, 0, -1); $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::tree', array($match[1], $match[2], $request_file)); return new Pluf_HTTP_Response_Redirect($url, 301); } $request_file_info = $scm->getPathInfo($request_file, $commit); if (!$request_file_info) { // Redirect to the main branch $fburl = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase', array($request->project->shortname, $scm->getMainBranch())); return new Pluf_HTTP_Response_Redirect($fburl); } $branches = $scm->getBranches(); $tags = $scm->getTags(); if ($request_file_info->type != 'tree') { $info = self::getRequestedFileMimeType($request_file_info, $commit, $scm); if (!IDF_FileUtil::isText($info)) { $rep = new Pluf_HTTP_Response($scm->getFile($request_file_info), $info[0]); $rep->headers['Content-Disposition'] = 'attachment; filename="' . $info[1] . '"'; return $rep; } else { // We want to display the content of the file as text $extra = array('branches' => $branches, 'tags' => $tags, 'commit' => $commit, 'request_file' => $request_file, 'request_file_info' => $request_file_info, 'mime' => $info); return $this->viewFile($request, $match, $extra); } } $bc = self::makeBreadCrumb($request->project, $commit, $request_file_info->fullpath); $title = sprintf(__('%1$s %2$s Source Tree'), $request->project, $this->getScmType($request)); $page_title = $bc . ' - ' . $title; $cobject = $scm->getCommit($commit); if (!$cobject) { // Redirect to the first branch $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase', array($request->project->shortname, $scm->getMainBranch())); return new Pluf_HTTP_Response_Redirect($url); } $in_branches = $scm->inBranches($commit, $request_file); $in_tags = $scm->inTags($commit, $request_file); $cache = Pluf_Cache::factory(); $key = sprintf('Project:%s::IDF_Views_Source::tree:%s::%s', $request->project->id, $commit, $request_file); if (null === ($res = $cache->get($key))) { $res = new Pluf_Template_ContextVars($scm->getTree($commit, $request_file)); $cache->set($key, $res); } // try to find the previous level if it exists. $prev = explode('/', $request_file); $l = array_pop($prev); $previous = substr($request_file, 0, -strlen($l . ' ')); $scmConf = $request->conf->getVal('scm', 'git'); $props = $scm->getProperties($commit, $request_file); $res->uasort(array('IDF_Views_Source', 'treeSort')); return Pluf_Shortcuts_RenderToResponse('idf/source/' . $scmConf . '/tree.html', array('page_title' => $page_title, 'title' => $title, 'breadcrumb' => $bc, 'files' => $res, 'commit' => $commit, 'cobject' => $cobject, 'base' => $request_file_info->file, 'prev' => $previous, 'tree_in' => $in_branches, 'branches' => $branches, 'tags' => $tags, 'tags_in' => $in_tags, 'props' => $props), $request); }
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_FileUtil::getMimeType($attach->filename); if (!IDF_FileUtil::isText($info)) { return $this->getAttachment($request, $match); } // Now we want to look at the file but with links back to the // issue. $file = IDF_FileUtil::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); }
function isText() { $info = IDF_FileUtil::getMimeType($this->filename); return IDF_FileUtil::isText($info); }