From d260815d9ec119483d500fee626f26336e59d7ae Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 15 Apr 2011 01:11:55 -0400 Subject: [PATCH] merging in base_app removing plugins that can be submodules --- app_controller.php | 109 +- app_helper.php | 26 +- app_model.php | 168 +- config/asset_compress.ini | 12 + config/bootstrap.php | 66 +- config/control | 10 + .../migrations/001_users_and_login_tokens.php | 82 + config/migrations/002_add_is_admin_field.php | 55 + config/migrations/map.php | 8 + config/permit.php | 18 +- config/routes.php | 13 +- config/schema/schema.php | 39 + controllers/account_controller.php | 40 + controllers/users_controller.php | 59 + models/behaviors/callbackable.php | 141 -- models/login_token.php | 12 + models/user.php | 324 +++ plugins/authsome/README.md | 334 ---- .../controllers/components/authsome.php | 236 --- plugins/debug_kit/README.mdown | 22 - plugins/debug_kit/build.py | 130 -- .../controllers/components/toolbar.php | 650 ------ .../controllers/toolbar_access_controller.php | 103 - .../debug_kit/debug_kit_app_controller.php | 23 - plugins/debug_kit/debug_kit_app_model.php | 23 - plugins/debug_kit/locale/debug_kit.pot | 138 -- .../locale/eng/LC_MESSAGES/debug_kit.po | 135 -- .../locale/spa/LC_MESSAGES/debug_kit.po | 135 -- plugins/debug_kit/models/behaviors/timed.php | 106 - plugins/debug_kit/models/toolbar_access.php | 56 - .../tests/cases/behaviors/timed.test.php | 77 - .../controllers/components/toolbar.test.php | 552 ------ .../cases/models/toolbar_access.test.php | 66 - .../debug_kit/tests/cases/test_objects.php | 53 - .../cases/vendors/debug_kit_debugger.test.php | 233 --- .../tests/cases/vendors/fire_cake.test.php | 341 ---- .../tests/cases/views/debug.test.php | 157 -- .../views/helpers/fire_php_toolbar.test.php | 147 -- .../cases/views/helpers/html_toolbar.test.php | 352 ---- .../cases/views/helpers/toolbar.test.php | 170 -- .../tests/groups/view_group.group.php | 45 - .../controllers/debug_kit_test_controller.php | 36 - .../tests/test_app/vendors/test_panel.php | 25 - .../debug_kit_test/request_action_render.ctp | 1 - .../debug_kit/vendors/debug_kit_debugger.php | 401 ---- plugins/debug_kit/vendors/fire_cake.php | 547 ------ .../debug_kit/vendors/shells/benchmark.php | 168 -- .../debug_kit/vendors/shells/whitespace.php | 70 - plugins/debug_kit/views/debug.php | 80 - .../views/elements/debug_toolbar.ctp | 56 - .../views/elements/history_panel.ctp | 195 -- .../debug_kit/views/elements/log_panel.ctp | 40 - .../views/elements/request_panel.ctp | 36 - .../views/elements/session_panel.ctp | 22 - .../views/elements/sql_log_panel.ctp | 90 - .../debug_kit/views/elements/timer_panel.ctp | 108 - .../views/elements/variables_panel.ctp | 25 - .../views/helpers/fire_php_toolbar.php | 97 - .../debug_kit/views/helpers/html_toolbar.php | 184 -- .../debug_kit/views/helpers/simple_graph.php | 85 - plugins/debug_kit/views/helpers/toolbar.php | 178 -- .../views/toolbar_access/history_state.ctp | 29 - .../views/toolbar_access/sql_explain.ctp | 9 - .../debug_kit/webroot/css/debug_toolbar.css | 312 --- plugins/debug_kit/webroot/img/cake.icon.png | Bin 943 -> 0 bytes .../debug_kit/webroot/js/js_debug_toolbar.js | 700 ------- plugins/interactive/README | 58 - .../controllers/interactive_controller.php | 29 - .../interactive_app_controller.php | 5 - plugins/interactive/interactive_app_model.php | 5 - plugins/interactive/models/interactive.php | 142 -- .../tests/cases/models/interactive.test.php | 143 -- .../interactive/vendors/interactive_panel.php | 7 - .../vendors/shells/interactive.php | 111 -- .../views/elements/interactive_panel.ctp | 78 - plugins/interactive/views/interactive/cmd.ctp | 24 - .../interactive/webroot/img/ajax-loader.gif | Bin 673 -> 0 bytes plugins/sanction/README.textile | 152 -- plugins/sanction/config/permit.php | 12 - .../controllers/components/access.php | 58 - .../controllers/components/permit.php | 197 -- plugins/sanction/license | 22 - .../sanction/models/behaviors/endorsed.php | 63 - plugins/sanction/tests/cases/permit.test.php | 304 --- plugins/sanction/vendors/permit_panel.php | 16 - .../sanction/views/elements/permit_panel.ctp | 8 - plugins/sanction/views/helpers/clearance.php | 193 -- .../config/migrations/initial_migration.php | 85 - plugins/searchable/config/migrations/map.php | 6 - plugins/searchable/config/routes.php | 7 - .../searchable/config/sql/search_index.sql | 17 - .../controllers/search_indexes_controller.php | 67 - .../models/behaviors/searchable.php | 410 ---- plugins/searchable/models/search_index.php | 30 - .../searchable/searchable_app_controller.php | 4 - plugins/searchable/searchable_app_model.php | 4 - .../vendors/shells/build_search_index.php | 247 --- plugins/searchable/views/elements/form.ctp | 4 - .../searchable/views/helpers/searchable.php | 15 - .../searchable/views/search_indexes/index.ctp | 32 - .../controllers/components/webservice.php | 38 - plugins/webservice/views/webservice.php | 430 ---- plugins/wysiwyg/README.textile | 53 - plugins/wysiwyg/views/helpers/fck.php | 143 -- plugins/wysiwyg/views/helpers/jwysiwyg.php | 139 -- plugins/wysiwyg/views/helpers/markitup.php | 180 -- plugins/wysiwyg/views/helpers/nicedit.php | 133 -- plugins/wysiwyg/views/helpers/tinymce.php | 170 -- plugins/wysiwyg/views/helpers/wysiwyg.php | 118 -- vendors/CssMin/CssMin.php | 1746 +++++++++++++++++ vendors/JsMin/JsMin.php | 325 +++ views/account/delete.ctp | 8 + views/account/password.ctp | 13 + views/account/settings.ctp | 18 + views/auto_helper.php | 164 ++ views/users/admin_index.ctp | 36 + views/users/index.ctp | 0 views/users/login.ctp | 16 + views/users/register.ctp | 13 + 119 files changed, 3212 insertions(+), 12046 deletions(-) create mode 100644 config/asset_compress.ini create mode 100644 config/control create mode 100644 config/migrations/001_users_and_login_tokens.php create mode 100644 config/migrations/002_add_is_admin_field.php create mode 100644 config/migrations/map.php create mode 100644 config/schema/schema.php create mode 100644 controllers/account_controller.php create mode 100644 controllers/users_controller.php delete mode 100644 models/behaviors/callbackable.php create mode 100644 models/login_token.php create mode 100644 models/user.php delete mode 100755 plugins/authsome/README.md delete mode 100755 plugins/authsome/controllers/components/authsome.php delete mode 100755 plugins/debug_kit/README.mdown delete mode 100755 plugins/debug_kit/build.py delete mode 100755 plugins/debug_kit/controllers/components/toolbar.php delete mode 100755 plugins/debug_kit/controllers/toolbar_access_controller.php delete mode 100755 plugins/debug_kit/debug_kit_app_controller.php delete mode 100755 plugins/debug_kit/debug_kit_app_model.php delete mode 100755 plugins/debug_kit/locale/debug_kit.pot delete mode 100755 plugins/debug_kit/locale/eng/LC_MESSAGES/debug_kit.po delete mode 100755 plugins/debug_kit/locale/spa/LC_MESSAGES/debug_kit.po delete mode 100755 plugins/debug_kit/models/behaviors/timed.php delete mode 100755 plugins/debug_kit/models/toolbar_access.php delete mode 100755 plugins/debug_kit/tests/cases/behaviors/timed.test.php delete mode 100755 plugins/debug_kit/tests/cases/controllers/components/toolbar.test.php delete mode 100755 plugins/debug_kit/tests/cases/models/toolbar_access.test.php delete mode 100755 plugins/debug_kit/tests/cases/test_objects.php delete mode 100755 plugins/debug_kit/tests/cases/vendors/debug_kit_debugger.test.php delete mode 100755 plugins/debug_kit/tests/cases/vendors/fire_cake.test.php delete mode 100755 plugins/debug_kit/tests/cases/views/debug.test.php delete mode 100755 plugins/debug_kit/tests/cases/views/helpers/fire_php_toolbar.test.php delete mode 100755 plugins/debug_kit/tests/cases/views/helpers/html_toolbar.test.php delete mode 100755 plugins/debug_kit/tests/cases/views/helpers/toolbar.test.php delete mode 100755 plugins/debug_kit/tests/groups/view_group.group.php delete mode 100755 plugins/debug_kit/tests/test_app/controllers/debug_kit_test_controller.php delete mode 100755 plugins/debug_kit/tests/test_app/vendors/test_panel.php delete mode 100755 plugins/debug_kit/tests/test_app/views/debug_kit_test/request_action_render.ctp delete mode 100755 plugins/debug_kit/vendors/debug_kit_debugger.php delete mode 100755 plugins/debug_kit/vendors/fire_cake.php delete mode 100755 plugins/debug_kit/vendors/shells/benchmark.php delete mode 100755 plugins/debug_kit/vendors/shells/whitespace.php delete mode 100755 plugins/debug_kit/views/debug.php delete mode 100755 plugins/debug_kit/views/elements/debug_toolbar.ctp delete mode 100755 plugins/debug_kit/views/elements/history_panel.ctp delete mode 100755 plugins/debug_kit/views/elements/log_panel.ctp delete mode 100755 plugins/debug_kit/views/elements/request_panel.ctp delete mode 100755 plugins/debug_kit/views/elements/session_panel.ctp delete mode 100755 plugins/debug_kit/views/elements/sql_log_panel.ctp delete mode 100755 plugins/debug_kit/views/elements/timer_panel.ctp delete mode 100755 plugins/debug_kit/views/elements/variables_panel.ctp delete mode 100755 plugins/debug_kit/views/helpers/fire_php_toolbar.php delete mode 100755 plugins/debug_kit/views/helpers/html_toolbar.php delete mode 100755 plugins/debug_kit/views/helpers/simple_graph.php delete mode 100755 plugins/debug_kit/views/helpers/toolbar.php delete mode 100755 plugins/debug_kit/views/toolbar_access/history_state.ctp delete mode 100755 plugins/debug_kit/views/toolbar_access/sql_explain.ctp delete mode 100755 plugins/debug_kit/webroot/css/debug_toolbar.css delete mode 100755 plugins/debug_kit/webroot/img/cake.icon.png delete mode 100755 plugins/debug_kit/webroot/js/js_debug_toolbar.js delete mode 100644 plugins/interactive/README delete mode 100644 plugins/interactive/controllers/interactive_controller.php delete mode 100644 plugins/interactive/interactive_app_controller.php delete mode 100644 plugins/interactive/interactive_app_model.php delete mode 100644 plugins/interactive/models/interactive.php delete mode 100644 plugins/interactive/tests/cases/models/interactive.test.php delete mode 100644 plugins/interactive/vendors/interactive_panel.php delete mode 100644 plugins/interactive/vendors/shells/interactive.php delete mode 100644 plugins/interactive/views/elements/interactive_panel.ctp delete mode 100644 plugins/interactive/views/interactive/cmd.ctp delete mode 100644 plugins/interactive/webroot/img/ajax-loader.gif delete mode 100644 plugins/sanction/README.textile delete mode 100644 plugins/sanction/config/permit.php delete mode 100644 plugins/sanction/controllers/components/access.php delete mode 100644 plugins/sanction/controllers/components/permit.php delete mode 100644 plugins/sanction/license delete mode 100644 plugins/sanction/models/behaviors/endorsed.php delete mode 100644 plugins/sanction/tests/cases/permit.test.php delete mode 100644 plugins/sanction/vendors/permit_panel.php delete mode 100644 plugins/sanction/views/elements/permit_panel.ctp delete mode 100644 plugins/sanction/views/helpers/clearance.php delete mode 100644 plugins/searchable/config/migrations/initial_migration.php delete mode 100644 plugins/searchable/config/migrations/map.php delete mode 100755 plugins/searchable/config/routes.php delete mode 100755 plugins/searchable/config/sql/search_index.sql delete mode 100755 plugins/searchable/controllers/search_indexes_controller.php delete mode 100755 plugins/searchable/models/behaviors/searchable.php delete mode 100755 plugins/searchable/models/search_index.php delete mode 100755 plugins/searchable/searchable_app_controller.php delete mode 100755 plugins/searchable/searchable_app_model.php delete mode 100755 plugins/searchable/vendors/shells/build_search_index.php delete mode 100755 plugins/searchable/views/elements/form.ctp delete mode 100755 plugins/searchable/views/helpers/searchable.php delete mode 100755 plugins/searchable/views/search_indexes/index.ctp delete mode 100644 plugins/webservice/controllers/components/webservice.php delete mode 100644 plugins/webservice/views/webservice.php delete mode 100644 plugins/wysiwyg/README.textile delete mode 100644 plugins/wysiwyg/views/helpers/fck.php delete mode 100644 plugins/wysiwyg/views/helpers/jwysiwyg.php delete mode 100644 plugins/wysiwyg/views/helpers/markitup.php delete mode 100644 plugins/wysiwyg/views/helpers/nicedit.php delete mode 100644 plugins/wysiwyg/views/helpers/tinymce.php delete mode 100644 plugins/wysiwyg/views/helpers/wysiwyg.php create mode 100644 vendors/CssMin/CssMin.php create mode 100644 vendors/JsMin/JsMin.php create mode 100644 views/account/delete.ctp create mode 100644 views/account/password.ctp create mode 100644 views/account/settings.ctp create mode 100644 views/auto_helper.php create mode 100644 views/users/admin_index.ctp create mode 100644 views/users/index.ctp create mode 100644 views/users/login.ctp create mode 100644 views/users/register.ctp diff --git a/app_controller.php b/app_controller.php index 72bf778..18280b4 100644 --- a/app_controller.php +++ b/app_controller.php @@ -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', @@ -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' - ); -} -?> \ No newline at end of file + 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); + } +} \ No newline at end of file diff --git a/app_helper.php b/app_helper.php index b810098..64598f9 100644 --- a/app_helper.php +++ b/app_helper.php @@ -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'); } -} -?> \ No newline at end of file + + 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()); + } + +} \ No newline at end of file diff --git a/app_model.php b/app_model.php index 701ff38..ae79ad3 100644 --- a/app_model.php +++ b/app_model.php @@ -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: @@ -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') ); @@ -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 diff --git a/config/asset_compress.ini b/config/asset_compress.ini new file mode 100644 index 0000000..651178a --- /dev/null +++ b/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 \ No newline at end of file diff --git a/config/bootstrap.php b/config/bootstrap.php index 50bf3ff..a0ddb02 100644 --- a/config/bootstrap.php +++ b/config/bootstrap.php @@ -50,25 +50,49 @@ */ if (!defined('STDIN') && !class_exists('Assert')) App::import('Vendor', 'assert'); -function diebug($variable = false, $showHtml = true, $showFrom = true, $die = true) { - if (Configure::read() > 0) { - if (is_array($showHtml)) { - $showHtml = array_merge(array('showHtml' => true, 'showFrom' => true, 'die' => true), $showHtml); - extract($showHtml); - } - if ($showFrom) { - $calledFrom = debug_backtrace(); - echo '' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . ''; - echo ' (line ' . $calledFrom[0]['line'] . ')

'; - } - if ($showHtml) { - if (!class_exists('dBug')) App::import('Vendor', 'dBug', array('file' => 'dBug.php')); - new dBug($variable); - echo '
'; - } else { - debug($variable, $showHtml, $showFrom); - } - if ($die) die; - } + +function diebug($var = false, $showHtml = true, $showFrom = true, $die = true) { + if (Configure::read() > 0) { + $file = ''; + $line = ''; + if ($showFrom) { + $calledFrom = debug_backtrace(); + $file = substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1); + $line = $calledFrom[0]['line']; + } + $html = <<%s (line %s) +
+%s
+
+HTML; + $text = <<'), array('<', '>'), $var); + } + printf($template, $file, $line, $var); + if ($die) die; + } } -?> \ No newline at end of file + +Configure::write('UrlCache.pageFiles', true); +Configure::write('Settings.SiteTitle', 'CakePHP Website'); +Configure::write('Settings.SmtpUsername', 'username'); +Configure::write('Settings.SmtpPassword', 'password'); +Configure::write('Settings.ServerEmail', 'mail@example.com'); +Configure::write('Settings.FULL_BASE_URL', 'mail@example.com'); \ No newline at end of file diff --git a/config/control b/config/control new file mode 100644 index 0000000..66dca69 --- /dev/null +++ b/config/control @@ -0,0 +1,10 @@ +Package: app_skellington +Source: git://github.com/josegonzalez/app_skellington.git +Type: skeleton +Section: skeleton +Description: builds a barebones cakephp app skeleton based on the db config +Pre-depends: CakePHP==1.3 +Recommends: +Suggests: +Bugs: http://github.com/josegonzalez/cakepackages/issues +Callbacks: git-submodules \ No newline at end of file diff --git a/config/migrations/001_users_and_login_tokens.php b/config/migrations/001_users_and_login_tokens.php new file mode 100644 index 0000000..4fd74d9 --- /dev/null +++ b/config/migrations/001_users_and_login_tokens.php @@ -0,0 +1,82 @@ + array( + 'create_table' => array( + 'login_tokens' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => NULL), + 'token' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 32, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'duration' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 32, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'used' => array('type' => 'boolean', 'null' => false, 'default' => '0'), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'expires' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), + ), + 'users' => array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'first_name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'email_address' => array('type' => 'string', 'null' => false, 'default' => NULL, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'password' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'last_name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 40, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'location' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'status' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 4), + 'indexes' => array( + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'credentials' => array('column' => array('email_address', 'password'), 'unique' => 0), + 'email' => array('column' => 'email_address', 'unique' => 0), + ), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), + ), + ), + ), + 'down' => array( + 'drop_table' => array( + 'login_tokens', 'users' + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction, up or down direction of migration process + * @return boolean Should process continue + * @access public + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction, up or down direction of migration process + * @return boolean Should process continue + * @access public + */ + public function after($direction) { + return true; + } +} +?> \ No newline at end of file diff --git a/config/migrations/002_add_is_admin_field.php b/config/migrations/002_add_is_admin_field.php new file mode 100644 index 0000000..810e3fc --- /dev/null +++ b/config/migrations/002_add_is_admin_field.php @@ -0,0 +1,55 @@ + array( + 'create_field' => array( + 'users' => array( + 'is_admin' => array('type' => 'boolean', 'null' => false, 'default' => '0'), + ), + ), + ), + 'down' => array( + 'drop_field' => array( + 'users' => array('is_admin',), + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction, up or down direction of migration process + * @return boolean Should process continue + * @access public + */ + public function before($direction) { + return true; + } + +/** + * After migration callback + * + * @param string $direction, up or down direction of migration process + * @return boolean Should process continue + * @access public + */ + public function after($direction) { + return true; + } +} +?> \ No newline at end of file diff --git a/config/migrations/map.php b/config/migrations/map.php new file mode 100644 index 0000000..806f647 --- /dev/null +++ b/config/migrations/map.php @@ -0,0 +1,8 @@ + array( + '001_users_and_login_tokens' => 'M4d9feadf0ac84c55afbe45988fa129d9'), + 2 => array( + '002_add_is_admin_field' => 'M4da0bff6de6c435b9b30145b8fa129d9'), +); +?> \ No newline at end of file diff --git a/config/permit.php b/config/permit.php index 5588440..5087720 100644 --- a/config/permit.php +++ b/config/permit.php @@ -7,14 +7,24 @@ array('auth' => array('group' => 'admin')), array('redirect' => array('plugin' => null, 'controller' => 'users', 'action' => 'login'), 'element' => 'flash/error')); +Permit::access( + array('controller' => 'users', 'action' => array('login', 'register', 'forgot_password', 'reset_password')), + array('auth' => false), + array('redirect' => array('controller' => 'users', 'action' => 'index'))); + Permit::access( array('controller' => 'users', 'action' => array('change_password', 'dashboard', 'profile', 'logout')), array('auth' => true), - array('redirect' => array('plugin' => null, 'controller' => 'users', 'action' => 'login'), 'element' => 'flash/error')); + array('redirect' => array('controller' => 'users', 'action' => 'login'))); Permit::access( - array('controller' => 'users', 'action' => array('forgot_password', 'login', 'reset_password')), - array('auth' => false), - array('redirect' => array('plugin' => 'log', 'controller' => 'logs', 'action' => 'index'), 'element' => 'flash/error')); + array('controller' => 'account'), + array('auth' => true), + array('redirect' => array('controller' => 'users', 'action' => 'login'))); + +Permit::access( + array('admin' => true), + array('auth' => array('is_admin' => true)), + array('redirect' => array('controller' => 'users', 'action' => 'index', 'admin' => false))); ?> \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 90ac26c..8fadc73 100644 --- a/config/routes.php +++ b/config/routes.php @@ -23,16 +23,7 @@ */ Router::parseExtensions('json', 'rss', 'xml'); - -/** - * Here, we are connecting '/' (base path) to controller called 'Pages', - * its action called 'display', and we pass a param to select the view file - * to use (in this case, /app/views/pages/home.ctp)... - */ Router::connect('/', array('plugin' => 'log', 'controller' => 'logs', 'action' => 'index')); - -/** - * ...and connect the rest of 'Pages' controller's urls. - */ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); -?> \ No newline at end of file + Router::connect('/cache_css/*', array('plugin' => 'asset_compress', 'controller' => 'css_files', 'action' => 'get')); + Router::connect('/cache_js/*', array('plugin' => 'asset_compress', 'controller' => 'js_files', 'action' => 'get')); diff --git a/config/schema/schema.php b/config/schema/schema.php new file mode 100644 index 0000000..80b9392 --- /dev/null +++ b/config/schema/schema.php @@ -0,0 +1,39 @@ + array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'user_id' => array('type' => 'integer', 'null' => false, 'default' => NULL), + 'token' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 32, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'duration' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 32, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'used' => array('type' => 'boolean', 'null' => false, 'default' => '0'), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'expires' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); + var $users = array( + 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), + 'first_name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'email_address' => array('type' => 'string', 'null' => false, 'default' => NULL, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'password' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 40, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'last_name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 40, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'location' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL), + 'status' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 4), + 'is_admin' => array('type' => 'boolean', 'null' => false, 'default' => '0'), + 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1), 'credentials' => array('column' => array('email_address', 'password'), 'unique' => 0), 'email' => array('column' => 'email_address', 'unique' => 0)), + 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') + ); +} +?> \ No newline at end of file diff --git a/controllers/account_controller.php b/controllers/account_controller.php new file mode 100644 index 0000000..0f15a30 --- /dev/null +++ b/controllers/account_controller.php @@ -0,0 +1,40 @@ +data)) { + if ($this->User->updateAccount($this->data)) { + $this->Session->setFlash(__('Your account has been updated', true)); + $this->redirect(array('action' => 'account')); + } else { + $this->Session->setFlash(__('You account could not be updated. Please fix any errors and try again', true)); + } + } else { + $this->data = $this->User->find('account'); + } + } + + public function password() { + if (!empty($this->data)) { + if ($this->User->updatePassword($this->data)) { + $this->Session->setFlash(__('Your password has been updated', true)); + $this->redirect(array('action' => 'password')); + } else { + $this->Session->setFlash(__('You password could not be updated. Please fix any errors and try again', true)); + } + } + } + + public function delete() { + if (!empty($this->data['User']['delete'])) { + if ($this->User->deleteAccount()) { + $this->Session->setFlash(__('Your account has been deleted', true)); + $this->_logout('/'); + } else { + $this->Session->setFlash(__('Your account could not be deleted', true)); + } + } + } +} \ No newline at end of file diff --git a/controllers/users_controller.php b/controllers/users_controller.php new file mode 100644 index 0000000..25bb88c --- /dev/null +++ b/controllers/users_controller.php @@ -0,0 +1,59 @@ +data)) { + return; + } + + $user = $this->Authsome->login('credentials', $this->data['User']); + if (!$user) { + $this->Session->setFlash(__('Unknown user or incorrect Password', true)); + return; + } + + if (!empty($this->data['User']['remember'])) $this->Authsome->persist(); + + $this->Session->setFlash(__('You have been logged in', true)); + $this->redirect(array('action' => 'index')); + } + + public function logout() { + $this->_logout(); + } + + public function register() { + if (!empty($this->data)) { + if ($this->User->register($this->data)) { + $this->Session->setFlash(__('You\'ve been successfully registered!', true)); + $this->redirect(array('action' => 'index')); + } else { + $this->Session->setFlash(__('You could not be registered. Please fix any errors and try again', true)); + } + + if (isset($this->data['User']['password'])) { + unset($this->data['User']['password']); + } + } + } + + public function index() { + + } + + public function admin_index() { + $this->paginate = array('forapproval'); + $this->set('users', $this->paginate()); + } + + public function admin_approve($id = null) { + $message = sprintf(__('Unable to approve user #id %s', true), $id); + if ($this->User->approveAccount($id)) { + $message = sprintf(__('Approved user #id %s', true), $id); + } + + $this->Session->setFlash($message); + $this->redirect(array('action' => 'index', 'admin' => true)); + } + +} \ No newline at end of file diff --git a/models/behaviors/callbackable.php b/models/behaviors/callbackable.php deleted file mode 100644 index 7ddaab2..0000000 --- a/models/behaviors/callbackable.php +++ /dev/null @@ -1,141 +0,0 @@ -__data = $data; - return $this->__data; - } - -/** - * Convenience function to get extra data for use within callbacks - * - * Can also optionally check for the type of the returned data and return null - * if the type does not match - * - * @param string $key Optional Key potentially pointing to some data - * @param string $type Optional Enforces a type constraint on returned data - * @return mixed contents of the key if isset, null otherwise. - * @author Jose Diaz-Gonzalez - * @access public - **/ - function getCallbackableData(&$model, $key = null, $type = null) { - if (!$key) return $this->__data; - - if (empty($this->__data[$key])) { - if (!$type) return $this->__data[$key]; - - if (gettype($this->__data[$key]) === $type) return $this->__data[$key]; - } - return null; - } - -/** - * Before validate callback - * - * @param object $model Model using this behavior - * @return boolean True if validate operation should continue, false to abort - * @access public - */ - function beforeValidate(&$model) { - $method = null; - if (($callback = $this->getCallbackableData($model, 'callback', 'string')) != false) { - $method = sprintf('__beforeValidate%s', Inflector::camelize($callback)); - } - - if($method && method_exists($model, $method)) { - return $model->{$method}($model); - } - return true; - } - -/** - * After save callback - * - * @param object $model Model using this behavior - * @param boolean $created True if this save created a new record - * @access public - * @return boolean True if the operation succeeded, false otherwise - */ - function afterSave(&$model, $created) { - $method = null; - if (($callback = $this->getCallbackableData($model, 'callback', 'string')) != false) { - $method = sprintf('__afterSave%s', Inflector::camelize($callback)); - } - - if($method && method_exists($model, $method)) { - return $model->{$method}($data); - } - return true; - } - -/** - * Before delete callback - * - * @param object $model Model using this behavior - * @param boolean $cascade If true records that depend on this record will also be deleted - * @return boolean True if the operation should continue, false if it should abort - * @access public - */ - function beforeDelete(&$model, $cascade = true) { - $method = null; - if (($callback = $this->getCallbackableData($model, 'callback', 'string')) != false) { - $method = sprintf('__beforeDelete%s', Inflector::camelize($callback)); - } - - if($method && method_exists($model, $method)) { - return $model->{$method}($model, $cascade); - } - return true; - } - -/** - * After delete callback - * - * @param object Model using this behavior - * @access public - */ - function afterDelete(&$model) { - $method = null; - if (($callback = $this->getCallbackableData($model, 'callback', 'string')) != false) { - $method = sprintf('__afterDelete%s', Inflector::camelize($callback)); - } - - if($method && method_exists($model, $method)) { - $model->{$method}($model); - } - } - -/** - * DataSource error callback - * - * @param object $model Model using this behavior - * @param string $error Error generated in DataSource - * @access public - */ - function onError(&$model, $error) { - $method = null; - if (($callback = $this->getCallbackableData($model,'callback', 'string')) != false) { - $method = sprintf('__onError%s', Inflector::camelize($callback)); - } - - if($method && method_exists($model, $method)) { - $model->{$method}($model, $error); - } - } -} -?> \ No newline at end of file diff --git a/models/login_token.php b/models/login_token.php new file mode 100644 index 0000000..64fb0f0 --- /dev/null +++ b/models/login_token.php @@ -0,0 +1,12 @@ +useTable, + 'user_id', + $user_id + ); + } + +} \ No newline at end of file diff --git a/models/user.php b/models/user.php new file mode 100644 index 0000000..98b80ee --- /dev/null +++ b/models/user.php @@ -0,0 +1,324 @@ + 'deleteAccount', + ); + + public function __construct($id = false, $table = null, $ds = null) { + parent::__construct($id, $table, $ds); + $this->order = array("`{$this->alias}`.`{$this->displayField}` asc"); + $this->_findMethods['account'] = true; + $this->_findMethods['approve'] = true; + $this->_findMethods['forapproval'] = true; + $this->validate = array( + 'first_name' => array( + 'required' => array( + 'rule' => array('notempty'), + 'message' => __('cannot be left empty', true), + ), + 'alphanumeric' => array( + 'rule' => array('alphanumeric'), + 'message' => __('must contain only letters and numbers', true), + ), + ), + 'last_name' => array( + 'alphanumeric' => array( + 'rule' => array('alphanumeric'), + 'message' => __('must contain only letters and numbers', true), + ), + ), + 'email_address' => array( + 'required' => array( + 'rule' => array('notempty'), + 'message' => __('cannot be left empty', true), + ), + 'email' => array( + 'rule' => array('email'), + 'message' => __('must be a valid email address', true), + ), + 'isUnique' => array( + 'rule' => array('isUnique'), + 'message' => __('this email is already registered, did you forget your password?', true), + ), + ), + 'password' => array( + 'required' => array( + 'rule' => array('notempty'), + 'message' => __('cannot be left empty', true), + ), + 'minLength' => array( + 'rule' => array('minLength', 6), + 'message' => __('must be at least 6 characters long', true), + ), + ), + 'new_password' => array( + 'minLength' => array( + 'rule' => array('minLength', 6), + 'message' => __('must be at least 6 characters long', true), + ), + ), + 'confirm_password' => array( + 'match' => array( + 'rule' => array('match', 'new_password'), + 'message' => __('passwords do not match', true), + ) + ), + + ); + } + + public function authsomeLogin($type, $credentials = array()) { + switch ($type) { + case 'guest': + // You can return any non-null value here, if you don't + // have a guest account, just return an empty array + return array('guest' => 'guest'); + case 'user_id' : + $conditions = array( + "{$this->alias}.{$this->primaryKey}" => $credentials['login'], + ); + break; + case 'credentials': + // Don't even attempt to login an invalid email address + if (!strstr($credentials['login'], '@')) { + return false; + } + + // This is the logic for validating the login + $conditions = array( + "{$this->alias}.email_address" => $credentials['login'], + "{$this->alias}.password" => Authsome::hash($credentials['credential']), + ); + break; + case 'cookie': + list($token, $id) = split(':', $credentials['token']); + $duration = $credentials['duration']; + + $loginToken = $this->LoginToken->find('first', array( + 'conditions' => array( + 'user_id' => $id, + 'token' => $token, + 'duration' => $duration, + 'used' => false, + 'expires <=' => date('Y-m-d H:i:s', strtotime($duration)), + ), + )); + + if (!$loginToken) { + return false; + } + + $loginToken['LoginToken']['used'] = true; + $this->LoginToken->save($loginToken); + + $conditions = array( + $this->alias . '.' . $this->primaryKey => $loginToken['LoginToken']['user_id'], + ); + break; + default: + return null; + } + + $user = $this->find('first', compact('conditions')); + if (!$user) { + return false; + } + $user[$this->alias]['loginType'] = $type; + return $user; + } + + public function authsomePersist($user, $duration) { + $token = md5(uniqid(mt_rand(), true)); + $id = $user[$this->alias][$this->primaryKey]; + + $this->LoginToken->create(array( + 'user_id' => $id, + 'token' => $token, + 'duration' => $duration, + 'expires' => date('Y-m-d H:i:s', strtotime($duration)), + )); + $this->LoginToken->save(); + + return $token . ':' . $userId; + } + + public function changeActivationKey($id) { + $activationKey = md5(uniqid()); + $data = array( + $this->alias => array( + $this->primaryKey => $id, + 'activation_key' => $activationKey, + ), + ); + + if (!$this->save($data, array('callbacks' => false))) return false; + return $activationKey; + } + + public function register($data = array()) { + $fields = array('first_name', 'email_address', 'password'); + + foreach ($fields as $field) { + if (!isset($data[$this->alias][$field])) { + return false; + } + } + + $this->create(array( + 'first_name' => $data[$this->alias]['first_name'], + 'email_address' => $data[$this->alias]['email_address'], + 'password' => Authsome::hash($data[$this->alias]['password']), + 'status' => User::STATUS_PENDING, + )); + if (!$this->save()) return false; + + Authsome::login('user_id', array('login' => $this->id)); + return true; + } + + public function approveAccount($id = null) { + if (!$id) return false; + + $user = $this->find('approve', $id); + if (!$user) return false; + + if ($user[$this->alias]['status'] == User::STATUS_APPROVED) { + return true; + } + + $user[$this->alias]['status'] = User::STATUS_APPROVED; + return $this->save($user); + } + + public function deleteAccount() { + $queries = array(); + $user_id = Authsome::get('id'); + + foreach ($this->deleteAccount as $modelName => $method) { + if (strstr($modelName, '.') === false && isset($this->$modelName)) { + if (method_exists($this->$modelName, $method)) { + $queries[] = $this->$modelName->$method($user_id); + } + } else { + $modelObj = ClassRegistry::init($modelName); + if (is_object($modelObj) && method_exists($this->$modelName, $method)) { + $queries[] = $this->$modelName->$method($user_id); + } + } + } + + $queries[] = sprintf('DELETE FROM %s WHERE `%s` = %s', + $this->useTable, + $this->primaryKey, + $user_id + ); + + $dataSource = $this->getDataSource(); + $dataSource->begin($this); + foreach ($queries as $query) { + if (!$this->query($query)) { + $dataSource->rollback($this); + return false; + } + } + return $dataSource->commit($this); + } + + public function updateAccount($data = array()) { + if (empty($data)) return false; + + $fields = array('first_name', 'last_name', 'location'); + foreach ($fields as $field) { + if (!empty($data[$this->alias][$field])) { + $results[$field] = $data[$this->alias][$field]; + } + } + + if (empty($results)) return false; + + $this->create($data); + $this->id = Authsome::get('id'); + return $this->save(); + } + + public function updatePassword($data = array()) { + if (empty($data[$this->alias]['new_password'])) return false; + if (empty($data[$this->alias]['confirm_password'])) return false; + + $this->set(array( + 'new_password' => $data[$this->alias]['new_password'], + 'confirm_password' => $data[$this->alias]['confirm_password'] + )); + if (!$this->validates()) return false; + + $this->create(array('password' => Authsome::hash($data[$this->alias]['new_password']))); + $this->id = Authsome::get('id'); + return $this->save(); + } + + public function _findAccount($state, $query, $results = array()) { + if ($state == 'before') { + $query['conditions'] = array("{$this->alias}.{$this->primaryKey}" => Authsome::get('id')); + $query['fields'] = array('first_name', 'last_name', 'location'); + return $query; + } elseif ($state == 'after') { + if (empty($results[0])) { + return false; + } + return $results[0]; + } + } + + public function _findApprove($state, $query, $results = array()) { + if ($state == 'before') { + if (isset($query[0])) { + $query['conditions'] = array("{$this->alias}.{$this->primaryKey}" => $query[0]); + } else if (isset($query['user_id'])) { + $query['conditions'] = array("{$this->alias}.{$this->primaryKey}" => $query['user']); + } else { + $query['conditions'] = array("{$this->alias}.{$this->primaryKey}" => null); + } + + $query['fields'] = array('id', 'status'); + return $query; + } elseif ($state == 'after') { + if (empty($results[0])) { + return false; + } + return $results[0]; + } + } + + public function _findForapproval($state, $query, $results = array()) { + if ($state == 'before') { + $query['conditions'] = array("{$this->alias}.status" => User::STATUS_PENDING); + $query['fields'] = array('id', 'first_name', 'email_address', 'created', 'status'); + + if (!empty($query['operation'])) { + return $this->_findPaginatecount($state, $query, $results); + } + return $query; + } elseif ($state == 'after') { + if (!empty($query['operation'])) { + return $this->_findPaginatecount($state, $query, $results); + } + + return $results; + } + } + function match($check, $field) { + $value = array_values($check); + return $value[0] == $this->data[$this->alias][$field]; + } + +} \ No newline at end of file diff --git a/plugins/authsome/README.md b/plugins/authsome/README.md deleted file mode 100755 index 07f0e83..0000000 --- a/plugins/authsome/README.md +++ /dev/null @@ -1,334 +0,0 @@ -# Auth for people who hate the Auth component - -Authsome is a CakePHP 1.2 plugin that makes authentication a pleasure to work with by following a few simple rules: - -**Assume nothing:** Authsome requires that you have some kind of user model, but that's it. It doesn't care if you use a database, passwords or religious ceremonies for verifying your member logins. - -**Touch nothing:** Authsome does not interact with your application at all. No login redirects, no permissions checks, nothing. You never have to worry about the underlaying magic, it will never get into your way. - -**Always available:** Authsome is there for you when you need it. You can do stuff like `Authsome::get('id')` from anywhere in your project. If you have MVC OCD, you can also use Authsome as a regular component: `$this->Authsome->get('id')` - -## Installation - -Copy the contents of this directory into plugins/authsome: - - cd my_cake_app - git clone git://github.com/felixge/cakephp-authsome.git plugins/authsome - -Load authsome in your AppController and specify the name of your user model: - - class AppController extends Controller { - public $components = array( - 'Authsome.Authsome' => array( - 'model' => 'User' - ) - ); - } - -Implement authsomeLogin in your user model (must return a non-null value): - - class User extends AppModel{ - public function authsomeLogin($type, $credentials = array()) { - switch ($type) { - case 'guest': - // You can return any non-null value here, if you don't - // have a guest account, just return an empty array - return array('it' => 'works'); - case 'credentials': - $password = Authsome::hash($credentials['password']); - - // This is the logic for validating the login - $conditions = array( - 'User.email' => $credentials['email'], - 'User.password' => $password, - ); - break; - default: - return null; - } - - return $this->find('first', compact('conditions')); - } - } - -Almost done! Check if you did everything right so far by putting this in one of your controllers: - - $guest = Authsome::get(); - debug($guest); - -If this returns `Array([it] => works)`, you can go ahead and implement a simple login function: - - class UsersController extends AppController{ - public function login() { - if (empty($this->data)) { - return; - } - - $user = Authsome::login($this->data['User']); - - if (!$user) { - $this->Session->setFlash('Unknown user or wrong password'); - return; - } - - $user = Authsome::get(); - debug($user); - } - } - -And add a app/views/users/login.ctp file like this: - -

pageTitle = 'Login'; ?>

- create('User', array('action' => $this->action)); - echo $form->input('email', array('label' => 'Email')); - echo $form->input('password', array('label' => "Password")); - echo $form->submit('Login'); - echo $form->end(); - ?> - - -The array passed into `Authsome::login()` gets passed directly to your `authsomeLogin` function, so you really pass any kind of credentials. You can even come up with your own authentication types by doing `Authsome::login('voodoo_auth', $chickenBones)`. - -## Cookies - -Any login created by `Authsome::login()` will only last as long as your CakePHP session itself. However, you might want to offer one of those nifty "Remember me for 2 weeks" buttons. `Authsome::persist()` comes to rescue! - -First of all change your login action like this: - - public function login() { - if (empty($this->data)) { - return; - } - - $user = Authsome::login($this->data['User']); - - if (!$user) { - $this->Session->setFlash('Unknown user or wrong password'); - return; - } - - $remember = (!empty($this->data['User']['remember'])); - if ($remember) { - Authsome::persist('2 weeks'); - } - } - -Also add a checkbox like this to your form: - - echo $form->input('remember', array( - 'label' => "Remember me for 2 weeks", - 'type' => "checkbox" - )); - -Authsome itself does not care how you manage your cookie login tokens for auth persistence, but I highly recommend following [Charles' Receipe][1] for this. Charles recommends to create a table that maps `user_id`s and login tokens, here is what I use: - -[1]: http://fishbowl.pastiche.org/2004/01/19/persistent_login_cookie_best_practice/ - - CREATE TABLE `login_tokens` ( - `id` int(11) NOT NULL auto_increment, - `user_id` int(11) NOT NULL, - `token` char(32) NOT NULL, - `duration` varchar(32) NOT NULL, - `used` tinyint(1) NOT NULL default '0', - `created` datetime NOT NULL, - `expires` datetime NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 - -Don't forget to create an empty model in app/models/login_token.php for this: - - class LoginToken extends AppModel{ - } - -Next you'll need to implement `authsomePersist` in your user model, which creates and stores a unique login token when `Authsome::persist()` is called: - - public $hasMany = array('LoginToken'); - - public function authsomePersist($user, $duration) { - $token = md5(uniqid(mt_rand(), true)); - $userId = $user['User']['id']; - - $this->LoginToken->create(array( - 'user_id' => $userId, - 'token' => $token, - 'duration' => $duration, - 'expires' => date('Y-m-d H:i:s', strtotime($duration)), - )); - $this->LoginToken->save(); - - return "${token}:${userId}"; - } - -So far so good. If you are still on track, you should now be able to see new records showing up in your `login_tokens` table if you log in with the remember checkbox checked. - -If so, proceed to the next step and add the `'cookie'` login `$type` to your authsomeLogin function: - - public function authsomeLogin($type, $credentials = array()) { - switch ($type) { - case 'guest': - // You can return any non-null value here, if you don't - // have a guest account, just return an empty array - return array('it' => 'works'); - case 'credentials': - $password = Authsome::hash($credentials['password']); - - // This is the logic for validating the login - $conditions = array( - 'User.email' => $credentials['email'], - 'User.password' => $password, - ); - break; - case 'cookie': - list($token, $userId) = split(':', $credentials['token']); - $duration = $credentials['duration']; - - $loginToken = $this->LoginToken->find('first', array( - 'conditions' => array( - 'user_id' => $userId, - 'token' => $token, - 'duration' => $duration, - 'used' => false, - 'expires <=' => date('Y-m-d H:i:s', strtotime($duration)), - ), - 'contain' => false - )); - - if (!$loginToken) { - return false; - } - - $loginToken['LoginToken']['used'] = true; - $this->LoginToken->save($loginToken); - - $conditions = array( - 'User.id' => $loginToken['LoginToken']['user_id'] - ); - break; - default: - return null; - } - - return $this->find('first', compact('conditions')); - } - -Let's go over this real quick. First we are checking the db for a matching token. If none is found, we return false. If we find a valid token, we invalidate it and set the conditions for finding the user that belongs to the token. - -Pretty simple! You could also do this entirely different. For example you could skip having a `login_tokens` table all together and instead give out tokens that are signed with a secret and a timestamp. However, the drawback with those tokens is that they could be used multiple times which makes cookie theft a more severe problem. - -**Security Advisory:** You should require users to re-authenticate using an alternative login method in case of the following: - -* Changing the user's password -* Changing the user's email address (especially if email-based password recovery is used) -* Any access to the user's address, payment details or financial information -* Any ability to make a purchase - -This can easily be done by tweaking the end of your authsomeLogin function like this: - - $user = $this->find('first', compact('conditions')); - if (!$user) { - return false; - } - $user['User']['loginType'] = $type; - return $user; - -Then deny access to any of the functionality mentioned above like this: - - if (Authsome::get('loginType') === 'cookie') { - Authsome::logout(); - $this->redirect(array( - 'controller' => 'users', - 'action' => 'login', - )) - } - -## Documentation - -### AuthsomeComponent::initialize($controller, $settings) - -Initializes the AuthsomeComponent with the given settings. This method is called for you when including Authsome in your AppController: - - public $components = array( - 'Authsome.Authsome' => array( - 'model' => 'User' - ) - ); - -Available `$settings` and their defaults: - - 'model' => 'User', - // Those all default to $settings['model'] if not set explicitly - 'configureKey' => null, - 'sessionKey' => null, - 'cookieKey' => null, - -### AuthsomeComponent::get($field = null) - -Returns the current user record. If `$field` is given, the records sub-field for the main model is extracted. The following two calls are identical: - - $this->Authsome->get('id'); - $this->Authsome->get('User.id'); - -However, you could can also access any associations you may habe returned from your user models `authsomeLogin` function: - - $this->Authsome->get('Role.name'); - -### AuthsomeComponent::login($type = 'credentials', $credentials = null) - -Passes the given `$type` and `$credentials` to your user model `authsomeLogin` function. Returns false on failure, or the user record on success. - -If you skip the `$type` parameter, the default will be `'credentials'`. This means the following two calls are identical: - - $user = $this->Authsome->login('credentials', $this->data); - $user = $this->Authsome->login($this->data); - -### AuthsomeComponent::logout() - -Destroys the current authsome session and also deletes any authsome cookies. - -### AuthsomeComponent::persist($duration = '2 weeks') - -Calls the user models `authsomePersist` function to get a login token and stores it in a cookie. `$duration` must be a relative time string that can be parsed by `strtotime()` and must not be an absolute date or timestamp. - -When performing a cookie login, authsome will automatically renew the login cookie for the given `$duration` again. - -### AuthsomeComponent::hash($passwords) - -Takes the given `$passwords` and returns the sha1 hash for it using core.php's `'Security.salt'` setting. The following two lines are identical: - - $hashedPw = $this->Authsome->hash('foobar'); - $hashedPw = Security::hash('foobar', 'sha1', true); - -This is a convenience function. It is not used by Authsome internally, you are free to use any password hashing schema you desire. - -### Static convenience functions - -The following static shortcuts exist for your convenience: - - Authsome::get() - Authsome::login() - Authsome::logout() - Authsome::persist() - Authsome::hash() - -They are identical to calling the AuthsomeComponent in your controller, but allow you to access Authsome anywhere in your app (models, views, etc.). If you suffer from MVC OCD, do not use these functions. - -## Under the hood - -Authsome builds on a fairly simple logic. The first time you call `Authsome::get()`, it tries to find out who the active user it. This is done as follows: - -1. Check if Configure::read($this->settings['configureKey']) for a user record -2. Check $this->Session->read($this->settings['sessionKey']) for a user record -3. Check $this->Cookie->read($this->settings['cookieKey']) for a token - -If all 3 of those checks do not produce a valid user record, authsome calls the user models `authsomeLogin('guest')` function and takes the record returned from that. If even that fails, authsome will throw an exception and bring your app to a crashing halt. - -## License - -Authsome is licensed under the MIT license. - -## Sponsors - -The initial development of Authsome was paid for by [ThreeLeaf Creative](http://threeleaf.tv/), the makers of a fantastic CakePHP CMS system. - -Authsome is developed by [Debuggable Ltd](http://debuggable.com/). Get in touch if you need help making your next project an authsome one! \ No newline at end of file diff --git a/plugins/authsome/controllers/components/authsome.php b/plugins/authsome/controllers/components/authsome.php deleted file mode 100755 index 268af72..0000000 --- a/plugins/authsome/controllers/components/authsome.php +++ /dev/null @@ -1,236 +0,0 @@ - 'User', - 'configureKey' => null, - 'sessionKey' => null, - 'cookieKey' => null, - ); - - private $__userModel; - - public function initialize($controller, $settings = array()) { - Authsome::instance($this); - $this->settings = Set::merge($this->settings, $settings); - - // Use the model name as the key everywhere by default - $keys = array('configure', 'session', 'cookie'); - foreach ($keys as $prefix) { - $key = $prefix.'Key'; - if (empty($this->settings[$key])) { - $this->settings[$key] = $this->settings['model']; - } - } - } - - public function get($field = null) { - $user = $this->__getActiveUser(); - - if (empty($field)) { - return $user; - } - - if (strpos($field, '.') === false) { - if (in_array($field, array_keys($user))) { - return $user[$field]; - } - $field = $this->settings['model'].'.'.$field; - } - - return Set::extract($user, $field); - } - - public function login($type = 'credentials', $credentials = null) { - $userModel = $this->__getUserModel(); - - $args = func_get_args(); - if (!method_exists($userModel, 'authsomeLogin')) { - $this->cakeError('missing_method', array( - 'className' => $userModel, - 'methodName' => 'authsomeLogin', - 'parameters' => '$type, $credentials = array()' - )); - } - - if (!is_string($type) && is_null($credentials)) { - $credentials = $type; - $type = 'credentials'; - } - - $user = $userModel->authsomeLogin($type, $credentials); - - Configure::write($this->settings['configureKey'], $user); - $this->Session->write($this->settings['sessionKey'], $user); - return $user; - } - - public function logout() { - Configure::write($this->settings['configureKey'], array()); - $this->Session->write($this->settings['sessionKey'], array()); - $this->Cookie->write($this->settings['cookieKey'], ''); - - return true; - } - - public function persist($duration = '2 weeks') { - $userModel = $this->__getUserModel(); - - if (!method_exists($userModel, 'authsomePersist')) { - $this->cakeError('missing_method', array( - 'className' => $userModel, - 'methodName' => 'authsomePersist', - 'parameters' => '$user, $duration' - )); - } - - $token = $userModel->authsomePersist(Authsome::get(), $duration); - $token = $token.':'.$duration; - - return $this->Cookie->write( - $this->settings['cookieKey'], - $token, - true, // encrypt = true - $duration - ); - } - - public function hash($password) { - return Authsome::hash($password); - } - - private function __getUserModel() { - if ($this->__userModel) { - return $this->__userModel; - } - - return $this->__userModel = ClassRegistry::init( - $this->settings['model'] - ); - } - - private function __getActiveUser() { - $user = Configure::read($this->settings['configureKey']); - if (!empty($user)) { - return $user; - } - - $this->__useSession() || - $this->__useCookieToken() || - $this->__useGuestAccount(); - - $user = Configure::read($this->settings['configureKey']); - if (is_null($user)) { - throw new Exception( - 'Unable to initialize user' - ); - } - - return $user; - } - - private function __useSession() { - $user = $this->Session->read($this->settings['sessionKey']); - if (!$user) { - return false; - } - - Configure::write($this->settings['configureKey'], $user); - return true; - } - - private function __useCookieToken() { - $token = $this->Cookie->read($this->settings['cookieKey']); - if (!$token) { - return false; - } - - // Extract the duration appendix from the token - $tokenParts = split(':', $token); - $duration = array_pop($tokenParts); - $token = join(':', $tokenParts); - - $user = $this->login('cookie', compact('token', 'duration')); - - // Delete the cookie once its been used - $this->Cookie->delete($this->settings['cookieKey']); - - if (!$user) { - return; - } - - $this->persist($duration); - - return (bool)$user; - } - - private function __useGuestAccount() { - return $this->login('guest'); - } -} - -// Static Authsomeness -class Authsome{ - static function instance($setInstance = null) { - static $instance; - - if ($setInstance) { - $instance = $setInstance; - } - - if (!$instance) { - throw new Exception( - 'AuthsomeComponent not initialized properly!' - ); - } - - return $instance; - } - - public static function get($field = null) { - return self::instance()->get($field); - } - - public static function login($type = 'credentials', $credentials = null) { - return self::instance()->login($type, $credentials); - } - - public static function logout() { - return self::instance()->logout(); - } - - public static function persist($duration = '2 weeks') { - return self::instance()->persist($duration); - } - - public static function hash($password, $method = 'sha1', $salt = true) { - return Security::hash($password, $method, $salt); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/README.mdown b/plugins/debug_kit/README.mdown deleted file mode 100755 index c1c56b3..0000000 --- a/plugins/debug_kit/README.mdown +++ /dev/null @@ -1,22 +0,0 @@ -# CakePHP DebugKit - -DebugKit provides a debugging toolbar and enhanced debugging tools for CakePHP applications. - -## Installation - -* Clone/Copy the files in this directory into `app/plugins/debug_kit` -* Include the toolbar component in your `app_controller.php`: - * `var $components = array('DebugKit.Toolbar');` -* Set debug mode to at least 1. - -## Documentation - -Further documentation including additional configuration and ways of extending DebugKit can be found in the [Lighthouse wiki](http://cakephp.lighthouseapp.com/projects/42880-debug-kit/overview) - -## Reporting issues - -If you have an issues with DebugKit please open a ticket on lighthouse http://cakephp.lighthouseapp.com/projects/42880-debug-kit/overview - -## Contributing - -If you'd like to contribute to DebugKit, check out the [Roadmap](http://cakephp.lighthouseapp.com/projects/42880/roadmap) for any planned features. You can fork the project add features and send pull requests, or open tickets on lighthouse. \ No newline at end of file diff --git a/plugins/debug_kit/build.py b/plugins/debug_kit/build.py deleted file mode 100755 index ba75dcf..0000000 --- a/plugins/debug_kit/build.py +++ /dev/null @@ -1,130 +0,0 @@ -#! /usr/bin/env python - -import sys, os -import tarfile, zipfile, gzip, bz2 -from optparse import OptionParser - -""" -Builds packaged releases of DebugKit so I don't have to do things manually. - -Excludes itself (build.py), .gitignore, .DS_Store and the .git folder from the archives. -""" -def main(): - parser = OptionParser(); - parser.add_option('-o', '--output-dir', dest="output_dir", - help="write the packages to DIR", metavar="DIR") - parser.add_option('-p', '--prefix-name', dest="prefix", - help="prefix used for the generated files") - parser.add_option('-k', '--skip', dest="skip", default="", - help="A comma separated list of files to skip") - parser.add_option('-s', '--source-dir', dest="source", default=".", - help="The source directory for the build process") - - (options, args) = parser.parse_args() - - if options.output_dir == '' or options.output_dir == options.source: - print 'Requires an output dir, and that output dir cannot be the same as the source one!' - exit() - - # append .git and build.py to the skip files - skip = options.skip.split(',') - skip.extend(['.git', '.gitignore', '.DS_Store', 'build.py']) - - # get list of files in top level dir. - files = os.listdir(options.source) - - os.chdir(options.source) - - # filter the files, I couldn't figure out how to do it in a more concise way. - for f in files[:]: - try: - skip.index(f) - files.remove(f) - except ValueError: - pass - - # make a boring tar file - destfile = ''.join([options.output_dir, options.prefix]) - tar_file_name = destfile + '.tar' - tar = tarfile.open(tar_file_name, 'w'); - for f in files: - tar.add(f) - tar.close() - print "Generated tar file" - - # make the gzip - if make_gzip(tar_file_name, destfile): - print "Generated gzip file" - else: - print "Could not generate gzip file" - - # make the bz2 - if make_bz2(tar_file_name, destfile): - print "Generated bz2 file" - else: - print "Could not generate bz2 file" - - # make the zip file - zip_recursive(destfile + '.zip', options.source, files) - print "Generated zip file\n" - -def make_gzip(tar_file, destination): - """ - Takes a tar_file and destination. Compressess the tar file and creates - a .tar.gzip - """ - tar_contents = open(tar_file, 'rb') - gzipfile = gzip.open(destination + '.tar.gz', 'wb') - gzipfile.writelines(tar_contents) - gzipfile.close() - tar_contents.close() - return True - -def make_bz2(tar_file, destination): - """ - Takes a tar_file and destination. Compressess the tar file and creates - a .tar.bz2 - """ - tar_contents = open(tar_file, 'rb') - bz2file = bz2.BZ2File(destination + '.tar.bz2', 'wb') - bz2file.writelines(tar_contents) - bz2file.close() - tar_contents.close() - return True - -def zip_recursive(destination, source_dir, rootfiles): - """ - Recursively zips source_dir into destination. - rootfiles should contain a list of files in the top level directory that - are to be included. Any top level files not in rootfiles will be omitted - from the zip file. - """ - zipped = zipfile.ZipFile(destination, 'w', zipfile.ZIP_DEFLATED) - - for root, dirs, files in os.walk(source_dir): - inRoot = False - if root == source_dir: - inRoot = True - - if inRoot: - for d in dirs: - try: - rootfiles.index(d) - except ValueError: - dirs.remove(d) - - for f in files[:]: - if inRoot: - try: - rootfiles.index(f) - except ValueError: - continue - - fullpath = os.path.join(root, f) - zipped.write(fullpath) - zipped.close() - return destination - - -if __name__ == '__main__': - main() \ No newline at end of file diff --git a/plugins/debug_kit/controllers/components/toolbar.php b/plugins/debug_kit/controllers/components/toolbar.php deleted file mode 100755 index eaf8c14..0000000 --- a/plugins/debug_kit/controllers/components/toolbar.php +++ /dev/null @@ -1,650 +0,0 @@ - false, - 'autoRun' => true - ); -/** - * Controller instance reference - * - * @var object - */ - var $controller; -/** - * Components used by DebugToolbar - * - * @var array - */ - var $components = array('RequestHandler', 'Session'); -/** - * The default panels the toolbar uses. - * which panels are used can be configured when attaching the component - * - * @var array - */ - var $_defaultPanels = array('history', 'session', 'request', 'sqlLog', 'timer', 'log', 'variables'); -/** - * Loaded panel objects. - * - * @var array - */ - var $panels = array(); -/** - * javascript files component will be using - * - * @var array - **/ - var $javascript = array( - 'behavior' => '/debug_kit/js/js_debug_toolbar' - ); -/** - * CacheKey used for the cache file. - * - * @var string - **/ - var $cacheKey = 'toolbar_cache'; -/** - * Duration of the debug kit history cache - * - * @var string - **/ - var $cacheDuration = '+4 hours'; -/** - * initialize - * - * If debug is off the component will be disabled and not do any further time tracking - * or load the toolbar helper. - * - * @return bool - **/ - function initialize(&$controller, $settings) { - $this->settings = am($this->settings, $settings); - if (!Configure::read('debug') && empty($this->settings['forceEnable'])) { - $this->enabled = false; - return false; - } - if ($this->settings['autoRun'] == false && !isset($controller->params['url']['debug'])) { - $this->enabled = false; - return false; - } - App::import('Vendor', 'DebugKit.DebugKitDebugger'); - - DebugKitDebugger::setMemoryPoint(__d('debug_kit', 'Component intitailization', true)); - DebugKitDebugger::startTimer('componentInit', __d('debug_kit', 'Component initialization and startup', true)); - - $panels = $this->_defaultPanels; - if (isset($settings['panels'])) { - $panels = $this->_makePanelList($settings['panels']); - unset($settings['panels']); - } - - $this->cacheKey .= $this->Session->read('Config.userAgent'); - if (in_array('history', $panels) || (isset($settings['history']) && $settings['history'] !== false)) { - $this->_createCacheConfig(); - } - - $this->_loadPanels($panels, $settings); - - $this->_set($settings); - $this->controller =& $controller; - return false; - } -/** - * Go through user panels and remove default panels as indicated. - * - * @param array $userPanels The list of panels ther user has added removed. - * @return array Array of panels to use. - **/ - function _makePanelList($userPanels) { - $panels = $this->_defaultPanels; - foreach ($userPanels as $key => $value) { - if (is_numeric($key)) { - $panels[] = $value; - } - if (is_string($key) && $value === false) { - $index = array_search($key, $panels); - if ($index !== false) { - unset($panels[$index]); - } - } - } - return $panels; - } -/** - * Component Startup - * - * @return bool - **/ - function startup(&$controller) { - $currentViewClass = $controller->view; - $this->_makeViewClass($currentViewClass); - $controller->view = 'DebugKit.Debug'; - $isHtml = ( - !isset($controller->params['url']['ext']) || - (isset($controller->params['url']['ext']) && $controller->params['url']['ext'] == 'html') - ); - - if (!$this->RequestHandler->isAjax() && $isHtml) { - $format = 'Html'; - } else { - $format = 'FirePhp'; - } - $controller->helpers['DebugKit.Toolbar'] = array( - 'output' => sprintf('DebugKit.%sToolbar', $format), - 'cacheKey' => $this->cacheKey, - 'cacheConfig' => 'debug_kit', - 'forceEnable' => $this->settings['forceEnable'], - ); - $panels = array_keys($this->panels); - foreach ($panels as $panelName) { - $this->panels[$panelName]->startup($controller); - } - DebugKitDebugger::stopTimer('componentInit'); - DebugKitDebugger::startTimer('controllerAction', __d('debug_kit', 'Controller action', true)); - DebugKitDebugger::setMemoryPoint(__d('debug_kit', 'Controller action start', true)); - } -/** - * beforeRedirect callback - * - * @return void - **/ - function beforeRedirect(&$controller) { - if (!class_exists('DebugKitDebugger')) { - return null; - } - DebugKitDebugger::stopTimer('controllerAction'); - $vars = $this->_gatherVars($controller); - $this->_saveState($controller, $vars); - } -/** - * beforeRender callback - * - * Calls beforeRender on all the panels and set the aggregate to the controller. - * - * @return void - **/ - function beforeRender(&$controller) { - DebugKitDebugger::stopTimer('controllerAction'); - $vars = $this->_gatherVars($controller); - $this->_saveState($controller, $vars); - - $controller->set(array('debugToolbarPanels' => $vars, 'debugToolbarJavascript' => $this->javascript)); - DebugKitDebugger::startTimer('controllerRender', __d('debug_kit', 'Render Controller Action', true)); - DebugKitDebugger::setMemoryPoint(__d('debug_kit', 'Controller render start', true)); - } -/** - * Load a toolbar state from cache - * - * @param int $key - * @return array - **/ - function loadState($key) { - $history = Cache::read($this->cacheKey, 'debug_kit'); - if (isset($history[$key])) { - return $history[$key]; - } - return array(); - } -/** - * Create the cache config for the history - * - * @return void - * @access protected - **/ - function _createCacheConfig() { - if (Configure::read('Cache.disable') !== true) { - Cache::config('debug_kit', array( - 'duration' => $this->cacheDuration, - 'engine' => 'File', - 'path' => CACHE - )); - Cache::config('default'); - } - } -/** - * collects the panel contents - * - * @return array Array of all panel beforeRender() - * @access protected - **/ - function _gatherVars(&$controller) { - $vars = array(); - $panels = array_keys($this->panels); - - foreach ($panels as $panelName) { - $panel =& $this->panels[$panelName]; - $panelName = Inflector::underscore($panelName); - $vars[$panelName]['content'] = $panel->beforeRender($controller); - $elementName = Inflector::underscore($panelName) . '_panel'; - if (isset($panel->elementName)) { - $elementName = $panel->elementName; - } - $vars[$panelName]['elementName'] = $elementName; - $vars[$panelName]['plugin'] = $panel->plugin; - $vars[$panelName]['title'] = $panel->title; - $vars[$panelName]['disableTimer'] = true; - } - return $vars; - } -/** - * Load Panels used in the debug toolbar - * - * @return void - * @access protected - **/ - function _loadPanels($panels, $settings) { - foreach ($panels as $panel) { - $className = $panel . 'Panel'; - if (!class_exists($className) && !App::import('Vendor', $className)) { - trigger_error(sprintf(__d('debug_kit', 'Could not load DebugToolbar panel %s', true), $panel), E_USER_WARNING); - continue; - } - if (strpos($className, '.') !== false) { - list($plugin, $className) = explode('.', $className); - } - $panelObj =& new $className($settings); - if (is_subclass_of($panelObj, 'DebugPanel') || is_subclass_of($panelObj, 'debugpanel')) { - $this->panels[$panel] =& $panelObj; - } - } - } -/** - * Makes the DoppleGangerView class if it doesn't already exist. - * This allows DebugView to be compatible with all view classes. - * - * @param string $baseClassName - * @access protected - * @return void - */ - function _makeViewClass($baseClassName) { - if (!class_exists('DoppelGangerView')) { - App::import('View', $baseClassName); - if (strpos($baseClassName, '.') !== false) { - list($plugin, $baseClassName) = explode('.', $baseClassName); - } - if (strpos($baseClassName, 'View') === false) { - $baseClassName .= 'View'; - } - $class = "class DoppelGangerView extends $baseClassName {}"; - $this->_eval($class); - } - } -/** - * Method wrapper for eval() for testing uses. - * - * @return void - **/ - function _eval($code) { - eval($code); - } -/** - * Save the current state of the toolbar varibles to the cache file. - * - * @param object $controller Controller instance - * @param array $vars Vars to save. - * @access protected - * @return void - **/ - function _saveState(&$controller, $vars) { - $config = Cache::config('debug_kit'); - if (empty($config) || !isset($this->panels['history'])) { - return; - } - $history = Cache::read($this->cacheKey, 'debug_kit'); - if (empty($history)) { - $history = array(); - } - if (count($history) == $this->panels['history']->history) { - array_pop($history); - } - unset($vars['history']); - array_unshift($history, $vars); - Cache::write($this->cacheKey, $history, 'debug_kit'); - } -} - -/** - * Debug Panel - * - * Abstract class for debug panels. - * - * @package cake.debug_kit - */ -class DebugPanel extends Object { -/** - * Defines which plugin this panel is from so the element can be located. - * - * @var string - */ - var $plugin = null; -/** - * Defines the title for displaying on the toolbar. - * - * @var string - */ - var $title = null; -/** - * startup the panel - * - * Pull information from the controller / request - * - * @param object $controller Controller reference. - * @return void - **/ - function startup(&$controller) { } -/** - * Prepare output vars before Controller Rendering. - * - * @param object $controller Controller reference. - * @return void - **/ - function beforeRender(&$controller) { } -} - -/** - * History Panel - * - * Provides debug information on previous requests. - * - * @package cake.debug_kit.panels - **/ -class HistoryPanel extends DebugPanel { - var $plugin = 'debug_kit'; -/** - * Number of history elements to keep - * - * @var string - **/ - var $history = 5; -/** - * Constructor - * - * @param array $settings Array of settings. - * @return void - **/ - function __construct($settings) { - if (isset($settings['history'])) { - $this->history = $settings['history']; - } - } -/** - * beforeRender callback function - * - * @return array contents for panel - **/ - function beforeRender(&$controller) { - $cacheKey = $controller->Toolbar->cacheKey; - $toolbarHistory = Cache::read($cacheKey, 'debug_kit'); - $historyStates = array(); - if (is_array($toolbarHistory) && !empty($toolbarHistory)) { - $prefix = array(); - if (!empty($controller->params['prefix'])) { - $prefix[$controller->params['prefix']] = false; - } - foreach ($toolbarHistory as $i => $state) { - if (!isset($state['request']['content']['params']['url']['url'])) { - continue; - } - $historyStates[] = array( - 'title' => $state['request']['content']['params']['url']['url'], - 'url' => array_merge($prefix, array( - 'plugin' => 'debug_kit', - 'controller' => 'toolbar_access', - 'action' => 'history_state', - $i + 1)) - ); - } - } - if (count($historyStates) >= $this->history) { - array_pop($historyStates); - } - return $historyStates; - } -} - -/** - * Variables Panel - * - * Provides debug information on the View variables. - * - * @package cake.debug_kit.panels - **/ -class VariablesPanel extends DebugPanel { - var $plugin = 'debug_kit'; -/** - * beforeRender callback - * - * @return array - **/ - function beforeRender(&$controller) { - return array_merge($controller->viewVars, array('$this->data' => $controller->data)); - } -} - -/** - * Session Panel - * - * Provides debug information on the Session contents. - * - * @package cake.debug_kit.panels - **/ -class SessionPanel extends DebugPanel { - var $plugin = 'debug_kit'; -/** - * beforeRender callback - * - * @param object $controller - * @access public - * @return array - */ - function beforeRender(&$controller) { - $sessions = $controller->Toolbar->Session->read(); - return $sessions; - } -} - -/** - * Request Panel - * - * Provides debug information on the Current request params. - * - * @package cake.debug_kit.panels - **/ -class RequestPanel extends DebugPanel { - var $plugin = 'debug_kit'; -/** - * beforeRender callback - grabs request params - * - * @return array - **/ - function beforeRender(&$controller) { - $out = array(); - $out['params'] = $controller->params; - if (isset($controller->Cookie)) { - $out['cookie'] = $controller->Cookie->read(); - } - $out['get'] = $_GET; - $out['currentRoute'] = Router::currentRoute(); - return $out; - } -} - -/** - * Timer Panel - * - * Provides debug information on all timers used in a request. - * - * @package cake.debug_kit.panels - **/ -class TimerPanel extends DebugPanel { - var $plugin = 'debug_kit'; -/** - * startup - add in necessary helpers - * - * @return void - **/ - function startup(&$controller) { - if (!in_array('Number', $controller->helpers)) { - $controller->helpers[] = 'Number'; - } - if (!in_array('SimpleGraph', $controller->helpers)) { - $controller->helpers[] = 'DebugKit.SimpleGraph'; - } - } -} - -/** - * SqlLog Panel - * - * Provides debug information on the SQL logs and provides links to an ajax explain interface. - * - * @package cake.debug_kit.panels - **/ -class SqlLogPanel extends DebugPanel { - var $plugin = 'debug_kit'; -/** - * Minimum number of Rows Per Millisecond that must be returned by a query before an explain - * is done. - * - * @var int - **/ - var $slowRate = 20; -/** - * Gets the connection names that should have logs + dumps generated. - * - * @param string $controller - * @access public - * @return void - */ - function beforeRender(&$controller) { - if (!class_exists('ConnectionManager')) { - return array(); - } - $connections = array(); - - $dbConfigs = ConnectionManager::sourceList(); - foreach ($dbConfigs as $configName) { - $db =& ConnectionManager::getDataSource($configName); - if (!isset($db->config['driver'])) { - return false; - } - $driver = $db->config['driver']; - $explain = false; - $isExplainable = ($driver === 'mysql' || $driver === 'mysqli' || $driver === 'postgres'); - if ($isExplainable && $db->isInterfaceSupported('getLog')) { - $explain = true; - } - $connections[$configName] = $explain; - } - return array('connections' => $connections, 'threshold' => $this->slowRate); - } -} - -/** - * Log Panel - Reads log entries made this request. - * - * @package cake.debug_kit.panels - */ -class LogPanel extends DebugPanel { - var $plugin = 'debug_kit'; -/** - * Log files to scan - * - * @var array - */ - var $logFiles = array('error.log', 'debug.log'); -/** - * startup - * - * @return void - **/ - function startup(&$controller) { - if (!class_exists('CakeLog')) { - App::import('Core', 'CakeLog'); - } - } -/** - * beforeRender Callback - * - * @return array - **/ - function beforeRender(&$controller) { - $this->startTime = DebugKitDebugger::requestStartTime(); - $this->currentTime = DebugKitDebugger::requestTime(); - $out = array(); - foreach ($this->logFiles as $log) { - $file = LOGS . $log; - if (!file_exists($file)) { - continue; - } - $out[$log] = $this->_parseFile($file); - } - return $out; - } -/** - * parse a log file and find the relevant entries - * - * @param string $filename Name of file to read - * @access protected - * @return array - */ - function _parseFile($filename) { - $fh = fopen($filename, 'r'); - $timePattern = '/^(\d{4}-\d{2}\-\d{2}\s\d{1,2}\:\d{1,2}\:\d{1,2})\s(.*)/'; - - $out = array(); - $entry = ''; - $done = false; - - while (!feof($fh)) { - $line = fgets($fh); - if (preg_match($timePattern, $line, $matches)) { - if (strtotime($matches[1]) < $this->startTime) { - continue; - } - $out[] = $matches[1]; - $out[] = $matches[2]; - } elseif (count($out) - 1 > 0) { - $currentIndex = count($out) - 1; - while (!feof($fh)) { - $line = fgets($fh); - if (preg_match($timePattern, $line)) { - break; - } - $out[$currentIndex] .= $line; - } - } - } - fclose($fh); - return $out; - } -} - -?> \ No newline at end of file diff --git a/plugins/debug_kit/controllers/toolbar_access_controller.php b/plugins/debug_kit/controllers/toolbar_access_controller.php deleted file mode 100755 index bd566a0..0000000 --- a/plugins/debug_kit/controllers/toolbar_access_controller.php +++ /dev/null @@ -1,103 +0,0 @@ - array('output' => 'DebugKit.HtmlToolbar'), - 'Javascript', 'Number', 'DebugKit.SimpleGraph' - ); - -/** - * Components - * - * @var array - **/ - var $components = array('RequestHandler', 'DebugKit.Toolbar'); - -/** - * beforeFilter callback - * - * @return void - **/ - function beforeFilter() { - parent::beforeFilter(); - if (isset($this->Toolbar)) { - $this->Toolbar->enabled = false; - } - $this->helpers['DebugKit.Toolbar']['cacheKey'] = $this->Toolbar->cacheKey; - $this->helpers['DebugKit.Toolbar']['cacheConfig'] = 'debug_kit'; - } - -/** - * Get a stored history state from the toolbar cache. - * - * @return void - **/ - function history_state($key = null) { - if (Configure::read('debug') == 0) { - return $this->redirect($this->referer()); - } - $oldState = $this->Toolbar->loadState($key); - $this->set('toolbarState', $oldState); - $this->set('debugKitInHistoryMode', true); - } - -/** - * Run SQL explain/profiling on queries. Checks the hash + the hashed queries, - * if there is mismatch a 404 will be rendered. If debug == 0 a 404 will also be - * rendered. No explain will be run if a 404 is made. - * - * @return void - */ - function sql_explain() { - if ( - empty($this->params['named']['sql']) || - empty($this->params['named']['ds']) || - empty($this->params['named']['hash']) || - Configure::read('debug') == 0 - ) { - $this->cakeError('error404', array(array( - 'message' => 'Invalid parameters' - ))); - } - App::import('Core', 'Security'); - $hash = Security::hash($this->params['named']['sql'] . $this->params['named']['ds'], null, true); - if ($hash !== $this->params['named']['hash']) { - $this->cakeError('error404', array(array( - 'message' => 'Invalid parameters' - ))); - } - $result = $this->ToolbarAccess->explainQuery($this->params['named']['ds'], $this->params['named']['sql']); - $this->set(compact('result')); - } -} \ No newline at end of file diff --git a/plugins/debug_kit/debug_kit_app_controller.php b/plugins/debug_kit/debug_kit_app_controller.php deleted file mode 100755 index 3b369d8..0000000 --- a/plugins/debug_kit/debug_kit_app_controller.php +++ /dev/null @@ -1,23 +0,0 @@ - \ No newline at end of file diff --git a/plugins/debug_kit/debug_kit_app_model.php b/plugins/debug_kit/debug_kit_app_model.php deleted file mode 100755 index e065b3f..0000000 --- a/plugins/debug_kit/debug_kit_app_model.php +++ /dev/null @@ -1,23 +0,0 @@ - \ No newline at end of file diff --git a/plugins/debug_kit/locale/debug_kit.pot b/plugins/debug_kit/locale/debug_kit.pot deleted file mode 100755 index df4988d..0000000 --- a/plugins/debug_kit/locale/debug_kit.pot +++ /dev/null @@ -1,138 +0,0 @@ -# LANGUAGE translation of Debug Kit Application -# Copyright 2008 Andy Dawson -# No version information was available in the source files. -# -#, fuzzy -msgid "" -msgstr "" -"Project-Id-Version: debug_kit-\n" -"POT-Creation-Date: 2009-05-27 09:47+0200\n" -"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" -"Last-Translator: Andy Dawson \n" -"Language-Team:\n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=utf-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Poedit-Basepath: ../../../\n" - -#: controllers/components/toolbar.php:91 -msgid "Component initialization and startup" -msgstr "" - -#: controllers/components/toolbar.php:140 -msgid "Controller Action" -msgstr "" - -#: controllers/components/toolbar.php:167 -msgid "Render Controller Action" -msgstr "" - -#: controllers/components/toolbar.php:231 -msgid "Could not load DebugToolbar panel %s" -msgstr "" - -#: views/elements/debug_toolbar.ctp:25 -msgid "There are no active panels. You must enable a panel to see its output." -msgstr "" - -#: views/elements/history_panel.ctp:21 -msgid "Request History" -msgstr "" - -#: views/elements/history_panel.ctp:23 -msgid "No previous requests logged." -msgstr "" - -#: views/elements/history_panel.ctp:25 -msgid "previous requests available" -msgstr "" - -#: views/elements/history_panel.ctp:27 -msgid "Restore to current request" -msgstr "" - -#: views/elements/log_panel.ctp:21 -msgid "Logs" -msgstr "" - -#: views/elements/log_panel.ctp:28 -msgid "Time" -msgstr "" - -#: views/elements/log_panel.ctp:28 -#: views/elements/timer_panel.ctp:54 -msgid "Message" -msgstr "" - -#: views/elements/log_panel.ctp:37 -msgid "There were no log entries made this request" -msgstr "" - -#: views/elements/request_panel.ctp:21 -msgid "Request" -msgstr "" - -#: views/elements/request_panel.ctp:35 -msgid "Current Route" -msgstr "" - -#: views/elements/session_panel.ctp:21 -msgid "Session" -msgstr "" - -#: views/elements/sql_log_panel.ctp:21 -msgid "Sql Logs" -msgstr "" - -#: views/elements/sql_log_panel.ctp:31 -msgid "toggle (%s) query explains for %s" -msgstr "" - -#: views/elements/sql_log_panel.ctp:39 -msgid "No slow queries!, or your database does not support EXPLAIN" -msgstr "" - -#: views/elements/sql_log_panel.ctp:44 -msgid "No active database connections" -msgstr "" - -#: views/elements/timer_panel.ctp:33 -msgid "Memory" -msgstr "" - -#: views/elements/timer_panel.ctp:35 -msgid "Current Memory Use" -msgstr "" - -#: views/elements/timer_panel.ctp:39 -msgid "Peak Memory Use" -msgstr "" - -#: views/elements/timer_panel.ctp:43 -msgid "Timers" -msgstr "" - -#: views/elements/timer_panel.ctp:45 -msgid "%s (ms)" -msgstr "" - -#: views/elements/timer_panel.ctp:46 -msgid "Total Request Time:" -msgstr "" - -#: views/elements/timer_panel.ctp:54 -msgid "Time in ms" -msgstr "" - -#: views/elements/timer_panel.ctp:54 -msgid "Graph" -msgstr "" - -#: views/elements/variables_panel.ctp:21 -msgid "View Variables" -msgstr "" - -#: views/helpers/simple_graph.php:79 -msgid "Starting %sms into the request, taking %sms" -msgstr "" - diff --git a/plugins/debug_kit/locale/eng/LC_MESSAGES/debug_kit.po b/plugins/debug_kit/locale/eng/LC_MESSAGES/debug_kit.po deleted file mode 100755 index 9aec832..0000000 --- a/plugins/debug_kit/locale/eng/LC_MESSAGES/debug_kit.po +++ /dev/null @@ -1,135 +0,0 @@ -# LANGUAGE translation of CakePHP Application -# Copyright YEAR NAME -# No version information was available in the source files. -# -#, fuzzy -msgid "" -msgstr "Project-Id-Version: PROJECT VERSION\n" - "POT-Creation-Date: 2009-05-27 09:47+0200\n" - "PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" - "Last-Translator: NAME \n" - "Language-Team: LANGUAGE \n" - "MIME-Version: 1.0\n" - "Content-Type: text/plain; charset=UTF-8\n" - "Content-Transfer-Encoding: 8bit\n" - "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" - -#: controllers/components/toolbar.php:91 -msgid "Component initialization and startup" -msgstr "" - -#: controllers/components/toolbar.php:140 -msgid "Controller Action" -msgstr "" - -#: controllers/components/toolbar.php:167 -msgid "Render Controller Action" -msgstr "" - -#: controllers/components/toolbar.php:231 -msgid "Could not load DebugToolbar panel %s" -msgstr "" - -#: views/elements/debug_toolbar.ctp:25 -msgid "There are no active panels. You must enable a panel to see its output." -msgstr "" - -#: views/elements/history_panel.ctp:21 -msgid "Request History" -msgstr "" - -#: views/elements/history_panel.ctp:23 -msgid "No previous requests logged." -msgstr "" - -#: views/elements/history_panel.ctp:25 -msgid "previous requests available" -msgstr "" - -#: views/elements/history_panel.ctp:27 -msgid "Restore to current request" -msgstr "" - -#: views/elements/log_panel.ctp:21 -msgid "Logs" -msgstr "" - -#: views/elements/log_panel.ctp:28 -msgid "Time" -msgstr "" - -#: views/elements/log_panel.ctp:28 views/elements/timer_panel.ctp:54 -msgid "Message" -msgstr "" - -#: views/elements/log_panel.ctp:37 -msgid "There were no log entries made this request" -msgstr "" - -#: views/elements/request_panel.ctp:21 -msgid "Request" -msgstr "" - -#: views/elements/request_panel.ctp:35 -msgid "Current Route" -msgstr "" - -#: views/elements/session_panel.ctp:21 -msgid "Session" -msgstr "" - -#: views/elements/sql_log_panel.ctp:21 -msgid "Sql Logs" -msgstr "" - -#: views/elements/sql_log_panel.ctp:31 -msgid "toggle (%s) query explains for %s" -msgstr "" - -#: views/elements/sql_log_panel.ctp:39 -msgid "No slow queries!, or your database does not support EXPLAIN" -msgstr "" - -#: views/elements/sql_log_panel.ctp:44 -msgid "No active database connections" -msgstr "" - -#: views/elements/timer_panel.ctp:33 -msgid "Memory" -msgstr "" - -#: views/elements/timer_panel.ctp:35 -msgid "Current Memory Use" -msgstr "" - -#: views/elements/timer_panel.ctp:39 -msgid "Peak Memory Use" -msgstr "" - -#: views/elements/timer_panel.ctp:43 -msgid "Timers" -msgstr "" - -#: views/elements/timer_panel.ctp:45 -msgid "%s (ms)" -msgstr "" - -#: views/elements/timer_panel.ctp:46 -msgid "Total Request Time:" -msgstr "" - -#: views/elements/timer_panel.ctp:54 -msgid "Time in ms" -msgstr "" - -#: views/elements/timer_panel.ctp:54 -msgid "Graph" -msgstr "" - -#: views/elements/variables_panel.ctp:21 -msgid "View Variables" -msgstr "" - -#: views/helpers/simple_graph.php:79 -msgid "Starting %sms into the request, taking %sms" -msgstr "" diff --git a/plugins/debug_kit/locale/spa/LC_MESSAGES/debug_kit.po b/plugins/debug_kit/locale/spa/LC_MESSAGES/debug_kit.po deleted file mode 100755 index 0833a49..0000000 --- a/plugins/debug_kit/locale/spa/LC_MESSAGES/debug_kit.po +++ /dev/null @@ -1,135 +0,0 @@ -# LANGUAGE translation of CakePHP Application -# Copyright YEAR NAME -# No version information was available in the source files. -# -#, fuzzy -msgid "" -msgstr "Project-Id-Version: PROJECT VERSION\n" - "POT-Creation-Date: 2009-05-27 09:47+0200\n" - "PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n" - "Last-Translator: NAME \n" - "Language-Team: LANGUAGE \n" - "MIME-Version: 1.0\n" - "Content-Type: text/plain; charset=UTF-8\n" - "Content-Transfer-Encoding: 8bit\n" - "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" - -#: controllers/components/toolbar.php:91 -msgid "Component initialization and startup" -msgstr "" - -#: controllers/components/toolbar.php:140 -msgid "Controller Action" -msgstr "" - -#: controllers/components/toolbar.php:167 -msgid "Render Controller Action" -msgstr "" - -#: controllers/components/toolbar.php:231 -msgid "Could not load DebugToolbar panel %s" -msgstr "" - -#: views/elements/debug_toolbar.ctp:25 -msgid "There are no active panels. You must enable a panel to see its output." -msgstr "" - -#: views/elements/history_panel.ctp:21 -msgid "Request History" -msgstr "" - -#: views/elements/history_panel.ctp:23 -msgid "No previous requests logged." -msgstr "" - -#: views/elements/history_panel.ctp:25 -msgid "previous requests available" -msgstr "" - -#: views/elements/history_panel.ctp:27 -msgid "Restore to current request" -msgstr "" - -#: views/elements/log_panel.ctp:21 -msgid "Logs" -msgstr "" - -#: views/elements/log_panel.ctp:28 -msgid "Time" -msgstr "" - -#: views/elements/log_panel.ctp:28 views/elements/timer_panel.ctp:54 -msgid "Message" -msgstr "" - -#: views/elements/log_panel.ctp:37 -msgid "There were no log entries made this request" -msgstr "" - -#: views/elements/request_panel.ctp:21 -msgid "Request" -msgstr "" - -#: views/elements/request_panel.ctp:35 -msgid "Current Route" -msgstr "" - -#: views/elements/session_panel.ctp:21 -msgid "Session" -msgstr "" - -#: views/elements/sql_log_panel.ctp:21 -msgid "Sql Logs" -msgstr "" - -#: views/elements/sql_log_panel.ctp:31 -msgid "toggle (%s) query explains for %s" -msgstr "" - -#: views/elements/sql_log_panel.ctp:39 -msgid "No slow queries!, or your database does not support EXPLAIN" -msgstr "" - -#: views/elements/sql_log_panel.ctp:44 -msgid "No active database connections" -msgstr "" - -#: views/elements/timer_panel.ctp:33 -msgid "Memory" -msgstr "" - -#: views/elements/timer_panel.ctp:35 -msgid "Current Memory Use" -msgstr "" - -#: views/elements/timer_panel.ctp:39 -msgid "Peak Memory Use" -msgstr "" - -#: views/elements/timer_panel.ctp:43 -msgid "Timers" -msgstr "" - -#: views/elements/timer_panel.ctp:45 -msgid "%s (ms)" -msgstr "" - -#: views/elements/timer_panel.ctp:46 -msgid "Total Request Time:" -msgstr "" - -#: views/elements/timer_panel.ctp:54 -msgid "Time in ms" -msgstr "" - -#: views/elements/timer_panel.ctp:54 -msgid "Graph" -msgstr "" - -#: views/elements/variables_panel.ctp:21 -msgid "View Variables" -msgstr "" - -#: views/helpers/simple_graph.php:79 -msgid "Starting %sms into the request, taking %sms" -msgstr "" \ No newline at end of file diff --git a/plugins/debug_kit/models/behaviors/timed.php b/plugins/debug_kit/models/behaviors/timed.php deleted file mode 100755 index 9c5c960..0000000 --- a/plugins/debug_kit/models/behaviors/timed.php +++ /dev/null @@ -1,106 +0,0 @@ -settings[$Model->alias] = array_merge($this->_defaults, $settings); - } else { - $this->settings[$Model->alias] = $this->_defaults; - } - } - -/** - * beforeFind, starts a timer for a find operation. - * - * @param Model $Model - * @param array $queryData Array of query data (not modified) - * @return boolean true - */ - function beforeFind(&$Model, $queryData){ - DebugKitDebugger::startTimer($Model->alias . '_find', $Model->alias . '->find()'); - return true; - } - -/** - * afterFind, stops a timer for a find operation. - * - * @param Model $Model - * @param array $results Array of results - * @return boolean true. - */ - function afterFind(&$Model, $results){ - DebugKitDebugger::stopTimer($Model->alias . '_find'); - return true; - } - -/** - * beforeSave, starts a time before a save is initiated. - * - * @param Model $Model - * @return boolean true - */ - function beforeSave(&$Model){ - DebugKitDebugger::startTimer($Model->alias . '_save', $Model->alias . '->save()'); - return true; - } - -/** - * afterSave, stop the timer started from a save. - * - * @param string $Model - * @param string $created - * @return void - */ - function afterSave(&$Model, $created) { - DebugKitDebugger::stopTimer($Model->alias . '_save'); - return true; - } - } - -?> \ No newline at end of file diff --git a/plugins/debug_kit/models/toolbar_access.php b/plugins/debug_kit/models/toolbar_access.php deleted file mode 100755 index da1e23a..0000000 --- a/plugins/debug_kit/models/toolbar_access.php +++ /dev/null @@ -1,56 +0,0 @@ -config['driver']; - - $return = array(); - if ($driver === 'mysqli' || $driver === 'mysql' || $driver === 'postgres') { - $explained = $db->query('EXPLAIN ' . $query); - if ($driver === 'postgres') { - $queryPlan = array(); - foreach ($explained as $postgreValue) { - $queryPlan[] = array($postgreValue[0]['QUERY PLAN']); - } - $return = array_merge(array(array('')), $queryPlan); - } else { - $keys = array_keys($explained[0][0]); - foreach ($explained as $mysqlValue) { - $queryPlan[] = array_values($mysqlValue[0]); - } - $return = array_merge(array($keys), $queryPlan); - } - } - return $return; - } -} \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/behaviors/timed.test.php b/plugins/debug_kit/tests/cases/behaviors/timed.test.php deleted file mode 100755 index e0ad09d..0000000 --- a/plugins/debug_kit/tests/cases/behaviors/timed.test.php +++ /dev/null @@ -1,77 +0,0 @@ -Article =& new Model(array('ds' => 'test_suite', 'table' => 'Articles', 'name' => 'Article')); - $this->Article->Behaviors->attach('DebugKit.Timed'); - } - -/** - * end a test - * - * @return void - */ - function endTest() { - unset($this->Article); - ClassRegistry::flush(); - DebugKitDebugger::clearTimers(); - } - -/** - * test find timers - * - * @return void - */ - function testFindTimers() { - $timers = DebugKitDebugger::getTimers(false); - $this->assertEqual(count($timers), 1); - - $this->Article->find('all'); - $result = DebugKitDebugger::getTimers(false); - $this->assertEqual(count($result), 2); - - $this->Article->find('all'); - $result = DebugKitDebugger::getTimers(false); - $this->assertEqual(count($result), 3); - } - -/** - * test save timers - * - * @return void - */ - function testSaveTimers() { - $timers = DebugKitDebugger::getTimers(false); - $this->assertEqual(count($timers), 1); - - $this->Article->save(array('user_id' => 1, 'title' => 'test', 'body' => 'test')); - $result = DebugKitDebugger::getTimers(false); - $this->assertEqual(count($result), 2); - } -} \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/controllers/components/toolbar.test.php b/plugins/debug_kit/tests/cases/controllers/components/toolbar.test.php deleted file mode 100755 index 01f49b1..0000000 --- a/plugins/debug_kit/tests/cases/controllers/components/toolbar.test.php +++ /dev/null @@ -1,552 +0,0 @@ -_loadPanels($panels, $settings); - } - - function _eval($code) { - if ($this->evalTest) { - $this->evalCode = $code; - return; - } - eval($code); - } -} - -Mock::generate('DebugPanel'); - -if (!class_exists('AppController')) { - class AppController extends Controller { - - } -} - -class TestPanel extends DebugPanel { - -} - -/** -* DebugToolbar Test case -*/ -class DebugToolbarTestCase extends CakeTestCase { -/** - * fixtures. - * - * @var array - **/ - var $fixtures = array('core.article'); -/** - * Start test callback - * - * @access public - * @return void - **/ - function startTest() { - Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); - $this->Controller =& new Controller(); - $this->Controller->params = Router::parse('/'); - $this->Controller->params['url']['url'] = '/'; - $this->Controller->uses = array(); - $this->Controller->components = array('TestToolBar'); - $this->Controller->constructClasses(); - $this->Controller->Toolbar =& $this->Controller->TestToolBar; - - $this->_server = $_SERVER; - $this->_paths = array(); - $this->_paths['plugins'] = App::path('plugins'); - $this->_paths['views'] = App::path('views'); - $this->_paths['vendors'] = App::path('vendors'); - $this->_paths['controllers'] = App::path('controllers'); - Configure::write('Cache.disable', false); - } -/** - * endTest - * - * @return void - **/ - function endTest() { - $_SERVER = $this->_server; - App::build(array( - 'plugins' => $this->_paths['plugins'], - 'views' => $this->_paths['views'], - 'controllers' => $this->_paths['controllers'], - 'vendors' => $this->_paths['vendors'] - ), true); - Configure::write('Cache.disable', true); - - unset($this->Controller); - if (class_exists('DebugKitDebugger')) { - DebugKitDebugger::clearTimers(); - DebugKitDebugger::clearMemoryPoints(); - } - } -/** - * test Loading of panel classes - * - * @return void - **/ - function testLoadPanels() { - $this->Controller->Toolbar->loadPanels(array('session', 'request')); - $this->assertTrue(is_a($this->Controller->Toolbar->panels['session'], 'SessionPanel')); - $this->assertTrue(is_a($this->Controller->Toolbar->panels['request'], 'RequestPanel')); - - $this->Controller->Toolbar->loadPanels(array('history'), array('history' => 10)); - $this->assertEqual($this->Controller->Toolbar->panels['history']->history, 10); - - $this->expectError(); - $this->Controller->Toolbar->loadPanels(array('randomNonExisting', 'request')); - } -/** - * test Loading of panel classes from a plugin - * - * @return void - **/ - function testLoadPluginPanels() { - $this->Controller->Toolbar->loadPanels(array('plugin.test')); - $this->assertTrue(is_a($this->Controller->Toolbar->panels['plugin.test'], 'TestPanel')); - } -/** - * test generating a DoppelGangerView with a pluginView. - * - * @return void - **/ - function testPluginViewParsing() { - App::import('Vendor', 'DebugKit.DebugKitDebugger'); - $this->Controller->Toolbar->evalTest = true; - $this->Controller->view = 'Plugin.OtherView'; - $this->Controller->Toolbar->startup($this->Controller); - $this->assertPattern('/class DoppelGangerView extends OtherView/', $this->Controller->Toolbar->evalCode); - } -/** - * test loading of vendor panels from test_app folder - * - * @access public - * @return void - */ - function testVendorPanels() { - $debugKitPath = App::pluginPath('DebugKit'); - $noDir = (empty($debugKitPath) || !file_exists($debugKitPath)); - $skip = $this->skipIf($noDir, 'Could not find debug_kit in plugin paths, skipping %s'); - if ($skip) { - return; - } - - App::build(array( - 'vendors' => array($debugKitPath . 'tests' . DS . 'test_app' . DS . 'vendors' . DS) - )); - $this->Controller->components = array( - 'DebugKit.Toolbar' => array( - 'panels' => array('test'), - ) - ); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Component->startup($this->Controller); - $this->assertTrue(isset($this->Controller->Toolbar->panels['test'])); - $this->assertTrue(is_a($this->Controller->Toolbar->panels['test'], 'TestPanel')); - } -/** - * test initialize - * - * @return void - * @access public - **/ - function testInitialize() { - $this->Controller->components = array('DebugKit.Toolbar'); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - - $this->assertFalse(empty($this->Controller->Toolbar->panels)); - - $timers = DebugKitDebugger::getTimers(); - $this->assertTrue(isset($timers['componentInit'])); - $memory = DebugKitDebugger::getMemoryPoints(); - $this->assertTrue(isset($memory['Component intitailization'])); - } -/** - * test initialize w/ custom panels and defaults - * - * @return void - * @access public - **/ - function testInitializeCustomPanelsWithDefaults() { - $this->Controller->components = array( - 'DebugKit.Toolbar' => array('panels' => array('test')) - ); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - - $expected = array('history', 'session', 'request', 'sqlLog', 'timer', 'log', 'variables', 'test'); - $this->assertEqual($expected, array_keys($this->Controller->Toolbar->panels)); - } -/** - * test syntax for removing panels - * - * @return void - **/ - function testInitializeRemovingPanels() { - $this->Controller->components = array( - 'DebugKit.Toolbar' => array('panels' => array('session' => false, 'history' => false, 'test')) - ); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - - $expected = array('request', 'sqlLog', 'timer', 'log', 'variables', 'test'); - $this->assertEqual($expected, array_keys($this->Controller->Toolbar->panels)); - } -/** - * ensure that enabled = false when debug == 0 on initialize - * - * @return void - **/ - function testDebugDisableOnInitialize() { - $_debug = Configure::read('debug'); - Configure::write('debug', 0); - $this->Controller->components = array('DebugKit.Toolbar'); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->assertFalse($this->Controller->Toolbar->enabled); - - Configure::write('debug', $_debug); - } -/** - * test that passing in forceEnable will enable the toolbar even if debug = 0 - * - * @return void - **/ - function testForceEnable() { - $_debug = Configure::read('debug'); - Configure::write('debug', 0); - $this->Controller->components = array('DebugKit.Toolbar' => array('forceEnable' => true)); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->assertTrue($this->Controller->Toolbar->enabled); - - Configure::write('debug', $_debug); - } -/** - * Test disabling autoRunning of toolbar - * - * @return void - **/ - function testAutoRunSettingFalse() { - $this->Controller->components = array('DebugKit.Toolbar' => array('autoRun' => false)); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->assertFalse($this->Controller->Toolbar->enabled); - } -/** - * test autorun = false with query string param - * - * @return void - **/ - function testAutoRunSettingWithQueryString() { - $this->Controller->params['url']['debug'] = true; - $this->Controller->components = array('DebugKit.Toolbar' => array('autoRun' => false)); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->assertTrue($this->Controller->Toolbar->enabled); - } -/** - * test startup - * - * @return void - **/ - function testStartup() { - $this->Controller->components = array( - 'DebugKit.Toolbar' => array( - 'panels' => array('MockDebug') - ) - ); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Toolbar->panels['MockDebug']->expectOnce('startup'); - $this->Controller->Toolbar->startup($this->Controller); - - $this->assertEqual($this->Controller->view, 'DebugKit.Debug'); - $this->assertTrue(isset($this->Controller->helpers['DebugKit.Toolbar'])); - - $this->assertEqual($this->Controller->helpers['DebugKit.Toolbar']['output'], 'DebugKit.HtmlToolbar'); - $this->assertEqual($this->Controller->helpers['DebugKit.Toolbar']['cacheConfig'], 'debug_kit'); - $this->assertTrue(isset($this->Controller->helpers['DebugKit.Toolbar']['cacheKey'])); - - $timers = DebugKitDebugger::getTimers(); - $this->assertTrue(isset($timers['controllerAction'])); - $memory = DebugKitDebugger::getMemoryPoints(); - $this->assertTrue(isset($memory['Controller action start'])); - } -/** - * Test that cache config generation works. - * - * @return void - **/ - function testCacheConfigGeneration() { - $this->Controller->components = array('DebugKit.Toolbar'); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Component->startup($this->Controller); - - $results = Cache::config('debug_kit'); - $this->assertTrue(is_array($results)); - } -/** - * test state saving of toolbar - * - * @return void - **/ - function testStateSaving() { - $this->Controller->components = array('DebugKit.Toolbar'); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $configName = 'debug_kit'; - $this->Controller->Toolbar->cacheKey = 'toolbar_history'; - - $this->Controller->Component->startup($this->Controller); - $this->Controller->set('test', 'testing'); - $this->Controller->Component->beforeRender($this->Controller); - - $result = Cache::read('toolbar_history', $configName); - $this->assertEqual($result[0]['variables']['content']['test'], 'testing'); - Cache::delete('toolbar_history', $configName); - } -/** - * Test Before Render callback - * - * @return void - **/ - function testBeforeRender() { - $this->Controller->components = array( - 'DebugKit.Toolbar' => array( - 'panels' => array('MockDebug', 'session') - ) - ); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Toolbar->panels['MockDebug']->expectOnce('beforeRender'); - $this->Controller->Toolbar->beforeRender($this->Controller); - - $this->assertTrue(isset($this->Controller->viewVars['debugToolbarPanels'])); - $vars = $this->Controller->viewVars['debugToolbarPanels']; - - $expected = array( - 'plugin' => 'debug_kit', - 'elementName' => 'session_panel', - 'content' => $this->Controller->Toolbar->Session->read(), - 'disableTimer' => true, - 'title' => '' - ); - $this->assertEqual($expected, $vars['session']); - - $memory = DebugKitDebugger::getMemoryPoints(); - $this->assertTrue(isset($memory['Controller render start'])); - } -/** - * test that vars are gathered and state is saved on beforeRedirect - * - * @return void - **/ - function testBeforeRedirect() { - $this->Controller->components = array( - 'DebugKit.Toolbar' => array( - 'panels' => array('MockDebug', 'session', 'history') - ) - ); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - - $configName = 'debug_kit'; - $this->Controller->Toolbar->cacheKey = 'toolbar_history'; - Cache::delete('toolbar_history', $configName); - - DebugKitDebugger::startTimer('controllerAction', 'testing beforeRedirect'); - $this->Controller->Toolbar->panels['MockDebug']->expectOnce('beforeRender'); - $this->Controller->Toolbar->beforeRedirect($this->Controller); - - $result = Cache::read('toolbar_history', $configName); - $this->assertTrue(isset($result[0]['session'])); - $this->assertTrue(isset($result[0]['mock_debug'])); - - $timers = DebugKitDebugger::getTimers(); - $this->assertTrue(isset($timers['controllerAction'])); - } -/** - * test that loading state (accessing cache) works. - * - * @return void - **/ - function testLoadState() { - $this->Controller->Toolbar->cacheKey = 'toolbar_history'; - - $data = array(0 => array('my data')); - Cache::write('toolbar_history', $data, 'debug_kit'); - $result = $this->Controller->Toolbar->loadState(0); - $this->assertEqual($result, $data[0]); - } -/** - * test the Log panel log reading. - * - * @return void - **/ - function testLogPanel() { - sleep(1); - $this->Controller->log('This is a log I made this request'); - $this->Controller->log('This is the second log I made this request'); - $this->Controller->log('This time in the debug log!', LOG_DEBUG); - - $this->Controller->components = array( - 'DebugKit.Toolbar' => array( - 'panels' => array('log', 'session', 'history' => false, 'variables' => false, 'sqlLog' => false, - 'timer' => false) - ) - ); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Component->startup($this->Controller); - $this->Controller->Component->beforeRender($this->Controller); - $result = $this->Controller->viewVars['debugToolbarPanels']['log']; - - $this->assertEqual(count($result['content']), 2); - $this->assertEqual(count($result['content']['error.log']), 4); - $this->assertEqual(count($result['content']['debug.log']), 2); - - $this->assertEqual(trim($result['content']['debug.log'][1]), 'Debug: This time in the debug log!'); - $this->assertEqual(trim($result['content']['error.log'][1]), 'Error: This is a log I made this request'); - - $data = array( - 'Post' => array( - 'id' => 1, - 'title' => 'post!', - 'body' => 'some text here', - 'created' => '2009-11-07 23:23:23' - ), - 'Comment' => array( - 'id' => 23 - ) - ); - $this->Controller->log($data); - $this->Controller->Component->beforeRender($this->Controller); - $result = $this->Controller->viewVars['debugToolbarPanels']['log']; - $this->assertPattern('/\[created\] => 2009-11-07 23:23:23/', $result['content']['error.log'][5]); - $this->assertPattern('/\[Comment\] => Array/', $result['content']['error.log'][5]); - } -/** - * Test that history state urls set prefix = null and admin = null so generated urls do not - * adopt these params. - * - * @return void - **/ - function testHistoryUrlGenerationWithPrefixes() { - $configName = 'debug_kit'; - $this->Controller->params = array( - 'controller' => 'posts', - 'action' => 'edit', - 'admin' => 1, - 'prefix' => 'admin', - 'plugin' => 'cms', - 'url' => array( - 'url' => '/admin/cms/posts/edit/' - ) - ); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Toolbar->cacheKey = 'url_test'; - $this->Controller->Component->beforeRender($this->Controller); - - $result = $this->Controller->Toolbar->panels['history']->beforeRender($this->Controller); - $expected = array( - 'plugin' => 'debug_kit', 'controller' => 'toolbar_access', 'action' => 'history_state', - 0 => 1, 'admin' => false - ); - $this->assertEqual($result[0]['url'], $expected); - Cache::delete('url_test', $configName); - } -/** - * Test that the FireCake toolbar is used on AJAX requests - * - * @return void - **/ - function testAjaxToolbar() { - $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; - $this->Controller->components = array('DebugKit.Toolbar'); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Component->startup($this->Controller); - $this->assertEqual($this->Controller->helpers['DebugKit.Toolbar']['output'], 'DebugKit.FirePhpToolbar'); - } -/** - * Test that the toolbar does not interfere with requestAction - * - * @return void - **/ - function testNoRequestActionInterference() { - $debugKitPath = App::pluginPath('DebugKit'); - $noDir = (empty($debugKitPath) || !file_exists($debugKitPath)); - $skip = $this->skipIf($noDir, 'Could not find debug_kit in plugin paths, skipping %s'); - if ($skip) { - return; - } - - App::build(array( - 'controllers' => $debugKitPath . 'tests' . DS . 'test_app' . DS . 'controllers' . DS, - 'views' => array( - $debugKitPath . 'tests' . DS . 'test_app' . DS . 'views' . DS, - CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'libs' . DS . 'view' . DS - ), - 'plugins' => $this->_paths['plugins'] - )); - Router::reload(); - - $result = $this->Controller->requestAction('/debug_kit_test/request_action_return', array('return')); - $this->assertEqual($result, 'I am some value from requestAction.'); - - $result = $this->Controller->requestAction('/debug_kit_test/request_action_render', array('return')); - $this->assertEqual($result, 'I have been rendered.'); - } -/** - * test the sqlLog panel parsing of db->showLog - * - * @return void - **/ - function testSqlLogPanel() { - App::import('Core', 'Model'); - $Article =& new Model(array('ds' => 'test_suite', 'name' => 'Article')); - $Article->find('first', array('conditions' => array('Article.id' => 1))); - - $this->Controller->components = array( - 'DebugKit.Toolbar' => array( - 'panels' => array('SqlLog') - ) - ); - $this->Controller->Component->init($this->Controller); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Component->startup($this->Controller); - $this->Controller->Component->beforeRender($this->Controller); - $result = $this->Controller->viewVars['debugToolbarPanels']['sql_log']; - - $this->assertTrue(isset($result['content']['connections']['test_suite'])); - $this->assertTrue(isset($result['content']['threshold'])); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/models/toolbar_access.test.php b/plugins/debug_kit/tests/cases/models/toolbar_access.test.php deleted file mode 100755 index 0be5eb4..0000000 --- a/plugins/debug_kit/tests/cases/models/toolbar_access.test.php +++ /dev/null @@ -1,66 +0,0 @@ -Model =& new ToolbarAccess(); - } - -/** - * endTest - * - * @return void - */ - function endTest() { - unset($this->Model); - } - -/** - * test that explain query returns arrays of query information. - * - * @return void - */ - function testExplainQuery() { - $db =& ConnectionManager::getDataSource('test_suite'); - $sql = 'SELECT * FROM ' . $db->fullTableName('posts') . ';'; - $result = $this->Model->explainQuery('test_suite', $sql); - - $this->assertTrue(is_array($result)); - $this->assertFalse(empty($result)); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/test_objects.php b/plugins/debug_kit/tests/cases/test_objects.php deleted file mode 100755 index 714b161..0000000 --- a/plugins/debug_kit/tests/cases/test_objects.php +++ /dev/null @@ -1,53 +0,0 @@ -sentHeaders[$name] = $value; - } -/** - * skip client detection as headers are not being sent. - * - * @access public - * @return void - */ - function detectClientExtension() { - return true; - } -/** - * Reset the fireCake - * - * @return void - **/ - function reset() { - $_this =& FireCake::getInstance(); - $_this->sentHeaders = array(); - $_this->_messageIndex = 1; - } -} - -?> diff --git a/plugins/debug_kit/tests/cases/vendors/debug_kit_debugger.test.php b/plugins/debug_kit/tests/cases/vendors/debug_kit_debugger.test.php deleted file mode 100755 index 39783c4..0000000 --- a/plugins/debug_kit/tests/cases/vendors/debug_kit_debugger.test.php +++ /dev/null @@ -1,233 +0,0 @@ -assertTrue(DebugKitDebugger::startTimer('test1', 'this is my first test')); - usleep(5000); - $this->assertTrue(DebugKitDebugger::stopTimer('test1')); - $elapsed = DebugKitDebugger::elapsedTime('test1'); - $this->assertTrue($elapsed > 0.0050); - - $this->assertTrue(DebugKitDebugger::startTimer('test2', 'this is my second test')); - sleep(1); - $this->assertTrue(DebugKitDebugger::stopTimer('test2')); - $elapsed = DebugKitDebugger::elapsedTime('test2'); - $this->assertTrue($elapsed > 1); - - DebugKitDebugger::startTimer('test3'); - $this->assertFalse(DebugKitDebugger::elapsedTime('test3')); - $this->assertFalse(DebugKitDebugger::stopTimer('wrong')); - } -/** - * test timers with no names. - * - * @return void - **/ - function testAnonymousTimers() { - $this->assertTrue(DebugKitDebugger::startTimer()); - usleep(2000); - $this->assertTrue(DebugKitDebugger::stopTimer()); - $timers = DebugKitDebugger::getTimers(); - - $this->assertEqual(count($timers), 2); - end($timers); - $key = key($timers); - $lineNo = __LINE__ - 8; - - $file = Debugger::trimPath(__FILE__); - $expected = $file . ' line ' . $lineNo; - $this->assertEqual($key, $expected); - - $timer = $timers[$expected]; - $this->assertTrue($timer['time'] > 0.0020); - $this->assertEqual($timers[$expected]['message'], $expected); - } -/** - * Assert that nested anonymous timers don't get mixed up. - * - * @return void - **/ - function testNestedAnonymousTimers() { - $this->assertTrue(DebugKitDebugger::startTimer()); - usleep(100); - $this->assertTrue(DebugKitDebugger::startTimer()); - usleep(100); - $this->assertTrue(DebugKitDebugger::stopTimer()); - $this->assertTrue(DebugKitDebugger::stopTimer()); - - $timers = DebugKitDebugger::getTimers(); - $this->assertEqual(count($timers), 3, 'incorrect number of timers %s'); - $firstTimerLine = __LINE__ -9; - $secondTimerLine = __LINE__ -8; - $file = Debugger::trimPath(__FILE__); - - $this->assertTrue(isset($timers[$file . ' line ' . $firstTimerLine]), 'first timer is not set %s'); - $this->assertTrue(isset($timers[$file . ' line ' . $secondTimerLine]), 'second timer is not set %s'); - - $firstTimer = $timers[$file . ' line ' . $firstTimerLine]; - $secondTimer = $timers[$file . ' line ' . $secondTimerLine]; - $this->assertTrue($firstTimer['time'] > $secondTimer['time']); - } -/** - * test that calling startTimer with the same name does not overwrite previous timers - * and instead adds new ones. - * - * @return void - **/ - function testRepeatTimers() { - DebugKitDebugger::startTimer('my timer', 'This is the first call'); - usleep(100); - DebugKitDebugger::startTimer('my timer', 'This is the second call'); - usleep(100); - - DebugKitDebugger::stopTimer('my timer'); - DebugKitDebugger::stopTimer('my timer'); - - $timers = DebugKitDebugger::getTimers(); - $this->assertEqual(count($timers), 3, 'wrong timer count %s'); - - $this->assertTrue(isset($timers['my timer'])); - $this->assertTrue(isset($timers['my timer #2'])); - - $this->assertTrue($timers['my timer']['time'] > $timers['my timer #2']['time'], 'timer 2 is longer? %s'); - $this->assertEqual($timers['my timer']['message'], 'This is the first call'); - $this->assertEqual($timers['my timer #2']['message'], 'This is the second call #2'); - } -/** - * testRequestTime - * - * @access public - * @return void - */ - function testRequestTime() { - $result1 = DebugKitDebugger::requestTime(); - usleep(50); - $result2 = DebugKitDebugger::requestTime(); - $this->assertTrue($result1 < $result2); - } -/** - * test getting all the set timers. - * - * @return void - **/ - function testGetTimers() { - DebugKitDebugger::startTimer('test1', 'this is my first test'); - DebugKitDebugger::stopTimer('test1'); - usleep(50); - DebugKitDebugger::startTimer('test2'); - DebugKitDebugger::stopTimer('test2'); - $timers = DebugKitDebugger::getTimers(); - - $this->assertEqual(count($timers), 3); - $this->assertTrue(is_float($timers['test1']['time'])); - $this->assertTrue(isset($timers['test1']['message'])); - $this->assertTrue(isset($timers['test2']['message'])); - } -/** - * test memory usage - * - * @return void - **/ - function testMemoryUsage() { - $result = DebugKitDebugger::getMemoryUse(); - $this->assertTrue(is_int($result)); - - $result = DebugKitDebugger::getPeakMemoryUse(); - $this->assertTrue(is_int($result)); - } -/** - * test _output switch to firePHP - * - * @return void - */ - function testOutput() { - $firecake =& FireCake::getInstance('TestFireCake'); - Debugger::invoke(DebugKitDebugger::getInstance('DebugKitDebugger')); - Debugger::output('fb'); - $foo .= ''; - $result = $firecake->sentHeaders; - - $this->assertPattern('/GROUP_START/', $result['X-Wf-1-1-1-1']); - $this->assertPattern('/ERROR/', $result['X-Wf-1-1-1-2']); - $this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-5']); - - Debugger::invoke(Debugger::getInstance('Debugger')); - Debugger::output(); - } -/** - * test making memory use markers. - * - * @return void - **/ - function testMemorySettingAndGetting() { - $result = DebugKitDebugger::setMemoryPoint('test marker'); - $this->assertTrue($result); - - $result = DebugKitDebugger::getMemoryPoints(true); - $this->assertEqual(count($result), 1); - $this->assertTrue(isset($result['test marker'])); - $this->assertTrue(is_numeric($result['test marker'])); - - $result = DebugKitDebugger::getMemoryPoints(); - $this->assertTrue(empty($result)); - - DebugKitDebugger::setMemoryPoint('test marker'); - DebugKitDebugger::setMemoryPoint('test marker'); - $result = DebugKitDebugger::getMemoryPoints(); - $this->assertEqual(count($result), 2); - $this->assertTrue(isset($result['test marker'])); - $this->assertTrue(isset($result['test marker #2'])); - } - -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/vendors/fire_cake.test.php b/plugins/debug_kit/tests/cases/vendors/fire_cake.test.php deleted file mode 100755 index 4429973..0000000 --- a/plugins/debug_kit/tests/cases/vendors/fire_cake.test.php +++ /dev/null @@ -1,341 +0,0 @@ -firecake =& FireCake::getInstance('TestFireCake'); - } -/** - * test getInstance cheat. - * - * If this fails the rest of the test is going to fail too. - * - * @return void - **/ - function testGetInstanceOverride() { - $instance =& FireCake::getInstance(); - $instance2 =& FireCake::getInstance(); - $this->assertReference($instance, $instance2); - $this->assertIsA($instance, 'FireCake'); - $this->assertIsA($instance, 'TestFireCake', 'Stored instance is not a copy of TestFireCake, test case is broken.'); - } -/** - * testsetoption - * - * @return void - **/ - function testSetOptions() { - FireCake::setOptions(array('includeLineNumbers' => false)); - $this->assertEqual($this->firecake->options['includeLineNumbers'], false); - } -/** - * test Log() - * - * @access public - * @return void - */ - function testLog() { - FireCake::setOptions(array('includeLineNumbers' => false)); - FireCake::log('Testing'); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1'])); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 1); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '26|[{"Type":"LOG"},"Testing"]|'); - - FireCake::log('Testing', 'log-info'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '45|[{"Type":"LOG","Label":"log-info"},"Testing"]|'); - } -/** - * test info() - * - * @access public - * @return void - */ - function testInfo() { - FireCake::setOptions(array('includeLineNumbers' => false)); - FireCake::info('I have information'); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1'])); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 1); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '38|[{"Type":"INFO"},"I have information"]|'); - - FireCake::info('I have information', 'info-label'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '59|[{"Type":"INFO","Label":"info-label"},"I have information"]|'); - } -/** - * test info() - * - * @access public - * @return void - */ - function testWarn() { - FireCake::setOptions(array('includeLineNumbers' => false)); - FireCake::warn('A Warning'); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1'])); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 1); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '29|[{"Type":"WARN"},"A Warning"]|'); - - FireCake::warn('A Warning', 'Bzzz'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '44|[{"Type":"WARN","Label":"Bzzz"},"A Warning"]|'); - } -/** - * test error() - * - * @access public - * @return void - **/ - function testError() { - FireCake::setOptions(array('includeLineNumbers' => false)); - FireCake::error('An error'); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1'])); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 1); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '29|[{"Type":"ERROR"},"An error"]|'); - - FireCake::error('An error', 'wonky'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '45|[{"Type":"ERROR","Label":"wonky"},"An error"]|'); - } -/** - * test dump() - * - * @return void - **/ - function testDump() { - FireCake::dump('mydump', array('one' => 1, 'two' => 2)); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-2-1-1'], '28|{"mydump":{"one":1,"two":2}}|'); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-2'])); - } -/** - * test table() generation - * - * @return void - **/ - function testTable() { - $table[] = array('Col 1 Heading','Col 2 Heading'); - $table[] = array('Row 1 Col 1','Row 1 Col 2'); - $table[] = array('Row 2 Col 1','Row 2 Col 2'); - $table[] = array('Row 3 Col 1','Row 3 Col 2'); - FireCake::table('myTrace', $table); - $expected = '162|[{"Type":"TABLE","Label":"myTrace"},[["Col 1 Heading","Col 2 Heading"],["Row 1 Col 1","Row 1 Col 2"],["Row 2 Col 1","Row 2 Col 2"],["Row 3 Col 1","Row 3 Col 2"]]]|'; - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], $expected); - } -/** - * testStringEncoding - * - * @return void - **/ - function testStringEncode() { - $vars = array(1,2,3); - $result = $this->firecake->stringEncode($vars); - $this->assertEqual($result, array(1,2,3)); - - $this->firecake->setOptions(array('maxArrayDepth' => 3)); - $deep = array(1 => array(2 => array(3))); - $result = $this->firecake->stringEncode($deep); - $this->assertEqual($result, array(1 => array(2 => '** Max Array Depth (3) **'))); - } -/** - * test object encoding - * - * @return void - **/ - function testStringEncodeObjects() { - $obj =& FireCake::getInstance(); - $result = $this->firecake->stringEncode($obj); - - $this->assertTrue(is_array($result)); - $this->assertEqual($result['_defaultOptions']['useNativeJsonEncode'], true); - $this->assertEqual($result['_encodedObjects'][0], '** Recursion (TestFireCake) **'); - } -/** - * test trace() - * - * @return void - **/ - function testTrace() { - FireCake::trace('myTrace'); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-Protocol-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Plugin-1'])); - $this->assertTrue(isset($this->firecake->sentHeaders['X-Wf-1-Structure-1'])); - $dump = $this->firecake->sentHeaders['X-Wf-1-1-1-1']; - $this->assertPattern('/"Message":"myTrace"/', $dump); - $this->assertPattern('/"Trace":\[/', $dump); - } -/** - * test enabling and disabling of FireCake output - * - * @return void - **/ - function testEnableDisable() { - FireCake::disable(); - FireCake::trace('myTrace'); - $this->assertTrue(empty($this->firecake->sentHeaders)); - - FireCake::enable(); - FireCake::trace('myTrace'); - $this->assertFalse(empty($this->firecake->sentHeaders)); - } - -/** - * test correct line continuation markers on multi line headers. - * - * @access public - * @return void - */ - function testMultiLineOutput() { - $skip = $this->skipIf(!PHP5, 'Output is not long enough with PHP4'); - if ($skip) { - return; - } - FireCake::trace('myTrace'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 4); - $header = $this->firecake->sentHeaders['X-Wf-1-1-1-1']; - $this->assertEqual(substr($header, -2), '|\\'); - - $header = $this->firecake->sentHeaders['X-Wf-1-1-1-2']; - $this->assertEqual(substr($header, -2), '|\\'); - - $header = $this->firecake->sentHeaders['X-Wf-1-1-1-3']; - $this->assertEqual(substr($header, -2), '|\\'); - - $header = $this->firecake->sentHeaders['X-Wf-1-1-1-4']; - $this->assertEqual(substr($header, -1), '|'); - } -/** - * test inclusion of line numbers - * - * @return void - **/ - function testIncludeLineNumbers() { - FireCake::setOptions(array('includeLineNumbers' => true)); - FireCake::info('Testing'); - $result = $this->firecake->sentHeaders['X-Wf-1-1-1-1']; - $this->assertPattern('/"File"\:".*fire_cake.test.php/', $result); - $this->assertPattern('/"Line"\:\d+/', $result); - } -/** - * test Group messages - * - * @return void - **/ - function testGroup() { - FireCake::setOptions(array('includeLineNumbers' => false)); - FireCake::group('test'); - FireCake::info('my info'); - FireCake::groupEnd(); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '63|[{"Collapsed":"true","Type":"GROUP_START","Label":"test"},null]|'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-3'], '27|[{"Type":"GROUP_END"},null]|'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 3); - } -/** - * test fb() parameter parsing - * - * @return void - **/ - function testFbParameterParsing() { - FireCake::setOptions(array('includeLineNumbers' => false)); - FireCake::fb('Test'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '23|[{"Type":"LOG"},"Test"]|'); - - FireCake::fb('Test', 'warn'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-2'], '24|[{"Type":"WARN"},"Test"]|'); - - FireCake::fb('Test', 'Custom label', 'warn'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-3'], '47|[{"Type":"WARN","Label":"Custom label"},"Test"]|'); - - $this->expectError(); - $this->assertFalse(FireCake::fb('Test', 'Custom label', 'warn', 'more parameters')); - - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-Index'], 3); - } -/** - * Test defaulting to log if incorrect message type is used - * - * @return void - **/ - function testIncorrectMessageType() { - FireCake::setOptions(array('includeLineNumbers' => false)); - FireCake::fb('Hello World', 'foobared'); - $this->assertEqual($this->firecake->sentHeaders['X-Wf-1-1-1-1'], '30|[{"Type":"LOG"},"Hello World"]|'); - } -/** - * testClientExtensionDetection. - * - * @return void - **/ - function testDetectClientExtension() { - $back = env('HTTP_USER_AGENT'); - $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4 FirePHP/0.2.1'; - $this->assertTrue(FireCake::detectClientExtension()); - - $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4 FirePHP/0.0.4'; - $this->assertFalse(FireCake::detectClientExtension()); - - $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4'; - $this->assertFalse(FireCake::detectClientExtension()); - $_SERVER['HTTP_USER_AGENT'] = $back; - } -/** - * test of Non Native JSON encoding. - * - * @return void - **/ - function testNonNativeEncoding() { - FireCake::setOptions(array('useNativeJsonEncode' => false)); - $json = FireCake::jsonEncode(array('one' => 1, 'two' => 2)); - $this->assertEqual($json, '{"one":1,"two":2}'); - - $json = FireCake::jsonEncode(array(1,2,3)); - $this->assertEqual($json, '[1,2,3]'); - - $json = FireCake::jsonEncode(FireCake::getInstance()); - $this->assertPattern('/"options"\:\{"maxObjectDepth"\:\d*,/', $json); - } -/** - * reset the FireCake counters and headers. - * - * @access public - * @return void - */ - function tearDown() { - TestFireCake::reset(); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/views/debug.test.php b/plugins/debug_kit/tests/cases/views/debug.test.php deleted file mode 100755 index 3f09ca8..0000000 --- a/plugins/debug_kit/tests/cases/views/debug.test.php +++ /dev/null @@ -1,157 +0,0 @@ - 'pages', 'action' => 'display', 'home')); - Router::parse('/'); - $this->Controller =& ClassRegistry::init('Controller'); - $this->View =& new DebugView($this->Controller, false); - $this->_debug = Configure::read('debug'); - $this->_paths = array(); - $this->_paths['plugins'] = App::path('plugins'); - $this->_paths['views'] = App::path('views'); - $this->_paths['vendors'] = App::path('vendors'); - $this->_paths['controllers'] = App::path('controllers'); - } -/** - * tear down function - * - * @return void - **/ - function endTest() { - App::build(array( - 'plugins' => $this->_paths['plugins'], - 'views' => $this->_paths['views'], - 'vendors' => $this->_paths['vendors'], - 'controllers' => $this->_paths['controllers'] - )); - - unset($this->View, $this->Controller); - DebugKitDebugger::clearTimers(); - Configure::write('debug', $this->_debug); - } -/** - * start Case - switch view paths - * - * @return void - **/ - function startCase() { - App::build(array( - 'views' => array( - TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, - APP . 'plugins' . DS . 'debug_kit' . DS . 'views'. DS, - ROOT . DS . LIBS . 'view' . DS - ) - ), true); - } -/** - * test that element timers are working - * - * @return void - **/ - function testElementTimers() { - $result = $this->View->element('test_element'); - $this->assertPattern('/^this is the test element$/', $result); - - $result = DebugKitDebugger::getTimers(); - $this->assertTrue(isset($result['render_test_element.ctp'])); - } -/** - * test rendering and ensure that timers are being set. - * - * @access public - * @return void - */ - function testRenderTimers() { - $this->Controller->viewPath = 'posts'; - $this->Controller->action = 'index'; - $this->Controller->params = array( - 'action' => 'index', - 'controller' => 'posts', - 'plugin' => null, - 'url' => array('url' => 'posts/index'), - 'base' => null, - 'here' => '/posts/index', - ); - $this->Controller->layout = 'default'; - $View =& new DebugView($this->Controller, false); - $View->render('index'); - - $result = DebugKitDebugger::getTimers(); - $this->assertEqual(count($result), 4); - $this->assertTrue(isset($result['viewRender'])); - $this->assertTrue(isset($result['render_default.ctp'])); - $this->assertTrue(isset($result['render_index.ctp'])); - - $result = DebugKitDebugger::getMemoryPoints(); - $this->assertTrue(isset($result['View render complete'])); - } -/** - * Test for correct loading of helpers into custom view - * - * @return void - */ - function testLoadHelpers() { - $loaded = array(); - $result = $this->View->_loadHelpers($loaded, array('Html', 'Javascript', 'Number')); - $this->assertTrue(is_object($result['Html'])); - $this->assertTrue(is_object($result['Javascript'])); - $this->assertTrue(is_object($result['Number'])); - } -/** - * test that $out is returned when a layout is rendered instead of the empty - * $this->output. As this causes issues with requestAction() - * - * @return void - **/ - function testProperReturnUnderRequestAction() { - $plugins = App::path('plugins'); - $views = App::path('views'); - $testapp = $plugins[1] . 'debug_kit' . DS . 'tests' . DS . 'test_app' . DS . 'views' . DS; - array_unshift($views, $testapp); - App::build(array('views' => $views), true); - - $this->View->set('test', 'I have been rendered.'); - $this->View->viewPath = 'debug_kit_test'; - $this->View->layout = false; - $result = $this->View->render('request_action_render'); - - $this->assertEqual($result, 'I have been rendered.'); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/views/helpers/fire_php_toolbar.test.php b/plugins/debug_kit/tests/cases/views/helpers/fire_php_toolbar.test.php deleted file mode 100755 index dee6874..0000000 --- a/plugins/debug_kit/tests/cases/views/helpers/fire_php_toolbar.test.php +++ /dev/null @@ -1,147 +0,0 @@ - 'pages', 'action' => 'display', 'home')); - Router::parse('/'); - - $this->Toolbar =& new ToolbarHelper(array('output' => 'DebugKit.FirePhpToolbar')); - $this->Toolbar->FirePhpToolbar =& new FirePhpToolbarHelper(); - - $this->Controller =& ClassRegistry::init('Controller'); - if (isset($this->_debug)) { - Configure::write('debug', $this->_debug); - } - } -/** - * start Case - switch view paths - * - * @return void - **/ - function startCase() { - $this->_viewPaths = Configure::read('viewPaths'); - Configure::write('viewPaths', array( - TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, - APP . 'plugins' . DS . 'debug_kit' . DS . 'views'. DS, - ROOT . DS . LIBS . 'view' . DS - )); - $this->_debug = Configure::read('debug'); - $this->firecake =& FireCake::getInstance(); - } -/** - * test neat array (dump)creation - * - * @return void - */ - function testMakeNeatArray() { - $this->Toolbar->makeNeatArray(array(1,2,3)); - $result = $this->firecake->sentHeaders; - $this->assertTrue(isset($result['X-Wf-1-1-1-1'])); - $this->assertPattern('/\[1,2,3\]/', $result['X-Wf-1-1-1-1']); - } -/** - * testAfterlayout element rendering - * - * @return void - */ - function testAfterLayout(){ - $this->Controller->viewPath = 'posts'; - $this->Controller->action = 'index'; - $this->Controller->params = array( - 'action' => 'index', - 'controller' => 'posts', - 'plugin' => null, - 'url' => array('url' => 'posts/index', 'ext' => 'xml'), - 'base' => null, - 'here' => '/posts/index', - ); - $this->Controller->layout = 'default'; - $this->Controller->uses = null; - $this->Controller->components = array('DebugKit.Toolbar'); - $this->Controller->constructClasses(); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Component->startup($this->Controller); - $this->Controller->Component->beforeRender($this->Controller); - $result = $this->Controller->render(); - $this->assertNoPattern('/debug-toolbar/', $result); - $result = $this->firecake->sentHeaders; - $this->assertTrue(is_array($result)); - } -/** - * test starting a panel - * - * @return void - **/ - function testPanelStart() { - $this->Toolbar->panelStart('My Panel', 'my_panel'); - $result = $this->firecake->sentHeaders; - $this->assertPattern('/GROUP_START.+My Panel/', $result['X-Wf-1-1-1-1']); - } -/** - * test ending a panel - * - * @return void - **/ - function testPanelEnd() { - $this->Toolbar->panelEnd(); - $result = $this->firecake->sentHeaders; - $this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-1']); - } -/** - * endTest() - * - * @return void - */ - function endTest() { - TestFireCake::reset(); - } -/** - * reset the view paths - * - * @return void - **/ - function endCase() { - Configure::write('viewPaths', $this->_viewPaths); - } -/** - * tearDown - * - * @access public - * @return void - */ - function tearDown() { - unset($this->Toolbar, $this->Controller); - ClassRegistry::removeObject('view'); - ClassRegistry::flush(); - Router::reload(); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/views/helpers/html_toolbar.test.php b/plugins/debug_kit/tests/cases/views/helpers/html_toolbar.test.php deleted file mode 100755 index 01c2e4f..0000000 --- a/plugins/debug_kit/tests/cases/views/helpers/html_toolbar.test.php +++ /dev/null @@ -1,352 +0,0 @@ - 'pages', 'action' => 'display', 'home')); - Router::parse('/'); - - $this->Toolbar =& new ToolbarHelper(array('output' => 'DebugKit.HtmlToolbar')); - $this->Toolbar->HtmlToolbar =& new HtmlToolbarHelper(); - $this->Toolbar->HtmlToolbar->Html =& new HtmlHelper(); - $this->Toolbar->HtmlToolbar->Javascript =& new JavascriptHelper(); - - $this->Controller =& ClassRegistry::init('Controller'); - if (isset($this->_debug)) { - Configure::write('debug', $this->_debug); - } - } -/** - * start Case - switch view paths - * - * @return void - **/ - function startCase() { - $this->_viewPaths = Configure::read('viewPaths'); - Configure::write('viewPaths', array( - TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, - APP . 'plugins' . DS . 'debug_kit' . DS . 'views'. DS, - ROOT . DS . LIBS . 'view' . DS - )); - $this->_debug = Configure::read('debug'); - } -/** - * test Neat Array formatting - * - * @return void - **/ - function testMakeNeatArray() { - $in = false; - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - 'assertTags($result, $expected); - - $in = null; - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - 'assertTags($result, $expected); - - $in = true; - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - 'assertTags($result, $expected); - - $in = array(); - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - 'assertTags($result, $expected); - - $in = array('key' => 'value'); - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - 'assertTags($result, $expected); - - $in = array('key' => null); - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - 'assertTags($result, $expected); - - $in = array('key' => 'value', 'foo' => 'bar'); - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - 'assertTags($result, $expected); - - $in = array( - 'key' => 'value', - 'foo' => array( - 'this' => 'deep', - 'another' => 'value' - ) - ); - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - ' array('class' => 'neat-array depth-1')), - 'assertTags($result, $expected); - - $in = array( - 'key' => 'value', - 'foo' => array( - 'this' => 'deep', - 'another' => 'value' - ), - 'lotr' => array( - 'gandalf' => 'wizard', - 'bilbo' => 'hobbit' - ) - ); - $result = $this->Toolbar->makeNeatArray($in, 1); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0 expanded'), - ' array('class' => 'neat-array depth-1')), - ' array('class' => 'neat-array depth-1')), - 'assertTags($result, $expected); - - $result = $this->Toolbar->makeNeatArray($in, 2); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0 expanded'), - ' array('class' => 'neat-array depth-1 expanded')), - ' array('class' => 'neat-array depth-1 expanded')), - 'assertTags($result, $expected); - - $in = array('key' => 'value', 'array' => array()); - $result = $this->Toolbar->makeNeatArray($in); - $expected = array( - 'ul' => array('class' => 'neat-array depth-0'), - 'assertTags($result, $expected); - } - -/** - * Test injection of toolbar - * - * @return void - **/ - function testInjectToolbar() { - $this->Controller->viewPath = 'posts'; - $this->Controller->action = 'index'; - $this->Controller->params = array( - 'action' => 'index', - 'controller' => 'posts', - 'plugin' => null, - 'url' => array('url' => 'posts/index'), - 'base' => null, - 'here' => '/posts/index', - ); - $this->Controller->helpers = array('Html', 'Javascript', 'DebugKit.Toolbar'); - $this->Controller->layout = 'default'; - $this->Controller->uses = null; - $this->Controller->components = array('DebugKit.Toolbar'); - $this->Controller->constructClasses(); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Component->startup($this->Controller); - $this->Controller->Component->beforeRender($this->Controller); - $result = $this->Controller->render(); - $result = str_replace(array("\n", "\r"), '', $result); - $this->assertPattern('#
.+
#', $result); - } - -/** - * test injection of javascript - * - * @return void - **/ - function testJavascriptInjection() { - $this->Controller->viewPath = 'posts'; - $this->Controller->uses = null; - $this->Controller->action = 'index'; - $this->Controller->params = array( - 'action' => 'index', - 'controller' => 'posts', - 'plugin' => null, - 'url' => array('url' => 'posts/index'), - 'base' => '/', - 'here' => '/posts/index', - ); - $this->Controller->helpers = array('Javascript', 'Html'); - $this->Controller->components = array('DebugKit.Toolbar'); - $this->Controller->layout = 'default'; - $this->Controller->constructClasses(); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->Component->startup($this->Controller); - $this->Controller->Component->beforeRender($this->Controller); - $result = $this->Controller->render(); - $result = str_replace(array("\n", "\r"), '', $result); - $this->assertPattern('#\s?#', $result); - } - -/** - * test message creation - * - * @return void - */ - function testMessage() { - $result = $this->Toolbar->message('test', 'one, two'); - $expected = array( - 'assertTags($result, $expected); - } -/** - * Test Table generation - * - * @return void - */ - function testTable() { - $rows = array( - array(1,2), - array(3,4), - ); - $result = $this->Toolbar->table($rows); - $expected = array( - 'table' => array('class' =>'debug-table'), - array('tr' => array('class' => 'odd')), - ' array('class' => 'even')), - 'assertTags($result, $expected); - } -/** - * test starting a panel - * - * @return void - **/ - function testStartPanel() { - $result = $this->Toolbar->panelStart('My Panel', 'my_panel'); - $expected = array( - 'a' => array('href' => '#my_panel'), - 'My Panel', - '/a' - ); - $this->assertTags($result, $expected); - } -/** - * test ending a panel - * - * @return void - **/ - function testPanelEnd() { - $result = $this->Toolbar->panelEnd(); - $this->assertNull($result); - } -/** - * reset the view paths - * - * @return void - **/ - function endCase() { - Configure::write('viewPaths', $this->_viewPaths); - } - -/** - * tearDown - * - * @access public - * @return void - */ - function tearDown() { - unset($this->Toolbar, $this->Controller); - ClassRegistry::removeObject('view'); - ClassRegistry::flush(); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/cases/views/helpers/toolbar.test.php b/plugins/debug_kit/tests/cases/views/helpers/toolbar.test.php deleted file mode 100755 index 1e15848..0000000 --- a/plugins/debug_kit/tests/cases/views/helpers/toolbar.test.php +++ /dev/null @@ -1,170 +0,0 @@ - 'pages', 'action' => 'display', 'home')); - Router::parse('/'); - - $this->Toolbar =& new ToolbarHelper(array( - 'output' => 'MockBackendHelper', - 'cacheKey' => 'debug_kit_toolbar_test_case', - 'cacheConfig' => 'default' - )); - $this->Toolbar->MockBackend = new MockBackendHelper(); - - $this->Controller =& ClassRegistry::init('Controller'); - if (isset($this->_debug)) { - Configure::write('debug', $this->_debug); - } - } -/** - * start Case - switch view paths - * - * @return void - **/ - function startCase() { - $this->_viewPaths = Configure::read('viewPaths'); - Configure::write('viewPaths', array( - TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, - APP . 'plugins' . DS . 'debug_kit' . DS . 'views'. DS, - ROOT . DS . LIBS . 'view' . DS - )); - $this->_debug = Configure::read('debug'); - } -/** - * test cache writing for views. - * - * @return void - **/ - function testCacheWrite() { - $result = $this->Toolbar->writeCache('test', array('stuff', 'to', 'cache')); - $this->assertTrue($result); - } -/** - * Ensure that the cache writing only affects the - * top most level of the history stack. As this is where the current request is stored. - * - * @return void - **/ - function testOnlyWritingToFirstElement() { - $values = array( - array('test' => array('content' => array('first', 'values'))), - array('test' => array('content' => array('second', 'values'))), - ); - Cache::write('debug_kit_toolbar_test_case', $values, 'default'); - $this->Toolbar->writeCache('test', array('new', 'values')); - - $result = $this->Toolbar->readCache('test'); - $this->assertEqual($result, array('new', 'values')); - - $result = $this->Toolbar->readCache('test', 1); - $this->assertEqual($result, array('second', 'values')); - } -/** - * test cache reading for views - * - * @return void - **/ - function testCacheRead() { - $result = $this->Toolbar->writeCache('test', array('stuff', 'to', 'cache')); - $this->assertTrue($result, 'Cache write failed %s'); - - $result = $this->Toolbar->readCache('test'); - $this->assertEqual($result, array('stuff', 'to', 'cache'), 'Cache value is wrong %s'); - - $result = $this->Toolbar->writeCache('test', array('new', 'stuff')); - $this->assertTrue($result, 'Cache write failed %s'); - - $result = $this->Toolbar->readCache('test'); - $this->assertEqual($result, array('new', 'stuff'), 'Cache value is wrong %s'); - } -/** - * Test that reading/writing doesn't work with no cache config. - * - * @return void - **/ - function testNoCacheConfigPresent() { - $this->Toolbar = new ToolbarHelper(array('output' => 'MockBackendHelper')); - - $result = $this->Toolbar->writeCache('test', array('stuff', 'to', 'cache')); - $this->assertFalse($result, 'Writing to cache succeeded with no cache config %s'); - - $result = $this->Toolbar->readCache('test'); - $this->assertFalse($result, 'Reading cache succeeded with no cache config %s'); - } -/** - * ensure that getQueryLogs works and writes to the cache so the history panel will - * work. - * - * @return void - */ - function testGetQueryLogs() { - $model =& new Model(array('ds' => 'test_suite', 'table' => 'posts')); - $model->find('all'); - $model->find('first'); - - $result = $this->Toolbar->getQueryLogs('test_suite', array('cache' => false)); - $this->assertTrue(is_array($result)); - $this->assertTrue(count($result) >= 2, 'Should be more than 2 queries in the log %s'); - $this->assertTrue(isset($result[0]['actions'])); - - Cache::delete('debug_kit_toolbar_test_case', 'default'); - $this->Toolbar->getQueryLogs('test_suite', array('cache' => true)); - - $cached = $this->Toolbar->readCache('sql_log'); - $this->assertTrue(isset($cached['test_suite'])); - $this->assertEqual($cached['test_suite'][0], $result[0]); - - } -/** - * reset the view paths - * - * @return void - **/ - function endCase() { - Configure::write('viewPaths', $this->_viewPaths); - Cache::delete('debug_kit_toolbar_test_case', 'default'); - } -/** - * endTest - * - * @access public - * @return void - */ - function endTest() { - unset($this->Toolbar, $this->Controller); - ClassRegistry::removeObject('view'); - ClassRegistry::flush(); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/groups/view_group.group.php b/plugins/debug_kit/tests/groups/view_group.group.php deleted file mode 100755 index 4434089..0000000 --- a/plugins/debug_kit/tests/groups/view_group.group.php +++ /dev/null @@ -1,45 +0,0 @@ - \ No newline at end of file diff --git a/plugins/debug_kit/tests/test_app/controllers/debug_kit_test_controller.php b/plugins/debug_kit/tests/test_app/controllers/debug_kit_test_controller.php deleted file mode 100755 index 52e3ec3..0000000 --- a/plugins/debug_kit/tests/test_app/controllers/debug_kit_test_controller.php +++ /dev/null @@ -1,36 +0,0 @@ -autoRender = false; - return 'I am some value from requestAction.'; - } - - function request_action_render() { - $this->set('test', 'I have been rendered.'); - } - -} \ No newline at end of file diff --git a/plugins/debug_kit/tests/test_app/vendors/test_panel.php b/plugins/debug_kit/tests/test_app/vendors/test_panel.php deleted file mode 100755 index 5a111ed..0000000 --- a/plugins/debug_kit/tests/test_app/vendors/test_panel.php +++ /dev/null @@ -1,25 +0,0 @@ -testPanel = true; - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/tests/test_app/views/debug_kit_test/request_action_render.ctp b/plugins/debug_kit/tests/test_app/views/debug_kit_test/request_action_render.ctp deleted file mode 100755 index 172d541..0000000 --- a/plugins/debug_kit/tests/test_app/views/debug_kit_test/request_action_render.ctp +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/plugins/debug_kit/vendors/debug_kit_debugger.php b/plugins/debug_kit/vendors/debug_kit_debugger.php deleted file mode 100755 index b0132d4..0000000 --- a/plugins/debug_kit/vendors/debug_kit_debugger.php +++ /dev/null @@ -1,401 +0,0 @@ -__benchmarks) { - return; - } - $timers = array_values(DebugKitDebugger::getTimers()); - $end = end($timers); - echo ''; - echo ''; - echo ''; - $i = 0; - foreach ($timers as $timer) { - $indent = 0; - for ($j = 0; $j < $i; $j++) { - if (($timers[$j]['end']) > ($timer['start']) && ($timers[$j]['end']) > ($timer['end'])) { - $indent++; - } - } - $indent = str_repeat(' » ', $indent); - - extract($timer); - $start = round($start * 1000, 0); - $end = round($end * 1000, 0); - $time = round($time * 1000, 0); - echo ""; - $i++; - } - echo '
Debug timer info
MessageStart Time (ms)End Time (ms)Duration (ms)
{$indent}$message$start$end$time
'; - } -/** - * Start an benchmarking timer. - * - * @param string $name The name of the timer to start. - * @param string $message A message for your timer - * @return bool true - * @static - **/ - function startTimer($name = null, $message = null) { - $start = getMicrotime(); - $_this =& DebugKitDebugger::getInstance(); - - if (!$name) { - $named = false; - $calledFrom = debug_backtrace(); - $_name = $name = Debugger::trimpath($calledFrom[0]['file']) . ' line ' . $calledFrom[0]['line']; - } else { - $named = true; - } - - if (!$message) { - $message = $name; - } - - $_name = $name; - $i = 1; - while (isset($_this->__benchmarks[$name])) { - $i++; - $name = $_name . ' #' . $i; - } - - if ($i > 1) { - $message .= ' #' . $i; - } - - $_this->__benchmarks[$name] = array( - 'start' => $start, - 'message' => $message, - 'named' => $named - ); - return true; - } -/** - * Stop a benchmarking timer. - * - * $name should be the same as the $name used in startTimer(). - * - * @param string $name The name of the timer to end. - * @access public - * @return boolean true if timer was ended, false if timer was not started. - * @static - */ - function stopTimer($name = null) { - $end = getMicrotime(); - $_this =& DebugKitDebugger::getInstance(); - if (!$name) { - $names = array_reverse(array_keys($_this->__benchmarks)); - foreach($names as $name) { - if (!empty($_this->__benchmarks[$name]['end'])) { - continue; - } - if (empty($_this->__benchmarks[$name]['named'])) { - break; - } - } - } else { - $i = 1; - $_name = $name; - while (isset($_this->__benchmarks[$name])) { - if (empty($_this->__benchmarks[$name]['end'])) { - break; - } - $i++; - $name = $_name . ' #' . $i; - } - } - if (!isset($_this->__benchmarks[$name])) { - return false; - } - $_this->__benchmarks[$name]['end'] = $end; - return true; - } -/** - * Get all timers that have been started and stopped. - * Calculates elapsed time for each timer. If clear is true, will delete existing timers - * - * @param bool $clear false - * @return array - * @access public - **/ - function getTimers($clear = false) { - $_this =& DebugKitDebugger::getInstance(); - $start = DebugKitDebugger::requestStartTime(); - $now = getMicrotime(); - - $times = array(); - if (!empty($_this->__benchmarks)) { - $firstTimer = current($_this->__benchmarks); - $_end = $firstTimer['start']; - } else { - $_end = $now; - } - $times['Core Processing (Derived)'] = array( - 'message' => __d('debug_kit', 'Core Processing (Derived)', true), - 'start' => 0, - 'end' => $_end - $start, - 'time' => round($_end - $start, 6), - 'named' => null - ); - foreach ($_this->__benchmarks as $name => $timer) { - if (!isset($timer['end'])) { - $timer['end'] = $now; - } - $times[$name] = array_merge($timer, array( - 'start' => $timer['start'] - $start, - 'end' => $timer['end'] - $start, - 'time' => DebugKitDebugger::elapsedTime($name) - )); - } - if ($clear) { - $_this->__benchmarks = array(); - } - return $times; - } -/** - * Clear all existing timers - * - * @return bool true - **/ - function clearTimers() { - $_this =& DebugKitDebugger::getInstance(); - $_this->__benchmarks = array(); - return true; - } -/** - * Get the difference in time between the timer start and timer end. - * - * @param $name string the name of the timer you want elapsed time for. - * @param $precision int the number of decimal places to return, defaults to 5. - * @return float number of seconds elapsed for timer name, 0 on missing key - * @static - **/ - function elapsedTime($name = 'default', $precision = 5) { - $_this =& DebugKitDebugger::getInstance(); - if (!isset($_this->__benchmarks[$name]['start']) || !isset($_this->__benchmarks[$name]['end'])) { - return 0; - } - return round($_this->__benchmarks[$name]['end'] - $_this->__benchmarks[$name]['start'], $precision); - } -/** - * Get the total execution time until this point - * - * @access public - * @return float elapsed time in seconds since script start. - * @static - */ - function requestTime() { - $start = DebugKitDebugger::requestStartTime(); - $now = getMicroTime(); - return ($now - $start); - } -/** - * get the time the current request started. - * - * @access public - * @return float time of request start - * @static - */ - function requestStartTime() { - if (defined('TIME_START')) { - $startTime = TIME_START; - } else if (isset($GLOBALS['TIME_START'])) { - $startTime = $GLOBALS['TIME_START']; - } else { - $startTime = env('REQUEST_TIME'); - } - return $startTime; - } -/** - * get current memory usage - * - * @return integer number of bytes ram currently in use. 0 if memory_get_usage() is not available. - * @static - **/ - function getMemoryUse() { - if (!function_exists('memory_get_usage')) { - return 0; - } - return memory_get_usage(); - } -/** - * Get peak memory use - * - * @return integer peak memory use (in bytes). Returns 0 if memory_get_peak_usage() is not available - * @static - **/ - function getPeakMemoryUse() { - if (!function_exists('memory_get_peak_usage')) { - return 0; - } - return memory_get_peak_usage(); - } -/** - * Stores a memory point in the internal tracker. - * Takes a optional message name which can be used to identify the memory point. - * If no message is supplied a debug_backtrace will be done to identifty the memory point. - * If you don't have memory_get_xx methods this will not work. - * - * @param string $message Message to identify this memory point. - * @return boolean - **/ - function setMemoryPoint($message = null) { - $memoryUse = DebugKitDebugger::getMemoryUse(); - if (!$message) { - $named = false; - $trace = debug_backtrace(); - $message = Debugger::trimpath($trace[0]['file']) . ' line ' . $trace[0]['line']; - } - $self =& DebugKitDebugger::getInstance(); - if (isset($self->__memoryPoints[$message])) { - $originalMessage = $message; - $i = 1; - while (isset($self->__memoryPoints[$message])) { - $i++; - $message = $originalMessage . ' #' . $i; - } - } - $self->__memoryPoints[$message] = $memoryUse; - return true; - } -/** - * Get all the stored memory points - * - * @param boolean $clear Whether you want to clear the memory points as well. Defaults to false. - * @return array Array of memory marks stored so far. - **/ - function getMemoryPoints($clear = false) { - $self =& DebugKitDebugger::getInstance(); - $marks = $self->__memoryPoints; - if ($clear) { - $self->__memoryPoints = array(); - } - return $marks; - } -/** - * Clear out any existing memory points - * - * @return void - **/ - function clearMemoryPoints() { - $self =& DebugKitDebugger::getInstance(); - $self->__memoryPoints = array(); - } -/** - * Handles object conversion to debug string. - * - * @param string $var Object to convert - * @access protected - */ - function _output($data = array()) { - extract($data); - if (is_array($level)) { - $error = $level['error']; - $code = $level['code']; - if (isset($level['helpID'])) { - $helpID = $level['helpID']; - } else { - $helpID = ''; - } - $description = $level['description']; - $file = $level['file']; - $line = $level['line']; - $context = $level['context']; - $level = $level['level']; - } - $files = $this->trace(array('start' => 2, 'format' => 'points')); - $listing = $this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1); - $trace = $this->trace(array('start' => 2, 'depth' => '20')); - - if ($this->_outputFormat == 'fb') { - $kontext = array(); - foreach ((array)$context as $var => $value) { - $kontext[] = "\${$var}\t=\t" . $this->exportVar($value, 1); - } - $this->_fireError($error, $code, $description, $file, $line, $trace, $kontext); - } else { - $data = compact( - 'level', 'error', 'code', 'helpID', 'description', 'file', 'path', 'line', 'context' - ); - echo parent::_output($data); - } - } -/** - * Create a FirePHP error message - * - * @param string $error Name of error - * @param string $code Code of error - * @param string $description Description of error - * @param string $file File error occured in - * @param string $line Line error occured on - * @param string $trace Stack trace at time of error - * @param string $context context of error - * @return void - * @access protected - */ - function _fireError($error, $code, $description, $file, $line, $trace, $context) { - $name = $error . ' - ' . $description; - $message = "$error $code $description on line: $line in file: $file"; - FireCake::group($name); - FireCake::error($message, $name); - FireCake::log($context, 'Context'); - FireCake::log($trace, 'Trace'); - FireCake::groupEnd(); - } -} - - -Debugger::invoke(DebugKitDebugger::getInstance('DebugKitDebugger')); -Debugger::getInstance('DebugKitDebugger'); -?> \ No newline at end of file diff --git a/plugins/debug_kit/vendors/fire_cake.php b/plugins/debug_kit/vendors/fire_cake.php deleted file mode 100755 index d3faaaa..0000000 --- a/plugins/debug_kit/vendors/fire_cake.php +++ /dev/null @@ -1,547 +0,0 @@ - 10, - 'maxArrayDepth' => 20, - 'useNativeJsonEncode' => true, - 'includeLineNumbers' => true, - ); -/** - * Message Levels for messages sent via FirePHP - * - * @var array - */ - var $_levels = array( - 'log' => 'LOG', - 'info' => 'INFO', - 'warn' => 'WARN', - 'error' => 'ERROR', - 'dump' => 'DUMP', - 'trace' => 'TRACE', - 'exception' => 'EXCEPTION', - 'table' => 'TABLE', - 'groupStart' => 'GROUP_START', - 'groupEnd' => 'GROUP_END', - ); - - var $_version = '0.2.1'; -/** - * internal messageIndex counter - * - * @var int - * @access protected - */ - var $_messageIndex = 1; -/** - * stack of objects encoded by stringEncode() - * - * @var array - **/ - var $_encodedObjects = array(); -/** - * methodIndex to include in tracebacks when using includeLineNumbers - * - * @var array - **/ - var $_methodIndex = array('info', 'log', 'warn', 'error', 'table', 'trace'); -/** - * FireCake output status - * - * @var bool - **/ - var $_enabled = true; -/** - * get Instance of the singleton - * - * @param string $class Class instance to store in the singleton. Used with subclasses and Tests. - * @access public - * @static - * @return void - */ - function &getInstance($class = null) { - static $instance = array(); - if (!empty($class)) { - if (!$instance || strtolower($class) != strtolower(get_class($instance[0]))) { - $instance[0] =& new $class(); - $instance[0]->setOptions(); - } - } - if (!isset($instance[0]) || !$instance[0]) { - $instance[0] =& new FireCake(); - $instance[0]->setOptions(); - } - return $instance[0]; - } -/** - * setOptions - * - * @param array $options Array of options to set. - * @access public - * @static - * @return void - */ - function setOptions($options = array()) { - $_this =& FireCake::getInstance(); - if (empty($_this->options)) { - $_this->options = array_merge($_this->_defaultOptions, $options); - } else { - $_this->options = array_merge($_this->options, $options); - } - } -/** - * Return boolean based on presence of FirePHP extension - * - * @access public - * @return boolean - **/ - function detectClientExtension() { - $ua = FireCake::getUserAgent(); - if (!preg_match('/\sFirePHP\/([\.|\d]*)\s?/si', $ua, $match) || !version_compare($match[1], '0.0.6', '>=')) { - return false; - } - return true; - } -/** - * Get the Current UserAgent - * - * @access public - * @static - * @return string UserAgent string of active client connection - **/ - function getUserAgent() { - return env('HTTP_USER_AGENT'); - } -/** - * Disable FireCake output - * All subsequent output calls will not be run. - * - * @return void - **/ - function disable() { - $_this =& FireCake::getInstance(); - $_this->_enabled = false; - } -/** - * Enable FireCake output - * - * @return void - **/ - function enable() { - $_this =& FireCake::getInstance(); - $_this->_enabled = true; - } -/** - * Convenience wrapper for LOG messages - * - * @param string $message Message to log - * @param string $label Label for message (optional) - * @access public - * @static - * @return void - */ - function log($message, $label = null) { - FireCake::fb($message, $label, 'log'); - } -/** - * Convenience wrapper for WARN messages - * - * @param string $message Message to log - * @param string $label Label for message (optional) - * @access public - * @static - * @return void - */ - function warn($message, $label = null) { - FireCake::fb($message, $label, 'warn'); - } -/** - * Convenience wrapper for INFO messages - * - * @param string $message Message to log - * @param string $label Label for message (optional) - * @access public - * @static - * @return void - */ - function info($message, $label = null) { - FireCake::fb($message, $label, 'info'); - } -/** - * Convenience wrapper for ERROR messages - * - * @param string $message Message to log - * @param string $label Label for message (optional) - * @access public - * @static - * @return void - */ - function error($message, $label = null) { - FireCake::fb($message, $label, 'error'); - } -/** - * Convenience wrapper for TABLE messages - * - * @param string $message Message to log - * @param string $label Label for message (optional) - * @access public - * @static - * @return void - */ - function table($label, $message) { - FireCake::fb($message, $label, 'table'); - } -/** - * Convenience wrapper for DUMP messages - * - * @param string $message Message to log - * @param string $label Unique label for message - * @access public - * @static - * @return void - */ - function dump($label, $message) { - FireCake::fb($message, $label, 'dump'); - } -/** - * Convenience wrapper for TRACE messages - * - * @param string $label Label for message (optional) - * @access public - * @return void - */ - function trace($label) { - FireCake::fb($label, 'trace'); - } -/** - * Convenience wrapper for GROUP messages - * Messages following the group call will be nested in a group block - * - * @param string $label Label for group (optional) - * @access public - * @return void - */ - function group($label) { - FireCake::fb(null, $label, 'groupStart'); - } -/** - * Convenience wrapper for GROUPEND messages - * Closes a group block - * - * @param string $label Label for group (optional) - * @access public - * @return void - */ - function groupEnd() { - FireCake::fb(null, null, 'groupEnd'); - } -/** - * fb - Send messages with FireCake to FirePHP - * - * Much like FirePHP's fb() this method can be called with various parameter counts - * fb($message) - Just send a message defaults to LOG type - * fb($message, $type) - Send a message with a specific type - * fb($message, $label, $type) - Send a message with a custom label and type. - * - * @param mixed $message Message to output. For other parameters see usage above. - * @static - * @return void - **/ - function fb($message) { - $_this =& FireCake::getInstance(); - - if (headers_sent($filename, $linenum)) { - trigger_error(sprintf(__d('debug_kit', 'Headers already sent in %s on line %s. Cannot send log data to FirePHP.', true), $filename, $linenum), E_USER_WARNING); - return false; - } - if (!$_this->_enabled || !$_this->detectClientExtension()) { - return false; - } - - $args = func_get_args(); - $type = $label = null; - switch (count($args)) { - case 1: - $type = $_this->_levels['log']; - break; - case 2: - $type = $args[1]; - break; - case 3: - $type = $args[2]; - $label = $args[1]; - break; - default: - trigger_error(__d('debug_kit', 'Incorrect parameter count for FireCake::fb()', true), E_USER_WARNING); - return false; - } - if (isset($_this->_levels[$type])) { - $type = $_this->_levels[$type]; - } else { - $type = $_this->_levels['log']; - } - - $meta = array(); - $skipFinalObjectEncode = false; - if ($type == $_this->_levels['trace']) { - $trace = debug_backtrace(); - if (!$trace) { - return false; - } - $message = $_this->_parseTrace($trace, $args[0]); - $skipFinalObjectEncode = true; - } - - if ($_this->options['includeLineNumbers']) { - if (!isset($meta['file']) || !isset($meta['line'])) { - $trace = debug_backtrace(); - for ($i = 0, $len = count($trace); $i < $len ; $i++) { - $keySet = (isset($trace[$i]['class']) && isset($trace[$i]['function'])); - $selfCall = ($keySet && - strtolower($trace[$i]['class']) == 'firecake' && - in_array($trace[$i]['function'], $_this->_methodIndex) - ); - if ($selfCall) { - $meta['File'] = isset($trace[$i]['file']) ? Debugger::trimPath($trace[$i]['file']) : ''; - $meta['Line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; - break; - } - } - } - } - - $structureIndex = 1; - if ($type == $_this->_levels['dump']) { - $structureIndex = 2; - $_this->_sendHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); - } else { - $_this->_sendHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); - } - - $_this->_sendHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); - $_this->_sendHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'. $_this->_version); - if ($type == $_this->_levels['groupStart']) { - $meta['Collapsed'] = 'true'; - } - if ($type == $_this->_levels['dump']) { - $dump = $_this->jsonEncode($message); - $msg = '{"' . $label .'":' . $dump .'}'; - } else { - $meta['Type'] = $type; - if ($label !== null) { - $meta['Label'] = $label; - } - $msg = '[' . $_this->jsonEncode($meta) . ',' . $_this->jsonEncode($message, $skipFinalObjectEncode).']'; - } - - $lines = explode("\n", chunk_split($msg, 5000, "\n")); - - foreach ($lines as $i => $line) { - if (empty($line)) { - continue; - } - $header = 'X-Wf-1-' . $structureIndex . '-1-' . $_this->_messageIndex; - if (count($lines) > 2) { - $first = ($i == 0) ? strlen($msg) : ''; - $end = ($i < count($lines) - 2) ? '\\' : ''; - $message = $first . '|' . $line . '|' . $end; - $_this->_sendHeader($header, $message); - } else { - $_this->_sendHeader($header, strlen($line) . '|' . $line . '|'); - } - $_this->_messageIndex++; - if ($_this->_messageIndex > 99999) { - trigger_error(__d('debug_kit', 'Maximum number (99,999) of messages reached!', true), E_USER_WARNING); - } - } - $_this->_sendHeader('X-Wf-1-Index', $_this->_messageIndex - 1); - return true; - } -/** - * Parse a debug backtrace - * - * @param array $trace Debug backtrace output - * @access protected - * @return array - **/ - function _parseTrace($trace, $messageName) { - $message = array(); - for ($i = 0, $len = count($trace); $i < $len ; $i++) { - $keySet = (isset($trace[$i]['class']) && isset($trace[$i]['function'])); - $selfCall = ($keySet && $trace[$i]['class'] == 'FireCake'); - if (!$selfCall) { - $message = array( - 'Class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : '', - 'Type' => isset($trace[$i]['type']) ? $trace[$i]['type'] : '', - 'Function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : '', - 'Message' => $messageName, - 'File' => isset($trace[$i]['file']) ? Debugger::trimPath($trace[$i]['file']) : '', - 'Line' => isset($trace[$i]['line']) ? $trace[$i]['line'] : '', - 'Args' => isset($trace[$i]['args']) ? $this->stringEncode($trace[$i]['args']) : '', - 'Trace' => $this->_escapeTrace(array_splice($trace, $i + 1)) - ); - break; - } - } - return $message; - } -/** - * Fix a trace for use in output - * - * @param mixed $trace Trace to fix - * @access protected - * @static - * @return string - **/ - function _escapeTrace($trace) { - for ($i = 0, $len = count($trace); $i < $len; $i++) { - if (isset($trace[$i]['file'])) { - $trace[$i]['file'] = Debugger::trimPath($trace[$i]['file']); - } - if (isset($trace[$i]['args'])) { - $trace[$i]['args'] = $this->stringEncode($trace[$i]['args']); - } - } - return $trace; - } -/** - * Encode non string objects to string. - * Filter out recursion, so no errors are raised by json_encode or $javascript->object() - * - * @param mixed $object Object or variable to encode to string. - * @param int $objectDepth Current Depth in object chains. - * @param int $arrayDepth Current Depth in array chains. - * @static - * @return void - **/ - function stringEncode($object, $objectDepth = 1, $arrayDepth = 1) { - $_this =& FireCake::getInstance(); - $return = array(); - if (is_resource($object)) { - return '** ' . (string)$object . '**'; - } - if (is_object($object)) { - if ($objectDepth == $_this->options['maxObjectDepth']) { - return '** Max Object Depth (' . $_this->options['maxObjectDepth'] . ') **'; - } - foreach ($_this->_encodedObjects as $encoded) { - if ($encoded === $object) { - return '** Recursion (' . get_class($object) . ') **'; - } - } - $_this->_encodedObjects[] =& $object; - - $return['__className'] = $class = get_class($object); - $properties = (array)$object; - foreach ($properties as $name => $property) { - $return[$name] = FireCake::stringEncode($property, 1, $objectDepth + 1); - } - array_pop($_this->_encodedObjects); - } - if (is_array($object)) { - if ($arrayDepth == $_this->options['maxArrayDepth']) { - return '** Max Array Depth ('. $_this->options['maxArrayDepth'] . ') **'; - } - foreach ($object as $key => $value) { - $return[$key] = FireCake::stringEncode($value, 1, $arrayDepth + 1); - } - } - if (is_string($object) || is_numeric($object) || is_bool($object) || is_null($object)) { - return $object; - } - return $return; - } -/** - * Encode an object into JSON - * - * @param mixed $object Object or array to json encode - * @param boolean $doIt - * @access public - * @static - * @return string - **/ - function jsonEncode($object, $skipEncode = false) { - $_this =& FireCake::getInstance(); - if (!$skipEncode) { - $object = FireCake::stringEncode($object); - } - - if (function_exists('json_encode') && $_this->options['useNativeJsonEncode']) { - return json_encode($object); - } else { - return FireCake::_jsonEncode($object); - } - } -/** - * jsonEncode Helper method for PHP4 compatibility - * - * @param mixed $object Something to encode - * @access protected - * @static - * @return string - **/ - function _jsonEncode($object) { - if (!class_exists('JavascriptHelper')) { - App::import('Helper', 'Javascript'); - } - $javascript =& new JavascriptHelper(); - $javascript->useNative = false; - if (is_string($object)) { - return '"' . $javascript->escapeString($object) . '"'; - } - return $javascript->object($object); - } -/** - * Send Headers - write headers. - * - * @access protected - * @return void - **/ - function _sendHeader($name, $value) { - header($name . ': ' . $value); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/vendors/shells/benchmark.php b/plugins/debug_kit/vendors/shells/benchmark.php deleted file mode 100755 index aa64231..0000000 --- a/plugins/debug_kit/vendors/shells/benchmark.php +++ /dev/null @@ -1,168 +0,0 @@ -args) || count($this->args) > 1) { - return $this->help(); - } - - $url = $this->args[0]; - $defaults = array('t' => 100, 'n' => 10); - $options = array_merge($defaults, $this->params); - $times = array(); - - $this->out(String::insert(__d('debug_kit', '-> Testing :url', true), compact('url'))); - $this->out(""); - for ($i = 0; $i < $options['n']; $i++) { - if (floor($options['t'] - array_sum($times)) <= 0 || $options['n'] <= 1) { - break; - } - - $start = microtime(true); - file_get_contents($url); - $stop = microtime(true); - - $times[] = $stop - $start; - } - $this->_results($times); - } -/** - * Prints calculated results - * - * @param array $times Array of time values - * @return void - * @access protected - */ - function _results($times) { - $duration = array_sum($times); - $requests = count($times); - - $this->out(String::insert(__d('debug_kit', 'Total Requests made: :requests', true), compact('requests'))); - $this->out(String::insert(__d('debug_kit', 'Total Time elapsed: :duration (seconds)', true), compact('duration'))); - - $this->out(""); - - $this->out(String::insert(__d('debug_kit', 'Requests/Second: :rps req/sec', true), array( - 'rps' => round($requests / $duration, 3) - ))); - - $this->out(String::insert(__d('debug_kit', 'Average request time: :average-time seconds', true), array( - 'average-time' => round($duration / $requests, 3) - ))); - - $this->out(String::insert(__d('debug_kit', 'Standard deviation of average request time: :std-dev', true), array( - 'std-dev' => round($this->_deviation($times, true), 3) - ))); - - $this->out(String::insert(__d('debug_kit', 'Longest/shortest request: :longest sec/:shortest sec', true), array( - 'longest' => round(max($times), 3), - 'shortest' => round(min($times), 3) - ))); - - $this->out(""); - - } -/** - * One-pass, numerically stable calculation of population variance. - * - * Donald E. Knuth (1998). - * The Art of Computer Programming, volume 2: Seminumerical Algorithms, 3rd edn., - * p. 232. Boston: Addison-Wesley. - * - * @param array $times Array of values - * @param boolean $sample If true, calculates an unbiased estimate of the population - * variance from a finite sample. - * @return float Variance - * @access protected - */ - function _variance($times, $sample = true) { - $n = $mean = $M2 = 0; - - foreach($times as $time){ - $n += 1; - $delta = $time - $mean; - $mean = $mean + $delta/$n; - $M2 = $M2 + $delta*($time - $mean); - } - - if ($sample) $n -= 1; - - return $M2/$n; - } -/** - * Calculate the standard deviation. - * - * @param array $times Array of values - * @return float Standard deviation - * @access protected - */ - function _deviation($times, $sample = true) { - return sqrt($this->_variance($times, $sample)); - } -/** - * Help for Benchmark shell - * - * @return void - * @access public - */ - function help() { - $this->out(__d('debug_kit', "DebugKit Benchmark Shell", true)); - $this->out(""); - $this->out(__d('debug_kit', "\tAllows you to obtain some rough benchmarking statistics \n\tabout a fully qualified URL.", true)); - $this->out(""); - $this->out(__d('debug_kit', "\tUse:", true)); - $this->out(__d('debug_kit', "\t\tcake benchmark [-n iterations] [-t timeout] url", true)); - $this->out(""); - $this->out(__d('debug_kit', "\tParams:", true)); - $this->out(__d('debug_kit', "\t\t-n Number of iterations to perform. Defaults to 10. \n\t\t Must be an integer.", true)); - $this->out(__d('debug_kit', "\t\t-t Maximum total time for all iterations, in seconds. \n\t\t Defaults to 100. Must be an integer.", true)); - $this->out(""); - $this->out(__d('debug_kit', "\tIf a single iteration takes more than the \n\ttimeout specified, only one request will be made.", true)); - $this->out(""); - $this->out(__d('debug_kit', "\tExample Use:", true)); - $this->out(__d('debug_kit', "\t\tcake benchmark -n 10 -t 100 http://localhost/testsite", true)); - $this->out(""); - $this->out(__d('debug_kit', "\tNote that this benchmark does not include browser render time", true)); - $this->out(""); - $this->hr(); - $this->out(""); - } -} - -?> \ No newline at end of file diff --git a/plugins/debug_kit/vendors/shells/whitespace.php b/plugins/debug_kit/vendors/shells/whitespace.php deleted file mode 100755 index 5e772fe..0000000 --- a/plugins/debug_kit/vendors/shells/whitespace.php +++ /dev/null @@ -1,70 +0,0 @@ -findRecursive('.*\.php'); - $this->out("Checking *.php in ".ROOT); - foreach($r as $file) { - $c = file_get_contents($file); - if (preg_match('/^[\n\r|\n\r|\n|\r|\s]+\<\?php/',$c)) { - $this->out('!!!contains leading whitespaces: '.$this->shortPath($file)); - } - if (preg_match('/\?\>[\n\r|\n\r|\n|\r|\s]+$/',$c)) { - $this->out('!!!contains trailing whitespaces: '.$this->shortPath($file)); - } - } - } - -/** - * Much like main() except files are modified. Be sure to have - * backups or use version control. - * - * @return void - */ - function trim() { - $siteRoot = new Folder(ROOT); - - $r = $siteRoot->findRecursive('.*\.php'); - $this->out("Checking *.php in ".ROOT); - foreach($r as $file) { - $c = file_get_contents($file); - if (preg_match('/^[\n\r|\n\r|\n|\r|\s]+\<\?php/', $c) || preg_match('/\?\>[\n\r|\n\r|\n|\r|\s]+$/', $c)) { - $this->out('trimming' . $this->shortPath($file)); - $c = preg_replace('/^[\n\r|\n\r|\n|\r|\s]+\<\?php/', '[\n\r|\n\r|\n|\r|\s]+$/', '?>', $c); - file_put_contents($file, $c); - } - } - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/views/debug.php b/plugins/debug_kit/views/debug.php deleted file mode 100755 index 27e498b..0000000 --- a/plugins/debug_kit/views/debug.php +++ /dev/null @@ -1,80 +0,0 @@ -params['requested']) && isset($this->loaded['toolbar'])) { - $backend = $this->loaded['toolbar']->getName(); - $this->loaded['toolbar']->{$backend}->send(); - } - if (empty($this->output)) { - return $out; - } - return $this->output; - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/views/elements/debug_toolbar.ctp b/plugins/debug_kit/views/elements/debug_toolbar.ctp deleted file mode 100755 index b7172b0..0000000 --- a/plugins/debug_kit/views/elements/debug_toolbar.ctp +++ /dev/null @@ -1,56 +0,0 @@ - -
- -

- - - -
\ No newline at end of file diff --git a/plugins/debug_kit/views/elements/history_panel.ctp b/plugins/debug_kit/views/elements/history_panel.ctp deleted file mode 100755 index 3154b1a..0000000 --- a/plugins/debug_kit/views/elements/history_panel.ctp +++ /dev/null @@ -1,195 +0,0 @@ - -

- -

- - -
    -
  • link(__d('debug_kit', 'Restore to current request', true), - '#', array('class' => 'history-link', 'id' => 'history-restore-current')); ?> -
  • - -
  • link($previous['title'], $previous['url'], array('class' => 'history-link')); ?>
  • - -
- - - \ No newline at end of file diff --git a/plugins/debug_kit/views/elements/log_panel.ctp b/plugins/debug_kit/views/elements/log_panel.ctp deleted file mode 100755 index fbb68c1..0000000 --- a/plugins/debug_kit/views/elements/log_panel.ctp +++ /dev/null @@ -1,40 +0,0 @@ - -

-
- $logs): ?> -

- 0): - $headers = array(__d('debug_kit', 'Time', true), __d('debug_kit', 'Message', true)); - $rows = array(); - for ($i = 0; $i < $len; $i += 2): - $rows[] = array( - $logs[$i], h($logs[$i + 1]) - ); - endfor; - echo $toolbar->table($rows, $headers, array('title' => $logName)); - else: ?> -

