<commit_before><?php
/**
 * CommonAppController
 *
 * PHP 5
 *
 * Copyright 2013, <NAME> (http://jadb.io)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2013, <NAME> (http://jadb.io)
 * @link          http://github.com/gourmet/common
 * @since         0.1.0
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

App::uses('Controller', 'Controller');
App::uses('CakeLog', 'Log');
App::uses('DebugTimer', 'DebugKit.Lib');

/**
 * Common application's controller
 *
 * This file needs to be extended by `AppController` in order to take advantage
 * of its built-in features.
 *
 * @package       Common.Controller
 */
class CommonAppController extends Controller {

/**
 * List of pre-defined alert messages.
 *
 * @var array
 * @see `CommonAppController::alert()`.
 */
	public $alertMessages = array();

/**
 * List of breadcrumbs. Associative array where the key is the title
 * and it's associated value is the link and/or options.
 *
 * Example:
 *
 *    $this->breadCrumbs = array(
 *      'Home' => array('controller' => 'pages', 'action' => 'display', 'home'),
 *      'Users' => array(
 *        'link' => array('controller' => 'users', 'action' => 'index'),
 *        'options' => array('class' => 'parent')
 *      )
 *    );
 *
 * @var array
 */
	public $breadCrumbs = array();

/**
 * Crumb titles. By default, the friendly plugin, controller and action
 * names are used. This allows to overwrite any of them by setting their
 * original name as the key and the replacement as value.
 *
 * Example:
 *
 *   $this->crumbTitles = array('admin_edit' => 'Edit profile');
 *
 * @var array
 */
	public $crumbTitles = array();

/**
 * User-friendly name for the `Controller::$modelClass`.
 *
 * @var string
 */
	public $modelName = null;

/**
 * {@inheritdoc}
 */
	public function __construct($request = null, $response = null) {
		parent::__construct($request, $response);

		// Mark all the `CommonAppController` methods as private for `Controller::__isPrivateAction()`.
		$this->methods = array_diff($this->methods, get_class_methods('CommonAppController'));
	}

/**
 * Create generic alert message to display.
 *
 * The method can be used in two ways, using the `AppController::$alertMessages` and setting
 * up some defaults or direclty passing the message and options.
 *
 * Common defaults are set up by the `Controller.alertMessages` event and can be overridden
 * at anytime before calling this method.
 *
 *		// manually
 *  	$this->alert('foo bar', array('redirect' => true, 'level' => 'warning'));
 *
 *		// pre-defined
 *  	$this->alertMessages['my_message'] = array(
 *   		'message' => 'foo bar',
 *     	'redirect' => true, // false, '', array() '/url'
 *      'level' => 'warning', // success, error etc
 *    );
 *
 *		$this->alert('my_message');
 *
 *		// pre-defined with custom level option
 *  	$this->alert('my_message', array('level' => 'success'));
 *
 * @param string $msg The message to show to the user.
 * @param array $options Array of configuration options.
 * @return void
 * @see CommonEventListener::controllerAlertMessages()
 */
	public function alert($msg, $options = array()) {
		$defaults = array(
			'level' => 'success',
			'redirect' => false,
			'plugin' => 'Common',
			'code' => 0,
			'element' => 'alerts/default',
			'dismiss' => false,
			'key' => 'flash'
		);

		if ($msg instanceof Exception) {
			$options = array_merge(array('level' => 'error'), $options);
			$msg = $msg->getMessage();
		}

		if (!empty($this->alertMessages[$msg])) {
			if (!is_array($this->alertMessages[$msg])) {
				$msg = $this->alertMessages[$msg];
			} else if (!empty($this->alertMessages[$msg]['message'])) {
				$options = array_merge($this->alertMessages[$msg], $options);
				$msg = $options['message'];
				unset($options['message']);
			}
		}

		$insert = array('modelName' => strtolower($this->modelName));
		$msg = ucfirst(String::insert($msg, array_merge($insert, $options), array('clean' => true)));

		$options = array_merge($defaults, $options);
		$params = array('code' => $options['code'], 'plugin' => $options['plugin']);

		// View element
		$element = explode('/', $options['element']);
		$pluginDot = null;
		if (!empty($this->params['prefix'])) {
			array_push($element, $this->params['prefix'] . '_' . array_pop($element));
		}

		$elementPath = 'View' . DS . 'Elements' . DS . implode('/', $element) . '.ctp';
		if (!empty($options['plugin']) && CakePlugin::loaded($options['plugin'])) {
			$elementPath = CakePlugin::path($options['plugin']) . $elementPath;
			$pluginDot = $options['plugin'] . '.';
		}

		if (!is_file($elementPath)) {
			$element = $defaults['element'];
		} else {
			$element = implode('/', $element);
		}

		// Redirect URL
		$redirect = $options['redirect'];
		if (true === $redirect) {
			$redirect = $this->referer();<commit_msg>Fix missing alert element plugin name.<commit_after><?php
/**
 * CommonAppController
 *
 * PHP 5
 *
 * Copyright 2013, <NAME> (http://jadb.io)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2013, <NAME> (http://jadb.io)
 * @link          http://github.com/gourmet/common
 * @since         0.1.0
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

App::uses('Controller', 'Controller');
App::uses('CakeLog', 'Log');
App::uses('DebugTimer', 'DebugKit.Lib');

/**
 * Common application's controller
 *
 * This file needs to be extended by `AppController` in order to take advantage
 * of its built-in features.
 *
 * @package       Common.Controller
 */
class CommonAppController extends Controller {

/**
 * List of pre-defined alert messages.
 *
 * @var array
 * @see `CommonAppController::alert()`.
 */
	public $alertMessages = array();

/**
 * List of breadcrumbs. Associative array where the key is the title
 * and it's associated value is the link and/or options.
 *
 * Example:
 *
 *    $this->breadCrumbs = array(
 *      'Home' => array('controller' => 'pages', 'action' => 'display', 'home'),
 *      'Users' => array(
 *        'link' => array('controller' => 'users', 'action' => 'index'),
 *        'options' => array('class' => 'parent')
 *      )
 *    );
 *
 * @var array
 */
	public $breadCrumbs = array();

/**
 * Crumb titles. By default, the friendly plugin, controller and action
 * names are used. This allows to overwrite any of them by setting their
 * original name as the key and the replacement as value.
 *
 * Example:
 *
 *   $this->crumbTitles = array('admin_edit' => 'Edit profile');
 *
 * @var array
 */
	public $crumbTitles = array();

/**
 * User-friendly name for the `Controller::$modelClass`.
 *
 * @var string
 */
	public $modelName = null;

/**
 * {@inheritdoc}
 */
	public function __construct($request = null, $response = null) {
		parent::__construct($request, $response);

		// Mark all the `CommonAppController` methods as private for `Controller::__isPrivateAction()`.
		$this->methods = array_diff($this->methods, get_class_methods('CommonAppController'));
	}

/**
 * Create generic alert message to display.
 *
 * The method can be used in two ways, using the `AppController::$alertMessages` and setting
 * up some defaults or direclty passing the message and options.
 *
 * Common defaults are set up by the `Controller.alertMessages` event and can be overridden
 * at anytime before calling this method.
 *
 *		// manually
 *  	$this->alert('foo bar', array('redirect' => true, 'level' => 'warning'));
 *
 *		// pre-defined
 *  	$this->alertMessages['my_message'] = array(
 *   		'message' => 'foo bar',
 *     	'redirect' => true, // false, '', array() '/url'
 *      'level' => 'warning', // success, error etc
 *    );
 *
 *		$this->alert('my_message');
 *
 *		// pre-defined with custom level option
 *  	$this->alert('my_message', array('level' => 'success'));
 *
 * @param string $msg The message to show to the user.
 * @param array $options Array of configuration options.
 * @return void
 * @see CommonEventListener::controllerAlertMessages()
 */
	public function alert($msg, $options = array()) {
		$defaults = array(
			'level' => 'success',
			'redirect' => false,
			'plugin' => 'Common',
			'code' => 0,
			'element' => 'alerts/default',
			'dismiss' => false,
			'key' => 'flash'
		);

		if ($msg instanceof Exception) {
			$options = array_merge(array('level' => 'error'), $options);
			$msg = $msg->getMessage();
		}

		if (!empty($this->alertMessages[$msg])) {
			if (!is_array($this->alertMessages[$msg])) {
				$msg = $this->alertMessages[$msg];
			} else if (!empty($this->alertMessages[$msg]['message'])) {
				$options = array_merge($this->alertMessages[$msg], $options);
				$msg = $options['message'];
				unset($options['message']);
			}
		}

		$insert = array('modelName' => strtolower($this->modelName));
		$msg = ucfirst(String::insert($msg, array_merge($insert, $options), array('clean' => true)));

		$options = array_merge($defaults, $options);
		$params = array('code' => $options['code'], 'plugin' => $options['plugin']);

		// View element
		$element = explode('/', $options['element']);
		$pluginDot = null;
		if (!empty($this->params['prefix'])) {
			array_push($element, $this->params['prefix'] . '_' . array_pop($element));
		}

		$elementPath = 'View' . DS . 'Elements' . DS . implode('/', $element) . '.ctp';
		if (!empty($options['plugin']) && CakePlugin::loaded($options['plugin'])) {
			$elementPath = CakePlugin::path($options['plugin']) . $elementPath;
			$pluginDot = $options['plugin'] . '.';
		}

		if (!is_file($elementPath)) {
			$element = $defaults['element'];
		} else {
			$element = $pluginDot . implode('/', $element);
		}

		// Redirect URL
		$redirect = $options['redirect'];
		if (true === $redirect) {
			$redirect = $this->referer();
{'fraction_non_alphanumeric': 0.18502425222312044, 'fraction_numerical': 0.002627324171382377, 'mean_word_length': 3.712857142857143, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 99, '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': '1988567', 'n_tokens_mistral': 3226, 'n_tokens_neox': 3033, 'n_words': 817}