Get all Page Resources

@param Page $page Rcm Page Entity
@param Site $site Rcm Site Entity

@return mixed
432035
protected function getPageResources(Page $page, Site $site)
    {
        $primaryDomainName = $site->getDomain()->getDomainName();
        $siteId = $site->getSiteId();
        $pageName = $page->getName();
        $pageType = $page->getPageType();

        $pagesResourceId = $this->resourceName->get(self::RESOURCE_SITES, $siteId, self::RESOURCE_PAGES);
        $pageResourceId = $this->resourceName->get(
            self::RESOURCE_SITES,
            $siteId,
            self::RESOURCE_PAGES,
            $pageType,
            $pageName
        );

        $return[$pageResourceId] = [
            'resourceId' => $pageResourceId,
            'parentResourceId' => $pagesResourceId,
            'name' => $primaryDomainName . ' - pages - ' . $pageName,
            'description' => "Resource for page '{$pageName}'" . " of type '{$pageType}' on site '{$primaryDomainName}'"
        ];

        $return[$pageResourceId] = array_merge(
            $this->resources[self::RESOURCE_PAGES],
            $return[$pageResourceId]
        );

        return $return;
    }
141616
public function getPageUrl(Page $page)
    {
        return $this->config['base_url'].'/'.
            ($page->getSubFolder() === null ? '' : $page->getSubFolder().'/').
            $this->getPagePublishFilename($page);
    }
668750
public function getOnlinePrevSibling(Page $page)
    {
        $query = $this->createQueryBuilder('p')
                ->andIsSiblingsOf($page, true, ['_leftnode' => 'DESC', '_position' => 'DESC'], 1, 0)
                ->andIsOnline();

        if (true === $page->hasMainSection()) {
            $query->andIsSection()
                    ->andWhere($query->getSectionAlias().'._leftnode < :leftnode')
                    ->setParameter('leftnode', $page->getLeftnode());
        } else {
            $qOR = $query->expr()->orX();
            $qOR->add('p._section != p')
                    ->add($query->getSectionAlias().'._parent = :parent');

            $query->andWhere('p._position < :position')
                    ->andWhere($qOR)
                    ->setParameter('position', $page->getPosition())
                    ->setParameter('parent', $page->getParent()->getSection());
        }

        return $query->getQuery()
                        ->getOneOrNullResult();
    }
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;
    }
137700
public function getPagedResults($limit = 25, $page = 0)
    {
        $template = self::DQL_ALL;
        $dql = sprintf($template, Application::class);

        return $this->getPaginator($dql, $limit, $page, []);
    }
1074458
public function getLocalizedUrlsForPage(BasePageDocument $page)
    {
        $localizedUrls = [];
        $webspaceKey = $this->getWebspace($page);
        $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
        $node = $this->getNode($page);

        $structure = $this->getStructureMetadata($page);
        $resourceLocatorProperty = $structure->getPropertyByTagName('sulu.rlp');

        foreach ($webspace->getAllLocalizations() as $localization) {
            $resolvedLocale = $localization->getLocale();
            $locale = $resolvedLocale;

            $shadowEnabledName = $this->encoder->localizedSystemName(
                ShadowLocaleSubscriber::SHADOW_ENABLED_FIELD,
                $resolvedLocale
            );

            if (true === $node->getPropertyValueWithDefault($shadowEnabledName, false)) {
                $shadowLocaleName = $this->encoder->localizedSystemName(
                    ShadowLocaleSubscriber::SHADOW_LOCALE_FIELD,
                    $resolvedLocale
                );
                $resolvedLocale = $node->getPropertyValue($shadowLocaleName);
            }

            $stageName = $this->encoder->localizedSystemName(
                WorkflowStageSubscriber::WORKFLOW_STAGE_FIELD,
                $resolvedLocale
            );

            if (false === $node->hasProperty($stageName)) {
                continue;
            }

            $stage = $node->getProperty($stageName);

            if (WorkflowStage::PUBLISHED !== $stage->getValue()) {
                continue;
            }

            $url = $node->getPropertyValueWithDefault(
                $this->encoder->localizedContentName($resourceLocatorProperty->getName(), $locale),
                null
            );

            if (null === $url) {
                continue;
            }

            $localizedUrls[$locale] = $url;
        }

        return $localizedUrls;
    }
542005
public function getPagedResults($limit = 25, $page = 0)
    {
        $template = self::DQL_ALL;
        $dql = sprintf($template, UserPermission::class, User::class);

        return $this->getPaginator($dql, $limit, $page, []);
    }
