示例#1
0
 /**
  * searches defined files in a given path recursivly
  *
  * @throws Exception raised if the search directory cant be read
  * @param string search in this path
  * @param string optional: regular expression for files
  * @param integer optional: maximum search in this depth (0 is infinite)
  * @return void
  */
 public static function searchFiles($path, $searchRegex = '', $pathDepth = 0)
 {
     if (!($fhd = @opendir($path))) {
         throw new Exception('directory "' . $path . '" cant be read');
     }
     $fileArray = array();
     while ($file = readdir($fhd)) {
         $filePath = $path . '/' . $file;
         // ignore links and point directories
         if (preg_match('/^\\.{1,2}$/', $file) || is_link($filePath)) {
             continue;
         }
         // save path to file or continue
         if (is_file($filePath)) {
             if (empty($searchRegex)) {
                 $fileArray[] = $filePath;
             } elseif (preg_match($searchRegex, $file)) {
                 $fileArray[] = $filePath;
             }
             continue;
         }
         // breakpoint, if pathDepth is reached
         if ($pathDepth <= 1 && $pathDepth != 0) {
             continue;
         }
         // next dir
         if (is_dir($filePath)) {
             $fileArray = array_merge($fileArray, sgLib::searchFiles($filePath, $searchRegex, $pathDepth - 1));
         }
     }
     closedir($fhd);
     return $fileArray;
 }
示例#2
0
 /**
  * adds items to the MOD_MENU array. Used for the language file menu selector.
  *
  * @throws LFException raised if no language files are found
  * @return void
  */
 private function menuLangFileList()
 {
     // check
     if (empty($this->MOD_SETTINGS['extList'])) {
         throw new LFException('failure.search.noLangFile');
     }
     // search and prepare files
     try {
         $files = sgLib::searchFiles($this->MOD_SETTINGS['extList'], $this->extConfig['searchRegex'], $this->extConfig['searchPathDepth']);
     } catch (Exception $e) {
         throw new LFException('failure.search.noLangFile', 0, '(' . $e->getMessage() . ')');
     }
     if (is_array($files) && count($files)) {
         foreach ($files as $file) {
             $filename = substr($file, strlen($this->MOD_SETTINGS['extList']) + 1);
             $fileArray[$filename] = $filename;
         }
     } else {
         throw new LFException('failure.search.noLangFile');
     }
     // create list
     $this->MOD_MENU = array('langFileList' => $fileArray);
     parent::menuConfig();
 }