/**
  * scan a folder for music
  * @param string $path
  * @return int the number of songs found
  */
 public static function scanFolder($path)
 {
     if (OC_Filesystem::is_dir($path)) {
         $songs = 0;
         if ($dh = OC_Filesystem::opendir($path)) {
             while (($filename = readdir($dh)) !== false) {
                 if ($filename != '.' and $filename != '..' and substr($filename, 0, 1) != '.') {
                     $file = $path . '/' . $filename;
                     if (OC_Filesystem::is_dir($file)) {
                         $songs += self::scanFolder($file);
                     } elseif (OC_Filesystem::is_file($file)) {
                         $data = self::scanFile($file);
                         if ($data) {
                             $songs++;
                         }
                     }
                 }
             }
         }
     } elseif (OC_Filesystem::is_file($path)) {
         $songs = 1;
         self::scanFile($path);
     } else {
         $songs = 0;
     }
     return $songs;
 }
Ejemplo n.º 2
0
 /**
  * Compress File or Folder
  * @param $target The target to compress
  * @return Boolean  
  */
 public static function compressTarget($target)
 {
     $oc_target = OC::$CONFIG_DATADIRECTORY . $target;
     if (OC_Filesystem::is_file($target)) {
         $fileinfo = pathinfo($oc_target);
         $archiveName = $fileinfo['filename'];
         $dirTarget = $fileinfo['dirname'];
     } else {
         $archiveName = basename($oc_target);
         $dirTarget = dirname($oc_target);
     }
     $archiveName .= '.zip';
     if (file_exists($dirTarget . '/' . $archiveName)) {
         $archiveName = md5(rand()) . '_' . $archiveName;
     }
     $zip = new ZipArchive();
     if ($zip->open($dirTarget . '/' . $archiveName, ZipArchive::CREATE) === TRUE) {
         if (!is_dir($oc_target)) {
             $zip->addFile($oc_target, basename($oc_target));
         } else {
             self::addFolderToZip($oc_target, $zip, basename($oc_target) . '/');
         }
     }
     $zip->close();
 }
Ejemplo n.º 3
0
 /**
  * Compress File or Folder
  * @param $target The target to compress
  * @return Boolean  
  */
 public static function compressTarget($target)
 {
     $oc_target = OC::$CONFIG_DATADIRECTORY . $target;
     if (OC_Filesystem::is_file($target)) {
         $fileinfo = pathinfo($oc_target);
         $archiveName = $fileinfo['filename'];
         $dirTarget = $fileinfo['dirname'];
     } else {
         $archiveName = basename($oc_target);
         $dirTarget = dirname($oc_target);
     }
     $archiveName .= '.tar';
     if (file_exists($dirTarget . '/' . $archiveName)) {
         $archiveName = md5(rand()) . '_' . $archiveName;
     }
     require_once '../config/config.php';
     exec($_CompressConf['tar_bin_path'] . " cf " . $dirTarget . '/' . $archiveName . " " . $oc_target);
     exec($_CompressConf['gzip_bin_path'] . " -9 " . $dirTarget . '/' . $archiveName);
 }
Ejemplo n.º 4
0
 public static function zipAddDir($dir, $zip, $internalDir = '')
 {
     $dirname = basename($dir);
     $zip->addEmptyDir($internalDir . $dirname);
     $internalDir .= $dirname .= '/';
     $files = OC_Files::getdirectorycontent($dir);
     foreach ($files as $file) {
         $filename = $file['name'];
         $file = $dir . '/' . $filename;
         if (OC_Filesystem::is_file($file)) {
             $tmpFile = OC_Filesystem::toTmpFile($file);
             OC_Files::$tmpFiles[] = $tmpFile;
             $zip->addFile($tmpFile, $internalDir . $filename);
         } elseif (OC_Filesystem::is_dir($file)) {
             self::zipAddDir($file, $zip, $internalDir);
         }
     }
 }
Ejemplo n.º 5
0
        header('WWW-Authenticate: Basic realm="ownCloud Server"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'Valid credentials must be supplied';
        exit;
    } else {
        if (!OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) {
            exit;
        }
    }
}
list($type, $file) = explode('/', substr($path_info, 1 + strlen($service) + 1), 2);
if ($type != 'oc_chunked') {
    OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
    die;
}
if (!OC_Filesystem::is_file($file)) {
    OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
    die;
}
switch ($_SERVER['REQUEST_METHOD']) {
    case 'PUT':
        $input = fopen("php://input", "r");
        $org_file = OC_Filesystem::fopen($file, 'rb');
        $info = array('name' => basename($file));
        $sync = new OC_FileChunking($info);
        $result = $sync->signature_split($org_file, $input);
        echo json_encode($result);
        break;
    default:
        OC_Response::setStatus(OC_Response::STATUS_NOT_FOUND);
}
Ejemplo n.º 6
0
 * 
 * Copyright 2013 EnginSoft S.p.A.
 * All rights reserved
 */
$filename = $_POST['filename'];
$json = false;
if (isset($_POST['json'])) {
    $json = (bool) $_POST["json"];
}
/*
 * max size of output file, to avoid reading a very big output and clogging the network
 */
$MAX_SIZE = 1024 * 512;
# "512k of memory should be enough for everyone"
$content = "";
if (OC_Filesystem::is_file($filename) && OC_Filesystem::is_readable($filename)) {
    if (OC_Filesystem::filesize($filename) > $MAX_SIZE) {
        $handle = OC_Filesystem::fopen($filename, "r");
        if ($handle) {
            $content = fread($handle, $MAX_SIZE);
            fclose($handle);
        }
    } else {
        $content = OC_Filesystem::file_get_contents($filename);
    }
} else {
    echo "ERROR: Cannot read " . $filename;
}
if ($json) {
    $json_obj = json_decode($content);
    foreach ($json_obj as $key => $value) {
Ejemplo n.º 7
0
/**
 * Returns an associative array with the info associated with a running job
 * the array contains the keys:
 * status (either RUNNING, KILLED, FINISHED)
 * pid (numeric)
 * start_date
 * 
 * if the $study parameter does not represent a valid case study, or if $jobid does not exist
 * or if the 
 * 
 * @param type $study
 * @param type $jobid
 * @return array an array with the job info, containing the key "pid", "job_id"
 */
function get_job_info($study, $jobid)
{
    $path = get_job_info_file($study, $jobid);
    if (OC_Filesystem::is_file($path)) {
        $json = OC_Filesystem::file_get_contents($path);
        return json_decode($json, true);
        // true for returning an associative array
    } else {
        return false;
    }
}