コード例 #1
0
ファイル: NodeStorage.php プロジェクト: jarves/jarves
 public function populateRow($clazz, $row, $selects, $relations, $relationFields, $permissionCheck = false)
 {
     $row = parent::populateRow($clazz, $row, $selects, $relations, $relationFields, $permissionCheck);
     if ($row) {
         $row['url'] = $this->pageStack->getNodeUrl($row['id']);
     }
     return $row;
 }
コード例 #2
0
 public function onFinishRequestPre(FinishRequestEvent $event)
 {
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     $key = $this->pageStack->isAdmin() ? 'backend' : 'frontend';
     $this->log($key, microtime(true) - $this->start);
 }
コード例 #3
0
ファイル: EditMode.php プロジェクト: jarves/jarves
 /**
  * @param int|null $nodeId
  *
  * @return bool
  */
 public function isEditMode($nodeId = null)
 {
     $request = $this->requestStack->getMasterRequest();
     $hasRequest = !!$request;
     if ($nodeId) {
         return $hasRequest && 1 === (int) $request->get('_jarves_editor') && $this->acl->isUpdatable('jarves/node', ['id' => $nodeId]);
     }
     return $hasRequest && 1 === (int) $request->get('_jarves_editor') && $this->pageStack->getCurrentPage() && $this->acl->isUpdatable('jarves/node', ['id' => $this->pageStack->getCurrentPage()->getId()]);
 }
コード例 #4
0
ファイル: Markdowner.php プロジェクト: jarves/jarves
 public function transform($text)
 {
     $parser = new MarkdownExtra();
     $stylesAdded = false;
     if (class_exists('Kadet\\Highlighter\\Language\\Language')) {
         $parser->code_block_content_func = function ($code, $language) use(&$stylesAdded) {
             if (!$stylesAdded) {
                 $this->pageStack->getPageResponse()->addCssFile('@Jarves/keylighter/default.scss');
                 $stylesAdded = true;
             }
             return Highlighter\highlight($code, Language::byName($language));
         };
     }
     return $parser->transform($text);
 }
コード例 #5
0
ファイル: ResponseCacher.php プロジェクト: jarves/jarves
 /**
  * Returns a rendered view. If we find html behind the given cache
  * it returns this directly. This is a couple os ms faster than `renderCached`
  * since the template engine is never used when there's a valid cache.
  *
  * Example:
  *
  *  return $this->renderFullCached('myCache', 'plugin1/default.tpl', function(){
  *     return array('items' => heavyDbQuery());
  * });
  *
  * Note: The $data callable is only called if the cache needs to regenerate (when it has been
  * invalidated or empty, or the view file changed).
  *
  * If the callable $data returns NULL, then this will return NULL, too, without entering
  * the actual rendering process.
  *
  * You should use this method in your plugins instead of writing your own cache mechanism,
  * because this method handles PageResponse merging. Means: If templates used in this
  * $view are changing somehow the PageResponse ({{loadAsset('style.css')}} calls) then
  * this information (diff to current PageResponse) is stored and restored when we found
  * a html cache. The diff is beside the actual rendered HTML also stored in the cache
  * to keep this possible.
  *
  * @param string $cacheKey
  * @param string $view
  * @param array|callable $data Pass the data as array or a data provider function.
  * @param integer $lifeTime In seconds. Default is one hour/3600 seconds.
  * @param bool $force Force to bypass the cache and always call $data. For debuggin purposes.
  *
  * @see method `render` to get more information.
  *
  * @return string
  */
 public function renderFullCached($cacheKey, $view, $data = null, $lifeTime = null, $force = false)
 {
     $cache = $this->cacher->getDistributedCache($cacheKey);
     $mTime = $this->getViewMTime($view);
     if (!is_string($cache)) {
         $cache = null;
     } else {
         $cache = @unserialize($cache);
     }
     if ($force || !$cache || !$cache['content'] || !is_array($cache) || $mTime != $cache['fileMTime']) {
         $oldResponse = clone $this->pageStack->getPageResponse();
         $data2 = $data;
         if (is_callable($data)) {
             $data2 = call_user_func($data, $view);
             if (null === $data2) {
                 //the data callback returned NULL so this means
                 //we aren't the correct controller for this request
                 //or the request contains invalid input
                 return null;
             }
         }
         $content = $this->templating->render($view, $data2);
         $response = $this->pageStack->getPageResponse();
         $diff = $oldResponse->diff($response);
         $cache = array('content' => $content, 'fileMTime' => $mTime, 'responseDiff' => $diff);
         $this->cacher->setDistributedCache($cacheKey, serialize($cache), $lifeTime ?: 3600);
     } else {
         if ($cache['responseDiff']) {
             $this->pageStack->getPageResponse()->patch($cache['responseDiff']);
         }
     }
     return $this->pageResponseFactory->createPluginResponse($cache['content']);
 }
コード例 #6
0
ファイル: Navigation.php プロジェクト: jarves/jarves
 /**
  * @param array $options
  *
  * @return null|Model\Node
  *
  * @throws Exceptions\BundleNotFoundException
  * @throws \Exception
  */
 public function get($options)
 {
     $options['id'] = isset($options['id']) ? $options['id'] : false;
     $options['level'] = isset($options['level']) ? $options['level'] : false;
     //        $withFolders = (isset($options['folders']) && $options['folders'] == 1) ? true : false;
     $navigation = false;
     if (!$navigation && $options['id'] != 'breadcrumb' && ($options['id'] || $options['level'])) {
         if ($options['id'] + 0 > 0) {
             $navigation = $this->pageStack->getPage($options['id'] + 0);
             if (!$navigation) {
                 return null;
             }
         }
         if ($options['level'] > 1) {
             $currentPage = $this->pageStack->getCurrentPage();
             $parents = $currentPage->getParents();
             $parents[] = $currentPage;
             $currentLevel = count($parents) + 1;
             $page = $this->arrayLevel($parents, $options['level']);
             if ($page && $page->getId() > 0) {
                 $navigation = $this->pageStack->getPage($page->getId());
             } elseif ($options['level'] == $currentLevel + 1) {
                 $navigation = $this->pageStack->getCurrentPage();
             }
         }
         if ($options['level'] == 1) {
             $navigation = NodeQuery::create()->findRoot($this->pageStack->getCurrentDomain()->getId());
         }
     }
     return $navigation;
 }
