List the files and folders.

@param  string $path path to browse.
@param  string $page page to browse.
@return array of result.
512539
public function get_listing($path='', $page = '') {
        if (empty($path)) {
            $path = $this->build_node_path('root', get_string('pluginname', 'repository_onedrive'));
        }

        if ($this->disabled) {
            // Empty list of files for disabled repository.
            return ['dynload' => false, 'list' => [], 'nologin' => true];
        }

        // We analyse the path to extract what to browse.
        $trail = explode('/', $path);
        $uri = array_pop($trail);
        list($id, $name) = $this->explode_node_path($uri);

        // Handle the special keyword 'search', which we defined in self::search() so that
        // we could set up a breadcrumb in the search results. In any other case ID would be
        // 'root' which is a special keyword, or a parent (folder) ID.
        if ($id === 'search') {
            $q = $name;
            $id = 'root';

            // Append the active path for search.
            $str = get_string('searchfor', 'repository_onedrive', $searchtext);
            $path = $this->build_node_path('search', $str, $path);
        }

        // Query the Drive.
        $parent = $id;
        if ($parent != 'root') {
            $parent = 'items/' . $parent;
        }
        $q = '';
        $results = $this->query($q, $path, $parent);

        $ret = [];
        $ret['dynload'] = true;
        $ret['path'] = $this->build_breadcrumb($path);
        $ret['list'] = $results;
        $ret['manage'] = 'https://www.office.com/';
        return $ret;
    }
1148879
protected function getFileInfo($path)
    {
        return [
            'name' => substr($path, strrpos($path, '/') + 1),
            'path' => $path,
            'url'  => $this->getFileUrl($path),
        ];
    }
379126
public static function glob_recursive( $path ) {
		$files = [];
		if ( preg_match( '/\\' . DIRECTORY_SEPARATOR . 'vendor$/', $path ) ) {
			return $files;
		}

		foreach ( glob( $path . '/*' ) as $file ) {
			if ( is_dir( $file ) ) {
				$files = array_merge( $files, static::glob_recursive( $file ) );
			} elseif ( preg_match( '/\.php$/', $file ) ) {
				$files[] = $file;
			}
		}

		return $files;
	}
140750
public function get_listing($fullpath = '', $page = '') {
        global $OUTPUT;

        $list = array(
            'list' => array(),
            'manage' => false,
            'dynload' => true,
            'nologin' => true,
            'path' => array()
        );

        // We analyse the path to extract what to browse.
        $fullpath = empty($fullpath) ? $this->build_node_path('root') : $fullpath;
        $trail = explode('|', $fullpath);
        $trail = array_pop($trail);
        list($mode, $path, $unused) = $this->explode_node_path($trail);

        // Is that a search?
        if ($mode === 'search') {
            return $this->search($path, $page);
        }

        // Cleaning up the requested path.
        $path = trim($path, '/');
        if (!$this->is_in_repository($path)) {
            // In case of doubt on the path, reset to default.
            $path = '';
        }
        $rootpath = $this->get_rootpath();
        $abspath = rtrim($rootpath . $path, '/') . '/';

        // Retrieve list of files and directories and sort them.
        $fileslist = array();
        $dirslist = array();
        if ($dh = opendir($abspath)) {
            while (($file = readdir($dh)) != false) {
                if ($file != '.' and $file != '..') {
                    if (is_file($abspath . $file)) {
                        $fileslist[] = $file;
                    } else {
                        $dirslist[] = $file;
                    }
                }
            }
        }
        core_collator::asort($fileslist, core_collator::SORT_NATURAL);
        core_collator::asort($dirslist, core_collator::SORT_NATURAL);

        // Fill the results.
        foreach ($dirslist as $file) {
            $list['list'][] = $this->build_node($rootpath, $path, $file, true, $fullpath);
        }
        foreach ($fileslist as $file) {
            $list['list'][] = $this->build_node($rootpath, $path, $file, false, $fullpath);
        }

        $list['path'] = $this->build_breadcrumb($fullpath);
        $list['list'] = array_filter($list['list'], array($this, 'filter'));

        return $list;
    }
349834
private function ls72(string $path) : array
    {
        $list = [];
        foreach ($this->mlsd($path) as $fileInfo) {
            $list[] = new File($fileInfo);
        }
        return $list;
    }
