Display embedded equella interface

@param string $path
@param mixed $page
@return array
335427
public function get_listing($path = null, $page = null) {
        global $COURSE;
        $callbackurl = new moodle_url('/repository/equella/callback.php', array('repo_id'=>$this->id));

        $mimetypesstr = '';
        $restrict = '';
        if (!empty($this->mimetypes)) {
            $mimetypesstr = '&mimeTypes=' . implode(',', $this->mimetypes);
            // We're restricting to a mime type, so we always restrict to selecting resources only.
            $restrict = '&attachmentonly=true';
        } else if ($this->get_option('equella_select_restriction') != 'none') {
            // The option value matches the EQUELLA paramter name.
            $restrict = '&' . $this->get_option('equella_select_restriction') . '=true';
        }

        $url = $this->get_option('equella_url')
                . '?method=lms'
                . '&returnurl='.urlencode($callbackurl)
                . '&returnprefix=tle'
                . '&template=standard'
                . '&token='.urlencode($this->getssotoken('write'))
                . '&courseId='.urlencode($COURSE->idnumber)
                . '&courseCode='.urlencode($COURSE->shortname)
                . '&action=searchThin'
                . '&forcePost=true'
                . '&cancelDisabled=true'
                . '&attachmentUuidUrls=true'
                . '&options='.urlencode($this->get_option('equella_options') . $mimetypesstr)
                . $restrict;

        $manageurl = $this->get_option('equella_url');
        $manageurl = str_ireplace('signon.do', 'logon.do', $manageurl);
        $manageurl = $this->appendtoken($manageurl);

        $list = array();
        $list['object'] = array();
        $list['object']['type'] = 'text/html';
        $list['object']['src'] = $url;
        $list['nologin']  = true;
        $list['nosearch'] = true;
        $list['norefresh'] = true;
        $list['manage'] = $manageurl;
        return $list;
    }
655941
public function get_listing($path='', $page = '') {
        if (empty($path)) {
            $path = $this->build_node_path('root', get_string('pluginname', 'repository_googledocs'));
        }
        if (!$this->issuer->get('enabled')) {
            // 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 set up by Google, or a parent (folder) ID.
        if ($id === 'search') {
            return $this->search($name);
        }

        // Query the Drive.
        $q = "'" . str_replace("'", "\'", $id) . "' in parents";
        $q .= ' AND trashed = false';
        $results = $this->query($q, $path);

        $ret = array();
        $ret['dynload'] = true;
        $ret['defaultreturntype'] = $this->default_returntype();
        $ret['path'] = $this->build_breadcrumb($path);
        $ret['list'] = $results;
        $ret['manage'] = 'https://drive.google.com/';

        return $ret;
    }
63862
static function FindPageGroup(Page $page)
    {
        $currPage = $page;
        $result = null;
        do 
        {
            $result = $currPage->GetUserGroup();
            $currPage = $currPage->GetParent();
        } 
        while (!$result && $currPage);
        if (!$result && $page->GetSite())
        {
            return $page->GetSite()->GetUserGroup();
        }
        return $result;
    }
236066
public function get_listing($path = '', $page = '') {
        global $USER, $OUTPUT;
        $itemid = optional_param('itemid', 0, PARAM_INT);
        $env = optional_param('env', 'filepicker', PARAM_ALPHA);
        $ret = array(
            'dynload' => true,
            'nosearch' => true,
            'nologin' => true,
            'list' => array(),
        );
        if (empty($itemid) || $env !== 'editor') {
            return $ret;
        }

        // In the most cases files embedded in textarea do not have subfolders. Do not show path by default.
        $retpath = array(array('name' => get_string('files'), 'path' => ''));
        if (!empty($path)) {
            $pathchunks = preg_split('|/|', trim($path, '/'));
            foreach ($pathchunks as $i => $chunk) {
                $retpath[] = array(
                    'name' => $chunk,
                    'path' => '/'. join('/', array_slice($pathchunks, 0, $i + 1)). '/'
                );
            }
            $ret['path'] = $retpath; // Show path if already inside subfolder.
        }

        $context = context_user::instance($USER->id);
        $fs = get_file_storage();
        $files = $fs->get_directory_files($context->id, 'user', 'draft', $itemid,
                empty($path) ? '/' : $path, false, true);
        foreach ($files as $file) {
            if ($file->is_directory()) {
                $node = array(
                    'title' => basename($file->get_filepath()),
                    'path' => $file->get_filepath(),
                    'children' => array(),
                    'datemodified' => $file->get_timemodified(),
                    'datecreated' => $file->get_timecreated(),
                    'icon' => $OUTPUT->image_url(file_folder_icon(24))->out(false),
                    'thumbnail' => $OUTPUT->image_url(file_folder_icon(90))->out(false)
                );
                $ret['list'][] = $node;
                $ret['path'] = $retpath; // Show path if subfolders exist.
                continue;
            }
            $fileurl = moodle_url::make_draftfile_url($itemid, $file->get_filepath(), $file->get_filename());
            $node = array(
                'title' => $file->get_filename(),
                'size' => $file->get_filesize(),
                'source' => $fileurl->out(),
                'datemodified' => $file->get_timemodified(),
                'datecreated' => $file->get_timecreated(),
                'author' => $file->get_author(),
                'license' => $file->get_license(),
                'isref' => $file->is_external_file(),
                'iscontrolledlink' => $file->is_controlled_link(),
                'icon' => $OUTPUT->image_url(file_file_icon($file, 24))->out(false),
                'thumbnail' => $OUTPUT->image_url(file_file_icon($file, 90))->out(false)
            );
            if ($file->get_status() == 666) {
                $node['originalmissing'] = true;
            }
            if ($imageinfo = $file->get_imageinfo()) {
                $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified()));
                $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
                $node['image_width'] = $imageinfo['width'];
                $node['image_height'] = $imageinfo['height'];
            }
            $ret['list'][] = $node;
        }
        $ret['list'] = array_filter($ret['list'], array($this, 'filter'));
        return $ret;
    }
