Exemple #1
0
 function ajaxChat($jid)
 {
     if (!$this->validateJid($jid)) {
         return;
     }
     $c = new Chats();
     $c->ajaxOpen($jid);
     RPC::call('movim_redirect', $this->route('chat', $jid));
 }
Exemple #2
0
 /**
  * @brief Get a discussion
  * @param string $jid
  */
 function ajaxGet($jid = null)
 {
     if ($jid == null) {
         RPC::call('movim_fill', 'chat_widget', $this->prepareEmpty());
     } else {
         $chats = new Chats();
         $chats->ajaxGetHistory($jid);
         $html = $this->prepareChat($jid);
         $header = $this->prepareHeader($jid);
         Header::fill($header);
         RPC::call('movim_fill', 'chat_widget', $html);
         RPC::call('MovimTpl.scrollPanel');
         RPC::call('MovimTpl.showPanel');
         $this->prepareMessages($jid);
     }
 }
Exemple #3
0
 function ajaxChat($jid)
 {
     $c = new Chats();
     $c->ajaxOpen($jid);
     RPC::call('movim_redirect', $this->route('chat', $jid));
 }
Exemple #4
0
 /**
  * @brief Get a discussion
  * @param string $jid
  */
 function ajaxGet($jid = null)
 {
     if ($jid == null) {
         RPC::call('MovimUtils.pushState', $this->route('chat'));
         RPC::call('MovimUtils.removeClass', '#chat_widget', 'fixed');
         RPC::call('MovimTpl.fill', '#chat_widget', $this->prepareEmpty());
     } else {
         $chats = new Chats();
         $chats->ajaxGetHistory($jid);
         $notif = new Notification();
         $notif->ajaxClear('chat|' . $jid);
         $html = $this->prepareChat($jid);
         RPC::call('MovimUtils.pushState', $this->route('chat', $jid));
         RPC::call('MovimUtils.addClass', '#chat_widget', 'fixed');
         RPC::call('MovimTpl.fill', '#chat_widget', $html);
         RPC::call('MovimTpl.showPanel');
         RPC::call('Chat.focus');
         $this->prepareMessages($jid);
     }
 }
Exemple #5
0
<?php

