예제 #1
0
 /**
  * check $path for updates
  *
  * @param string $path
  */
 public function checkUpdate($path)
 {
     $cachedEntry = $this->cache->get($path);
     if ($this->storage->hasUpdated($path, $cachedEntry['mtime'])) {
         if ($this->storage->is_dir($path)) {
             $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
         } else {
             $this->scanner->scanFile($path);
         }
         if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
             $this->cleanFolder($path);
         }
         $this->cache->correctFolderSize($path);
     }
 }
예제 #2
0
 /**
  * Function to start a scan in a directory.
  * @return Array
  * @throws DirectoryNotFoundException
  */
 public static function scanDir($parentDirectory)
 {
     $occurences = array(array());
     //if the directory/file does not exists, then throw and error.
     if (!file_exists($parentDirectory)) {
         throw new DirectoryORFileNotFoundException("ERROR: Directory not found!");
     }
     //get the list of all the files inside this directory.
     $allFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($parentDirectory));
     $fileList = array();
     //remove (.), (..) and directories from the list of all files so that only files are left.
     while ($allFiles->valid()) {
         if (!$allFiles->isDot()) {
             if (!is_dir($allFiles->key())) {
                 array_push($fileList, $allFiles->key());
             }
         }
         $allFiles->next();
     }
     $i = 0;
     foreach ($fileList as $file) {
         if (pathinfo($file, PATHINFO_EXTENSION) != "php") {
             continue;
         }
         $occurences[$i]['file'] = realpath($file);
         $occurences[$i]['result'] = Scanner::scanFile($file);
         $i++;
     }
     return $occurences;
 }
예제 #3
0
파일: watcher.php 프로젝트: sunblade/core
 /**
  * Update the cache for changes to $path
  *
  * @param string $path
  * @param array $cachedData
  */
 public function update($path, $cachedData)
 {
     if ($this->storage->is_dir($path)) {
         $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
     } else {
         $this->scanner->scanFile($path);
     }
     if ($cachedData['mimetype'] === 'httpd/unix-directory') {
         $this->cleanFolder($path);
     }
     $this->cache->correctFolderSize($path);
 }
예제 #4
0
 /**
  * check $path for updates
  *
  * @param string $path
  * @return boolean|array true if path was updated, otherwise the cached data is returned
  */
 public function checkUpdate($path)
 {
     if ($this->watchPolicy === self::CHECK_ALWAYS or $this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false) {
         $cachedEntry = $this->cache->get($path);
         $this->checkedPaths[] = $path;
         if ($this->storage->hasUpdated($path, $cachedEntry['storage_mtime'])) {
             if ($this->storage->is_dir($path)) {
                 $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
             } else {
                 $this->scanner->scanFile($path);
             }
             if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
                 $this->cleanFolder($path);
             }
             $this->cache->correctFolderSize($path);
             return true;
         }
         return $cachedEntry;
     } else {
         return false;
     }
 }
예제 #5
0
 /**
  *
  */
 public static function updateFile($params)
 {
     $path = $params['path'];
     if (!$path) {
         return;
     }
     //fix a bug where there were multiply '/' in front of the path, it should only be one
     while ($path[0] == '/') {
         $path = substr($path, 1);
     }
     $path = '/' . $path;
     $collection = new Collection(\OCP\User::getUser());
     $scanner = new Scanner($collection);
     $scanner->scanFile($path);
 }
예제 #6
0
                    $f2s = $key . '/' . $val;
                    if (substr($f2s, -3) == 'php') {
                        $output .= 'File: ' . $f2s . PHP_EOL;
                    }
                }
            }
        }
    } else {
        $info = new SplFileInfo($o2s);
        $perms = substr(sprintf('%o', $info->getPerms()), -4);
        $owner = $info->getOwner();
        $group = $info->getGroup();
        $type = $info->getType();
        $size = $info->getSize();
        $scanner = new Scanner($o2s, $eol, $htmlMode, $scannerOptions);
        $scanner->scanFile("all", $patternData, $stringData);
        if (count($scanner->found)) {
            foreach ($scanner->found as $l) {
                $found .= $l;
            }
        } else {
            $found = '';
        }
        //make human readable size
        $size = $scanner->size_readable($size);
    }
} else {
    $ainfo = "The file/folder {$bS}{$o2s}{$bE} does not exist";
}
//translate . to path if o2s eq .
if ($o2s == '.') {
예제 #7
0
//add steps
include_once 'lib/step_simplestring.php';
$scanner->addStep(new StepSimplestring($scanner, $log));
include_once 'lib/step_simplepattern.php';
$scanner->addStep(new StepSimplepattern($scanner, $log));
include_once 'lib/step_preg.php';
$scanner->addStep(new StepPreg($scanner, $log));
include_once 'lib/step_wp.php';
$scanner->addStep(new StepWP($scanner, $log));
include_once 'lib/step_comments.php';
$scanner->addStep(new StepComments($scanner, $log));
//run scan
$filenum = count($scanner->files);
$log->logHeader();
$log->logNormal('Scanning: ' . $filenum . " file(s)", 0);
//parse in steps
$scanner->prepareSteps();
//real scan
$at = 0;
foreach ($scanner->files as $onefile) {
    $log->logFilename($onefile);
    $scanner->setNewf2s($onefile);
    $scanner->scanFile();
    $at++;
    $log->logUpdateStatus($filenum, $at);
}
$log->logFooter($filenum, $scanner);
//write log at the end
if ($scanner->nologfile == false) {
    $log->flushLogToFile();
}
예제 #8
0
파일: api.php 프로젝트: CDN-Sparks/owncloud
 case 'get_artists':
     \OCP\JSON::encodedPrint($collection->getArtists($arguments['search']));
     break;
 case 'get_albums':
     \OCP\JSON::encodedPrint($collection->getAlbums($arguments['artist'], $arguments['search']));
     break;
 case 'get_songs':
     \OCP\JSON::encodedPrint($collection->getSongs($arguments['artist'], $arguments['album'], $arguments['search']));
     break;
 case 'get_path_info':
     if (\OC\Files\Filesystem::file_exists($arguments['path'])) {
         $songId = $collection->getSongByPath($arguments['path']);
         if ($songId == 0) {
             unset($_SESSION['collection']);
             $scanner = new Scanner($collection);
             $songId = $scanner->scanFile($arguments['path']);
         }
         if ($songId > 0) {
             $song = $collection->getSong($songId);
             $song['artist'] = $collection->getArtistName($song['song_artist']);
             $song['album'] = $collection->getAlbumName($song['song_album']);
             \OCP\JSON::encodedPrint($song);
         }
     }
     break;
 case 'play':
     $ftype = \OC\Files\Filesystem::getMimeType($arguments['path']);
     if (substr($ftype, 0, 5) != 'audio' and $ftype != 'application/ogg') {
         echo 'Not an audio file';
         exit;
     }