Esempio n. 1
0
 public static function getGitConfig($repo_path)
 {
     if (DirectoryHelper::isGitClone($repo_path)) {
         $repo_config_file = DirectoryHelper::slashDirname($repo_path) . DirectoryHelper::slashDirname('.git') . 'config';
         if (file_exists($repo_config_file)) {
             try {
                 $config = parse_ini_file($repo_config_file, true);
                 return $config;
             } catch (\Exception $e) {
             }
         }
     }
     return null;
 }
Esempio n. 2
0
 public function getDocBookScanStack($recursive = false)
 {
     if (!isset($this->cache['docbook_scan_stack'])) {
         $dir = new DocBookRecursiveDirectoryIterator($this->getRealPath());
         $hasWip = false;
         $paths = $known_filenames = array();
         foreach ($dir as $file) {
             /* @var \DocBook\\WebFilesystem\\DocBookFile $file */
             $filename = $lang = null;
             if ($file->isDir() && $file->getBasename() === FrontController::WIP_DIR) {
                 $hasWip = true;
             } else {
                 if ($file->isLink()) {
                     $filename_real = basename($file->getRealPath());
                     if (strpos($filename_real, '.') !== false) {
                         $filename_parts = explode('.', $filename_real);
                         $filename = array_shift($filename_parts);
                         $lang = array_shift($filename_parts);
                         if ($lang === 'md') {
                             $lang = null;
                         }
                     }
                 } elseif ($file->isFile()) {
                     $filename_parts = explode('.', $file->getBasename());
                     $filename = array_shift($filename_parts);
                     $lang = array_shift($filename_parts);
                     if ($lang === 'md') {
                         $lang = null;
                     }
                 } else {
                     $filename = $file->getBasename();
                 }
                 if (array_key_exists($filename, $paths) && !empty($lang)) {
                     $paths[$filename]['trads'][$lang] = Helper::getRoute($file->getRealPath());
                 } elseif (array_key_exists($filename, $paths)) {
                     $original = $paths[$filename];
                     $dbfile = new DocBookFile($file);
                     $paths[$filename] = $dbfile->getDocBookStack();
                     $paths[$filename]['trads'] = isset($original['trads']) ? $original['trads'] : array();
                     if ($file->isDir() && $recursive) {
                         $dirscan = $dbfile->getDocBookScanStack(true);
                         $paths[$filename] = array_merge($paths[$filename], $dirscan);
                     }
                 } else {
                     $dbfile = new DocBookFile($file);
                     if ($this->isDir() && $this->isLink()) {
                         $dbfile->setIsRootLink(true);
                     }
                     $paths[$filename] = $dbfile->getDocBookStack();
                     if ($file->isDir() && $recursive) {
                         $dirscan = $dbfile->getDocBookScanStack(true);
                         $paths[$filename] = array_merge($paths[$filename], $dirscan);
                     }
                     if (!empty($lang)) {
                         $paths[$filename]['trads'][$lang] = Helper::getRoute($file->getRealPath());
                     }
                 }
             }
         }
         $dir_is_clone = DirectoryHelper::isGitClone($dir->getPath());
         $remote = null;
         if ($dir_is_clone) {
             $git_config = Helper::getGitConfig($dir->getPath());
             if (!empty($git_config) && isset($git_config['remote origin']) && isset($git_config['remote origin']['url'])) {
                 $remote = $git_config['remote origin']['url'];
             }
         }
         $this->cache['docbook_scan_stack'] = array('dirname' => $this->getHumanReadableFilename(), 'dirpath' => $this->getDocBookPath(), 'dir_has_wip' => $hasWip, 'dir_is_clone' => $dir_is_clone, 'clone_remote' => $remote, 'dirscan' => $paths);
     }
     return $this->cache['docbook_scan_stack'];
 }