494418
private function lsdir(string $path): array
    {
        $result = @scandir($path);

        if (false === $result) {
            $message = 'Could not read directory.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return array_values(array_diff($result, ['.', '..']));
    }
484644
protected function _scandir($path) {
		return isset($this->dirsCache[$path])
			? $this->dirsCache[$path]
			: $this->cacheDir($path);
	}
932890
public function listAction($page = 1, $pageSize = 10, $sort = 'id', $sortDirection = "ASC")
    {
        return parent::listAction($page, $pageSize, $sort, $sortDirection);
    }
819700
protected function scan($path = '')
		{
			// add folder
			$this->addFolder($path);

			// get elements
			$root       = AbstractScanner::folderize($this->path . $path);
			$els        = array_diff(scandir($root), ['.', '..']);

			// split elements
			$files      = [];
			$folders    = [];
			foreach ($els as $el)
			{
				is_dir($root . $el)
					? array_push($folders, $el)
					: array_push($files, $el);
			}

			// get all controllers
			$controllers = [];
			$ordered = [];
			foreach ($files as $file)
			{
				$abspath = $root . $file;
				if($this->isController($abspath))
				{
					$controller = $this->addController($abspath, $path);
					if ($controller)
					{
						property_exists($controller, 'order') && $controller->order !== 0
							? array_push($ordered, $controller)
							: array_push($controllers, $controller);
					}
				}

			}

			// re-insert ordered controllers
			uasort($ordered, function ($a, $b) { return $a->order - $b->order; });
			foreach($ordered as $c)
			{
				array_splice($controllers, $c->order - 1, 0, [$c]);
			}

			// add controllers
			$this->controllers = array_merge($this->controllers, array_values($controllers));

			// folders
			foreach ($folders as $folder)
			{
				$relpath = $path . $folder;
				$this->scan($relpath . '/');
			}
		}
755323
private function getCompiledViewPaths(string $path) : array
    {
        if (!is_dir($path)) {
            return [];
        }

        $files = [];
        $iter = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::SELF_FIRST,
            RecursiveIteratorIterator::CATCH_GET_CHILD
        );
        $iter->setMaxDepth(0);

        foreach ($iter as $path => $item) {
            if ($item->isFile()) {
                $files[] = $path;
            }
        }

        return $files;
    }
1132142
protected function loadFile($path) {
        $path = realpath($path);

        if ($this->matchEnvironment($path)) {
            foreach ($this->getDrivers() as $driver) {
                if ($driver->supports($path)) {
                    return $driver->loadFile($path);
                }
            }
        }

        return [];
    }
617106
public function get_listing($path = '', $page = '') {
        global $CFG;
        $ret = array();
        $ret['nologin']  = true;
        $ret['nosearch'] = true;
        $ret['norefresh'] = true;
        $ret['list'] = array();
        $ret['dynload'] = false;
        $ret['upload'] = array('label'=>get_string('attachment', 'repository'), 'id'=>'repo-form');
        $ret['allowcaching'] = true; // indicates that result of get_listing() can be cached in filepicker.js
        return $ret;
    }
1332049
public function showAction(Page $page)
    {
        $deleteForm = $this->createDeleteForm($page);

        return array(
            'page' => $page,
            'delete_form' => $deleteForm->createView(),
        );
    }
706979
protected function folderDetails($path)
    {
        $path = '/'.ltrim($path, '/');

        return [
            'name'     => basename($path),
            'mimeType' => 'folder',
            'fullPath' => $path,
            'modified' => $this->fileModified($path),
        ];
    }
190881
protected function fileDetails($path)
    {
        $path = '/'.ltrim($path, '/');

        return [
            'name'         => basename($path),
            'fullPath'     => $path,
            'webPath'      => $this->fileWebpath($path),
            'mimeType'     => $this->fileMimeType($path),
            'size'         => $this->fileSize($path),
            'modified'     => $this->fileModified($path),
            'relativePath' => $this->fileRelativePath($path),
        ];
    }
1278746
public function getMappingFiles($path)
    {
        $files = $this->files->glob($path.'/*_*.php');

        if ($files === false) {
            return [];
        }

        $files = array_map(function ($file) {
            return str_replace('.php', '', basename($file));
        }, $files);

        return $files;
    }
461918
protected function loadPath($path) {
        if (directory_exists($path)) {
            return $this->loadDirectory($path);
        } else if (file_exists($path)) {
            return $this->loadFile($path);
        }

        return [];
    }