File: browse.php

package info (click to toggle)
chora2 2.0.1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,208 kB
  • ctags: 302
  • sloc: php: 1,298; xml: 406; makefile: 66
file content (244 lines) | stat: -rw-r--r-- 9,432 bytes parent folder | download
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
/**
 * $Horde: chora/browse.php,v 1.5.4.3 2005/06/02 11:37:36 selsky Exp $
 *
 * Copyright 1999-2005 Anil Madhavapeddy <anil@recoil.org>
 * Copyright 1999-2005 Charles Hagenbuch <chuck@horde.org>
 *
 * See the enclosed file COPYING for license information (GPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 */

@define('CHORA_BASE', dirname(__FILE__));
require_once CHORA_BASE . '/lib/base.php';
require_once 'Horde/MIME/Magic.php';
require_once 'Horde/MIME/Viewer.php';
require_once HORDE_BASE . '/config/mime_drivers.php';
require_once CHORA_BASE . '/config/mime_drivers.php';

if ($atdir) {
    Chora::checkError($dir = $VC->queryDir($where));

    $atticFlags = (boolean)$acts['sa'];
    Chora::checkError($dir->browseDir($cache, true, $atticFlags));
    $dir->applySort($acts['sbt'], $acts['ord']);
    Chora::checkError($dirList = &$dir->queryDirList());
    Chora::checkError($fileList = $dir->queryFileList($atticFlags));

    /* Decide what title to display. */
    if ($where == '') {
        $title = $conf['options']['introTitle'];
    } else {
        $title = sprintf(_("Source Directory of /%s"), Text::htmlallSpaces($where));
    }

    if (is_a($VC, 'VC_svn')) {
        // Showing deleted files is not supported in svn.
        $extraLink = '';
    } else {
        if ($acts['sa']) {
            $extraLink = Horde::widget(Chora::url('', $where . '/', array('sa' => 0)), _("Hide Deleted Files"), 'widget', '', '', _("Hide _Deleted Files"));
        } else {
            $extraLink = Horde::widget(Chora::url('', $where . '/', array('sa' => 1)), _("Show Deleted Files"), 'widget', '', '', _("Show _Deleted Files"));
        }
    }

    require CHORA_TEMPLATES . '/common-header.inc';
    require CHORA_TEMPLATES . '/menu.inc';
    require CHORA_TEMPLATES . '/headerbar.inc';

    foreach (array('age', 'rev', 'name', 'author') as $u) {
        $umap = array('age' => VC_SORT_AGE, 'rev' => VC_SORT_REV,
                      'name' => VC_SORT_NAME, 'author' => VC_SORT_AUTHOR);
        $arg = array('sbt' => $umap[$u]);
        if ($acts['sbt'] == $umap[$u]) {
            $arg['ord'] = !$acts['ord'];
        }
        $url[$u] = Chora::url('', $where . '/', $arg);
    }

    /* Print out the directory header. */
    $printAllCols = count($fileList);
    require CHORA_TEMPLATES . '/directory/header.inc';

    /* Unless we're at the top, display the 'back' bar. */
    $dirrow = 1;
    if ($where != '') {
        $dirrow = ++$dirrow % 2;
        $url = Chora::url('', preg_replace('|[^/]+$|', '', $where));
        require CHORA_TEMPLATES . '/directory/back.inc';
    }

    /* Display all the directories first. */
    foreach ($dirList as $currentDir) {
        if ($conf['hide_restricted'] && Chora::isRestricted($currentDir)) {
            continue;
        }
        $dirrow = ++$dirrow % 2;
        $url = Chora::url('', "$where/$currentDir/");
        $currDir = Text::htmlAllSpaces($currentDir);
        require CHORA_TEMPLATES . '/directory/dir.inc';
    }

    /* Display all of the files in this directory */
    foreach ($fileList as $currFile) {
        if ($conf['hide_restricted'] && Chora::isRestricted($currFile->queryName())) {
            continue;
        }
        $dirrow = ++$dirrow % 2;
        $lg = $currFile->queryLastLog();
        if (is_a($lg, 'PEAR_Error')) {
            continue;
        }
        $realname = $currFile->queryName();
        $mimeType = MIME_Magic::filenameToMIME($realname);

        $icon = MIME_Viewer::getIcon($mimeType);

        $aid = $lg->queryAuthor();
        $author = Chora::showAuthorName($aid);
        $head = $currFile->queryHead();
        $date = $lg->queryDate();
        $log  = $lg->queryLog();
        $attic = $currFile->isAtticFile();
        $fileName = $where . ($attic ? '/' . 'Attic' : '') . '/' . $realname;
        $name = Text::htmlAllSpaces($realname);
        $url = Chora::url('', $fileName);
        $readableDate = Chora::readableTime($date);
        if ($log) {
            $shortLog = str_replace("\n", ' ',
                trim(substr($log, 0, $conf['options']['shortLogLength'] - 1)));
            if (strlen($log) > 80) {
                $shortLog .= "...";
            }
        }
        require CHORA_TEMPLATES.'/directory/file.inc';
    }
    /* Display the options control panel at the bottom */
    $formwhere = $scriptName . '/' . $where;

    require CHORA_TEMPLATES . '/directory/footer.inc';
    require $registry->get('templates', 'horde') . '/common-footer.inc';

} elseif ($VC->isFile($fullname)) {
    $fl = &$VC->getFileObject($where, $cache);
    Chora::checkError($fl);
    $title = sprintf(_("Source Log for %s"), Text::htmlAllSpaces($where));
    $upwhere = preg_replace('|[^/]+$|', '', $where);
    $onb = Util::getFormData('onb', 0);
    $r1 = Util::getFormData('r1', 0);

    $isBranch = isset($onb) && isset($fl->branches[$onb]) ? $fl->branches[$onb] : '';
    $extraLink = Chora::getFileViews();

    require CHORA_TEMPLATES . '/common-header.inc';
    require CHORA_TEMPLATES . '/menu.inc';
    require CHORA_TEMPLATES . '/headerbar.inc';

    $mimeType = MIME_Magic::filenameToMIME($fullname);
    $defaultTextPlain = ($mimeType == 'text/plain');

    foreach ($fl->logs as $lg) {
        $rev = $lg->rev;

        /* Are we sticking only to one branch ? */
        if ($onb && VC_Revision::valid($onb)) {

            /* If so, if we are on the branch itself, let it through */
            if (substr($rev, 0, strlen($onb)) != $onb) {

                /* We are not on the branch, see if we are on a trunk
                 * branch below the branch */
                $baseRev = VC_Revision::strip($onb, 1);

                /* Check we are at the same level of branching or less */
                if (substr_count($rev, '.') <= substr_count($baseRev, '.')) {
                    /* If we are at the same level, and the revision is
                     * less, then let the revision through, since it was
                     * committed before the branch actually took place
                     */
                    if (VC_Revision::cmp($rev, $baseRev) > 0) {
                        continue;
                    }
                } else {
                    continue;
                }
            }
        }

        $textURL = Chora::url('co', $where, array('r' => $rev));
        $commitDate = strftime('%c', $lg->date);
        $readableDate = Chora::readableTime($lg->date, true);

        $aid = $lg->queryAuthor();
        $author = Chora::showAuthorName($aid, true);

        if (!empty($lg->tags)) {
            $commitTags = implode(', ', $lg->tags);
        } else {
            $commitTags = '';
        }

        $branchPointsArr = array();
        foreach ($lg->querySymbolicBranches() as $symb => $bra) {
            $branchPointsArr[] = '<a href="' . Chora::url('', $where, array('onb' => $bra)) . '">'. $symb . '</a>';
        }

        /* Calculate the current branch name and revision. */
        $branchPoints = implode(' , ', $branchPointsArr);
        $branchRev = VC_Revision::strip($rev, 1);
        if (@isset($fl->branches[$branchRev])) {
            $branchName = $fl->branches[$branchRev];
        } else {
            $branchName = '';
        }

        if ($prevRevision = $fl->queryPreviousRevision($lg->queryRevision())) {
            $changedLines = $lg->queryChangedLines();
            $coloredDiffURL = Chora::url('diff', $where, array('r1' => $prevRevision, 'r2' => $rev, 'ty' => 'h'));
            $longDiffURL = Chora::url('diff', $where, array('r1' => $prevRevision, 'r2' => $rev, 'ty' => 'h', 'num' => 10));
            $uniDiffURL = Chora::url('diff', $where, array('r1' => $prevRevision, 'r2' => $rev, 'ty' => 'u'));
            $nowsDiffURL = Chora::url('diff', $where, array('ws' => 0, 'r1' => $prevRevision, 'r2' => $rev, 'ty' => 'u'));
        }

        $manyRevisions = !($fl->queryRevision() === '1.1');
        if ($manyRevisions) {
            $selURL = Chora::url('', $where, array('r1' => $rev, 'onb' => $onb));
            if (!empty($r1)) {
                $selColoredDiffURL = Chora::url('diff', $where, array('r1' => $r1, 'r2' => $rev, 'ty' => 'h'));
                $selLongDiffURL = Chora::url('diff', $where, array('r1' => $r1, 'r2' => $rev, 'ty' => 'h', 'num' => 10));
                $selUniDiffURL = Chora::url('diff', $where, array('r1' => $r1, 'r2' => $rev, 'ty' => 'u'));
                $selNowsDiffURL = Chora::url('diff', $where, array('ws' => 0, 'r1' => $r1, 'r2' => $rev, 'ty' => 'u'));
            }
        }

        $logMessage = Chora::formatLogMessage($lg->log);

        if ($r1 === $rev) {
            $bgclass = 'diff-selected';
        } else {
            $bgclass = 'control';
        }

        require CHORA_TEMPLATES . '/log/rev.inc';
    }

    $first = end($fl->logs);
    $diffValueLeft  = $first->rev;
    $diffValueRight = $fl->queryRevision();

    $sel = '';
    foreach ($fl->symrev as $sm => $rv) {
        $sel .= '<option value="' . $rv . '">' . $sm . '</option>';
    }

    $selAllBranches = '';
    foreach ($fl->branches as $num => $sym) {
        $selAllBranches .= '<option value="' . $num . '">' . $sym . '</option>';
    }

    require CHORA_TEMPLATES . '/log/request.inc';
    require $registry->get('templates', 'horde') . '/common-footer.inc';
} else {
    Chora::fatal('404 Not Found', "$where: no such file or directory");
}