<commit_before><?php namespace Bkwld\Decoy\Routing;

// Dependencies
use Agent; // Laravel-Agent package
use App;
use Bkwld\Decoy\Breadcrumbs;
use Config;
use Decoy;
use DecoyURL;
use HTML;
use Illuminate\Support\ViewErrorBag;
use Illuminate\Support\MessageBag;
use Input;
use Redirect;
use Request;
use Route;
use Session;
use Str;
use URL;
use View;

/**
 * Route filters for Decoy
 */
class Filters {
	
	// Properties
	private $dir; // The path "directory" of the admin.  I.e. "admin"
	
	/**
	 * Constructor
	 * @param string $dir The path "directory" of the admin.  I.e. "admin"
	 */
	public function __construct($dir) {
		$this->dir = $dir;
	}
	
	/**
	 * Register all filters during the `before` callback
	 *
	 * @param Illuminate\Http\Request $request 
	 */
	public function onBefore($request) {

		// Add Decoy's frontend tools if show_frontend_tools is set in the site config
		if (Config::get('decoy::site.show_frontend_tools')) Route::after([$this, 'frontendTools']);

		// Dont' register anything more if we're not in the admin.
		if (!Decoy::handling()) return;

		// Filters are added during a "before" handler via the Decoy service
		// provider, so this can just be run directly.
		$this->csrf();
		$this->supportedBrowsers();
		
		// Access control
		Route::filter('decoy.acl', array($this, 'acl'));
		Route::when($this->dir.'/*', 'decoy.acl');
		
		// Save redirect
		Route::filter('decoy.saveRedirect', array($this, 'saveRedirect'));
		Route::when($this->dir.'/*', 'decoy.saveRedirect');
		
		// Redirect old edit links.  Route::when() does not support true regular
		// expressions, thus had to catch all
		Route::filter('decoy.editRedirect', array($this, 'editRedirect'));
		Route::when($this->dir.'/*', 'decoy.editRedirect', array('get'));

		// Tell IE that we're compatible so it doesn't show the compatbility checkbox
		Route::after(function($request, $response) {
			$response->header('X-UA-Compatible', 'IE=Edge');
		});
	}

	/**
	 * Add markup needed for Decoy's frontend tools
	 *
	 * @param $request Illuminate\Http\Request
	 * @param $response Illuminate\Http\Response
	 */
	public function frontendTools($request, $response) {
		if (app('decoy.auth')->check() // Require an authed admin
			&& !Decoy::handling() // Don't apply to the backend
			&& ($content = $response->getContent()) // Get the whole response HTML
			&& is_string($content)) { // Double check it's a string
			
			// Add the Decoy Frontend markup to the page right before the closing body tag
			$response->setContent(
				str_replace('</body>', View::make('decoy::frontend._embed').'</body>', $content)
			);
		}
	}
	
	/**
	 * Force users to login to the admin
	 */
	public function acl() {
		
		// Do nothing if the current path contains any of the whitelisted urls
		if ($this->isPublic()) return;

		// Everything else in admin requires a logged in user.  So redirect
		// to login and pass along the current url so we can take the user there.
		if (!App::make('decoy.auth')->check()) return App::make('decoy.acl_fail');

		// Always allow logout
		if (Request::is('/admin/logout')) return;

		// If permissions were defined, see if the user has permission for the current action<commit_msg>Fixing logout exception<commit_after><?php namespace Bkwld\Decoy\Routing;

// Dependencies
use Agent; // Laravel-Agent package
use App;
use Bkwld\Decoy\Breadcrumbs;
use Config;
use Decoy;
use DecoyURL;
use HTML;
use Illuminate\Support\ViewErrorBag;
use Illuminate\Support\MessageBag;
use Input;
use Redirect;
use Request;
use Route;
use Session;
use Str;
use URL;
use View;

/**
 * Route filters for Decoy
 */
class Filters {
	
	// Properties
	private $dir; // The path "directory" of the admin.  I.e. "admin"
	
	/**
	 * Constructor
	 * @param string $dir The path "directory" of the admin.  I.e. "admin"
	 */
	public function __construct($dir) {
		$this->dir = $dir;
	}
	
	/**
	 * Register all filters during the `before` callback
	 *
	 * @param Illuminate\Http\Request $request 
	 */
	public function onBefore($request) {

		// Add Decoy's frontend tools if show_frontend_tools is set in the site config
		if (Config::get('decoy::site.show_frontend_tools')) Route::after([$this, 'frontendTools']);

		// Dont' register anything more if we're not in the admin.
		if (!Decoy::handling()) return;

		// Filters are added during a "before" handler via the Decoy service
		// provider, so this can just be run directly.
		$this->csrf();
		$this->supportedBrowsers();
		
		// Access control
		Route::filter('decoy.acl', array($this, 'acl'));
		Route::when($this->dir.'/*', 'decoy.acl');
		
		// Save redirect
		Route::filter('decoy.saveRedirect', array($this, 'saveRedirect'));
		Route::when($this->dir.'/*', 'decoy.saveRedirect');
		
		// Redirect old edit links.  Route::when() does not support true regular
		// expressions, thus had to catch all
		Route::filter('decoy.editRedirect', array($this, 'editRedirect'));
		Route::when($this->dir.'/*', 'decoy.editRedirect', array('get'));

		// Tell IE that we're compatible so it doesn't show the compatbility checkbox
		Route::after(function($request, $response) {
			$response->header('X-UA-Compatible', 'IE=Edge');
		});
	}

	/**
	 * Add markup needed for Decoy's frontend tools
	 *
	 * @param $request Illuminate\Http\Request
	 * @param $response Illuminate\Http\Response
	 */
	public function frontendTools($request, $response) {
		if (app('decoy.auth')->check() // Require an authed admin
			&& !Decoy::handling() // Don't apply to the backend
			&& ($content = $response->getContent()) // Get the whole response HTML
			&& is_string($content)) { // Double check it's a string
			
			// Add the Decoy Frontend markup to the page right before the closing body tag
			$response->setContent(
				str_replace('</body>', View::make('decoy::frontend._embed').'</body>', $content)
			);
		}
	}
	
	/**
	 * Force users to login to the admin
	 */
	public function acl() {
		
		// Do nothing if the current path contains any of the whitelisted urls
		if ($this->isPublic()) return;

		// Everything else in admin requires a logged in user.  So redirect
		// to login and pass along the current url so we can take the user there.
		if (!App::make('decoy.auth')->check()) return App::make('decoy.acl_fail');

		// Always allow logout
		if (Request::is('admin/logout')) return;

		// If permissions were defined, see if the user has permission for the current action
{'fraction_non_alphanumeric': 0.14741284977333124, 'fraction_numerical': 0.0, 'mean_word_length': 3.739259259259259, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1669515', 'n_tokens_mistral': 2129, 'n_tokens_neox': 1940, 'n_words': 649}