305295
public function needTranslatedPages(Page $page)
    {
       // Route page
       if (!$page->getParent() || !is_null($page->getSourceId()))
       {
            return FALSE;
       }
       if ($this->container->hasParameter('fulgurio_light_cms.languages'))
       {
            $availableLangs = $this->container->getParameter('fulgurio_light_cms.languages');
            $nbAvailableLangs = count($availableLangs);
            $availableTranslatedPages = $this->doctrine->getRepository('FulgurioLightCMSBundle:Page')->findBy(array('source_id' => $page->getId()), array('lang' => 'ASC'));
            $nbAvailableTranslatedPages = count($availableTranslatedPages);
            $availableTranslatedParents = $this->doctrine->getRepository('FulgurioLightCMSBundle:Page')->findBy(array('source_id' => $page->getParent()->getId()), array('lang' => 'ASC'));
            $nbAvailableTranslatedParents = count($availableTranslatedParents);
            // If we create a new page
            if ($page->getParent()->getMetaValue('is_home') == '1' && $nbAvailableLangs != $availableTranslatedPages)
            {
                $langs = array_flip($availableLangs);
                foreach ($availableTranslatedPages as $availableTranslatedPage)
                {
                    unset($langs[$availableTranslatedPage->getLang()]);
                }
                foreach ($langs as $lang => $value)
                {
                    if ($lang == $page->getLang())
                    {
                        unset($langs[$lang]);
                    }
                    else
                    {
                        $langs[$lang] = $page->getParent()->getId();
                    }
                }
                return $langs;
            }
            // Normal children page
            else if ($nbAvailableTranslatedPages != $nbAvailableTranslatedParents && $nbAvailableTranslatedParents < $nbAvailableLangs)
            {
                $langs = array_flip($availableLangs);
                foreach ($availableTranslatedPages as $availableTranslatedPage)
                {
                    unset($langs[$availableTranslatedPage->getLang()]);
                }
                foreach ($availableTranslatedParents as $availableTranslatedParent)
                {
                    if (isset($langs[$availableTranslatedParent->getLang()]))
                    {
                        $langs[$availableTranslatedParent->getLang()] = $availableTranslatedParent->getId();
                    }
                }
                foreach ($langs as $lang => $value)
                {
                    if (is_null($value) || $lang == $page->getLang())
                    {
                        unset($langs[$lang]);
                    }
                }
                return $langs;
            }
        }
        return FALSE;
    }
