From e6c250128f1c084d89b61097fa26a90ac1647f4e Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Fri, 23 Feb 2024 17:20:46 +0100 Subject: [PATCH 1/4] reduced function and added username to path --- application/models/Eqsl_images.php | 12 +++++------- application/models/Qsl_model.php | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/application/models/Eqsl_images.php b/application/models/Eqsl_images.php index 92e0c5ad9..e25146db3 100644 --- a/application/models/Eqsl_images.php +++ b/application/models/Eqsl_images.php @@ -40,17 +40,15 @@ class Eqsl_images extends CI_Model { $eqsl_dir = "eqsl_card"; // test if new folder directory exist // $userdata_dir = $this->config->item('userdata'); + $user_name = $this->session->userdata('user_name'); if (isset($userdata_dir)) { - if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir)) { - mkdir(realpath(APPPATH.'../').'/'.$userdata_dir, 0755, true); - } - if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$eqsl_dir)) { - mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$eqsl_dir, 0755, true); + if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir)) { + mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir, 0755, true); } if ($pathorurl=='u') { - return $userdata_dir.'/'.$eqsl_dir; + return $userdata_dir.'/'.$user_name.'/'.$eqsl_dir; } else { - return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$eqsl_dir; + return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir; } } else { return 'images/eqsl_card_images'; diff --git a/application/models/Qsl_model.php b/application/models/Qsl_model.php index 4a6e6f0d4..84397e906 100644 --- a/application/models/Qsl_model.php +++ b/application/models/Qsl_model.php @@ -133,17 +133,15 @@ class Qsl_model extends CI_Model { $qsl_dir = "qsl_card"; // test if new folder directory exist // $userdata_dir = $this->config->item('userdata'); + $user_name = $this->session->userdata('user_name'); if (isset($userdata_dir)) { - if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir)) { - mkdir(realpath(APPPATH.'../').'/'.$userdata_dir, 0755, true); - } - if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$qsl_dir)) { - mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$qsl_dir, 0755, true); + if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir)) { + mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir, 0755, true); } if ($pathorurl=='u') { - return $userdata_dir.'/'.$qsl_dir; + return $userdata_dir.'/'.$user_name.'/'.$qsl_dir; } else { - return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$qsl_dir; + return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir; } } else { return 'assets/qslcard'; From 126397b6c10c8e4c482c0353fa26e8ab7f81aede Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Fri, 23 Feb 2024 22:04:35 +0100 Subject: [PATCH 2/4] improve readability --- application/models/Eqsl_images.php | 44 +++++++++++++++++++----------- application/models/Qsl_model.php | 44 +++++++++++++++++++----------- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/application/models/Eqsl_images.php b/application/models/Eqsl_images.php index e25146db3..7d7e23443 100644 --- a/application/models/Eqsl_images.php +++ b/application/models/Eqsl_images.php @@ -35,24 +35,36 @@ class Eqsl_images extends CI_Model { return $this->db->get('eQSL_images'); } - // return path of eQsl file : u=url / p=real path // + // return path of eQsl file : u=url / p=real path function get_imagePath($pathorurl='u') { - $eqsl_dir = "eqsl_card"; - // test if new folder directory exist // - $userdata_dir = $this->config->item('userdata'); + + // check if there is a user_name in the session data and it's not emoty $user_name = $this->session->userdata('user_name'); - if (isset($userdata_dir)) { - if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir)) { - mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir, 0755, true); - } - if ($pathorurl=='u') { - return $userdata_dir.'/'.$user_name.'/'.$eqsl_dir; - } else { - return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir; - } - } else { - return 'images/eqsl_card_images'; - } + if ($user_name != '') { + + $eqsl_dir = "eqsl_card"; + + // test if new folder directory exist + $userdata_dir = $this->config->item('userdata'); + if (isset($userdata_dir)) { + + // create the folder + if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir)) { + mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir, 0755, true); + } + + // and return it + if ($pathorurl=='u') { + return $userdata_dir.'/'.$user_name.'/'.$eqsl_dir; + } else { + return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir; + } + } else { + + // if the config option is not set we just return the old path + return 'images/eqsl_card_images'; + } + } } } diff --git a/application/models/Qsl_model.php b/application/models/Qsl_model.php index 84397e906..077764269 100644 --- a/application/models/Qsl_model.php +++ b/application/models/Qsl_model.php @@ -128,23 +128,35 @@ class Qsl_model extends CI_Model { return $this->db->insert_id(); } - // return path of Qsl file : u=url / p=real path // + // return path of Qsl file : u=url / p=real path function get_imagePath($pathorurl='u') { - $qsl_dir = "qsl_card"; - // test if new folder directory exist // - $userdata_dir = $this->config->item('userdata'); + + // check if there is a user_name in the session data and it's not emoty $user_name = $this->session->userdata('user_name'); - if (isset($userdata_dir)) { - if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir)) { - mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir, 0755, true); - } - if ($pathorurl=='u') { - return $userdata_dir.'/'.$user_name.'/'.$qsl_dir; - } else { - return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir; - } - } else { - return 'assets/qslcard'; - } + if ($user_name != '') { + + $qsl_dir = "qsl_card"; + + // test if new folder directory exist + $userdata_dir = $this->config->item('userdata'); + if (isset($userdata_dir)) { + + // create the folder + if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir)) { + mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir, 0755, true); + } + + // and return it + if ($pathorurl=='u') { + return $userdata_dir.'/'.$user_name.'/'.$qsl_dir; + } else { + return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir; + } + } else { + + // if the config option is not set we just return the old path + return 'assets/qslcard'; + } + } } } From fa3b6af75386c1646ddbf734857b5dc18c287296 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sat, 24 Feb 2024 07:49:11 +0100 Subject: [PATCH 3/4] take user_id instead user_name --- application/models/Eqsl_images.php | 14 +++++++------- application/models/Qsl_model.php | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/application/models/Eqsl_images.php b/application/models/Eqsl_images.php index 7d7e23443..8bd806bcd 100644 --- a/application/models/Eqsl_images.php +++ b/application/models/Eqsl_images.php @@ -38,9 +38,9 @@ class Eqsl_images extends CI_Model { // return path of eQsl file : u=url / p=real path function get_imagePath($pathorurl='u') { - // check if there is a user_name in the session data and it's not emoty - $user_name = $this->session->userdata('user_name'); - if ($user_name != '') { + // check if there is a user_id in the session data and it's not empty + $user_id = $this->session->userdata('user_id'); + if ($user_id != '') { $eqsl_dir = "eqsl_card"; @@ -49,15 +49,15 @@ class Eqsl_images extends CI_Model { if (isset($userdata_dir)) { // create the folder - if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir)) { - mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir, 0755, true); + if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir)) { + mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir, 0755, true); } // and return it if ($pathorurl=='u') { - return $userdata_dir.'/'.$user_name.'/'.$eqsl_dir; + return $userdata_dir.'/'.$user_id.'/'.$eqsl_dir; } else { - return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$eqsl_dir; + return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir; } } else { diff --git a/application/models/Qsl_model.php b/application/models/Qsl_model.php index 077764269..2f3f2e1d1 100644 --- a/application/models/Qsl_model.php +++ b/application/models/Qsl_model.php @@ -131,9 +131,9 @@ class Qsl_model extends CI_Model { // return path of Qsl file : u=url / p=real path function get_imagePath($pathorurl='u') { - // check if there is a user_name in the session data and it's not emoty - $user_name = $this->session->userdata('user_name'); - if ($user_name != '') { + // check if there is a user_id in the session data and it's not empty + $user_id = $this->session->userdata('user_id'); + if ($user_id != '') { $qsl_dir = "qsl_card"; @@ -142,15 +142,15 @@ class Qsl_model extends CI_Model { if (isset($userdata_dir)) { // create the folder - if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir)) { - mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir, 0755, true); + if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$qsl_dir)) { + mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$qsl_dir, 0755, true); } // and return it if ($pathorurl=='u') { - return $userdata_dir.'/'.$user_name.'/'.$qsl_dir; + return $userdata_dir.'/'.$user_id.'/'.$qsl_dir; } else { - return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_name.'/'.$qsl_dir; + return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$qsl_dir; } } else { From e00fc29c426b6272f10765945510f82d4fa95675 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Sat, 24 Feb 2024 08:49:40 +0100 Subject: [PATCH 4/4] first check config option before everything else --- application/models/Eqsl_images.php | 28 ++++++++++++++++------------ application/models/Qsl_model.php | 30 +++++++++++++++++------------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/application/models/Eqsl_images.php b/application/models/Eqsl_images.php index 8bd806bcd..ab18f05f5 100644 --- a/application/models/Eqsl_images.php +++ b/application/models/Eqsl_images.php @@ -38,16 +38,18 @@ class Eqsl_images extends CI_Model { // return path of eQsl file : u=url / p=real path function get_imagePath($pathorurl='u') { - // check if there is a user_id in the session data and it's not empty - $user_id = $this->session->userdata('user_id'); - if ($user_id != '') { + // test if new folder directory option is enabled + $userdata_dir = $this->config->item('userdata'); + + if (isset($userdata_dir)) { - $eqsl_dir = "eqsl_card"; - - // test if new folder directory exist - $userdata_dir = $this->config->item('userdata'); - if (isset($userdata_dir)) { + $eqsl_dir = "eqsl_card"; + $user_id = $this->session->userdata('user_id'); + + // check if there is a user_id in the session data and it's not empty + if ($user_id != '') { + // create the folder if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir)) { mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir, 0755, true); @@ -60,11 +62,13 @@ class Eqsl_images extends CI_Model { return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$eqsl_dir; } } else { + log_message('Error', 'Can not get eqsl image path because no user_id in session data'); + } + } else { - // if the config option is not set we just return the old path - return 'images/eqsl_card_images'; - } - } + // if the config option is not set we just return the old path + return 'images/eqsl_card_images'; + } } } diff --git a/application/models/Qsl_model.php b/application/models/Qsl_model.php index 2f3f2e1d1..8f22abb2e 100644 --- a/application/models/Qsl_model.php +++ b/application/models/Qsl_model.php @@ -128,19 +128,21 @@ class Qsl_model extends CI_Model { return $this->db->insert_id(); } - // return path of Qsl file : u=url / p=real path + // return path of qsl file : u=url / p=real path function get_imagePath($pathorurl='u') { - // check if there is a user_id in the session data and it's not empty - $user_id = $this->session->userdata('user_id'); - if ($user_id != '') { + // test if new folder directory option is enabled + $userdata_dir = $this->config->item('userdata'); + + if (isset($userdata_dir)) { - $qsl_dir = "qsl_card"; - - // test if new folder directory exist - $userdata_dir = $this->config->item('userdata'); - if (isset($userdata_dir)) { + $qsl_dir = "qsl_card"; + $user_id = $this->session->userdata('user_id'); + + // check if there is a user_id in the session data and it's not empty + if ($user_id != '') { + // create the folder if (!file_exists(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$qsl_dir)) { mkdir(realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$qsl_dir, 0755, true); @@ -153,10 +155,12 @@ class Qsl_model extends CI_Model { return realpath(APPPATH.'../').'/'.$userdata_dir.'/'.$user_id.'/'.$qsl_dir; } } else { + log_message('Error', 'Can not get qsl card image path because no user_id in session data'); + } + } else { - // if the config option is not set we just return the old path - return 'assets/qslcard'; - } - } + // if the config option is not set we just return the old path + return 'assets/qslcard'; + } } }