コード例 #7
0
ファイル: AdminAssets.php プロジェクト: jarves/jarves
 /**
  * Injects all necessary files to get the Jarves Content Editor working
  * on the current page response.
  *
  * This register in `parent.jarves` a new jarves.Editor.
  */
 public function registerEditor()
 {
     $this->addMainResources(['noJs' => true]);
     $this->addSessionScripts();
     $page = $this->pageStack->getCurrentPage();
     $response = $this->pageStack->getPageResponse();
     $response->addJsFile('@JarvesBundle/admin/mootools-core-1.4.5-fixed-memory-leak.js');
     $response->addJsFile('@JarvesBundle/admin/mootools-more.js');
     $response->setResourceCompression(false);
     $response->setDomainHandling(false);
     $request = $this->pageStack->getRequest();
     $nodeArray['id'] = $page->getId();
     $nodeArray['title'] = $page->getTitle();
     $nodeArray['domainId'] = $page->getDomainId();
     $nodeArray['theme'] = $page->getTheme();
     $nodeArray['layout'] = $request->query->get('_jarves_editor_layout') ?: $page->getLayout();
     $domain = DomainQuery::create()->findPk($page->getDomainId());
     $domainArray['id'] = $domain->getId();
     $domainArray['domain'] = $domain->getDomain();
     $domainArray['path'] = $domain->getPath();
     $domainArray['theme'] = $domain->getTheme();
     $domainArray['themeOptions'] = $domain->getThemeOptions();
     $options = ['id' => $request->query->get('_jarves_editor_id'), 'node' => $nodeArray, 'domain' => $domainArray];
     if (is_array($extraOptions = $request->query->get('_jarves_editor_options'))) {
         $options = array_merge($options, $extraOptions);
         $options['standalone'] = filter_var($options['standalone'], FILTER_VALIDATE_BOOLEAN);
     }
     $response->addJsAtBottom('window.editor = new parent.jarves.Editor(' . json_encode($options) . ', document.documentElement);');
 }
コード例 #8
0
 /**
  * @param Node|int|string $id Node, node id, or node url
  * @param bool $exact whether it should also return true when a children is active
  * @return bool
  */
 public function isActive($id, $exact = false)
 {
     $current = $this->pageStack->getCurrentPage();
     $url = $this->pageStack->getNodeUrl($current, true, true);
     $purl = $this->pageStack->getNodeUrl($id, true, true);
     if ($url === $purl) {
         return true;
     }
     if (!$exact) {
         if ($url && $purl) {
             $pos = strpos($url, $purl);
             if ($url == '/' || $pos != 0 || $pos === false) {
                 return false;
             } else {
                 return true;
             }
         }
     }
 }
コード例 #9
0
ファイル: JarvesHandler.php プロジェクト: jarves/jarves
 /**
  * @return LogRequest
  */
 public function getLogRequest()
 {
     if (!$this->logRequest && $this->pageStack->getRequest()) {
         $this->logRequest = new LogRequest();
         $this->logRequest->setId(md5(mt_rand() . ':' . uniqid()));
         $this->logRequest->setDate(microtime(true));
         $this->logRequest->setIp($this->pageStack->getRequest()->getClientIp());
         $this->logRequest->setPath(substr($this->pageStack->getRequest()->getPathInfo(), 0, 254));
         $this->logRequest->setUsername($this->pageStack->getUser() instanceof UserInterface ? $this->pageStack->getUser()->getUsername() : 'Guest');
     }
     return $this->logRequest;
 }
コード例 #10
0
 public function onKernelView(GetResponseForControllerResultEvent $event)
 {
     $data = $event->getControllerResult();
     $request = $event->getRequest();
     if (!$event->getRequest()->attributes->get('_jarves_is_plugin')) {
         //we accept only plugin responses.
         return;
     }
     $content = $request->attributes->get('_content');
     if (null !== $data) {
         if ($data instanceof PluginResponseInterface) {
             $response = $data;
         } else {
             $response = $this->pageResponseFactory->createPluginResponse($data);
         }
         //it's required to place a PluginResponseInterface as response, so
         //PluginResponseListener::onKernelResponse can correctly identify it
         //and set it as response for this plugin content, so ContentTypes\TypePlugin
         //can place the correct response at the correct position, without executing
         //the plugin twice.
         $event->setResponse($response);
     } else {
         //we hit a plugin route, but it has responsed with NULL
         //this means it is not responsible for this route/slug.
         //we need now to remove this plugin route from the route collection
         //and fire again a sub request until all plugins on this page
         //are handled. If no plugin is responsible for this url pattern
         //and the main page route is also not responsible
         //no response is set in the $event and a 404 is thrown by the HttpKernel.
         $foundRoute = false;
         $routes = $this->frontendRouteListener->getRoutes();
         foreach ($routes as $idx => $route) {
             /** @var \Symfony\Component\Routing\Route $route */
             if ($content === $route->getDefault('_content')) {
                 //remove exactly only the current plugin that was hit in this sub request
                 $routes->remove($idx);
                 $foundRoute = true;
                 break;
             }
         }
         if ($foundRoute) {
             //we've removed the route and fire now again a sub request
             $request = clone $this->pageStack->getRequest();
             $request->attributes = new ParameterBag();
             $response = $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST);
             $event->setResponse($response);
         }
         //we do not need to restore routes in the frontendRouteListener, because
         //it reload all routes on every master request
     }
 }
