If a search page returns an additional offset from which segment to take the search query
@param string $path
@param Page $parentPage
@return false|int
962455
protected function _isSearchPage($path, Page $parentPage)
    {
        $ppIsNamedSearch = ($parentPage->pageLang() && $parentPage->pageLang()->url == 'search');
        if ($path == 'search' || $ppIsNamedSearch) {
            return $ppIsNamedSearch ? 0 : 1;
        } else {
            return false;
        }
    }
131780
public function saveParentPage(Lang $lang, Page $page, int $parentPageId) : void
    {
        if ($parentPageId === 0)
        {
            $parentPage = $this->pageRepository->findOneLangRoot($lang);
        }
        else
        {
            $parentPage = $this->pageRepository->findOneById($parentPageId);
        }

        if (!$parentPage)
        {
            throw new \Exception("Nadřazená stránka s id: '{$parentPageId}' nebyla nalezena.");
        }

        $page->setParent($parentPage);
        $page->moveToLastChildOf($parentPage);
        $page->save();
    }
469160
public function get_listing($path = '', $page = '') {
        $ret  = array();
        $ret['nologin'] = true;
        $ret['list'] = $this->_get_collection($this->keyword);
        return $ret;
    }
899921
public function parent(PageInterface $var = null)
    {
        if ($var) {
            $this->parent = $var->path();

            return $var;
        }

        /** @var Pages $pages */
        $pages = Grav::instance()['pages'];

        return $pages->get($this->parent);
    }
284948
public function isParentOf(AbsolutePathInterface $path)
    {
        if (!$this->matchesDriveOrNull($this->pathDriveSpecifier($path))) {
            return false;
        }

        return parent::isParentOf($path);
    }
119188
private function _getRouteMatch($path,$routes)
	{
		foreach ($routes as $route)
		{
			if ($match = $route->getMatch($path, $this->metadata($route->getName())))
				return $match;
		}
		return false;
	}
211830
public static function remove($path, $parent = true)
    {
        $ok = true;
        if (true===self::ensureExists($path)) {
            if (false===@is_dir($path) || true===is_link($path)) {
                return @unlink($path);
            }
            $iterator = new \RecursiveIteratorIterator(
                new \RecursiveDirectoryIterator($path),
                \RecursiveIteratorIterator::SELF_FIRST | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS
            );
            foreach($iterator as $item) {
                if (in_array($item->getFilename(), array('.', '..'))) {
                    continue;
                }
                if ($item->isDir()) {
                    $ok = self::remove($item);
                } else {
                    $ok = @unlink($item);
                }
            }
            if ($ok && $parent) {
                @rmdir($path);
            }
            @clearstatcache();
        }
        return $ok;
    }
223120
public function setParent(Page $parent)
    {
        if (!$parent->hasMainSection()) {
            throw new InvalidArgumentException('A parent page must be a section');
        }

        if (!$this->hasMainSection() || $this->isRoot()) {
            $this->setSection($parent->getSection());
        } else {
            $this->getSection()->setParent($parent->getSection());
        }
        return $this;
    }
298199
private function getMaxPosition(Page $page)
    {
        if (false === $page->hasMainSection()) {
            return 0;
        }

        $query = $this->createQueryBuilder('p');
        $max = $query->select($query->expr()->max('p._position'))
                ->andParentIs($page)
                ->getQuery()
                ->getResult(\Doctrine\ORM\Query::HYDRATE_SINGLE_SCALAR);

        return (null === $max) ? 0 : $max;
    }
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;
    }
508352
public function addPage($page = null)
    {
        if ($page = parent::addPage($page)) {
            $page->setParent($this);
        }

        return $page;
    }
