Index: branches/5.2.x/core/units/admin/admin_events_handler.php
===================================================================
diff -u -N -r14851 -r14870
--- branches/5.2.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 14851)
+++ branches/5.2.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 14870)
@@ -1,6 +1,6 @@
array('self' => true),
'OnClosePopup' => array('self' => true),
'OnSaveSetting' => array('self' => true),
- // export/import permissions is checked within events
- 'OnExportCSV' => Array('self' => true),
- 'OnGetCSV' => Array('self' => true),
- 'OnCSVImportBegin' => Array('self' => true),
- 'OnCSVImportStep' => Array('self' => true),
'OnDropTempTablesByWID' => Array('self' => true),
);
$this->permMapping = array_merge($this->permMapping, $permissions);
@@ -51,7 +46,7 @@
'OnDeploy', 'OnRebuildThemes', 'OnCheckPrefixConfig', 'OnMemoryCacheGet', 'OnMemoryCacheSet'
);
- if (in_array($event->Name, $system_events)) {
+ if ( in_array($event->Name, $system_events) ) {
// events from "Tools -> System Tools" section are controlled via that section "edit" permission
$perm_value = /*$this->Application->isDebugMode() ||*/ $this->Application->CheckPermission($event->getSection() . '.edit');
}
@@ -69,32 +64,53 @@
'OnSqlQuery' => 'in-portal:sql_query.view',
);
- if (array_key_exists($event->Name, $tools_events)) {
+ if ( array_key_exists($event->Name, $tools_events) ) {
$perm_value = $this->Application->CheckPermission($tools_events[$event->Name]);
}
- if ($event->Name == 'OnSaveMenuFrameWidth') {
+ if ( $event->Name == 'OnSaveMenuFrameWidth' ) {
$perm_value = $this->Application->isAdminUser;
}
- if (isset($perm_value)) {
- $perm_helper =& $this->Application->recallObject('PermissionsHelper');
- /* @var $perm_helper kPermissionsHelper */
+ $perm_helper =& $this->Application->recallObject('PermissionsHelper');
+ /* @var $perm_helper kPermissionsHelper */
+ $csv_events = Array ('OnCSVImportBegin', 'OnCSVImportStep', 'OnExportCSV', 'OnGetCSV');
+
+ if ( in_array($event->Name, $csv_events) ) {
+ $csv_helper =& $this->Application->recallObject('CSVHelper');
+ /* @var $csv_helper kCSVHelper */
+
+ $prefix = $csv_helper->getPrefix(stripos($event->Name, 'import') !== false);
+
+ $perm_mapping = Array (
+ 'OnCSVImportBegin' => 'OnProcessSelected',
+ 'OnCSVImportStep' => 'OnProcessSelected',
+ 'OnExportCSV' => 'OnLoad',
+ 'OnGetCSV' => 'OnLoad',
+ );
+
+ $tmp_event = new kEvent($prefix . ':' . $perm_mapping[$event->Name] );
+ $perm_value = $perm_helper->CheckEventPermission($tmp_event, $this->permMapping);
+ }
+
+ if ( isset($perm_value) ) {
return $perm_helper->finalizePermissionCheck($event, $perm_value);
}
return parent::CheckPermission($event);
}
/**
- * Enter description here...
+ * Reset mod-rewrite url cache
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnResetModRwCache(&$event)
+ protected function OnResetModRwCache(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') == 'yes') {
+ if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
}
@@ -110,7 +126,7 @@
* @return void
* @access protected
*/
- protected function OnResetSections(&$event)
+ protected function OnResetSections(kEvent &$event)
{
if ($this->Application->GetVar('ajax') == 'yes') {
$event->status = kEvent::erSTOP;
@@ -127,13 +143,20 @@
$event->SetRedirectParam('action_completed', 1);
}
- function OnResetConfigsCache(&$event)
+ /**
+ * Resets unit config cache
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnResetConfigsCache(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') == 'yes') {
+ if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
}
- if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
$this->Application->rebuildCache('master:config_files', kCache::REBUILD_LATER, CacheSettings::$unitCacheRebuildTime);
}
else {
@@ -152,10 +175,12 @@
* Resets parsed data from unit configs
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnResetParsedData(&$event)
+ protected function OnResetParsedData(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') == 'yes') {
+ if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
}
@@ -185,7 +210,14 @@
$event->SetRedirectParam('action_completed', 1);
}
- function OnCompileTemplates(&$event)
+ /**
+ * Compiles all templates (with a progress bar)
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnCompileTemplates(kEvent &$event)
{
$compiler =& $this->Application->recallObject('NParserCompiler');
/* @var $compiler NParserCompiler */
@@ -198,8 +230,10 @@
* Deletes all compiled templates
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnDeleteCompiledTemplates(&$event)
+ protected function OnDeleteCompiledTemplates(kEvent &$event)
{
if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
@@ -220,7 +254,15 @@
$event->SetRedirectParam('action_completed', 1);
}
- function _deleteCompiledTemplates($folder, $unlink_folder = false)
+ /**
+ * Deletes compiled templates in a given folder
+ *
+ * @param string $folder
+ * @param bool $unlink_folder
+ * @return void
+ * @access protected
+ */
+ protected function _deleteCompiledTemplates($folder, $unlink_folder = false)
{
$sub_folders = glob($folder . '/*', GLOB_ONLYDIR);
@@ -244,34 +286,35 @@
}
/**
- * Generates sturcture for specified table
+ * Generates structure for specified table
*
* @param kEvent $event
- * @author Alex
+ * @return void
+ * @access protected
*/
- function OnGenerateTableStructure(&$event)
+ protected function OnGenerateTableStructure(kEvent &$event)
{
- $types_hash = Array(
+ $types_hash = Array (
'string' => 'varchar|text|mediumtext|longtext|date|datetime|time|timestamp|char|year|enum|set',
'int' => 'smallint|mediumint|int|bigint|tinyint',
'float' => 'float|double|decimal',
);
$table_name = $this->Application->GetVar('table_name');
- if (!$table_name) {
+ if ( !$table_name ) {
echo 'error: no table name specified';
- return ;
+ return;
}
- if (TABLE_PREFIX && !preg_match('/^'.preg_quote(TABLE_PREFIX, '/').'(.*)/', $table_name) && (strtolower($table_name) != $table_name)) {
+ if ( TABLE_PREFIX && !preg_match('/^' . preg_quote(TABLE_PREFIX, '/') . '(.*)/', $table_name) && (strtolower($table_name) != $table_name) ) {
// table name without prefix, then add it (don't affect K3 tables named in lowercase)
- $table_name = TABLE_PREFIX.$table_name;
+ $table_name = TABLE_PREFIX . $table_name;
}
- if (!$this->Conn->TableFound($table_name)) {
+ if ( !$this->Conn->TableFound($table_name) ) {
// table with prefix doesn't exist, assume that just config prefix passed -> resolve table name from it
$prefix = preg_replace('/^' . preg_quote(TABLE_PREFIX, '/') . '/', '', $table_name);
- if ($this->Application->prefixRegistred($prefix)) {
+ if ( $this->Application->prefixRegistred($prefix) ) {
// when prefix is found -> use it's table (don't affect K3 tables named in lowecase)
$table_name = $this->Application->getUnitOption($prefix, 'TableName');
}
@@ -290,23 +333,23 @@
$grid_fields = Array();
$id_field = '';
- $fields = Array();
+ $fields = Array ();
$float_types = Array ('float', 'double', 'numeric');
foreach ($table_info as $field_info) {
- if (preg_match('/l[\d]+_.*/', $field_info['Field'])) {
+ if ( preg_match('/l[\d]+_.*/', $field_info['Field']) ) {
// don't put multilingual fields in config
continue;
}
$field_options = Array ();
- $grid_col_options = Array(
+ $grid_col_options = Array (
'title' => 'la_col_' . $field_info['Field'],
'filter_block' => 'grid_like_filter',
);
// 1. get php field type by mysql field type
foreach ($types_hash as $php_type => $db_types) {
- if (preg_match('/'.$db_types.'/', $field_info['Type'])) {
+ if ( preg_match('/' . $db_types . '/', $field_info['Type']) ) {
$field_options['type'] = $php_type;
break;
}
@@ -316,7 +359,7 @@
$default_value = $field_info['Default'];
$not_null = $field_info['Null'] != 'YES';
- if (is_numeric($default_value)) {
+ if ( is_numeric($default_value) ) {
$default_value = preg_match('/[\.,]/', $default_value) ? (float)$default_value : (int)$default_value;
}
@@ -326,62 +369,61 @@
if ( in_array($php_type, $float_types) ) {
// this is float number
- if (preg_match('/'.$db_types.'\([\d]+,([\d]+)\)/i', $field_info['Type'], $regs)) {
+ if ( preg_match('/' . $db_types . '\([\d]+,([\d]+)\)/i', $field_info['Type'], $regs) ) {
// size is described in structure -> add formatter
$field_options['formatter'] = 'kFormatter';
- $field_options['format'] = '%01.'.$regs[1].'f';
+ $field_options['format'] = '%01.' . $regs[1] . 'f';
- if ($not_null) {
+ if ( $not_null ) {
// null fields, will most likely have NULL as default value
$default_value = 0;
}
}
- elseif ($not_null) {
+ elseif ( $not_null ) {
// no size information, just convert to float
// null fields, will most likely have NULL as default value
$default_value = (float)$default_value;
-
}
}
- if (preg_match('/varchar\(([\d]+)\)/i', $field_info['Type'], $regs)) {
+ if ( preg_match('/varchar\(([\d]+)\)/i', $field_info['Type'], $regs) ) {
$field_options['max_len'] = (int)$regs[1];
}
- if (preg_match('/tinyint\([\d]+\)/i', $field_info['Type'])) {
+ if ( preg_match('/tinyint\([\d]+\)/i', $field_info['Type']) ) {
$field_options['formatter'] = 'kOptionsFormatter';
$field_options['options'] = Array (1 => 'la_Yes', 0 => 'la_No');
$field_options['use_phrases'] = 1;
$grid_col_options['filter_block'] = 'grid_options_filter';
}
- if ($not_null) {
+ if ( $not_null ) {
$field_options['not_null'] = 1;
}
- if ($field_info['Key'] == 'PRI') {
+ if ( $field_info['Key'] == 'PRI' ) {
$default_value = 0;
$id_field = $field_info['Field'];
}
- if ($php_type == 'int' && !$not_null) {
+ if ( $php_type == 'int' && !$not_null ) {
// numeric null field
- if (preg_match('/(On|Date)$/', $field_info['Field']) || $field_info['Field'] == 'Modified') {
+ if ( preg_match('/(On|Date)$/', $field_info['Field']) || $field_info['Field'] == 'Modified' ) {
$field_options['formatter'] = 'kDateFormatter';
$grid_col_options['filter_block'] = 'grid_date_rage_filter';
}
}
- if ($php_type == 'int' && ($not_null || is_numeric($default_value))) {
+ if ( $php_type == 'int' && ($not_null || is_numeric($default_value)) ) {
// is integer field AND not null
$field_options['default'] = (int)$default_value;
}
else {
$field_options['default'] = $default_value;
}
- $fields[ $field_info['Field'] ] = $field_options;
- $grids_fields[ $field_info['Field'] ] = $grid_col_options;
+ $fields[$field_info['Field']] = $field_options;
+ $grids_fields[$field_info['Field']] = $grid_col_options;
}
$grids['Default']['Fields'] = $grids_fields;
@@ -416,10 +458,12 @@
* Refreshes ThemeFiles & Theme tables by actual content on HDD
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnRebuildThemes(&$event)
+ protected function OnRebuildThemes(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') == 'yes') {
+ if ( $this->Application->GetVar('ajax') == 'yes' ) {
$event->status = kEvent::erSTOP;
}
@@ -431,7 +475,14 @@
$event->SetRedirectParam('action_completed', 1);
}
- function OnSaveColumns(&$event)
+ /**
+ * Saves grid column widths after their resize by user
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnSaveColumns(kEvent &$event)
{
$picker_helper =& $this->Application->recallObject('ColumnPickerHelper');
/* @var $picker_helper kColumnPickerHelper */
@@ -451,11 +502,13 @@
* Saves various admin settings via ajax
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnSaveSetting(&$event)
+ protected function OnSaveSetting(kEvent &$event)
{
- if ($this->Application->GetVar('ajax') != 'yes') {
- return ;
+ if ( $this->Application->GetVar('ajax') != 'yes' ) {
+ return;
}
$var_name = $this->Application->GetVar('var_name');
@@ -470,8 +523,10 @@
* Just closes popup & deletes last_template & opener_stack if popup, that is closing
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnClosePopup(&$event)
+ protected function OnClosePopup(kEvent &$event)
{
$event->SetRedirectParam('opener', 'u');
}
@@ -480,11 +535,13 @@
* Occurs right after initialization of the kernel, used mainly as hook-to event
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnStartup(&$event)
+ protected function OnStartup(kEvent &$event)
{
if ( $this->Application->isAdmin ) {
- return ;
+ return;
}
$base_url = preg_quote($this->Application->BaseURL(), '/');
@@ -500,17 +557,22 @@
* Occurs right before echoing the output, in Done method of application, used mainly as hook-to event
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBeforeShutdown(&$event)
+ protected function OnBeforeShutdown(kEvent &$event)
{
+
}
/**
* Is called after tree was build (when not from cache)
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnAfterBuildTree(&$event)
+ protected function OnAfterBuildTree(kEvent &$event)
{
}
@@ -519,114 +581,85 @@
* Called by AJAX to perform CSV export
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnExportCSV(&$event)
+ protected function OnExportCSV(kEvent &$event)
{
- $export_helper =& $this->Application->recallObject('CSVHelper');
- /* @var $export_helper kCSVHelper */
+ $csv_helper =& $this->Application->recallObject('CSVHelper');
+ /* @var $csv_helper kCSVHelper */
- $prefix_special = $this->Application->GetVar('PrefixSpecial');
- if(!$prefix_special) {
- $prefix_special = $export_helper->ExportData('prefix');
- }
- $prefix_elems = preg_split('/\.|_/', $prefix_special, 2);
- $perm_sections = $this->Application->getUnitOption($prefix_elems[0], 'PermSection');
-
- if(!$this->Application->CheckPermission($perm_sections['main'].'.view')) {
- $event->status = kEvent::erPERM_FAIL;
- return ;
- }
-
- $export_helper->PrefixSpecial = $prefix_special;
- $export_helper->grid = $this->Application->GetVar('grid');
- $export_helper->ExportStep();
+ $csv_helper->PrefixSpecial = $csv_helper->getPrefix(false);
+ $csv_helper->grid = $this->Application->GetVar('grid');
+ $csv_helper->ExportStep();
$event->status = kEvent::erSTOP;
}
/**
* Returning created by AJAX CSV file
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnGetCSV(&$event)
+ protected function OnGetCSV(kEvent &$event)
{
- $export_helper =& $this->Application->recallObject('CSVHelper');
- /* @var $export_helper kCSVHelper */
+ $csv_helper =& $this->Application->recallObject('CSVHelper');
+ /* @var $csv_helper kCSVHelper */
- $prefix_special = $export_helper->ExportData('prefix');
- $prefix_elems = preg_split('/\.|_/', $prefix_special, 2);
- $perm_sections = $this->Application->getUnitOption($prefix_elems[0], 'PermSection');
-
- if(!$this->Application->CheckPermission($perm_sections['main'].'.view')) {
- $event->status = kEvent::erPERM_FAIL;
- return ;
- }
-
- $export_helper->GetCSV();
+ $csv_helper->GetCSV();
}
/**
- * Enter description here...
+ * Start CSV import
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnCSVImportBegin(&$event)
+ protected function OnCSVImportBegin(kEvent &$event)
{
- $prefix_special = $this->Application->GetVar('PrefixSpecial');
- $prefix_elems = preg_split('/\.|_/', $prefix_special, 2);
- $perm_sections = $this->Application->getUnitOption($prefix_elems[0], 'PermSection');
-
- if(!$this->Application->CheckPermission($perm_sections['main'].'.add') && !$this->Application->CheckPermission($perm_sections['main'].'.edit')) {
- $event->status = kEvent::erPERM_FAIL;
- return ;
- }
-
- $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object =& $event->getObject(Array ('skip_autoload' => true));
/* @var $object kDBItem */
- $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- $field_values = array_shift($items_info);
- $object->SetFieldsFromHash($field_values);
+ $object->SetFieldsFromHash( $this->getSubmittedFields($event) );
+
$event->redirect = false;
$result = 'required';
- if($object->GetDBField('ImportFile')) {
- $import_helper =& $this->Application->recallObject('CSVHelper');
- /* @var $import_helper kCSVHelper */
- $import_helper->PrefixSpecial = $this->Application->GetVar('PrefixSpecial');
- $import_helper->grid = $this->Application->GetVar('grid');
- $result = $import_helper->ImportStart( $object->GetField('ImportFile', 'file_paths') );
- if($result === true) {
+
+ if ( $object->GetDBField('ImportFile') ) {
+ $csv_helper =& $this->Application->recallObject('CSVHelper');
+ /* @var $csv_helper kCSVHelper */
+
+ $csv_helper->PrefixSpecial = $csv_helper->getPrefix(true);
+ $csv_helper->grid = $this->Application->GetVar('grid');
+ $result = $csv_helper->ImportStart($object->GetField('ImportFile', 'file_paths'));
+
+ if ( $result === true ) {
$event->redirect = $this->Application->GetVar('next_template');
$event->SetRedirectParam('PrefixSpecial', $this->Application->GetVar('PrefixSpecial'));
$event->SetRedirectParam('grid', $this->Application->GetVar('grid'));
}
}
- if($event->redirect === false) {
+ if ( $event->redirect === false ) {
$object->SetError('ImportFile', $result);
$event->status = kEvent::erFAIL;
}
}
/**
- * Enter description here...
+ * Performs one CSV import step
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnCSVImportStep(&$event)
+ protected function OnCSVImportStep(kEvent &$event)
{
$import_helper =& $this->Application->recallObject('CSVHelper');
/* @var $import_helper kCSVHelper */
- $prefix_special = $import_helper->ImportData('prefix');
- $prefix_elems = preg_split('/\.|_/', $prefix_special, 2);
- $perm_sections = $this->Application->getUnitOption($prefix_elems[0], 'PermSection');
-
- if ( !$this->Application->CheckPermission($perm_sections['main'] . '.add') && !$this->Application->CheckPermission($perm_sections['main'] . '.edit') ) {
- $event->status = kEvent::erPERM_FAIL;
- return;
- }
-
$import_helper->ImportStep();
$event->status = kEvent::erSTOP;
}
@@ -635,8 +668,10 @@
* Shows unit config filename, where requested prefix is defined
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnCheckPrefixConfig(&$event)
+ protected function OnCheckPrefixConfig(kEvent &$event)
{
$prefix = $this->Application->GetVar('config_prefix');
$config_file = $this->Application->UnitConfigReader->prefixFiles[$prefix];
@@ -656,37 +691,45 @@
Close Window
Application->ParseBlock(Array('name' => 'incs/footer'));
+ echo $this->Application->ParseBlock(Array ('name' => 'incs/footer'));
echo ob_get_clean();
$event->status = kEvent::erSTOP;
}
- function OnDropTempTablesByWID(&$event)
+ /**
+ * Deletes temp tables, when user closes window using "x" button in top right corner
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnDropTempTablesByWID(kEvent &$event)
{
$sid = $this->Application->GetSID();
$wid = $this->Application->GetVar('m_wid');
$tables = $this->Conn->GetCol('SHOW TABLES');
- $mask_edit_table = '/'.TABLE_PREFIX.'ses_'.$sid.'_'.$wid.'_edit_(.*)$/';
- foreach($tables as $table)
- {
- if( preg_match($mask_edit_table,$table,$rets) )
- {
- $this->Conn->Query('DROP TABLE IF EXISTS '.$table);
+ $mask_edit_table = '/' . TABLE_PREFIX . 'ses_' . $sid . '_' . $wid . '_edit_(.*)$/';
+
+ foreach ($tables as $table) {
+ if ( preg_match($mask_edit_table, $table, $rets) ) {
+ $this->Conn->Query('DROP TABLE IF EXISTS ' . $table);
}
}
+
echo 'OK';
$event->status = kEvent::erSTOP;
- return ;
}
/**
* Backup all data
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBackup(&$event)
+ protected function OnBackup(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -702,8 +745,10 @@
* Perform next backup step
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBackupProgress(&$event)
+ protected function OnBackupProgress(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -723,8 +768,10 @@
* Stops Backup & redirect to Backup template
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnBackupCancel(&$event)
+ protected function OnBackupCancel(kEvent &$event)
{
$event->redirect = 'tools/backup1';
}
@@ -733,8 +780,10 @@
* Starts restore process
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnRestore(&$event)
+ protected function OnRestore(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -743,7 +792,14 @@
$event->redirect = 'tools/restore3';
}
- function OnRestoreProgress(&$event)
+ /**
+ * Performs next restore step
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnRestoreProgress(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -772,8 +828,10 @@
* Stops Restore & redirect to Restore template
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnRestoreCancel(&$event)
+ protected function OnRestoreCancel(kEvent &$event)
{
$event->redirect = 'tools/restore1';
}
@@ -782,8 +840,10 @@
* Deletes one backup file
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnDeleteBackup(&$event)
+ protected function OnDeleteBackup(kEvent &$event)
{
$backup_helper =& $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
@@ -795,37 +855,33 @@
* Starts restore process
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnSqlQuery(&$event)
+ protected function OnSqlQuery(kEvent &$event)
{
$sql = $this->Application->GetVar('sql');
- if ($sql) {
+
+ if ( $sql ) {
$start = microtime(true);
$result = $this->Conn->Query($sql);
$this->Application->SetVar('sql_time', round(microtime(true) - $start, 7));
-
- if ($result)
- {
- if (is_array($result))
- {
+ if ( $result ) {
+ if ( is_array($result) ) {
$this->Application->SetVar('sql_has_rows', 1);
$this->Application->SetVar('sql_rows', serialize($result));
}
}
$check_sql = trim(strtolower($sql));
- if (
- (substr($check_sql, 0, 6) == 'insert')
- || (substr($check_sql, 0, 6) == 'update')
- || (substr($check_sql, 0, 7) == 'replace')
- || (substr($check_sql, 0, 6) == 'delete')
- ) {
+
+ if ( preg_match('/^(insert|update|replace|delete)/', $check_sql) ) {
$this->Application->SetVar('sql_has_affected', 1);
$this->Application->SetVar('sql_affected', $this->Conn->getAffectedRows());
}
-
}
+
$this->Application->SetVar('query_status', 1);
$event->status = kEvent::erFAIL;
}
@@ -834,8 +890,10 @@
* Occurs after unit config cache was successfully rebuilt
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnAfterCacheRebuild(&$event)
+ protected function OnAfterCacheRebuild(kEvent &$event)
{
}
@@ -868,13 +926,15 @@
* Saves menu (tree) frame width
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnSaveMenuFrameWidth(&$event)
+ protected function OnSaveMenuFrameWidth(kEvent &$event)
{
$event->status = kEvent::erSTOP;
- if (!$this->Application->ConfigValue('ResizableFrames')) {
- return ;
+ if ( !$this->Application->ConfigValue('ResizableFrames') ) {
+ return;
}
$this->Application->SetConfigValue('MenuFrameWidth', (int)$this->Application->GetVar('width'));
@@ -884,34 +944,36 @@
* Retrieves data from memory cache
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnMemoryCacheGet(&$event)
+ protected function OnMemoryCacheGet(kEvent &$event)
{
$event->status = kEvent::erSTOP;
$ret = Array ('message' => '', 'code' => 0); // 0 - ok, > 0 - error
$key = $this->Application->GetVar('key');
- if (!$key) {
+ if ( !$key ) {
$ret['code'] = 1;
$ret['message'] = 'Key name missing';
}
else {
$value = $this->Application->getCache($key);
$ret['value'] =& $value;
- $ret['size'] = is_string($value) ? kUtil::formatSize( strlen($value) ) : '?';
+ $ret['size'] = is_string($value) ? kUtil::formatSize(strlen($value)) : '?';
$ret['type'] = gettype($value);
- if (kUtil::IsSerialized($value)) {
+ if ( kUtil::IsSerialized($value) ) {
$value = unserialize($value);
}
- if (is_array($value)) {
+ if ( is_array($value) ) {
$ret['value'] = print_r($value, true);
}
- if ($ret['value'] === false) {
+ if ( $ret['value'] === false ) {
$ret['code'] = 2;
$ret['message'] = 'Key "' . $key . '" doesn\'t exist';
}
@@ -927,15 +989,17 @@
* Retrieves data from memory cache
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnMemoryCacheSet(&$event)
+ protected function OnMemoryCacheSet(kEvent &$event)
{
$event->status = kEvent::erSTOP;
$ret = Array ('message' => '', 'code' => 0); // 0 - ok, > 0 - error
$key = $this->Application->GetVar('key');
- if (!$key) {
+ if ( !$key ) {
$ret['code'] = 1;
$ret['message'] = 'Key name missing';
}
@@ -958,8 +1022,10 @@
* Usage: "php tools/run_event.php adm:OnDeploy b674006f3edb1d9cd4d838c150b0567d"
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnDeploy(&$event)
+ protected function OnDeploy(kEvent &$event)
{
if ( isset($GLOBALS['argv']) ) {
// command line invocation -> don't perform redirect
@@ -978,8 +1044,10 @@
* Synchronizes database revisions from "project_upgrades.sql" file
*
* @param kEvent $event
+ * @return void
+ * @access protected
*/
- function OnSynchronizeDBRevisions(&$event)
+ protected function OnSynchronizeDBRevisions(kEvent &$event)
{
$deployment_helper =& $this->Application->recallObject('DeploymentHelper');
/* @var $deployment_helper DeploymentHelper */
@@ -1001,7 +1069,7 @@
* @return void
* @access protected
*/
- protected function OnOptimizePerformance(&$event)
+ protected function OnOptimizePerformance(kEvent &$event)
{
$start_time = adodb_mktime();
@@ -1021,7 +1089,7 @@
$sid = $matches[1];
- if ( isset($active_sessions[$sid]) || (filemtime($file_path . $file_name) > $start_time ) ) {
+ if ( isset($active_sessions[$sid]) || (filemtime($file_path . $file_name) > $start_time) ) {
// debug file belongs to an active session
// debug file is recently created (after sessions snapshot)
continue;
@@ -1043,17 +1111,24 @@
var $parentPath = Array ();
- function decorate($var, $level = 0)
+ /**
+ * Decorates given array
+ *
+ * @param Array $var
+ * @param int $level
+ * @return string
+ */
+ public function decorate($var, $level = 0)
{
$ret = '';
$deep_level = count($this->parentPath);
- if ($deep_level && ($this->parentPath[0] == 'Fields')) {
+ if ( $deep_level && ($this->parentPath[0] == 'Fields') ) {
$expand = $level < 2;
}
- elseif ($deep_level && ($this->parentPath[0] == 'Grids')) {
- if ($deep_level == 3 && $this->parentPath[2] == 'Icons') {
+ elseif ( $deep_level && ($this->parentPath[0] == 'Grids') ) {
+ if ( $deep_level == 3 && $this->parentPath[2] == 'Icons' ) {
$expand = false;
}
else {
@@ -1064,7 +1139,7 @@
$expand = $level == 0;
}
- if (is_array($var)) {
+ if ( is_array($var) ) {
$ret .= 'Array (';
$prepend = $expand ? "\n" . str_repeat("\t", $level + 1) : '';
@@ -1078,10 +1153,10 @@
$ret = rtrim($ret, ', ') . $prepend . ')';
}
else {
- if (is_null($var)) {
+ if ( is_null($var) ) {
$ret = 'NULL';
}
- elseif (is_string($var)) {
+ elseif ( is_string($var) ) {
$ret = "'" . $var . "'";
}
else {