1285778
public function get($pages = 0)
    {
        $endpoint = $this->getEndpoint();
        $params = $this->getParams();
        $list = $this->getClient()->request($endpoint, 'GET', $params);

        $i = 1;
        while ($list['metadata']['continue']) {
            if ($pages > 0 && $pages >= $i) {
                return $list;
            }
            $params['continue'] = $list['metadata']['continue'];
            $i_list = $this->getClient()->request($endpoint, 'GET', $params);
            $i_list['items'] = array_merge($list['items'], $i_list['items']);
            $list = $i_list;
            unset($i_list);
            $i++;
        }

        return $list;
    }
7744
public function getAction( Request $request, $resource, $site = 'default' )
	{
		$cntl = $this->createAdmin( $request, $site, $resource );

		if( ( $html = $cntl->get() ) == '' ) {
			return $cntl->getView()->response();
		}

		return $this->getHtml( $html );
	}
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;
    }
289106
public function pageAction( $page = 1 )
    {
        $sitemap               = new DOMDocument( "1.0", "UTF-8" );
        $root                  = $sitemap->createElement( "urlset" );
        $sitemap->formatOutput = true;
        $root->setAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" );
        $sitemap->appendChild( $root );
        $query         = $this->getQuery();
        $query->limit  = static::PACKET_MAX;
        $query->offset = static::PACKET_MAX * ( $page - 1 );

        $searchService = $this->get( "ezpublish.api.repository" )->getSearchService();

        $results = $searchService->findLocations( $query );
        $this->fillSitemap( $sitemap, $root, $results );

        $response = new Response( $sitemap->saveXML(), 200, [ "Content-type" => "text/xml" ] );
        $response->setSharedMaxAge( 24 * 3600 );

        return $response;
    }
1215631
public static function getSiteLinks(string $page, string $host, string $scheme, array $do_not_follow_links = [], array $extensions_to_parse = ['php', 'html'], array $already_parsed_urls = []): array
    {
        // Already checked - skip
        if (isset($already_parsed_urls[$page]) && $already_parsed_urls[$page] === true) {
            return $already_parsed_urls;
        }

        // If no content - skip
        $content = @file_get_contents($page);

        if (!$content) {
            unset($already_parsed_urls[$page]);

            return $already_parsed_urls;
        }

        // Set link as checked
        $already_parsed_urls[$page] = true;

        // Check if we do not need to go to the link, in meta
        if (preg_match('/<[Mm][Ee][Tt][Aa].*[Nn][Aa][Mm][Ee]=.?("|\'|).*[Rr][Oo][Bb][Oo][Tt][Ss].*?("|\'|).*?[Cc][Oo][Nn][Tt][Ee][Nn][Tt]=.*?("|\'|).*([Nn][Oo][Ff][Oo][Ll]{...}[Oo][Ww]|[Nn][Oo][Ii][Nn][Dd][Ee][Xx]|[Nn][Oo][Nn][Ee]).*?("|\'|).*>/', $content)) {
            $content = '';
        }

        // Get all links from page
        preg_match_all("/<[Aa][\s]{1}[^>]*[Hh][Rr][Ee][Ff][^=]*=[ '\"\s]*([^ \"'>\s#]+)[^>]*>/", $content, $tmp);

        // Add add only links without "nofollow"
        $links = [];
        foreach ($tmp[0] as $k => $v) {
            if (!preg_match('/<.*[Rr][Ee][Ll]=.?("|\'|).*[Nn][Oo][Ff][Oo][Ll]{...}[Oo][Ww].*?("|\'|)/', $v)) {
                $links[$k] = $tmp[1][$k];
            }
        }

        // Here we count links in every iteration, do not move it to external variable
        /** @noinspection CallableInLoopTerminationConditionInspection */
        for ($i = 0; $i < count($links); $i++) {
            // Stop function if too many links
            if (self::$maximum_link_count && count($already_parsed_urls) > self::$maximum_link_count) {
                return $already_parsed_urls;
            }

            // Can set external domain, so we check and set as main
            if (false === strpos($links[$i], $scheme . $host)) {
                $links[$i] = $scheme . $host . $links[$i];
            }

            // Remove js anchors
            $links[$i] = preg_replace('/#.*/X', '', $links[$i]);

            // Get info about link
            $url_info = parse_url($links[$i]);
            if (!isset($url_info['path'])) {
                $url_info['path'] = '';
            }

            // TODO check it for errors
            // Bad link, maybe mail or something similar
            if ((isset($url_info['host']) && $url_info['host'] !== $host)
                || $url_info['path'] === '/'
                || isset($already_parsed_urls[$links[$i]])
                || false !== strpos($links[$i], '@')
                || false !== strpos($links[$i], 'mailto:'
                    || false !== strpos($links[$i], 'tel:'
                    ))
            ) {
                continue;
            }

            // Link is in skip list?
            $do_not_follow_this_link = false;
            if ($do_not_follow_links) {
                foreach ($do_not_follow_links as $one_link) {
                    if (false !== strpos($links[$i], $one_link)) {
                        $do_not_follow_this_link = true;
                        break;
                    }
                }
            }
            // Skip link if should not follow it
            if ($do_not_follow_this_link) {
                continue;
            }

            // Check link extension
            $array_of_path_data = explode('.', $url_info['path']);
            $extension = end($array_of_path_data);
            $no_extension = false;

            if ($extension !== '' && false !== strpos($url_info['path'], '.') && 0 !== count($extensions_to_parse)) {
                $no_extension = true;
                foreach ($extensions_to_parse as $skip_extension) {
                    if ($extension === $skip_extension) {
                        $no_extension = false;
                        continue;
                    }
                }
            }

            // Page have no extension
            if ($no_extension) {
                continue;
            }

            // Finally add link to the list to check in future iterations
            $already_parsed_urls[$links[$i]] = false;

            // And go check links further and deeper
            $already_parsed_urls = self::getSiteLinks($links[$i], $host, $scheme, $do_not_follow_links, $extensions_to_parse, $already_parsed_urls);
        }

        return $already_parsed_urls;
    }
