Changeset View
Changeset View
Standalone View
Standalone View
core/units/configuration/configuration_event_handler.php
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
* @see kDBEventHandler::OnListBuild() | * @see kDBEventHandler::OnListBuild() | ||||
*/ | */ | ||||
protected function SetCustomQuery(kEvent $event) | protected function SetCustomQuery(kEvent $event) | ||||
{ | { | ||||
parent::SetCustomQuery($event); | parent::SetCustomQuery($event); | ||||
/** @var kDBList $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBList */ | |||||
$module = $this->Application->GetVar('module'); | $module = $this->Application->GetVar('module'); | ||||
$section = $this->Application->GetVar('section'); | $section = $this->Application->GetVar('section'); | ||||
$object->addFilter('module_filter', '%1$s.ModuleOwner = ' . $this->Conn->qstr($module)); | $object->addFilter('module_filter', '%1$s.ModuleOwner = ' . $this->Conn->qstr($module)); | ||||
$object->addFilter('section_filter', '%1$s.Section = ' . $this->Conn->qstr($section)); | $object->addFilter('section_filter', '%1$s.Section = ' . $this->Conn->qstr($section)); | ||||
$can_change = $this->Application->ConfigValue('AllowAdminConsoleInterfaceChange'); | $can_change = $this->Application->ConfigValue('AllowAdminConsoleInterfaceChange'); | ||||
Show All 15 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnPreCreate(kEvent $event) | protected function OnPreCreate(kEvent $event) | ||||
{ | { | ||||
parent::OnPreCreate($event); | parent::OnPreCreate($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$object->SetDBField('Section', $this->Application->GetVar('section')); | $object->SetDBField('Section', $this->Application->GetVar('section')); | ||||
$object->SetDBField('ModuleOwner', $this->Application->GetVar('module')); | $object->SetDBField('ModuleOwner', $this->Application->GetVar('module')); | ||||
} | } | ||||
/** | /** | ||||
* Sets custom validation | * Sets custom validation | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemLoad(kEvent $event) | protected function OnAfterItemLoad(kEvent $event) | ||||
{ | { | ||||
static $default_field_options = null; | static $default_field_options = null; | ||||
parent::OnAfterItemLoad($event); | parent::OnAfterItemLoad($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
// ability to validate each configuration variable separately | // ability to validate each configuration variable separately | ||||
if ( !isset($default_field_options) ) { | if ( !isset($default_field_options) ) { | ||||
$default_field_options = $object->GetFieldOptions('VariableValue'); | $default_field_options = $object->GetFieldOptions('VariableValue'); | ||||
} | } | ||||
$new_field_options = $default_field_options; | $new_field_options = $default_field_options; | ||||
$validation = $object->GetDBField('Validation'); | $validation = $object->GetDBField('Validation'); | ||||
Show All 11 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemValidate(kEvent $event) | protected function OnBeforeItemValidate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemValidate($event); | parent::OnBeforeItemValidate($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
// if password field is empty, then don't update | // if password field is empty, then don't update | ||||
if ( $object->GetDBField('ElementType') == 'password' ) { | if ( $object->GetDBField('ElementType') == 'password' ) { | ||||
if ( trim($object->GetDBField('VariableValue')) != '' ) { | if ( trim($object->GetDBField('VariableValue')) != '' ) { | ||||
/** @var kPasswordFormatter $password_formatter */ | |||||
$password_formatter = $this->Application->recallObject('kPasswordFormatter'); | $password_formatter = $this->Application->recallObject('kPasswordFormatter'); | ||||
/* @var $password_formatter kPasswordFormatter */ | |||||
$object->SetDBField('VariableValue', $password_formatter->hashPassword($object->GetDBField('VariableValue'))); | $object->SetDBField('VariableValue', $password_formatter->hashPassword($object->GetDBField('VariableValue'))); | ||||
} | } | ||||
} | } | ||||
$this->_processCountryState($event); | $this->_processCountryState($event); | ||||
$variable_name = $object->GetDBField('VariableName'); | $variable_name = $object->GetDBField('VariableName'); | ||||
Show All 14 Lines | |||||
$object->SetError('VariableValue', 'template_file_missing', 'la_error_TemplateFileMissing'); | $object->SetError('VariableValue', 'template_file_missing', 'la_error_TemplateFileMissing'); | ||||
} | } | ||||
} | } | ||||
elseif ( $variable_name == 'DefaultEmailRecipients' ) { | elseif ( $variable_name == 'DefaultEmailRecipients' ) { | ||||
$email_event_data = $this->Application->GetVar('email-template_' . $event->Prefix); | $email_event_data = $this->Application->GetVar('email-template_' . $event->Prefix); | ||||
$object->SetDBField('VariableValue', $email_event_data[0]['Recipients']); | $object->SetDBField('VariableValue', $email_event_data[0]['Recipients']); | ||||
} | } | ||||
/** @var kSectionsHelper $sections_helper */ | |||||
$sections_helper = $this->Application->recallObject('SectionsHelper'); | $sections_helper = $this->Application->recallObject('SectionsHelper'); | ||||
/* @var $sections_helper kSectionsHelper */ | |||||
$section = $object->GetDBField('Section'); | $section = $object->GetDBField('Section'); | ||||
if ( $section && !$sections_helper->getSectionData($section) ) { | if ( $section && !$sections_helper->getSectionData($section) ) { | ||||
$object->SetError('Section', 'unknown_section'); | $object->SetError('Section', 'unknown_section'); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Checks, that state belongs to selected country | * Checks, that state belongs to selected country | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function _processCountryState(kEvent $event) | protected function _processCountryState(kEvent $event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$country_iso = $this->_getCountryByState($event); | $country_iso = $this->_getCountryByState($event); | ||||
$state_name = $object->GetDBField('VariableValue'); | $state_name = $object->GetDBField('VariableValue'); | ||||
if ( !$country_iso || !$state_name ) { | if ( !$country_iso || !$state_name ) { | ||||
return; | return; | ||||
} | } | ||||
/** @var kCountryStatesHelper $cs_helper */ | |||||
$cs_helper = $this->Application->recallObject('CountryStatesHelper'); | $cs_helper = $this->Application->recallObject('CountryStatesHelper'); | ||||
/* @var $cs_helper kCountryStatesHelper */ | |||||
$state_iso = $cs_helper->getStateIso($state_name, $country_iso); | $state_iso = $cs_helper->getStateIso($state_name, $country_iso); | ||||
if ( $state_iso !== false ) { | if ( $state_iso !== false ) { | ||||
$object->SetDBField('VariableValue', $state_iso); | $object->SetDBField('VariableValue', $state_iso); | ||||
} | } | ||||
else { | else { | ||||
// selected state doesn't belong to selected country | // selected state doesn't belong to selected country | ||||
$object->SetError('VariableValue', 'invalid_state', 'la_InvalidState'); | $object->SetError('VariableValue', 'invalid_state', 'la_InvalidState'); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Returns country iso code, that matches current state variable name | * Returns country iso code, that matches current state variable name | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return bool | * @return bool | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function _getCountryByState(kEvent $event) | protected function _getCountryByState(kEvent $event) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$variable_name = $object->GetDBField('VariableName'); | $variable_name = $object->GetDBField('VariableName'); | ||||
$state_country_hash = Array ( | $state_country_hash = Array ( | ||||
'Comm_State' => 'Comm_Country', | 'Comm_State' => 'Comm_Country', | ||||
'Comm_Shipping_State' => 'Comm_Shipping_Country' | 'Comm_Shipping_State' => 'Comm_Shipping_Country' | ||||
); | ); | ||||
Show All 17 Lines | |||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnBeforeItemUpdate(kEvent $event) | protected function OnBeforeItemUpdate(kEvent $event) | ||||
{ | { | ||||
parent::OnBeforeItemUpdate($event); | parent::OnBeforeItemUpdate($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
// if password field is empty, then don't update | // if password field is empty, then don't update | ||||
if ( $object->GetDBField('ElementType') == 'password' && trim($object->GetDBField('VariableValue')) == '' ) { | if ( $object->GetDBField('ElementType') == 'password' && trim($object->GetDBField('VariableValue')) == '' ) { | ||||
$object->SetFieldOption('VariableValue', 'skip_empty', 1); | $object->SetFieldOption('VariableValue', 'skip_empty', 1); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Occurs after updating item | * Occurs after updating item | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event | ||||
* @return void | * @return void | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function OnAfterItemUpdate(kEvent $event) | protected function OnAfterItemUpdate(kEvent $event) | ||||
{ | { | ||||
static $skin_deleted = false; | static $skin_deleted = false; | ||||
parent::OnAfterItemUpdate($event); | parent::OnAfterItemUpdate($event); | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
if ( $object->GetDBField('ElementType') == 'password' && trim($object->GetDBField('VariableValue')) == '' ) { | if ( $object->GetDBField('ElementType') == 'password' && trim($object->GetDBField('VariableValue')) == '' ) { | ||||
$object->SetFieldOption('VariableValue', 'skip_empty', 0); | $object->SetFieldOption('VariableValue', 'skip_empty', 0); | ||||
} | } | ||||
// allows to check if variable's value was changed now | // allows to check if variable's value was changed now | ||||
$variable_name = $object->GetDBField('VariableName'); | $variable_name = $object->GetDBField('VariableName'); | ||||
$changed = $this->Application->GetVar($event->getPrefixSpecial() . '_changed', Array ()); | $changed = $this->Application->GetVar($event->getPrefixSpecial() . '_changed', Array ()); | ||||
Show All 12 Lines | |||||
WHERE VariableName LIKE "' . $sorting_prefix . '%Sortings.%"'; | WHERE VariableName LIKE "' . $sorting_prefix . '%Sortings.%"'; | ||||
$this->Conn->Query($sql); | $this->Conn->Query($sql); | ||||
} | } | ||||
} | } | ||||
if ( $variable_name == 'Require_AdminSSL' || $variable_name == 'AdminSSL_URL' ) { | if ( $variable_name == 'Require_AdminSSL' || $variable_name == 'AdminSSL_URL' ) { | ||||
// when administrative console is moved to SSL mode, then delete skin | // when administrative console is moved to SSL mode, then delete skin | ||||
if ( in_array($variable_name, $changed) && !$skin_deleted ) { | if ( in_array($variable_name, $changed) && !$skin_deleted ) { | ||||
/** @var SkinHelper $skin_helper */ | |||||
$skin_helper = $this->Application->recallObject('SkinHelper'); | $skin_helper = $this->Application->recallObject('SkinHelper'); | ||||
/* @var $skin_helper SkinHelper */ | |||||
$skin_file = $skin_helper->getSkinPath(); | $skin_file = $skin_helper->getSkinPath(); | ||||
if ( file_exists($skin_file) ) { | if ( file_exists($skin_file) ) { | ||||
unlink($skin_file); | unlink($skin_file); | ||||
} | } | ||||
$skin_deleted = true; | $skin_deleted = true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
$items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); | $items_info = $this->Application->GetVar($event->getPrefixSpecial(true)); | ||||
// 1. save user selected module root category | // 1. save user selected module root category | ||||
$new_category_id = getArrayValue($items_info, 'ModuleRootCategory', 'VariableValue'); | $new_category_id = getArrayValue($items_info, 'ModuleRootCategory', 'VariableValue'); | ||||
if ( $new_category_id !== false ) { | if ( $new_category_id !== false ) { | ||||
unset($items_info['ModuleRootCategory']); | unset($items_info['ModuleRootCategory']); | ||||
} | } | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject( Array('skip_autoload' => true) ); | $object = $event->getObject( Array('skip_autoload' => true) ); | ||||
Lint: Generic.PHP.LowerCaseKeyword.Found: PHP keywords must be lowercase; expected "array" but found "Array" | |||||
Expected 0 spaces before closing bracket; 1 found Lint: CodingStandard.Functions.FunctionCallSignature.SpaceBeforeCloseBracket: Expected 0 spaces before closing bracket; 1 found | |||||
Space after opening parenthesis of function call prohibited Lint: PSR2.Methods.FunctionCallSignature.SpaceAfterOpenBracket: Space after opening parenthesis of function call prohibited | |||||
Space after opening parenthesis of function call prohibited Lint: CodingStandard.Functions.FunctionCallSignature.SpaceAfterOpenBracket: Space after opening parenthesis of function call prohibited | |||||
Expected 0 spaces before closing bracket; 1 found Lint: PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket: Expected 0 spaces before closing bracket; 1 found | |||||
/* @var $object kDBItem */ | |||||
if ( $items_info ) { | if ( $items_info ) { | ||||
$has_error = false; | $has_error = false; | ||||
foreach ($items_info as $id => $field_values) { | foreach ($items_info as $id => $field_values) { | ||||
$object->Clear(); // clear validation errors from previous variable | $object->Clear(); // clear validation errors from previous variable | ||||
$object->Load($id); | $object->Load($id); | ||||
$object->SetFieldsFromHash($field_values); | $object->SetFieldsFromHash($field_values); | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | |||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function _generateMaintenancePage($template = null) | protected function _generateMaintenancePage($template = null) | ||||
{ | { | ||||
if ( !isset($template) ) { | if ( !isset($template) ) { | ||||
$template = $this->Application->ConfigValue('HardMaintenanceTemplate'); | $template = $this->Application->ConfigValue('HardMaintenanceTemplate'); | ||||
} | } | ||||
/** @var kCurlHelper $curl_helper */ | |||||
$curl_helper = $this->Application->recallObject('CurlHelper'); | $curl_helper = $this->Application->recallObject('CurlHelper'); | ||||
/* @var $curl_helper kCurlHelper */ | |||||
$html = $curl_helper->Send($this->Application->BaseURL() . '?t=' . $template); | $html = $curl_helper->Send($this->Application->BaseURL() . '?t=' . $template); | ||||
if ( $curl_helper->isGoodResponseCode() ) { | if ( $curl_helper->isGoodResponseCode() ) { | ||||
file_put_contents(WRITEABLE . DIRECTORY_SEPARATOR . 'maintenance.html', $html); | file_put_contents(WRITEABLE . DIRECTORY_SEPARATOR . 'maintenance.html', $html); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Returns auto-complete values for ajax-dropdown | * Returns auto-complete values for ajax-dropdown | ||||
* | * | ||||
* @param kEvent $event Event. | * @param kEvent $event Event. | ||||
* @param string $term Term. | * @param string $term Term. | ||||
* | * | ||||
* @return Array | * @return Array | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected function getAutoCompleteSuggestions(kEvent $event, $term) | protected function getAutoCompleteSuggestions(kEvent $event, $term) | ||||
{ | { | ||||
/** @var kDBItem $object */ | |||||
$object = $event->getObject(); | $object = $event->getObject(); | ||||
/* @var $object kDBItem */ | |||||
$field = $this->Application->GetVar('field'); | $field = $this->Application->GetVar('field'); | ||||
if ( !$field || !$term || !$object->isField($field) ) { | if ( !$field || !$term || !$object->isField($field) ) { | ||||
return array(); | return array(); | ||||
} | } | ||||
$limit = $this->Application->GetVar('limit'); | $limit = $this->Application->GetVar('limit'); | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
PHP keywords must be lowercase; expected "array" but found "Array"