Exemple #1
0
 public function onPing(OW_Event $event)
 {
     $eventParams = $event->getParams();
     $params = $eventParams['params'];
     if ($eventParams['command'] != 'ajaxim_ping') {
         return;
     }
     $service = AJAXIM_BOL_Service::getInstance();
     if (empty($_SESSION['lastRequestTimestamp'])) {
         $_SESSION['lastRequestTimestamp'] = (int) $params['lastRequestTimestamp'];
     }
     if ((int) $params['lastRequestTimestamp'] - (int) $_SESSION['lastRequestTimestamp'] < 3) {
         $event->setData(array('error' => "Too much requests"));
     }
     $_SESSION['lastRequestTimestamp'] = (int) $params['lastRequestTimestamp'];
     if (!OW::getUser()->isAuthenticated()) {
         $event->setData(array('error' => "You have to sign in"));
     }
     if (!OW::getRequest()->isAjax()) {
         $event->setData(array('error' => "Ajax request required"));
     }
     $onlinePeople = AJAXIM_BOL_Service::getInstance()->getOnlinePeople(OW::getUser());
     if (!empty($params['lastMessageTimestamps'])) {
         $clientOnlineList = array_keys($params['lastMessageTimestamps']);
     } else {
         $clientOnlineList = array();
     }
     $onlineInfo = array();
     /* @var $user BOL_User */
     foreach ($onlinePeople['users'] as $user) {
         if (!OW::getAuthorization()->isUserAuthorized($user->getId(), 'ajaxim', 'chat') && !OW::getAuthorization()->isUserAuthorized($user->getId(), 'ajaxim')) {
             $onlinePeople['count']--;
             continue;
         }
         if (!in_array($user->getId(), $clientOnlineList)) {
             $friendship = OW::getEventManager()->call('plugin.friends.check_friendship', array('userId' => OW::getUser()->getId(), 'friendId' => $user->getId()));
             $roster = $service->getUserInfoByNode($user, $friendship);
             $roster['show'] = 'chat';
             $roster['status'] = 'online';
             $presence = array('node' => $user->getId(), 'data' => $roster);
             $onlineInfo[] = $presence;
         }
     }
     /* @var $user BOL_User */
     foreach ($clientOnlineList as $userId) {
         if (!array_key_exists($userId, $onlinePeople['users'])) {
             $presence = array('node' => $userId, 'data' => array('status' => 'offline'));
             $onlineInfo[] = $presence;
         }
     }
     switch ($params['action']) {
         case "get":
             $response = array();
             if (!empty($onlineInfo)) {
                 $response['presenceList'] = $onlineInfo;
             }
             if ($onlinePeople['count'] != $params['onlineCount']) {
                 $response['onlineCount'] = $onlinePeople['count'];
             }
             if (!empty($params['lastMessageTimestamps'])) {
                 $messageList = AJAXIM_BOL_Service::getInstance()->findUnreadMessages(OW::getUser(), $params['lastMessageTimestamps']);
                 if (!empty($messageList)) {
                     $response['messageList'] = $messageList;
                     $response['messageListLength'] = count($messageList);
                 }
             }
             $event->setData($response);
             break;
     }
 }
Exemple #2
0
 public function getUserInfoByNode($user, $friendship)
 {
     $this->checkPermissions();
     $url = BOL_UserService::getInstance()->getUserUrl($user->getId());
     $avatar = BOL_AvatarService::getInstance()->getAvatarUrl($user->getId());
     if (empty($avatar)) {
         $avatar = BOL_AvatarService::getInstance()->getDefaultAvatarUrl();
     }
     $is_friend = false;
     if (!empty($friendship) && $friendship->getStatus() == 'active') {
         $is_friend = true;
     }
     $info = array('node' => $user->getId(), 'username' => BOL_UserService::getInstance()->getDisplayName($user->getId()), 'user_avatar_src' => $avatar, 'user_url' => $url, 'isFriend' => $is_friend, 'isBlocker' => BOL_UserService::getInstance()->isBlocked(OW::getUser()->getId(), $user->getId()), 'lastMessageTimestamp' => 1000 * AJAXIM_BOL_Service::getInstance()->getLastMessageTimestamp(OW::getUser()->getId(), $user->getId()));
     return $info;
 }