255417
public function get($path)
    {
        $return = null;
        $path = \preg_split('#[./]#', $path);
        $depth = 0;
        while ($path) {
            $key = \array_shift($path);
            if ($depth == 0) {
                if ($key == 'currentPage') {
                    $return = $this->data['pages'][ $this->data['i'] ];
                } elseif ($key == 'nextI') {
                    foreach ($this->data['pages'] as $i => $page) {
                        if (!$page['completed']) {
                            return $i;
                        }
                    }
                // } elseif ($key == 'submitted') {
                    // return $this->data['submitted'];
                } elseif (isset($this->data[$key])) {
                    $return = $this->data[$key];
                } elseif (isset($this->data['persist'][$key])) {
                    $return = $this->data['persist'][$key];
                } else {
                    return null;
                }
            } elseif (isset($return[$key])) {
                $return = $return[$key];
            } else {
                return null;
            }
            $depth++;
        }
        return $return;
    }
133559
public static function getPagePathFromToken($path, PageInterface $page = null)
    {
        $path_parts = pathinfo($path);
        $grav       = Grav::instance();

        $basename = '';
        if (isset($path_parts['extension'])) {
            $basename = '/' . $path_parts['basename'];
            $path     = rtrim($path_parts['dirname'], ':');
        }

        $regex = '/(@self|self@)|((?:@page|page@):(?:.*))|((?:@theme|theme@):(?:.*))/';
        preg_match($regex, $path, $matches);

        if ($matches) {
            if ($matches[1]) {
                if (null === $page) {
                    throw new \RuntimeException('Page not available for this self@ reference');
                }
            } elseif ($matches[2]) {
                // page@
                $parts = explode(':', $path);
                $route = $parts[1];
                $page  = $grav['page']->find($route);
            } elseif ($matches[3]) {
                // theme@
                $parts = explode(':', $path);
                $route = $parts[1];
                $theme = str_replace(ROOT_DIR, '', $grav['locator']->findResource("theme://"));

                return $theme . $route . $basename;
            }
        } else {
            return $path . $basename;
        }

        if (!$page) {
            throw new \RuntimeException('Page route not found: ' . $path);
        }

        $path = str_replace($matches[0], rtrim($page->relativePagePath(), '/'), $path);

        return $path . $basename;
    }
1354415
public function get_listing($path = '', $page = 1) {
        $people = $this->flickr->people_findByEmail($this->flickr_account);
        $this->nsid = $people['nsid'];
        $photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format', 24, $page);
        $ret = array();

        return $this->build_list($photos, $page, $ret);
    }
547320
public function get_listing($encodedpath = '', $page = '') {
        global $CFG, $USER, $OUTPUT;
        $ret = array();
        $ret['dynload'] = true;
        $ret['nosearch'] = true;
        $ret['nologin'] = true;
        $manageurl = new moodle_url('/user/files.php');
        $ret['manage'] = $manageurl->out();
        $list = array();

        if (!empty($encodedpath)) {
            $params = json_decode(base64_decode($encodedpath), true);
            if (is_array($params)) {
                $filepath = clean_param($params['filepath'], PARAM_PATH);
                $filename = clean_param($params['filename'], PARAM_FILE);
            }
        } else {
            $itemid   = 0;
            $filepath = '/';
            $filename = null;
        }
        $filearea = 'private';
        $component = 'user';
        $itemid  = 0;
        $context = context_user::instance($USER->id);

        try {
            $browser = get_file_browser();

            if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
                $pathnodes = array();
                $level = $fileinfo;
                $params = $fileinfo->get_params();
                while ($level && $params['component'] == 'user' && $params['filearea'] == 'private') {
                    $encodedpath = base64_encode(json_encode($level->get_params()));
                    $pathnodes[] = array('name'=>$level->get_visible_name(), 'path'=>$encodedpath);
                    $level = $level->get_parent();
                    $params = $level->get_params();
                }
                $ret['path'] = array_reverse($pathnodes);

                // build file tree
                $children = $fileinfo->get_children();
                foreach ($children as $child) {
                    if ($child->is_directory()) {
                        $encodedpath = base64_encode(json_encode($child->get_params()));
                        $node = array(
                            'title' => $child->get_visible_name(),
                            'datemodified' => $child->get_timemodified(),
                            'datecreated' => $child->get_timecreated(),
                            'path' => $encodedpath,
                            'children'=>array(),
                            'thumbnail' => $OUTPUT->image_url(file_folder_icon(90))->out(false)
                        );
                        $list[] = $node;
                    } else {
                        $encodedpath = base64_encode(json_encode($child->get_params()));
                        $node = array(
                            'title' => $child->get_visible_name(),
                            'size' => $child->get_filesize(),
                            'datemodified' => $child->get_timemodified(),
                            'datecreated' => $child->get_timecreated(),
                            'author' => $child->get_author(),
                            'license' => $child->get_license(),
                            'isref' => $child->is_external_file(),
                            'source'=> $encodedpath,
                            'icon' => $OUTPUT->image_url(file_file_icon($child, 24))->out(false),
                            'thumbnail' => $OUTPUT->image_url(file_file_icon($child, 90))->out(false)
                        );
                        if ($child->get_status() == 666) {
                            $node['originalmissing'] = true;
                        }
                        if ($imageinfo = $child->get_imageinfo()) {
                            $fileurl = new moodle_url($child->get_url());
                            $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $child->get_timemodified()));
                            $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $child->get_timemodified()));
                            $node['image_width'] = $imageinfo['width'];
                            $node['image_height'] = $imageinfo['height'];
                        }
                        $list[] = $node;
                    }
                }
            }
        } catch (Exception $e) {
            throw new repository_exception('emptyfilelist', 'repository_user');
        }
        $ret['list'] = $list;
        $ret['list'] = array_filter($list, array($this, 'filter'));
        return $ret;
    }