コード例 #11
0
ファイル: PageResponseFactory.php プロジェクト: jarves/jarves
 /**
  * @param Node|string|int $page Node model, url or node id. Use Jarves\Model\Node::createPage()
  * @param string|array|null $contents
  *
  * @return PageResponse
  */
 public function createFromPage($page, $contents = null)
 {
     $page = $this->pageStack->getPage($page);
     if (!$page) {
         throw new \InvalidArgumentException('Can not find page.');
     }
     $this->pageStack->setCurrentPage($page);
     $pageResponse = new PageResponse('', 200, [], $this->pageStack, $this->jarves, $this->stopwatch, $this->assetCompilerContainer, $this->eventDispatcher, $this->templating, $this->editMode);
     $this->pageStack->setPageResponse($pageResponse);
     if (null !== $contents) {
         $pageResponse->setPageContent($contents);
     }
     return $pageResponse;
 }
コード例 #12
0
ファイル: BreadcrumbExtension.php プロジェクト: jarves/jarves
 public function breadcrumb(\Twig_Environment $twig, $view = 'JarvesBundle:Default:breadcrumb.html.twig')
 {
     $breadcrumbs = [];
     $page = $this->pageStack->getCurrentPage();
     $cacheKey = 'core/breadcrumbs/' . $page->getCacheKey();
     if ($cache = $this->cacher->getDistributedCache($cacheKey)) {
         if (is_string($cache)) {
             return $cache;
         }
     }
     foreach ($page->getParents() as $parent) {
         if ($parent->getLevel() === 0) {
             continue;
         }
         if ($parent->getType() >= 2) {
             continue;
         }
         $breadcrumbs[] = $parent;
     }
     $data = ['domain' => $this->pageStack->getCurrentDomain(), 'baseUrl' => $this->pageStack->getPageResponse()->getBaseHref(), 'breadcrumbs' => $breadcrumbs, 'currentPage' => $this->pageStack->getCurrentPage()];
     $html = $twig->render($view, $data);
     $this->cacher->setDistributedCache($cacheKey, $html);
     return $html;
 }
コード例 #13
0
ファイル: TypePlugin.php プロジェクト: jarves/jarves
 public function render()
 {
     if ($response = $this->pageStack->getPageResponse()->getPluginResponse($this->getContent())) {
         return $response->getContent();
     } elseif ($this->plugin) {
         $config = $this->jarves->getConfig($this->bundleName);
         if (!$config) {
             return sprintf('Bundle `%s` does not exist. You probably have to install this bundle.', $this->bundleName);
         }
         if ($this->pluginDef = $config->getPlugin($this->plugin['plugin'])) {
             $controller = $this->pluginDef->getController();
             if ($this->isPreview()) {
                 if (!$this->pluginDef->isPreview()) {
                     //plugin does not allow to have a preview on the actual action method
                     return ($config->getLabel() ?: $config->getBundleName()) . ': ' . $this->pluginDef->getLabel();
                 }
             }
             //create a sub request
             $request = new Request();
             $request->attributes->add(array('_controller' => $controller, '_content' => $this->getContent(), '_jarves_is_plugin' => true, 'options' => isset($this->plugin['options']) ? $this->plugin['options'] : array()));
             $dispatcher = $this->eventDispatcher;
             $callable = array($this, 'exceptionHandler');
             $fixResponse = array($this, 'fixResponse');
             $dispatcher->addListener(KernelEvents::EXCEPTION, $callable, 100);
             $dispatcher->addListener(KernelEvents::VIEW, $fixResponse, 100);
             ob_start();
             $response = $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST);
             //EventListener\PluginRequestListener converts all PluginResponse objects to PageResponses
             if ($response instanceof PageResponse) {
                 if ($pluginResponse = $response->getPluginResponse($this->getContent()->getId())) {
                     $response = $pluginResponse;
                 }
             }
             //                if ($response instanceof PageResponse) {
             //                    if ($response->getPluginResponse($this->getContent()->getId())) {
             //                        $response = $response->getPluginResponse($this->getContent()->getId());
             //                    }
             //                }
             $ob = ob_get_clean();
             $dispatcher->removeListener(KernelEvents::EXCEPTION, $callable);
             $dispatcher->removeListener(KernelEvents::VIEW, $fixResponse);
             return trim($ob) . $response->getContent();
         } else {
             return sprintf('Plugin `%s` in bundle `%s` does not exist. You probably have to install the bundle first.', $this->plugin['plugin'], $this->bundleName);
         }
     }
 }
