/** * Notify all contact that the user goes offline and remove subscriptions to NetSync channels */ private function markOffline() { $procList = ProcManager::getInstance()->getProcessesList(); foreach ($procList as $pid => $proc) { if ($proc == 'session') { $userId = ProcManager::getInstance()->getProcessByPid($pid)->getLoginContext()->getEyeosUser()->getId(); } } if (!$userId) { return; } $subscriptionProvider = new SqlSubscriptionProvider(); // Notify to all Contacts that the user goes offline $contacts = PeopleController::getInstance()->getAllContacts($userId); $ids = array(); $myCometSender = new CometSenderLongPolling(); foreach ($contacts as $contact) { $id = $contact->getRelation()->getSourceId(); if ($id == $userId) { $id = $contact->getRelation()->getTargetId(); } $message = new NetSyncMessage('status', 'offline', $id, $userId); $myCometSender->send($message); } // Remove Subscriptions to NetSync channels $subscriptionProvider->removeAllSubscriptions($userId); }
protected function notifyClosedPresence($presence) { $userId = $presence->getUserId(); $peopleController = PeopleController::getInstance(); $contacts = $peopleController->getAllContacts($userId); foreach ($contacts as $contact) { if ($contact->getRelation()->getSourceId() != $userId) { $contactId = $contact->getRelation()->getSourceId(); } else { $contactId = $contact->getRelation()->getTargetId(); } $NetSyncMessage = new NetSyncMessage('presence', 'userDisconnect', $contactId, $userId); NetSyncController::getInstance()->send($NetSyncMessage); } }
/** * TODO: To remove, only used by eyeos.socialbar-ShareWindow. * use contact manager instead * * * @param <type> $params * @return <type> */ public static function getContacts($params) { $myProcManager = ProcManager::getInstance(); $peopleController = PeopleController::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $results = array(); foreach ($params as $userId) { $otherUser = UMManager::getInstance()->getUserById($userId); $settings = MetaManager::getInstance()->retrieveMeta($otherUser); $myRelation = $peopleController->getContact($currentUserId, $userId); $lists = array(); $listsName = array(); $tagsPerImpression = ImpressionsManager::getInstance()->getTagsPerImpression($myRelation->getImpression()); foreach ($tagsPerImpression as $tagPerImpression) { $lists[] = $tagPerImpression->getTagId(); $listsName[] = $peopleController->getTagName($tagPerImpression->getTagId()); } $result[] = array('id' => $userId, 'name' => $settings->get('eyeos.user.firstname') . ' ' . $settings->get('eyeos.user.lastname'), 'listsName' => $listsName); } return $result; }
public static function searchPeople($params) { //Buscar en Provider con consulta rollo LIKE etc... $peopleController = PeopleController::getInstance(); $resultsSearch = $peopleController->searchContacts($params); $myProcManager = ProcManager::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); //$peopleController = new PeopleController(); $results = array(); foreach ($resultsSearch as $result) { if ($result != $currentUserId) { // I don't want to search myself try { $user = UMManager::getInstance()->getUserById($result); } catch (Exception $e) { continue; } $settings = MetaManager::getInstance()->retrieveMeta($user); $nameOfUser = $user->getName(); $realName = $nameOfUser; $description = 'No description'; $pathImage = 'index.php?extern=images/48x48/apps/system-users.png'; if ($settings != null) { if ($settings->get('eyeos.user.firstname') != null && $settings->get('eyeos.user.lastname') != null) { $realName = $settings->get('eyeos.user.firstname') . ' ' . $settings->get('eyeos.user.lastname'); } if ($settings->get('eyeos.user.currentlife.city') != null) { $description = $settings->get('eyeos.user.currentlife.city'); } } $myRelationManager = RelationsManager::getInstance(); $relation = $myRelationManager->getRelation($result, $currentUserId); $state = $relation != null ? $relation->getState() : null; $results[] = array('userId' => $result, 'description' => $nameOfUser, 'realName' => $realName, 'state' => $state); } } return $results; }
/** * program entrypoint * * @access public * @param AppExecutionContext $context * @param MMapResponse $response */ public static function __run(AppExecutionContext $context, MMapResponse $response) { $buffer = ''; $basePath = EYE_ROOT . '/' . APPS_DIR . '/netsync/'; $buffer .= file_get_contents($basePath . 'netsync.js'); $response->appendToBody($buffer); //notify users about my new online status, i'm inside netsync! $peopleController = PeopleController::getInstance(); //now we have the patch, lets apply it! $myProcManager = ProcManager::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $contacts = $peopleController->getAllContacts($currentUserId); $ids = array(); $myCometSender = new CometSenderLongPolling(); foreach ($contacts as $contact) { $id = $contact->getRelation()->getSourceId(); if ($id == $currentUserId) { $id = $contact->getRelation()->getTargetId(); } $message = new NetSyncMessage('status', 'online', $id, $currentUserId); $myCometSender->send($message); } }
/** * Handle the answer provided by the user and execute the relative action * * @param AbstractEventNotification $event */ public function handleAnswer(AbstractEventNotification $event) { if ($event->getAnswer() === null || !is_string($event->getAnswer())) { throw new EyeInvalidArgumentException('Missing or invalid answer property'); } $peopleController = PeopleController::getInstance(); switch ($event->getAnswer()) { case 'Confirm': try { //Action for add the contact $myProcManager = ProcManager::getInstance(); $currentUser = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser(); $peopleController = PeopleController::getInstance(); $peopleController->confirmContact($currentUser, $user = UMManager::getInstance()->getUserById($event->getSender())); //Send message to the BUS $message = new ClientBusMessage('events', 'confirmContact', $event->getSender()); ClientMessageBusController::getInstance()->queueMessage($message); } catch (Exception $e) { //FIXME There should be real control on exception } break; case 'Cancel': try { //Action for delete the contact $contact = $peopleController->getContact($event->getReceiver(), $event->getSender()); $peopleController->removeContact($contact); //Send message to the bus $message = new ClientBusMessage('events', 'deleteContact', $event->getSender()); ClientMessageBusController::getInstance()->queueMessage($message); } catch (Exception $e) { //FIXME There should be real control on exception } break; default: throw new EyeInvalidArgumentException('The answer to this events is not correct'); } }
public static function getRecentsContacts($params) { $myProcManager = ProcManager::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $myRelationManager = RelationsManager::getInstance(); $lastRelationIds = $myRelationManager->getLastRelationsId($currentUserId, $params); $results = array(); $peopleController = PeopleController::getInstance(); foreach ($lastRelationIds as $resultId) { $result = $peopleController->getContact($currentUserId, $resultId); if ($result->getRelation()->getSourceId() != $currentUserId) { $contactId = $result->getRelation()->getSourceId(); } else { $contactId = $result->getRelation()->getTargetId(); } $state = $result->getRelation()->getState(); $lists = array(); $listsName = array(); $tagsPerImpression = ImpressionsManager::getInstance()->getTagsPerImpression($result->getImpression()); foreach ($tagsPerImpression as $tagPerImpression) { $lists[] = $tagPerImpression->getTagId(); $listsName[] = $peopleController->getTagName($tagPerImpression->getTagId()); } $otherUser = UMManager::getInstance()->getUserById($contactId); $meta = MetaManager::getInstance()->retrieveMeta($otherUser)->getAll(); $results[] = array('id' => $contactId, 'nickname' => $otherUser->getName(), 'lists' => $lists, 'listsName' => $listsName, 'state' => $state, 'meta' => $meta); } return $results; }
public function listen($manager) { $userId = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $username = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser()->getName(); $subscriptionProvider = new SqlSubscriptionProvider(); if ($subscriptionProvider->getSubscriptions($userId) == false) { /** * User try to listen message, but for same reason (connection problem, logout) * netSync delete subscriptions to this user. * * Stop LongPolling and notify client */ echo "forceRefresh"; exit; } //$myPressence = new Pressence(); //$myPressence->markOnline($username, $manager); session_write_close(); set_time_limit(0); ignore_user_abort(1); header('Cache-Control: no-cache, must-revalidate'); header('Content-type: application/json'); $Logger = Logger::getLogger('system.Frameworks.EyeosModules.NetSync'); //one of every 20 loops, will update the pressence time //but the first one, should do it ever $loop = 20; while (1) { try { echo "\n"; ob_flush(); flush(); if (connection_status() != CONNECTION_NORMAL) { //Maybe user gone offline sleep(35); //Check if user is still connected if (!$subscriptionProvider->isUserConnected($userId)) { // if not notify to all contacts $contacts = PeopleController::getInstance()->getAllContacts($userId); $ids = array(); $myCometSender = new CometSenderLongPolling(); foreach ($contacts as $contact) { $id = $contact->getRelation()->getSourceId(); if ($id == $userId) { $id = $contact->getRelation()->getTargetId(); } $message = new NetSyncMessage('status', 'offline', $id, $userId); //TODO24 ultra hardcoded, we need some kind of php listeners here! $myCometSender->send($message); } shell_exec('rm -rf ' . escapeshellarg(EYE_ROOT . '/' . USERS_DIR . '/' . utf8_basename($username) . '/files/.office/')); $subscriptionProvider->removeAllSubscriptions($userId); } exit; } if ($loop == 20) { $mySubscriptionProvider = new SqlSubscriptionProvider(); $mySubscriptionProvider->refreshPressence($userId); $loop = 0; } else { $loop++; } $mySubscriptionProvider = new SqlSubscriptionProvider(); $channels = $mySubscriptionProvider->getSubscriptions($userId); $messageProvider = new CometSqlMessageProvider(); if (is_array($channels)) { $messages = $messageProvider->read($channels, $userId, $this->lastId); if (is_array($messages) && count($messages) > 0) { @session_start(); usort($messages, "customMessageComparation"); $_SESSION['comet']['lastid'] = $messages[count($messages) - 1]['id']; //$Logger->debug("last message id: " . $_SESSION['comet']['lastid']); //@todo use pseudo-random-related-to-tableid or something as transaction ID, no a id of table return $messages; } } sleep(1); } catch (Exception $e) { $logger = Logger::getLogger('netsync'); $logger->fatal('Exception in netsync!'); $logger->fatal(ExceptionStackUtil::getStackTrace($e, false)); exit; } } }
{ // nothing to do for the moment.... } public function beforeTagDeletionToContact(PeopleEvent $e) { // nothing to do for the moment.... } public function tagDeletedToContact(PeopleEvent $e) { // nothing to do for the moment.... } public function tagCreated(PeopleEvent $e) { // nothing to do for the moment.... } public function tagModified(PeopleEvent $e) { // nothing to do for the moment.... } public function beforeTagDeletion(PeopleEvent $e) { // nothing to do for the moment.... } public function tagRemoved(PeopleEvent $e) { // nothing to do for the moment.... } } // Register singleton listener on the target dispatcher PeopleController::getInstance()->addPeopleListener(ContactManagerPeopleListener::getInstance());
/** * Update the Lists of a Contact whit a new one and return a list of changes * * @param string $contactId The id of the contact involved in the changes * @param array $newLists The array with the new list of the contact * * @return array $results = ( * 'add' => array, The list of the id that was added * 'delete' => array The list of the id that was removed * ) * */ private static function syncLists($contactId, $newLists) { $myProcManager = ProcManager::getInstance(); $peopleController = PeopleController::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $contact = $peopleController->getContact($currentUserId, $contactId); //Retrive the old list $oldLists = array(); $tagsPerImpression = ImpressionsManager::getInstance()->getTagsPerImpression($contact->getImpression()); foreach ($tagsPerImpression as $tagPerImpression) { $oldLists[] = $tagPerImpression->getTagId(); } //Check if we have to add Tags $results = array('add' => array(), 'delete' => array()); foreach ($newLists as $newTagId) { if (!in_array($newTagId, $oldLists)) { //Add the tag to the contact $tag = new PeopleTag(); $tag->setId($newTagId); $tag->setName($peopleController->getTagName($newTagId)); $tag->setUserId($currentUserId); $peopleController->addTagToContact($tag, $contact); //Update the return value $results['add'][] = (int) $newTagId; } } //Check if we have to delete Tags foreach ($oldLists as $oldTagId) { if (!in_array($oldTagId, $newLists)) { //Add the tag to the contact $tag = new PeopleTag(); $tag->setId($oldTagId); $tag->setName($peopleController->getTagName($oldTagId)); $tag->setUserId($currentUserId); $peopleController->removeTagToContact($tag, $contact); //Update the return value $results['delete'][] = (int) $oldTagId; } } return $results; }
public static function getAllContacts($params) { $peopleController = PeopleController::getInstance(); $myProcManager = ProcManager::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $tempResults = $peopleController->getAllContacts($currentUserId); $results = array(); foreach ($tempResults as $result) { if ($result->getRelation()->getSourceId() != $currentUserId) { $contactId = $result->getRelation()->getSourceId(); } else { $contactId = $result->getRelation()->getTargetId(); } $lists = array(); $listsName = array(); $tagsPerImpression = ImpressionsManager::getInstance()->getTagsPerImpression($result->getImpression()); foreach ($tagsPerImpression as $tagPerImpression) { $lists[] = $tagPerImpression->getTagId(); $listsName[] = $peopleController->getTagName($tagPerImpression->getTagId()); } $otherUser = UMManager::getInstance()->getUserById($contactId); $settings = MetaManager::getInstance()->retrieveMeta($otherUser); $nameOfUser = utf8_encode($otherUser->getName()); $pathImage = 'index.php?extern=images/48x48/apps/system-users.png'; if ($settings != null) { if ($settings->get('eyeos.user.picture.url') != null) { $pathImage = $settings->get('eyeos.user.picture.url'); } if ($settings->get('eyeos.user.firstname') != null && $settings->get('eyeos.user.lastname') != null) { $nameOfUser = utf8_encode($settings->get('eyeos.user.firstname') . ' ' . $settings->get('eyeos.user.lastname')); } } $results[] = array('userId' => $contactId, 'userName' => $nameOfUser, 'image' => $pathImage, 'lists' => $lists, 'listsName' => $listsName, 'icon' => $pathImage); } return $results; }
/** * Retrieve the name of a tag by its id */ public static function getListName($listId) { $myProcManager = ProcManager::getInstance(); $currentUserId = $myProcManager->getCurrentProcess()->getLoginContext()->getEyeosUser()->getId(); $peopleController = PeopleController::getInstance(); return $peopleController->getTagName($listId); }
public function listFiles($pattern = '*', $flags = AdvancedPathLib::GLOB_NORMAL) { $files = array(); $urlParts = $this->getURLComponents(); $isRoot = false; if (!isset($urlParts['principalname'])) { $isRoot = true; if ($urlParts['path'] != '/') { throw new EyeBadMethodCallException('Cannot list files: ' . $this->path . ' is not a (handled) directory.'); } } // ROOT (share://): list the owners sharing files with the current user if ($isRoot) { //--- Legacy code [I'd like to keep this part of the code in case some people change suddenly their minds, once again...] /*$currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $shareInfo = SharingManager::getInstance()->getAllShareInfoFromCollaborator($currentUser, null, 'IShareableFile'); // Build an array(ownerId => ownerName) $owners = array(); foreach($shareInfo as $shareInfoData) { try { $currentOwner = $shareInfoData->getOwner(); if (!isset($owners[$currentOwner->getId()])) { $owners[$currentOwner->getId()] = $currentOwner->getName(); } } catch (Exception $e) { Logger::getLogger('system.services.FileSystem.EyeSharedFile')->warn('Cannot retrieve ShareInfo components from shared file: "' . $shareInfoData->getShareable() . '", skipping.'); } } sort($owners); foreach($owners as $ownerName) { $files[] = new EyeSharedFile(self::URL_SCHEME_SHARE . '://' . self::URL_LOCATOR_CHAR . $ownerName . '/'); }*/ //--- Legacy code $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $peopleController = PeopleController::getInstance(); $contacts = $peopleController->getAllContacts($currentUser->getId()); foreach ($contacts as $contact) { if ($contact->getRelation()->getSourceId() == $currentUser->getId()) { $otherUser = UMManager::getInstance()->getUserById($contact->getRelation()->getTargetId()); } else { $otherUser = UMManager::getInstance()->getUserById($contact->getRelation()->getSourceId()); } $files[] = new EyeSharedFile(self::URL_SCHEME_SHARE . '://' . self::URL_LOCATOR_CHAR . $otherUser->getName() . '/'); } } else { if ($flags & AdvancedPathLib::GLOB_ONLY_DIR) { // Folders are not shareable yet return array(); } $ownerName = $urlParts['principalname']; $owner = UMManager::getInstance()->getUserByName($ownerName); $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); // CURRENT USER ROOT (share://~currentUser/): Show the list of all the files that are currently // shared by the current user if ($owner == $currentUser) { $shareInfo = SharingManager::getInstance()->getAllShareInfoFromOwner($currentUser, 'IShareableFile'); } else { $shareInfo = SharingManager::getInstance()->getAllShareInfoFromCollaborator($currentUser, $owner, 'IShareableFile'); } // Special temporary array for files IDs to avoid duplication in the returned array $fileIds = array(); foreach ($shareInfo as $shareInfoData) { $sharedFile = $shareInfoData->getShareable(); $id = $sharedFile->getId(); if (!isset($fileIds[$id])) { $fileIds[$id] = 0; // Arbitrary value (we only use keys in this array) $files[] = $sharedFile; } } } return $files; }