@@ -26,6 +26,9 @@ discard block |
||
| 26 | 26 | echo "New connection! ({$conn->resourceId})\n"; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | + /** |
|
| 30 | + * @param ConnectionInterface $conn |
|
| 31 | + */ |
|
| 29 | 32 | public function setID($conn) |
| 30 | 33 | { |
| 31 | 34 | session_id($conn->WebSocket->request->getCookies()['PHPSESSID']); |
@@ -126,30 +129,47 @@ discard block |
||
| 126 | 129 | return $obSidebar->LoadSideBar($data); |
| 127 | 130 | } |
| 128 | 131 | |
| 132 | + /** |
|
| 133 | + * @param string $data |
|
| 134 | + * @param boolean $para |
|
| 135 | + */ |
|
| 129 | 136 | public function onConversation($data, $para, $sessionId) |
| 130 | 137 | { |
| 131 | 138 | $obConversation = new Conversation($sessionId); |
| 132 | 139 | return $obConversation->ConversationLoad($data, $para); |
| 133 | 140 | } |
| 134 | 141 | |
| 142 | + /** |
|
| 143 | + * @param string $data |
|
| 144 | + * @param boolean $para |
|
| 145 | + */ |
|
| 135 | 146 | public function onReceiver($data, $para, $sessionId) |
| 136 | 147 | { |
| 137 | 148 | $obReceiver = new Receiver($sessionId); |
| 138 | 149 | return $obReceiver->ReceiverLoad($data, True); |
| 139 | 150 | } |
| 140 | 151 | |
| 152 | + /** |
|
| 153 | + * @param string $data |
|
| 154 | + */ |
|
| 141 | 155 | public function onSearch($data, $sessionId) |
| 142 | 156 | { |
| 143 | 157 | $obSearch = new Search($sessionId); |
| 144 | 158 | return $obSearch->SearchItem(json_decode($data)); |
| 145 | 159 | } |
| 146 | 160 | |
| 161 | + /** |
|
| 162 | + * @param string $data |
|
| 163 | + */ |
|
| 147 | 164 | public function onCompose($data, $sessionId) |
| 148 | 165 | { |
| 149 | 166 | $obCompose = new Compose($sessionId); |
| 150 | 167 | return $obCompose->SelectUser(json_decode($data)); |
| 151 | 168 | } |
| 152 | 169 | |
| 170 | + /** |
|
| 171 | + * @param string $data |
|
| 172 | + */ |
|
| 153 | 173 | public function onReply($data, $sessionId) |
| 154 | 174 | { |
| 155 | 175 | $obReply = new Reply($sessionId); |
@@ -52,28 +52,23 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $initial->conversation[0]->login_status = $this->online; |
| 54 | 54 | $from->send(json_encode($initial)); |
| 55 | - } |
|
| 56 | - elseif ($msg == 'Load Sidebar') |
|
| 55 | + } elseif ($msg == 'Load Sidebar') |
|
| 57 | 56 | { |
| 58 | 57 | @$initial->initial = json_decode($this->onSidebar($from->userId)); |
| 59 | 58 | $from->send(json_encode($initial)); |
| 60 | - } |
|
| 61 | - elseif (@json_decode($msg)->newConversation == 'Initiated') |
|
| 59 | + } elseif (@json_decode($msg)->newConversation == 'Initiated') |
|
| 62 | 60 | { |
| 63 | 61 | @$result->conversation = json_decode($this->onConversation($msg, False, $sessionId)); |
| 64 | 62 | $from->send(json_encode($result)); |
| 65 | - } |
|
| 66 | - elseif (@json_decode($msg)->search == 'search') |
|
| 63 | + } elseif (@json_decode($msg)->search == 'search') |
|
| 67 | 64 | { |
| 68 | 65 | $searchResult = $this->onSearch($msg, $sessionId); |
| 69 | 66 | $from->send($searchResult); |
| 70 | - } |
|
| 71 | - elseif (@json_decode($msg)->Compose == 'Compose') |
|
| 67 | + } elseif (@json_decode($msg)->Compose == 'Compose') |
|
| 72 | 68 | { |
| 73 | 69 | $composeResult = $this->onCompose($msg, $sessionId); |
| 74 | 70 | $from->send($composeResult); |
| 75 | - } |
|
| 76 | - else |
|
| 71 | + } else |
|
| 77 | 72 | { |
| 78 | 73 | $this->onReply($msg, $sessionId); |
| 79 | 74 | |
@@ -97,8 +92,7 @@ discard block |
||
| 97 | 92 | |
| 98 | 93 | $client->send(json_encode($result)); |
| 99 | 94 | $this->online = 1; |
| 100 | - } |
|
| 101 | - elseif($client == $from) |
|
| 95 | + } elseif($client == $from) |
|
| 102 | 96 | { |
| 103 | 97 | @$result->sidebar = json_decode($this->onSidebar($client->userId)); |
| 104 | 98 | |
@@ -90,6 +90,11 @@ |
||
| 90 | 90 | $this->connect->close(); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + /** |
|
| 94 | + * @param string $identifier |
|
| 95 | + * @param string $reply |
|
| 96 | + * @param string $time |
|
| 97 | + */ |
|
| 93 | 98 | function UpdateMessages($query, $identifier, $reply, $id, $time) |
| 94 | 99 | { |
| 95 | 100 | if($result = $this->connect->query($query)) |
@@ -21,18 +21,22 @@ discard block |
||
| 21 | 21 | function replyTo($msg) |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - if(isset($_SESSION['start']) && isset($msg)) //checks for session login and the value send |
|
| 24 | + if(isset($_SESSION['start']) && isset($msg)) { |
|
| 25 | + //checks for session login and the value send |
|
| 25 | 26 | { |
| 26 | 27 | $id = $_SESSION['start']; |
| 28 | + } |
|
| 27 | 29 | $msg = json_decode($msg); //decode json value |
| 28 | 30 | $identifier = $msg->name; |
| 29 | 31 | |
| 30 | 32 | $receiverID = $identifier; //stores id of the person whom message is to be sent |
| 31 | 33 | |
| 32 | - if($identifier > $id) // geneate specific unique code to store messages |
|
| 34 | + if($identifier > $id) { |
|
| 35 | + // geneate specific unique code to store messages |
|
| 33 | 36 | $identifier = $id.":".$identifier; |
| 34 | - else |
|
| 35 | - $identifier = $identifier.":".$id; |
|
| 37 | + } else { |
|
| 38 | + $identifier = $identifier.":".$id; |
|
| 39 | + } |
|
| 36 | 40 | |
| 37 | 41 | $reply = addslashes(trim($msg->reply[0])); // stores the message sent by the user. |
| 38 | 42 | |
@@ -46,27 +50,31 @@ discard block |
||
| 46 | 50 | $query = "SELECT * from login where login_id = '$receiverID'"; |
| 47 | 51 | |
| 48 | 52 | $result = $this->connect->query($query); |
| 49 | - if($result->num_rows > 0) // if true |
|
| 53 | + if($result->num_rows > 0) { |
|
| 54 | + // if true |
|
| 50 | 55 | { |
| 51 | 56 | //check whether he is sending message for thr first time or he has sent messages before |
| 52 | 57 | $query = "SELECT * from total_message where identifier = '$identifier'"; |
| 58 | + } |
|
| 53 | 59 | $result = $this->connect->query($query); |
| 54 | - if($result->num_rows>0) // if he has sent messages before |
|
| 60 | + if($result->num_rows>0) { |
|
| 61 | + // if he has sent messages before |
|
| 55 | 62 | { |
| 56 | 63 | // Update Total_Message Table |
| 57 | 64 | $query = "UPDATE total_message SET total_messages = total_messages+1, time = '$time', unread = 1, id = '$time_id' WHERE identifier = '$identifier'"; |
| 65 | + } |
|
| 58 | 66 | $this->UpdateMessages($query, $identifier, $reply, $id, $time); |
| 59 | 67 | |
| 60 | - } |
|
| 61 | - else // if he sends message for the first time |
|
| 68 | + } else // if he sends message for the first time |
|
| 62 | 69 | { |
| 63 | 70 | $length = strlen($id); |
| 64 | - if(substr($identifier, 0, $length) == $id) // generate specific unique code |
|
| 71 | + if(substr($identifier, 0, $length) == $id) { |
|
| 72 | + // generate specific unique code |
|
| 65 | 73 | { |
| 66 | 74 | $user2 = substr($identifier, $length+1); |
| 67 | - $user1 = $id; |
|
| 68 | 75 | } |
| 69 | - else |
|
| 76 | + $user1 = $id; |
|
| 77 | + } else |
|
| 70 | 78 | { |
| 71 | 79 | $user2 = $id; |
| 72 | 80 | $length = strlen($identifier) - $length-1; |
@@ -76,14 +84,12 @@ discard block |
||
| 76 | 84 | $query = "INSERT into total_message values('$identifier', 1, '$user1', '$user2', 1, '$time', '$time_id')"; |
| 77 | 85 | $this->UpdateMessages($query, $identifier, $reply, $id, $time); |
| 78 | 86 | } |
| 79 | - } |
|
| 80 | - else // if he is unauthorized echo message is failed |
|
| 87 | + } else // if he is unauthorized echo message is failed |
|
| 81 | 88 | { |
| 82 | 89 | echo "Message is failed"; |
| 83 | 90 | } |
| 84 | 91 | } |
| 85 | - } |
|
| 86 | - else |
|
| 92 | + } else |
|
| 87 | 93 | { |
| 88 | 94 | echo "failed"; |
| 89 | 95 | } |
@@ -99,8 +105,7 @@ discard block |
||
| 99 | 105 | if($result = $this->connect->query($query)) |
| 100 | 106 | { |
| 101 | 107 | echo "Messages is sent \n"; // if query is executed return true |
| 102 | - } |
|
| 103 | - else |
|
| 108 | + } else |
|
| 104 | 109 | { |
| 105 | 110 | echo "Message is failed"; |
| 106 | 111 | } |
@@ -40,18 +40,15 @@ |
||
| 40 | 40 | } |
| 41 | 41 | $this->array = array_merge([], ["Compose" => $this->array]); |
| 42 | 42 | return json_encode($this->array); |
| 43 | - } |
|
| 44 | - else |
|
| 43 | + } else |
|
| 45 | 44 | { |
| 46 | 45 | return json_encode(["Compose" => "Not Found"]); |
| 47 | 46 | } |
| 48 | - } |
|
| 49 | - else |
|
| 47 | + } else |
|
| 50 | 48 | { |
| 51 | 49 | return json_encode(["Compose" => "Query Failed"]); |
| 52 | 50 | } |
| 53 | - } |
|
| 54 | - else |
|
| 51 | + } else |
|
| 55 | 52 | { |
| 56 | 53 | return json_encode(["Compose" => "Not Found"]); |
| 57 | 54 | } |
@@ -16,14 +16,15 @@ |
||
| 16 | 16 | function TimeConversion($time) |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - if(substr($time,4,11) == date("d M Y", time() + 16200)) |
|
| 20 | - $time = substr($time,16,5); |
|
| 21 | - else if(substr($time,7,8) == date("M Y", time() + 16200) && substr($time, 4,2) - date("d") < 7) |
|
| 22 | - $time = substr($time,0,3); |
|
| 23 | - else if(substr($time,11,4) == date("Y", time() + 16200)) |
|
| 24 | - $time = substr($time,4,6); |
|
| 25 | - else |
|
| 26 | - $time = substr($time,4,11); |
|
| 19 | + if(substr($time,4,11) == date("d M Y", time() + 16200)) { |
|
| 20 | + $time = substr($time,16,5); |
|
| 21 | + } else if(substr($time,7,8) == date("M Y", time() + 16200) && substr($time, 4,2) - date("d") < 7) { |
|
| 22 | + $time = substr($time,0,3); |
|
| 23 | + } else if(substr($time,11,4) == date("Y", time() + 16200)) { |
|
| 24 | + $time = substr($time,4,6); |
|
| 25 | + } else { |
|
| 26 | + $time = substr($time,4,11); |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | return $time; |
| 29 | 30 | } |
@@ -21,17 +21,19 @@ |
||
| 21 | 21 | |
| 22 | 22 | function UserDetails($id, $para) |
| 23 | 23 | { |
| 24 | - if($para == True) |
|
| 25 | - $this->query = "SELECT * from login where login_id = '$id'"; |
|
| 26 | - else |
|
| 27 | - $this->query = "SELECT * from login where username = '$id'"; |
|
| 24 | + if($para == True) { |
|
| 25 | + $this->query = "SELECT * from login where login_id = '$id'"; |
|
| 26 | + } else { |
|
| 27 | + $this->query = "SELECT * from login where username = '$id'"; |
|
| 28 | + } |
|
| 28 | 29 | $this->result = $this->connect->query($this->query); |
| 29 | - if($this->result->num_rows > 0) // if true |
|
| 30 | + if($this->result->num_rows > 0) { |
|
| 31 | + // if true |
|
| 30 | 32 | { |
| 31 | 33 | $this->details = $this->result->fetch_assoc(); |
| 32 | - return $this->details; |
|
| 33 | 34 | } |
| 34 | - else |
|
| 35 | + return $this->details; |
|
| 36 | + } else |
|
| 35 | 37 | { |
| 36 | 38 | return NULL; |
| 37 | 39 | } |
@@ -45,10 +45,11 @@ discard block |
||
| 45 | 45 | $login_id = (int)$fetch['login_id']; |
| 46 | 46 | |
| 47 | 47 | // Unique Identifier |
| 48 | - if($login_id > $id) |
|
| 49 | - $identifier = $id.':'.$login_id; |
|
| 50 | - else |
|
| 51 | - $identifier = $login_id.':'.$id; |
|
| 48 | + if($login_id > $id) { |
|
| 49 | + $identifier = $id.':'.$login_id; |
|
| 50 | + } else { |
|
| 51 | + $identifier = $login_id.':'.$id; |
|
| 52 | + } |
|
| 52 | 53 | |
| 53 | 54 | $query = "SELECT total_messages from total_message where identifier = '$identifier'"; |
| 54 | 55 | if($result = $this->connect->query($query)) |
@@ -57,11 +58,12 @@ discard block |
||
| 57 | 58 | { |
| 58 | 59 | $total = $result->fetch_assoc(); |
| 59 | 60 | $total = $total['total_messages']; |
| 60 | - if($total - $load > 0) |
|
| 61 | - if($total - $load > 10) |
|
| 61 | + if($total - $load > 0) { |
|
| 62 | + if($total - $load > 10) |
|
| 62 | 63 | $add_load = $load + 10; |
| 63 | - else |
|
| 64 | - $add_load = $total; |
|
| 64 | + } else { |
|
| 65 | + $add_load = $total; |
|
| 66 | + } |
|
| 65 | 67 | } |
| 66 | 68 | } |
| 67 | 69 | |
@@ -79,23 +81,19 @@ discard block |
||
| 79 | 81 | |
| 80 | 82 | $this->array = array_merge([['name' => $fetch['name'], 'username' => $fetch['username'], 'id' => $fetch['login_id'], 'load' => $add_load, 'type' => 1]], $this->array); |
| 81 | 83 | return json_encode($this->array); |
| 82 | - } |
|
| 83 | - else |
|
| 84 | + } else |
|
| 84 | 85 | { |
| 85 | 86 | return json_encode([['name' => $fetch['name'], 'username' => $fetch['username'], 'id' => $fetch['login_id'], 'type' => 0]]); |
| 86 | 87 | } |
| 87 | - } |
|
| 88 | - else |
|
| 88 | + } else |
|
| 89 | 89 | { |
| 90 | 90 | echo "Query Failed"; |
| 91 | 91 | } |
| 92 | - } |
|
| 93 | - else |
|
| 92 | + } else |
|
| 94 | 93 | { |
| 95 | 94 | echo "Query Failed"; |
| 96 | 95 | } |
| 97 | - } |
|
| 98 | - else |
|
| 96 | + } else |
|
| 99 | 97 | { |
| 100 | 98 | header('Location:../login.php'); |
| 101 | 99 | } |
@@ -61,16 +61,14 @@ |
||
| 61 | 61 | { |
| 62 | 62 | $this->array = array_merge([], ["Search" => $this->array]); |
| 63 | 63 | return json_encode($this->array); |
| 64 | + } else { |
|
| 65 | + return json_encode(["Search" => "Not Found"]); |
|
| 64 | 66 | } |
| 65 | - else |
|
| 66 | - return json_encode(["Search" => "Not Found"]); |
|
| 67 | - } |
|
| 68 | - else |
|
| 67 | + } else |
|
| 69 | 68 | { |
| 70 | 69 | return json_encode(["Search" => "Not Found"]); |
| 71 | 70 | } |
| 72 | - } |
|
| 73 | - else |
|
| 71 | + } else |
|
| 74 | 72 | { |
| 75 | 73 | return json_encode(["Search" => "Not Found"]); |
| 76 | 74 | } |
@@ -38,27 +38,22 @@ |
||
| 38 | 38 | if($substring != $userId) |
| 39 | 39 | { |
| 40 | 40 | $this->Data($substring, $row); |
| 41 | - } |
|
| 42 | - |
|
| 43 | - else |
|
| 41 | + } else |
|
| 44 | 42 | { |
| 45 | 43 | $substring = substr($identifier, $length+1); |
| 46 | 44 | $this->Data($substring, $row); |
| 47 | 45 | } |
| 48 | 46 | } |
| 49 | 47 | return json_encode($this->array); |
| 50 | - } |
|
| 51 | - else |
|
| 48 | + } else |
|
| 52 | 49 | { |
| 53 | 50 | return json_encode(null); |
| 54 | 51 | } |
| 55 | - } |
|
| 56 | - else |
|
| 52 | + } else |
|
| 57 | 53 | { |
| 58 | 54 | echo "Query Failed"; |
| 59 | 55 | } |
| 60 | - } |
|
| 61 | - else |
|
| 56 | + } else |
|
| 62 | 57 | { |
| 63 | 58 | header('Location:../login.php'); |
| 64 | 59 | } |
@@ -129,8 +129,7 @@ |
||
| 129 | 129 | </html> |
| 130 | 130 | |
| 131 | 131 | <?php |
| 132 | -} |
|
| 133 | -else{ |
|
| 132 | +} else{ |
|
| 134 | 133 | header('Location:http://www.localhost/openchat/login.php'); |
| 135 | 134 | } |
| 136 | 135 | ?> |