- - -
\ No newline at end of file diff --git a/plugins/debug_kit/views/elements/request_panel.ctp b/plugins/debug_kit/views/elements/request_panel.ctp deleted file mode 100755 index 3b48f96..0000000 --- a/plugins/debug_kit/views/elements/request_panel.ctp +++ /dev/null @@ -1,36 +0,0 @@ - -

-

Cake Params

-makeNeatArray($content['params']); ?> - -

$_GET

-makeNeatArray($content['get']); ?> - -

Cookie

- - makeNeatArray($content['cookie']); ?> - -

To view Cookies, add CookieComponent to Controller

- - -

-makeNeatArray($content['currentRoute']); ?> \ No newline at end of file diff --git a/plugins/debug_kit/views/elements/session_panel.ctp b/plugins/debug_kit/views/elements/session_panel.ctp deleted file mode 100755 index 3b620f8..0000000 --- a/plugins/debug_kit/views/elements/session_panel.ctp +++ /dev/null @@ -1,22 +0,0 @@ - -

-makeNeatArray($content); ?> \ No newline at end of file diff --git a/plugins/debug_kit/views/elements/sql_log_panel.ctp b/plugins/debug_kit/views/elements/sql_log_panel.ctp deleted file mode 100755 index 8f2b80e..0000000 --- a/plugins/debug_kit/views/elements/sql_log_panel.ctp +++ /dev/null @@ -1,90 +0,0 @@ -readCache('sql_log', $this->params['pass'][0]); -} -?> -

