-
Notifications
You must be signed in to change notification settings - Fork 2
/
co.php
116 lines (96 loc) · 3.39 KB
/
co.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* Copyright 2000-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Anil Madhavapeddy <[email protected]>
* @package Chora
*/
require_once __DIR__ . '/lib/Application.php';
/* If a revision is specified, it's safe to cache for a long time. */
if (empty($_GET['r'])) {
Horde_Registry::appInit('chora');
} else {
session_cache_expire(10080);
Horde_Registry::appInit('chora', array('session_cache_limiter' => 'public'));
}
/* If we know we're at a directory, just go to browsedir.php. */
if ($atdir) {
require CHORA_BASE . '/browsedir.php';
exit;
}
/* Should we pretty-print this output or not? */
$plain = Horde_Util::getFormData('p', 0);
/* Create the VC_File object and populate it. */
try {
$file = $VC->getFile($where);
} catch (Horde_Vcs_Exception $e) {
Chora::fatal($e);
}
/* Get the revision number. */
$r = Horde_Util::getFormData('r');
/* If no revision is specified, default to HEAD. */
if (is_null($r)) {
$r = $file->getRevision();
}
/* Is this a valid revision being requested? */
if (!$VC->isValidRevision($r)) {
Chora::fatal(sprintf(_("Revision Not Found: %s is not a valid revision"), $r), '400 Bad Request');
}
/* Retrieve the actual checkout. */
try {
$checkOut = $VC->checkout($file->getPath(), $r);
} catch (Horde_Vcs_Exception $e) {
Chora::fatal($e);
}
/* Get the MIME type of the file, or at least our best guess at it. */
$mime_type = Horde_Mime_Magic::filenameToMIME($fullname);
if ($mime_type == 'application/octet-stream') {
$mime_type = 'text/plain';
}
if (!$plain) {
/* Pretty-print the checked out copy */
$pretty = Chora::pretty($mime_type, $checkOut);
if (strpos($mime_type, 'text/plain') !== false) {
$data = $pretty->render('inline');
$data = reset($data);
$rendered = '<div class="fixed">' . $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($data['data'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO)) . '</div>';
} elseif (strpos($mime_type, 'image/') !== false) {
$rendered = Horde::img(Horde::selfUrl(true)->add('p', 1), '', '', '');
} elseif ($pretty->canRender('inline')) {
$data = $pretty->render('inline');
$data = reset($data);
$rendered = $data['data'];
} else {
$rendered = Horde::link(Horde::selfUrl(true)->add('p', 1)) . Horde::img('download.png') . ' ' . sprintf(_("Download revision %s"), $r) . '</a>';
}
/* Get this revision's attributes in printable form. */
$log = $file->getLog($r);
$title = sprintf(_("Revision %s (%s ago) for:"),
$r,
Chora::readableTime($log->getDate(), true));
$page_output->addScriptFile('stripe.js', 'horde');
Chora::header($title);
echo Chora::getFileViews($where, $r)->render('co');
require CHORA_TEMPLATES . '/checkout/checkout.inc';
$page_output->footer();
exit;
}
/* Download the file. */
// Get data.
$content = '';
while ($line = fgets($checkOut)) {
$content .= $line;
}
fclose($checkOut);
// Get name.
$filename = $file->getFileName();
if ($browser->getBrowser() == 'opera') {
$filename = strtr($filename, ' ', '_');
}
// Send headers.
$browser->downloadHeaders($filename, $mime_type, false, strlen($content));
// Send data.
echo $content;