493463
public function getSignatureRequests($page = 1)
    {
        $params = array(
            'page' => $page
        );

        $response = $this->rest->get(
            static::SIGNATURE_REQUEST_LIST_PATH,
            $params
        );

        $this->checkResponse($response);

        $list = new SignatureRequestList($response);

        if ($page > $list->getNumPages()) {
            throw new Error('page_not_found', 'Page not found');
        }

        return $list;
    }
598047
public function getBreadcrumb(Page $page = null, $breadcrumb = array())
    {
        if (null === $this->breadcrumb) {
            $page = (null !== $page) ? $page : $this;
            $breadcrumb[] = $page;
            if (null !== $page->getParent()) {
                return $this->getBreadcrumb($page->getParent(), $breadcrumb);
            } else {
                $this->breadcrumb = $breadcrumb;
            }
        }

        return $this->breadcrumb;
    }
941326
public function get_listing($encodedpath = '', $page = '') {
        global $CFG, $USER, $OUTPUT;
        $ret = array();
        $ret['dynload'] = true;
        $ret['nosearch'] = false;
        $ret['nologin'] = true;
        $ret['list'] = array();

        $itemid   = null;
        $filename = null;
        $filearea = null;
        $filepath = null;
        $component = null;

        if (!empty($encodedpath)) {
            $params = json_decode(base64_decode($encodedpath), true);
            if (is_array($params) && isset($params['contextid'])) {
                $component = is_null($params['component']) ? NULL : clean_param($params['component'], PARAM_COMPONENT);
                $filearea  = is_null($params['filearea']) ? NULL : clean_param($params['filearea'], PARAM_AREA);
                $itemid    = is_null($params['itemid']) ? NULL : clean_param($params['itemid'], PARAM_INT);
                $filepath  = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH);
                $filename  = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE);
                $context = context::instance_by_id(clean_param($params['contextid'], PARAM_INT));
            }
        }
        if (empty($context) && !empty($this->context)) {
            $context = $this->context->get_course_context(false);
        }
        if (empty($context)) {
            $context = context_system::instance();
        }

        // prepare list of allowed extensions: $extensions is either string '*'
        // or array of lowercase extensions, i.e. array('.gif','.jpg')
        $extensions = optional_param_array('accepted_types', '', PARAM_RAW);
        if (empty($extensions) || $extensions === '*' || (is_array($extensions) && in_array('*', $extensions))) {
            $extensions = '*';
        } else {
            if (!is_array($extensions)) {
                $extensions = array($extensions);
            }
            $extensions = array_map('core_text::strtolower', $extensions);
        }

        // build file tree
        $browser = get_file_browser();
        if (!($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename))) {
            // if file doesn't exist, build path nodes root of current context
            $fileinfo = $browser->get_file_info($context, null, null, null, null, null);
        }
        $ret['list'] = $this->get_non_empty_children($fileinfo, $extensions);

        // build path navigation
        $path = array();
        for ($level = $fileinfo; $level; $level = $level->get_parent()) {
            array_unshift($path, $level);
        }
        array_unshift($path, null);
        $ret['path'] = array();
        for ($i=1; $i<count($path); $i++) {
            if ($path[$i] == $fileinfo || !$this->can_skip($path[$i], $extensions, $path[$i-1])) {
                $ret['path'][] = $this->get_node_path($path[$i]);
            }
        }
        return $ret;
    }