- - $explain): ?> -
-

- getQueryLogs($dbName, array( - 'explain' => $explain, 'threshold' => $content['threshold'] - )); - else: - $queryLog = $content[$dbName]; - endif; - echo $toolbar->table($queryLog, $headers, array('title' => 'SQL Log ' . $dbName)); - ?> -

-
- -

-
-
- -message('Warning', __d('debug_kit', 'No active database connections', true)); -endif; ?> - - \ No newline at end of file diff --git a/plugins/debug_kit/views/elements/timer_panel.ctp b/plugins/debug_kit/views/elements/timer_panel.ctp deleted file mode 100755 index e0de45b..0000000 --- a/plugins/debug_kit/views/elements/timer_panel.ctp +++ /dev/null @@ -1,108 +0,0 @@ -readCache('timer', $this->params['pass'][0]); - if (is_array($content)): - extract($content); - endif; -endif; -?> -
-

-
- message(__d('debug_kit', 'Peak Memory Use', true), $number->toReadableSize($peakMemory)); ?> -
- - $value): - $rows[] = array($key, $number->toReadableSize($value)); - endforeach; - - echo $toolbar->table($rows, $headers); - ?> -
- -
-

-
- precision($requestTime * 1000, 0)); ?> - message(__d('debug_kit', 'Total Request Time:', true), $totalTime)?> -
- $timeInfo): - $indent = 0; - for ($j = 0; $j < $i; $j++) { - if (($values[$j]['end'] > $timeInfo['start']) && ($values[$j]['end']) > ($timeInfo['end'])) { - $indent++; - } - } - $indent = str_repeat(' » ', $indent); - $rows[] = array( - $indent . $timeInfo['message'], - $number->precision($timeInfo['time'] * 1000, 2), - $simpleGraph->bar( - $number->precision($timeInfo['time'] * 1000, 2), - $number->precision($timeInfo['start'] * 1000, 2), - array( - 'max' => $maxTime * 1000, - 'requestTime' => $requestTime * 1000, - ) - ) - ); - $i++; -endforeach; - -if (strtolower($toolbar->getName()) == 'firephptoolbar'): - for ($i = 0, $len = count($rows); $i < $len; $i++): - unset($rows[$i][2]); - endfor; - unset($headers[2]); -endif; - -echo $toolbar->table($rows, $headers, array('title' => 'Timers')); - -if (!isset($debugKitInHistoryMode)): - $toolbar->writeCache('timer', compact('timers', 'currentMemory', 'peakMemory', 'requestTime')); -endif; -?> -
\ No newline at end of file diff --git a/plugins/debug_kit/views/elements/variables_panel.ctp b/plugins/debug_kit/views/elements/variables_panel.ctp deleted file mode 100755 index 7f97eb7..0000000 --- a/plugins/debug_kit/views/elements/variables_panel.ctp +++ /dev/null @@ -1,25 +0,0 @@ - -