33885
protected function pageResourceMapper($resourceId)
    {
        if (!$this->resourceName->isPagesResourceId($resourceId)) {
            return null;
        }

        $resources = explode('.', $resourceId);

        if (empty($resources[1])) {
            return null;
        }

        $siteResourceId = $this->resourceName->get(self::RESOURCE_SITES, $resources[1]);

        $return = [
            'resourceId' => $resourceId,
            'parentResourceId' => $siteResourceId,
        ];

        if ($this->resourceName->isPageResourceId($resourceId)) {
            $pagesResourceId = $this->resourceName->get(self::RESOURCE_SITES, $resources[1], self::RESOURCE_PAGES);
            $return['parentResourceId'] = $pagesResourceId;
        }

        return array_merge(
            $this->resources[self::RESOURCE_PAGES],
            $return
        );
    }
322788
public function getData($pageSize, $page)
    {
        $limit = ($page - 1) * $pageSize;
        $offset = $pageSize;
        $sql = "{$this->sqlment} LIMIT {$limit}, {$offset}";

        return $this->db->findAllBySql($sql, $this->params);
    }
1166684
public function retrievePageElements($entityName, $page)
    {
        $page = $page < 1 ? 1 : $page;

        $qb = $this->createQueryBuilder($entityName);
        $qb
            ->setMaxResults($this->itemPerPage)
            ->setFirstResult(($page-1) * $this->itemPerPage)
        ;

        $paginator = new Paginator($qb, true);

        $this->page = $page;
        $this->count = $paginator->count();
        $this->results = $paginator->getIterator();
        $this->maxPage = ceil($this->count / $this->itemPerPage);

        return $this;
    }
108758
public static function findAll($page_request = null)
    {
        if($page_request != null){
            return self::listAllPromotions(['page' => $page_request->getPageNumber(), 'size' => $page_request->getSize() ]);
        }else {
            return self::listAllPromotions();
        }
    }
427946
protected function getRevision(
        Site $site,
        Page $page,
        $pageRevisionId = null
    ) {
        $hasRevisionId = !empty($pageRevisionId);

        $hasAccess = false;

        if ($hasRevisionId) {
            $hasAccess = $this->cmsPermissionChecks->shouldShowRevisions(
                $site->getSiteId(),
                $page->getName(),
                $page->getPageType()
            );
        }

        if ($hasAccess) {
            return $page->getRevisionById($pageRevisionId);
        }

        // Check for staging
        $hasAccess = $this->cmsPermissionChecks->siteAdminCheck(
            $site
        );

        $revision = null;

        if ($hasAccess) {
            // @todo is this right, This means admins can never see published revisions
            $revision = $page->getStagedRevision();
        }

        // There might be cases where there is no staged revision
        // so this check is required
        if (!empty($revision)) {
            return $revision;
        }

        // Finally look for published revision
        return $page->getPublishedRevision();
    }