From bebc6163d8c123b646d068437e06954a745e9f6b Mon Sep 17 00:00:00 2001 From: lsces Date: Mon, 2 Feb 2026 21:05:12 +0000 Subject: Restructure layout in line with namespace addition and PHP8.4 style rules --- admin/admin_messages_inc.php | 1 - admin/schema_inc.php | 0 admin/upgrade_inc.php | 91 ------------------------------------- broadcast.php | 12 ++--- compose.php | 25 +++++----- contact.php | 8 ++-- icons/pkg_messages.gif | Bin icons/pkg_messages.png | Bin includes/bit_setup_inc.php | 1 - includes/classes/Messages.php | 14 ++---- includes/user_preferences_inc.php | 9 ++-- index.php | 0 message_box.php | 30 +++++------- modules/mod_unread_messages.tpl | 0 read.php | 13 +++--- templates/admin_messages.tpl | 0 templates/broadcast.tpl | 0 templates/compose.tpl | 0 templates/contact.tpl | 0 templates/html_head_inc.tpl | 0 templates/index.php | 0 templates/mailbox.tpl | 0 templates/menu_messages_admin.tpl | 0 templates/message_notification.tpl | 0 templates/messages_nav.tpl | 0 templates/preferences_inc.tpl | 0 templates/read.tpl | 0 templates/user_preferences_inc.tpl | 0 28 files changed, 52 insertions(+), 152 deletions(-) mode change 100644 => 100755 admin/admin_messages_inc.php mode change 100644 => 100755 admin/schema_inc.php delete mode 100644 admin/upgrade_inc.php mode change 100644 => 100755 broadcast.php mode change 100644 => 100755 compose.php mode change 100644 => 100755 contact.php mode change 100644 => 100755 icons/pkg_messages.gif mode change 100644 => 100755 icons/pkg_messages.png mode change 100644 => 100755 includes/bit_setup_inc.php mode change 100644 => 100755 includes/classes/Messages.php mode change 100644 => 100755 includes/user_preferences_inc.php mode change 100644 => 100755 index.php mode change 100644 => 100755 message_box.php mode change 100644 => 100755 modules/mod_unread_messages.tpl mode change 100644 => 100755 read.php mode change 100644 => 100755 templates/admin_messages.tpl mode change 100644 => 100755 templates/broadcast.tpl mode change 100644 => 100755 templates/compose.tpl mode change 100644 => 100755 templates/contact.tpl mode change 100644 => 100755 templates/html_head_inc.tpl mode change 100644 => 100755 templates/index.php mode change 100644 => 100755 templates/mailbox.tpl mode change 100644 => 100755 templates/menu_messages_admin.tpl mode change 100644 => 100755 templates/message_notification.tpl mode change 100644 => 100755 templates/messages_nav.tpl mode change 100644 => 100755 templates/preferences_inc.tpl mode change 100644 => 100755 templates/read.tpl mode change 100644 => 100755 templates/user_preferences_inc.tpl diff --git a/admin/admin_messages_inc.php b/admin/admin_messages_inc.php old mode 100644 new mode 100755 index 8f62d56..ba55556 --- a/admin/admin_messages_inc.php +++ b/admin/admin_messages_inc.php @@ -15,4 +15,3 @@ if( !empty( $_REQUEST['anonymous_settings'] ) ) { } $gBitSystem->setHelpInfo( 'Features', 'Settings', 'Help with the features settings' ); -?> diff --git a/admin/schema_inc.php b/admin/schema_inc.php old mode 100644 new mode 100755 diff --git a/admin/upgrade_inc.php b/admin/upgrade_inc.php deleted file mode 100644 index 836e93b..0000000 --- a/admin/upgrade_inc.php +++ /dev/null @@ -1,91 +0,0 @@ - array( - 'BWR1' => array( - -// STEP 1 -array( 'DATADICT' => array( - array( 'RENAMECOLUMN' => array( - 'messu_messages' => array( - '`msgId`' => '`msg_id` I4 AUTO', - '`isRead`' => '`is_read` VARCHAR(1)', - '`isReplied`' => '`is_replied` VARCHAR(1)', - '`isFlagged`' => '`is_flagged` VARCHAR(1)', - '`user_to`' => '`msg_to` X', - '`user_cc`' => '`msg_cc` X', - '`user_bcc`' => '`msg_bcc` X', - ), - )), - array( 'ALTER' => array( - 'messu_messages' => array( - 'to_user_id' => array( '`to_user_id`', 'I4' ), - 'from_user_id' => array( '`from_user_id`', 'I4' ), - ), - )) -)), - -// STEP 3 -array( 'QUERY' => - array( 'SQL92' => array( - "UPDATE `".BIT_DB_PREFIX."messu_messages` SET `to_user_id`=(SELECT `user_id` FROM `".BIT_DB_PREFIX."users_users` WHERE `".BIT_DB_PREFIX."users_users`.`login`=`".BIT_DB_PREFIX."messu_messages`.`user`)", - "UPDATE `".BIT_DB_PREFIX."messu_messages` SET `from_user_id`=(SELECT `user_id` FROM `".BIT_DB_PREFIX."users_users` WHERE `".BIT_DB_PREFIX."users_users`.`login`=`".BIT_DB_PREFIX."messu_messages`.`user_from`)", - ), -)), - -// STEP 4 -array( 'DATADICT' => array( - array( 'DROPCOLUMN' => array( - 'messu_messages' => array( '`user`', '`user_from`' ), - )), -)), - - ) - ), - - - -// next upgrade path - 'BWR1' => array( - 'BWR2' => array( - -array( 'DATADICT' => array( - array( 'ALTER' => array( - 'messu_messages' => array( - 'group_id' => array( '`group_id`', 'I4' ), - ), - )), - // de-tikify tables - array( 'RENAMETABLE' => array( - 'messu_messages' => 'messages', - )), - array( 'CREATE' => array ( - 'messages_system_map' => " - msg_id I4, - to_user_id I4 NOTNULL, - is_read C(1), - is_flagged C(1), - is_replied C(1), - priority I4, - is_hidden C(1) - CONSTRAINT ', CONSTRAINT `messages_system_message_ref` FOREIGN KEY (`msg_id`) REFERENCES `".BIT_DB_PREFIX."messages` (`msg_id`)' - " - )), - array( 'RENAMECOLUMN' => array( - 'messages' => array( - '`date`' => '`msg_date` I8' - ), - )), -)), - - ) - ), -); - -if( isset( $upgrades[$gUpgradeFrom][$gUpgradeTo] ) ) { - $gBitSystem->registerUpgrade( MESSAGES_PKG_NAME, $upgrades[$gUpgradeFrom][$gUpgradeTo] ); -} - - -?> diff --git a/broadcast.php b/broadcast.php old mode 100644 new mode 100755 index 57eb60d..0c30dbf --- a/broadcast.php +++ b/broadcast.php @@ -1,4 +1,5 @@ isRegistered() ) { - $gBitSmarty->fatalError( tra( "You are not logged in" ) ); +// $gBitSmarty->fatalError( KernelTools::tra( "You are not logged in" ) ); } $gBitSystem->isPackageActive( 'messages', TRUE ); @@ -35,7 +36,7 @@ if( isset( $_REQUEST['send'] ) ) { } if( $gBitUser->isAdmin() ) { - $pListHash = array('sort_mode' => 'group_id_asc'); + $pListHash = [ 'sort_mode' => 'group_id_asc' ]; $groups = $gBitUser->getAllGroups( $pListHash ); } else { $gBitUser->loadGroups(); @@ -44,5 +45,4 @@ if( $gBitUser->isAdmin() ) { $gBitSmarty->assign( 'groups', $groups ); $gBitSmarty->assign( 'feedback', $feedback ); -$gBitSystem->display( 'bitpackage:messages/broadcast.tpl', NULL, array( 'display_mode' => 'display' )); -?> +$gBitSystem->display( 'bitpackage:messages/broadcast.tpl', NULL, [ 'display_mode' => 'display' ]); diff --git a/compose.php b/compose.php old mode 100644 new mode 100755 index 4ef75ac..2ef3f96 --- a/compose.php +++ b/compose.php @@ -1,4 +1,5 @@ isRegistered() ) { - $gBitSmarty->assign('msg', tra("You are not logged in")); - $gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'display' )); + $gBitSmarty->assign('msg', KernelTools::tra("You are not logged in")); + $gBitSystem->display( 'error.tpl' , NULL, [ 'display_mode' => 'display' ]); die; } @@ -58,7 +60,7 @@ if( !empty( $_REQUEST['action']['reply'] ) || !empty( $_REQUEST['action']['reply // Strip Re:Re:Re: from subject if(isset($_REQUEST['action']['reply']) || isset($_REQUEST['action']['replyall'])) { - $_REQUEST['subject'] = tra("Re: ").preg_replace("/^(".tra("Re: ").")+/i", "", $_REQUEST['subject']); + $_REQUEST['subject'] = KernelTools::tra("Re: ").preg_replace("/^(".KernelTools::tra("Re: ").")+/i", "", $_REQUEST['subject']); } $gBitSmarty->assign('to', $_REQUEST['to']); @@ -70,14 +72,14 @@ $gBitSmarty->assign('priority', $_REQUEST['priority']); $gBitSmarty->assign('sent', 0); $feedback = array(); -$gBitSmarty->assignByRef( 'feedback', $feedback ); +$gBitSmarty->assign( 'feedback', $feedback ); if (isset($_REQUEST['replyto']) || isset($_REQUEST['replyallto'])) { - $flagHash = array( + $flagHash = [ 'msg_id' => $_REQUEST['msg_id'], 'act' => 'is_replied', 'actval' => 'y', - ); + ]; $messages->flagMessage( $flagHash ); } @@ -99,7 +101,7 @@ if (isset($_REQUEST['send'])) { if( !empty( $toUser ) ) { $_REQUEST['to_login'] = $toUser; if( $messages->postMessage( $_REQUEST ) ) { - $feedback['success'][] = tra( "Message will be sent to: " ).' '.$toUser; + $feedback['success'][] = KernelTools::tra( "Message will be sent to: " ).' '.$toUser; } else { $feedback['error'][] = $messages->mErrors['compose']; } @@ -107,12 +109,11 @@ if (isset($_REQUEST['send'])) { } $gBitSmarty->assign('sent', 1); } else { - $feedback['error'][] = tra('ERROR: No valid users to send the message.'); + $feedback['error'][] = KernelTools::tra('ERROR: No valid users to send the message.'); } } else { - $feedback['error'][] = tra( 'ERROR: Either the subject or body must contain text.' ); + $feedback['error'][] = KernelTools::tra( 'ERROR: Either the subject or body must contain text.' ); } } -$gBitSystem->display( 'bitpackage:messages/compose.tpl', 'Compose Message' , array( 'display_mode' => 'display' )); -?> +$gBitSystem->display( 'bitpackage:messages/compose.tpl', 'Compose Message' , [ 'display_mode' => 'display' ]); diff --git a/contact.php b/contact.php old mode 100644 new mode 100755 index 79082b4..affaaeb --- a/contact.php +++ b/contact.php @@ -1,4 +1,5 @@ verifyFeature( 'messages_site_contact' ); $messages = new Messages(); if( !empty( $_REQUEST['send'] )) { if( empty( $_REQUEST['subject'] ) && empty( $_REQUEST['body'] ) ) { - $gBitSystem->fatalError( tra( "Either a subject or a message body is required." )); + $gBitSystem->fatalError( KernelTools::tra( "Either a subject or a message body is required." )); } $postHash = $_REQUEST; $postHash['to_login'] = $postHash['msg_to'] = $gBitSystem->getConfig( 'messages_contact_user' ); $messages->postMessage( $postHash ); - $feedback['success'] = tra( 'Your message was sent to' ).': '.$gBitSystem->getConfig( 'messages_contact_user' ); + $feedback['success'] = KernelTools::tra( 'Your message was sent to' ).': '.$gBitSystem->getConfig( 'messages_contact_user' ); $gBitSmarty->assign( 'feedback', $feedback ); } diff --git a/icons/pkg_messages.gif b/icons/pkg_messages.gif old mode 100644 new mode 100755 diff --git a/icons/pkg_messages.png b/icons/pkg_messages.png old mode 100644 new mode 100755 diff --git a/includes/bit_setup_inc.php b/includes/bit_setup_inc.php old mode 100644 new mode 100755 index 5c5c2b5..38c9e5f --- a/includes/bit_setup_inc.php +++ b/includes/bit_setup_inc.php @@ -15,7 +15,6 @@ define( 'MESSAGES_PKG_CLASS_PATH', BIT_ROOT_PATH . basename( $pRegisterHash['pac $gBitSystem->registerPackage( $pRegisterHash ); if( $gBitSystem->isPackageActive( 'messages' ) && $gBitUser->hasPermission( 'p_messages_send' ) ) { - require_once MESSAGES_PKG_CLASS_PATH . 'Messages.php'; $messages = new Messages(); $unreadMsgs = $messages->unreadMessages( $gBitUser->mUserId ); $gBitSmarty->assign( 'unreadMsgs', $unreadMsgs ); diff --git a/includes/classes/Messages.php b/includes/classes/Messages.php old mode 100644 new mode 100755 index e53042e..104f02a --- a/includes/classes/Messages.php +++ b/includes/classes/Messages.php @@ -229,8 +229,8 @@ class Messages extends BitBase { // ====================== insane message mergin and sorting ====================== $sort_mode = $pListHash['sort_mode']; $ret = []; - $normalMessageCount = count($normalMessages); - $systemMessageCount = count($systemMessages); + $normalMessageCount = \count($normalMessages); + $systemMessageCount = \count($systemMessages); $normalMsg = $systemMsg = NULL; if (strpos($sort_mode, '_asc') !== FALSE) { $sortType = '_asc'; @@ -361,11 +361,7 @@ class Messages extends BitBase { $bindVars[] = '%'.strtoupper( $pListHash['find'] ).'%'; } - if( !empty( $pListHash['neighbour'] ) && $pListHash['neighbour'] == 'prev' ) { - $query = "SELECT MAX(`msg_id`) FROM `".BIT_DB_PREFIX."messages` mm WHERE `to_user_id`=? AND `msg_id` < ? $whereSql"; - } else { - $query = "SELECT MIN(`msg_id`) FROM `".BIT_DB_PREFIX."messages` mm WHERE `to_user_id`=? AND `msg_id` > ? $whereSql"; - } + $query = ( !empty( $pListHash['neighbour'] ) && $pListHash['neighbour'] == 'prev' ) ? "SELECT MAX(`msg_id`) FROM `" . BIT_DB_PREFIX . "messages` mm WHERE `to_user_id`=? AND `msg_id` < ? $whereSql" : "SELECT MIN(`msg_id`) FROM `" . BIT_DB_PREFIX . "messages` mm WHERE `to_user_id`=? AND `msg_id` > ? $whereSql"; $msg_id = $this->mDb->getOne( $query, $bindVars ); return( !empty( $msg_id ) ? $msg_id : FALSE ); @@ -403,9 +399,9 @@ class Messages extends BitBase { // Standard user to user messages $normalCount = $this->mDb->getOne( "select count( * ) from `".BIT_DB_PREFIX."messages` where `to_user_id`=? and `is_read`=?", [ $pUserId, 'n' ] ); // Broadcast messages where they have a messages_system_map row but is_read is not yet set - $broadcastCount = $this->mDb->getOne("SELECT COUNT(mm.`msg_id`) FROM `".BIT_DB_PREFIX."messages` mm INNER JOIN `".BIT_DB_PREFIX."messages_system_map` msm ON (mm.`msg_id` = msm.`msg_id` AND msm.`is_read` <> 'y' AND `is_hidden` <> 'y' AND msm.`to_user_id`= ?) WHERE mm.`to_user_id` = ? AND mm.`group_id` IN (SELECT `group_id` FROM `".BIT_DB_PREFIX."users_groups_map` WHERE `user_id`= ?) ", array($pUserId, ROOT_USER_ID, $pUserId)); + $broadcastCount = $this->mDb->getOne("SELECT COUNT(mm.`msg_id`) FROM `".BIT_DB_PREFIX."messages` mm INNER JOIN `".BIT_DB_PREFIX."messages_system_map` msm ON (mm.`msg_id` = msm.`msg_id` AND msm.`is_read` <> 'y' AND `is_hidden` <> 'y' AND msm.`to_user_id`= ?) WHERE mm.`to_user_id` = ? AND mm.`group_id` IN (SELECT `group_id` FROM `".BIT_DB_PREFIX."users_groups_map` WHERE `user_id`= ?) ", [ $pUserId, ROOT_USER_ID, $pUserId ]); // Broadcast messages where they do not yet have a messages_system_map row - $broadcastCount2 = $this->mDb->getOne("SELECT COUNT(mm.`msg_id`) FROM `".BIT_DB_PREFIX."messages` mm WHERE mm.`to_user_id` = ? AND mm.`group_id` IN (SELECT `group_id` FROM `".BIT_DB_PREFIX."users_groups_map` WHERE `user_id` = ?) AND NOT EXISTS ( SELECT msm.`msg_id` FROM `".BIT_DB_PREFIX."messages_system_map` msm WHERE msm.`msg_id` = mm.`msg_id` AND msm.`to_user_id` = ?)", array(ROOT_USER_ID, $pUserId, $pUserId)); + $broadcastCount2 = $this->mDb->getOne("SELECT COUNT(mm.`msg_id`) FROM `".BIT_DB_PREFIX."messages` mm WHERE mm.`to_user_id` = ? AND mm.`group_id` IN (SELECT `group_id` FROM `".BIT_DB_PREFIX."users_groups_map` WHERE `user_id` = ?) AND NOT EXISTS ( SELECT msm.`msg_id` FROM `".BIT_DB_PREFIX."messages_system_map` msm WHERE msm.`msg_id` = mm.`msg_id` AND msm.`to_user_id` = ?)", [ ROOT_USER_ID, $pUserId, $pUserId ]); return $normalCount + $broadcastCount + $broadcastCount2; } diff --git a/includes/user_preferences_inc.php b/includes/user_preferences_inc.php old mode 100644 new mode 100755 index eca829e..1a2d377 --- a/includes/user_preferences_inc.php +++ b/includes/user_preferences_inc.php @@ -10,9 +10,8 @@ $title = "User Messages"; if( isset( $_REQUEST['messprefs'] ) ) { - $editUser->storePreference( 'messages_alert', !empty( $_REQUEST['messages_alert'] ) ? 'y' : 'n', USERS_PKG_NAME ); - $editUser->storePreference( 'messages_max_records', $_REQUEST['messages_max_records'], USERS_PKG_NAME ); - $editUser->storePreference( 'messages_min_priority', !empty( $_REQUEST['messages_min_priority'] ) ? $_REQUEST['messages_min_priority'] : NULL, USERS_PKG_NAME ); - $editUser->storePreference( 'messages_allow_messages', !empty( $_REQUEST['messages_allow_messages'] ) ? 'y' : 'n', USERS_PKG_NAME ); + $editUser->storePreference( 'messages_alert', !empty( $_REQUEST['messages_alert'] ) ? 'y' : 'n' ); + $editUser->storePreference( 'messages_max_records', $_REQUEST['messages_max_records'] ); + $editUser->storePreference( 'messages_min_priority', !empty( $_REQUEST['messages_min_priority'] ) ? $_REQUEST['messages_min_priority'] : NULL ); + $editUser->storePreference( 'messages_allow_messages', !empty( $_REQUEST['messages_allow_messages'] ) ? 'y' : 'n' ); } -?> diff --git a/index.php b/index.php old mode 100644 new mode 100755 diff --git a/message_box.php b/message_box.php old mode 100644 new mode 100755 index 5a84d2b..177f876 --- a/message_box.php +++ b/message_box.php @@ -1,4 +1,5 @@ isRegistered() ) { - $gBitSmarty->assign('msg', tra("You are not logged in")); + $gBitSmarty->assign('msg', KernelTools::tra("You are not logged in")); $gBitSystem->display( 'error.tpl' , NULL, array( 'display_mode' => 'display' )); die; } @@ -35,11 +38,11 @@ $max_records = $gBitSystem->getConfig( 'max_records', 20 ); if (isset($_REQUEST["mark"]) && isset($_REQUEST["msg"])) { foreach( array_keys( $_REQUEST["msg"] ) as $msg_id ) { $parts = explode( '_', $_REQUEST['action'] ); - $flagHash = array( - 'msg_id' => $msg_id , - 'act' => $parts[0].'_'.$parts[1], + $flagHash = [ + 'msg_id' => $msg_id, + 'act' => "$parts[0]_$parts[1]", 'actval' => $parts[2], - ); + ]; $messages->flagMessage( $flagHash ); } } @@ -60,22 +63,13 @@ if( !empty( $_REQUEST['filter'] ) ) { } } -if ( empty( $_REQUEST["sort_mode"] ) ) { - $_REQUEST['sort_mode'] = 'msg_date_desc'; -} else { - $_REQUEST['sort_mode'] = $_REQUEST["sort_mode"]; -} +$_REQUEST['sort_mode'] = ( empty( $_REQUEST["sort_mode"] ) ) ? 'msg_date_desc' : $_REQUEST["sort_mode"]; -if (isset($_REQUEST["find"])) { - $find = $_REQUEST["find"]; -} else { - $find = ''; -} +$find = ( isset( $_REQUEST["find"] ) ) ? $_REQUEST["find"] : ''; $listHash = $_REQUEST; $items = $messages->getList( $listHash ); $gBitSmarty->assign( 'items', $items ); $gBitSmarty->assign( 'listInfo', $listHash['listInfo'] ); -$gBitSystem->display( 'bitpackage:messages/mailbox.tpl', 'Message box' , array( 'display_mode' => 'display' )); -?> +$gBitSystem->display( 'bitpackage:messages/mailbox.tpl', 'Message box' , [ 'display_mode' => 'display' ]); diff --git a/modules/mod_unread_messages.tpl b/modules/mod_unread_messages.tpl old mode 100644 new mode 100755 diff --git a/read.php b/read.php old mode 100644 new mode 100755 index fe68231..bbef5aa --- a/read.php +++ b/read.php @@ -1,4 +1,5 @@ isRegistered() ) { - $gBitSystem->fatalError( tra( "You are not logged in" ) ); + $gBitSystem->fatalError( KernelTools::tra( "You are not logged in" ) ); } $gBitSystem->isPackageActive( 'messages' ); @@ -47,11 +50,11 @@ $gBitSmarty->assign('next', $next); $gBitSmarty->assign('prev', $prev); // Mark the message as read -$flagHash = array( +$flagHash = [ 'msg_id' => $_REQUEST['msg_id'], 'act' => 'is_read', 'actval' => 'y', -); +]; $messages->flagMessage( $flagHash ); // Get the message and assign its data to template vars @@ -59,5 +62,3 @@ $msg = $messages->getMessage( $gBitUser->mUserId, $_REQUEST['msg_id']); $gBitSmarty->assign( 'msg', $msg ); $gBitSystem->display( 'bitpackage:messages/read.tpl', NULL, array( 'display_mode' => 'display' )); - -?> diff --git a/templates/admin_messages.tpl b/templates/admin_messages.tpl old mode 100644 new mode 100755 diff --git a/templates/broadcast.tpl b/templates/broadcast.tpl old mode 100644 new mode 100755 diff --git a/templates/compose.tpl b/templates/compose.tpl old mode 100644 new mode 100755 diff --git a/templates/contact.tpl b/templates/contact.tpl old mode 100644 new mode 100755 diff --git a/templates/html_head_inc.tpl b/templates/html_head_inc.tpl old mode 100644 new mode 100755 diff --git a/templates/index.php b/templates/index.php old mode 100644 new mode 100755 diff --git a/templates/mailbox.tpl b/templates/mailbox.tpl old mode 100644 new mode 100755 diff --git a/templates/menu_messages_admin.tpl b/templates/menu_messages_admin.tpl old mode 100644 new mode 100755 diff --git a/templates/message_notification.tpl b/templates/message_notification.tpl old mode 100644 new mode 100755 diff --git a/templates/messages_nav.tpl b/templates/messages_nav.tpl old mode 100644 new mode 100755 diff --git a/templates/preferences_inc.tpl b/templates/preferences_inc.tpl old mode 100644 new mode 100755 diff --git a/templates/read.tpl b/templates/read.tpl old mode 100644 new mode 100755 diff --git a/templates/user_preferences_inc.tpl b/templates/user_preferences_inc.tpl old mode 100644 new mode 100755 -- cgit v1.3