-validationErrors'] = $this->validationErrors; -$content['Loaded Helpers'] = array_keys($this->loaded); -echo $toolbar->makeNeatArray($content); ?> \ No newline at end of file diff --git a/plugins/debug_kit/views/helpers/fire_php_toolbar.php b/plugins/debug_kit/views/helpers/fire_php_toolbar.php deleted file mode 100755 index b0afa85..0000000 --- a/plugins/debug_kit/views/helpers/fire_php_toolbar.php +++ /dev/null @@ -1,97 +0,0 @@ - 'firePHP', 'forceEnable' => false); -/** - * send method - * - * @return void - * @access protected - */ - function send() { - $view =& ClassRegistry::getObject('view'); - $view->element('debug_toolbar', array('plugin' => 'debug_kit', 'disableTimer' => true)); - } -/** - * makeNeatArray. - * - * wraps FireCake::dump() allowing panel elements to continue functioning - * - * @param string $values - * @return void - */ - function makeNeatArray($values) { - FireCake::info($values); - } -/** - * Create a simple message - * - * @param string $label Label of message - * @param string $message Message content - * @return void - */ - function message($label, $message) { - FireCake::log($message, $label); - } -/** - * Generate a table with FireCake - * - * @param array $rows Rows to print - * @param array $headers Headers for table - * @param array $options Additional options and params - * @return void - */ - function table($rows, $headers, $options = array()) { - $title = $headers[0]; - if (isset($options['title'])) { - $title = $options['title']; - } - array_unshift($rows, $headers); - FireCake::table($title, $rows); - } -/** - * Start a panel which is a 'Group' in FirePHP - * - * @return void - **/ - function panelStart($title, $anchor) { - FireCake::group($title); - } -/** - * End a panel (Group) - * - * @return void - **/ - function panelEnd() { - FireCake::groupEnd(); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/views/helpers/html_toolbar.php b/plugins/debug_kit/views/helpers/html_toolbar.php deleted file mode 100755 index 6e0777f..0000000 --- a/plugins/debug_kit/views/helpers/html_toolbar.php +++ /dev/null @@ -1,184 +0,0 @@ - 'html', 'forceEnable' => false); -/** - * Recursively goes through an array and makes neat HTML out of it. - * - * @param mixed $values Array to make pretty. - * @param int $openDepth Depth to add open class - * @param int $currentDepth current depth. - * @return string - **/ - function makeNeatArray($values, $openDepth = 0, $currentDepth = 0) { - $className ="neat-array depth-$currentDepth"; - if ($openDepth > $currentDepth) { - $className .= ' expanded'; - } - $nextDepth = $currentDepth + 1; - $out = "
    "; - if (!is_array($values)) { - if (is_bool($values)) { - $values = array($values); - } - if (is_null($values)) { - $values = array(null); - } - } - if (empty($values)) { - $values[] = '(empty)'; - } - foreach ($values as $key => $value) { - $out .= '
  • ' . $key . ''; - if ($value === null) { - $value = '(null)'; - } - if ($value === false) { - $value = '(false)'; - } - if ($value === true) { - $value = '(true)'; - } - if (empty($value) && $value != 0) { - $value = '(empty)'; - } - - if (is_object($value)) { - $value = Set::reverse($value, true); - } - - if (is_array($value) && !empty($value)) { - $out .= $this->makeNeatArray($value, $openDepth, $nextDepth); - } else { - $out .= h($value); - } - $out .= '
  • '; - } - $out .= '