Exemple #3
0
 public function render()
 {
     OW::getDocument()->addScript(OW::getPluginManager()->getPlugin("base")->getStaticJsUrl() . "jquery-ui.min.js");
     OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('ajaxim')->getStaticJsUrl() . 'audio-player.js');
     OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('ajaxim')->getStaticJsUrl() . 'ajaxim.js');
     $node = OW::getUser()->getId();
     $password = '';
     $domain = 'localhost';
     $port = 0;
     $username = BOL_UserService::getInstance()->getDisplayName($node);
     $avatar = BOL_AvatarService::getInstance()->getAvatarUrl(OW::getUser()->getId());
     if (empty($avatar)) {
         $avatar = BOL_AvatarService::getInstance()->getDefaultAvatarUrl();
     }
     $jsGenerator = UTIL_JsGenerator::newInstance();
     $jsGenerator->setVariable('im_oldTitle', OW::getDocument()->getTitle());
     $jsGenerator->setVariable('im_soundEnabled', (bool) BOL_PreferenceService::getInstance()->getPreferenceValue('ajaxim_user_settings_enable_sound', OW::getUser()->getId()));
     $jsGenerator->setVariable('im_awayTimeout', 5000);
     //TODO change to 30000
     $jsGenerator->setVariable('im_soundSwf', OW::getPluginManager()->getPlugin('ajaxim')->getStaticUrl() . 'js/player.swf');
     $jsGenerator->setVariable('im_soundUrl', OW::getPluginManager()->getPlugin('ajaxim')->getStaticUrl() . 'sound/receive.mp3');
     $jsGenerator->setVariable('window.ajaximLogMsgUrl', OW::getRouter()->urlFor('AJAXIM_CTRL_Action', 'logMsg'));
     $jsGenerator->setVariable('window.ajaximGetLogUrl', OW::getRouter()->urlFor('AJAXIM_CTRL_Action', 'getLog'));
     $jsGenerator->setVariable('window.im_updateUserInfoUrl', OW::getRouter()->urlFor('AJAXIM_CTRL_Action', 'updateUserInfo'));
     $jsGenerator->setVariable('window.im_userBlockedMessage', OW::getLanguage()->text('base', 'user_block_message'));
     $site_timezone = OW::getConfig()->getValue('base', 'site_timezone');
     $site_datetimezone = new DateTimeZone($site_timezone);
     $site_datetime = new DateTime("now", $site_datetimezone);
     $jsGenerator->setVariable('ajaximSiteTimezoneOffset', $site_datetimezone->getOffset($site_datetime) * 1000);
     $isFriendsOnlyMode = (bool) OW::getEventManager()->call('plugin.friends');
     $jsGenerator->setVariable('im_isFriendsOnlyMode', (bool) $isFriendsOnlyMode);
     $privacyPluginActive = OW::getEventManager()->call('plugin.privacy');
     $this->assign('privacyPluginActive', $privacyPluginActive);
     $privacyActionValue = OW::getEventManager()->call('plugin.privacy.get_privacy', array('ownerId' => OW::getUser()->getId(), 'action' => 'ajaxim_invite_to_chat'));
     $jsGenerator->setVariable('im_privacyActionValue', $privacyActionValue);
     if ($privacyPluginActive) {
         $this->assign('privacy_settings_url', OW::getRouter()->urlForRoute('privacy_index'));
         $visibleForFriends = $privacyActionValue == 'friends_only';
         $visibleForEverybody = $privacyActionValue == 'everybody';
     } else {
         $visibleForFriends = false;
         $visibleForEverybody = true;
     }
     $jsGenerator->setVariable('im_visibleForFriends', $visibleForFriends);
     $jsGenerator->setVariable('im_visibleForEverybody', $visibleForEverybody);
     $this->assign('im_sound_url', OW::getPluginManager()->getPlugin('ajaxim')->getStaticUrl() . 'sound/receive.mp3');
     /* Instant Chat DEBUG MODE */
     $debugMode = false;
     $jsGenerator->setVariable('im_debug_mode', $debugMode);
     $this->assign('debug_mode', $debugMode);
     $variables = $jsGenerator->generateJs();
     $details = array('userId' => OW::getUser()->getId(), 'node' => $node, 'password' => $password, 'username' => $username, 'domain' => $domain, 'avatar' => $avatar);
     OW::getDocument()->addScriptDeclaration("window.OW_InstantChat.Details = " . json_encode($details) . ";\n " . $variables);
     $userSettingsForm = AJAXIM_BOL_Service::getInstance()->getUserSettingsForm();
     $this->addForm($userSettingsForm);
     $userSettingsForm->getElement('user_id')->setValue(OW::getUser()->getId());
     $avatar_proto_data = array('url' => 1, 'src' => BOL_AvatarService::getInstance()->getDefaultAvatarUrl(), 'class' => 'talk_box_avatar');
     $this->assign('avatar_proto_data', $avatar_proto_data);
     $this->assign('no_avatar_url', BOL_AvatarService::getInstance()->getDefaultAvatarUrl());
     $this->assign('online_list_url', OW::getRouter()->urlForRoute('base_user_lists', array('list' => 'online')));
     return parent::render();
 }
Exemple #4
0
 public function processUserSettingsForm()
 {
     if (!OW::getRequest()->isAjax()) {
         throw new Redirect404Exception();
     }
     $form = AJAXIM_BOL_Service::getInstance()->getUserSettingsForm();
     if ($form->isValid($_POST)) {
         $data = $form->getValues();
         BOL_PreferenceService::getInstance()->savePreferenceValue('ajaxim_user_settings_enable_sound', (bool) $data['im_enable_sound'], $data['user_id']);
         echo json_encode(array('im_soundEnabled' => (bool) $data['im_enable_sound']));
         exit;
     }
 }