コード例 #14
0
ファイル: BackendController.php プロジェクト: jarves/jarves
 /**
  * @ApiDoc(
  *  section="Backend",
  *  description="Prints all JavaScript files combined"
  * )
  *
  * @Rest\QueryParam(name="printSourceMap", requirements=".+", description="If the sourceMap should printed")
  *
  * @Rest\Get("/admin/backend/script")
  *
  * @return string javascript
  */
 public function loadJsAction()
 {
     $assets = array();
     $md5String = '';
     $newestMTime = 0;
     $jsContent = '';
     foreach ($this->jarves->getConfigs() as $bundleConfig) {
         foreach ($bundleConfig->getAdminAssetsInfo() as $assetInfo) {
             if (!$assetInfo->isJavaScript()) {
                 continue;
             }
             if (!$assetInfo->isCompressionAllowed()) {
                 continue;
             }
             $path = $this->jarves->resolveWebPath($assetInfo->getPath());
             if (file_exists($path)) {
                 $assets[] = $assetInfo->getPath();
                 $mtime = filemtime($path);
                 $newestMTime = max($newestMTime, $mtime);
                 $md5String .= ">{$path}.{$mtime}<";
                 $content = file_get_contents($path);
                 $jsContent .= "\n/* file: {$assetInfo->getPath()} */\n{$content}\n";
             }
         }
     }
     $ifModifiedSince = $this->pageStack->getRequest()->headers->get('If-Modified-Since');
     if (isset($ifModifiedSince) && strtotime($ifModifiedSince) == $newestMTime) {
         // Client's cache IS current, so we just respond '304 Not Modified'.
         $response = new Response();
         $response->setStatusCode(304);
         $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $newestMTime) . ' GMT');
         return $response;
     }
     $expires = 60 * 60 * 24 * 14;
     //2 weeks
     $response = new Response();
     $response->headers->set('Content-Type', 'application/javascript');
     $response->headers->set('Pragma', 'public');
     $response->headers->set('Cache-Control', 'max-age=' . $expires);
     $response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
     //        $content = implode($files);
     $response->setContent($jsContent);
     return $response;
 }
コード例 #15
0
ファイル: FileController.php プロジェクト: jarves/jarves
 /**
  * @ApiDoc(
  *  section="File Manager",
  *  description="Displays a (complete) image (with cache-headers)"
  * )
  *
  * @Rest\QueryParam(name="path", requirements=".+", strict=true, description="The file path or its ID")
  *
  * @Rest\Get("/admin/file/image")
  *
  * @param ParamFetcher $paramFetcher
  * @return Response
  */
 public function showImageAction(ParamFetcher $paramFetcher)
 {
     $path = $paramFetcher->get('path');
     if (is_numeric($path)) {
         $path = $this->webFilesystem->getPath($path);
     }
     $this->checkAccess($path, ACL::MODE_VIEW);
     $file = $this->webFilesystem->getFile($path);
     if ($file->isDir()) {
         return;
     }
     $ifModifiedSince = $this->pageStack->getRequest()->headers->get('If-Modified-Since');
     if (isset($ifModifiedSince) && strtotime($ifModifiedSince) == $file->getModifiedTime()) {
         // Client's cache IS current, so we just respond '304 Not Modified'.
         $response = new Response();
         $response->setStatusCode(304);
         $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $file->getModifiedTime()) . ' GMT');
         return $response;
     }
     $content = $this->webFilesystem->read($path);
     $image = \PHPImageWorkshop\ImageWorkshop::initFromString($content);
     $result = $image->getResult();
     $size = new FileSize();
     $size->setHandleFromBinary($content);
     $expires = 3600;
     //1 h
     $response = new Response();
     $response->headers->set('Content-Type', 'png' == $size->getType() ? 'image/png' : 'image/jpeg');
     $response->headers->set('Pragma', 'public');
     $response->headers->set('Cache-Control', 'max-age=' . $expires);
     $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $file->getModifiedTime()) . ' GMT');
     $response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
     ob_start();
     if ('png' === $size->getType()) {
         imagepng($result, null, 3);
     } else {
         imagejpeg($result, null, 100);
     }
     $response->setContent(ob_get_contents());
     ob_end_clean();
     return $response;
 }
コード例 #16
0
ファイル: FrontendRouter.php プロジェクト: jarves/jarves
 /**
  * Returns the id of given path-info. Null if not existent.
  *
  * @return Node|null
  */
 public function searchPage()
 {
     $url = $this->getRequest()->getPathInfo();
     $page = null;
     $title = sprintf('Searching Page [%s]', $url);
     $this->stopwatch->start($title);
     if (!$page) {
         $domain = $this->pageStack->getCurrentDomain();
         $urls = $this->pageStack->getCachedUrlToPage($domain->getId());
         $possibleUrl = $url;
         $id = false;
         while (1) {
             if (isset($urls[$possibleUrl])) {
                 $id = $urls[$possibleUrl];
                 break;
             }
             if (false !== ($pos = strrpos($possibleUrl, '/'))) {
                 $possibleUrl = substr($possibleUrl, 0, $pos);
             } else {
                 break;
             }
         }
         if (!$id) {
             //set to startpage
             $id = $domain->getStartnodeId();
             $possibleUrl = '/';
         }
         $url = $possibleUrl;
         if ($url == '/') {
             $pageId = $this->pageStack->getCurrentDomain()->getStartnodeId();
             if (!$pageId > 0) {
                 $this->eventDispatcher->dispatch('core/domain-no-start-page');
             }
         } else {
             $pageId = $id;
         }
         /** @var \Jarves\Model\Node $page */
         $page = $this->pageStack->getPage($pageId);
     }
     $this->stopwatch->stop($title);
     return $page;
 }