'; - return $out; - } -/** - * Create an HTML message - * - * @param string $label label content - * @param string $message message content - * @return string - */ - function message($label, $message) { - return sprintf('

%s %s

', $label, $message); - } -/** - * Start a panel. - * make a link and anchor. - * - * @return void - **/ - function panelStart($title, $anchor) { - $link = $this->Html->link($title, '#' . $anchor); - return $link; - } -/** - * Create a table. - * - * @param array $rows Rows to make. - * @param array $headers Optional header row. - * @return string - */ - function table($rows, $headers = array()) { - $out = ''; - if (!empty($headers)) { - $out .= $this->Html->tableHeaders($headers); - } - $out .= $this->Html->tableCells($rows, array('class' => 'odd'), array('class' => 'even'), false, false); - $out .= '
'; - return $out; - } -/** - * send method - * - * @return void - * @access public - */ - function send() { - if (!$this->settings['forceEnable'] && Configure::read('debug') == 0) { - return; - } - $view =& ClassRegistry::getObject('view'); - $head = $this->Html->css('/debug_kit/css/debug_toolbar'); - if (isset($view->viewVars['debugToolbarJavascript'])) { - foreach ($view->viewVars['debugToolbarJavascript'] as $script) { - if ($script) { - $head .= $this->Javascript->link($script); - } - } - } - if (preg_match('##', $view->output)) { - $view->output = preg_replace('##', $head . "\n", $view->output, 1); - } - $toolbar = $view->element('debug_toolbar', array('plugin' => 'debug_kit', 'disableTimer' => true)); - if (preg_match('##', $view->output)) { - $view->output = preg_replace('##', $toolbar . "\n", $view->output, 1); - } - } -/** - * Generates a SQL explain link for a given query - * - * @param string $sql SQL query string you want an explain link for. - * @return string Rendered Html link or '' if the query is not a select/describe - */ - function explainLink($sql, $connection) { - if (!preg_match('/^(SELECT)/i', $sql)) { - return ''; - } - App::import('Core', 'Security'); - $hash = Security::hash($sql . $connection, null, true); - $url = array( - 'plugin' => 'debug_kit', - 'controller' => 'toolbar_access', - 'action' => 'sql_explain', - 'ds' => $connection, - 'sql' => $sql, - 'hash' => $hash - ); - foreach (Router::prefixes() as $prefix) { - $url[$prefix] = false; - } - return $this->Html->link(__d('debug_kit', 'Explain', true), $url, array('class' => 'sql-explain-link')); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/views/helpers/simple_graph.php b/plugins/debug_kit/views/helpers/simple_graph.php deleted file mode 100755 index ea85e37..0000000 --- a/plugins/debug_kit/views/helpers/simple_graph.php +++ /dev/null @@ -1,85 +0,0 @@ - (int) Maximum value in the graphs - * - width => (int) - * - valueType => string (value, percentage) - * - style => array - * - * @var array - */ - var $__defaultSettings = array( - 'max' => 100, - 'width' => 350, - 'valueType' => 'value', - ); -/** - * bar method - * - * @param $value Value to be graphed - * @param $offset how much indentation - * @param $options Graph options - * @return string Html graph - * @access public - */ - function bar($value, $offset, $options = array()) { - $settings = array_merge($this->__defaultSettings, $options); - extract($settings); - - $graphValue = ($value / $max) * $width; - $graphValue = max(round($graphValue), 1); - - if ($valueType == 'percentage') { - $graphOffset = 0; - } else { - $graphOffset = ($offset / $max) * $width; - $graphOffset = round($graphOffset); - } - return $this->Html->div( - 'debug-kit-graph-bar', - $this->Html->div( - 'debug-kit-graph-bar-value', - ' ', - array( - 'style' => "margin-left: {$graphOffset}px; width: {$graphValue}px", - 'title' => sprintf(__d('debug_kit', "Starting %sms into the request, taking %sms", true), $offset, $value), - ) - ), - array('style' => "width: {$width}px;"), - false - ); - } -} -?> \ No newline at end of file diff --git a/plugins/debug_kit/views/helpers/toolbar.php b/plugins/debug_kit/views/helpers/toolbar.php deleted file mode 100755 index f6bce9b..0000000 --- a/plugins/debug_kit/views/helpers/toolbar.php +++ /dev/null @@ -1,178 +0,0 @@ -_myName = strtolower(get_class($this)); - $this->settings = am($this->settings, $options); - - if ($this->_myName !== 'toolbarhelper') { - return; - } - - if (!isset($options['output'])) { - $options['output'] = 'DebugKit.HtmlToolbar'; - } - App::import('Helper', $options['output']); - $className = $options['output']; - if (strpos($options['output'], '.') !== false) { - list($plugin, $className) = explode('.', $options['output']); - } - $this->_backEndClassName = $className; - $this->helpers[$options['output']] = $options; - if (isset($options['cacheKey']) && isset($options['cacheConfig'])) { - $this->_cacheKey = $options['cacheKey']; - $this->_cacheConfig = $options['cacheConfig']; - $this->_cacheEnabled = true; - } - } -/** - * Get the name of the backend Helper - * used to conditionally trigger toolbar output - * - * @return string - **/ - function getName() { - return $this->_backEndClassName; - } -/** - * call__ - * - * Allows method calls on backend helper - * - * @param string $method - * @param mixed $params - * @access public - * @return void - */ - function call__($method, $params) { - if (method_exists($this->{$this->_backEndClassName}, $method)) { - return $this->{$this->_backEndClassName}->dispatchMethod($method, $params); - } - } -/** - * Allows for writing to panel cache from view. - * Some panels generate all variables in the view by - * necessity ie. Timer. Using this method, will allow you to replace in full - * the content for a panel. - * - * @param string $name Name of the panel you are replacing. - * @param string $content Content to write to the panel. - * @return boolean Sucess of write. - **/ - function writeCache($name, $content) { - if (!$this->_cacheEnabled) { - return false; - } - $existing = (array)Cache::read($this->_cacheKey, $this->_cacheConfig); - $existing[0][$name]['content'] = $content; - return Cache::write($this->_cacheKey, $existing, $this->_cacheConfig); - } -/** - * Read the toolbar - * - * @param string $name Name of the panel you want cached data for - * @return mixed Boolean false on failure, array of data otherwise. - **/ - function readCache($name, $index = 0) { - if (!$this->_cacheEnabled) { - return false; - } - $existing = (array)Cache::read($this->_cacheKey, $this->_cacheConfig); - if (!isset($existing[$index][$name]['content'])) { - return false; - } - return $existing[$index][$name]['content']; - } -/** - * Gets the query logs for the given connection names. - * - * ### Options - * - * - explain - Whether explain links should be generated for this connection. - * - cache - Whether the toolbar_state Cache should be updated. - * - threshold - The threshold at which a visual 'maybe slow' flag should be added. - * results with rows/ms lower than $threshold will be marked. - * - * @param string $connection Connection name to get logs for. - * @param array $options Options for the query log retrieval. - * @return array Array of data to be converted into a table. - */ - function getQueryLogs($connection, $options = array()) { - $options += array('explain' => false, 'cache' => true, 'threshold' => 20); - App::import('Model', 'ConnectionManager'); - $db =& ConnectionManager::getDataSource($connection); - - $out = array(); - $log = $db->getLog(); - foreach ($log['log'] as $i => $query) { - $isSlow = ( - $query['took'] > 0 && - $query['numRows'] / $query['took'] != 1 && - $query['numRows'] / $query['took'] <= $options['threshold'] - ); - $query['actions'] = ''; - $isHtml = ($this->getName() == 'HtmlToolbar'); - if ($isSlow && $isHtml) { - $query['actions'] = sprintf( - '%s', - __d('debug_kit', 'maybe slow', true) - ); - } elseif ($isSlow) { - $query['actions'] = '*'; - } - if ($options['explain'] && $isHtml) { - $query['actions'] .= $this->explainLink($query['query'], $connection); - } - if ($isHtml) { - $query['query'] = h($query['query']); - } - $out[] = $query; - } - if ($options['cache']) { - $existing = $this->readCache('sql_log'); - $existing[$connection] = $out; - $this->writeCache('sql_log', $existing); - } - return $out; - } -} \ No newline at end of file diff --git a/plugins/debug_kit/views/toolbar_access/history_state.ctp b/plugins/debug_kit/views/toolbar_access/history_state.ctp deleted file mode 100755 index c7ad685..0000000 --- a/plugins/debug_kit/views/toolbar_access/history_state.ctp +++ /dev/null @@ -1,29 +0,0 @@ - $panel) { - $panels[$panelName] = $this->element($panel['elementName'], array( - 'content' => $panel['content'], - 'plugin' => $panel['plugin'] - )); -} -echo $javascript->object($panels); -Configure::write('debug', 0); -?> \ No newline at end of file diff --git a/plugins/debug_kit/views/toolbar_access/sql_explain.ctp b/plugins/debug_kit/views/toolbar_access/sql_explain.ctp deleted file mode 100755 index 36e59a3..0000000 --- a/plugins/debug_kit/views/toolbar_access/sql_explain.ctp +++ /dev/null @@ -1,9 +0,0 @@ - -tableHeaders($headers); -echo $html->tableCells($result); -?> -
- \ No newline at end of file diff --git a/plugins/debug_kit/webroot/css/debug_toolbar.css b/plugins/debug_kit/webroot/css/debug_toolbar.css deleted file mode 100755 index 13ade53..0000000 --- a/plugins/debug_kit/webroot/css/debug_toolbar.css +++ /dev/null @@ -1,312 +0,0 @@ -/* @override http://localhost/mark_story/site/debug_kit/css/debug_toolbar.css */ -#debug-kit-toolbar { - position: fixed; - top: 0px; - right:0px; - width: 100%; - height: 1%; - overflow: visible; - z-index:10000; - font-family: helvetica, arial, sans-serif; - font-size: 12px; - direction: ltr; -} -#debug-kit-toolbar img { - border:0; - outline:0; -} - -/* panel tabs */ -#debug-kit-toolbar #panel-tabs { - float: right; - list-style: none; - margin: 0; -} -#debug-kit-toolbar .panel-tab { - clear: none; - float: left; - margin: 0; - padding: 0; - list-style: none; -} -#debug-kit-toolbar .panel-tab a { - float: left; - clear: none; - background: #efefef; - background: -webkit-gradient(linear, left top, left bottom, from(#efefef), to(#cacaca)); - background: -moz-linear-gradient(left top, left bottom, from(#efefef), to(#cacaca)); - color: #222; - padding: 6px; - border-right: 1px solid #ccc; - border-bottom: 1px solid #aaa; - font-size: 12px; - line-height: 16px; - margin: 0; - display: block; - text-decoration:none; - text-shadow:1px 1px #eee; - -moz-text-shadow:1px 1px #eee; - -webkit-text-shadow:1px 1px #eee; -} -#debug-kit-toolbar .panel-tab .active { - background: #fff; - background: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#fff)); -} -#debug-kit-toolbar .panel-tab a:hover { - background: #fff; - background: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#fff)); - text-decoration:underline; -} -#debug-kit-toolbar .panel-tab.icon a { - padding: 4px; -} -#debug-kit-toolbar .panel-tab a.edit-value { - float: none; - display: inline; -} - -/* Hovering over link shows tab, useful for no js */ -#debug-kit-toolbar .panel-tab a:hover + .panel-content, -#debug-kit-toolbar .panel-tab a + .panel-content:hover { - display: block; -} -#debug-kit-toolbar .panel-tab.icon a { - -webkit-border-top-left-radius: 8px 8px; - -webkit-border-bottom-left-radius: 8px 8px; - -moz-border-radius-topleft: 8px; - -moz-border-radius-bottomleft: 8px -} -#debug-kit-toolbar .panel-tab.icon img { - display:block; -} - -/* panel content */ -#debug-kit-toolbar .panel-content { - position: absolute; - text-align: left; - width: auto; - top:28px; - right:0px; - background: #fff; - color: #000; - width:100%; - box-shadow:0px 5px 6px #ccc; -} - -#debug-kit-toolbar .panel-resize-region { - overflow:auto; - height:99%; - max-height: 550px; - padding:15px; -} - -#debug-kit-toolbar .panel-resize-handle { - width:100%; - background:#ccc; - background: -webkit-gradient(linear, left top, left bottom, from(#d6d6d6), to(#c2c2c2)); - text-align:center; - cursor:move; - border-top:1px solid #afafaf; - border-bottom:1px solid #7c7c7c; - color:#666; - text-shadow:1px 1px #eee; - -webkit-text-shadow:1px 1px #eee; - -moz-text-shadow:1px 1px #eee; - height:14px; -} - -/* Hide panel content by default */ -#debug-kit-toolbar .panel-content { - display: none; -} -.panel-content p { - margin: 1em 0; -} -.panel-content h2 { - padding: 0; - margin-top:0; -} -.panel-content h3 { - padding: 0; - margin-top: 1em; -} -.panel-content .info { - padding: 4px; - border-top: 1px dashed #6c6cff; - border-bottom: 1px dashed #6c6cff; -} -#debug-kit-toolbar h1, -#debug-kit-toolbar h2, -#debug-kit-toolbar h3, -#debug-kit-toolbar h4, -#debug-kit-toolbar h5, -#debug-kit-toolbar th { - color: #5d1717; - font-family: "Trebuchet MS", trebuchet, helvetica, arial, sans-serif; - margin-bottom:0.6em; - background:none; -} -#debug-kit-toolbar h1 { - font-size: 18px; -} -#debug-kit-toolbar h2 { - font-size: 16px; -} -#debug-kit-toolbar h4 { - font-size: 14px; -} - - -/* panel tables */ -#debug-kit-toolbar table.debug-table { - width: 100%; - border: 0; - clear:both; -} -#debug-kit-toolbar table.debug-table td, -#debug-kit-toolbar table.debug-table th { - text-align: left; - border: 0; - padding: 3px; -} -#debug-kit-toolbar table.debug-table th { - border-bottom: 1px solid #222; - background: 0; - color: #252525; -} -#debug-kit-toolbar table.debug-table tr:nth-child(2n+1) td { - background:#f6f6f6; -} -#debug-kit-toolbar table.debug-table tr.even td { - background:#f7f7f7; -} -#debug-kit-toolbar .debug-timers .debug-table td:nth-child(2), -#debug-kit-toolbar .debug-timers .debug-table th:nth-child(2) { - text-align:right; -} - -/** code tables **/ -#debug-kit-toolbar .code-table td { - white-space: pre; - font-family: monaco, corsiva, "courier new", courier, monospaced; -} -#debug-kit-toolbar .code-table td:first-child { - width: 15%; -} -#debug-kit-toolbar .code-table td:last-child { - width: 80%; -} - -#debug-kit-toolbar .panel-content.request { - display: block; -} - -/** Neat Array styles **/ -#debug-kit-toolbar .neat-array, -#debug-kit-toolbar .neat-array li { - list-style:none; - list-style-image:none; -} -.neat-array { - padding: 1px 2px 1px 20px; - background: #CE9E23; - list-style: none; - margin: 0 0 1em 0; -} -.neat-array .neat-array { - padding: 0 0 0 20px; - margin:0; - border-top:1px solid #CE9E23; -} -.neat-array li { - background: #FEF6E5; - border-top: 1px solid #CE9E23; - border-bottom: 1px solid #CE9E23; - margin: 0; - line-height: 1.5em; -} -.neat-array li:hover { - background: #fff; -} -.neat-array li strong { - padding: 0 8px; - font-weight: bold; -} - - -/* expandable sections */ -.neat-array li.expandable { - cursor: pointer; -} -.neat-array .expanded { - border-bottom:0; -} -.neat-array li.expandable.expanded > strong:before { - content: 'v '; -} -.neat-array li.expandable.collapsed > strong:before, -.neat-array li.expandable.expanded .expandable.collapsed > strong:before { - content: '> '; -} -.neat-array li { - cursor: default; -} - -#debug-kit-toolbar .debug-kit-graph-bar, -#debug-kit-toolbar .debug-kit-graph-bar-value { - margin: 0; - padding: 0px; - border: none; - overflow: hidden; - height: 10px; -} -#debug-kit-toolbar .debug-kit-graph-bar { - background-color: #ddd; - padding:2px; -} -#debug-kit-toolbar .debug-kit-graph-bar-value { - background-color: #CE9E23; -} - -/* Sql Log */ -#sql_log-tab td, -#sql_log-tab .slow-query-container p { - font-family: Monaco, 'Corsiva', "Courier New", Courier, monospaced; -} -#debug-kit-toolbar #sql_log-tab a.show-slow { - display:block; - margin: 3px; - float:none; -} -#sql_log-tab .slow-query-container p { - display:block; - clear:both; - margin: 20px 0 5px; -} -#debug-kit-toolbar #sql_log-tab a { - background: none; - border:none; -} -#sql_log-tab .slow-query { - background:#e79302; - font-size:9px; - color:#fff; - padding: 2px; - white-space:nowrap; -} - -/* previous panels */ -#debug-kit-toolbar .panel-history { - display: none; - background:#eeffff; -} -#debug-kit-toolbar #history-tab a { - float: none; -} -#debug-kit-toolbar #history-tab a.active { - background: #FEF6E5; -} -#debug-kit-toolbar #history-tab a.loading:after { - content : ' Loading...'; - font-style:italic; -} diff --git a/plugins/debug_kit/webroot/img/cake.icon.png b/plugins/debug_kit/webroot/img/cake.icon.png deleted file mode 100755 index 394fa42d5131cdc7b0b1246af93b92179f3c887e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 943 zcmV;g15o^lP)9q)cr7> zIGsQFGn3| zCzs2iP$-yfVPOGVTU&6sT(-5fwHb2tVsLP9#{Vr9Ct?R7q(rf?v2A5#W$OI=e1YUJ zQ1YRnA&iWSQ1XYAm__>aYb6XIhMiYVD+-z8_pYi6+CsH{*^m;vOjqvbr=H&DFkeqxHQBh$Scsoy0Glw(T zsaSG*ok62V;~yXYNgP*DUw;o98^+0@vGFb{HC+As}XJ=;xg=B7N_;-mKbHH{|lXs_o+aPcs5~J?s%^P2Odb)Uz z$GvY6^!N9(C2-h?28B$qx7%_yHnt2eU%nQ0qThbl6a_+b)EirjBgQ`g1_07Fr&6R? RzIgxu002ovPDHLkV1mdlwUYn< diff --git a/plugins/debug_kit/webroot/js/js_debug_toolbar.js b/plugins/debug_kit/webroot/js/js_debug_toolbar.js deleted file mode 100755 index 5deb918..0000000 --- a/plugins/debug_kit/webroot/js/js_debug_toolbar.js +++ /dev/null @@ -1,700 +0,0 @@ -/** - * Debug Toolbar Javascript. - * - * Creates the DEBUGKIT namespace and provides methods for extending - * and enhancing the Html toolbar. Includes library agnostic Event, Element, - * Cookie and Request wrappers. - * - * - * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) - * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The MIT License - * Redistributions of files must retain the above copyright notice. - * - * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://cakephp.org - * @package debug_kit - * @subpackage debug_kit.views.helpers - * @since DebugKit 0.1 - * @license MIT License (http://www.opensource.org/licenses/mit-license.php) - */ -var DEBUGKIT = function () { - var undef; - return { - module: function (newmodule) { - if (this[newmodule] === undef) { - this[newmodule] = {}; - return this[newmodule]; - } - return this[newmodule]; - } - }; -}() ; - -DEBUGKIT.loader = function () { - return { - //list of methods to run on startup. - _startup: [], - - //register a new method to be run on dom ready. - register: function (method) { - this._startup.push(method); - }, - - init: function () { - for (var i = 0, callback; callback = this._startup[i]; i++) { - callback.init(); - } - } - }; -}(); - -//Util module and Element utility class. -DEBUGKIT.module('Util'); -DEBUGKIT.Util.Element = { - - //test if an element is a name node. - nodeName: function (element, name) { - return element.nodeName && element.nodeName.toLowerCase() == name.toLowerCase(); - }, - - //return a boolean if the element has the classname - hasClass: function (element, className) { - if (!element.className) { - return false; - } - return element.className.indexOf(className) > -1; - }, - - addClass: function (element, className) { - if (!element.className) { - element.className = className; - return; - } - element.className = element.className.replace(/^(.*)$/, '$1 ' + className); - }, - - removeClass: function (element, className) { - if (DEBUGKIT.Util.isArray(element)) { - DEBUGKIT.Util.Collection.apply(element, function (element) { - Element.removeClass(element, className); - }); - } - if (!element.className) { - return false; - } - element.className = element.className.replace(new RegExp(' ?(' + className +') ?'), ''); - }, - - swapClass: function (element, removeClass, addClass) { - if (!element.className) { - return false; - } - element.className = element.className.replace(removeClass, addClass); - }, - - show: function (element) { - element.style.display = 'block'; - }, - - hide: function (element) { - element.style.display = 'none'; - }, - - //go between hide() and show() depending on element.style.display - toggle: function (element) { - if (element.style.display == 'none') { - this.show(element); - return; - } - this.hide(element); - }, - - _walk: function (element, walk) { - var sibling = element[walk]; - while (true) { - if (sibling.nodeType == 1) { - break; - } - sibling = sibling[walk]; - } - return sibling; - }, - - getNext: function (element) { - return this._walk(element, 'nextSibling'); - }, - - getPrevious: function (element) { - return this._walk(element, 'previousSibling'); - }, - - //get or set an element's height, omit value to get, add value (integer) to set. - height: function (element, value) { - //get value - if (value === undefined) { - return parseInt(this.getStyle(element, 'height')); - } - element.style.height = value + 'px'; - }, - - //gets the style in css format for property - getStyle: function (element, property) { - if (element.currentStyle) { - property = property.replace(/-[a-z]/g, function (match) { - return match.charAt(1).toUpperCase(); - }); - return element.currentStyle[property]; - } - if (window.getComputedStyle) { - return document.defaultView.getComputedStyle(element, null).getPropertyValue(property); - } - } -}; - -DEBUGKIT.Util.Collection = { - /* - Apply the passed function to each item in the collection. - The current element in the collection will be `this` in the callback - The callback is also passed the element and the index as arguments. - Optionally you can supply a binding parameter to change `this` in the callback. - */ - apply: function (collection, callback, binding) { - //for (var i = 0, len = collection.length; i < len; i++) { - for (var i in collection) { - if (!collection.hasOwnProperty(i)) { - continue; - } - var thisVar = collection[i]; - if (binding !== undefined) { - thisVar = binding; - } - callback.apply(thisVar, [collection[i], i]); - } - } -} - - -//Event binding -DEBUGKIT.Util.Event = function () { - var _listeners = {}, - _eventId = 0; - - var preventDefault = function () { - this.returnValue = false; - } - - var stopPropagation = function () { - this.cancelBubble = true; - } - - // Fixes IE's broken event object, adds in common methods + properties. - var fixEvent = function (event) { - event.preventDefault = event.preventDefault || preventDefault; - event.stopPropagation = event.stopPropagation || stopPropagation; - return event; - } - - return { - // bind an event listener of type to element, handler is your method. - addEvent: function(element, type, handler, capture) { - capture = (capture === undefined) ? false : capture; - - var callback = function (event) { - event = fixEvent(event || window.event); - handler.apply(this, [event]); - }; - - if (element.addEventListener) { - element.addEventListener(type, callback, capture); - } else if (element.attachEvent) { - type = 'on' + type; - element.attachEvent(type, callback); - } else { - type = 'on' + type; - element[type] = callback; - } - _listeners[++_eventId] = {element: element, type: type, handler: callback}; - }, - - // destroy an event listener. requires the exact same function as was used for attaching - // the event. - removeEvent: function (element, type, handler) { - if (element.removeEventListener) { - element.removeEventListener(type, handler, false); - } else if (element.detachEvent) { - type = 'on' + type; - element.detachEvent(type, handler); - } else { - type = 'on' + type; - element[type] = null; - } - }, - - // bind an event to the DOMContentLoaded or other similar event. - domready: function(callback) { - if (document.addEventListener) { - return document.addEventListener("DOMContentLoaded", callback, false); - } - - if (document.all && !window.opera) { - //Define a "blank" external JavaScript tag - document.write(' \ No newline at end of file diff --git a/plugins/interactive/views/interactive/cmd.ctp b/plugins/interactive/views/interactive/cmd.ctp deleted file mode 100644 index 3cfe031..0000000 --- a/plugins/interactive/views/interactive/cmd.ctp +++ /dev/null @@ -1,24 +0,0 @@ - - ' . $result['cmd'] . '
'; - if (is_array($result['output'])) { - if(empty($result['output'])) { - __('No results found.'); - } else { - echo $toolbar->makeNeatArray($result['output']); - } - } else { - if (is_bool($result['output'])) { - $result['output'] = (!empty($result['output']) ? 'true' : 'false'; - } - - if ($result['raw']) { - echo htmlentities($result['output']) . '
'; - } - - echo $result['output'] . '

