Skip to content

Commit

Permalink
merging in base_app
Browse files Browse the repository at this point in the history
removing plugins that can be submodules
  • Loading branch information
josegonzalez committed Apr 15, 2011
1 parent 818f43e commit d260815
Show file tree
Hide file tree
Showing 119 changed files with 3,212 additions and 12,046 deletions.
109 changes: 97 additions & 12 deletions app_controller.php
Expand Up @@ -19,16 +19,19 @@ class AppController extends Controller {
* @access public
* @link http://book.cakephp.org/view/961/components-helpers-and-uses
*/
var $components = array(
'Authsome.Authsome' => array('model' => 'User'),
'DebugKit.Toolbar' => array('panels' => array(
'Interactive.interactive', 'Sanction.permit', 'Settings.settings'
)),
public $components = array(
'Authsome.Authsome' => array(
'configureKey' => 'Auth',
'sessionKey' => 'Auth',
'cookieKey' => 'Auth',
'model' => 'User'
),
'CakeDjjob.CakeDjjob',
'Log.Logging',
'Mail',
'RequestHandler',
'Sanction.Permit' => array(
'path' => 'User.User',
'path' => 'Auth.User',
'check' => 'role'
),
'Session',
Expand All @@ -46,9 +49,91 @@ class AppController extends Controller {
* @access protected
* @link http://book.cakephp.org/view/961/components-helpers-and-uses
*/
var $helpers = array(
'Form', 'Html', 'Js', 'Resource', 'Sanction.Clearance',
'Session', 'Time', 'Wysiwyg.Tinymce', 'UploadPack.Upload'
);
}
?>
public $helpers = array(
'AssetCompress.AssetCompress',
'Sanction.Clearance',
'Wysiwyg.Tinymce',
'UploadPack.Upload',
);

/**
* Used to set a max for the pagination limit
*
* @var int
*/
public $paginationMaxLimit = 25;

/**
* Sets the view class to AutoHelper, which autoloads helpers when needed
*
* @var string
* @access public
*/
public $view = 'AutoHelper';

/**
* Object constructor - Adds the Debugkit panel if in development mode
*
* @return void
*/
public function __construct() {
if (Configure::read('debug')) {
$this->components[] = 'DebugKit.Toolbar';
}
parent::__construct();
}

/**
* Called before the controller action.
*
* Used to set a max for the pagination limit
*
* @access public
*/
public function beforeFilter() {
// Enforces an absolute limit of 25
if (isset($this->passedArgs['limit'])) {
$this->passedArgs['limit'] = min(
$this->paginationMaxLimit,
$this->passedArgs['limit']
);
}
}

/**
* Given a component name from the `$component` parameter we will load
* it up to the current controller with the provided `$configuration` --
* note that if the same component is already loaded, you could wind up
* with some shennanigans, so be careful with that.
*
* Loading a component that doesn't exist will result in a CakeError
* being thrown and the execution will be halted.
*
* We return boolean to indicate success in loading the component.
*
* @param string $component
* @param array $configuration
* @return boolean
* @access protected
*/
protected function _loadComponent($component, $configuration = array()) {
if (!isset($this->components[$component])) {
$this->components[$component] = $configuration;
$this->Component->_loadComponents($this);
return isset($this->$component);
}
return false;
}

/**
* Convenience method for logging a user out of the application completely
*
* @param mixed $redirect If false, do not redirect, else redirect to specified action
* @return void
*/
protected function _logout($redirect = array('action' => 'login')) {
$this->Authsome->logout();
$this->Session->delete('Auth');
if ($redirect) $this->redirect($redirect);
}
}
26 changes: 18 additions & 8 deletions app_helper.php
Expand Up @@ -7,15 +7,25 @@
*
* @package app
*/
class AppHelper extends Helper {
var $view = null;

function h2($contents, $alternate = null) {
App::import('Vendor', 'UrlCache.url_cache_app_helper');
class AppHelper extends UrlCacheAppHelper {
public $view = null;

public function h2($contents, $alternate = null) {
if ((empty($contents) || $contents == '' || $contents == ' ') && isset($alternate)) $contents = $alternate;
if (!$this->view) $this->view = ClassRegistry::getObject('view');

$this->view->set('title_for_layout', "{$contents} |");
$this->view->set("h2_for_layout", $contents);
$this->for_layout($contents . ' |', 'title');
$this->for_layout($contents, 'h2');
}
}
?>

public function for_layout($content, $name) {
ob_start();
if (!$this->view) {
$this->view = ClassRegistry::getObject('view');
}
echo $content;
$this->view->set($name . '_for_layout', ob_get_clean());
}

}
168 changes: 56 additions & 112 deletions app_model.php
Expand Up @@ -6,7 +6,8 @@
*
* @package app
*/
class AppModel extends Model {
App::import('Lib', 'LazyModel.LazyModel');
class AppModel extends LazyModel {
/**
* List of behaviors to load when the model object is initialized. Settings can be
* passed to behaviors by using the behavior name as index. Eg:
Expand All @@ -18,8 +19,9 @@ class AppModel extends Model {
* @link http://book.cakephp.org/view/1072/Using-Behaviors
*/
var $actsAs = array(
'Callbackable',
'CakeDjjob.CakeDjjob',
'Containable',
'Linkable.Linkable'
'Log.Logable' => array('change' => 'full')
);

Expand All @@ -41,129 +43,71 @@ class AppModel extends Model {
*/
var $query = null;

/**
* Custom find types, as per Matt Curry's method
*
* @param string $type
* @param array $options
* @return mixed array|integer|boolean
* @access public
* @author Matt Curry
* @link http://github.com/mcurry/find
*/
function find($type, $options = array()) {
$method = null;
if (is_string($type)) $method = sprintf('__find%s', Inflector::camelize($type));

if ($method && method_exists($this, $method)) {
$return = $this->{$method}($options);
if ($this->query != null) {
unset($this->query['paginate']);
$query = $this->query;
$this->query = null;
return $query;
}
return $return;
}
if (!empty($options['blacklist'])) {
$options['blacklist'] = (array) $options['blacklist'];
$options['fields'] = (isset($options['fields'])) ? $options['fields'] : array_keys($this->schema());
$options['fields'] = array_diff($options['fields'], $options['blacklist']);
unset($options['blacklist']);
}
if (!empty($options['cache'])) {
if (!class_exists('MiCache')) App::import('Vendor', 'mi_cache');
if (is_int($options['cache'])) MiCache::config(array('duration' => $options['cache']));
unset($options['cache']);
return MiCache::data($this->alias, 'find', $type, $options);
}
if (!in_array($type, array_keys($this->_findMethods))) {
diebug(array($type, $options));
$calledFrom = debug_backtrace();
CakeLog::write('error', "Unknown method {$this->alias}->{$method} in " . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . ' on line ' . $calledFrom[0]['line'] );
return false;
}
$args = func_get_args();
return call_user_func_array(array('parent', 'find'), $args);
}
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->_findMethods['paginatecount'] = true;
}

/**
* Allows the returning of query parameters for use in pagination
* Automatically set contain to false if not otherwise specified
*
* @param array $queryData Data used to execute this query, i.e. conditions, order, etc.
* @return mixed true if the operation should continue, false if it should abort; or, modified
* $queryData to continue with new $queryData
* @access public
* @author Matt Curry
* @link http://book.cakephp.org/view/1048/Callback-Methods#beforeFind-1049
*/
function beforeFind($query = array()) {
$query = (array) $query;
if (!empty($query['blacklist'])) {
$query['blacklist'] = (array) $query['blacklist'];
$query['fields'] = (isset($query['fields'])) ? $query['fields'] : array_keys($this->schema());
$query['fields'] = array_diff($query['fields'], $query['blacklist']);
unset($query['blacklist']);
}
if (!empty($query['paginate'])) {
$keys = array('fields', 'order', 'limit', 'page');
foreach ($keys as $key) {
if (empty($query[$key]) || (!empty($query[$key]) && empty($query[$key][0]) === null)) {
unset($query[$key]);
}
}
$this->query = $query;
return false;
}
$this->query = null;
return true;
}
public function beforeFind($queryData = array()) {
if (!isset($queryData['contain'])) {
$queryData['contain'] = false;
}
return $queryData;
}

/**
* Saves model data (based on white-list, if supplied) to the database. By
* default, validation occurs before save.
* Removes 'fields' key from count query on custom finds when it is an array,
* as it will completely break the Model::_findCount() call
*
* @param array $data Data to save.
* @param mixed $validate Either a boolean, or an array.
* If a boolean, indicates whether or not to validate before saving.
* If an array, allows control of validate, callbacks, and fieldList
* @param array $fieldList List of fields to allow to be written
* @param array $extra controls access to optional data a Behavior may want
* @return mixed On success Model::$data if its not empty or true, false on failure
* @access public
* @author Jose Diaz-Gonzalez
* @link http://book.cakephp.org/view/1031/Saving-Your-Data
**/
function save($data = null, $validate = true, $fieldList = array(), $extra = array()) {
$this->data = (!$data) ? $this->data : $data;
if (!$this->data) return false;

$options = array('validate' => true, 'fieldList' => array(), 'callbacks' => true);
if (is_array($validate)) {
$options = array_merge($options, $validate);
foreach($options as $key => &$value) {
if (!in_array($key, array('validate', 'fieldList', 'callbacks'))) {
$extra[$key] = $value;
}
}
} else {
$options = array_merge($options, compact('validate', 'fieldList', 'callbacks'));
}

$this->setCallbackableData($extra);

$method = null;
if (($callback = $this->getCallbackableData('callback', 'string')) != false) {
$method = sprintf('__beforeSave%s', Inflector::camelize($callback));
}

if($method && method_exists($this, $method)) {
$this->data = $this->{$method}($this->data, $extra);
}
if (!$this->data) return false;
return parent::save($this->data, $options);
}
* @param string $state Either "before" or "after"
* @param array $query
* @param array $data
* @return int The number of records found, or false
* @access protected
* @see Model::find()
*/
public function _findPaginatecount($state, $query, $results = array()) {
if ($state == 'before' && isset($query['operation'])) {
if (!empty($query['fields']) && is_array($query['fields'])) {
if (!preg_match('/^count/i', $query['fields'][0])) {
unset($query['fields']);
}
}
}
return parent::_findCount($state, $query, $results);
}

/**
* Custom Model::paginateCount() method to support custom model find pagination
*
* @param array $conditions
* @param int $recursive
* @param array $extra
* @return array
*/
public function paginateCount($conditions = array(), $recursive = 0, $extra = array()) {
$parameters = compact('conditions');

if ($recursive != $this->recursive) {
$parameters['recursive'] = $recursive;
}

if (isset($extra['type']) && isset($this->_findMethods[$extra['type']])) {
$extra['operation'] = 'count';
return $this->find($extra['type'], array_merge($parameters, $extra));
} else {
return $this->find('count', array_merge($parameters, $extra));
}
}

/**
* Convenience method to update one record without invoking any callbacks
Expand Down
12 changes: 12 additions & 0 deletions config/asset_compress.ini
@@ -0,0 +1,12 @@
[Css]
searchPaths[] = WEBROOT/css/
cacheFilePath = WEBROOT/cache_css/
cacheFiles = true
timestamp = true
filters[] = CssMin

[Javascript]
searchPaths[] = WEBROOT/js/
cacheFilePath = WEBROOT/cache_js/
cacheFiles = true
timestamp = true

0 comments on commit d260815

Please sign in to comment.