コード例 #17
0
ファイル: ContentRender.php プロジェクト: jarves/jarves
 /**
  * Filters $contents and returns only $content items which have valid access. (is visible, accessible by current user etc)
  *
  * @param Content[] $contents
  *
  * @return array
  */
 protected function filterContentsForAccess($contents)
 {
     $filteredContents = [];
     foreach ($contents as $content) {
         $access = true;
         if (is_string($content)) {
             $filteredContents[] = $content;
             continue;
         }
         if ($content->getAccessFrom() + 0 > 0 && $content->getAccessFrom() > time() || $content->getAccessTo() + 0 > 0 && $content->getAccessTo() < time()) {
             $access = false;
         }
         if ($content->getHide()) {
             $access = false;
         }
         if ($access && $content->getAccessFromGroups()) {
             $access = false;
             $groups = ',' . $content->getAccessFromGroups() . ',';
             $userGroups = $this->pageStack->getUser()->getUserGroups();
             foreach ($userGroups as $group) {
                 if (strpos($groups, ',' . $group->getGroupId() . ',') !== false) {
                     $access = true;
                     break;
                 }
             }
             if (!$access) {
                 $adminGroups = $this->pageStack->getUser()->getUserGroups();
                 foreach ($adminGroups as $group) {
                     if (strpos($groups, ',' . $group->getGroupId() . ',') !== false) {
                         $access = true;
                         break;
                     }
                 }
             }
         }
         if ($access) {
             $filteredContents[] = $content;
         }
     }
     return $filteredContents;
 }
コード例 #18
0
 /**
  * @ApiDoc(
  *  section="Interface i18n",
  *  description="Prints all language messages"
  * )
  *
  * @Rest\QueryParam(name="lang", requirements="[a-z]{2,3}", strict=true, description="The language code")
  * @Rest\QueryParam(name="javascript", requirements=".+", default=false, description="If it should be printed as javascript")
  *
  * @Rest\Get("/admin/ui/language")
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return array|string depends on javascript param
  */
 public function getLanguageAction(ParamFetcher $paramFetcher)
 {
     $lang = $paramFetcher->get('lang');
     $javascript = $paramFetcher->get('javascript');
     if (!$this->translator->isValidLanguage($lang)) {
         $lang = 'en';
     }
     $this->pageStack->getSession()->set('admin_language', $lang);
     $messages = $this->translator->loadMessages($lang);
     if ($javascript) {
         $response = new Response();
         $response->headers->set('Content-Type', 'text/javascript');
         $content = "if( typeof(jarves)=='undefined') window.jarves = {}; jarves.lang = " . json_encode($messages, JSON_PRETTY_PRINT);
         $content .= "\nLocale.define('en-US', 'Date', " . $this->templating->render('JarvesBundle:Default:javascript-locales.js.twig') . ");";
         $response->setContent($content);
         return $response;
     } else {
         $messages['mootools'] = $this->templating->render('JarvesBundle:Default:javascript-locales.js.twig');
         return $messages;
     }
 }
コード例 #19
0
ファイル: AdminController.php プロジェクト: jarves/jarves
 /**
  * @ApiDoc(
  *  section="Administration",
  *  description="Returns a renderer content element as preview for Jarves page editor"
  * )
  *
  * @Rest\QueryParam(name="template", requirements=".+", strict=true,
  *      description="The template/view to be used for this content")
  *
  * @Rest\QueryParam(name="type", requirements=".+", strict=true, description="The content type")
  *
  * @Rest\QueryParam(name="nodeId", requirements="[0-9]+",
  *      description="The node id in which context this content should be rendered")
  * @Rest\QueryParam(name="domainId", requirements="[0-9]+",
  *      description="The domain id in which context this content should be rendered")
  * @Rest\RequestParam(name="content", requirements=".*", description="The actual content")
  *
  * @Rest\Post("/admin/content/preview")
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return array
  */
 public function getContentPreviewAction(ParamFetcher $paramFetcher)
 {
     $template = $paramFetcher->get('template');
     $type = $paramFetcher->get('type');
     $content = $paramFetcher->get('content');
     $nodeId = $paramFetcher->get('nodeId');
     $domainId = $paramFetcher->get('domainId');
     //todo, check if $template is defined as content template
     $contentObject = new Content();
     $contentObject->setType($type);
     $contentObject->setTemplate($template);
     $contentObject->setContent($content);
     if ($domainId) {
         $domain = $this->pageStack->getDomain($domainId);
         $this->pageStack->setCurrentDomain($domain);
     }
     if ($nodeId) {
         $page = $this->pageStack->getPage($nodeId);
         $this->pageStack->setCurrentPage($page);
     }
     return $this->contentRender->renderContent($contentObject, ['preview' => true]);
 }