'; - } - } - ?> -
\ No newline at end of file diff --git a/plugins/interactive/webroot/img/ajax-loader.gif b/plugins/interactive/webroot/img/ajax-loader.gif deleted file mode 100644 index d0bce1542342e912da81a2c260562df172f30d73..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 673 zcmZ?wbhEHb6krfw_{6~Q|Nnmm28Kh24mmkF0U1e2Nli^nlO|14{Lk&@8WQa67~pE8 zXTZz|lvDgC+Z`3#dv5h=E26FfcG1 zbL_hF&)}42ws10s6^G;;cE1^EoUR)U5A70}d2pLv!jVIT7j&Z~EblI3x0K*v_sV|m z0kj3v921Z^em#l`(k(o@H$3ZdDRc@9NidXDNbqrumReCGv$gd8+e8WW28HVqkJ_9i zH>s*<31KtHjANIPvi2#*6BEu%3Dak5O_t&NBI)H?V$TxT}#l{vOTn5naXTfF^&~Hhq+NX@#Ccc>y7T?;vjI&jdhsDsPJyAw*m0Qz>i}K7# zL9w50Ng{fT}A5JUe8lRK1h7_Y2;BWJDd=c6f&i?Wv5(5q?6|P zQw{>maxZP<537OA37Uk}7@%_$4o$EWe_Zl>&#id|lE-BpDC#+Fn|msJ%_2h{Hg1vP z#N8WAzfWasG}yq|xqE)DrWaOofX=z|?*pgc%{ig5vl!pqDlC|q&~Z0$&Rvsft&VO- z4MZj+%-+Vx%W}v;V76hyp=;+R;x+~t^Q%*xuFTQAF2})fSfTHDAs>sO!OBw`)&)o$ c0!CNZt))x~rAZP^^P&YOFfdqy5)K#u0POD40{{R3 diff --git a/plugins/sanction/README.textile b/plugins/sanction/README.textile deleted file mode 100644 index 7feafc6..0000000 --- a/plugins/sanction/README.textile +++ /dev/null @@ -1,152 +0,0 @@ -h1. Sanction Plugin for CakePHP - -Tired of defining your permissions in 7 controllers, or bloating your AppController::beforeFilter() with checks on the User's session? - -h2. Requirements - -* CakeSession-accessible User session -* CakePHP 1.3.x. Untested with the 1.2.x series, but should work fine - -h2. PermitComponent Setup - -Install the SanctionPlugin in your @app/plugins/@ folder under the @sanction@ folder. - -If you want to use the PermitComponent to block user access to controllers/actions, add the following to your AppController or a specific Controller: - -
 array('path' => 'Auth.User'));
-
-// Example for default AuthsomeComponent Configuration
-var $components = array('Sanction.Permit' => array('path' => 'User.User'));
-?>
-
- -Then you will want to setup some permissions... - -Create a file called @permit.php@ in your @app/config/@ folder. You'll need to do the following: - -# Add @App::import('Component', 'PermitComponent');@ -# Define some rules (these will be outlined below) - -You can test those rules by browsing to the url you are protecting. - -h2. ClearanceHelper Setup - -Install the SanctionPlugin in your @app/plugins/@ folder under the @sanction@ folder. - -If you want to use the ClearanceHelper to block user access to controllers/actions, add the following to your AppController or a specific Controller: - -
 array('path' => 'Auth.User'));
-
-// Example for default AuthsomeComponent Configuration
-var $helpers = array('Sanction.Clearance' => array('path' => 'User.User'));
-?>
-
- -Then you will want to setup some permissions... - -Create a file called @permit.php@ in your @app/config/@ folder. You'll need to do the following: - -# Add @App::import('Component', 'PermitComponent');@ -# Define some rules (these will be outlined below) - -Then create links in your views using @$this->Clearance->link()@ instead of @$this->Html->link()@. If the currently logged in user (or not logged in user) has access as defined by the @app/config/permit.php@ file, then the link will appear in whatever view the ClearanceHelper was created in. - -Note that checking against the @app/config/permit.php@ file is an expensive operation (for now!), so you might want to use this on links that will actually vary when displayed to different users, as opposed to all links in your application. - -h2. DebugKit Panel - -Included in the Sanction plugin is a debug_kit panel (as of commit fb061e57) which displays not only the currently matched access rule, but also all rules that you have defined for the application. Useful information if only so you can see whether the current request even went through a rule. - -To use it, add the following to your AppController: - -
 array('panels' => array('Sanction.permit')),
-	'Sanction.Permit' => array('path' => 'Auth.User')
-);
-
-// Example for default AuthsomeComponent Configuration
-var $components = array(
-	'DebugKit.Toolbar' => array('panels' => array('Sanction.permit')),
-	'Sanction.Permit' => array('path' => 'User.User')
-);
-?>
-
- -In the future, it will also keep a history of past requests, as well as highlighting explicitly which access rule was used. - -h2. Rules - -Rules are defined by @Permit::access();@ and can contain 3 arrays: - -* Array of rules upon which we will control access -* Array of rules by which the User's session must be defined by -* Array of extra parameters, such as where to redirect, the flash message, etc. - -An example @app/config/permit.php@: - -
 'posts', 'action' => array('add', 'edit', 'delete')),
