<commit_before><?php

/**
 * Sticky Notes
 *
 * An open source lightweight pastebin application
 *
 * @package     StickyNotes
 * @author      <NAME>
 * @copyright   (c) 2013 <NAME> <<EMAIL>>
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @link        http://sayakbanerjee.com/sticky-notes
 * @since       Version 1.0
 * @filesource
 */

/**
 * AdminController
 *
 * This controller handles site administration
 *
 * @package     StickyNotes
 * @subpackage  Controllers
 * @author      <NAME>
 */
class AdminController extends BaseController {

	/**
	 * Redirects to the administration dashboard
	 *
	 * @access public
	 * @return \Illuminate\Support\Facades\Redirect
	 */
	public function getIndex()
	{
		return Redirect::to('admin/dashboard');
	}

	/**
	 * Displays the administration dashboard
	 *
	 * @access public
	 * @return \Illuminate\Support\Facades\View
	 */
	public function getDashboard()
	{
		// Get the application configuration
		$app = Config::get('app');

		// Get the database configuration
		$db = Config::get('database');

		// Collect view data
		$data = array(
			'users'         => User::count(),
			'pastes'        => Paste::count(),
			'php_version'   => phpversion(),
			'sn_version'    => $app['version'],
			'db_driver'     => $db['default'],
		);

		return View::make('admin/dashboard', $data);
	}

	/**
	 * Search, edit and delete pastes
	 *
	 * @param  string  $urlkey
	 * @param  string  $action
	 * @return \Illuminate\Support\Facades\View|\Illuminate\Support\Facades\Redirect
	 */
	public function getPaste($urlkey = '', $action = '')
	{
		$paste = NULL;

		if ( ! empty($urlkey))
		{
			$paste = Paste::where('urlkey', $urlkey)->first();

			// Paste was not found
			if (is_null($paste))
			{
				Session::flash('messages.error', Lang::get('admin.paste_404'));
			}

			// Perform requested action
			switch ($action)
			{
				case 'rempass':
					$paste->password = <PASSWORD>;

					$paste->save();

					return Redirect::to(URL::previous());

				case 'toggle':
					Revision::where('urlkey', $paste->urlkey)->delete();

					$paste->private = $paste->private ? 0 : 1;

					$paste->password = <PASSWORD>;

					$paste->save();

					return Redirect::to(URL::previous());

				case 'delete':
					Revision::where('urlkey', $paste->urlkey)->delete();

					$paste->delete();

					Session::flash('messages.success', Lang::get('admin.paste_deleted'));

					return Redirect::to('admin/paste');
			}
		}

		return View::make('admin/paste', array('paste' => $paste));
	}

	/**
	 * Handles POST requests to the paste module
	 *
	 * @return \Illuminate\Support\Facades\Redirect
	 */
	public function postPaste()
	{
		if (Input::has('search'))
		{
			$key = Input::get('search');

			return Redirect::to('admin/paste/'.urlencode($key));
		}
		else
		{
			return Redirect::to('admin/paste');
		}
	}

	/**
	 * Search, create, edit or delete users
	 *
	 * @param  string  $action
	 * @param  string  $username
	 * @return \Illuminate\Support\Facades\View|\Illuminate\Support\Facades\Redirect
	 */
	public function getUser($action = '', $username = '')
	{
		$perPage = Site::config('general')->perPage;

		$user = User::where('username', $username)->where('type', 'db')->first();

		$users = User::where('type', 'db')->orderBy('username')->paginate($perPage);

		$pages = $users->links();

		// User not found
		if ( ! empty($username) AND is_null($user))
		{
			Session::flash('messages.error', Lang::get('admin.user_404'));

			return Redirect::to('admin/user');
		}

		// Perform the specified action
		switch ($action)
		{
			case 'create':
				$data = array(
					'user'     => new User,
					'founder'  => FALSE,
				);

				return View::make('admin/user', $data);

			case 'delete':
				// Cannot delete founder user or own account
				if ($user->id != 1 AND $user->id != Auth::user()->id)
				{
					$user->delete();

					Session::flash('messages.success', Lang::get('admin.user_deleted'));

					return Redirect::to('admin/user');
				}
				else
				{
					Session::flash('messages.error', Lang::get('admin.user_del_fail'));
				}
		}

		// Render the view. The founder flag here makes sure that the first
		// user cannot be blocked or removed from admin status.
		$data = array(
			'user'     => $user,
			'users'    => $users,
			'pages'    => $pages,
			'founder'  => $user->id == User::min('id'),
		);

		return View::make('admin/user', $data);
	}