コード例 #20
0
ファイル: Utils.php プロジェクト: jarves/jarves
 /**
  * Adds a new news-feed entry. If not message (means null) is passed we generate a diff.
  *
  * @param Objects $repo
  * @param string $objectKey
  * @param array $item
  * @param string $verb
  * @param string|null $message
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function newNewsFeed(Objects $repo, $objectKey, $item, $verb, $message = null)
 {
     $definition = $repo->getDefinition($objectKey);
     $itemLabel = '';
     if ($labelField = $definition->getLabelField()) {
         $itemLabel = $item[$labelField];
     }
     if (!$itemLabel) {
         $pks = $definition->getPrimaryKeys();
         $itemLabel = '#' . $item[$pks[0]->getId()];
     }
     $username = '******';
     $userId = 0;
     if ($user = $this->pageStack->getUser()) {
         $userId = $user->getId();
         if ($user->getFirstName() || $user->getLastName()) {
             $username = $user->getFirstName();
             if ($username) {
                 $username .= ' ';
             }
             $username .= $user->getLastName();
         } else {
             $username = $user->getUsername();
         }
     }
     $newsFeed = new \Jarves\Model\NewsFeed();
     $newsFeed->setUsername($username);
     $newsFeed->setUserId($userId);
     $newsFeed->setVerb($verb);
     $newsFeed->setTargetObject($objectKey);
     $newsFeed->setTargetPk($repo->getObjectUrlId($objectKey, $item));
     $newsFeed->setTargetLabel($itemLabel);
     $newsFeed->setCreated(time());
     $newsFeed->setMessage(null === $message ? $this->generateDiff($repo, $objectKey, $item) : $message);
     $newsFeed->save();
 }
コード例 #21
0
ファイル: UserLogin.php プロジェクト: jarves/jarves
 /**
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function doLogout()
 {
     $this->userOperator->logout();
     return RedirectResponse::create($this->pageStack->getCurrentUrl());
 }
コード例 #22
0
ファイル: ConditionOperator.php プロジェクト: jarves/jarves
 /**
  * @param array $objectItem
  * @param array $conditionRule
  * @param string $objectKey
  *
  * @return bool
  */
 public function checkRule($objectItem, $conditionRule, $objectKey = null)
 {
     $field = $conditionRule[0];
     $operator = $conditionRule[1];
     $value = $conditionRule[2];
     if (is_numeric($field)) {
         $ovalue = $field;
     } else {
         $ovalue = @$objectItem[$field];
         if (null === $ovalue && $objectKey && ($definition = $this->objects->getDefinition($objectKey))) {
             $tableName = substr($field, 0, strpos($field, '.'));
             $fieldName = substr($field, strpos($field, '.') + 1);
             if ($tableName === $definition->getTable()) {
                 $ovalue = $objectItem[$fieldName];
             }
         }
     }
     if ($value instanceof ConditionSubSelect) {
         $value = $value->getValue($objectKey);
     }
     //'<', '>', '<=', '>=', '=', 'LIKE', 'IN', 'REGEXP'
     switch (strtoupper($operator)) {
         case '!=':
         case 'NOT EQUAL':
             return $ovalue != $value;
         case 'LIKE':
             $value = preg_quote($value, '/');
             $value = str_replace('%', '.*', $value);
             $value = str_replace('_', '.', $value);
             return !!preg_match('/^' . $value . '$/', $ovalue);
         case 'REGEXP':
             return !!preg_match('/' . preg_quote($value, '/') . '/', $ovalue);
         case 'NOT IN':
             return strpos(',' . $value . ',', ',' . $ovalue . ',') === false;
         case 'IN':
             return strpos(',' . $value . ',', ',' . $ovalue . ',') !== false;
         case '<':
         case 'LESS':
             return $ovalue < $value;
         case '>':
         case 'GREATER':
             return $ovalue > $value;
         case '<=':
         case '=<':
         case 'LESSEQUAL':
             return $ovalue <= $value;
         case '>=':
         case '=>':
         case 'GREATEREQUAL':
             return $ovalue >= $value;
         case '= CURRENT_USER':
         case 'EQUAL CURRENT_USER':
             return $this->pageStack->isLoggedIn() && $ovalue == $this->pageStack->getUser()->getId();
         case '!= CURRENT_USER':
         case 'NOT EQUAL CURRENT_USER':
             return $this->pageStack->isLoggedIn() && $ovalue != $this->pageStack->getUser()->getId();
         case '=':
         case 'EQUAL':
         default:
             return $ovalue == $value;
     }
 }
コード例 #23
0
ファイル: TerminationListener.php プロジェクト: jarves/jarves
 public function onKernelTerminate(PostResponseEvent $event)
 {
     $this->pageStack->reset();
     $this->jarves->terminate();
 }
コード例 #24
0
ファイル: NodeUrlExtension.php プロジェクト: jarves/jarves
 public function getUrl($nodeOrId = false)
 {
     return $this->pageStack->getNodeUrl($nodeOrId);
 }
コード例 #25
0
ファイル: PageResponse.php プロジェクト: jarves/jarves
 /**
  * Gets the html title.
  *
  * @return string
  */
 public function getTitle()
 {
     if (null !== $this->title) {
         return $this->title;
     }
     if ($this->getDomainHandling() && $this->pageStack->getCurrentDomain()) {
         $title = $this->pageStack->getCurrentDomain()->getTitleFormat() ?: '%title%';
         if ($page = $this->pageStack->getCurrentPage()) {
             return str_replace(array('%title%'), array($page->getAlternativeTitle() ?: $page->getTitle()), $title);
         }
     } else {
         if ($this->pageStack->getCurrentPage()) {
             return $this->pageStack->getCurrentPage()->getTitle();
         }
     }
 }
コード例 #26
0
ファイル: PageController.php プロジェクト: jarves/jarves
 /**
  * Returns a permanent(301) redirectResponse object.
  *
  * @return RedirectResponse
  */
 public function redirectToStartPageAction()
 {
     $qs = $this->pageStack->getRequest()->getQueryString();
     $response = new RedirectResponse(($this->pageStack->getRequest()->getBaseUrl() ?: '') . ($qs ? '?' . $qs : ''), 301);
     return $response;
 }
