jablonka.czprosek.czf

websvn

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

 

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 
97// A Repository configuration class
98 
99class Repository {
100 // {{{ Properties
101 
102 var $name;
103 var $svnName;
104 var $path;
105 var $group;
106 var $username;
107 var $password;
108 
109 // Local configuration options must start off unset
110 
111 var $allowDownload;
112 var $minDownloadLevel;
113 var $allowedExceptions = array();
114 var $disallowedExceptions = array();
115 var $rss;
116 var $spaces;
117 var $ignoreSvnMimeTypes;
118 var $ignoreWebSVNContentTypes;
119 var $bugtraq;
120 var $auth;
121 var $contentEnc;
122 var $templatePath;
123 
124 // }}}
125 
126 // {{{ __construct($name, $svnName, $path, [$group, [$username, [$password]]])
127 
128 function Repository($name, $svnName, $path, $group = NULL, $username = NULL, $password = NULL) {
129 $this->name = $name;
130 $this->svnName = $svnName;
131 $this->path = $path;
132 $this->group = $group;
133 $this->username = $username;
134 $this->password = $password;
135 }
136 
137 // }}}
138 
139 // {{{ getDisplayName()
140 
141 function getDisplayName() {
142 if (!empty($this->group)) {
143 return $this->group.".".$this->name;
144 }
145 
146 return $this->name;
147 }
148 
149 // }}}
150 
151 // {{{ svnParams
152 
153 function svnParams() {
154 if (!empty($this->username)) {
155 return " --username ".$this->username." --password ".$this->password." ";
156 }
157 
158 return " ";
159 }
160 
161 // }}}
162 
163 // Local configuration accessors
164 
165 // {{{ RSS Feed
166 
167 function hideRSS() {
168 $this->rss = false;
169 }
170 
171 function showRSS() {
172 $this->rss = true;
173 }
174 
175 function getHideRSS() {
176 global $config;
177 
178 if (isset($this->rss)) {
179 return $this->rss;
180 }
181 
182 return $config->getHideRSS();
183 }
184 
185 // }}}
186 
187 // {{{ Download
188 
189 function allowDownload() {
190 $this->allowDownload = true;
191 }
192 
193 function disallowDownload() {
194 $this->allowDownload = false;
195 }
196 
197 function getAllowDownload() {
198 global $config;
199 
200 if (isset($this->allowDownload)) {
201 return $this->allowDownload;
202 }
203 
204 return $config->getAllowDownload();
205 }
206 
207 function setMinDownloadLevel($level) {
208 $this->minDownloadLevel = $level;
209 }
210 
211 function getMinDownloadLevel() {
212 global $config;
213 
214 if (isset($this->minDownloadLevel)) {
215 return $this->minDownloadLevel;
216 }
217 
218 return $config->getMinDownloadLevel();
219 }
220 
221 function addAllowedDownloadException($path) {
222 if ($path{strlen($path) - 1} != "/") $path .= "/";
223 
224 $this->allowedExceptions[] = $path;
225 }
226 
227 function addDisallowedDownloadException($path) {
228 if ($path{strlen($path) - 1} != "/") $path .= "/";
229 
230 $this->disallowedExceptions[] = $path;
231 }
232 
233 function isDownloadAllowed($path) {
234 global $config;
235 
236 // Check global download option
237 if (!$this->getAllowDownload()) {
238 return false;
239 }
240 
241 // Check with access module
242 if (!$this->hasUnrestrictedReadAccess($path)) {
243 return false;
244 }
245 
246 $subs = explode("/", $path);
247 $level = count($subs) - 2;
248 if ($level >= $this->getMinDownloadLevel()) {
249 // Level OK, search for disallowed exceptions
250 
251 if ($config->findException($path, $this->disallowedExceptions)) {
252 return false;
253 }
254 
255 if ($config->findException($path, $config->disallowedExceptions)) {
256 return false;
257 }
258 
259 return true;
260 
261 } else {
262 // Level not OK, search for disallowed exceptions
263 
264 if ($config->findException($path, $this->allowedExceptions)) {
265 return true;
266 }
267 
268 if ($config->findException($path, $config->allowedExceptions)) {
269 return true;
270 }
271 
272 return false;
273 }
274 }
275 
276 // }}}
277 
278 // {{{ Templates
279 
280 function setTemplatePath($path) {
281 $lastchar = substr($path, -1, 1);
282 if (!($lastchar == DIRECTORY_SEPARATOR || $lastchar == '/' || $lastchar == '\\')) {
283 $path .= DIRECTORY_SEPARATOR;
284 }
285 
286 $this->templatePath = $path;
287 }
288 
289 function getTemplatePath() {
290 global $config;
291 if (!empty($this->templatePath)) {
292 return $this->templatePath;
293 }
294 
295 return $config->getTemplatePath();
296 }
297 
298 // }}}
299 
300 // {{{ Tab expansion
301 
302 function expandTabsBy($sp) {
303 $this->spaces = $sp;
304 }
305 
306 function getExpandTabsBy() {
307 global $config;
308 
309 if (isset($this->spaces)) {
310 return $this->spaces;
311 }
312 
313 return $config->getExpandTabsBy();
314 }
315 
316 // }}}
317 
318 // {{{ MIME-Type Handing
319 
320 function ignoreSvnMimeTypes() {
321 $this->ignoreSvnMimeTypes = true;
322 }
323 
324 function useSvnMimeTypes() {
325 $this->ignoreSvnMimeTypes = false;
326 }
327 
328 function getIgnoreSvnMimeTypes() {
329 global $config;
330 
331 if (isset($this->ignoreSvnMimeTypes)) {
332 return $this->ignoreSvnMimeTypes;
333 }
334 
335 return $config->getIgnoreSvnMimeTypes();
336 }
337 
338 function ignoreWebSVNContentTypes() {
339 $this->ignoreWebSVNContentTypes = true;
340 }
341 
342 function useWebSVNContentTypes() {
343 $this->ignoreWebSVNContentTypes = false;
344 }
345 
346 function getIgnoreWebSVNContentTypes() {
347 global $config;
348 
349 if (isset($this->ignoreWebSVNContentTypes)) {
350 return $this->ignoreWebSVNContentTypes;
351 }
352 
353 return $config->getIgnoreWebSVNContentTypes();
354 }
355 
356 // }}}
357 
358 // {{{ Issue Tracking
359 
360 function useBugtraqProperties() {
361 $this->bugtraq = true;
362 }
363 
364 function ignoreBugtraqProperties() {
365 $this->bugtraq = false;
366 }
367 
368 function getBugtraq() {
369 global $config;
370 
371 if (isset($this->bugtraq)) {
372 return $this->bugtraq;
373 }
374 
375 return $config->getBugtraq();
376 }
377 
378 // }}}
379 
380 // {{{ Encodings
381 
382 function setContentEncoding($contentEnc) {
383 $this->contentEnc = $contentEnc;
384 }
385 
386 function getContentEncoding() {
387 global $config;
388 
389 if (isset($this->contentEnc)) {
390 return $this->contentEnc;
391 }
392 
393 return $config->getContentEncoding();
394 }
395 
396 // }}}
397 
398 // {{{ Authentication
399 
400 function useAuthenticationFile($file) {
401 if (is_readable($file)) {
402 $this->auth = new Authentication($file);
403 } else {
404 die('Unable to read authentication file "'.$file.'"');
405 }
406 }
407 
408 function hasReadAccess($path, $checkSubFolders = false) {
409 global $config;
410 
411 $a = null;
412 if (isset($this->auth)) {
413 $a =& $this->auth;
414 } else {
415 $a =& $config->getAuth();
416 }
417 
418 if (!empty($a)) {
419 return $a->hasReadAccess($this->svnName, $path, $checkSubFolders);
420 }
421 
422 // No auth file - free access...
423 return true;
424 }
425 
426 function hasUnrestrictedReadAccess($path) {
427 global $config;
428 
429 $a = null;
430 if (isset($this->auth)) {
431 $a =& $this->auth;
432 } else {
433 $a =& $config->getAuth();
434 }
435 
436 if (!empty($a)) {
437 return $a->hasUnrestrictedReadAccess($this->svnName, $path);
438 }
439 
440 // No auth file - free access...
441 return true;
442 }
443 
444 // }}}
445 
446}
447 
448// The general configuration class
449 
450class WebSvnConfig {
451 // {{{ Properties
452 
453 // Tool path locations
454 
455 var $svnlook = "svnlook";
456 var $svn = "svn --non-interactive --config-dir /tmp";
457 var $svn_noparams = "svn --config-dir /tmp";
458 var $diff = "diff";
459 var $enscript ="enscript -q";
460 var $sed = "sed";
461 var $gzip = "gzip";
462 var $tar = "tar";
463 var $touch = "touch";
464 
465 // Other configuration items
466 
467 var $treeView = true;
468 var $flatIndex = true;
469 var $openTree = false;
470 var $showLastMod = true;
471 var $_showRepositorySelectionForm = true;
472 var $serverIsWindows = false;
473 var $multiViews = false;
474 var $useEnscript = false;
475 var $useGeshi = false;
476 var $allowDownload = false;
477 var $tarballTmpDir = 'temp';
478 var $minDownloadLevel = 0;
479 var $allowedExceptions = array();
480 var $disallowedExceptions = array();
481 var $rss = true;
482 var $spaces = 8;
483 var $bugtraq = false;
484 var $auth = "";
485 
486 var $templatePath = "./templates/Standard/";
487 
488 var $ignoreSvnMimeTypes = false;
489 var $ignoreWebSVNContentTypes = false;
490 
491 var $subversionMajorVersion = "";
492 var $subversionMinorVersion = "";
493 
494 // Default character encodings
495 var $inputEnc = ""; // Encoding of output returned from command line
496 var $contentEnc = ""; // Encoding of repository content
497 var $outputEnc = "UTF-8"; // Encoding of web page. Now forced to UTF-8
498 
499 var $defaultLanguage = 'en';
500 
501 var $quote = "'";
502 var $pathSeparator = ":";
503 
504 var $_repositories = array();
505 
506 // }}}
507 
508 // {{{ __construct()
509 
510 function WebSvnConfig() {
511 }
512 
513 // }}}
514 
515 // {{{ Repository configuration
516 
517 function addRepository($name, $url, $group = NULL, $username = NULL, $password = NULL) {
518 $url = str_replace(DIRECTORY_SEPARATOR, "/", $url);
519 
520 if ($url{strlen($url) - 1} == "/") {
521 $url = substr($url, 0, -1);
522 }
523 
524 $svnName = substr($url, strrpos($url, "/") + 1);
525 $this->_repositories[] = new Repository($name, $svnName, $url, $group, $username, $password);
526 }
527 
528 function getRepositories() {
529 return $this->_repositories;
530 }
531 
532 function &findRepository($name) {
533 foreach ($this->_repositories as $index => $rep) {
534 if (strcmp($rep->getDisplayName(), $name) == 0) {
535 $repref =& $this->_repositories[$index];
536 return $repref;
537 }
538 }
539 
540 print "ERROR: Unable to find repository '".htmlentities($name, ENT_QUOTES, 'UTF-8')."'";
541 exit;
542 }
543 
544 // }}}
545 
546 // {{{ setServerIsWindows
547 //
548 // The server is running on Windows
549 
550 function setServerIsWindows() {
551 $this->serverIsWindows = true;
552 
553 // Try to set the input encoding intelligently
554 
555 $cp = 0;
556 if ($cp = @shell_exec("CHCP")) {
557 $cp = trim(substr($cp, strpos($cp, ":") + 1));
558 settype($cp, "integer");
559 }
560 
561 // Use the most sensible default value if that failed
562 if ($cp == 0) $cp = 850;
563 
564 // We assume, as a default, that the encoding of the repository contents is
565 // in iso-8859-1, to be compatible with compilers and the like.
566 $this->setInputEncoding("CP$cp", "iso-8859-1");
567 
568 // On Windows machines, use double quotes around command line parameters
569 $this->quote = '"';
570 
571 // On Windows, semicolon separates path entries in a list rather than colon.
572 $this->pathSeparator = ";";
573 }
574 
575 // }}}
576 
577 // {{{ MultiViews
578 
579 // useMultiViews
580 //
581 // Use MultiViews to access the repository
582 
583 function useMultiViews() {
584 $this->multiViews = true;
585 }
586 
587 function getUseMultiViews() {
588 return $this->multiViews;
589 }
590 
591 // }}}
592 
593 // {{{ Enscript
594 
595 // useEnscript
596 //
597 // Use Enscript to colourise listings
598 
599 function useEnscript() {
600 $this->useEnscript = true;
601 }
602 
603 function getUseEnscript() {
604 return $this->useEnscript;
605 }
606 
607 // useGeshi
608 //
609 // Use GeSHi to colourise listings
610 function useGeshi() {
611 $this->useGeshi = true;
612 }
613 
614 function getUseGeshi() {
615 return $this->useGeshi;
616 }
617 
618 // }}}
619 
620 // {{{ RSS
621 
622 // offerRSS
623 //
624 // Use Enscript to colourise listings
625 
626 function hideRSS($myrep = 0) {
627 if (empty($myrep)) {
628 $this->rss = false;
629 } else {
630 $repo =& $this->findRepository($myrep);
631 $repo->hideRSS();
632 }
633 }
634 
635 function getHideRSS() {
636 return $this->rss;
637 }
638 
639 // }}}
640 
641 // {{{ Downloads
642 
643 // allowDownload
644 //
645 // Allow download of tarballs
646 
647 function allowDownload($myrep = 0) {
648 if (empty($myrep)) {
649 $this->allowDownload = true;
650 } else {
651 $repo =& $this->findRepository($myrep);
652 $repo->allowDownload();
653 }
654 }
655 
656 function disallowDownload($myrep = 0) {
657 if (empty($myrep)) {
658 $this->allowDownload = false;
659 } else {
660 $repo =& $this->findRepository($myrep);
661 $repo->disallowDownload();
662 }
663 }
664 
665 function getAllowDownload() {
666 return $this->allowDownload;
667 }
668 
669 function setTarballTmpDir($tmpdir) {
670 $this->tarballTmpDir = $tmpdir;
671 }
672 
673 function getTarballTmpDir() {
674 return $this->tarballTmpDir;
675 }
676 
677 function setMinDownloadLevel($level, $myrep = 0) {
678 if (empty($myrep)) {
679 $this->minDownloadLevel = $level;
680 } else {
681 $repo =& $this->findRepository($myrep);
682 $repo->setMinDownloadLevel($level);
683 }
684 }
685 
686 function getMinDownloadLevel() {
687 return $this->minDownloadLevel;
688 }
689 
690 function addAllowedDownloadException($path, $myrep = 0) {
691 if ($path{strlen($path) - 1} != "/") {
692 $path .= "/";
693 }
694 
695 if (empty($myrep)) {
696 $this->allowedExceptions[] = $path;
697 } else {
698 $repo =& $this->findRepository($myrep);
699 $repo->addAllowedDownloadException($path);
700 }
701 }
702 
703 function addDisallowedDownloadException($path, $myrep = 0) {
704 if ($path{strlen($path) - 1} != "/") {
705 $path .= "/";
706 }
707 
708 if (empty($myrep)) {
709 $this->disallowedExceptions[] = $path;
710 } else {
711 $repo =& $this->findRepository($myrep);
712 $repo->addDisallowedDownloadException($path);
713 }
714 }
715 
716 function findException($path, $exceptions) {
717 foreach ($exceptions As $key => $exc) {
718 if (strncmp($exc, $path, strlen($exc)) == 0) {
719 return true;
720 }
721 }
722 
723 return false;
724 }
725 
726 // }}}
727 
728 // {{{ getURL
729 //
730 // Get the URL to a path name based on the current config
731 
732 function getURL($rep, $path, $op) {
733 list($base, $params) = $this->getUrlParts($rep, $path, $op);
734 
735 $url = $base.'?';
736 foreach ($params as $k => $v) {
737 $url .= $k.'='.urlencode($v).'&amp;';
738 }
739 
740 return $url;
741 }
742 
743 // }}}
744 
745 // {{{ getUrlParts
746 //
747 // Get the Url and Parametes to a path name based on the current config
748 
749 function getUrlParts($rep, $path, $op) {
750 $params = array();
751 
752 if ($this->multiViews) {
753 $url = $_SERVER["SCRIPT_NAME"];
754 // Remove the .php
755 if (eregi(".php$", $url)) {
756 // Remove the .php
757 $url = substr($url, 0, -4);
758 }
759 
760 if ($path && $path{0} != "/") $path = "/".$path;
761 
762 if ($op == 'index') {
763 $url .= '/';
764 } else if (is_object($rep)) {
765 $url .= "/".$rep->getDisplayName().str_replace('%2F', '/', rawurlencode($path));
766 
767 if ($op != "dir" && $op != "file") {
768 $params['op'] = $op;
769 }
770 }
771 
772 return array($url, $params);
773 
774 } else {
775 switch ($op) {
776 case "index":
777 $fname = ".";
778 break;
779 
780 case "dir":
781 $fname = "listing.php";
782 break;
783 
784 case "revision":
785 $fname = "revision.php";
786 break;
787 
788 case "file":
789 $fname = "filedetails.php";
790 break;
791 
792 case "log":
793 $fname = "log.php";
794 break;
795 
796 case "diff":
797 $fname = "diff.php";
798 break;
799 
800 case "blame":
801 $fname = "blame.php";
802 break;
803 
804 case "form":
805 $fname = "form.php";
806 break;
807 
808 case "rss":
809 $fname = "rss.php";
810 break;
811 
812 case "dl":
813 $fname = "dl.php";
814 break;
815 
816 case "comp":
817 $fname = "comp.php";
818 break;
819 }
820 
821 if ($rep === -1) {
822 $params['path'] = $path;
823 } else if ($op != 'index') {
824 $params['repname'] = $rep->getDisplayName();
825 $params['path'] = $path;
826 }
827 
828 return array($fname, $params);
829 }
830 }
831 
832 // }}}
833 
834 // {{{ Paths and Commands
835 
836 // setPath
837 //
838 // Set the location of the given path
839 
840 function setPath(&$var, $path, $name, $params = '') {
841 if ($path == '') {
842 // Search in system search path. No check for existence possible
843 $var = $name;
844 } else {
845 $lastchar = substr($path, -1, 1);
846 $isDir = ($lastchar == DIRECTORY_SEPARATOR || $lastchar == '/' || $lastchar == '\\');
847 
848 if (!$isDir) $path .= DIRECTORY_SEPARATOR;
849 
850 if (($this->serverIsWindows && !file_exists($path.$name.'.exe')) || (!$this->serverIsWindows && !file_exists($path.$name))) {
851 echo "Unable to find '$name' tool at location '$path$name'";
852 exit;
853 }
854 
855 // On a windows machine we need to put spaces around the entire command
856 // to allow for spaces in the path
857 if ($this->serverIsWindows) {
858 $var = '"'.$path.$name.'"';
859 } else {
860 $var = $path.$name;
861 }
862 }
863 
864 // Append parameters
865 if ($params != '') $var .= ' '.$params;
866 }
867 
868 // setSVNCommandPath
869 //
870 // Define the location of the svn and svnlook commands
871 
872 function setSVNCommandPath($path) {
873 $this->setPath($this->svn, $path, "svn", "--non-interactive --config-dir /tmp");
874 $this->setPath($this->svn_noparams, $path, "svn", " --config-dir /tmp");
875 $this->setPath($this->svnlook, $path, "svnlook");
876 }
877 
878 function getSvnCommand() {
879 return $this->svn;
880 }
881 
882 function getCleanSvnCommand() {
883 return $this->svn_noparams;
884 }
885 
886 function getSvnlookCommand() {
887 return $this->svnlook;
888 }
889 
890 // setDiffPath
891 //
892 // Define the location of the diff command
893 
894 function setDiffPath($path) {
895 $this->setPath($this->diff, $path, "diff");
896 }
897 
898 function getDiffCommand() {
899 return $this->diff;
900 }
901 
902 // setEnscriptPath
903 //
904 // Define the location of the enscript command
905 
906 function setEnscriptPath($path) {
907 $this->setPath($this->enscript, $path, "enscript");
908 }
909 
910 function getEnscriptCommand() {
911 return $this->enscript;
912 }
913 
914 // setSedPath
915 //
916 // Define the location of the sed command
917 
918 function setSedPath($path) {
919 $this->setPath($this->sed, $path, "sed");
920 }
921 
922 function getSedCommand() {
923 return $this->sed;
924 }
925 
926 // setTarPath
927 //
928 // Define the location of the tar command
929 
930 function setTarPath($path) {
931 $this->setPath($this->tar, $path, "tar");
932 }
933 
934 function getTarCommand() {
935 return $this->tar;
936 }
937 
938 // setGzipPath
939 //
940 // Define the location of the GZip command
941 
942 function setGzipPath($path) {
943 $this->setPath($this->gzip, $path, "gzip");
944 }
945 
946 function getGzipCommand() {
947 return $this->gzip;
948 }
949 
950 // Templates
951 
952 function setTemplatePath($path, $myrep = 0) {
953 if (empty($myrep)) {
954 $lastchar = substr($path, -1, 1);
955 if (!($lastchar == DIRECTORY_SEPARATOR || $lastchar == '/' || $lastchar == '\\')) {
956 $path .= DIRECTORY_SEPARATOR;
957 }
958 
959 $this->templatePath = $path;
960 } else {
961 $repo =& $this->findRepository($myrep);
962 $repo->setTemplatePath($path);
963 }
964 }
965 
966 function getTemplatePath() {
967 return $this->templatePath;
968 }
969 
970 // }}}
971 
972 // {{{ parentPath
973 //
974 // Automatically set up the repositories based on a parent path
975 
976 function parentPath($path, $group = NULL, $pattern = false, $skipAlreadyAdded = true) {
977 if ($handle = @opendir($path)) {
978 // For each file...
979 while (false !== ($file = readdir($handle))) {
980 // That's also a non hidden directory
981 if ($file{0} != '.' && is_dir($path.DIRECTORY_SEPARATOR.$file) && is_readable($path.DIRECTORY_SEPARATOR.$file)) {
982 // And that contains a db directory (in an attempt to not include
983 // non svn repositories.
984 
985 if (is_dir($path.DIRECTORY_SEPARATOR.$file.DIRECTORY_SEPARATOR."db") && is_readable($path.DIRECTORY_SEPARATOR.$file.DIRECTORY_SEPARATOR."db")) {
986 // And matches the pattern if specified
987 if ($pattern === false || preg_match($pattern, $file)) {
988 $name = 'file:///'.$path.DIRECTORY_SEPARATOR.$file;
989 $add = true;
990 // And has not already been added if specified
991 if ($skipAlreadyAdded) {
992 $url = str_replace(DIRECTORY_SEPARATOR, '/', $name);
993 if ($url{strlen($url) - 1} == '/') $url = substr($url, 0, -1);
994 $url = substr($url, strrpos($url, '/') + 1);
995 foreach ($this->getRepositories() as $rep) {
996 if ($rep->svnName == $url) {
997 $add = false;
998 break;
999 }
1000 }
1001 }
1002 if ($add) {
1003 // We add the repository to the list
1004 $this->addRepository($file, $name, $group);
1005 }
1006 }
1007 }
1008 }
1009 }
1010 closedir($handle);
1011 }
1012 
1013 // Sort the repositories into alphabetical order
1014 
1015 if (!empty($this->_repositories)) {
1016 usort($this->_repositories, "cmpReps");
1017 }
1018 }
1019 
1020 // }}}
1021 
1022 // {{{ Encoding functions
1023 
1024 function setInputEncoding($systemEnc) {
1025 $this->inputEnc = $systemEnc;
1026 
1027 if (!isset($this->contentEnc)) {
1028 $this->contentEnc = $systemEnc;
1029 }
1030 }
1031 
1032 function getInputEncoding() {
1033 return $this->inputEnc;
1034 }
1035 
1036 function setContentEncoding($contentEnc, $myrep = 0) {
1037 if (empty($myrep)) {
1038 $this->contentEnc = $contentEnc;
1039 } else {
1040 $repo =& $this->findRepository($myrep);
1041 $repo->setContentEncoding($contentEnc);
1042 }
1043 }
1044 
1045 function getContentEncoding() {
1046 return $this->contentEnc;
1047 }
1048 
1049 // }}}
1050 
1051 function setDefaultLanguage($language) {
1052 $this->defaultLanguage = $language;
1053 }
1054 
1055 function getDefaultLanguage() {
1056 return $this->defaultLanguage;
1057 }
1058 
1059 // {{{ Tab expansion functions
1060 
1061 function expandTabsBy($sp, $myrep = 0) {
1062 if (empty($myrep)) {
1063 $this->spaces = $sp;
1064 } else {
1065 $repo =& $this->findRepository($myrep);
1066 $repo->expandTabsBy($sp);
1067 }
1068 }
1069 
1070 function getExpandTabsBy() {
1071 return $this->spaces;
1072 }
1073 
1074 // }}}
1075 
1076 // {{{ Misc settings
1077 
1078 function ignoreSvnMimeTypes() {
1079 $this->ignoreSvnMimeTypes = true;
1080 }
1081 
1082 function getIgnoreSvnMimeTypes() {
1083 return $this->ignoreSvnMimeTypes;
1084 }
1085 
1086 function ignoreWebSVNContentTypes() {
1087 $this->ignoreWebSVNContentTypes = true;
1088 }
1089 
1090 function getIgnoreWebSVNContentTypes() {
1091 return $this->ignoreWebSVNContentTypes;
1092 }
1093 
1094 function useBugtraqProperties($myrep = 0) {
1095 if (empty($myrep)) {
1096 $this->bugtraq = true;
1097 } else {
1098 $repo =& $this->findRepository($myrep);
1099 $repo->useBugtraqProperties();
1100 }
1101 }
1102 
1103 function getBugtraq() {
1104 return $this->bugtraq;
1105 }
1106 
1107 function useAuthenticationFile($file, $myrep = 0) {
1108 if (empty($myrep)) {
1109 if (is_readable($file)) {
1110 $this->auth = new Authentication($file);
1111 } else {
1112 echo "Unable to read authentication file '$file'";
1113 exit;
1114 }
1115 } else {
1116 $repo =& $this->findRepository($myrep);
1117 $repo->useAuthenticationFile($file);
1118 }
1119 }
1120 
1121 function &getAuth() {
1122 return $this->auth;
1123 }
1124 
1125 function useTreeView() {
1126 $this->treeView = true;
1127 }
1128 
1129 function getUseTreeView() {
1130 return $this->treeView;
1131 }
1132 
1133 function useFlatView() {
1134 $this->treeView = false;
1135 }
1136 
1137 function useTreeIndex($open) {
1138 $this->flatIndex = false;
1139 $this->openTree = $open;
1140 }
1141 
1142 function getUseFlatIndex() {
1143 return $this->flatIndex;
1144 }
1145 
1146 function getOpenTree() {
1147 return $this->openTree;
1148 }
1149 
1150 function showLastModInListing() {
1151 return $this->showLastMod;
1152 }
1153 
1154 function setShowLastModInListing($show) {
1155 $this->showLastMod = $show;
1156 }
1157 
1158 function showRepositorySelectionForm() {
1159 return $this->_showRepositorySelectionForm;
1160 }
1161 
1162 function setShowRepositorySelectionForm($show) {
1163 $this->_showRepositorySelectionForm = $show;
1164 }
1165 
1166 // setSubversionMajorVersion
1167 //
1168 // Set subversion major version
1169 
1170 function setSubversionMajorVersion($subversionMajorVersion) {
1171 $this->subversionMajorVersion = $subversionMajorVersion;
1172 }
1173 
1174 function getSubversionMajorVersion() {
1175 return $this->subversionMajorVersion;
1176 }
1177 
1178 // setSubversionMinorVersion
1179 //
1180 // Set subversion minor version
1181 
1182 function setSubversionMinorVersion($subversionMinorVersion) {
1183 $this->subversionMinorVersion = $subversionMinorVersion;
1184 }
1185 
1186 function getSubversionMinorVersion() {
1187 return $this->subversionMinorVersion;
1188 }
1189 
1190 // }}}
1191 
1192 // {{{ Sort the repostories
1193 //
1194 // This function sorts the repositories by group name. The contents of the
1195 // group are left in there original order, which will either be sorted if the
1196 // group was added using the parentPath function, or defined for the order in
1197 // which the repositories were included in the user's config file.
1198 //
1199 // Note that as of PHP 4.0.6 the usort command no longer preserves the order
1200 // of items that are considered equal (in our case, part of the same group).
1201 // The mergesort function preserves this order.
1202 
1203 function sortByGroup() {
1204 if (!empty($this->_repositories))
1205 mergesort($this->_repositories, "cmpGroups");
1206 }
1207 
1208 // }}}
1209}

Powered by WebSVN 2.2.1