require_once 'database.php';
session_start();
$chat = new Chats();
if (!empty($_POST['nickname'])) {
    $_SESSION['nickname'] = $_POST['nickname'];
}
if (!empty($_POST['message']) && !empty($_SESSION['nickname'])) {
    $message = $_POST['message'];
    $name = $_SESSION['nickname'];
    $chat->sendmessage($message, $name);
}
class Chats
{
    public function __construct()
    {
        $this->sodb = new Database();
        $this->base = (object) '';
        $this->base->url = 'http://' . $_SERVER['SERVER_NAME'];
        $this->index();
    }
    public function index()
    {
        $return = array();
        $query = $this->sodb->db->prepare('SELECT * FROM messages');
        try {
            $query->execute();
            for ($i = 0; $row = $query->fetch(); $i++) {
                $return[$i] = array();
                foreach ($row as $key => $value) {
 public function voteEntity($type, $entity_type)
 {
     //status is 1 for upvote, 0 for none, -1 for downvote
     $entity_id = Input::get('id');
     $member = Auth::user()->id;
     $status = 0;
     $user_exists = 0;
     if ($entity_type) {
         //Voting on a chat
         $entity = Chats::find($entity_id);
         $voted = new ChatsVoted();
         $temp = $voted->whereuser_id($member)->wherechat_id($entity_id)->first();
         $community = Communities::wherename(Auth::user()->page)->first();
         if ($temp) {
             $voted = $temp;
             $status = $voted->status;
         } else {
             $voted->user_id = $member;
             $voted->chat_id = $entity_id;
         }
         if (preg_match('/[a-zA-Z]/', $entity->admin)) {
             $user = new User();
             $user->name = $entity->admin;
             $user = $user->findAll();
             $user_exists = 1;
         }
     } else {
         //voting on a message
         $entity = Messages::find($entity_id);
         $voted = new MessagesVoted();
         $temp = $voted->whereuser_id($member)->wheremessage_id($entity_id)->first();
         if ($temp) {
             $voted = $temp;
             $status = $voted->status;
         } else {
             $voted->user_id = $member;
             $voted->message_id = $entity_id;
         }
         if (preg_match('/[a-zA-Z]/', $entity->author)) {
             $user = new User();
             $user->name = $entity->author;
             $user = $user->findAll();
             $user_exists = 1;
         }
     }
     /* MODIFY USER COGNIZANCE BASED ON UP OR DOWN VOTE */
     if ($user_exists) {
         if ($user->name != Auth::user()->name) {
             // create/modify asymmetric interaction
             $interaction_user = InteractionUsers::whereuser_id(Auth::user()->id)->whereentity_id($user->id)->wheretype(0)->first();
             if ($interaction_user) {
                 $interaction_user->bond = $interaction_user->bond - $status + $type;
                 if ($interaction_user->bond < 1) {
                     $interaction_user->delete();
                 } else {
                     $interaction_user->save();
                 }
                 $interaction_friend = InteractionUsers::whereentity_id(Auth::user()->id)->whereuser_id($user->id)->wheretype(0)->first();
                 if ($interaction_friend->bond < 1) {
                     $interaction_friend->delete();
                 } else {
                     $interaction_friend->save();
                 }
                 $interaction_friend->save();
             } else {
                 if ($type - $status > 0) {
                     $inter_user = new InteractionUsers();
                     $inter_user->user_id = Auth::user()->id;
                     $inter_user->entity_id = $user->id;
                     $inter_user->bond = $type - $status;
                     $inter_user->save();
                     $inter_friend = new InteractionUsers();
                     $inter_friend->user_id = $user->id;
                     $inter_friend->entity_id = Auth::user()->id;
                     $inter_friend->bond = 1;
                     $inter_friend->save();
                 }
             }
         }
         if ($user->level == 0) {
             if ($type == -1 && ($status == 0 || $status == -1)) {
             } else {
                 if ($type == 1 && $status == -1) {
                     $user->total_cognizance = $user->total_cognizance + 1;
                     if ($user->cognizance + 1 >= $user->next_level) {
                         $user->cognizance = ($user->cognizance + 1) % $user->next_level;
                         $user->level = $user->level + 1;
                         $user->next_level = $this->nextLevel($user->level);
                     } else {
                         $user->cognizance = ($user->cognizance + 1) % $user->next_level;
                     }
                 } else {
                     if ($type == -1 && $status == 1 || $type == 1 && $status == 1) {
                         $user->total_cognizance = $user->total_cognizance - 1;
                         if ($user->level > 0 && $user->cognizance - 1 < 0) {
                             $user->level = $user->level - 1;
                             $user->next_level = $this->nextLevel($user->level);
                             $user->cognizance = $user->next_level - 1;
                         } else {
                             $user->cognizance = ($user->cognizance - 1) % $user->next_level;
                         }
                     } else {
                         $user->total_cognizance = $user->total_cognizance - $status + $type;
                         if ($user->cognizance - $status + $type >= $user->next_level) {
                             $user->cognizance = ($user->cognizance - $status + $type) % $user->next_level;
                             $user->level = $user->level + 1;
                             $user->next_level = $this->nextLevel($user->level);
                         } else {
                             $user->cognizance = ($user->cognizance - $status + $type) % $user->next_level;
                         }
                     }
                 }
             }
         } else {
             $user->total_cognizance = $user->total_cognizance - $status + $type;
             if ($user->cognizance - $status + $type >= $user->next_level) {
                 $user->cognizance = ($user->cognizance - $status + $type) % $user->next_level;
                 $user->level = $user->level + 1;
                 $user->next_level = $this->nextLevel($user->level);
             } else {
                 if ($user->level > 0 && $user->cognizance - $status + $type < 0) {
                     $user->level = $user->level - 1;
                     $user->next_level = $this->nextLevel($user->level);
                     $user->cognizance = $user->next_level - $status + $type;
                 } else {
                     $user->cognizance = ($user->cognizance - $status + $type) % $user->next_level;
                 }
             }
         }
         $user->save();
     }
     if ($entity_type) {
         foreach ($entity->communities as $community) {
             $usercommunity = UsersToCommunities::wherecommunity_id($community->id)->whereuser_id(Auth::user()->id)->first();
             if ($usercommunity) {
                 $usercommunity->score = $usercommunity->score - $status + $type;
                 $usercommunity->save();
             }
             $community->popularity = $community->popularity - $status + $type;
             $community->save();
         }
     }
     /* MODIFY MESSAGE OR CHAT UPVOTES AND DOWNVOTES */
     if ($entity_type) {
         $chat_to_community = ChatsToCommunities::wherechat_id($entity->id)->wherecommunity_id($community->id)->first();
         if ($chat_to_community) {
             $chat_to_community->upvotes = $type == $status && $type == 1 ? $chat_to_community->upvotes - 1 : ($type != $status && $type == 1 ? $chat_to_community->upvotes + 1 : ($status == 1 && $type == -1 ? $chat_to_community->upvotes - 1 : $chat_to_community->upvotes));
             $chat_to_community->downvotes = $type == $status && $type == -1 ? $chat_to_community->downvotes - 1 : ($type != $status && $type == -1 ? $chat_to_community->downvotes + 1 : ($status == -1 && $type == 1 ? $chat_to_community->downvotes - 1 : $chat_to_community->downvotes));
             $chat_to_community->save();
         } else {
             $chat_to_communities = ChatsToCommunities::wherechat_id($chat_to_community->id)->get();
             foreach ($chat_to_communities as $chat_to_community) {
                 $chat_to_community->upvotes = $type == $status && $type == 1 ? $chat_to_community->upvotes - 1 : ($type != $status && $type == 1 ? $chat_to_community->upvotes + 1 : ($status == 1 && $type == -1 ? $chat_to_community->upvotes - 1 : $chat_to_community->upvotes));
                 $chat_to_community->downvotes = $type == $status && $type == -1 ? $chat_to_community->downvotes - 1 : ($type != $status && $type == -1 ? $chat_to_community->downvotes + 1 : ($status == -1 && $type == 1 ? $chat_to_community->downvotes - 1 : $chat_to_community->downvotes));
                 $chat_to_community->save();
             }
         }
     }
     $entity->upvotes = $type == $status && $type == 1 ? $entity->upvotes - 1 : ($type != $status && $type == 1 ? $entity->upvotes + 1 : ($status == 1 && $type == -1 ? $entity->upvotes - 1 : $entity->upvotes));
     $entity->downvotes = $type == $status && $type == -1 ? $entity->downvotes - 1 : ($type != $status && $type == -1 ? $entity->downvotes + 1 : ($status == -1 && $type == 1 ? $entity->downvotes - 1 : $entity->downvotes));
     $entity->save();
     if ($type == 1 && $status == -1) {
         //downvoted previously and now upvoted
         $voted->status = 1;
         $voted->save();
         return array('status' => 1, 'upvotes' => $entity->upvotes - $entity->downvotes);
     } elseif ($type == -1 && $status == 1) {
         // upvoted previously and now downvoted
         $voted->status = -1;
         $voted->save();
         return array('status' => 1, 'upvotes' => $entity->upvotes - $entity->downvotes);
     } elseif ($status == 1 && $type == 1 || $status == 0 && $type == -1) {
         //upvoted previously or first time downvoting
         if ($type == 1) {
             $voted->status = 0;
             $voted->save();
             return array('status' => 2, 'upvotes' => $entity->upvotes - $entity->downvotes);
         } else {
             $voted->status = -1;
             $voted->save();
             return array('status' => 3, 'upvotes' => $entity->upvotes - $entity->downvotes);
         }
     } else {
         //first time upvoting or downvoted previously now downvoted
         if ($type == 1) {
             $voted->status = 1;
             $voted->save();
             return array('status' => 3, 'upvotes' => $entity->upvotes - $entity->downvotes);
         } else {
             $voted->status = 0;
             $voted->save();
             return array('status' => 2, 'upvotes' => $entity->upvotes - $entity->downvotes);
         }
     }
 }