	/**
	 * Handles POST actions for the user module
	 *
	 * @return \Illuminate\Support\Facades\Redirect
	 */
	public function postUser()
	{<commit_msg>User list page doesnt need immutable flag<commit_after><?php

/**
 * Sticky Notes
 *
 * An open source lightweight pastebin application
 *
 * @package     StickyNotes
 * @author      <NAME>
 * @copyright   (c) 2013 <NAME> <<EMAIL>>
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @link        http://sayakbanerjee.com/sticky-notes
 * @since       Version 1.0
 * @filesource
 */

/**
 * AdminController
 *
 * This controller handles site administration
 *
 * @package     StickyNotes
 * @subpackage  Controllers
 * @author      <NAME>
 */
class AdminController extends BaseController {

	/**
	 * Redirects to the administration dashboard
	 *
	 * @access public
	 * @return \Illuminate\Support\Facades\Redirect
	 */
	public function getIndex()
	{
		return Redirect::to('admin/dashboard');
	}

	/**
	 * Displays the administration dashboard
	 *
	 * @access public
	 * @return \Illuminate\Support\Facades\View
	 */
	public function getDashboard()
	{
		// Get the application configuration
		$app = Config::get('app');

		// Get the database configuration
		$db = Config::get('database');

		// Collect view data
		$data = array(
			'users'         => User::count(),
			'pastes'        => Paste::count(),
			'php_version'   => phpversion(),
			'sn_version'    => $app['version'],
			'db_driver'     => $db['default'],
		);

		return View::make('admin/dashboard', $data);
	}

	/**
	 * Search, edit and delete pastes
	 *
	 * @param  string  $urlkey
	 * @param  string  $action
	 * @return \Illuminate\Support\Facades\View|\Illuminate\Support\Facades\Redirect
	 */
	public function getPaste($urlkey = '', $action = '')
	{
		$paste = NULL;

		if ( ! empty($urlkey))
		{
			$paste = Paste::where('urlkey', $urlkey)->first();

			// Paste was not found
			if (is_null($paste))
			{
				Session::flash('messages.error', Lang::get('admin.paste_404'));
			}

			// Perform requested action
			switch ($action)
			{
				case 'rempass':
					$paste->password = <PASSWORD>;

					$paste->save();

					return Redirect::to(URL::previous());

				case 'toggle':
					Revision::where('urlkey', $paste->urlkey)->delete();

					$paste->private = $paste->private ? 0 : 1;

					$paste->password = <PASSWORD>;

					$paste->save();

					return Redirect::to(URL::previous());

				case 'delete':
					Revision::where('urlkey', $paste->urlkey)->delete();

					$paste->delete();

					Session::flash('messages.success', Lang::get('admin.paste_deleted'));

					return Redirect::to('admin/paste');
			}
		}

		return View::make('admin/paste', array('paste' => $paste));
	}

	/**
	 * Handles POST requests to the paste module
	 *
	 * @return \Illuminate\Support\Facades\Redirect
	 */
	public function postPaste()
	{
		if (Input::has('search'))
		{
			$key = Input::get('search');

			return Redirect::to('admin/paste/'.urlencode($key));
		}
		else
		{
			return Redirect::to('admin/paste');
		}
	}

	/**
	 * Search, create, edit or delete users
	 *
	 * @param  string  $action
	 * @param  string  $username
	 * @return \Illuminate\Support\Facades\View|\Illuminate\Support\Facades\Redirect
	 */
	public function getUser($action = '', $username = '')
	{
		$perPage = Site::config('general')->perPage;

		$user = User::where('username', $username)->where('type', 'db')->first();

		$users = User::where('type', 'db')->orderBy('username')->paginate($perPage);

		$pages = $users->links();

		// User not found
		if ( ! empty($username) AND is_null($user))
		{
			Session::flash('messages.error', Lang::get('admin.user_404'));

			return Redirect::to('admin/user');
		}

		// Perform the specified action
		switch ($action)
		{
			case 'create':
				$data = array(
					'user'     => new User,
					'founder'  => FALSE,
				);

				return View::make('admin/user', $data);

			case 'delete':
				// Cannot delete founder user or own account
				if ($user->id != 1 AND $user->id != Auth::user()->id)
				{
					$user->delete();

					Session::flash('messages.success', Lang::get('admin.user_deleted'));

					return Redirect::to('admin/user');
				}
				else
				{
					Session::flash('messages.error', Lang::get('admin.user_del_fail'));
				}
		}

		// Render the view. The founder flag here makes sure that the first
		// user cannot be blocked or removed from admin status.
		$data = array(
			'user'     => $user,
			'users'    => $users,
			'pages'    => $pages,
			'founder'  => is_null($user) ? FALSE : $user->id == User::min('id'),
		);

		return View::make('admin/user', $data);
	}

	/**
	 * Handles POST actions for the user module
	 *
	 * @return \Illuminate\Support\Facades\Redirect
	 */
	public function postUser()
	{
{'fraction_non_alphanumeric': 0.1784431137724551, 'fraction_numerical': 0.00326619488296135, 'mean_word_length': 3.1100671140939595, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4919947', 'n_tokens_mistral': 3492, 'n_tokens_neox': 2902, 'n_words': 644}