285473
private function createPage(RouteDefinition $definition, PageInterface $parentPage = null)
    {
        $routeName = $definition->getRouteName();
        if (null !== $page = $this->findPageByRouteName($routeName)) {

            $updated = false;
            if ($page->getName() !== $definition->getPageName()) {
                $page->setName($definition->getPageName());
                $updated = true;
            }
            if ($page->isLocked() !== $definition->isLocked()) {
                $page->setLocked($definition->isLocked());
                $updated = true;
            }
            if ($page->isAdvanced() !== $definition->isAdvanced()) {
                $page->setAdvanced($definition->isAdvanced());
                $updated = true;
            }
            if ($page->isDynamicPath() !== $definition->isDynamic()) {
                $page->setDynamicPath($definition->isDynamic());
                $updated = true;
            }

            // Watch for paths update
            foreach ($this->locales as $locale) {
                if ($routeName === $path = $this->translator->trans(
                        $routeName, [], $this->routesTranslationDomain, $locale
                    )
                ) {
                    $path = $definition->getPath();
                }

                $pageTranslation = $page->translate($locale, true);
                if ($pageTranslation->getPath() !== $path) {
                    $pageTranslation->setPath($path);
                    $updated = true;
                }
            }

            if ($updated) {
                if (!$this->validate($page)) {
                    return false;
                }
                $this->pageOperator->persist($page);
            }

            $this->outputPageAction($page->getName(), $updated ? 'updated' : 'already exists');

        } else {
            /** @var PageInterface $page */
            $page = $this->pageRepository->createNew();

            // Seo
            $seoDefinition = $definition->getSeo();
            /** @var SeoInterface $seo */
            $seo = $this->seoRepository->createNew();
            $seo
                ->setChangefreq($seoDefinition['changefreq'])
                ->setPriority($seoDefinition['priority'])
                ->setFollow($seoDefinition['follow'])
                ->setIndex($seoDefinition['index'])
                ->setCanonical($seoDefinition['canonical']);

            // Page
            $page
                ->setName($definition->getPageName())
                ->setRoute($routeName)
                ->setPath($definition->getPath())
                ->setStatic(true)
                ->setLocked($definition->isLocked())
                ->setAdvanced($definition->isAdvanced())
                ->setParent($parentPage)
                ->setSeo($seo);

            $dynamic = false;
            foreach ($this->locales as $locale) {
                $title = $seoTitle = $definition->getPageName();
                if (null !== $parentPage && $parentPage->getRoute() !== $this->homeRouteName) {
                    $seoTitle = sprintf('%s - %s', $parentPage->getSeo()->translate($locale)->getTitle(), $title);
                }

                $seoTranslation = $seo->translate($locale, true);
                $seoTranslation
                    ->setTitle($seoTitle);

                if ($routeName === $path = $this->translator->trans(
                        $routeName, [], $this->routesTranslationDomain, $locale
                    )
                ) {
                    $path = $definition->getPath();
                }

                $pageTranslation = $page->translate($locale, true);
                $pageTranslation
                    ->setTitle($title)
                    ->setBreadcrumb($title)
                    ->setPath($path);

                if (0 < preg_match('~\{.*\}~', $path)) {
                    $dynamic = true;
                }
            }

            if ($dynamic != $page->isDynamicPath()) {
                $page->setDynamicPath($dynamic);
            }

            if (!$this->validate($page)) {
                return false;
            }

            $this->pageOperator->persist($page);

            $this->outputPageAction($page->getName(), 'created');
        }

        if (!$this->createMenus($page, $definition->getMenus())) {
            return false;
        }

        // Creates children pages
        foreach ($definition->getChildren() as $child) {
            if (!$this->createPage($child, $page)) {
                return false;
            }
        }

        return true;
    }
779334
protected function url($path, $label, $parent = null)
    {
        if ($this->config['generate_url']) {
            if ($this->route) {
                if (array_has($this->route, 'callback')) {
                    if(is_array($parent)) $parent = (object)$parent;
                    return call_user_func_array($this->route['callback'], [$path, $label, $parent]);
                } else {
                    end($this->route);
                    $param = current($this->route);
                    $name = key($this->route);
                    return URL::route($name, [$param => $path]);
                }
            }

            return URL::to($path);
        }

        return '/'.$path;
    }
697129
public static function getParentPath($path)
    {
        if ($path === '/') {
            $parentPath = '';
        } elseif (strrpos($path, '/') === 0) {
            $parentPath = '/';
        } else {
            $parentPath = substr($path, 0, strrpos($path, '/'));
        }

        return $parentPath;
    }
665154
public function alterQueryBuilderWithParentRoot($query, $parent_id, $include_parent = true)
    {
        if (is_null($parent_id)) {
            return $query;
        }
        $parent = $this->find($parent_id);

        $query->andWhere(
            $query->getRootAliases()[0] . '.lft >=' . $this->addNamedParameter('lft', $parent->getLft(), $query)
            . ' AND ' .
            $query->getRootAliases()[0] . '.lft <=' . $this->addNamedParameter('rgt', $parent->getRgt(), $query)
        );
        if (!$include_parent) {
            $query->andWhere(
                $query->getRootAliases()[0] . '.id !=' . $this->addNamedParameter('id', $parent_id, $query)
            );
        }
        return $query;
    }
300751
public function makeFullpath(Page $page)
    {
        if ($page->getParent() === NULL)
        {
            $page->setFullpath('');
            $page->setSlug('');
        }
        else
        {
            $parentFullpath = $page->getParent()->getFullpath();
            $slug = $this->addSuffixNumber($page->getSlug(), $page);
            $page->setFullpath(($parentFullpath != '' ? ($parentFullpath . '/') : '') . $slug);
            $page->setSlug($slug);
            if ($page->hasChildren())
            {
                foreach ($page->getChildren() as $children)
                {
                    $this->makeFullpath($children);
                    $this->doctrine->getManager()->persist($children);
                }
            }
        }
    }
330332
public function isAncestorOf(AbsolutePathInterface $path)
    {
        $parentAtoms = $this->normalize()->atoms();

        return $parentAtoms === array_slice(
            $path->normalize()->atoms(),
            0,
            count($parentAtoms)
        );
    }