Browse Source

Minor - format code, fix class name, use camelCase for function name.

jmontoyaa 7 years ago
parent
commit
9588128cd3
2 changed files with 16 additions and 46 deletions
  1. 4 4
      main/inc/ajax/chat.ajax.php
  2. 12 42
      main/inc/lib/chat.lib.php

+ 4 - 4
main/inc/ajax/chat.ajax.php

@@ -13,12 +13,12 @@ if (api_get_setting('allow_global_chat') == 'false') {
     exit;
 }
 
-$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
-
 if (api_is_anonymous()) {
     exit;
 }
 
+$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
+
 // Course Chat
 if ($action == 'preview') {
     echo CourseChatUtils::prepareMessage($_REQUEST['message']);
@@ -37,10 +37,10 @@ if (!isset($_SESSION['openChatBoxes'])) {
 }
 
 $chat = new Chat();
-if (chat::disableChat()) {
+if (Chat::disableChat()) {
     exit;
 }
-if ($chat->is_chat_blocked_by_exercises()) {
+if ($chat->isChatBlockedByExercises()) {
     // Disconnecting the user
     $chat->setUserStatus(0);
     exit;

+ 12 - 42
main/inc/lib/chat.lib.php

@@ -265,20 +265,6 @@ class Chat extends Model
             unset($_SESSION['tsChatBoxes'][$fromUserId]);
 
             foreach ($rows as $chat) {
-                /*$chat['message'] = Security::remove_XSS($chat['message']);
-                $item = array(
-                    's' => '0',
-                    'f' => $fromUserId,
-                    'm' => $chat['message'],
-                    'username' => $user_info['complete_name'],
-                    'date' => api_strtotime($chat['sent'], 'UTC'),
-                    'id' => $chat['id']
-                );
-                $items[$fromUserId]['items'][] = $item;
-                $items[$fromUserId]['total_messages'] = $count;
-                $items[$fromUserId]['user_info']['user_name'] = $user_info['complete_name'];
-                $items[$fromUserId]['user_info']['online'] = $user_info['user_is_online'];
-                $items[$fromUserId]['user_info']['avatar'] = $user_info['avatar_small'];*/
                 $_SESSION['openChatBoxes'][$fromUserId] = api_strtotime($chat['sent'], 'UTC');
             }
 
@@ -298,8 +284,8 @@ class Chat extends Model
         }
 
         if (!empty($_SESSION['openChatBoxes'])) {
-            foreach ($_SESSION['openChatBoxes'] as $user_id => $time) {
-                if (!isset($_SESSION['tsChatBoxes'][$user_id])) {
+            foreach ($_SESSION['openChatBoxes'] as $userId => $time) {
+                if (!isset($_SESSION['tsChatBoxes'][$userId])) {
                     $now = time() - $time;
                     $time = api_convert_and_format_date($time, DATE_TIME_FORMAT_SHORT_TIME_FIRST);
                     $message = sprintf(get_lang('SentAtX'), $time);
@@ -307,14 +293,14 @@ class Chat extends Model
                     if ($now > 180) {
                         $item = array(
                             's' => '2',
-                            'f' => $user_id,
+                            'f' => $userId,
                             'm' => $message
                         );
 
-                        if (isset($_SESSION['chatHistory'][$user_id])) {
-                            $_SESSION['chatHistory'][$user_id]['items'][] = $item;
+                        if (isset($_SESSION['chatHistory'][$userId])) {
+                            $_SESSION['chatHistory'][$userId]['items'][] = $item;
                         }
-                        $_SESSION['tsChatBoxes'][$user_id] = 1;
+                        $_SESSION['tsChatBoxes'][$userId] = 1;
                     }
                 }
             }
@@ -328,30 +314,14 @@ class Chat extends Model
         echo json_encode(['items' => $items]);
     }
 
-    /**
-    * Returns an array of messages inside a chat session with a specific user
-    * @param int The ID of the user with whom the current user is chatting
-    * @return array Messages list
-    */
-    public function box_session($user_id)
-    {
-        $items = array();
-        if (isset($_SESSION['chatHistory'][$user_id])) {
-            $items = $_SESSION['chatHistory'][$user_id];
-        }
-
-        return $items;
-    }
-
     /**
      * Saves into session the fact that a chat window exists with the given user
      * @param int The ID of the user with whom the current user is chatting
-     * @param integer $user_id
-     * @return void
+     * @param integer $userId
      */
-    public function save_window($user_id)
+    public function saveWindow($userId)
     {
-        $this->window_list[$user_id] = true;
+        $this->window_list[$userId] = true;
         Session::write('window_list', $this->window_list);
     }
 
@@ -380,7 +350,7 @@ class Chat extends Model
         if ($user_friend_relation == USER_RELATION_TYPE_FRIEND) {
             $now = api_get_utc_datetime();
             $user_info = api_get_user_info($to_user_id, true);
-            $this->save_window($to_user_id);
+            $this->saveWindow($to_user_id);
             $_SESSION['openChatBoxes'][$to_user_id] = $now;
 
             if ($sanitize) {
@@ -445,7 +415,7 @@ class Chat extends Model
      * Filter chat messages to avoid XSS or other JS
      * @param string $text Unfiltered message
      *
-     * @return string Filtered mssage
+     * @return string Filtered message
      */
     public function sanitize($text)
     {
@@ -487,7 +457,7 @@ class Chat extends Model
     /**
      * @return bool
      */
-    public function is_chat_blocked_by_exercises()
+    public function isChatBlockedByExercises()
     {
         $currentExercises = Session::read('current_exercises');
         if (!empty($currentExercises)) {