/**
     * @return SupraJsonResponse
     */
    public function pathInfoAction()
    {
        $input = $this->getRequestInput();
        $pathString = $input->get('page_path');
        $pathString = trim(parse_url($pathString, PHP_URL_PATH), '/');
        $path = new Path($pathString);
        $localeId = null;
        foreach ($this->getLocaleManager()->getLocales() as $locale) {
            /* @var $locale LocaleInterface */
            $pathPrefix = new Path($locale->getId());
            if ($path->startsWith($pathPrefix)) {
                $path->setBasePath($pathPrefix);
                $localeId = $locale->getId();
                break;
            }
        }
        $localeId = $localeId ?: $input->get('locale');
        $pathData = array();
        $localization = $this->getEntityManager()->createQuery('SELECT l FROM Cms:PageLocalization l JOIN l.path p
					WHERE p.path = :path AND l.locale = :locale')->setParameters(array('path' => $path->getPath(Path::FORMAT_NO_DELIMITERS), 'locale' => $localeId))->getOneOrNullResult();
        if ($localization) {
            /* @var $localization PageLocalization */
            $pathData = array('locale' => $localeId, 'page_id' => $localization->getId());
            if (($redirectTarget = $localization->getRedirectTarget()) instanceof RedirectTargetPage) {
                /* @var $redirectTarget RedirectTargetPage */
                $targetPage = $redirectTarget->getTargetPage();
                if ($targetPage && $targetPage->getLocalization($localeId) !== null) {
                    $pathData['redirect_page_id'] = $targetPage->getLocalization($localeId)->getId();
                }
            }
        }
        return new SupraJsonResponse($pathData);
    }
 /**
  * Loads page path
  * @param PageLocalization $pageData
  * @return Path
  */
 protected function findPagePath(PageLocalization $pageData)
 {
     $active = true;
     $limited = false;
     $inSitemap = true;
     $path = new Path();
     // Inactive page children have no path
     if (!$pageData->isActive()) {
         $active = false;
     }
     if (!$pageData->isVisibleInSitemap()) {
         $inSitemap = false;
     }
     $pathPart = $pageData->getPathPart();
     if (is_null($pathPart)) {
         return array(null, false, false, false);
     }
     $path->prependString($pathPart);
     $page = $pageData->getMaster();
     $locale = $pageData->getLocale();
     $parentPage = $page->getParent();
     if (is_null($parentPage)) {
         return array($path, $active, $limited, $inSitemap);
     }
     $parentLocalization = $parentPage->getLocalization($locale);
     // No parent page localization
     if (is_null($parentLocalization)) {
         return array(null, false, false, false);
     }
     // Page application feature to generate base path for pages
     if ($parentPage instanceof ApplicationPage) {
         $applicationId = $parentPage->getApplicationId();
         $pageApplicationManager = $this->container['cms.pages.page_application_manager'];
         /* @var $pageApplicationManager PageApplicationManager */
         if (!$pageApplicationManager->hasApplication($applicationId)) {
             throw new Exception\PagePathException(sprintf("Failed to generate path because, page application [%s] not found.", $applicationId), $pageData);
         }
         $application = $pageApplicationManager->createApplicationFor($pageData, $this->em);
         $pathBasePart = $application->generatePath($pageData);
         $path->prepend($pathBasePart);
     }
     // Search nearest page parent
     while (!$parentLocalization instanceof PageLocalization) {
         $parentPage = $parentPage->getParent();
         if (is_null($parentPage)) {
             return array($pageData->getPathPart(), $active, $limited, $inSitemap);
         }
         $parentLocalization = $parentPage->getLocalization($locale);
         // No parent page localization
         if (is_null($parentLocalization)) {
             return array(null, false, false, false);
         }
     }
     // Is checked further
     //		if ( ! $parentLocalization->isActive()) {
     //			$active = false;
     //		}
     // Assume that path is already regenerated for the parent
     $parentPath = $parentLocalization->getPathEntity()->getPath();
     $parentActive = $parentLocalization->getPathEntity()->isActive();
     $parentInSitemap = $parentLocalization->getPathEntity()->isVisibleInSitemap();
     if (!$parentActive) {
         $active = false;
     }
     if (!$parentInSitemap) {
         $inSitemap = false;
     }
     if (is_null($parentPath)) {
         return array(null, false, false, false);
     }
     $path->prepend($parentPath);
     return array($path, $active, $limited, $inSitemap);
 }
Beispiel #3
0
 /**
  * Whether the passed link is actual - is some descendant opened currently
  * @param string $path
  * @param boolean $strict
  * @return boolean
  */
 public function isActive($path, $strict = false)
 {
     // Check if path is relative
     $pathData = parse_url($path);
     if (!empty($pathData['scheme']) || !empty($pathData['host']) || !empty($pathData['port']) || !empty($pathData['user']) || !empty($pathData['pass'])) {
         return false;
     }
     $path = $pathData['path'];
     $localization = $this->getPage();
     if (!$localization instanceof PageLocalization) {
         return false;
     }
     // Remove locale prefix
     $path = preg_replace(sprintf('#^(/?)%s(/|$)#', preg_quote($localization->getLocaleId())), '$1', $path);
     $checkPath = new Path($path);
     $currentPath = $localization->getPath();
     if ($currentPath === null) {
         return false;
     }
     return $strict ? $checkPath->equals($currentPath) : $currentPath->startsWith($checkPath);
 }
 public function pathToString(VisitorInterface $visitor, Path $path)
 {
     return $path->getFullPath(Path::FORMAT_LEFT_DELIMITER);
 }