/**
  * Invalidate our database check by removing the timestamp file from cache.
  *
  * @return void
  */
 public function invalidate()
 {
     $fileName = $this->getValidityTimestampFilename();
     // delete the cached dbcheck-ts
     if (is_writable($fileName)) {
         unlink($fileName);
     } elseif (file_exists($fileName)) {
         $message = sprintf("The file '%s' exists, but couldn't be removed. Please remove this file manually, and try again.", $fileName);
         $this->app->abort(Response::HTTP_UNAUTHORIZED, $message);
     }
 }
Exemple #2
0
 /**
  * Checks if translations file is allowed to write to.
  *
  * @return bool
  */
 public function isWriteAllowed()
 {
     $msgRepl = array('%s' => $this->relPath);
     // No file, directory not writable
     if (!file_exists($this->absPath) && !is_writable(dirname($this->absPath))) {
         $msg = Trans::__("The translations file '%s' can't be created. You will have to use your own editor to make modifications to this file.", $msgRepl);
         $this->app['session']->getFlashBag()->add('warning', $msg);
         // Have a file, but not writable
     } elseif (file_exists($this->absPath) && !is_writable($this->absPath)) {
         $msg = Trans::__("The file '%s' is not writable. You will have to use your own editor to make modifications to this file.", $msgRepl);
         $this->app['session']->getFlashBag()->add('warning', $msg);
         // File is not readable: abort
     } elseif (file_exists($this->absPath) && !is_readable($this->absPath)) {
         $msg = Trans::__("The translations file '%s' is not readable.", $msgRepl);
         $this->app->abort(Response::HTTP_NOT_FOUND, $msg);
         // File is writeable
     } else {
         return true;
     }
     return false;
 }
Exemple #3
0
 /**
  * Middleware function to check whether a user is logged on.
  */
 public function before(Request $request, \Bolt\Application $app)
 {
     // Start the 'stopwatch' for the profiler.
     $app['stopwatch']->start('bolt.backend.before');
     // If there's no active session, don't do anything..
     if (!$app['users']->isValidSession()) {
         $app->abort(404, 'You must be logged in to use this.');
     }
     // Most of the 'check if user is allowed' happens here: match the current route to the 'allowed' settings.
     if (!$app['users']->isAllowed('extensions')) {
         $app['session']->getFlashBag()->set('error', __('You do not have the right privileges to view that page.'));
         return redirect('dashboard');
     }
     // Stop the 'stopwatch' for the profiler.
     $app['stopwatch']->stop('bolt.backend.before');
 }
