jablonka.czprosek.czf

websvn

Subversion Repositories:
[/] [include/] [configclass.php] - Blame information for rev 3

 

Line No. Rev Author Line
11simandl<?php
2// WebSVN - Subversion repository viewing via the web using PHP
3// Copyright (C) 2004-2006 Tim Armes
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18//
19// --
20//
21// configclass.php4
22//
23// General class for handling configuration options
24 
25require_once("include/command.php");
26require_once("include/auth.php");
27require_once("include/version.php");
28 
29// Auxillary functions used to sort repositories by name/group
30 
31// {{{ cmpReps($a, $b)
32 
33function cmpReps($a, $b) {
34 // First, sort by group
35 $g = strcasecmp($a->group, $b->group);
36 if ($g) return $g;
37 
38 // Same group? Sort by name
39 return strcasecmp($a->name, $b->name);
40}
41 
42// }}}
43 
44// {{{ cmpGroups($a, $b)
45 
46function cmpGroups($a, $b) {
47 $g = strcasecmp($a->group, $b->group);
48 if ($g) return $g;
49 
50 return 0;
51}
52 
53// }}}
54 
55// {{{ mergesort(&$array, [$cmp_function])
56 
57function mergesort(&$array, $cmp_function = 'strcmp') {
58 // Arrays of size < 2 require no action
59 
60 if (count($array) < 2) return;
61 
62 // Split the array in half
63 $halfway = count($array) / 2;
64 $array1 = array_slice($array, 0, $halfway);
65 $array2 = array_slice($array, $halfway);
66 
67 // Recurse to sort the two halves
68 mergesort($array1, $cmp_function);
69 mergesort($array2, $cmp_function);
70 
71 // If all of $array1 is <= all of $array2, just append them.
72 if (call_user_func($cmp_function, end($array1), $array2[0]) < 1) {
73 $array = array_merge($array1, $array2);
74 return;
75 }
76 
77 // Merge the two sorted arrays into a single sorted array
78 $array = array();
79 $ptr1 = $ptr2 = 0;
80 while ($ptr1 < count($array1) && $ptr2 < count($array2)) {
81 if (call_user_func($cmp_function, $array1[$ptr1], $array2[$ptr2]) < 1) {
82 $array[] = $array1[$ptr1++];
83 } else {
84 $array[] = $array2[$ptr2++];
85 }
86 }
87 
88 // Merge the remainder
89 while ($ptr1 < count($array1)) $array[] = $array1[$ptr1++];
90 while ($ptr2 < count($array2)) $array[] = $array2[$ptr2++];
91 
92 return;
93}
94 
95// }}}
96 
973simandl// A Repository parent path configuration class
98 
99class ParentPath {
100 // {{{ Properties
101 
102 var $path;
103 var $group;
104 var $pattern;
105 var $skipAlreadyAdded;
106 
107 // }}}
108 
109 // {{{ __construct($path, [$group, [$pattern, [$skipAlreadyAdded]]])
110 function ParentPath($path, $group = null, $pattern = false, $skipAlreadyAdded = true) {
111 $this->path = $path;
112 $this->group = $group;
113 $this->pattern = $pattern;
114 $this->skipAlreadyAdded = $skipAlreadyAdded;
115 }
116 // }}}
117 
118 // {{{ findRepository($name)
119 // look for a repository with $name
120 function &findRepository($name) {
121 global $config;
122 if ($this->group != null) {
123 $prefix = $this->group.'.';
124 if (substr($name, 0, strlen($prefix)) == $prefix) {
125 $name = substr($name, strlen($prefix));
126 } else {
127 $null = null;
128 return $null;
129 }
130 }
131 if ($handle = @opendir($this->path)) {
132 // is there a directory named $name?
133 $fullpath = $this->path.DIRECTORY_SEPARATOR.$name;
134 if (is_dir($fullpath) && is_readable($fullpath)) {
135 // And that contains a db directory (in an attempt to not include non svn repositories.
136 $dbfullpath = $fullpath.DIRECTORY_SEPARATOR.'db';
137 if (is_dir($dbfullpath) && is_readable($dbfullpath)) {
138 // And matches the pattern if specified
139 if ($this->pattern === false || preg_match($this->pattern, $name)) {
140 $url = 'file:///'.$fullpath;
141 $url = str_replace(DIRECTORY_SEPARATOR, '/', $url);
142 if ($url{strlen($url) - 1} == "/") {
143 $url = substr($url, 0, -1);
144 }
145 
146 if (!in_array($url, $config->_excluded, true)) {
147 $rep = new Repository($name, $name, $url, $this->group, null, null);
148 return $rep;
149 }
150 }
151 }
152 }
153 closedir($handle);
154 }
155 $null = null;
156 return $null;
157 }
158 // }}}
159 
160 // {{{ getRepositories()
161 // return all repositories in the parent path matching pattern
162 function &getRepositories() {
163 $repos = array();
164 if ($handle = @opendir($this->path)) {
165 // For each file...
166 while (false !== ($name = readdir($handle))) {
167 $fullpath = $this->path.DIRECTORY_SEPARATOR.$name;
168 if ($name{0} != '.' && is_dir($fullpath) && is_readable($fullpath)) {
169 // And that contains a db directory (in an attempt to not include non svn repositories.
170 $dbfullpath = $fullpath.DIRECTORY_SEPARATOR.'db';
171 if (is_dir($dbfullpath) && is_readable($dbfullpath)) {
172 // And matches the pattern if specified
173 if ($this->pattern === false || preg_match($this->pattern, $name)) {
174 $url = 'file:///'.$fullpath;
175 $url = str_replace(DIRECTORY_SEPARATOR, '/', $url);
176 if ($url{strlen($url) - 1} == "/") {
177 $url = substr($url, 0, -1);
178 }
179 
180 $repos[] = new Repository($name, $name, $url, $this->group, null, null);
181 }
182 }
183 }
184 }
185 closedir($handle);
186 }
187 
188 
189 // Sort the repositories into alphabetical order
190 if (!empty($repos)) {
191 usort($repos, "cmpReps");
192 }
193 
194 return $repos;
195 }
196 // }}}
197 
198 // {{{ getSkipAlreadyAdded()
199 // Return if we should skip already added repos for this parent path.
200 function getSkipAlreadyAdded() {
201 return $this->skipAlreadyAdded;
202 }
203 // }}}
204}
205 
2061simandl// A Repository configuration class
207 
208class Repository {
209 // {{{ Properties
210 
211 var $name;
212 var $svnName;
213 var $path;
2143simandl var $subpath;
2151simandl var $group;
216 var $username;
217 var $password;
218 
219 // Local configuration options must start off unset
220 
221 var $allowDownload;
222 var $minDownloadLevel;
223 var $allowedExceptions = array();
224 var $disallowedExceptions = array();
225 var $rss;
226 var $spaces;
227 var $ignoreSvnMimeTypes;
228 var $ignoreWebSVNContentTypes;
229 var $bugtraq;
230 var $auth;
231 var $contentEnc;
232 var $templatePath;
233 
234 // }}}
235 
236 // {{{ __construct($name, $svnName, $path, [$group, [$username, [$password]]])
237 
2383simandl function Repository($name, $svnName, $path, $group = NULL, $username = NULL, $password = NULL, $subpath = NULL) {
2391simandl $this->name = $name;
240 $this->svnName = $svnName;
241 $this->path = $path;
2423simandl $this->subpath = $subpath;
2431simandl $this->group = $group;
244 $this->username = $username;
245 $this->password = $password;
246 }
247 
248 // }}}
249 
250 // {{{ getDisplayName()
251 
252 function getDisplayName() {
253 if (!empty($this->group)) {
254 return $this->group.".".$this->name;
255 }
256 
257 return $this->name;
258 }
259 
260 // }}}
261 
262 // {{{ svnParams
263 
264 function svnParams() {
265 if (!empty($this->username)) {
266 return " --username ".$this->username." --password ".$this->password." ";
267 }
268 
269 return " ";
270 }
271 
272 // }}}
273 
274 // Local configuration accessors
275 
276 // {{{ RSS Feed
277 
278 function hideRSS() {
279 $this->rss = false;
280 }
281 
282 function showRSS() {
283 $this->rss = true;
284 }
285 
286 function getHideRSS() {
287 global $config;
288 
289 if (isset($this->rss)) {
290 return $this->rss;
291 }
292 
293 return $config->getHideRSS();
294 }
295 
296 // }}}
297 
298 // {{{ Download
299 
300 function allowDownload() {
301 $this->allowDownload = true;
302 }
303 
304 function disallowDownload() {
305 $this->allowDownload = false;
306 }
307 
308 function getAllowDownload() {
309 global $config;
310 
311 if (isset($this->allowDownload)) {
312 return $this->allowDownload;
313 }
314 
315 return $config->getAllowDownload();
316 }
317 
318 function setMinDownloadLevel($level) {
319 $this->minDownloadLevel = $level;
320 }
321 
322 function getMinDownloadLevel() {
323 global $config;
324 
325 if (isset($this->minDownloadLevel)) {
326 return $this->minDownloadLevel;
327 }
328 
329 return $config->getMinDownloadLevel();
330 }
331 
332 function addAllowedDownloadException($path) {
333 if ($path{strlen($path) - 1} != "/") $path .= "/";
334 
335 $this->allowedExceptions[] = $path;
336 }
337 
338 function addDisallowedDownloadException($path) {
339 if ($path{strlen($path) - 1} != "/") $path .= "/";
340 
341 $this->disallowedExceptions[] = $path;
342 }
343 
344 function isDownloadAllowed($path) {
345 global $config;
346 
347 // Check global download option
348 if (!$this->getAllowDownload()) {
349 return false;
350 }
351 
352 // Check with access module
353 if (!$this->hasUnrestrictedReadAccess($path)) {
354 return false;
355 }
356 
357 $subs = explode("/", $path);
358 $level = count($subs) - 2;
359 if ($level >= $this->getMinDownloadLevel()) {
360 // Level OK, search for disallowed exceptions
361 
362 if ($config->findException($path, $this->disallowedExceptions)) {
363 return false;
364 }
365 
366 if ($config->findException($path, $config->disallowedExceptions)) {
367 return false;
368 }
369 
370 return true;
371 
372 } else {
373 // Level not OK, search for disallowed exceptions
374 
375 if ($config->findException($path, $this->allowedExceptions)) {
376 return true;
377 }
378 
379 if ($config->findException($path, $config->allowedExceptions)) {
380 return true;
381 }
382 
383 return false;
384 }
385 }
386 
387 // }}}
388 
389 // {{{ Templates
390 
391 function setTemplatePath($path) {
392 $lastchar = substr($path, -1, 1);
393 if (!($lastchar == DIRECTORY_SEPARATOR || $lastchar == '/' || $lastchar == '\\')) {
394 $path .= DIRECTORY_SEPARATOR;
395 }
396 
397 $this->templatePath = $path;
398 }
399 
400 function getTemplatePath() {
401 global $config;
402 if (!empty($this->templatePath)) {
403 return $this->templatePath;
404 }
405 
406 return $config->getTemplatePath();
407 }
408 
409 // }}}
410 
411 // {{{ Tab expansion
412 
413 function expandTabsBy($sp) {
414 $this->spaces = $sp;
415 }
416 
417 function getExpandTabsBy() {
418 global $config;
419 
420 if (isset($this->spaces)) {
421 return $this->spaces;
422 }
423 
424 return $config->getExpandTabsBy();
425 }
426 
427 // }}}
428 
429 // {{{ MIME-Type Handing
430 
431 function ignoreSvnMimeTypes() {
432 $this->ignoreSvnMimeTypes = true;
433 }
434 
435 function useSvnMimeTypes() {
436 $this->ignoreSvnMimeTypes = false;
437 }
438 
439 function getIgnoreSvnMimeTypes() {
440 global $config;
441 
442 if (isset($this->ignoreSvnMimeTypes)) {
443 return $this->ignoreSvnMimeTypes;
444 }
445 
446 return $config->getIgnoreSvnMimeTypes();
447 }
448 
449 function ignoreWebSVNContentTypes() {
450 $this->ignoreWebSVNContentTypes = true;
451 }
452 
453 function useWebSVNContentTypes() {
454 $this->ignoreWebSVNContentTypes = false;
455 }
456 
457 function getIgnoreWebSVNContentTypes() {
458 global $config;
459 
460 if (isset($this->ignoreWebSVNContentTypes)) {
461 return $this->ignoreWebSVNContentTypes;
462 }
463 
464 return $config->getIgnoreWebSVNContentTypes();
465 }
466 
467 // }}}
468 
469 // {{{ Issue Tracking
470 
471 function useBugtraqProperties() {
472 $this->bugtraq = true;
473 }
474 
475 function ignoreBugtraqProperties() {
476 $this->bugtraq = false;
477 }
478 
479 function getBugtraq() {
480 global $config;
481 
482 if (isset($this->bugtraq)) {
483 return $this->bugtraq;
484 }
485 
486 return $config->getBugtraq();
487 }
488 
489 // }}}
490 
491 // {{{ Encodings
492 
493 function setContentEncoding($contentEnc) {
494 $this->contentEnc = $contentEnc;
495 }
496 
497 function getContentEncoding() {
498 global $config;
499 
500 if (isset($this->contentEnc)) {
501 return $this->contentEnc;
502 }
503 
504 return $config->getContentEncoding();
505 }
506 
507 // }}}
508 
509 // {{{ Authentication
510 
511 function useAuthenticationFile($file) {
512 if (is_readable($file)) {
513 $this->auth = new Authentication($file);
514 } else {
515 die('Unable to read authentication file "'.$file.'"');
516 }
517 }
518 
519 function hasReadAccess($path, $checkSubFolders = false) {
520 global $config;
521 
522 $a = null;
523 if (isset($this->auth)) {
524 $a =& $this->auth;
525 } else {
526 $a =& $config->getAuth();
527 }
528 
529 if (!empty($a)) {
530 return $a->hasReadAccess($this->svnName, $path, $checkSubFolders);
531 }
532 
533 // No auth file - free access...
534 return true;
535 }
536 
537 function hasUnrestrictedReadAccess($path) {
538 global $config;
539 
540 $a = null;
541 if (isset($this->auth)) {
542 $a =& $this->auth;
543 } else {
544 $a =& $config->getAuth();
545 }
546 
547 if (!empty($a)) {
548 return $a->hasUnrestrictedReadAccess($this->svnName, $path);
549 }
550 
551 // No auth file - free access...
552 return true;
553 }
554 
555 // }}}
556 
557}
558 
559// The general configuration class
560 
561class WebSvnConfig {
562 // {{{ Properties
563 
564 // Tool path locations
565 
566 var $svnlook = "svnlook";
5673simandl var $_commandPath = "";
568 var $_configPath = "/tmp";
5691simandl var $svn = "svn --non-interactive --config-dir /tmp";
570 var $svn_noparams = "svn --config-dir /tmp";
571 var $diff = "diff";
572 var $enscript ="enscript -q";
573 var $sed = "sed";
574 var $gzip = "gzip";
575 var $tar = "tar";
5763simandl var $zip = "zip";
5771simandl 
5783simandl // different modes for file and folder download
579 
580 var $defaultFileDlMode = "plain";
581 var $defaultFolderDlMode = "gzip";
582 
583 var $validFileDlModes = array( 'gzip', 'zip', 'plain' );
584 var $validFolderDlModes = array( 'gzip', 'zip' );
585 
5861simandl // Other configuration items
587 
588 var $treeView = true;
589 var $flatIndex = true;
590 var $openTree = false;
5913simandl var $alphabetic = false;
5921simandl var $showLastMod = true;
5933simandl var $showAgeInsteadOfDate = true;
5941simandl var $_showRepositorySelectionForm = true;
595 var $serverIsWindows = false;
596 var $multiViews = false;
597 var $useEnscript = false;
598 var $useGeshi = false;
5993simandl var $inlineMimeTypes = array();
6001simandl var $allowDownload = false;
601 var $tarballTmpDir = 'temp';
602 var $minDownloadLevel = 0;
603 var $allowedExceptions = array();
604 var $disallowedExceptions = array();
605 var $rss = true;
606 var $spaces = 8;
607 var $bugtraq = false;
608 var $auth = "";
609 
6103simandl var $templatePath = "./templates/calm/";
6111simandl 
612 var $ignoreSvnMimeTypes = false;
613 var $ignoreWebSVNContentTypes = false;
614 
6153simandl var $subversionVersion = "";
6161simandl var $subversionMajorVersion = "";
617 var $subversionMinorVersion = "";
618 
619 // Default character encodings
620 var $inputEnc = ""; // Encoding of output returned from command line
621 var $contentEnc = ""; // Encoding of repository content
622 var $outputEnc = "UTF-8"; // Encoding of web page. Now forced to UTF-8
623 
624 var $defaultLanguage = 'en';
6253simandl var $ignoreAcceptedLanguages = false;
6261simandl 
627 var $quote = "'";
628 var $pathSeparator = ":";
629 
630 var $_repositories = array();
631 
6323simandl var $_parentPaths = array(); // parent paths to load
633 
634 var $_parentPathsLoaded = false;
635 
636 var $_excluded = array();
637 
6381simandl // }}}
639 
640 // {{{ __construct()
641 
642 function WebSvnConfig() {
643 }
644 
645 // }}}
646 
647 // {{{ Repository configuration
648 
649 function addRepository($name, $url, $group = NULL, $username = NULL, $password = NULL) {
650 $url = str_replace(DIRECTORY_SEPARATOR, "/", $url);
651 
652 if ($url{strlen($url) - 1} == "/") {
653 $url = substr($url, 0, -1);
654 }
655 
656 $svnName = substr($url, strrpos($url, "/") + 1);
657 $this->_repositories[] = new Repository($name, $svnName, $url, $group, $username, $password);
658 }
659 
6603simandl function addRepositorySubpath($name, $url, $subpath, $group = NULL, $username = NULL, $password = NULL) {
661 $url = str_replace(DIRECTORY_SEPARATOR, '/', $url);
662 $subpath = str_replace(DIRECTORY_SEPARATOR, '/', $subpath);
663 
664 if ($url{strlen($url) - 1} == '/') {
665 $url = substr($url, 0, -1);
666 }
667 
668 $svnName = substr($url, strrpos($url, '/') + 1);
669 $this->_repositories[] = new Repository($name, $svnName, $url, $group, $username, $password, $subpath);
670 }
671 
672 
6731simandl function getRepositories() {
6743simandl // lazily load parent paths
675 if (!$this->_parentPathsLoaded) {
676 $this->_parentPathsLoaded = true;
677 foreach ($this->_parentPaths as $parentPath) {
678 $parentRepos = $parentPath->getRepositories();
679 foreach ($parentRepos as $repo) {
680 if (!$parentPath->getSkipAlreadyAdded()) {
681 $this->_repositories[] = $repo;
682 } else {
683 // we have to check if we already have a repo with the same svn name
684 $duplicate = false;
685 if (!empty($this->_repositories)) {
686 foreach ($this->_repositories as $knownRepos) {
687 if ($knownRepos->svnName == $repo->svnName && $knownRepos->subpath == $repo->subpath) {
688 $duplicate = true;
689 break;
690 }
691 }
692 }
693 
694 if (!$duplicate && !in_array($repo->path, $this->_excluded, true)) {
695 $this->_repositories[] = $repo;
696 }
697 }
698 }
699 }
700 }
701 
7021simandl return $this->_repositories;
703 }
704 
705 function &findRepository($name) {
7063simandl // first look in the "normal repositories"
7071simandl foreach ($this->_repositories as $index => $rep) {
708 if (strcmp($rep->getDisplayName(), $name) == 0) {
709 $repref =& $this->_repositories[$index];
710 return $repref;
711 }
712 }
713 
7143simandl // now if the parent repos have not already been loaded
715 // check them
716 if (!$this->_parentPathsLoaded) {
717 foreach ($this->_parentPaths as $parentPath) {
718 $repref =& $parentPath->findRepository($name);
719 if ($repref != null) {
720 return $repref;
721 }
722 }
723 }
724 
7251simandl print "ERROR: Unable to find repository '".htmlentities($name, ENT_QUOTES, 'UTF-8')."'";
726 exit;
727 }
728 
729 // }}}
730 
731 // {{{ setServerIsWindows
732 //
733 // The server is running on Windows
734 
735 function setServerIsWindows() {
736 $this->serverIsWindows = true;
737 
738 // Try to set the input encoding intelligently
739 
740 $cp = 0;
741 if ($cp = @shell_exec("CHCP")) {
742 $cp = trim(substr($cp, strpos($cp, ":") + 1));
743 settype($cp, "integer");
744 }
745 
746 // Use the most sensible default value if that failed
747 if ($cp == 0) $cp = 850;
748 
749 // We assume, as a default, that the encoding of the repository contents is
750 // in iso-8859-1, to be compatible with compilers and the like.
751 $this->setInputEncoding("CP$cp", "iso-8859-1");
752 
753 // On Windows machines, use double quotes around command line parameters
754 $this->quote = '"';
755 
756 // On Windows, semicolon separates path entries in a list rather than colon.
757 $this->pathSeparator = ";";
758 }
759 
760 // }}}
761 
762 // {{{ MultiViews
763 
764 // useMultiViews
765 //
766 // Use MultiViews to access the repository
767 
768 function useMultiViews() {
769 $this->multiViews = true;
770 }
771 
772 function getUseMultiViews() {
773 return $this->multiViews;
774 }
775 
776 // }}}
777 
778 // {{{ Enscript
779 
780 // useEnscript
781 //
782 // Use Enscript to colourise listings
783 
784 function useEnscript() {
785 $this->useEnscript = true;
786 }
787 
788 function getUseEnscript() {
789 return $this->useEnscript;
790 }
791 
7923simandl // }}}
793 
794 // {{{ GeSHi
795 
7961simandl // useGeshi
797 //
798 // Use GeSHi to colourise listings
799 function useGeshi() {
800 $this->useGeshi = true;
801 }
802 
803 function getUseGeshi() {
804 return $this->useGeshi;
805 }
8063simandl 
807 // }}}
8081simandl 
8093simandl // {{{ Inline MIME Types
810 
811 // inlineMimeTypes
812 //
813 // Specify MIME types to display inline in WebSVN pages
814 function addInlineMimeType($type) {
815 if (!in_array($type, $this->inlineMimeTypes)) {
816 $this->inlineMimeTypes[] = $type;
817 }
818 }
819 
820 function getInlineMimeTypes() {
821 return $this->inlineMimeTypes;
822 }
823 
8241simandl // }}}
825 
826 // {{{ RSS
827 
828 // offerRSS
829 //
830 // Use Enscript to colourise listings
831 
832 function hideRSS($myrep = 0) {
833 if (empty($myrep)) {
834 $this->rss = false;
835 } else {
836 $repo =& $this->findRepository($myrep);
837 $repo->hideRSS();
838 }
839 }
840 
841 function getHideRSS() {
842 return $this->rss;
843 }
844 
845 // }}}
846 
847 // {{{ Downloads
848 
849 // allowDownload
850 //
851 // Allow download of tarballs
852 
853 function allowDownload($myrep = 0) {
854 if (empty($myrep)) {
855 $this->allowDownload = true;
856 } else {
857 $repo =& $this->findRepository($myrep);
858 $repo->allowDownload();
859 }
860 }
861 
862 function disallowDownload($myrep = 0) {
863 if (empty($myrep)) {
864 $this->allowDownload = false;
865 } else {
866 $repo =& $this->findRepository($myrep);
867 $repo->disallowDownload();
868 }
869 }
870 
871 function getAllowDownload() {
872 return $this->allowDownload;
873 }
874 
875 function setTarballTmpDir($tmpdir) {
876 $this->tarballTmpDir = $tmpdir;
877 }
878 
879 function getTarballTmpDir() {
880 return $this->tarballTmpDir;
881 }
882 
883 function setMinDownloadLevel($level, $myrep = 0) {
884 if (empty($myrep)) {
885 $this->minDownloadLevel = $level;
886 } else {
887 $repo =& $this->findRepository($myrep);
888 $repo->setMinDownloadLevel($level);
889 }
890 }
891 
892 function getMinDownloadLevel() {
893 return $this->minDownloadLevel;
894 }
895 
896 function addAllowedDownloadException($path, $myrep = 0) {
897 if ($path{strlen($path) - 1} != "/") {
898 $path .= "/";
899 }
900 
901 if (empty($myrep)) {
902 $this->allowedExceptions[] = $path;
903 } else {
904 $repo =& $this->findRepository($myrep);
905 $repo->addAllowedDownloadException($path);
906 }
907 }
908 
909 function addDisallowedDownloadException($path, $myrep = 0) {
910 if ($path{strlen($path) - 1} != "/") {
911 $path .= "/";
912 }
913 
914 if (empty($myrep)) {
915 $this->disallowedExceptions[] = $path;
916 } else {
917 $repo =& $this->findRepository($myrep);
918 $repo->addDisallowedDownloadException($path);
919 }
920 }
921 
922 function findException($path, $exceptions) {
923 foreach ($exceptions As $key => $exc) {
924 if (strncmp($exc, $path, strlen($exc)) == 0) {
925 return true;
926 }
927 }
928 
929 return false;
930 }
931 
932 // }}}
933 
934 // {{{ getURL
935 //
936 // Get the URL to a path name based on the current config
937 
938 function getURL($rep, $path, $op) {
939 list($base, $params) = $this->getUrlParts($rep, $path, $op);
940 
941 $url = $base.'?';
942 foreach ($params as $k => $v) {
943 $url .= $k.'='.urlencode($v).'&amp;';
944 }
945 
946 return $url;
947 }
948 
949 // }}}
950 
951 // {{{ getUrlParts
952 //
9533simandl // Get the URL and parameters for a path name based on the current config
9541simandl 
955 function getUrlParts($rep, $path, $op) {
956 $params = array();
957 
958 if ($this->multiViews) {
959 $url = $_SERVER["SCRIPT_NAME"];
9603simandl if (preg_match('|\.php$|i', $url)) {
961 // remove the .php extension
9621simandl $url = substr($url, 0, -4);
963 }
964 
9653simandl if ($path && $path{0} != "/") {
966 $path = "/".$path;
967 }
9681simandl 
969 if ($op == 'index') {
970 $url .= '/';
971 } else if (is_object($rep)) {
972 $url .= "/".$rep->getDisplayName().str_replace('%2F', '/', rawurlencode($path));
973 
974 if ($op != "dir" && $op != "file") {
975 $params['op'] = $op;
976 }
977 }
978 
979 } else {
980 switch ($op) {
981 case "index":
9823simandl $url = ".";
9831simandl break;
984 
985 case "dir":
9863simandl $url = "listing.php";
9871simandl break;
988 
989 case "revision":
9903simandl $url = "revision.php";
9911simandl break;
992 
993 case "file":
9943simandl $url = "filedetails.php";
9951simandl break;
996 
997 case "log":
9983simandl $url = "log.php";
9991simandl break;
1000 
1001 case "diff":
10023simandl $url = "diff.php";
10031simandl break;
1004 
1005 case "blame":
10063simandl $url = "blame.php";
10071simandl break;
1008 
1009 case "form":
10103simandl $url = "form.php";
10111simandl break;
1012 
1013 case "rss":
10143simandl $url = "rss.php";
10151simandl break;
1016 
1017 case "dl":
10183simandl $url = "dl.php";
10191simandl break;
1020 
1021 case "comp":
10223simandl $url = "comp.php";
10231simandl break;
1024 }
1025 
10263simandl if ($rep !== -1 && $op != 'index') {
10271simandl $params['repname'] = $rep->getDisplayName();
10283simandl }
1029 if (!empty($path)) {
10301simandl $params['path'] = $path;
1031 }
10323simandl }
10331simandl 
10343simandl return array($url, $params);
10351simandl }
1036 
1037 // }}}
1038 
1039 // {{{ Paths and Commands
1040 
1041 // setPath
1042 //
1043 // Set the location of the given path
1044 
1045 function setPath(&$var, $path, $name, $params = '') {
1046 if ($path == '') {
1047 // Search in system search path. No check for existence possible
1048 $var = $name;
1049 } else {
1050 $lastchar = substr($path, -1, 1);
1051 $isDir = ($lastchar == DIRECTORY_SEPARATOR || $lastchar == '/' || $lastchar == '\\');
1052 
1053 if (!$isDir) $path .= DIRECTORY_SEPARATOR;
1054 
10553simandl if (($this->serverIsWindows && !file_exists($path.$name.'.exe')) || (!$this->serverIsWindows && !file_exists($path.$name))) {
10561simandl echo "Unable to find '$name' tool at location '$path$name'";
1057 exit;
1058 }
1059 
1060 // On a windows machine we need to put spaces around the entire command
1061 // to allow for spaces in the path
1062 if ($this->serverIsWindows) {
1063 $var = '"'.$path.$name.'"';
1064 } else {
1065 $var = $path.$name;
1066 }
1067 }
1068 
1069 // Append parameters
1070 if ($params != '') $var .= ' '.$params;
1071 }
1072 
10733simandl function setConfigPath($path) {
1074 $this->_configPath = $path;
1075 $this->updateSVNCommands();
1076 }
1077 
10781simandl // setSVNCommandPath
1079 //
1080 // Define the location of the svn and svnlook commands
1081 
1082 function setSVNCommandPath($path) {
10833simandl $this->_commandPath = $path;
1084 $this->updateSVNCommands();
10851simandl }
1086 
10873simandl function updateSVNCommands() {
1088 $this->setPath($this->svn, $this->_commandPath, "svn", "--non-interactive --config-dir ".$this->_configPath);
1089 $this->setPath($this->svn_noparams, $this->_commandPath, "svn", " --config-dir ".$this->_configPath);
1090 $this->setPath($this->svnlook, $this->_commandPath, "svnlook");
1091 }
1092 
10931simandl function getSvnCommand() {
1094 return $this->svn;
1095 }
1096 
1097 function getCleanSvnCommand() {
1098 return $this->svn_noparams;
1099 }
1100 
1101 function getSvnlookCommand() {
1102 return $this->svnlook;
1103 }
1104 
1105 // setDiffPath
1106 //
1107 // Define the location of the diff command
1108 
1109 function setDiffPath($path) {
1110 $this->setPath($this->diff, $path, "diff");
1111 }
1112 
1113 function getDiffCommand() {
1114 return $this->diff;
1115 }
1116 
1117 // setEnscriptPath
1118 //
1119 // Define the location of the enscript command
1120 
1121 function setEnscriptPath($path) {
1122 $this->setPath($this->enscript, $path, "enscript");
1123 }
1124 
1125 function getEnscriptCommand() {
1126 return $this->enscript;
1127 }
1128 
1129 // setSedPath
1130 //
1131 // Define the location of the sed command
1132 
1133 function setSedPath($path) {
1134 $this->setPath($this->sed, $path, "sed");
1135 }
1136 
1137 function getSedCommand() {
1138 return $this->sed;
1139 }
1140 
1141 // setTarPath
1142 //
1143 // Define the location of the tar command
1144 
1145 function setTarPath($path) {
1146 $this->setPath($this->tar, $path, "tar");
1147 }
1148 
1149 function getTarCommand() {
1150 return $this->tar;
1151 }
1152 
1153 // setGzipPath
1154 //
1155 // Define the location of the GZip command
1156 
1157 function setGzipPath($path) {
1158 $this->setPath($this->gzip, $path, "gzip");
1159 }
1160 
1161 function getGzipCommand() {
1162 return $this->gzip;
1163 }
1164 
11653simandl // setZipPath
1166 //
1167 // Define the location of the zip command
1168 function setZipPath($path) {
1169 $this->setPath($this->zip, $path, "zip");
1170 }
1171 
1172 function getZipPath() {
1173 return $this->zip;
1174 }
1175 
1176 // setDefaultFileDlMode
1177 //
1178 // Define the default file download mode - one of [gzip, zip, plain]
1179 function setDefaultFileDlMode($dlmode) {
1180 if (in_array($dlmode, $this->validFileDlModes)) {
1181 $this->defaultFileDlMode = $dlmode;
1182 } else {
1183 echo 'Setting default file download mode to an invalid value "'.$dlmode.'"';
1184 exit;
1185 }
1186 }
1187 
1188 function getDefaultFileDlMode() {
1189 return $this->defaultFileDlMode;
1190 }
1191 
1192 // setDefaultFolderDlMode
1193 //
1194 // Define the default folder download mode - one of [gzip, zip]
1195 function setDefaultFolderDlMode($dlmode) {
1196 if (in_array($dlmode, $this->validFolderDlModes)) {
1197 $this->defaultFolderDlMode = $dlmode;
1198 } else {
1199 echo 'Setting default file download mode to an invalid value "'.$dlmode.'"';
1200 exit;
1201 }
1202 }
1203 
1204 function getDefaultFolderDlMode() {
1205 return $this->defaultFolderDlMode;
1206 }
1207 
12081simandl // Templates
1209 
1210 function setTemplatePath($path, $myrep = 0) {
1211 if (empty($myrep)) {
1212 $lastchar = substr($path, -1, 1);
1213 if (!($lastchar == DIRECTORY_SEPARATOR || $lastchar == '/' || $lastchar == '\\')) {
1214 $path .= DIRECTORY_SEPARATOR;
1215 }
1216 
1217 $this->templatePath = $path;
1218 } else {
1219 $repo =& $this->findRepository($myrep);
1220 $repo->setTemplatePath($path);
1221 }
1222 }
1223 
1224 function getTemplatePath() {
1225 return $this->templatePath;
1226 }
1227 
1228 // }}}
1229 
1230 // {{{ parentPath
1231 //
1232 // Automatically set up the repositories based on a parent path
1233 
1234 function parentPath($path, $group = NULL, $pattern = false, $skipAlreadyAdded = true) {
12353simandl $this->_parentPaths[] = new ParentPath($path, $group, $pattern, $skipAlreadyAdded);
1236 }
12371simandl 
12383simandl function addExcludedPath($path) {
1239 $url = 'file:///'.$path;
1240 $url = str_replace(DIRECTORY_SEPARATOR, '/', $url);
1241 if ($url{strlen($url) - 1} == '/') {
1242 $url = substr($url, 0, -1);
12431simandl }
12443simandl $this->_excluded[] = $url;
12451simandl }
1246 
1247 // }}}
1248 
1249 // {{{ Encoding functions
1250 
1251 function setInputEncoding($systemEnc) {
1252 $this->inputEnc = $systemEnc;
1253 
1254 if (!isset($this->contentEnc)) {
1255 $this->contentEnc = $systemEnc;
1256 }
1257 }
1258 
1259 function getInputEncoding() {
1260 return $this->inputEnc;
1261 }
1262 
1263 function setContentEncoding($contentEnc, $myrep = 0) {
1264 if (empty($myrep)) {
1265 $this->contentEnc = $contentEnc;
1266 } else {
1267 $repo =& $this->findRepository($myrep);
1268 $repo->setContentEncoding($contentEnc);
1269 }
1270 }
1271 
1272 function getContentEncoding() {
1273 return $this->contentEnc;
1274 }
1275 
1276 // }}}
1277 
1278 function setDefaultLanguage($language) {
1279 $this->defaultLanguage = $language;
1280 }
1281 
1282 function getDefaultLanguage() {
1283 return $this->defaultLanguage;
1284 }
1285 
12863simandl function ignoreUserAcceptedLanguages() {
1287 $this->ignoreAcceptedLanguages = true;
1288 }
1289 
1290 function useAcceptedLanguages() {
1291 return !$this->ignoreAcceptedLanguages;
1292 }
1293 
12941simandl // {{{ Tab expansion functions
1295 
1296 function expandTabsBy($sp, $myrep = 0) {
1297 if (empty($myrep)) {
1298 $this->spaces = $sp;
1299 } else {
1300 $repo =& $this->findRepository($myrep);
1301 $repo->expandTabsBy($sp);
1302 }
1303 }
1304 
1305 function getExpandTabsBy() {
1306 return $this->spaces;
1307 }
1308 
1309 // }}}
1310 
1311 // {{{ Misc settings
1312 
1313 function ignoreSvnMimeTypes() {
1314 $this->ignoreSvnMimeTypes = true;
1315 }
1316 
1317 function getIgnoreSvnMimeTypes() {
1318 return $this->ignoreSvnMimeTypes;
1319 }
1320 
1321 function ignoreWebSVNContentTypes() {
1322 $this->ignoreWebSVNContentTypes = true;
1323 }
1324 
1325 function getIgnoreWebSVNContentTypes() {
1326 return $this->ignoreWebSVNContentTypes;
1327 }
1328 
1329 function useBugtraqProperties($myrep = 0) {
1330 if (empty($myrep)) {
1331 $this->bugtraq = true;
1332 } else {
1333 $repo =& $this->findRepository($myrep);
1334 $repo->useBugtraqProperties();
1335 }
1336 }
1337 
1338 function getBugtraq() {
1339 return $this->bugtraq;
1340 }
1341 
1342 function useAuthenticationFile($file, $myrep = 0) {
1343 if (empty($myrep)) {
1344 if (is_readable($file)) {
1345 $this->auth = new Authentication($file);
1346 } else {
1347 echo "Unable to read authentication file '$file'";
1348 exit;
1349 }
1350 } else {
1351 $repo =& $this->findRepository($myrep);
1352 $repo->useAuthenticationFile($file);
1353 }
1354 }
1355 
1356 function &getAuth() {
1357 return $this->auth;
1358 }
1359 
1360 function useTreeView() {
1361 $this->treeView = true;
1362 }
1363 
1364 function getUseTreeView() {
1365 return $this->treeView;
1366 }
1367 
1368 function useFlatView() {
1369 $this->treeView = false;
1370 }
1371 
1372 function useTreeIndex($open) {
1373 $this->flatIndex = false;
1374 $this->openTree = $open;
1375 }
1376 
1377 function getUseFlatIndex() {
1378 return $this->flatIndex;
1379 }
1380 
1381 function getOpenTree() {
1382 return $this->openTree;
1383 }
1384 
13853simandl function setAlphabeticOrder($flag) {
1386 $this->alphabetic = $flag;
1387 }
1388 
1389 function isAlphabeticOrder() {
1390 return $this->alphabetic;
1391 }
1392 
13931simandl function showLastModInListing() {
1394 return $this->showLastMod;
1395 }
1396 
1397 function setShowLastModInListing($show) {
1398 $this->showLastMod = $show;
1399 }
1400 
14013simandl function showAgeInsteadOfDate() {
1402 return $this->showAgeInsteadOfDate;
1403 }
1404 
1405 function setShowAgeInsteadOfDate($show) {
1406 $this->showAgeInsteadOfDate = $show;
1407 }
1408 
14091simandl function showRepositorySelectionForm() {
1410 return $this->_showRepositorySelectionForm;
1411 }
1412 
1413 function setShowRepositorySelectionForm($show) {
1414 $this->_showRepositorySelectionForm = $show;
1415 }
1416 
14173simandl // Methods for storing version information for the command-line svn tool
14181simandl 
14193simandl function setSubversionVersion($subversionVersion) {
1420 $this->subversionVersion = $subversionVersion;
1421 }
1422 
1423 function getSubversionVersion() {
1424 return $this->subversionVersion;
1425 }
1426 
14271simandl function setSubversionMajorVersion($subversionMajorVersion) {
1428 $this->subversionMajorVersion = $subversionMajorVersion;
1429 }
1430 
1431 function getSubversionMajorVersion() {
1432 return $this->subversionMajorVersion;
1433 }
1434 
1435 function setSubversionMinorVersion($subversionMinorVersion) {
1436 $this->subversionMinorVersion = $subversionMinorVersion;
1437 }
1438 
1439 function getSubversionMinorVersion() {
1440 return $this->subversionMinorVersion;
1441 }
1442 
1443 // }}}
1444 
1445 // {{{ Sort the repostories
1446 //
1447 // This function sorts the repositories by group name. The contents of the
1448 // group are left in there original order, which will either be sorted if the
1449 // group was added using the parentPath function, or defined for the order in
1450 // which the repositories were included in the user's config file.
1451 //
1452 // Note that as of PHP 4.0.6 the usort command no longer preserves the order
1453 // of items that are considered equal (in our case, part of the same group).
1454 // The mergesort function preserves this order.
1455 
1456 function sortByGroup() {
1457 if (!empty($this->_repositories))
1458 mergesort($this->_repositories, "cmpGroups");
1459 }
1460 
1461 // }}}
1462}

Powered by WebSVN 2.2.1