Beispiel #1
0
 public static function maybeTransformHref($href)
 {
     if (starts_with($href, 'press://')) {
         $filename = substr($href, strlen('press://'));
         try {
             $href = PressFacade::findFile($filename)->url();
         } catch (FileNotFoundException $e) {
             throw new LinkedFileNotFoundException("A file for the link {$href} could not be found.");
         }
     }
     return $href;
 }
Beispiel #2
0
 public function showCollection(Route $route, Router $router)
 {
     // We extract the params not set in the query from the URL
     $queryParams = $route->parameters();
     // Figure out the page from the route URL parameters
     $page = max(1, $route->getParameter('page'));
     $routeParams = $route->getAction();
     $query = $routeParams['query'];
     $articles = PressFacade::query($query, $queryParams);
     if (0 === $articles->count() && $page !== 1) {
         return abort(404);
     }
     // create a paginator if required
     if ($routeParams['paginate']) {
         $page_size = PressFacade::getConf('default_page_size');
         $paginator = $articles->getPaginator($page_size);
         $articles = $articles->forPage($page, $page_size);
     } else {
         $paginator = $articles->getPaginator(999999);
     }
     // decide the view. If it is provided with the query options, just use
     // it. if it is provided with a theme wildcard, use the default theme
     // else try to find a 'collection' view in the default theme.
     // Also, the user can set a theme to load the assets from.
     $theme = array_get($routeParams, 'theme', PressFacade::getConf('theme'));
     if (isset($routeParams['view'])) {
         $viewName = str_replace('_::', "{$theme}::", $routeParams['view']);
         $view = View::make($viewName);
     } else {
         $view = View::make("{$theme}::collection");
     }
     // paginator base path
     $baseUrlParamNames = $this->getRouteParamNames($routeParams['base_route'], $router);
     $baseUrlParams = array_only($queryParams, $baseUrlParamNames);
     $basePath = \URL::route($routeParams['base_route'], $baseUrlParams);
     $paginator->setBasePath($basePath);
     // metadata from the page can be defined trough the route
     $meta = (object) array_get($routeParams, 'meta', []);
     return $view->with('meta', SEO::getMeta())->with('articles', $articles)->with('cacheInfo', PressFacade::editingCacheInfo())->with('themeAssets', PressFacade::getThemeAssets($theme))->with('paginator', $paginator);
 }
Beispiel #3
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // @todo check if not authentified instead of editing
     if ($request->cookie('pressEditing')) {
         PressFacade::setEditing();
         return $next($request);
     }
     // The cache is automatically served by the webserver. So if
     // we hit this code, the only thing to do is to save the
     // response in an .html file
     // the generated output MUST NOT have user-based content. It
     // must be the same content for everybody
     // PressFacade::skipCache() can be used to not cache the
     // current request
     $response = $next($request);
     if (!PressFacade::isCacheableRequest($request, $response)) {
         return $response;
     }
     $contentHTML = $response->getContent();
     $miniContent = HTMLMinify::minify($contentHTML, ['doctype' => HTMLMinify::DOCTYPE_HTML5]);
     $cache = PressFacade::cache();
     $cache->writeFile($miniContent);
     return $this->makeFakeResponse($miniContent);
 }
Beispiel #4
0
 public function purge()
 {
     PressFacade::cache()->flush();
     return $this->redirectBack();
 }
Beispiel #5
0
 protected function getConf($key = null, $default = null)
 {
     return PressFacade::getConf($key, $default);
 }
Beispiel #6
0
 protected function readFileIfNotRead()
 {
     if ($this->readOK) {
         return;
     }
     $sep = PressFacade::getConf('meta_sep');
     $raw = file_get_contents($this->filename);
     $rawParts = explode($sep, $raw);
     if (count($rawParts) > 1) {
         $this->rawMeta = array_shift($rawParts);
     } else {
         $this->rawMeta = '';
     }
     $this->rawContent = implode($sep, $rawParts);
     $this->readOK = true;
 }
Beispiel #7
0
 public function url()
 {
     return PressFacade::filenameToUrl($this);
 }
Beispiel #8
0
<?php

namespace Lud\Press;

use Route;
Route::group(['namespace' => 'Lud\\Press'], function ($router) {
    Route::get('stop-editing', ['uses' => 'PressEditorController@stopEditing', 'as' => 'press.stop_editing']);
});
Route::group(['middleware' => 'auth', 'namespace' => 'Lud\\Press'], function ($router) {
    Route::get('editing', ['uses' => 'PressEditorController@startEditing', 'as' => 'press.editing']);
    Route::get('refresh', ['uses' => 'PressEditorController@refresh', 'as' => 'press.refresh_page_cache']);
    Route::get('purge', ['uses' => 'PressEditorController@purge', 'as' => 'press.purge_cache']);
});
// We will setup a route for each URL schema defined in the url_map config. We
// do not care about file schemas, since once we hit the controller, it handles
// the file search from URL
foreach (PressFacade::getConf('url_map') as $urlSchema) {
    $routeURL = PressService::replaceStrParts($urlSchema, function ($key) {
        return '{' . $key . '}';
    });
    Route::get($routeURL, ['pressCache' => true, 'uses' => 'Lud\\Press\\PressPubController@publish']);
}
// exit;
Beispiel #9
0
 private function logRequestInfo($message, $contextInfo)
 {
     $serverInfo = $infos = array_merge($contextInfo, array_only($_SERVER, ['HTTP_USER_AGENT', 'HTTP_REFERER']), ['url' => $this->req->fullUrl(), 'editing' => PressFacade::isEditing()]);
     return Log::debug($message, $infos);
 }
Beispiel #10
0
 private function consoleSetup()
 {
     $base = [__DIR__ . '/../../../public' => base_path('public/packages/lud/press'), static::confPath() => config_path('press.php')];
     $themes = PressFacade::themesPublishes();
     $this->publishes(array_merge($base, $themes));
 }
Beispiel #11
0
 public function transform($parserType, $preRendered)
 {
     $config = PressFacade::getConf($parserType, []);
     $method = 'transform' . lcfirst($parserType);
     return $html = call_user_func([$this, $method], $preRendered, $config);
 }