@@ -568,4 +568,83 @@ public function parseDrupalSiteName($civicrm_root) {
568
568
return $ siteName ;
569
569
}
570
570
571
+ /**
572
+ * @var $basepath String cached basepath to prevent having to parse it repeatedly.
573
+ **/
574
+ protected $ basepath ;
575
+
576
+ /**
577
+ * @var $filesUrl String holds resolved path.
578
+ **/
579
+ protected $ filesUrl ;
580
+
581
+ /**
582
+ * checkBasePath - Returns root directory with respect to $civicrm_root
583
+ *
584
+ * @param $root String
585
+ * @param $seek String
586
+ **/
587
+ public function checkBasePath ($ root , $ seek = "/sites/ " )
588
+ {
589
+ if (!isset ($ this ->basepath )) {
590
+ $ this ->basepath = substr ($ root , 0 , stripos ($ root , $ seek )+1 );
591
+ }
592
+
593
+ return $ this ->basepath ;
594
+ }
595
+
596
+ /**
597
+ * check if files exist in path. Just a simple helper function for viewing
598
+ * existence of sites.
599
+ *
600
+ * @param $basepath string
601
+ * @param $basepath string
602
+ **/
603
+ private function checkFilesExists ($ basepath , $ folder ) {
604
+ return file_exists ("{$ basepath }sites/ $ folder/files/civicrm/ " );
605
+ }
606
+
607
+ /**
608
+ * Returns the concatenated url for existing path.
609
+ *
610
+ * @param $baseUrl string
611
+ * @param $folder string
612
+ **/
613
+ private function getUrl ($ baseUrl , $ folder ) {
614
+ return "{$ baseUrl }sites/ $ folder/files/civicrm/ " ;
615
+ }
616
+
617
+ /**
618
+ * Returns the location of /sites/SITENAME/files/civicrm depending
619
+ * on system configuration.
620
+ *
621
+ * @fixed CRM-19303
622
+ * @param $root string
623
+ * @param $baseUrl string
624
+ * @param $default string
625
+ **/
626
+ public function checkMultisite ($ root , $ baseUrl , $ default = "default " ) {
627
+ if (isset ($ this ->filesUrl )) return $ this ->filesUrl ;
628
+
629
+ $ basepath = $ this ->checkBasePath ($ root );
630
+ $ correct = null ;
631
+ if ($ this ->checkFilesExists ($ root , $ default )) {
632
+ $ correct = $ default ;
633
+ }
634
+ else {
635
+ //Check for any other directories if default doesn't exist.
636
+ $ folders = scandir ($ basepath .'sites/ ' );
637
+ foreach ($ folders as $ folder ) {
638
+ //Ignore hidden directories/files...
639
+ if (strpos ($ folder ,'. ' ) === 0 || $ folder == 'all ' ) continue ;
640
+ //Check if it is a directory
641
+ if (!is_dir ($ basepath .'sites/ ' .$ folder )) continue ;
642
+
643
+ //Check if files path exists...
644
+ if ($ this ->checkFilesExists ($ basepath , $ folder )) {
645
+ $ correct = $ folder ;
646
+ break ;
647
+ }
648
+ }
649
+ }
571
650
}
0 commit comments