/** * 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; }
function search($query) { $files = OC_Filesystem::search($query); $results = array(); foreach ($files as $file) { if (OC_Filesystem::is_dir($file)) { $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'index.php?dir=' . $file), 'Files'); } else { $mime = OC_Filesystem::getMimeType($file); $mimeBase = substr($mime, 0, strpos($mime, '/')); switch ($mimeBase) { case 'audio': break; case 'text': $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Text'); break; case 'image': $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Images'); break; default: if ($mime == 'application/xml') { $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Text'); } else { $results[] = new OC_Search_Result(basename($file), '', OC_Helper::linkTo('files', 'download.php?file=' . $file), 'Files'); } } } } return $results; }
public function __construct($arguments) { $this->datadir = $arguments['datadir']; if (OC_Share::getItemsInFolder($this->datadir)) { if (!OC_Filesystem::is_dir($this->datadir)) { OC_Filesystem::mkdir($this->datadir); } } else { if (OC_Filesystem::is_dir($this->datadir)) { OC_Filesystem::rmdir($this->datadir); } } $this->datadir .= "/"; }
/** * Returns an array with all the child nodes * * @return Sabre_DAV_INode[] */ public function getChildren() { $nodes = array(); // foreach(scandir($this->path) as $node) if($node!='.' && $node!='..') $nodes[] = $this->getChild($node); if (OC_Filesystem::is_dir($this->path . '/')) { $dh = OC_Filesystem::opendir($this->path . '/'); while (($node = readdir($dh)) !== false) { if ($node != '.' && $node != '..') { $nodes[] = $this->getChild($node); } } } return $nodes; }
function handleStoreSettings($root, $order) { if (!OC_Filesystem::file_exists($root)) { OCP\JSON::error(array('cause' => 'No such file or directory')); return; } if (!OC_Filesystem::is_dir($root)) { OCP\JSON::error(array('cause' => $root . ' is not a directory')); return; } $current_root = OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/'); $root = trim($root); $root = rtrim($root, '/') . '/'; $rescan = $current_root == $root ? 'no' : 'yes'; OCP\Config::setUserValue(OCP\USER::getUser(), 'gallery', 'root', $root); OCP\Config::setUserValue(OCP\USER::getUser(), 'gallery', 'order', $order); OCP\JSON::success(array('rescan' => $rescan)); }
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); } } }
require_once '../lib/base.php'; // Check if we are a user OC_Util::checkLoggedIn(); // Load the files we need OC_Util::addStyle("files", "files"); OC_Util::addScript("files", "files"); OC_Util::addScript('files', 'filelist'); OC_Util::addScript('files', 'fileactions'); if (!isset($_SESSION['timezone'])) { OC_Util::addScript('files', 'timezone'); } OC_App::setActiveNavigationEntry("files_index"); // Load the files $dir = isset($_GET['dir']) ? stripslashes($_GET['dir']) : ''; // Redirect if directory does not exist if (!OC_Filesystem::is_dir($dir . '/')) { header("Location: " . $_SERVER['PHP_SELF'] . ""); } $files = array(); foreach (OC_Files::getdirectorycontent($dir) as $i) { $i["date"] = OC_Util::formatDate($i["mtime"]); if ($i['type'] == 'file') { $fileinfo = pathinfo($i['name']); $i['basename'] = $fileinfo['filename']; if (!empty($fileinfo['extension'])) { $i['extention'] = '.' . $fileinfo['extension']; } else { $i['extention'] = ''; } } if ($i['directory'] == '/') {
// download the whole shared directory OC_Files::get($path, '', $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); } } } else { // download a single shared file OC_Files::get("", $path, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false); } } else { OCP\Util::addStyle('files_sharing', 'public'); OCP\Util::addScript('files_sharing', 'public'); OCP\Util::addScript('files', 'fileactions'); $tmpl = new OCP\Template('files_sharing', 'public', 'base'); $tmpl->assign('owner', $uidOwner); // Show file list if (OC_Filesystem::is_dir($path)) { OCP\Util::addStyle('files', 'files'); OCP\Util::addScript('files', 'files'); OCP\Util::addScript('files', 'filelist'); $files = array(); $rootLength = strlen($baseDir) + 1; foreach (OC_Files::getDirectoryContent($path) as $i) { $i['date'] = OCP\Util::formatDate($i['mtime']); if ($i['type'] == 'file') { $fileinfo = pathinfo($i['name']); $i['basename'] = $fileinfo['filename']; $i['extension'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : ''; } $i['directory'] = '/' . substr('/' . $uidOwner . '/files' . $i['directory'], $rootLength); if ($i['directory'] == '/') { $i['directory'] = '';
$base = $query; } else { $base = dirname($query); } $query = substr($query, strlen($base)); if ($base != '/') { $query = substr($query, 1); } $queryLen = strlen($query); $query = strtolower($query); // echo "$base - $query"; $files = array(); if (OC_Filesystem::file_exists($base) and OC_Filesystem::is_dir($base)) { $dh = OC_Filesystem::opendir($base); if ($dh) { if (substr($base, -1, 1) != '/') { $base = $base . '/'; } while (($file = readdir($dh)) !== false) { if ($file != "." && $file != "..") { if (substr(strtolower($file), 0, $queryLen) == $query) { $item = $base . $file; if (!$dirOnly or OC_Filesystem::is_dir($item)) { $files[] = (object) array('id' => $item, 'label' => $item, 'name' => $item); } } } } } } OC_JSON::encodedPrint($files);
if ($source !== false) { // TODO Manipulating the string may not be the best choice. Is there an alternative? $user = substr($source, 1, strpos($source, "/", 1) - 1); OC_Util::setupFS($user); $source = substr($source, strlen("/" . $user . "/files")); $subPath = isset($_GET['path']) ? $_GET['path'] : ''; $root = $source; $source .= $subPath; if (!OC_Filesystem::file_exists($source)) { header("HTTP/1.0 404 Not Found"); $tmpl = new OC_Template("", "404", "guest"); $tmpl->assign("file", $subPath); $tmpl->printPage(); exit; } if (OC_Filesystem::is_dir($source)) { $files = array(); $rootLength = strlen($root); foreach (OC_Files::getdirectorycontent($source) as $i) { $i['date'] = OC_Util::formatDate($i['mtime']); if ($i['type'] == 'file') { $fileinfo = pathinfo($i['name']); $i['basename'] = $fileinfo['filename']; $i['extention'] = isset($fileinfo['extension']) ? '.' . $fileinfo['extension'] : ''; } $i['directory'] = substr($i['directory'], $rootLength); if ($i['directory'] == "/") { $i['directory'] = ""; } $files[] = $i; }
function findMusic($path = '') { $music = array(); $dh = OC_Filesystem::opendir($path); if ($dh) { while ($filename = readdir($dh)) { if ($filename[0] != '.') { $file = $path . '/' . $filename; if (OC_Filesystem::is_dir($file)) { $music = array_merge($music, findMusic($file)); } else { if (OC_MEDIA_SCANNER::isMusic($filename)) { $music[] = $file; } } } } } return $music; }
* License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ require_once '../../../../lib/base.php'; OC_JSON::checkAppEnabled('ocdownloader'); OC_JSON::checkLoggedIn(); if (!OC_Filesystem::is_dir('/Downloads')) { OC_Filesystem::mkdir('/Downloads'); } $pr = $_POST['pr']; switch ($pr) { case 'web': $k = OC_ocDownloaderFile::getHttpFile($_POST['url']); break; default: if (preg_match('/^pr_([0-9]{1,4})$/', $pr, $m)) { $pr_name = OC_ocDownloader::getProvider($m[1]); $user_info = OC_ocDownloader::getUserProviderInfo($m[1]); $pr_name = strtolower($pr_name['pr_name']); if (file_exists(OC::$SERVERROOT . '/apps/ocdownloader/providers/' . $pr_name . '.php')) { require_once OC::$SERVERROOT . '/apps/ocdownloader/providers/' . $pr_name . '.php'; }
function is_valid_casestudy($dir) { $musthavedirs = array("/data", "/pipeline", "/results"); foreach ($musthavedirs as $subdir) { if (!OC_Filesystem::is_dir($dir . $subdir)) { return "Missing subdir {$subdir}"; } } return null; }