Esempio n. 1
0
 /**
  * Perform any final actions for the request lifecycle.
  *
  * @param  \Symfony\Component\HttpFoundation\Request $request
  * @param  \Symfony\Component\HttpFoundation\Response $response
  * @return void
  */
 public function terminate($request, $response)
 {
     if (Auth::user()) {
         Log::create(array('user_id' => Auth::user()->id, 'path' => $request->path(), 'ip' => $request->ip()));
     } else {
         Log::create(array('path' => $request->path(), 'ip' => $request->ip()));
     }
 }
Esempio n. 2
0
 /**
  * Dispatch a Assets File Response.
  *
  * @return \Symfony\Component\HttpFoundation\Response|null
  */
 public function dispatch(SymfonyRequest $request)
 {
     // For proper Assets serving, the file URI should be either of the following:
     //
     // /templates/default/assets/css/style.css
     // /modules/blog/assets/css/style.css
     // /assets/css/style.css
     if (!in_array($request->method(), array('GET', 'HEAD'))) {
         // The Request Method is not valid for Asset Files.
         return null;
     }
     // Calculate the Asset File path, looking for a valid one.
     $uri = $request->path();
     if (preg_match('#^(templates|modules)/([^/]+)/assets/(.*)$#i', $uri, $matches)) {
         $baseName = strtolower($matches[1]);
         //
         $folder = $matches[2];
         if ($folder == 'adminlte' && $baseName == 'templates') {
             // The Asset path is on the AdminLTE Template.
             $folder = 'AdminLTE';
         } else {
             if (strlen($folder) > 3) {
                 // A standard Template or Module name.
                 $folder = Str::studly($folder);
             } else {
                 // A short Template or Module name.
                 $folder = strtoupper($folder);
             }
         }
         $path = str_replace('/', DS, $matches[3]);
         $filePath = APPDIR . ucfirst($baseName) . DS . $folder . DS . 'Assets' . DS . $path;
     } else {
         if (preg_match('#^(assets|vendor)/(.*)$#i', $uri, $matches)) {
             $baseName = strtolower($matches[1]);
             //
             $path = $matches[2];
             if ($baseName == 'vendor' && !Str::startsWith($path, $this->paths)) {
                 // The current URI is not a valid Asset File path on Vendor.
                 return null;
             }
             $filePath = ROOTDIR . $baseName . DS . str_replace('/', DS, $path);
         } else {
             // The current URI is not a valid Asset File path.
             return null;
         }
     }
     // Create a Response for the current Asset File path.
     $response = $this->serve($filePath, $request);
     // Prepare the Response instance.
     $response->prepare($request);
     return $response;
 }
 public function createFromRequest(Request $request)
 {
     $originalPath = $request instanceof CmsRequest ? $request->originalPath() : $request->path();
     $scope = $this->scopeDetector->detectScope($request);
     try {
         // Find matching page
         if (!($node = $this->getFirstMatchingNode($scope, $originalPath))) {
             return $this->createDeactivated($scope, $originalPath);
         }
     } catch (DomainException $e) {
         // if db is empty
         return $this->createDeactivated($scope, $originalPath);
     }
     $cmsPath = new CmsPath();
     $cmsPath->setOriginalPath($originalPath);
     $cmsPath->setIsCmsPath(TRUE);
     $cmsPath->setMatchedNode($node);
     $cmsPath->setFallbackNode($this->getFallbackNode($scope));
     $cmsPath->setCmsPathPrefix($this->cleanPathPrefix($scope->getPathPrefix()));
     $cmsPath->setTreeScope($scope);
     $pageType = $this->getPageType($node);
     $cmsPath->setPageType($pageType);
     $targetPath = $pageType->getTargetPath();
     $nodePath = $this->cleanHomeSegment($node->getPath());
     $originalPath = $this->cleanHomeSegment($originalPath);
     $cmsPath->setNodePath($node->getPath());
     $cmsPath->setRoutePath($targetPath);
     $rewrittenPath = trim($this->replacePathHead($nodePath, $targetPath, $originalPath), '/');
     $subPath = trim($this->replacePathHead($nodePath, '', $originalPath), '/');
     if (!$rewrittenPath) {
         $rewrittenPath = '/';
     }
     $rewrittenPath = $this->changePathWhenNotGet($request, $rewrittenPath);
     $cmsPath->setRewrittenPath($rewrittenPath);
     $cmsPath->setSubPath($subPath);
     return $cmsPath;
 }