Exemple #4
0
 /**
  * Middleware function to check whether a user is logged on.
  *
  * @return null|\Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function before(Request $request, Application $app)
 {
     // Start the 'stopwatch' for the profiler.
     $app['stopwatch']->start('bolt.backend.before');
     // If there's no active session, don't do anything.
     if (!$app['users']->isValidSession()) {
         $app->abort(Response::HTTP_NOT_FOUND, 'You must be logged in to use this.');
     }
     if (!$app['users']->isAllowed("files:uploads")) {
         $app['session']->getFlashBag()->add('error', Trans::__('You do not have the right privileges to upload.'));
         return Lib::redirect('dashboard');
     }
     // Stop the 'stopwatch' for the profiler.
     $app['stopwatch']->stop('bolt.backend.before');
     return null;
 }
Exemple #5
0
 /**
  * Attempt to rebuild extension autoloader when a "Class not found" error
  * occurs.
  *
  * @param \Bolt\Application $app
  * @param array             $error
  */
 private static function attemptExtensionRecovery($app, $error)
 {
     $cwd = getcwd();
     if ($error['type'] === E_ERROR && strpos($error['message'], 'Class') === 0) {
         $path = $_SERVER['PATH_INFO'];
         if (isset($_SERVER['QUERY_STRING'])) {
             if (strpos($_SERVER['QUERY_STRING'], 'rebuild-autoloader') !== false) {
                 header("location: {$path}?rebuild-done");
             } elseif (strpos($_SERVER['QUERY_STRING'], 'rebuild-done') !== false) {
                 chdir($cwd);
                 return;
             }
         }
         restore_error_handler();
         $html = self::$html;
         $html = str_replace('%error_title%', 'PHP Fatal Error: Bolt Extensions Class Loader', $html);
         $message = '<b>Attempting to rebuild extension autoloader</b>';
         $message .= "<p>Redirecting to <a href='{$path}?rebuild-autoloader'>{$path}</a> on completion.</p>";
         $message .= "<script>window.setTimeout(function () { window.location='{$path}?rebuild-autoloader'; }, 5000);</script>";
         $message = nl2br($message);
         $html = str_replace('%error%', $message, $html);
         $html = str_replace('%info%', '', $html);
         if (php_sapi_name() == 'cli') {
             $html = self::cleanHTML($html) . "\n\n";
         }
         echo $html;
         $app['extend.enabled'] = false;
         $app['extensions']->checkLocalAutoloader(true);
         $html = '<div style="max-width: 640px; margin: auto;"><p class="status-ok">Completed rebuild… Attempting reload!</p>';
         if (php_sapi_name() == 'cli') {
             $html = self::cleanHTML($html) . "\n\n";
         }
         echo $html;
         // Reboot the application and retry loading
         chdir($cwd);
         $app->boot();
         $app->abort(Response::HTTP_MOVED_PERMANENTLY);
     }
 }
 public static function sorttaxonomy(\Bolt\Application $app, $taxonomytype, $slug)
 {
     // First, get some content
     $page = $app['request']->query->get('page', 1);
     $order = $app['request']->query->get('order');
     $amount = $app['config']->get('general/listing_records');
     $order = !empty($order) ? $order : (!empty($contenttype['sort']) ? $contenttype['sort'] : $app['config']->get('general/listing_sort'));
     $content = $app['storage']->getContentByTaxonomy($taxonomytype, $slug, array('limit' => $amount, 'order' => $order, 'page' => $page));
     $taxonomytype = $app['storage']->getTaxonomyType($taxonomytype);
     // No taxonomytype, no possible content..
     if (empty($taxonomytype)) {
         return false;
     } else {
         $taxonomyslug = $taxonomytype['slug'];
     }
     if (!$content) {
         $app->abort(404, "Content for '{$taxonomyslug}/{$slug}' not found.");
     }
     $chosen = "taxonomy";
     // Set the template based on the (optional) setting in taxonomy.yml, or fall back to default listing template
     if ($app['config']->get('taxonomy/' . $taxonomyslug . '/listing_template')) {
         $template = $app['config']->get('taxonomy/' . $taxonomyslug . '/listing_template');
     } else {
         $template = $app['config']->get('general/listing_template');
     }
     $app['logger.system']->debug('template chosen: ' . $app['config']->get('general/theme') . "/{$template} ({$chosen})", array('event' => 'FrontendExt'));
     //$app['log']->setValue('templatechosen', $app['config']->get('general/theme') . "/$template ($chosen)");
     // Fallback: If file is not OK, show an error page
     $filename = $app['paths']['themepath'] . "/" . $template;
     if (!file_exists($filename) || !is_readable($filename)) {
         $error = sprintf("No template for '%s'-listing defined. Tried to use '%s/%s'.", $taxonomyslug, basename($app['config']->get('general/theme')), $template);
         //$app['log']->setValue('templateerror', $error);
         $app['logger.system']->error($error, array('event' => 'FrontendExt'));
         $app->abort(404, $error);
     }
     $name = $slug;
     // Look in taxonomies in 'content', to get a display value for '$slug', perhaps.
     foreach ($content as $record) {
         $flat = \Util::array_flatten($record->taxonomy);
         $key = $app['paths']['root'] . $taxonomytype['slug'] . '/' . $slug;
         if (isset($flat[$key])) {
             $name = $flat[$key];
         }
         $key = $app['paths']['root'] . $taxonomytype['singular_slug'] . '/' . $slug;
         if (isset($flat[$key])) {
             $name = $flat[$key];
         }
     }
     $app['twig']->addGlobal('records', $content);
     $app['twig']->addGlobal('slug', $name);
     $app['twig']->addGlobal('taxonomy', $app['config']->get('taxonomy/' . $taxonomyslug));
     $app['twig']->addGlobal('taxonomytype', $taxonomyslug);
     return $app['render']->render($template);
 }
Exemple #7
0
 /**
  * Middleware function to check whether a user is logged on.
  */
 public function before(Request $request, \Bolt\Application $app)
 {
     // Start the 'stopwatch' for the profiler.
     $app['stopwatch']->start('bolt.backend.before');
     // If there's no active session, don't do anything..
     if (!$app['users']->isValidSession()) {
         $app->abort(404, "You must be logged in to use this.");
     }
     // Stop the 'stopwatch' for the profiler.
     $app['stopwatch']->stop('bolt.backend.before');
 }