コード例 #27
0
ファイル: ACL.php プロジェクト: jarves/jarves
 /**
  * @param ACLRequest $aclRequest
  *
  * @return bool
  */
 public function check(ACLRequest $aclRequest)
 {
     $objectKey = Objects::normalizeObjectKey($aclRequest->getObjectKey());
     $targetType = $aclRequest->getTargetType();
     $targetId = $aclRequest->getTargetId();
     $pk = $aclRequest->getPrimaryKey();
     $field = $aclRequest->getField();
     $pk = $this->objects->normalizePkString($objectKey, $pk);
     if (ACL::TARGET_TYPE_USER === $targetType && null === $targetId) {
         //0 means guest
         $targetId = $this->pageStack->getUser() ? $this->pageStack->getUser()->getId() : 0;
     }
     $user = $this->pageStack->getUser();
     if ($user) {
         $groupIds = $user->getGroupIds();
         if (false !== strpos(',' . $groupIds . ',', ',1,')) {
             //user is in the admin group, so he has always access.
             return true;
         }
     }
     if (ACL::TARGET_TYPE_USER === $targetType && 1 === $targetId) {
         //user admin has always access
         return true;
     }
     if (ACL::TARGET_TYPE_GROUP === $targetType && 1 === $targetId) {
         //group admin has always access
         return true;
     }
     if (0 === $targetId) {
         //guests do always have no access
         return false;
     }
     if (ACL::TARGET_TYPE_GROUP === $targetType && !$targetId) {
         throw new \InvalidArgumentException('For type TARGET_TYPE_GROUP a targetId is required.');
     }
     $cacheKey = null;
     if ($pk && $this->getCaching()) {
         $pkString = $this->objects->getObjectUrlId($objectKey, $pk);
         $cacheKey = md5($targetType . '.' . $targetId . '.' . $objectKey . '/' . $pkString . '/' . json_encode($field));
         $cached = $this->cacher->getDistributedCache('core/acl/' . $cacheKey);
         if (null !== $cached) {
             return $cached;
         }
     }
     $rules = self::getRules($objectKey, $aclRequest->getMode(), $targetType, $targetId);
     if (count($rules) === 0) {
         //no rules found, so we have no access
         return false;
     }
     $access = null;
     $currentObjectPk = $pk;
     $definition = $this->objects->getDefinition($objectKey);
     $not_found = true;
     //starts directly as if we were in the parent checking.
     $parent_acl = $aclRequest->isAsParent();
     $fCount = null;
     $fKey = null;
     $fValue = null;
     $fIsArray = is_array($field);
     if ($fIsArray) {
         $fCount = count($field);
         $fKey = key($field);
         $fValue = current($field);
         if (is_int($fKey)) {
             $fKey = $fValue;
             $fValue = null;
         }
     }
     $depth = 0;
     $match = false;
     $originObjectItemPk = $currentObjectPk;
     while ($not_found) {
         $currentObjectPkString = null;
         if ($currentObjectPk) {
             $currentObjectPkString = $this->objects->getObjectUrlId($objectKey, $currentObjectPk);
         }
         $depth++;
         if ($depth > 50) {
             $not_found = false;
             break;
         }
         foreach ($rules as $aclRule) {
             if ($parent_acl && !$aclRule['sub']) {
                 //as soon we enter the parent_acl mode we only take acl rules into consideration
                 //that are also valid for children (sub=true)
                 continue;
             }
             $match = false;
             /*
              * CUSTOM CONSTRAINT
              */
             if ($aclRule['constraint_type'] === ACL::CONSTRAINT_CONDITION) {
                 $objectItem = null;
                 if ($originObjectItemPk === $currentObjectPk && null !== $aclRequest->getPrimaryObjectItem()) {
                     $objectItem = $aclRequest->getPrimaryObjectItem();
                 } else {
                     if ($originObjectItemPk) {
                         $objectItem = $this->objects->get($objectKey, $currentObjectPk);
                     }
                 }
                 if ($objectItem && $this->conditionOperator->satisfy($aclRule['constraint_code'], $objectItem, $objectKey)) {
                     $match = true;
                 }
                 /*
                  * EXACT
                  */
             } else {
                 if ($aclRule['constraint_type'] === ACL::CONSTRAINT_EXACT) {
                     if ($currentObjectPk && $aclRule['constraint_code'] === $currentObjectPkString) {
                         $match = true;
                     }
                     /**
                      * ALL
                      */
                 } else {
                     $match = true;
                 }
             }
             if (!$match && $aclRule['sub'] && $currentObjectPk) {
                 // we need to check if a parent matches this $acl as we have sub=true
                 $parentItem = $this->objects->normalizePkString($objectKey, $currentObjectPk);
                 $parentCondition = Condition::create($aclRule['constraint_code']);
                 $parentOptions['fields'] = $this->conditionOperator->extractFields($parentCondition);
                 while ($parentItem = $this->objects->getParent($objectKey, $this->objects->getObjectPk($objectKey, $parentItem), $parentOptions)) {
                     if ($aclRule['constraint_type'] === ACL::CONSTRAINT_CONDITION && $this->conditionOperator->satisfy($parentCondition, $parentItem)) {
                         $match = true;
                         break;
                     } else {
                         if ($aclRule['constraint_type'] === ACL::CONSTRAINT_EXACT && $aclRule['constraint_code'] === $this->objects->getObjectUrlId($objectKey, $parentItem)) {
                             $match = true;
                             break;
                         }
                     }
                 }
             }
             if ($match) {
                 //match, check all $field
                 $field2Key = $field;
                 if ($field) {
                     if ($fIsArray && $fCount === 1) {
                         if (is_string($fKey) && is_array($aclRule['fields'][$fKey])) {
                             //this field has limits
                             if (($field2Acl = $aclRule['fields'][$fKey]) !== null) {
                                 if (is_array($field2Acl[0])) {
                                     //complex field rule, $field2Acl = ([{access: no, condition: [['id', '>', 2], ..]}, {}, ..])
                                     foreach ($field2Acl as $fRule) {
                                         $satisfy = false;
                                         if (($f = $definition->getField($fKey)) && $f->getType() === 'object') {
                                             $uri = $f->getObject() . '/' . $fValue;
                                             $uriObject = $this->objects->getFromUrl($uri);
                                             $satisfy = $this->conditionOperator->satisfy($fRule['condition'], $uriObject);
                                         } else {
                                             if (null !== $fValue) {
                                                 $satisfy = $this->conditionOperator->satisfy($fRule['condition'], $field);
                                             }
                                         }
                                         if ($satisfy) {
                                             return $fRule['access'] === 1 ? true : false;
                                         }
                                     }
                                     //if no field rules fits, we consider the whole rule
                                     if ($aclRule['access'] !== 2) {
                                         return $aclRule['access'] === 1 ? true : false;
                                     }
                                 } else {
                                     //simple field rule $field2Acl = ({"value1": yes, "value2": no}
                                     if ($field2Acl[$fKey] !== null) {
                                         return $field2Acl[$fKey] === 1 ? true : false;
                                     } else {
                                         //current($field) is not exactly defined in $field2Acl, so we set $access to $acl['access']
                                         //
                                         //if access = 2 then wo do not know it, cause 2 means 'inherited', so maybe
                                         //a other rule has more detailed rule
                                         if ($aclRule['access'] !== 2) {
                                             $access = $aclRule['access'] === 1 ? true : false;
                                             break;
                                         }
                                     }
                                 }
                             }
                         } else {
                             //this field has only true or false
                             $field2Key = $fKey;
                         }
                     }
                     if (!is_array($field2Key)) {
                         if ($aclRule['fields'] && ($field2Acl = $aclRule['fields'][$field2Key]) !== null && !is_array($aclRule['fields'][$field2Key])) {
                             $access = $field2Acl === 1 ? true : false;
                             break;
                         } else {
                             //$field is not exactly defined, so we set $access to $acl['access']
                             //and maybe a rule with the same code has the field defined
                             // if access = 2 then this rule is only for exactly define fields
                             if ($aclRule['access'] !== 2) {
                                 $access = $aclRule['access'] === 1 ? true : false;
                                 break;
                             }
                         }
                     }
                 } else {
                     $access = $aclRule['access'] === 1 ? true : false;
                     break;
                 }
             }
         }
         //foreach
         if (null === $access && $definition->isNested() && $pk) {
             //$access has not defined yet (no rule matched yet). Check if nested and $pk is given
             //load its root and check again
             if (null === ($currentObjectPk = $this->objects->getParentPk($objectKey, $currentObjectPk))) {
                 $access = $aclRequest->isRootHasAccess() ? true : $access;
                 break;
             }
             $parent_acl = true;
         } else {
             break;
         }
     }
     $access = (bool) $access;
     if ($pk && $this->getCaching()) {
         $this->cacher->setDistributedCache('core/acl/' . $cacheKey, $access);
     }
     return $access;
 }
