From b01a08461722ca2245e43dd0782dcf053474bb6c Mon Sep 17 00:00:00 2001 From: David Date: Thu, 9 Jul 2020 10:42:56 +0200 Subject: [PATCH 01/11] update the insert declaration to match the one from the parent --- class/FieldHandler.php | 2 +- class/ProfileHandler.php | 2 +- class/RegstepHandler.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/class/FieldHandler.php b/class/FieldHandler.php index 1a919e6..6f6f8fa 100644 --- a/class/FieldHandler.php +++ b/class/FieldHandler.php @@ -98,7 +98,7 @@ public function &loadFields($force_update = false) { * * @return bool FALSE if failed, TRUE if already present and unchanged or successful */ - public function insert(&$obj, $force = false) { + public function insert(&$obj, $force = false, $checkObject = true, $debug = false) { $profile_handler = icms_getmodulehandler('profile', basename(dirname(dirname(__FILE__))), 'profile'); $obj->cleanVars(); diff --git a/class/ProfileHandler.php b/class/ProfileHandler.php index 7f69639..296cae8 100644 --- a/class/ProfileHandler.php +++ b/class/ProfileHandler.php @@ -59,7 +59,7 @@ public function &loadFields() { * @param bool $checkObject check if the object is dirty and clean the attributes * @return bool FALSE if failed, TRUE if already present and unchanged or successful */ - public function insert(&$obj, $force = false, $checkObject = true) { + public function insert(&$obj, $force = false, $checkObject = true, $checkObject = true, $debug = false) { $uservars = $this->getUserVars(); foreach ($uservars as $var) unset($obj->vars[$var]); if (count($obj->vars) == 1) return true; diff --git a/class/RegstepHandler.php b/class/RegstepHandler.php index 0b334f2..1d2a3b6 100644 --- a/class/RegstepHandler.php +++ b/class/RegstepHandler.php @@ -30,7 +30,7 @@ public function __construct(&$db) { * @param bool $force * @return bool */ - public function insert(&$obj, $force = false) { + public function insert(&$obj, $force = false, $checkObject = true, $debug = false) { if (parent::insert($obj, $force)) { if ($obj->getVar('step_save') == 1) return $this->updateAll('step_save', 0, new icms_db_criteria_Item('step_id', $obj->getVar('step_id'), "!=")); return true; From 4201411307668bbacc661b54b4d7460d3dec67da Mon Sep 17 00:00:00 2001 From: David Date: Thu, 9 Jul 2020 10:43:57 +0200 Subject: [PATCH 02/11] checkobject only needs to be declared once --- class/ProfileHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/ProfileHandler.php b/class/ProfileHandler.php index 296cae8..aa995a6 100644 --- a/class/ProfileHandler.php +++ b/class/ProfileHandler.php @@ -59,7 +59,7 @@ public function &loadFields() { * @param bool $checkObject check if the object is dirty and clean the attributes * @return bool FALSE if failed, TRUE if already present and unchanged or successful */ - public function insert(&$obj, $force = false, $checkObject = true, $checkObject = true, $debug = false) { + public function insert(&$obj, $force = false, $checkObject = true, $debug = false) { $uservars = $this->getUserVars(); foreach ($uservars as $var) unset($obj->vars[$var]); if (count($obj->vars) == 1) return true; From 6a0f914ff7805716ab17f8cc0dcad2157df42dd8 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 20 Feb 2022 11:28:47 +0100 Subject: [PATCH 03/11] get the count out of the loop + collapse __DIR__ calls --- class/FieldHandler.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/class/FieldHandler.php b/class/FieldHandler.php index 6f6f8fa..6b2f98a 100644 --- a/class/FieldHandler.php +++ b/class/FieldHandler.php @@ -24,7 +24,7 @@ class mod_profile_FieldHandler extends icms_ipf_Handler { * @param icms_db_legacy_Database $db */ public function __construct(&$db) { - parent::__construct($db, 'field', 'fieldid', 'field_name', 'field_description', basename(dirname(dirname(__FILE__)))); + parent::__construct($db, 'field', 'fieldid', 'field_name', 'field_description', basename(dirname(__FILE__, 2))); $this->enableUpload(array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png'), 5120, 18, 18); } @@ -36,9 +36,9 @@ public function __construct(&$db) { */ public function getProfileFields(&$thisUser) { // get handlers - $category_handler = icms_getModuleHandler('category', basename(dirname(dirname(__FILE__))), 'profile'); - $profile_handler = icms_getModuleHandler('profile', basename(dirname(dirname(__FILE__))), 'profile'); - $visibility_handler = icms_getModuleHandler('visibility', basename(dirname(dirname(__FILE__))), 'profile'); + $category_handler = icms_getModuleHandler('category', basename(dirname(__FILE__, 2)), 'profile'); + $profile_handler = icms_getModuleHandler('profile', basename(dirname(__FILE__, 2)), 'profile'); + $visibility_handler = icms_getModuleHandler('visibility', basename(dirname(__FILE__, 2)), 'profile'); $groups = is_object(icms::$user) ? icms::$user->getGroups() : array(ICMS_GROUP_ANONYMOUS); $criteria = new icms_db_criteria_Compo(); @@ -53,11 +53,13 @@ public function getProfileFields(&$thisUser) { $profile = $profile_handler->get($thisUser->getVar('uid')); unset($category_handler, $visibility_handler, $profile_handler, $criteria); - $module = icms::handler("icms_module")->getByDirname(basename(dirname(dirname(__FILE__))), TRUE); + $module = icms::handler("icms_module")->getByDirname(basename(dirname(__FILE__, 2)), TRUE); $rtn = array(); - for ($i = 0; $i < count($categories); $i++) { + $category_count = count($categories); + for ($i = 0; $i < $category_count; $i++) { $first_category = true; - for ($j = 0; $j < count($fields); $j++) { + $field_count = count($fields); + for ($j = 0; $j < $field_count; $j++) { $value = $fields[$j]->getOutputValue($thisUser, $profile); if ($fields[$j]->getVar('field_show') && $fields[$j]->getVar('catid') == $categories[$i]->getVar('catid') && ($module->config['show_empty'] || trim($value) || $value == '0')) {; if ($first_category) $rtn[$i]['title'] = $categories[$i]->getVar('cat_title'); @@ -99,7 +101,7 @@ public function &loadFields($force_update = false) { * @return bool FALSE if failed, TRUE if already present and unchanged or successful */ public function insert(&$obj, $force = false, $checkObject = true, $debug = false) { - $profile_handler = icms_getmodulehandler('profile', basename(dirname(dirname(__FILE__))), 'profile'); + $profile_handler = icms_getmodulehandler('profile', basename(dirname(__FILE__, 2)), 'profile'); $obj->cleanVars(); $defaultstring = ""; @@ -186,7 +188,7 @@ public function insert(&$obj, $force = false, $checkObject = true, $debug = fals public function filterSteps() { if(!count($this->_stepsArray)) { - $step_handler = icms_getModuleHandler("regstep", basename(dirname(dirname(__FILE__))), "profile"); + $step_handler = icms_getModuleHandler("regstep", basename(dirname(__FILE__, 2)), "profile"); $this->_stepsArray = $step_handler->getList(); } return $this->_stepsArray; @@ -200,12 +202,12 @@ public function filterSteps() { * @return bool FALSE if failed. **/ public function delete(&$obj, $force = false) { - $profile_handler = icms_getmodulehandler('profile', basename(dirname(dirname(__FILE__))), 'profile'); + $profile_handler = icms_getmodulehandler('profile', basename(dirname(__FILE__, 2)), 'profile'); $sql = "ALTER TABLE ".$profile_handler->table." DROP ".$obj->getVar('field_name', 'n'); if ($this->db->query($sql)) { if (!parent::delete($obj, $force)) return false; if ($obj->getVar('field_show') || $obj->getVar('field_edit')) { - $profile_module = icms::handler('icms_module')->getByDirname(basename(dirname(dirname(__FILE__)))); + $profile_module = icms::handler('icms_module')->getByDirname(basename(dirname(__FILE__, 2))); if (is_object($profile_module)) { // Remove group permissions $criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('gperm_modid', $profile_module->getVar('mid'))); @@ -271,7 +273,7 @@ public function getFieldTypeArray() { */ public function getCategoriesArray() { if (!$this->_categoriesArray) { - $profile_category_handler = icms_getModuleHandler('category', basename(dirname(dirname(__FILE__))), 'profile'); + $profile_category_handler = icms_getModuleHandler('category', basename(dirname(__FILE__, 2)), 'profile'); $criteria = new icms_db_criteria_Compo(); $criteria->setSort('cat_title'); $criteria->setOrder('ASC'); From 5e11bbb19a469c709f0e2dc12d0209e9cb92ee26 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 20 Feb 2022 11:30:51 +0100 Subject: [PATCH 04/11] remove closing tag --- class/FieldHandler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/class/FieldHandler.php b/class/FieldHandler.php index 6b2f98a..5dcaec2 100644 --- a/class/FieldHandler.php +++ b/class/FieldHandler.php @@ -298,4 +298,3 @@ protected function afterDelete(&$obj) { return true; } } -?> \ No newline at end of file From fc85aa1998455e1b431f4f0d03c202537c1914c1 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 20 Feb 2022 11:32:48 +0100 Subject: [PATCH 05/11] add function return types --- class/FieldHandler.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/class/FieldHandler.php b/class/FieldHandler.php index 5dcaec2..a000900 100644 --- a/class/FieldHandler.php +++ b/class/FieldHandler.php @@ -34,7 +34,8 @@ public function __construct(&$db) { * @param icms_member_user_Object $thisUser * @return array of profile fields */ - public function getProfileFields(&$thisUser) { + public function getProfileFields(&$thisUser): array + { // get handlers $category_handler = icms_getModuleHandler('category', basename(dirname(__FILE__, 2)), 'profile'); $profile_handler = icms_getModuleHandler('profile', basename(dirname(__FILE__, 2)), 'profile'); @@ -80,7 +81,8 @@ public function getProfileFields(&$thisUser) { * * @return array */ - public function &loadFields($force_update = false) { + public function &loadFields($force_update = false): array + { static $fields = array(); if ($force_update || count($fields) == 0) { @@ -100,7 +102,8 @@ public function &loadFields($force_update = false) { * * @return bool FALSE if failed, TRUE if already present and unchanged or successful */ - public function insert(&$obj, $force = false, $checkObject = true, $debug = false) { + public function insert(&$obj, $force = false, $checkObject = true, $debug = false): bool + { $profile_handler = icms_getmodulehandler('profile', basename(dirname(__FILE__, 2)), 'profile'); $obj->cleanVars(); @@ -201,7 +204,8 @@ public function filterSteps() { * @param bool $force * @return bool FALSE if failed. **/ - public function delete(&$obj, $force = false) { + public function delete(&$obj, $force = false): bool + { $profile_handler = icms_getmodulehandler('profile', basename(dirname(__FILE__, 2)), 'profile'); $sql = "ALTER TABLE ".$profile_handler->table." DROP ".$obj->getVar('field_name', 'n'); if ($this->db->query($sql)) { @@ -224,7 +228,8 @@ public function delete(&$obj, $force = false) { * * @return array */ - public function getUserVars() { + public function getUserVars(): array + { return array('uid', 'uname', 'name', 'email', 'url', 'user_avatar', 'user_regdate', 'user_icq', 'user_from', 'user_sig', 'user_viewemail', 'actkey', 'user_aim', 'user_yim', 'user_msnm', 'pass', 'posts', 'attachsig', 'rank', 'level', 'theme', 'timezone_offset', 'last_login', 'umode', 'uorder', 'notify_method', @@ -237,7 +242,8 @@ public function getUserVars() { * * @return array of field types */ - public function getFieldTypeArray() { + public function getFieldTypeArray(): array + { if (!$this->_fieldTypeArray) { $this->_fieldTypeArray["checkbox"] = _AM_PROFILE_FIELD_TYPE_CHECKBOX; $this->_fieldTypeArray["date"] = _AM_PROFILE_FIELD_TYPE_DATE; @@ -271,7 +277,8 @@ public function getFieldTypeArray() { * * @return array list of categories */ - public function getCategoriesArray() { + public function getCategoriesArray(): array + { if (!$this->_categoriesArray) { $profile_category_handler = icms_getModuleHandler('category', basename(dirname(__FILE__, 2)), 'profile'); $criteria = new icms_db_criteria_Compo(); @@ -291,7 +298,8 @@ public function getCategoriesArray() { * @param mod_profile_Field $obj object * @return bool */ - protected function afterDelete(&$obj) { + protected function afterDelete(&$obj): bool + { $imgPath = $this->getImagePath(); $imgUrl = $obj->getVar('url'); if (!empty($imgUrl)) unlink($imgPath.$imgUrl); From bf4466ac8ea8b700e8fe0f2f2caaddcf0b306282 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 20 Feb 2022 11:36:23 +0100 Subject: [PATCH 06/11] add function return types where possible --- class/Field.php | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/class/Field.php b/class/Field.php index ce7395e..e84f727 100644 --- a/class/Field.php +++ b/class/Field.php @@ -74,7 +74,7 @@ public function getEditElement($user, $profile) { $caption = $this->getVar('field_title'); $caption = defined($caption) ? constant($caption) : $caption; $name = $this->getVar('field_name', 'e'); - $options = unserialize($this->getVar('field_options', 'n')); + $options = unserialize($this->getVar('field_options', 'n'),); if ($this->getVar('field_type') != "image" && is_array($options)) { asort($options); @@ -293,6 +293,7 @@ public function getOutputValue(&$user, $profile) { * @return mixed */ public function getValueForSave($value, $oldvalue) { + $value = icms_core_DataFilter::checkVarArray($value); switch ($this->getVar('field_type')) { default: case "textbox": @@ -311,18 +312,28 @@ public function getValueForSave($value, $oldvalue) { case "longdate": return $value; case "date": - if ($value != "") return strtotime($value); - return $value; + if ($value != "") { + return strtotime($value); + } + else { + return $value; + } break; case "datetime": - if ($value != "") return strtotime($value['date']) + $value['time']; - return $value; + if ($value != "") { + return strtotime($value['date']) + $value['time']; + } + else { + return $value; + } break; case "image": - if (!isset($_FILES[$_POST['xoops_upload_file'][0]])) return $oldvalue; + if (!isset($_FILES[$_POST['xoops_upload_file'][0]])) { + return $oldvalue; + } $options = unserialize($this->getVar('field_options', 'n')); - $dirname = ICMS_UPLOAD_PATH.'/'.basename(dirname(dirname(__FILE__))); + $dirname = ICMS_UPLOAD_PATH.'/'.basename(dirname(__FILE__, 2)); if (!is_dir($dirname)) mkdir($dirname); $uploader = new icms_file_MediaUploadHandler($dirname, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), $options['maxsize']*1024, $options['maxwidth'], $options['maxheight']); @@ -348,7 +359,8 @@ public function getValueForSave($value, $oldvalue) { * * @return array */ - private function getUserVars() { + private function getUserVars(): array + { $profile_handler = icms_getModuleHandler('profile', basename(dirname(dirname(__FILE__))), 'profile'); return $profile_handler->getUserVars(); } @@ -383,7 +395,8 @@ public function getCatid() { * * @return string field name */ - public function getFieldName() { + public function getFieldName(): string + { return $this->getVar('field_name'); } @@ -402,9 +415,10 @@ public function getImage() { * generate delete button * * @staticvar icms_ipf_Controller $controller - * @return str linked icon to delete the object + * @return string linked icon to delete the object */ - public function getDeleteButtonForDisplay() { + public function getDeleteButtonForDisplay(): string + { static $controller = null; if ($this->getVar('system') == 1) return; if ($controller === null) $controller = new icms_ipf_Controller($this->handler); @@ -414,9 +428,10 @@ public function getDeleteButtonForDisplay() { /** * generate textbox control to edit weight on acp * - * @return str textbox control + * @return string textbox control */ - public function getField_weightControl() { + public function getField_weightControl(): string + { $control = new icms_form_elements_Text('', 'field_weight[]', 5, 4, $this->getVar('field_weight')); return $control->render(); } From 33bbe244e2808e62896105db2220130b139e2504 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 20 Feb 2022 11:36:38 +0100 Subject: [PATCH 07/11] remove closing tag --- class/Field.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/class/Field.php b/class/Field.php index e84f727..209af1b 100644 --- a/class/Field.php +++ b/class/Field.php @@ -435,5 +435,4 @@ public function getField_weightControl(): string $control = new icms_form_elements_Text('', 'field_weight[]', 5, 4, $this->getVar('field_weight')); return $control->render(); } -} -?> \ No newline at end of file +} \ No newline at end of file From 5a3c1d2c6a674ed2db635eefa47ef5725883bc77 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 20 Feb 2022 13:09:05 +0100 Subject: [PATCH 08/11] use __DIR__ --- icms_version.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/icms_version.php b/icms_version.php index 944966b..eac9955 100644 --- a/icms_version.php +++ b/icms_version.php @@ -22,12 +22,12 @@ 'name' => _MI_PROFILE_NAME, 'version' => 2.2, 'description' => _MI_PROFILE_DESC, - 'author' => "m0nty, phoenyx, Jan Pedersen, Marcello Brandao, Sina Asghari, Gustavo Pilla.", - 'credits' => "The XOOPS Project, The ImpressCMS Project, The SmartFactory, Ackbarr, Komeia, vaughan, alfred.", + 'author' => "fiammybe", + 'credits' => "The XOOPS Project, The ImpressCMS Project, The SmartFactory, Ackbarr, Komeia, vaughan, alfred, m0nty, phoenyx, Jan Pedersen, Marcello Brandao, Sina Asghari, Gustavo Pilla.", 'help' => "", 'license' => "GNU General Public License (GPL)", 'official' => 1, - 'dirname' => basename(dirname(__FILE__)), + 'dirname' => basename(__DIR__), 'modname' => 'profile', /** Images information */ @@ -36,11 +36,11 @@ 'image' => "images/icon_big.png", /* for backward compatibility */ /** Development information */ - 'status_version' => "Final", - 'status' => "Final", - 'date' => "02 Sept 2013", + 'status_version' => "Beta", + 'status' => "Beta", + 'date' => "20 Feb 2022", 'author_word' => "", - 'warning' => _CO_ICMS_WARNING_FINAL, + 'warning' => _CO_ICMS_WARNING_BETA, /** Contributors */ 'developer_website_url' => "http://www.impresscms.org", From 5e307d9177001adff629323c433a678f2c1cfbb4 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 20 Feb 2022 13:09:52 +0100 Subject: [PATCH 09/11] update to 2.3 beta --- icms_version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/icms_version.php b/icms_version.php index eac9955..b8c337f 100644 --- a/icms_version.php +++ b/icms_version.php @@ -20,7 +20,7 @@ $modversion = array( /** General Information */ 'name' => _MI_PROFILE_NAME, - 'version' => 2.2, + 'version' => 2.3, 'description' => _MI_PROFILE_DESC, 'author' => "fiammybe", 'credits' => "The XOOPS Project, The ImpressCMS Project, The SmartFactory, Ackbarr, Komeia, vaughan, alfred, m0nty, phoenyx, Jan Pedersen, Marcello Brandao, Sina Asghari, Gustavo Pilla.", From 86e407309c7bd4ebe82a125b4c09ec14d1c5dd52 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 20 Feb 2022 13:10:14 +0100 Subject: [PATCH 10/11] remove extra colon --- class/Field.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/class/Field.php b/class/Field.php index 209af1b..217ebe5 100644 --- a/class/Field.php +++ b/class/Field.php @@ -74,7 +74,7 @@ public function getEditElement($user, $profile) { $caption = $this->getVar('field_title'); $caption = defined($caption) ? constant($caption) : $caption; $name = $this->getVar('field_name', 'e'); - $options = unserialize($this->getVar('field_options', 'n'),); + $options = unserialize($this->getVar('field_options', 'n')); if ($this->getVar('field_type') != "image" && is_array($options)) { asort($options); @@ -417,7 +417,7 @@ public function getImage() { * @staticvar icms_ipf_Controller $controller * @return string linked icon to delete the object */ - public function getDeleteButtonForDisplay(): string + public function getDeleteButtonForDisplay() { static $controller = null; if ($this->getVar('system') == 1) return; From e5dfd8a5459856cb053a68b452e6eb06105048aa Mon Sep 17 00:00:00 2001 From: David Date: Mon, 21 Feb 2022 11:03:50 +0100 Subject: [PATCH 11/11] collapse dirname calls & add return types --- class/VideosHandler.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/class/VideosHandler.php b/class/VideosHandler.php index 021e6d7..af84521 100644 --- a/class/VideosHandler.php +++ b/class/VideosHandler.php @@ -19,7 +19,7 @@ class mod_profile_VideosHandler extends icms_ipf_Handler { * @param icms_db_legacy_Database $db database object */ public function __construct(&$db) { - parent::__construct($db, 'videos', 'videos_id', 'video_title', '', basename(dirname(dirname(__FILE__)))); + parent::__construct($db, 'videos', 'videos_id', 'video_title', '', basename(dirname(__FILE__, 2))); } /** @@ -62,7 +62,8 @@ public function getVideo($videos_id) { * @param int $videos_id ID of a single video to retrieve * @return array of videos */ - public function getVideos($start = 0, $limit = 0, $uid_owner = false, $videos_id = false) { + public function getVideos($start = 0, $limit = 0, $uid_owner = false, $videos_id = false): array + { $criteria = $this->getVideosCriteria($start, $limit, $uid_owner, $videos_id); $ret = $this->getObjects($criteria, true, false); return $ret; @@ -74,7 +75,8 @@ public function getVideos($start = 0, $limit = 0, $uid_owner = false, $videos_id * * @return bool true if he can false if not */ - public function userCanSubmit() { + public function userCanSubmit(): bool + { return is_object(icms::$user); } @@ -88,10 +90,10 @@ public function userCanSubmit() { */ protected function afterInsert(&$obj) { $thisUser = icms::handler("icms_member")->getUser($obj->getVar('uid_owner')); - $module = icms::handler("icms_module")->getByDirname(basename(dirname(dirname(__FILE__))), TRUE); + $module = icms::handler("icms_module")->getByDirname(basename(dirname(__FILE__, 2)), TRUE); $tags['VIDEO_TITLE'] = $obj->getVar('video_title'); $tags['VIDEO_OWNER'] = $thisUser->getVar('uname'); - $tags['VIDEO_URL'] = ICMS_URL.'/modules/'.basename(dirname(dirname(__FILE__))).'/videos.php?uid='.$obj->getVar('uid_owner'); + $tags['VIDEO_URL'] = ICMS_URL.'/modules/'.basename(dirname(__FILE__, 2)).'/videos.php?uid='.$obj->getVar('uid_owner'); icms::handler('icms_data_notification')->triggerEvent('videos', $obj->getVar('uid_owner'), 'new_video', $tags, array(), $module->getVar('mid')); return true;