1226939
public function find(PageDocument $page)
    {
        $request = $this->requestStack->getCurrentRequest();

        $template = $page->getDefault(AbstractPhpcrDocument::DEFAULT_TEMPLATE_KEY);
        if ($template === null) {
            $defaults = [];

            /** @var RouteEnhancerInterface $enhancer */
            foreach ($this->dynamicRouter->getRouteEnhancers() as $enhancer) {
                $defaults = array_merge($defaults, $enhancer->enhance(['_content' => $page], $request));
            }

            if (array_key_exists(AbstractPhpcrDocument::DEFAULT_TEMPLATE_KEY, $defaults)) {
                $template = $defaults[AbstractPhpcrDocument::DEFAULT_TEMPLATE_KEY];
            }
        }

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

        $ret = array();
        $ret['list'] = array();
        $ret['manage'] = self::MANAGE_URL;
        $ret['dynload'] = true;

        $crumbs = explode('/', $fullpath);
        $path = array_pop($crumbs);

        if (empty($path)) {
            $type = 'folder';
            $pathid = 0;
            $pathname = get_string('pluginname', 'repository_boxnet');
        } else {
            list($type, $pathid, $pathname) = $this->split_part($path);
        }

        $ret['path'] = $this->build_breadcrumb($fullpath);
        $folders = array();
        $files = array();

        if ($type == 'search') {
            $result = $this->boxnetclient->search($pathname);
        } else {
            $result = $this->boxnetclient->get_folder_items($pathid);
        }
        foreach ($result->entries as $item) {
            if ($item->type == 'folder') {
                $folders[$item->name . ':' . $item->id] = array(
                    'title' => $item->name,
                    'path' => $fullpath . '/' . $this->build_part('folder', $item->id, $item->name),
                    'date' => strtotime($item->modified_at),
                    'thumbnail' => $OUTPUT->image_url(file_folder_icon(64))->out(false),
                    'thumbnail_height' => 64,
                    'thumbnail_width' => 64,
                    'children' => array(),
                    'size' => $item->size,
                );
            } else {
                $files[$item->name . ':' . $item->id] = array(
                    'title' => $item->name,
                    'source' => $this->build_part('file', $item->id, $item->name),
                    'size' => $item->size,
                    'date' => strtotime($item->modified_at),
                    'thumbnail' => $OUTPUT->image_url(file_extension_icon($item->name, 64))->out(false),
                    'thumbnail_height' => 64,
                    'thumbnail_width' => 64,
                    'author' => $item->owned_by->name,
                );
            }
        }

        core_collator::ksort($folders, core_collator::SORT_NATURAL);
        core_collator::ksort($files, core_collator::SORT_NATURAL);
        $ret['list'] = array_merge($folders, $files);
        $ret['list'] = array_filter($ret['list'], array($this, 'filter'));

        return $ret;
    }
286485
private function pageToArray(PageInterface $page, $locale)
    {
        $tabs = '';
        for ($l=0; $l<$page->getLevel();$l++) {
            $tabs .= ' • ';
        }

        return [
            'value' => $page->getId(),
            'title' => $tabs . $page->translate($locale)->getTitle(),
            'data'  => [
                'locked' => $page->isLocked(),
                'path'   => $this->generateUrl($page->getRoute(), ['_locale' => $locale]),
            ],
        ];
    }
1113625
public function getPhpContents($path)
    {
        $fullPath = $this->concatPaths($path);

        if (file_exists($fullPath) && strtolower(substr($fullPath, -4)) == '.php') {
            $phpContents = include($fullPath);
            return $phpContents;
        }

        return false;
    }
1033565
public function getText(Page $page = null)
    {
        $header   = new Header(array(), $this->document);
        $contents = new PDFObject($this->document, $header, $this->content);

        return $contents->getText($this);
    }