コード例 #28
0
ファイル: LoadAssetExtension.php プロジェクト: jarves/jarves
 public function loadAssetAtBottom($asset, $contentType = null)
 {
     $this->pageStack->getPageResponse()->loadAssetFileAtBottom($asset, $contentType);
 }
コード例 #29
0
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
         //we need to reset all routes. They will anyway replaced by FrontendRouter::loadRoutes,
         //but to prevent caching conflicts, when a user removes a plugin for example
         //from a page, we need to know that without using actual caching.
         $this->routes = new RouteCollection();
         $this->urlMatcher->__construct($this->routes, $this->requestContext);
         //prepare for new master request: clear the PageResponse object
         $this->pageStack->setCurrentPage(null);
         $this->pageStack->setCurrentDomain(null);
         $this->pageStack->setPageResponse($this->pageResponseFactory->create());
         $this->frontendRouter->setRequest($request);
         $editorNodeId = (int) $this->pageStack->getRequest()->get('_jarves_editor_node');
         $editorDomainId = (int) $this->pageStack->getRequest()->get('_jarves_editor_domain');
         $domain = null;
         if ($editorDomainId) {
             $domain = $this->pageStack->getDomain($editorDomainId);
             if (!$domain) {
                 //we haven't found any domain that is responsible for this request
                 return;
             }
             $this->pageStack->setCurrentDomain($domain);
         }
         if ($editorNodeId) {
             //handle jarves content editor stuff
             //access is later checked
             if (!$editorNodeId && $domain) {
                 $editorNodeId = $domain->getStartnodeId();
             }
             $page = $this->pageStack->getPage($editorNodeId);
             if (!$page || !$page->isRenderable()) {
                 //we haven't found any page that is responsible for this request
                 return;
             }
             if (!$domain) {
                 $domain = $this->pageStack->getDomain($page->getDomainId());
             }
             $this->pageStack->setCurrentPage($page);
             $this->pageStack->setCurrentDomain($domain);
             $request->attributes->set('_controller', 'jarves.page_controller:handleAction');
         } else {
             //regular frontend route search
             //search domain
             if (!$domain) {
                 $domain = $this->frontendRouter->searchDomain();
                 if (!$domain) {
                     //we haven't found any domain that is responsible for this request
                     return;
                 }
                 $this->pageStack->setCurrentDomain($domain);
             }
             //search page
             $page = $this->frontendRouter->searchPage();
             if (!$page || !$page->isRenderable()) {
                 //we haven't found any page that is responsible for this request
                 return;
             }
             $this->pageStack->setCurrentPage($page);
             if ($response = $this->frontendRouter->loadRoutes($this->routes, $page)) {
                 //loadRoutes return in case of redirects and permissions a redirect or 404 response.
                 $event->setResponse($response);
                 return;
             }
             try {
                 //check routes in $this->route
                 parent::onKernelRequest($event);
             } catch (MethodNotAllowedException $e) {
             } catch (NotFoundHttpException $e) {
             }
         }
     }
 }
コード例 #30
0
 public function onKernelController(FilterControllerEvent $event)
 {
     if ($this->pageStack->isAdmin()) {
         $this->paramFetcherOnKernelController($event);
     }
 }