-	array('auth' => array('group' => 'admin')),
-	array('redirect' => array('controller' => 'users', 'action' => 'login')));
-?>
-
- -For the above, the following actions will be affected: - -* /posts/add/* -* /posts/edit/* -* /posts/delete/* - -The user must be in the group @admin@, and if they are not, they will be redirected to @/users/login@. - -
 'comments', 'action' => array('edit', 'delete')),
-	array('auth' => array('group' => 'admin')),
-	array(
-		'element' => 'comment',
-		'key' => 'flash',
-		'message' => __('You must be logged in to comment', true),
-		'redirect' => array('controller' => 'users', 'action' => 'login')));
-?>
-
- -For the above, the following actions will be affected: - -* /comments/edit/* -* /comments/delete/* - -The user must be in the group @admin@, and if they are not, they will be redirected to @/users/login@. A flash message at the key @flash@ using the @comment@ element will also be displayed, which will contain the message '@You must be logged in to comment@'. - -
 array('comments'), 'action' => array('add')),
-	array('auth' => true),
-	array(
-		'message' => __('You must be logged in to comment', true),
-		'redirect' => array('controller' => 'users', 'action' => 'login')));
-?>
-
- -For the above, the following actions will be affected: - -* /comments/add/* - -The user must authenticated, and if they are not, they will be redirected to @/users/login@. A flash message will also be presented to them which will contain the message '@You must be logged in to comment@'. - -h2. License - -The Sanction Plugin is offered under an MIT license. \ No newline at end of file diff --git a/plugins/sanction/config/permit.php b/plugins/sanction/config/permit.php deleted file mode 100644 index 0837162..0000000 --- a/plugins/sanction/config/permit.php +++ /dev/null @@ -1,12 +0,0 @@ - 'posts', 'action' => array('add', 'edit', 'delete')), - array('auth' => array('group' => 'admin')), - array('redirect' => array('controller' => 'users', 'action' => 'login'))); -*/ - -?> \ No newline at end of file diff --git a/plugins/sanction/controllers/components/access.php b/plugins/sanction/controllers/components/access.php deleted file mode 100644 index 3d36764..0000000 --- a/plugins/sanction/controllers/components/access.php +++ /dev/null @@ -1,58 +0,0 @@ - array(), - 'auth_denied' => array(), - 'auth_required' => array(), - 'denied' => array(), - 'callback' => 'initialize' - ); - - function initialize(&$controller, $settings) { - $this->settings = array_merge($this->defaults, $settings); - if ($this->settings['callback'] = 'initialize') { - $this->_isAuthorized($controller); - } - } - - function startup(&$controller) { - if ($this->settings['callback'] = 'startup') { - $this->_isAuthorized($controller); - } - } - - function _isAuthorized(&$controller) { - $action = strtolower($controller->params['action']); - - $authRequiredActions = array_map('strtolower', $this->settings['auth_required']); - $authRequired = ($authRequiredActions == array('*') || in_array($action, $authRequiredActions)); - if ($authRequired and Authsome::get('guest')) { - $controller->Session->setFlash('Please login to access this resource'); - $controller->redirect(array('controller' => 'users', 'action' => 'login')); - } - - $authDeniedActions = array_map('strtolower', $this->settings['auth_denied']); - $authDenied = ($authDeniedActions == array('*') || in_array($action, $authDeniedActions)); - if ($authDenied and !Authsome::get('guest')) { - $controller->Session->setFlash('You are already logged in'); - $controller->redirect(array('controller' => 'users', 'action' => 'dashboard')); - } - - $adminRequiredActions = array_map('strtolower', $this->settings['admin_required']); - $adminRequired = ($adminRequiredActions == array('*') || in_array($action, $adminRequiredActions)); - if ($adminRequired and (Authsome::get('group') != 'administrator')) { - $controller->Session->setFlash('You must be an administrator to access this resource'); - $controller->redirect(array('controller' => 'users', 'action' => 'dashboard')); - } - - $deniedActions = array_map('strtolower', $this->settings['denied']); - $denied = ($deniedActions == array('*') || in_array($action, $deniedActions)); - if ($denied) { - $controller->Session->setFlash('You do not have access to this resource'); - $controller->redirect(array('controller' => 'users', 'action' => 'index')); - } - } -} -?> \ No newline at end of file diff --git a/plugins/sanction/controllers/components/permit.php b/plugins/sanction/controllers/components/permit.php deleted file mode 100644 index c1f48f0..0000000 --- a/plugins/sanction/controllers/components/permit.php +++ /dev/null @@ -1,197 +0,0 @@ - 'Auth.User', - 'check' => 'group_id' - ); - -/** - * Array of routes connected with PermitComponent::access() - * - * @var array - * @access public - */ - var $routes = array(); - - function initialize(&$controller, $config = array()) { - $self =& PermitComponent::getInstance(); - if (!include(CONFIGS . DS . 'permit.php')) { - trigger_error("File containing permissions not found. It should be located at " . APP_PATH . DS . 'config' . DS . "permit.php", E_USER_ERROR); - } - - $self->controller = $controller; - - $self->settings = array_merge($self->settings, $config); - - foreach ($self->routes as $route) { - if (PermitComponent::parse($route['route'])) { - PermitComponent::execute($route); - break; - } - } - } - - function parse(&$route) { - $self =& PermitComponent::getInstance(); - $count = count($route); - if ($count == 0) return false; - - foreach($route as $key => $value) { - if (isset($self->controller->params[$key])) { - $values = (is_array($value)) ? $value : array($value); - foreach ($values as $k => $v) { - if ($self->controller->params[$key] == $v) { - $count--; - } - } - } - } - return ($count == 0); - } - - function execute($route) { - $self =& PermitComponent::getInstance(); - $self->executed = $route; - $self = $self->initializeSessionComponent($self); - - if (empty($route['rules'])) return; - - if (isset($route['rules']['deny'])) { - if ($route['rules']['deny'] == true) $self->redirect($route); - return; - } - - if (!isset($route['rules']['auth'])) return; - - if (is_bool($route['rules']['auth'])) { - $is_authed = $self->session->read("{$self->settings['path']}.{$self->settings['check']}"); - - if ($route['rules']['auth'] == true && !$is_authed) { - $self->redirect($route); - } - if ($route['rules']['auth'] == false && $is_authed) { - $self->redirect($route); - } - return; - } - - $count = count($route['rules']['auth']); - if ($count == 0) return; - - if (($user = $self->session->read("{$self->settings['path']}")) == false) { - $self->redirect($route); - } - - foreach ($route['rules']['auth'] as $field => $value) { - if (!is_array($value)) $value = (array) $value; - foreach ($value as $condition){ - if ($user[$field] == $condition) $count--; - } - } - - if ($count != 0) $self->redirect($route); - } - - function redirect($route) { - $self =& PermitComponent::getInstance(); - - if ($route['message'] != null) { - $message = $route['message']; - $element = $route['element']; - $params = $route['params']; - $self->session->write("Message.{$route['key']}", compact('message', 'element', 'params')); - } - $self->controller->redirect($route['redirect']); - } - - function initializeSessionComponent(&$self) { - if ($self->session != null) return $self; - - App::import('Component', 'Session'); - $componentClass = 'SessionComponent'; - $self->session =& new $componentClass(null); - - if (method_exists($self->session, 'initialize')) { - $self->session->initialize($self->controller); - } - - if (method_exists($self->session, 'startup')) { - $self->session->startup($self->controller); - } - - return $self; - } - -/** - * Gets a reference to the PermitComponent object instance - * - * @return PermitComponent Instance of the PermitComponent. - * @access public - * @static - */ - function &getInstance() { - static $instance = array(); - - if (!$instance) { - $instance[0] =& new PermitComponent(); - } - return $instance[0]; - } - -} - -class Permit extends Object{ - - var $redirect = '/'; - var $clearances = array(); - - function access($route, $rules = array(), $redirect = array()) { - $permitComponent =& PermitComponent::getInstance(); - $self =& Permit::getInstance(); - if (empty($rules)) return $permitComponent->routes; - - $redirect = array_merge(array('redirect' => $self->redirect, - 'message' => __('Access denied', true), - 'trace' => false, - 'element' => 'default', - 'params' => array(), - 'key' => 'flash'), - $redirect); - - $newRoute = array( - 'route' => $route, - 'rules' => $rules, - 'redirect' => $redirect['redirect'], - 'message' => $redirect['message'], - 'element' => $redirect['element'], - 'params' => $redirect['params'], - 'key' => $redirect['key'], - 'trace' => $redirect['trace'] - ); - - $permitComponent->routes[] = $newRoute; - $self->clearances[] = $newRoute; - - return $permitComponent->routes; - } - -/** - * Gets a reference to the Permit object instance - * - * @return Permit Instance of the Permit. - * @access public - * @static - */ - function &getInstance() { - static $instance = array(); - - if (!$instance) $instance[0] =& new Permit(); - return $instance[0]; - } -} -?> \ No newline at end of file diff --git a/plugins/sanction/license b/plugins/sanction/license deleted file mode 100644 index 29840f3..0000000 --- a/plugins/sanction/license +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2010 Jose Diaz-Gonzalez - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/plugins/sanction/models/behaviors/endorsed.php b/plugins/sanction/models/behaviors/endorsed.php deleted file mode 100644 index 293f228..0000000 --- a/plugins/sanction/models/behaviors/endorsed.php +++ /dev/null @@ -1,63 +0,0 @@ - array( - 'group' => 'admin', - ), - 'model_field' => "{$model->alias}_{$model->primaryKey}", - 'authsome_field' => 'id', - ), - $config - ); - - $this->settings[$model->alias] = $config; - } - - function beforeSave(&$model) { - if (!isset($model->id)) return true; - - $settings = $this->settings[$model->alias]; - $count = count($settings['exception']); - $user = Authsome::get(); - - if (!$user) return false; - - foreach ($settings['exception'] as $key => $value) { - if ($user[$model->alias][$key] == $value) { - $count--; - } - } - - if ($count == 0) return true; - - $rec = $model->find('first', array( - 'conditions' => array( - "{$model->alias}.{$settings['model_field']}" => $model->id), - 'contain' => false)); - return $rec[$model->alias][$settings['model_field']] == Authsome::get('authsome_field'); - } - -} -?> \ No newline at end of file diff --git a/plugins/sanction/tests/cases/permit.test.php b/plugins/sanction/tests/cases/permit.test.php deleted file mode 100644 index 183a2d1..0000000 --- a/plugins/sanction/tests/cases/permit.test.php +++ /dev/null @@ -1,304 +0,0 @@ - - * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) - * - * Licensed under The Open Group Test Suite License - * Redistributions of files must retain the above copyright notice. - * - * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests - * @package cake - * @subpackage cake.cake.tests.cases.libs.controller.components - * @since CakePHP(tm) v 1.2.0.5347 - * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License - */ -App::import('Component', array('Sanction.Permit', 'Session')); - -/** -* TestAuthComponent class -* -* @package cake -* @subpackage cake.tests.cases.libs.controller.components -*/ -class TestPermitComponent extends PermitComponent { - -/** - * testStop property - * - * @var bool false - * @access public - */ - var $testStop = false; - -/** - * Sets default login state - * - * @var bool true - * @access protected - */ - var $_loggedIn = true; - -/** - * stop method - * - * @access public - * @return void - */ - function _stop() { - $this->testStop = true; - } -} - -/** -* PermitTestController class -* -* @package cake -* @subpackage cake.tests.cases.libs.controller.components -*/ -class PermitTestController extends Controller { - -/** - * name property - * - * @var string 'AuthTest' - * @access public - */ - var $name = 'AuthTest'; - -/** - * uses property - * - * @var array - * @access public - */ - var $uses = array(); - -/** - * components property - * - * @var array - * @access public - */ - var $components = array('Sanction.Permit', 'Session'); - -/** - * testUrl property - * - * @var mixed null - * @access public - */ - var $testUrl = null; - -/** - * construct method - * - * @access private - * @return void - */ - function __construct() { - $this->params = Router::parse('/auth_test'); - Router::setRequestInfo(array($this->params, array('base' => null, 'here' => '/auth_test', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()))); - parent::__construct(); - } - -/** - * beforeFilter method - * - * @access public - * @return void - */ - function beforeFilter() { - } - -/** - * login method - * - * @access public - * @return void - */ - function login() { - } - -/** - * admin_login method - * - * @access public - * @return void - */ - function admin_login() { - } - -/** - * logout method - * - * @access public - * @return void - */ - function logout() { - // $this->redirect($this->Auth->logout()); - } - -/** - * add method - * - * @access public - * @return void - */ - function add() { - echo "add"; - } - -/** - * add method - * - * @access public - * @return void - */ - function camelCase() { - echo "camelCase"; - } - -/** - * redirect method - * - * @param mixed $url - * @param mixed $status - * @param mixed $exit - * @access public - * @return void - */ - function redirect($url, $status = null, $exit = true) { - $this->testUrl = Router::url($url); - return false; - } - - -/** - * Mock delete method - * - * @param mixed $url - * @param mixed $status - * @param mixed $exit - * @access public - * @return void - */ - function delete($id = null) { - echo 'delete'; - } -} - -/** -* PermitTest class -* -* @package cake -* @subpackage cake.tests.cases.libs.controller.components -*/ -class PermitTest extends CakeTestCase { - -/** - * name property - * - * @var string 'Auth' - * @access public - */ - var $name = 'Permit'; - -/** - * initialized property - * - * @var bool false - * @access public - */ - var $initialized = false; - -/** - * startTest method - * - * @access public - * @return void - */ - function startTest() { - $this->Controller =& new PermitTestController(); - restore_error_handler(); - - $this->Controller->constructClasses(); - $this->Controller->params = array( - 'pass' => array(), 'named' => array(), - 'plugin' => '', 'controller' => 'posts', - 'action' => 'index' - ); - $this->Controller->Component->initialize($this->Controller); - $this->Controller->beforeFilter(); - $this->Controller->Component->startup($this->Controller); - - set_error_handler('simpleTestErrorHandler'); - //$this->Controller->Permit->startup($this->Controller); - ClassRegistry::addObject('view', new View($this->Controller)); - - $this->Controller->Session->delete('Auth'); - $this->Controller->Session->delete('Message.auth'); - - Router::reload(); - - $this->initialized = true; - } - -/** - * endTest method - * - * @access public - * @return void - */ - function endTest() { - $this->Controller->Component->shutdown($this->Controller); - $this->Controller->afterFilter(); - - $this->Controller->Session->delete('Auth'); - $this->Controller->Session->delete('Message.auth'); - ClassRegistry::flush(); - unset($this->Controller); - } - - function testSingleParse() { - $testRoute = array('controller' => 'posts'); - $this->assertTrue($this->Controller->Permit->parse($testRoute)); - - $testRoute = array('controller' => 'posts', 'action' => 'index'); - $this->assertTrue($this->Controller->Permit->parse($testRoute)); - - $testRoute = array('plugin' => null, 'controller' => 'posts', 'action' => 'index'); - $this->assertTrue($this->Controller->Permit->parse($testRoute)); - - $testRoute = array('controller' => 'posts', 'action' => 'add'); - $this->assertFalse($this->Controller->Permit->parse($testRoute)); - - $testRoute = array('controller' => 'users', 'action' => 'index'); - $this->assertFalse($this->Controller->Permit->parse($testRoute)); - } - - function testMultipleParse() { - $testRoute = array('controller' => 'posts', 'action' => array('index')); - $this->assertTrue($this->Controller->Permit->parse($testRoute)); - - $testRoute = array('controller' => 'posts', 'action' => array('index', 'add')); - $this->assertTrue($this->Controller->Permit->parse($testRoute)); - - $testRoute = array('controller' => array('posts', 'users'), 'action' => array('index', 'add')); - $this->assertTrue($this->Controller->Permit->parse($testRoute)); - - $testRoute = array('plugin' => array(null, 'blog'), - 'controller' => array('posts', 'users'), - 'action' => array('index', 'add') - ); - $this->assertTrue($this->Controller->Permit->parse($testRoute)); - - $testRoute = array('controller' => 'posts', 'action' => array('add', 'edit', 'delete')); - $this->assertFalse($this->Controller->Permit->parse($testRoute)); - } -} -?> \ No newline at end of file diff --git a/plugins/sanction/vendors/permit_panel.php b/plugins/sanction/vendors/permit_panel.php deleted file mode 100644 index 796438d..0000000 --- a/plugins/sanction/vendors/permit_panel.php +++ /dev/null @@ -1,16 +0,0 @@ - $permit->clearances, - 'executed' => $permit_component->executed - ); - } -} -?> \ No newline at end of file diff --git a/plugins/sanction/views/elements/permit_panel.ctp b/plugins/sanction/views/elements/permit_panel.ctp deleted file mode 100644 index d0f1c8b..0000000 --- a/plugins/sanction/views/elements/permit_panel.ctp +++ /dev/null @@ -1,8 +0,0 @@ -

-' . __d('sanction', 'Executed Rule', true) . ''; -echo $toolbar->makeNeatArray(array('rule' => $content['executed'])); - -echo '

' . __d('sanction', 'Access Rules', true) . '

'; -echo $toolbar->makeNeatArray($content['clearances']); -?> \ No newline at end of file diff --git a/plugins/sanction/views/helpers/clearance.php b/plugins/sanction/views/helpers/clearance.php deleted file mode 100644 index 06edc06..0000000 --- a/plugins/sanction/views/helpers/clearance.php +++ /dev/null @@ -1,193 +0,0 @@ - 'Auth.User' - ); - -/** - * Sets the $this->helper to the helper configured in the session - * - * @return void - * @access public - * @author Jose Diaz-Gonzalez - **/ - function __construct($config) { - $this->settings = array_merge($config, $this->settings); - } - -/** - * Creates an HTML link. - * - * If $url starts with "http://" this is treated as an external link. Else, - * it is treated as a path to controller/action and parsed against the routes - * included in app/config/permit.php. If there is a match and the User's session - * clears with the rules, it is then sent off to the HtmlHelper::link() method - * - * If the $url is empty, $title is used instead. - * - * ### Options - * - * - `escape` Set to false to disable escaping of title and attributes. - * - * @param string $title The content to be wrapped by tags. - * @param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://) - * @param array $options Array of HTML attributes. - * @param string $confirmMessage JavaScript confirmation message. - * @return string An `` element. - * @access public - * @author Jose Diaz-Gonzalez - */ - function link($title, $url = null, $options = array(), $confirmMessage = false) { - if (!is_array($url)) return $this->Html->link($title, $url, $options, $confirmMessage); - - if (!isset($url['plugin']) && !empty($url['plugin'])) $url['plugin'] = $this->params['plugin']; - if (!isset($url['controller']) && empty($url['controller'])) $url['controller'] = $this->params['controller']; - if (!isset($url['action']) && empty($url['action'])) $url['action'] = $this->params['action']; - - if (empty($this->routes)) { - $permit =& Permit::getInstance(); - - // $permit->clearances should contain an array of all clearances now - $this->routes = $permit->clearances; - } - if (empty($this->routes)) return $this->Html->link($title, $url, $options, $confirmMessage); - - foreach ($this->routes as $route) { - if ($this->parse($url, $route)) { - return $this->execute($route, $title, $url, $options, $confirmMessage); - break; - } - } - - return $this->Html->link($title, $url, $options, $confirmMessage); - } - - -/** - * Parses the passed route against a rule - * - * @param string $currentRoute route being testing - * @param string $route route being tested against - * @return void - * @access public - * @author Jose Diaz-Gonzalez - */ - function parse(&$currentRoute, &$permit) { - $route = $permit['route']; - - $count = count($route); - if ($count == 0) return false; - - foreach($route as $key => $value) { - if (isset($currentRoute[$key])) { - $values = (is_array($value)) ? $value : array($value); - foreach ($values as $k => $v) { - if ($currentRoute[$key] == $v) { - $count--; - } - } - } - } - return $count == 0; - } - - -/** - * Executes the route based on it's rules - * - * @param string $route route being executed - * @param string $title The content to be wrapped by tags. - * @param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://) - * @param array $options Array of HTML attributes. - * @param string $confirmMessage JavaScript confirmation message. - * @return string An `` element. - * @access public - * @author Jose Diaz-Gonzalez - */ - function execute($route, $title, $url = null, $options = array(), $confirmMessage = false) { - if (empty($route['rules'])) return $this->Html->link($title, $url, $options, $confirmMessage); - - if (isset($route['rules']['deny'])) { - return ($route['rules']['deny'] == true) ? null : $this->Html->link($title, $url, $options, $confirmMessage); - } - - if (!isset($route['rules']['auth'])) return $this->Html->link($title, $url, $options, $confirmMessage); - - if (is_bool($route['rules']['auth'])) { - $is_authed = $this->Session->read("{$this->settings['path']}.group"); - - if ($route['rules']['auth'] == true && !$is_authed) { - return; - } - if ($route['rules']['auth'] == false && $is_authed) { - return; - } - return $this->Html->link($title, $url, $options, $confirmMessage); - } - - $count = count($route['rules']['auth']); - if ($count == 0) return $this->Html->link($title, $url, $options, $confirmMessage); - - if (($user = $this->Session->read("{$this->settings['path']}")) == false) { - return; - } - - foreach ($route['rules']['auth'] as $field => $value) { - if ($user[$field] == $value) { - $count--; - } - } - - return ($count != 0) ? null : $this->Html->link($title, $url, $options, $confirmMessage);; - } - -} -?> \ No newline at end of file diff --git a/plugins/searchable/config/migrations/initial_migration.php b/plugins/searchable/config/migrations/initial_migration.php deleted file mode 100644 index 1fb0b2f..0000000 --- a/plugins/searchable/config/migrations/initial_migration.php +++ /dev/null @@ -1,85 +0,0 @@ - array( - 'create_table' => array( - 'search_index' => array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), - 'model' => array('type' => 'string', 'null' => false, 'default' => NULL, 'key' => 'index'), - 'foreign_key' => array('type' => 'integer', 'null' => false, 'default' => NULL), - 'data' => array('type' => 'text', 'null' => false, 'default' => NULL, 'key' => 'index'), - 'name' => array('type' => 'string', 'null' => true, 'default' => NULL), - 'summary' => array('type' => 'text', 'null' => true, 'default' => NULL), - 'url' => array('type' => 'text', 'null' => true, 'default' => NULL), - 'active' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'key' => 'index'), - 'published' => array('type' => 'datetime', 'null' => true, 'default' => NULL), - 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), - 'modified' => array('type' => 'datetime', 'null' => true, 'default' => NULL), - 'indexes' => array( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'model' => array('column' => array('model', 'foreign_key'), 'unique' => 1), - 'active' => array('column' => 'active', 'unique' => 0), - 'data' => array('column' => 'data', 'unique' => 0), - ), - 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM'), - ), - 'settings' => array( - 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), - 'key' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 64, 'key' => 'unique'), - 'value' => array('type' => 'string', 'null' => false, 'default' => NULL), - 'title' => array('type' => 'string', 'null' => false, 'default' => NULL), - 'description' => array('type' => 'string', 'null' => false, 'default' => NULL), - 'input_type' => array('type' => 'string', 'null' => false, 'default' => 'text'), - 'indexes' => array( - 'PRIMARY' => array('column' => 'id', 'unique' => 1), - 'key' => array('column' => 'key', 'unique' => 1), - ), - 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM'), - ), - ), - ), - 'down' => array( - 'drop_table' => array( - 'search_index', 'settings' - ), - ), - ); - -/** - * Before migration callback - * - * @param string $direction, up or down direction of migration process - * @return boolean Should process continue - * @access public - */ - public function before($direction) { - return true; - } - -/** - * After migration callback - * - * @param string $direction, up or down direction of migration process - * @return boolean Should process continue - * @access public - */ - public function after($direction) { - return true; - } -} -?> \ No newline at end of file diff --git a/plugins/searchable/config/migrations/map.php b/plugins/searchable/config/migrations/map.php deleted file mode 100644 index f1eed64..0000000 --- a/plugins/searchable/config/migrations/map.php +++ /dev/null @@ -1,6 +0,0 @@ - array( - 'initial_migration' => 'M4b99be1fadb44683b662c4d6cbdd56cb'), -); -?> \ No newline at end of file diff --git a/plugins/searchable/config/routes.php b/plugins/searchable/config/routes.php deleted file mode 100755 index 46ac1dc..0000000 --- a/plugins/searchable/config/routes.php +++ /dev/null @@ -1,7 +0,0 @@ - 'searchable', - 'controller' => 'search_indexes', - 'action' => 'index', -)); -?> \ No newline at end of file diff --git a/plugins/searchable/config/sql/search_index.sql b/plugins/searchable/config/sql/search_index.sql deleted file mode 100755 index 03fdc34..0000000 --- a/plugins/searchable/config/sql/search_index.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE TABLE `search_index` ( - `id` int(11) NOT NULL auto_increment, - `model` varchar(255) NOT NULL, - `foreign_key` int(11) NOT NULL, - `data` text NOT NULL, - `name` varchar(255) default NULL, - `summary` text, - `url` text, - `active` tinyint(1) NOT NULL default '1', - `published` datetime default NULL, - `created` datetime default NULL, - `modified` datetime default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `model` (`model`,`foreign_key`), - KEY `active` (`active`), - FULLTEXT KEY `data` (`data`) -) ENGINE=MyISAM; \ No newline at end of file diff --git a/plugins/searchable/controllers/search_indexes_controller.php b/plugins/searchable/controllers/search_indexes_controller.php deleted file mode 100755 index 2c98d9c..0000000 --- a/plugins/searchable/controllers/search_indexes_controller.php +++ /dev/null @@ -1,67 +0,0 @@ - array('limit' => 10)); - var $helpers = array('Searchable.Searchable', 'Text'); - - function index($term = null) { - // Redirect with search data in the URL in pretty format - if (!empty($this->data)) { - $redirect = array(); - $redirect['plugin'] = 'searchable'; - $redirect['controller'] = 'search_indexes'; - $redirect['action'] = 'index'; - $redirect['type'] = 'All'; - if (isset($this->data['SearchIndex']['type']) && !empty($this->data['SearchIndex']['type'])) { - $redirect['type'] = $this->data['SearchIndex']['type']; - } elseif (isset($this->params['type']) && $this->params['type'] != 'All') { - $redirect['type'] = $this->params['type']; - } - if (isset($this->data['SearchIndex']['term'])) { - $redirect['term'] = $this->data['SearchIndex']['term']; - } - $this->redirect($redirect); - } - - $term = (!$term && isset($this->params['term'])) ? $this->params['term'] : $term; - // Add default scope condition - // Add published condition NULL or < NOW() - $this->paginate = array( - 'SearchIndex' => array( - 'conditions' => array( - 'SearchIndex.active' => 1, - 'OR' => array( - array('SearchIndex.published' => null), - array('SearchIndex.published <= ' => date('Y-m-d H:i:s')))))); - - // Add type condition if not All - if (isset($this->params['type']) && $this->params['type'] != 'All') { - $this->data['SearchIndex']['type'] = $this->params['type']; - $this->paginate['SearchIndex']['conditions']['model'] = $this->params['type']; - } - - // Add term condition, and sorting - if (isset($term) && $term != 'null') { - $this->data['SearchIndex']['term'] = $term; - App::import('Core', 'Sanitize'); - $term = Sanitize::escape($term); - $this->paginate['SearchIndex']['conditions'][] = array( - 'OR' => array( - "MATCH(SearchIndex.data) AGAINST('$term' IN BOOLEAN MODE)", - 'SearchIndex.data LIKE' => "%{$term}%")); - $this->paginate['SearchIndex']['fields'] = "*, MATCH(SearchIndex.data) AGAINST('$term' IN BOOLEAN MODE) AS score"; - $this->paginate['SearchIndex']['order'] = "score DESC"; - } - - $results = $this->paginate(); - if (count($results) == 1) { - $this->redirect(json_decode($results['0']['SearchIndex']['url'], true)); - } - - // Get types for select drop down - $types = $this->SearchIndex->getTypes(); - $this->set(compact('results', 'term', 'types')); - $this->pageTitle = 'Search'; - } -} -?> \ No newline at end of file diff --git a/plugins/searchable/models/behaviors/searchable.php b/plugins/searchable/models/behaviors/searchable.php deleted file mode 100755 index 89b95d1..0000000 --- a/plugins/searchable/models/behaviors/searchable.php +++ /dev/null @@ -1,410 +0,0 @@ - null, - 'scope' => array(), - 'name' => null, - 'summary' => null, - 'published' => null, - 'url' => null, - ); - -/** - * Records being saved or deleted that the Searchable Behavior transfers to - * the SearchIndex - * - * @var array - * @access protected - */ - var $_records; - -/** - * Initiate SearchableBehavior - * - * @param AppModel $model - * @param array $config Array of options for configuring the Searchable - * Behavior settings for the given model. Keys include: - * - fields - array of fields from the model to include in the search index. - * If omitted, all char, varchar, string, text fields will be included. - * To include data from fields in the current model, just specify the field - * name. E.g. array('title') - * The Searchable Behavior can include data from associated models in the - * Search Index too. This is useful for say Post belongsTo Category, and you - * want the Category name included in the Search Index. - * To achieve this, specify the field name in the current model as the key and - * the model and field in the associated model as the value. E.g. - * array('category_id' => 'Category.name') - * - scope - array of conditions in the form array('field' => 'value') to - * apply to determine whether the record in the Search Index is active or not, - * and therefore whether it should be included in the search results. If - * omitted, the record in the Search Index is always active. - * - name - the field to be used from the Searchable model when populating the - * name field in the Search Index. This is used as the title of a search - * result entry on the results page, and has the link to view the result on - * it. If omitted, the displayField of the model is used. Set to false if you - * don't want the title field to be populated. - * - summary - the field to be used from the Searchable model when populating - * the summary field in the Search Index. This is used as the summary of a - * search result entry on the results page. If omitted, no field is used, and - * the summary will be a series of excerpts from the Search Index data with - * the search terms highlighted. - * - published - the field to be used from the Searchable model when - * populating the published field in the Search Index. This can be used in the - * conditions array when performing the search. If omitted, no field is used, - * and the published field contain NULL. - * - url - array of url elements e.g. controller, action etc. If controller is - * omitted, the controller version of the model is used. If action is omitted, - * view is used, if there are no other non-url paramters (e.g. slug), the - * Searchable Model primary key value is added to the url. - */ - function setup(&$model, $config = array()) { - if (!is_array($config)) { - $config = array($config); - } - - // Add config to settings for given model - $this->settings[$model->alias] = array_merge($this->_defaults, $config); - - // Normalize the fields property using default string types from the model - // schema if not specified, or processing the fields config param passed in. - if (empty($this->settings[$model->alias]['fields'])) { - foreach ($model->schema() as $field => $info) { - if (in_array($info['type'], array('text','varchar','char','string','date'))) { - $this->settings[$model->alias]['fields'][$model->alias.'.'.$field] = $model->alias.'.'.$field; - } - } - } else { - // Ensure fields is in the format array(Model.field => Model.field, ...) - foreach ($this->settings[$model->alias]['fields'] as $field => $modelField) { - unset($this->settings[$model->alias]['fields'][$field]); - if (strpos($modelField, '.') === false) { - $modelField = $model->alias.'.'.$modelField; - } - if (is_numeric($field)) { - $field = $modelField; - } elseif (strpos($field, '.') === false) { - $field = $model->alias.'.'.$field; - } - $this->settings[$model->alias]['fields'][$field] = $modelField; - } - } - - // Set 'name' to false if you don't want to populate the 'name' field - if (!isset($this->settings[$model->alias]['name']) || $this->settings[$model->alias]['name'] !== false) { - $this->settings[$model->alias]['name'] = $model->displayField; - } - - // If url is not an array, make it one - if (!isset($this->settings[$model->alias]['url'])) { - $this->settings[$model->alias]['url'] = array(); - } - - // Add default plugin url component of null - if (!isset($this->settings[$model->alias]['url']['plugin'])) { - $this->settings[$model->alias]['url']['plugin'] = null; - } - // Add default controller url component of controller version of model - if (!isset($this->settings[$model->alias]['url']['controller'])) { - $this->settings[$model->alias]['url']['controller'] = Inflector::pluralize(Inflector::underscore($model->alias)); - } - // Add default action of view - if (!isset($this->settings[$model->alias]['url']['action'])) { - $this->settings[$model->alias]['url']['action'] = 'view'; - } - } - -/** - * Called automatically after saving a model with Searchable attached. - * - * Saves searchable model record being saved's data to Search Index. - * - * @param AppModel $model - * @param boolean $created - */ - function afterSave(&$model, $created) { - $this->setSearchableRecords($model, $created); - $this->saveSearchIndex($model, $created); - } - -/** - * Remembers records being deleted so corresponding records in Search Index - * can be deleted in afterDelete - * - * @param AppModel $model - * @return boolean Always true - */ - function beforeDelete(&$model) { - $this->setSearchableRecords($model); - return true; - } - -/** - * Deletes searchable model record being deleted from Search Index. - * - * @param AppModel $model - */ - function afterDelete(&$model) { - $this->deleteSearchIndex($model); - } - -/** - * Creates array of $model->alias => array($model->id => $model->data) for - * use by afterDelete or afterSave. - * - * @param AppModel $model - * @param boolean $created Indicates whether the record is being/was created - * @param boolean $reset Determines whether to reset the _records property - * before adding new ones. - */ - function setSearchableRecords(&$model, $created = false, $reset = false) { - if ($reset) { - $this->_records = array(); - } - // Set the foreign key from either the model id or the last inserted id - $foreignKey = $model->id; - if (!$foreignKey && $created) { - $foreignKey = $model->getInsertID(); - } - $this->_records[$model->alias][$foreignKey] = $model->data; - } - -/** - * Saves the Search Index record for the corresponding Searchable Model record - * - * @param AppModel $model - * @param boolean $created - */ - function saveSearchIndex(&$model, $created = false) { - $this->SearchIndex = ClassRegistry::init('Searchable.SearchIndex'); - - foreach ($this->_records[$model->alias] as $this->_foreignKey => $this->_modelData) { - $this->_initialiseSearchIndexData($model, $created); - - if (method_exists($model, 'getSearchableData')) { - $data = $model->getSearchableData($this->_modelData); - } else { - $data = $this->_getSearchableData($model); - } - - // Merge data with default or existing data, and json_encode it ready for - // saving the Search Index record. - $this->SearchIndex->data['SearchIndex']['data'] = array_merge($this->SearchIndex->data['SearchIndex']['data'], $data); - $this->SearchIndex->data['SearchIndex']['data'] = json_encode($this->SearchIndex->data['SearchIndex']['data']); - - $this->_setScope($model, $created); - $this->_setExtra($model, 'name'); - $this->_setExtra($model, 'summary'); - $this->_setExtra($model, 'published'); - $this->_setUrl($model, $data); - - $this->SearchIndex->save(); - } - } - -/** - * Enter description here... - */ - function _setUrl(&$model, $data) { - $url = $this->settings[$model->alias]['url']; - $nonStandardUrlComponents = array_diff_key($url, array_flip(array('plugin', 'controller', 'action'))); - - if (empty($nonStandardUrlComponents)) { - $url[] = $this->_foreignKey; - } else { - foreach ($nonStandardUrlComponents as $modelName => $modelFields) { - foreach ($modelFields as $key => $value) { - unset($url[$key]); - if (isset($data["{$modelName}.{$value}"])) { - $value = $data["{$modelName}.{$value}"]; - } - - if(!is_numeric($key)) { - $url[$key] = $value; - } else { - $url[] = $value; - } - } - unset($url[$modelName]); - } - } - $this->SearchIndex->data['SearchIndex']['url'] = json_encode($url); - return; - } - -/** - * Sets extra fields in the Search Index data property with values straight - * from model data (if set). Used for populating the name and summary fields. - * - * @param AppModel $model - * @param string $field - */ - function _setExtra(&$model, $field) { - // If the current model is configured to have this field, just go back - if (!$this->settings[$model->alias][$field]) { - return; - } - - // If the field is not set in the model data property, just go back. In this - // case it will be filled with NULL as that is the default in the DB if the - // record is being created, or, if an edit, the previous value will be set. - if (!isset($this->_modelData[$model->alias][$this->settings[$model->alias][$field]])) { - return; - } - - // Populate the Search Index data property with the value from model data - $this->SearchIndex->data['SearchIndex'][$field] = $this->_cleanValue($this->_modelData[$model->alias][$this->settings[$model->alias][$field]]); - } - -/** - * Sets the active field value in the Search Index data property according - * to the scope of the Searchable Model record - * - * @param AppModel $model - * @param boolean $created - */ - function _setScope(&$model, $created) { - // If the Searchable model doesn't have scope, just go back. - if (empty($this->settings[$model->alias]['scope'])) { - return; - } - - // Check whether the Searchable Model scope has actually been set, i.e. the - // scope data is available in model data. If it is not and the record has - // not just been created, do not explicitly set the active field in the - // Search Index data property - i.e. active will remain unchanged. - $scopeFieldsInModelData = array_intersect_key($this->_modelData[$model->alias], $this->settings[$model->alias]['scope']); - if (empty($scopeFieldsInModelData) && !$created) { - return; - } - - // Find out the scope of the current record in the Searchable Model by - // checking whether it meets the scope conditions - $conditions = $this->settings[$model->alias]['scope'] + array($model->primaryKey => $this->_foreignKey); - $inScope = $model->hasAny($conditions); - - $this->SearchIndex->data['SearchIndex']['active'] = (int) $inScope; - } - -/** - * Returns the data extracted from model->data - * - * @param AppModel $model - * @return array Array of . => - */ - function _getSearchableData(&$model) { - $data = array(); - - // Iterate through the fields configured to be used in the Search Index data - // field identifying the Model.field in the model data and the Model.field - // in the model or associated model data. - foreach ($this->settings[$model->alias]['fields'] as $modelDataSource => $searchDataSource) { - list($modelDataAlias, $modelDataField) = explode('.', $modelDataSource); - - // If the Model.field for the source is not in model data, continue - if (!isset($this->_modelData[$modelDataAlias][$modelDataField])) { - continue; - } - - // Get the value from the model data for the given source Model.field - $value = $this->_modelData[$modelDataAlias][$modelDataField]; - - // If the real value to include in the Search Index data field is actually - // from an associated model, fetch that value - if ($modelDataSource != $searchDataSource) { - list($searchDataAlias, $searchDataField) = explode('.', $searchDataSource); - - // The value from the associated model may already be in model data - if (isset($this->_modelData[$searchDataAlias][$searchDataField])) { - $value = $this->_modelData[$searchDataAlias][$searchDataField]; - } else { // But if it isn't, fetch it from the database. - $modelDataValue = $this->_modelData[$modelDataAlias][$modelDataField]; - $AssocModel = ClassRegistry::init($searchDataAlias); - $AssocModel->id = $modelDataValue; - $value = $AssocModel->field($searchDataField); - } - } - $data[$searchDataSource] = $this->_cleanValue($value); - } - return $data; - } - -/** - * Initialises Search index model id and data properties. - * - * If editing a Searchable Model record, fetch the details of that record from - * the database, so we can merge over the data field keys with the new model - * data. - * - * @param AppModel $model - * @param boolean $created - */ - function _initialiseSearchIndexData(&$model, $created) { - $this->SearchIndex->create(); - if (!$created) { - // Try and find an existing Search index record for this model record - $existing = $this->SearchIndex->find('first', array( - 'conditions' => array( - 'SearchIndex.model' => $model->alias, - 'SearchIndex.foreign_key' => $this->_foreignKey, - ), - ) - ); - // If found, set the id and data properties of the Search Index model - if ($existing) { - $this->SearchIndex->id = $existing['SearchIndex']['id']; - $this->SearchIndex->data = $existing; - // Transform the data field back to an array, ready for replacing the - // values with the new model data - $this->SearchIndex->data['SearchIndex']['data'] = json_decode($this->SearchIndex->data['SearchIndex']['data'], true); - return; - } - } - // We are creating, or the corresponding SearchIndex record was not found, - // so merge the default SearchIndex field values with the details about the - // current model and initialise the data field as an empty array ready for - // populating with data from the model. - $this->SearchIndex->data['SearchIndex'] = array_merge($this->SearchIndex->data['SearchIndex'], array( - 'model' => $model->alias, - 'foreign_key' => $this->_foreignKey, - 'data' => array(), - ) - ); - } - -/** - * Removes html, trims and converts html entities back to normal text. - * - * @param string $value - * @return string - */ - function _cleanValue($value) { - $value = strip_tags($value); - $value = trim($value); - $value = html_entity_decode($value, ENT_COMPAT, 'UTF-8'); - return $value; - } - -/** - * Delete single (identified by $model->id) or all records in the Search Index - * for a particular model. - * - * @param AppModel $model - * @param boolean $all Whether to delete all records or single - * @return boolean Result of - */ - function deleteSearchIndex(&$model, $all = false) { - $conditions = array('SearchIndex.model' => $model->alias); - if (!$all) { - $conditions['SearchIndex.foreign_key'] = $model->id; - } - return ClassRegistry::init('Searchable.SearchIndex')->deleteAll($conditions); - } -} -?> \ No newline at end of file diff --git a/plugins/searchable/models/search_index.php b/plugins/searchable/models/search_index.php deleted file mode 100755 index 797884b..0000000 --- a/plugins/searchable/models/search_index.php +++ /dev/null @@ -1,30 +0,0 @@ -find('all', array('fields' => array('DISTINCT(SearchIndex.model)', 'DISTINCT(SearchIndex.model)'))); - $data = Set::extract('/SearchIndex/model', $data); - $types = array(); - foreach ($data as $type) { - $types[$type] = Inflector::humanize(Inflector::tableize($type)); - } - // Store types in cache - Cache::write('search_index_types', $types); - return $types; - } -} -?> \ No newline at end of file diff --git a/plugins/searchable/searchable_app_controller.php b/plugins/searchable/searchable_app_controller.php deleted file mode 100755 index 3652b01..0000000 --- a/plugins/searchable/searchable_app_controller.php +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/plugins/searchable/searchable_app_model.php b/plugins/searchable/searchable_app_model.php deleted file mode 100755 index 184a74a..0000000 --- a/plugins/searchable/searchable_app_model.php +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/plugins/searchable/vendors/shells/build_search_index.php b/plugins/searchable/vendors/shells/build_search_index.php deleted file mode 100755 index 81c1dfe..0000000 --- a/plugins/searchable/vendors/shells/build_search_index.php +++ /dev/null @@ -1,247 +0,0 @@ -out('Build Search Index Shell'); - $this->hr(); - - // Figure out which db config we are using - $this->_setDbConfig(); - - // Determine the models for the selected db config that have Searchable - $this->_setAvailableModels(); - - // If no args on command line, run interactively - if (empty($this->args)) { - $modelNames = $this->_interactive(); - } else { // Pass command line args off to validate input - $modelNames = $this->_determineModelnames(implode(' ', $this->args)); - } - - foreach ($modelNames as $modelName) { - // Confirm rebuild index for this model - $skip = $this->in(__("Are you sure you want to rebuild the search index for $modelName, 'y' or 'n' or 'q' to exit", true), null, 'n'); - - // Quit if they want to - if (strtolower($skip) === 'q') { - $this->out(__("Exit", true)); - $this->_stop(); - } - - // Skip if they want to - if (strtolower($skip) !== 'y') { - $this->out(__("Skipping " . $modelName, true)); - continue; - } - - // Instantiate the model object - $ModelObj = ClassRegistry::init($modelName); - - // Delete the records in the search index for the current model - if (!$ModelObj->deleteSearchIndex(true)) { - $this->err(__('Could not delete search index', true)); - $this->_stop(); - } - - // Find all records - if (method_exists($ModelObj, 'getAllSearchableData')) { - $records = $ModelObj->getAllSearchableData(); - } else { - $records = $ModelObj->find('all',array('recursive' => 0)); - } - - foreach ($records as $record) { - // Set model->data property - $ModelObj->set($record); - - // Set the _records property of the Searchable Behavior - $ModelObj->setSearchableRecords(false, true); - - // Save the search index record - $ModelObj->saveSearchIndex(true); - - // Report progress - $this->out($ModelObj->alias . ' ' . $ModelObj->id . ' ' . $record[$ModelObj->alias][$ModelObj->displayField]); - } - } - - $this->hr(); - } - -/** - * Sets only or selected db config - */ - function _setDbConfig() { - $this->_useDbConfig = (!empty($this->params['connection'])) ? $this->params['connection'] : 'default'; - } - -/** - * Identifies all models that exist and have Searchable Beahavior attached - */ - function _setAvailableModels() { - // Initialise paths array with paths to app/models - $paths = array(MODELS); - - // Get a list of the plugins - $plugins = Configure::listObjects('plugin'); - - // For each plugin, add the plugin model path to paths and instantiate the - // plugin AppModel in case the plugin contains a model that is Searchable - // and we need to instantiate it later - if(!empty($plugins)) { - foreach($plugins AS $plugin) { - $paths[] = APP . 'plugins' . DS . Inflector::underscore($plugin) . DS . 'models' . DS; - App::import('Model', $plugin . '.' . $plugin . 'Model'); - } - } - - // Get a list of all the models in all the paths and sort them - // alphabetically - $modelNames = Configure::listObjects('model', $paths); - sort($modelNames); - - // Store those that exist and have Searchable attached - foreach ($modelNames as $modelName) { - // Try to import the model - if (!App::import('Model', $modelName, true, $paths)) { - continue; - } - - // If Searchable not attached, skip - if (!ClassRegistry::init($modelName)->Behaviors->attached('Searchable')) { - continue; - } - - // Store model name in class property - $this->_availableModelnames[] = $modelName; - } - } - -/** - * Returns an array of one, multiple or all model names. Displays available - * models with Searchable and prompts the user to make a selection - * - * @return array - */ - function _interactive() { - $this->out(__('Possible Models based on your current database:', true)); - - // List available mode names with numbers for easy selection - $i = 1; - foreach ($this->_availableModelnames as $modelName) { - $this->out($i++ . ". " . $modelName); - } - - // While the user has not made a selection - $enteredModel = ''; - while ($enteredModel == '') { - - // Prompt them for a selection - $enteredModel = $this->in(__("Enter one or more numbers from the list above separated by a space, or type in the names of one or more other models, 'a' for all or 'q' to exit", true), null, 'q'); - - // Quit if they want to - if (strtolower($enteredModel) === 'q') { - $this->out(__("Exit", true)); - $this->_stop(); - } - } - - // Determine the model name from what they entered - return $this->_determineModelnames($enteredModel); - } - -/** - * Determines actual model names based on entered model names - * - * @param string $enteredModel - * @return array Array of model names - */ - function _determineModelnames($enteredModel) { - // If they want all available models return them all - if (strtolower($enteredModel) == 'a' || strtolower($enteredModel) == 'all') { - return $this->_availableModelnames; - } - - // Make an array of the input from the user, by splitting on non - // alphanumeric characters if multiple - if (preg_match('/[^a-z0-9]/i', $enteredModel)) { - $enteredModels = preg_split('/[^a-z0-9]/i', $enteredModel); - } else { // Else make it an array - $enteredModels = array($enteredModel); - } - - // For each value the user entered, check if they entered a number - // corresponding to one of the options, else assume they entered the name of - // the model they want, so camelise it and check it's one of the available - // ones, else, error. - $selectedModelNames = array(); - foreach ($enteredModels as $enteredModel) { - // If a valid number was entered, work out the corresponding model name - if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_availableModelnames) ) { - $selectedModelNames[] = $this->_availableModelnames[intval($enteredModel) - 1]; - // Else, if they entered text that matches an available model name, use that - } elseif (in_array(Inflector::camelize($enteredModel), $this->_availableModelnames)) { - $selectedModelNames[] = Inflector::camelize($enteredModel); - // Else, tell them it didn't work, and send them back to the start - } else { - $this->err(__('You entered an invalid model "'.$enteredModel.'". Please try again.', true)); - return $this->_interactive(); - } - } - - return $selectedModelNames; - } - -/** - * Displays help contents - */ - function help() { - $this->out('CakePHP Build Search Index Shell:'); - $this->hr(); - $this->out('Rebuilds the search index for selected models'); - $this->hr(); - $this->out("Usage: cake build_search_index [all| []...]"); - $this->hr(); - $this->out('Arguments:'); - $this->out("\n\n\tInteractive mode e.g. cake build_search_index"); - $this->out("\nall\n\tBuilds search index for all searchable models e.g. cake build_search_index all"); - $this->out("\n\n\tOne or more CamelCasedModelNames e.g. cake build_search_index Post Category."); - $this->out(""); - } -} -?> \ No newline at end of file diff --git a/plugins/searchable/views/elements/form.ctp b/plugins/searchable/views/elements/form.ctp deleted file mode 100755 index 940b61e..0000000 --- a/plugins/searchable/views/elements/form.ctp +++ /dev/null @@ -1,4 +0,0 @@ -create('SearchIndex', array( - 'url' => array('plugin' => 'searchable', 'controller' => 'search_indexes', 'action' => 'index'))); ?> -input('term', array('label' => 'Search', 'id' => 'SearchSearch')); ?> -end(); ?> diff --git a/plugins/searchable/views/helpers/searchable.php b/plugins/searchable/views/helpers/searchable.php deleted file mode 100755 index a7058fa..0000000 --- a/plugins/searchable/views/helpers/searchable.php +++ /dev/null @@ -1,15 +0,0 @@ -data['SearchIndex']['term'])) ? trim($this->data['SearchIndex']['term']) : ''; - $snippets = ''; - while (strlen($snippets) < 255 && $value = next($data)) { - $snippets .= ' ' . $this->Text->highlight($this->Text->excerpt($value, $term, 20), $term); - } - return $snippets; - } -} -?> diff --git a/plugins/searchable/views/search_indexes/index.ctp b/plugins/searchable/views/search_indexes/index.ctp deleted file mode 100755 index 2be0342..0000000 --- a/plugins/searchable/views/search_indexes/index.ctp +++ /dev/null @@ -1,32 +0,0 @@ -

Search results

-create('SearchIndex', array( - 'url' => array('plugin' => 'searchable', 'controller' => 'search_indexes', 'action' => 'index'))); ?> - input('term', array('label' => 'Search')); ?> - input('type', array('empty' => 'All',)); ?> -end('View Search Results'); ?> - -
    - -
  • -

    link ($result['SearchIndex']['name'], - json_decode($result['SearchIndex']['url'], true)); ?>

    - -

    - - snippets($result['SearchIndex']['data']); ?> - -
  • - -
- params, array_flip(array('type', 'term'))); ?> - - - options(array('url' => $params)); ?> -
- prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> - | numbers();?> - next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?> -
- -

Sorry, your search did not return any matches.

- \ No newline at end of file diff --git a/plugins/webservice/controllers/components/webservice.php b/plugins/webservice/controllers/components/webservice.php deleted file mode 100644 index 1f23e39..0000000 --- a/plugins/webservice/controllers/components/webservice.php +++ /dev/null @@ -1,38 +0,0 @@ -RequestHandler->ext, array('json', 'xml'))) { - $controller->view = 'Webservice.Webservice'; - } - } -} -?> \ No newline at end of file diff --git a/plugins/webservice/views/webservice.php b/plugins/webservice/views/webservice.php deleted file mode 100644 index b59509b..0000000 --- a/plugins/webservice/views/webservice.php +++ /dev/null @@ -1,430 +0,0 @@ -__passedVars); - for ($j = 0; $j < $count; $j++) { - $var = $this->__passedVars[$j]; - $this->{$var} = $controller->{$var}; - } - } - parent::__construct(); - - if ($register) { - ClassRegistry::addObject('view', $this); - } - } - - - function render() { - Configure::write('debug', 0); - if (isset($this->viewVars['debugToolbarPanels'])) unset($this->viewVars['debugToolbarPanels']); - if (isset($this->viewVars['debugToolbarJavascript'])) unset($this->viewVars['debugToolbarJavascript']); - - if ($this->params['url']['ext'] == 'json') { - header("Pragma: no-cache"); - header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate"); - header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); - header("Last-Modified: " . gmdate('D, d M Y H:i:s') . ' GMT'); - header('Content-type: application/json'); - - header("X-JSON: " . $this->object($this->viewVars)); - - return $this->object($this->viewVars); - } - header('Content-type: application/xml'); - return $this->toXml($this->viewVars); - } - -/** - * Dummy method - * - * @deprecated deprecated in Webservice view - */ - function renderLayout() { - } - -/** - * Generates a JavaScript object in JavaScript Object Notation (JSON) - * from an array - * - * ### Options - * - * - block - Wraps the return value in a script tag if true. Default is false - * - prefix - Prepends the string to the returned data. Default is '' - * - postfix - Appends the string to the returned data. Default is '' - * - stringKeys - A list of array keys to be treated as a string. - * - quoteKeys - If false treats $stringKeys as a list of keys **not** to be quoted. Default is true. - * - q - The type of quote to use. Default is '"'. This option only affects the keys, not the values. - * - * @param array $data Data to be converted - * @param array $options Set of options: block, prefix, postfix, stringKeys, quoteKeys, q - * @return string A JSON code block - */ - function object($data = array(), $options = array()) { - if (!empty($options) && !is_array($options)) { - $options = array('block' => $options); - } else if (empty($options)) { - $options = array(); - } - - $defaultOptions = array( - 'block' => false, 'prefix' => '', 'postfix' => '', - 'stringKeys' => array(), 'quoteKeys' => true, 'q' => '"' - ); - $options = array_merge($defaultOptions, $options, array_filter(compact(array_keys($defaultOptions)))); - - if (is_object($data)) { - $data = get_object_vars($data); - } - - $out = $keys = array(); - $numeric = true; - - if ($this->json_useNative) { - $rt = json_encode($data); - } else { - if (is_null($data)) { - return 'null'; - } - if (is_bool($data)) { - return $data ? 'true' : 'false'; - } - - if (is_array($data)) { - $keys = array_keys($data); - } - - if (!empty($keys)) { - $numeric = (array_values($keys) === array_keys(array_values($keys))); - } - - foreach ($data as $key => $val) { - if (is_array($val) || is_object($val)) { - $val = $this->object( - $val, - array_merge($options, array('block' => false, 'prefix' => '', 'postfix' => '')) - ); - } else { - $quoteStrings = ( - !count($options['stringKeys']) || - ($options['quoteKeys'] && in_array($key, $options['stringKeys'], true)) || - (!$options['quoteKeys'] && !in_array($key, $options['stringKeys'], true)) - ); - $val = $this->value($val, $quoteStrings); - } - if (!$numeric) { - $val = $options['q'] . $this->value($key, false) . $options['q'] . ':' . $val; - } - $out[] = $val; - } - - if (!$numeric) { - $rt = '{' . implode(',', $out) . '}'; - } else { - $rt = '[' . implode(',', $out) . ']'; - } - } - - return $rt; - } - -/** - * Converts a PHP-native variable of any type to a JSON-equivalent representation - * - * @param mixed $val A PHP variable to be converted to JSON - * @param boolean $quoteStrings If false, leaves string values unquoted - * @return string a JavaScript-safe/JSON representation of $val - */ - function value($val, $quoteStrings = true) { - switch (true) { - case (is_array($val) || is_object($val)): - $val = $this->object($val); - break; - case ($val === null): - $val = 'null'; - break; - case (is_bool($val)): - $val = !empty($val) ? 'true' : 'false'; - break; - case (is_int($val)): - $val = $val; - break; - case (is_float($val)): - $val = sprintf("%.11f", $val); - break; - default: - $val = $this->escapeString($val); - if ($quoteStrings) { - $val = '"' . $val . '"'; - } - break; - } - return $val; - } - -/** - * Escape a string to be JavaScript friendly. - * - * List of escaped ellements: - * + "\r\n" => '\n' - * + "\r" => '\n' - * + "\n" => '\n' - * + '"' => '\"' - * + "'" => "\\'" - * - * @param string $script String that needs to get escaped. - * @return string Escaped string. - */ - function escapeString($string) { - App::import('Core', 'Multibyte'); - $escape = array("\r\n" => "\n", "\r" => "\n"); - $string = str_replace(array_keys($escape), array_values($escape), $string); - return $this->_utf8ToHex($string); - } - -/** - * Encode a string into JSON. Converts and escapes necessary characters. - * - * @return void - */ - function _utf8ToHex($string) { - $length = strlen($string); - $return = ''; - for ($i = 0; $i < $length; ++$i) { - $ord = ord($string{$i}); - switch (true) { - case $ord == 0x08: - $return .= '\b'; - break; - case $ord == 0x09: - $return .= '\t'; - break; - case $ord == 0x0A: - $return .= '\n'; - break; - case $ord == 0x0C: - $return .= '\f'; - break; - case $ord == 0x0D: - $return .= '\r'; - break; - case $ord == 0x22: - case $ord == 0x2F: - case $ord == 0x5C: - case $ord == 0x27: - $return .= '\\' . $string{$i}; - break; - case (($ord >= 0x20) && ($ord <= 0x7F)): - $return .= $string{$i}; - break; - case (($ord & 0xE0) == 0xC0): - if ($i + 1 >= $length) { - $i += 1; - $return .= '?'; - break; - } - $charbits = $string{$i} . $string{$i + 1}; - $char = Multibyte::utf8($charbits); - $return .= sprintf('\u%04s', dechex($char[0])); - $i += 1; - break; - case (($ord & 0xF0) == 0xE0): - if ($i + 2 >= $length) { - $i += 2; - $return .= '?'; - break; - } - $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2}; - $char = Multibyte::utf8($charbits); - $return .= sprintf('\u%04s', dechex($char[0])); - $i += 2; - break; - case (($ord & 0xF8) == 0xF0): - if ($i + 3 >= $length) { - $i += 3; - $return .= '?'; - break; - } - $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3}; - $char = Multibyte::utf8($charbits); - $return .= sprintf('\u%04s', dechex($char[0])); - $i += 3; - break; - case (($ord & 0xFC) == 0xF8): - if ($i + 4 >= $length) { - $i += 4; - $return .= '?'; - break; - } - $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4}; - $char = Multibyte::utf8($charbits); - $return .= sprintf('\u%04s', dechex($char[0])); - $i += 4; - break; - case (($ord & 0xFE) == 0xFC): - if ($i + 5 >= $length) { - $i += 5; - $return .= '?'; - break; - } - $charbits = $string{$i} . $string{$i + 1} . $string{$i + 2} . $string{$i + 3} . $string{$i + 4} . $string{$i + 5}; - $char = Multibyte::utf8($charbits); - $return .= sprintf('\u%04s', dechex($char[0])); - $i += 5; - break; - } - } - return $return; - } - -/** - * The main function for converting to an XML document. - * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document. - * - * @param array $data - * @param string $rootNodeName - what you want the root node to be - defaultsto data. - * @param SimpleXMLElement $xml - should only be used recursively - * @return string XML - */ - public function toXML($data, $rootNodeName = 'ResultSet', &$xml = null) { - // turn off compatibility mode as simple xml throws a wobbly if you don't. - if (ini_get('zend.ze1_compatibility_mode') == 1) ini_set('zend.ze1_compatibility_mode', 0); - if (is_null($xml)) $xml = simplexml_load_string("<{$rootNodeName} />"); - - // loop through the data passed in. - foreach ($data as $key => $value) { - // no numeric keys in our xml please! - $numeric = false; - if (is_numeric($key)) { - $numeric = 1; - $key = $rootNodeName; - } - - // delete any char not allowed in XML element names - $key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key); - - // if there is another array found recrusively call this function - if (is_array($value)) { - $node = $this->isAssoc($value) || $numeric ? $xml->addChild($key) : $xml; - - // recrusive call. - if ($numeric) $key = 'anon'; - $this->toXml($value, $key, $node); - } else { - // add single node. - $value = htmlentities($value); - $xml->addChild($key, $value); - } - } - - //return $xml->asXML(); - // if you want the XML to be formatted, use the below instead to return the XML - - $doc = new DOMDocument('1.0'); - $doc->preserveWhiteSpace = false; - $doc->loadXML($xml->asXML()); - $doc->formatOutput = true; - return $doc->saveXML(); - } - - -/** - * Convert an XML document to a multi dimensional array - * Pass in an XML document (or SimpleXMLElement object) and this recursively loops through and builds a representative array - * - * @param string $xml - XML document - can optionally be a SimpleXMLElement object - * @return array ARRAY - */ - public function toArray($xml) { - if (is_string($xml)) $xml = new SimpleXMLElement($xml); - - $children = $xml->children(); - if (!$children) return (string) $xml; - - $arr = array(); - foreach ($children as $key => $node) { - $node = $this->toArray($node); - - // support for 'anon' non-associative arrays - if ($key == 'anon') $key = count($arr); - - // if the node is already set, put it into an array - if (isset($arr[$key])) { - if (!is_array($arr[$key]) || $arr[$key][0] == null) $arr[$key] = array($arr[$key]); - $arr[$key][] = $node; - } else { - $arr[$key] = $node; - } - } - return $arr; - } - -/** - * Determine if a variable is an associative array - * - * @param mixed $variable variable to checked for associativity - * @return boolean try if variable is an associative array, false if otherwise - */ - public function isAssoc($variable) { - return (is_array($variable) && 0 !== count(array_diff_key($variable, array_keys(array_keys($variable))))); - } -} -?> \ No newline at end of file diff --git a/plugins/wysiwyg/README.textile b/plugins/wysiwyg/README.textile deleted file mode 100644 index c6b31c3..0000000 --- a/plugins/wysiwyg/README.textile +++ /dev/null @@ -1,53 +0,0 @@ -h2. Wysiwyg Helpers Plugin - -I've been on a small refactoring spree as part of my work on Marcy Avenue. I realize, after years of working with Joomla and Wordpress, that people prefer different WYSIWYG editors. So to alleviate this, I am attempting to build a set of CakePHP helpers for each of the major WYSIWYG editors on the market, and as many small ones as possible. - -The plugin also allows you to automatically change from one WYSIWYG Editor to another when using the WysiwygHelper and configuring it in the controller. You may also change the Editor within the view. - - -h3. Installation - -* Clone from github : in your plugin directory type `git clone git://github.com/josegonzalez/cakephp-wysiwyg-helper.git wysiwyg` -* Add as a git submodule : in your plugin directory type `git submodule add git://github.com/josegonzalez/cakephp-wysiwyg-helper.git wysiwyg` -* Download an archive from github and extract it in `/plugins/wysiwyg` - -* Also download the JS distribution of your editor of choice and install it in your js folder - -h3. Available Helpers - -* Wysiwyg (Wysiwyg.Wysiwyg) -* FCKEditor (Wysiwyg.Fck) -* Nicedit (Wysiwyg.Nicedit) -* Markitup (Wysiwyg.Markitup) -* TinyMCE (Wysiwyg.Tinymce) - -h3. Usage - -h4. WyswigHelper - -# Add the following to the controller where you'd like to use your preferred editor: -## var $helper = array('Wysiwyg.Wysiwyg' => array('editor' => 'fck')); -### You can omit the parameters if you like, the default editor is 'Tinymce' -# Replace your textarea inputs with either of the following: -## $wysiwyg->input("ModelName.fieldName"); -## $wysiwyg->textarea("ModelName.fieldName"); -# Array Options for the FormHelper are contained in the second parameter, while the third parameter contains and array of options for the editor -# Change the editor within the view as follows: -## $wysiwyg->changeEditor('nicedit'); -## Changes come into affect for the proceeding editor -# At this point, everything should theoretically work. - -h4. Other Helpers - -# If hardcoding your editor, you can do the following: -## var $helper = array('Wysiwyg.Nicedit'); -## $nicedit->input("ModelName.fieldName"); -## $nicedit->textarea("ModelName.fieldName"); - -h3. TODO: - -# [-Better code commenting-] -# Figure out how to include the JS distributions -# Enable file-uploading using whatever is native to the editor -# [-Refactor where possible-] -# [-Create a WysiwygHelper that will auto-create the type of helper you want based upon settings given to the view-] \ No newline at end of file diff --git a/plugins/wysiwyg/views/helpers/fck.php b/plugins/wysiwyg/views/helpers/fck.php deleted file mode 100644 index f445399..0000000 --- a/plugins/wysiwyg/views/helpers/fck.php +++ /dev/null @@ -1,143 +0,0 @@ -__field($field); - $options = array_merge( - array( - 'basepath' => $this->Html->base, - 'fckPath' => '/js/fckeditor/', - 'content' => '', - 'toolbarSet' => 'Default', - 'skinPath' => 'editor/skins/', - 'skin' => 'default'), - $options); - - if (!$this->_initialized) { - // We don't want to add this every time, it's only needed once - $this->_initialized = true; - $this->Javascript->link('fckeditor/fckeditor.js', false); - } - - return $this->Javascript->codeBlock( - "window.onload = function() { - var oFCKeditor = new FCKeditor('data[" . $modelFieldPair['model'] . "][" . $modelFieldPair['field'] . "]'); - oFCKeditor.BasePath = \"" . $options['basepath'] . $options['fckPath'] . "\"; - oFCKeditor.Config['SkinPath'] = \"" . $options['fckPath'] . $options['skinPath'] . $options['skin'] . '/' . "\"; - oFCKeditor.Value = \"" . $options['content'] . "\"; - oFCKeditor.ToolbarSet = \"" . $options['toolbarSet'] . "\"; - oFCKeditor.ReplaceTextarea(); - } - ", array('safe' => false, 'inline' => false) - ); - } - -/** -* Creates an fckeditor input field -* -* @param string $field - used to build input name for views, -* @param array $options Array of HTML attributes. -* @param array $fckOptions Array of FckEditor attributes for this input field -* @return string An HTML input element with FckEditor -*/ - function input($field = null, $options = array(), $fckOptions = array()){ - return $this->Form->input($field, $options) . $this->_build($field, $fckOptions); - } - -/** -* Creates an fckeditor textarea -* -* @param string $field - used to build input name for views, -* @param array $options Array of HTML attributes. -* @param array $fckOptions Array of FckEditor attributes for this textarea -* @return string An HTML textarea element with FckEditor -*/ - function textarea($field = null, $options = array(), $fckOptions = array()){ - return $this->Form->textarea($field, $options) . $this->_build($field, $fckOptions); - } - -/** - * Returns the modelname and fieldname for the current string - * - * @return mixed Array containing modelName and/or fieldName, null in all other cases - * @author Jose Diaz-Gonzalez - **/ - function __field($field = null) { - if (empty($field)) { - return null; - } - - $firstToken = strtok($field, '.'); - $secondToken = strtok('.'); - if($secondToken === false) { - $modelName = $this->__defaultModel(); - $fieldName = $firstToken; - } else { - $modelName = $firstToken; - $fieldName = $secondToken; - } - $this->__modelFieldPair = array('model' => $modelName, 'field' => $fieldName); - return $this->__modelFieldPair; - } - -/** - * Gets the default model of the paged sets - * - * @return string Model name or the inflected controller name if the model isn't initialized. Null in all other cases - */ - function __defaultModel() { - if ($this->__defaultModel != null) { - return $this->__defaultModel; - } else { - if (!empty($this->params['controller'])) { - $this->__defaultModel = Inflector::classify($this->params['controller']); - } - } - return $this->__defaultModel; - } -} -?> \ No newline at end of file diff --git a/plugins/wysiwyg/views/helpers/jwysiwyg.php b/plugins/wysiwyg/views/helpers/jwysiwyg.php deleted file mode 100644 index ac0629d..0000000 --- a/plugins/wysiwyg/views/helpers/jwysiwyg.php +++ /dev/null @@ -1,139 +0,0 @@ -__field($field); - - if (!$this->_initialized) { - // We don't want to add this every time, it's only needed once - $this->_initialized = true; - $this->Javascript->link('jwysiwyg/jquery.wysiwyg', false); - } - - $options = Set::merge($this->_defaults, $options); - - return $this->Javascript->codeBlock( - " - jQuery(function () { - jQuery('#" . $modelFieldPair['model'] . $modelFieldPair['field'] . "').wysiwyg(" . $this->Javascript->object($options) . "); - });", - array('safe' => false)); - } - -/** -* Creates an jwysiwyg input field -* -* @param string $field - used to build input name for views, -* @param array $options Array of HTML attributes. -* @param array $nicOptions Array of Jwysiwyg attributes for this input field -* @return string An HTML input field element with Jwysiwyg -*/ - function input($field = null, $options = array(), $nicOptions = array()) { - return $this->Form->input($field, $options) . $this->_build($field, $nicOptions); - } - -/** -* Creates an jwysiwyg textarea -* -* @param string $field - used to build input name for views, -* @param array $options Array of HTML attributes. -* @param array $nicOptions Array of Jwysiwyg attributes for this textarea -* @return string An HTML textarea element with Jwysiwyg -*/ - function textarea($field = null, $options = array(), $nicOptions) { - return $this->Form->textarea($field, $options) . $this->_build($field, $nicOptions); - } - -/** - * Returns the modelname and fieldname for the current string - * - * @return mixed Array containing modelName and/or fieldName, null in all other cases - * @author Jose Diaz-Gonzalez - **/ - function __field($field = null) { - if (empty($field)) { - return null; - } - - $firstToken = strtok($field, '.'); - $secondToken = strtok('.'); - if($secondToken === false) { - $modelName = $this->__defaultModel(); - $fieldName = ucfirst($firstToken); - } else { - $modelName = $firstToken; - $fieldName = ucfirst($secondToken); - } - $this->__modelFieldPair = array('model' => $modelName, 'field' => $fieldName); - return $this->__modelFieldPair; - } - -/** - * Gets the default model of the paged sets - * - * @return string Model name or the inflected controller name if the model isn't initialized. Null in all other cases - */ - function __defaultModel() { - if ($this->__defaultModel != null) { - return $this->__defaultModel; - } else { - if (!empty($this->params['controller'])) { - $this->__defaultModel = Inflector::classify($this->params['controller']); - } - } - return $this->__defaultModel; - } -} -?> \ No newline at end of file diff --git a/plugins/wysiwyg/views/helpers/markitup.php b/plugins/wysiwyg/views/helpers/markitup.php deleted file mode 100644 index 72b03be..0000000 --- a/plugins/wysiwyg/views/helpers/markitup.php +++ /dev/null @@ -1,180 +0,0 @@ -Form->input($field, $options) . $this->editor($field, $options); - } - -/** -* Creates an nicedit textarea -* -* @param string $field - used to build input name for views, -* @param array $options Array of HTML attributes. -* @param array $nicOptions Array of Nicedit attributes for this textarea -* @return string An HTML textarea element with Nicedit -*/ - function textarea($field = null, $options = array()) { - return $this->Form->textarea($field, $options) . $this->editor($field, $options); - } - -/** - * Generates a form textarea element complete with label and wrapper div with markItUp! applied. - * @param string $fieldName This should be "Modelname.fieldname" - * @param array $settings - * @return string An