Code Review Changes

- Refactored code to include constants
- Fixed comment formatting issues
This commit is contained in:
objecttothis
2020-05-20 13:48:24 +04:00
parent f5424a3ed2
commit 145f49d247
2 changed files with 30 additions and 30 deletions

View File

@@ -62,12 +62,12 @@ class Config extends Secure_Controller
}
elseif($fileinfo->getBasename() == 'bower.LICENSES')
{
// set a flag to indicate that the JS Plugin bower.LICENSES file is available and needs to be attached at the end
// set a flag to indicate that the JS Plugin bower.LICENSES file is available and needs to be attached at the end
$bower = TRUE;
}
elseif($fileinfo->getBasename() == 'composer.LICENSES')
{
// set a flag to indicate that the composer.LICENSES file is available and needs to be attached at the end
// set a flag to indicate that the composer.LICENSES file is available and needs to be attached at the end
$composer = TRUE;
}
}
@@ -125,7 +125,7 @@ class Config extends Secure_Controller
$license[$i]['text'] = $this->xss_clean($license[$i]['text']);
}
// attach the licenses from the LICENSES file generated by bower
// attach the licenses from the LICENSES file generated by bower
if($bower)
{
++$i;
@@ -177,7 +177,7 @@ class Config extends Secure_Controller
{
$themes = array();
// read all themes in the dist folder
// read all themes in the dist folder
$dir = new DirectoryIterator('dist/bootswatch');
foreach($dir as $dirinfo)
@@ -213,10 +213,10 @@ class Config extends Secure_Controller
$data = $this->xss_clean($data);
// load all the license statements, they are already XSS cleaned in the private function
// load all the license statements, they are already XSS cleaned in the private function
$data['licenses'] = $this->_licenses();
// load all the themes, already XSS cleaned in the private function
// load all the themes, already XSS cleaned in the private function
$data['themes'] = $this->_themes();
$data['mailchimp'] = array();
@@ -231,7 +231,7 @@ class Config extends Secure_Controller
$data['mailchimp']['list_id'] = '';
}
// load mailchimp lists associated to the given api key, already XSS cleaned in the private function
// load mailchimp lists associated to the given api key, already XSS cleaned in the private function
$data['mailchimp']['lists'] = $this->_mailchimp();
$this->load->view("configs/manage", $data);
@@ -305,14 +305,14 @@ class Config extends Secure_Controller
$definition_data['definition_name'] = 'ospos_category';
$definition_data['definition_flags'] = 0;
$definition_data['definition_type'] = 'DROPDOWN';
$definition_data['definition_id'] = -1;
$definition_data['definition_id'] = CATEGORY_DEFINITION_ID;
$definition_data['deleted'] = 0;
$this->Attribute->save_definition($definition_data, -1);
$this->Attribute->save_definition($definition_data, CATEGORY_DEFINITION_ID);
}
else if($batch_save_data['category_dropdown'] == 0)
else if($batch_save_data['category_dropdown'] == NO_DEFINITION_ID)
{
$this->Attribute->delete_definition(-1);
$this->Attribute->delete_definition(CATEGORY_DEFINITION_ID);
}
$result = $this->Appconfig->batch_save($batch_save_data);
@@ -569,7 +569,7 @@ class Config extends Secure_Controller
{
$location_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
// save or update
// save or update
$location_data = array('location_name' => $value);
if($this->Stock_location->save($location_data, $location_id))
{
@@ -580,7 +580,7 @@ class Config extends Secure_Controller
}
}
// all locations not available in post will be deleted now
// all locations not available in post will be deleted now
$deleted_locations = $this->Stock_location->get_all()->result_array();
foreach($deleted_locations as $location => $location_data)
@@ -619,7 +619,7 @@ class Config extends Secure_Controller
$dinner_table_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
$not_to_delete[] = $dinner_table_id;
// save or update
// save or update
$table_data = array('name' => $value);
if($this->Dinner_table->save($table_data, $dinner_table_id))
{
@@ -628,7 +628,7 @@ class Config extends Secure_Controller
}
}
// all tables not available in post will be deleted now
// all tables not available in post will be deleted now
$deleted_tables = $this->Dinner_table->get_all()->result_array();
foreach($deleted_tables as $dinner_tables => $table)
@@ -855,7 +855,7 @@ class Config extends Secure_Controller
{
$this->load->helper('directory');
// load upload library
// load upload library
$config = array('upload_path' => './uploads/',
'allowed_types' => 'gif|jpg|png',
'max_size' => '1024',
@@ -872,42 +872,42 @@ class Config extends Secure_Controller
{
$encryption_key = $this->config->item('encryption_key');
// check if the encryption_key config item is the default one
// check if the encryption_key config item is the default one
if($encryption_key == '' || $encryption_key == 'YOUR KEY')
{
// Config path
// Config path
$config_path = APPPATH . 'config/config.php';
// Open the file
// Open the file
$config = file_get_contents($config_path);
// $key will be assigned a 32-byte (256-bit) hex-encoded random key
// $key will be assigned a 32-byte (256-bit) hex-encoded random key
$key = bin2hex($this->encryption->create_key(32));
// set the encryption key in the config item
// set the encryption key in the config item
$this->config->set_item('encryption_key', $key);
// replace the empty placeholder with a real randomly generated encryption key
// replace the empty placeholder with a real randomly generated encryption key
$config = preg_replace("/(.*encryption_key.*)('');/", "$1'$key';", $config);
$result = FALSE;
// Chmod the file
// Chmod the file
@chmod($config_path, 0777);
// Verify file permissions
// Verify file permissions
if(is_writable($config_path))
{
// Write the new config.php file
// Write the new config.php file
$handle = @fopen($config_path, 'w+');
// Write the file
// Write the file
$result = (fwrite($handle, $config) === FALSE) ? FALSE : TRUE;
fclose($handle);
}
// Chmod the file
// Chmod the file
@chmod($config_path, 0444);
return $result;
@@ -937,7 +937,7 @@ class Config extends Secure_Controller
{
ob_end_clean();
}
force_download($file_name, $backup);
}
else

View File

@@ -6,8 +6,8 @@ define('DECIMAL', 'DECIMAL');
define('DATE', 'DATE');
define('TEXT', 'TEXT');
define('CHECKBOX', 'CHECKBOX');
define(NO_DEFINITION_ID,0);
define(CATEGORY_DEFINITION_ID,-1);
define(NO_DEFINITION_ID, 0);
define(CATEGORY_DEFINITION_ID, -1);
const DEFINITION_TYPES = [GROUP, DROPDOWN, DECIMAL, TEXT, DATE, CHECKBOX];