Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62c9246
commit 83c34db
Showing
23 changed files
with
1,748 additions
and
1,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,40 @@ | ||
<?php | ||
/** | ||
* ConfigsAppController | ||
* | ||
* @package Infinitas.Configs.Controller | ||
*/ | ||
|
||
/** | ||
* @page Configs-Plugin Configs Plugin | ||
* | ||
* @section configs-overview What is it | ||
* | ||
* The configs plugin provides a way to overload configuration options from the | ||
* admin backend. The configs plugin uses the normal Configure class from | ||
* CakePHP. This is done to allow normal usage within the code but have the | ||
* ability to overload options in the backend. | ||
* | ||
* @link http://api.cakephp.org/class/configure | ||
* | ||
* @section configs-usage How to use it | ||
* | ||
* You can use all the normal Configure methods within the code including | ||
* Configure::load(), Configure::read('debug') and Configure::write(). There are some | ||
* Event callbacks that are triggered early on in the request so if you would | ||
* like the data to be cached it should be loaded in these calls. | ||
* | ||
* Configs plugin provides a number of things to manage configs, including | ||
* adding new ones from the backend, overloading options and seeing what has | ||
* changed from the defaults. | ||
* | ||
* @image html sql_configs_plugin.png "Configs Plugin table structure" | ||
* | ||
* @section configs-see-also Also see | ||
* @ref AppEvents | ||
* @ref EventCore | ||
*/ | ||
App::uses('AppController', 'Controller'); | ||
|
||
/** | ||
* ConfigsAppController is the main controller class that all other | ||
* configuration related controllers extend. | ||
* | ||
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) | ||
* @link http://www.infinitas-cms.org | ||
* @package Infinitas.Configs | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @since 0.5a | ||
* | ||
* @author Carl Sutton <dogmatic69@infinitas-cms.org> | ||
*/ | ||
App::uses('AppController', 'Controller'); | ||
class ConfigsAppController extends AppController { | ||
} | ||
/** | ||
* ConfigsAppController | ||
* | ||
* The configs plugin provides a way to overload configuration options from the | ||
* admin backend. The configs plugin uses the normal Configure class from | ||
* CakePHP. This is done to allow normal usage within the code but have the | ||
* ability to overload options in the backend. | ||
* | ||
* You can use all the normal Configure methods within the code including | ||
* Configure::load(), Configure::read('debug') and Configure::write(). There are some | ||
* Event callbacks that are triggered early on in the request so if you would | ||
* like the data to be cached it should be loaded in these calls. | ||
* | ||
* Configs plugin provides a number of things to manage configs, including | ||
* adding new ones from the backend, overloading options and seeing what has | ||
* changed from the defaults. | ||
* | ||
* @image html sql_configs_plugin.png "Configs Plugin table structure" | ||
* | ||
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) | ||
* @link http://www.infinitas-cms.org | ||
* @package Infinitas.Configs.Controller | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @since 0.5a | ||
* | ||
* @author Carl Sutton <dogmatic69@infinitas-cms.org> | ||
*/ | ||
|
||
class ConfigsAppController extends AppController { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,131 @@ | ||
<?php | ||
/** | ||
* The ConfigsController is for managing the site configs from the backend | ||
* | ||
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 ) | ||
* @link http://infinitas-cms.org | ||
* @package Infinitas.Configs.controllers | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @since 0.5a | ||
* | ||
* @author Carl Sutton <dogmatic69@infinitas-cms.org> | ||
*/ | ||
|
||
class ConfigsController extends ConfigsAppController { | ||
/** | ||
* dont see where this is used | ||
* | ||
* @deprecated | ||
*/ | ||
public $configOptions = array(); | ||
|
||
public function admin_index() { | ||
$configs = $this->Paginator->paginate(null, $this->Filter->filter); | ||
|
||
$filterOptions = $this->Filter->filterOptions; | ||
$filterOptions['fields'] = array( | ||
'key', | ||
'value', | ||
'type' => $this->Config->_configTypes | ||
); | ||
|
||
$this->set(compact('configs', 'filterOptions')); | ||
} | ||
|
||
public function admin_available() { | ||
$this->set('configs', $this->Config->availableConfigs()); | ||
$this->set('overloaded', $this->Config->find('list', array('fields' => array('Config.key', 'Config.value')))); | ||
} | ||
/** | ||
* ConfigsController | ||
* | ||
* @package Infinitas.Configs.Controller | ||
*/ | ||
|
||
/** | ||
* ConfigsController | ||
* | ||
* The ConfigsController is for managing the site configs from the backend | ||
* | ||
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 ) | ||
* @link http://www.infinitas-cms.org | ||
* @package Infinitas.Configs.Controller | ||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | ||
* @since 0.5a | ||
* | ||
* @author Carl Sutton <dogmatic69@infinitas-cms.org> | ||
*/ | ||
|
||
class ConfigsController extends ConfigsAppController { | ||
/** | ||
* List configs in the database | ||
* | ||
* These are the overloaded and additional configs from the defaults found in | ||
* `PluginName/Config/config.php` | ||
* | ||
* @return void | ||
*/ | ||
public function admin_index() { | ||
$configs = $this->Paginator->paginate(null, $this->Filter->filter); | ||
|
||
$filterOptions = $this->Filter->filterOptions; | ||
$filterOptions['fields'] = array( | ||
'key', | ||
'value', | ||
'type' => $this->Config->_configTypes | ||
); | ||
|
||
$this->set(compact('configs', 'filterOptions')); | ||
} | ||
|
||
/** | ||
* List available configs | ||
* | ||
* @return void | ||
*/ | ||
public function admin_available() { | ||
$this->set('configs', $this->Config->availableConfigs()); | ||
$this->set('overloaded', $this->Config->find('list', array('fields' => array('Config.key', 'Config.value')))); | ||
} | ||
|
||
/** | ||
* Add a new config option | ||
* | ||
* @return void | ||
*/ | ||
public function admin_add() { | ||
parent::admin_add(); | ||
|
||
if(isset($this->request->params['named']['Config.key'])) { | ||
$this->request->data['Config']['key'] = $this->request->params['named']['Config.key']; | ||
$value = Configure::read($this->request->params['named']['Config.key']); | ||
switch(true) { | ||
case is_int($value): | ||
$this->request->data['Config']['type'] = 'integer'; | ||
break; | ||
|
||
case is_bool($value): | ||
$this->request->data['Config']['type'] = 'bool'; | ||
break; | ||
|
||
default: | ||
$array = explode(',', $value); | ||
if(count($array) > 1) { | ||
$this->request->data['Config']['type'] = 'array'; | ||
$this->request->data['Config']['value'] = $array[0]; | ||
$this->request->data['Config']['options'] = $value; | ||
} | ||
else{ | ||
$this->request->data['Config']['type'] = 'string'; | ||
} | ||
} | ||
|
||
public function admin_add() { | ||
parent::admin_add(); | ||
|
||
if(isset($this->request->params['named']['Config.key'])) { | ||
$this->request->data['Config']['key'] = $this->request->params['named']['Config.key']; | ||
$value = Configure::read($this->request->params['named']['Config.key']); | ||
switch(true) { | ||
case is_int($value): | ||
$this->request->data['Config']['type'] = 'integer'; | ||
break; | ||
|
||
case is_bool($value): | ||
$this->request->data['Config']['type'] = 'bool'; | ||
break; | ||
|
||
default: | ||
$array = explode(',', $value); | ||
if(count($array) > 1) { | ||
$this->request->data['Config']['type'] = 'array'; | ||
$this->request->data['Config']['value'] = $array[0]; | ||
$this->request->data['Config']['options'] = $value; | ||
} | ||
else{ | ||
$this->request->data['Config']['type'] = 'string'; | ||
} | ||
} | ||
|
||
if(!isset($this->request->data['Config']['value'])) { | ||
$this->request->data['Config']['value'] = $value; | ||
} | ||
if(!isset($this->request->data['Config']['value'])) { | ||
$this->request->data['Config']['value'] = $value; | ||
} | ||
} | ||
|
||
$this->set('types', $this->Config->_configTypes); | ||
$this->set('types', $this->Config->_configTypes); | ||
} | ||
|
||
/** | ||
* Edit config option | ||
* | ||
* @param string $id the config id | ||
* | ||
* @return void | ||
*/ | ||
public function admin_edit($id = null) { | ||
if (!$id) { | ||
$this->notice('invalid'); | ||
} | ||
|
||
public function admin_edit($id = null) { | ||
if (!$id) { | ||
$this->notice('invalid'); | ||
if (!empty($this->request->data)) { | ||
switch($this->request->data['Config']['type']) { | ||
case 'bool': | ||
switch($this->request->data['Config']['value']) { | ||
case 1: | ||
$this->request->data['Config']['value'] = 'true'; | ||
break; | ||
|
||
default: | ||
$this->request->data['Config']['value'] = 'false'; | ||
} | ||
break; | ||
} | ||
|
||
if (!empty($this->request->data)) { | ||
switch($this->request->data['Config']['type']) { | ||
case 'bool': | ||
switch($this->request->data['Config']['value']) { | ||
case 1: | ||
$this->request->data['Config']['value'] = 'true'; | ||
break; | ||
|
||
default: | ||
$this->request->data['Config']['value'] = 'false'; | ||
} // switch | ||
break; | ||
} // switch | ||
if ($this->Config->save($this->request->data)) { | ||
$this->notice('saved'); | ||
} | ||
|
||
$this->notice('not_saved'); | ||
if ($this->Config->save($this->request->data)) { | ||
$this->notice('saved'); | ||
} | ||
|
||
if ($id && empty($this->request->data)) { | ||
$this->request->data = $this->Config->read(null, $id); | ||
} | ||
$this->notice('not_saved'); | ||
} | ||
} | ||
|
||
if ($id && empty($this->request->data)) { | ||
$this->request->data = $this->Config->read(null, $id); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.