private function handleClientMessageQueue(MMapResponse $response) { $messages = ClientMessageBusController::getInstance()->getQueue(); // Check for client bus messages to be appended to the response if ($messages->count() > 0) { self::$Logger->info($messages->count() . ' client bus message(s) found, processing...'); // Only if the current body/bodyrenderer is mappable to a control message $currentBodyRenderer = $response->getBodyRenderer(); if ($currentBodyRenderer !== null && !$currentBodyRenderer instanceof DataManagerBodyRenderer) { self::$Logger->error('Cannot append client bus messages: unable to replace current BodyRenderer from class ' . get_class($currentBodyRenderer) . ', ignoring.'); ClientMessageBusController::getInstance()->getQueue()->clear(); return; } $messages = $messages->getArrayCopy(); foreach ($messages as &$message) { $message = $message->toArray(); } $data = $currentBodyRenderer !== null ? $currentBodyRenderer->getRenderedBody() : $response->getBody(); $newBody = array('messages' => $messages, 'data' => $data); // When using qx.io.ScriptLoader on the JS side, no callback proxy is available // to intercept control messages, so we're using a little workaround here by // calling directly eyeos._callbackProxyWithContent() with the messages queue in // argument. $controlMessageBodyRenderer = new ControlMessageBodyRenderer(ControlMessageBodyRenderer::TYPE_ENHANCEDDATA, $newBody); $responseContent = $controlMessageBodyRenderer->getRenderedBody(); $response->appendToBody('eyeos._callbackProxyWithContent(null, null, null, ' . $responseContent . ');'); ClientMessageBusController::getInstance()->getQueue()->clear(); } }
public static function createLink($params) { $structure = array(); $structure['url'] = $params[0]; $structure['width'] = $params[1]; $structure['height'] = $params[2]; $structure['icon'] = str_replace('eyeos/extern/', 'index.php?extern=', $params[5]); $structure['openInNewWindow'] = $params[6]; $structure['type'] = 'web'; $linkName = utf8_basename($params[3]); $info = pathinfo($linkName); if (!isset($info['extension']) || $info['extension'] != 'lnk') { $linkName .= '.lnk'; } $path = $params[4]; $text = json_encode($structure); $linkName = str_replace('?', '_', $linkName); $linkName = str_replace('#', '_', $linkName); $newFile = FSI::getFile($path . '/' . $linkName); $newFile->createNewFile(); $newFile->putContents($text); $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $settings = MetaManager::getInstance()->retrieveMeta($currentUser); //TODO: better message? $message = new ClientBusMessage('file', 'uploadComplete', self::getFileInfo($newFile, $settings)); ClientMessageBusController::getInstance()->queueMessage($message); }
public function userDeleted(UMEvent $e) { if ($e->getSource() instanceof AbstractEyeosUser) { //Send message to the BUS $message = new ClientBusMessage('ummanager', 'userDeleted', $e->getSource()->getId()); ClientMessageBusController::getInstance()->queueMessage($message); MetaManager::getInstance()->deleteMeta($e->getSource()); } }
public static function submitFile($path) { try { if (!isset($_FILES['Filedata'])) { echo '<div style="font-size:20px;font-family:Helvetica, Arial, Verdana, Sans, FreeSans;margin-top:80px;margin-right:15px;"><center> <img style="position:relative;top:15px"src="index.php?extern=/images/48x48/actions/dialog-close.png" />Error uploading files</center>'; exit; } $Logger = Logger::getLogger('application.upload'); foreach ($_FILES['Filedata']['name'] as $k => $v) { if (!empty($v)) { $filename = $_FILES['Filedata']['name'][$k]; if (!isset($_POST['UPLOAD_IDENTIFIER'])) { $filename = utf8_encode($filename); } $tmpPath = $_FILES['Filedata']['tmp_name'][$k]; $Logger->debug("Filename: " . $filename); if (!is_uploaded_file($tmpPath)) { throw new EyeFileNotFoundException('Uploaded file not found at "' . $tmpPath . '".'); } $request = MMapManager::getCurrentRequest(); $destPath = $path; $filename = str_replace('?', '_', $filename); $filename = str_replace('#', '_', $filename); $tmp = pathinfo($filename); if (isset($tmp['extension']) && "lnk" == $tmp['extension']) { throw new EyeFileNotFoundException('This file cannot be uploaded (file type banned)'); } /* if ( '?' == $filename{0} ) { $filename{0} = "_"; } */ $destFile = FSI::getFile($destPath . '/' . $filename); //The uploaded file is necessarily on the local filesystem and we want to avoid any //permission check through EyeLocalFile, so we use LocalFile directly $tmpFile = new LocalFile($tmpPath); $num = 1; $extension = AdvancedPathLib::pathinfo($filename, PATHINFO_EXTENSION); $filename = AdvancedPathLib::pathinfo($filename, PATHINFO_FILENAME); $Logger->debug("CLASS: " . get_class($destFile)); $Logger->debug("Exists: " . $destFile->exists()); //exit(); while ($destFile->exists()) { $newBasename = $filename . ' (' . $num++ . ')' . ($extension ? '.' . $extension : ''); $destFile = FSI::getFile($destPath . '/' . $newBasename); } $destFile->checkWritePermission(); $tmpFile->moveTo($destFile); $currentUser = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $settings = MetaManager::getInstance()->retrieveMeta($currentUser); $message = new ClientBusMessage('file', 'uploadComplete', self::getFileInfo($destFile, $settings)); ClientMessageBusController::getInstance()->queueMessage($message); $event = new FileEvent($destFile); $destFile->fireEvent('fileWritten', $event); } } register_shutdown_function('endRequestUpload'); } catch (EyeException $e) { echo '<div style="font-size:20px;font-family:Helvetica, Arial, Verdana, Sans, FreeSans;margin-top:80px;margin-right:15px;"><center> <img style="position:relative;top:15px"src="index.php?extern=/images/48x48/actions/dialog-close.png" />Error uploading files: ' . $e->getMessage() . '</center>'; exit; } }
public static function getInstance() { if (self::$Instance === null) { self::$Instance = new ClientMessageBusController(); } return self::$Instance; }
private function handleClientMessageQueue(MMapResponse $response) { $messages = ClientMessageBusController::getInstance()->getQueue(); // Check for client bus messages to be appended to the response if ($messages->count() > 0) { self::$Logger->info($messages->count() . ' client bus message(s) found, processing...'); // Only if the current body/bodyrenderer is mappable to a control message $currentBodyRenderer = $response->getBodyRenderer(); if ($currentBodyRenderer !== null && !$currentBodyRenderer instanceof DataManagerBodyRenderer) { self::$Logger->error('Cannot append client bus messages: unable to replace current BodyRenderer from class ' . get_class($currentBodyRenderer) . ', ignoring.'); return; } $messages = $messages->getArrayCopy(); foreach ($messages as &$message) { $message = $message->toArray(); } if ($currentBodyRenderer !== null) { if ($currentBodyRenderer instanceof ControlMessageBodyRenderer) { $data = $currentBodyRenderer->getBodyData(); } else { $data = $currentBodyRenderer->getRenderedBody(); } } else { $data = $response->getBody(); } $newBody = array('messages' => $messages, 'data' => $data); $controlMessageBodyRenderer = new ControlMessageBodyRenderer(ControlMessageBodyRenderer::TYPE_ENHANCEDDATA, $newBody); $response->setBodyRenderer($controlMessageBodyRenderer); } }
/** * 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 function processStarted(ProcEvent $e) { $proc = $e->getSource(); $message = new ClientBusMessage('application', 'start', $e->getSource()->getAttributesMap()); ClientMessageBusController::getInstance()->queueMessage($message); }
public function fileWritten(FileEvent $e) { //Logger::getLogger('sebas')->error('MetadataWritten:' . $e->getSource()->getPath()); $apiManager = new ApiManager(); $path = $e->getSource()->getPath(); $user = ProcManager::getInstance()->getCurrentProcess()->getLoginContext()->getEyeosUser(); $userName = $user->getName(); $cloud = $this->isCloud($path, $userName); $resourceUrl = null; if ($cloud->isCloud) { $pathU1db = substr($path, strlen($cloud->path)); $lenfinal = strrpos($pathU1db, $e->getSource()->getName()); $posfinal = $lenfinal > 1 ? $lenfinal - strlen($pathU1db) - 1 : $lenfinal - strlen($pathU1db); $pathParent = substr($pathU1db, 0, $posfinal); $folder = NULL; if ($pathParent !== '/') { $pos = strrpos($pathParent, '/'); $folder = substr($pathParent, $pos + 1); $pathParent = substr($pathParent, 0, $pos + 1); } $parentId = false; if ($folder !== NULL) { $path = $pathParent . $folder . '/'; $lista = new stdClass(); $lista->cloud = $cloud->name; $lista->path = $pathParent; $lista->filename = $folder; $lista->user_eyeos = $user->getId(); $u1db = json_decode($apiManager->callProcessU1db('parent', $lista)); if ($u1db !== NULL && count($u1db) > 0) { $parentId = $u1db[0]->id; if (isset($u1db[0]->resource_url)) { $resourceUrl = new stdClass(); $resourceUrl->resource_url = $u1db[0]->resource_url; $resourceUrl->token = new stdClass(); $resourceUrl->token->key = $u1db[0]->access_token_key; $resourceUrl->token->secret = $u1db[0]->access_token_secret; if ($parentId === 'null') { $parentId = 0; } } } } else { $parentId = '0'; $path = $pathParent; } if ($parentId !== false) { $pathAbsolute = AdvancedPathLib::getPhpLocalHackPath($e->getSource()->getRealFile()->getAbsolutePath()); $token = $_SESSION['access_token_' . $cloud->name . '_v2']; if ($resourceUrl) { $token = $resourceUrl->token; $resourceUrl = $resourceUrl->resource_url; } $result = $apiManager->createMetadata($cloud->name, $token, $user->getId(), true, $e->getSource()->getName(), $parentId, $path, $pathAbsolute, $resourceUrl); if ($result['status'] == 'OK') { $params = array($e->getSource()->getParentPath(), $e->getSource()->getPath()); $message = new ClientBusMessage('file', 'refreshStackSync', $params); ClientMessageBusController::getInstance()->queueMessage($message); } else { if ($result['error'] == 403) { $path = $this->cleanCloud($cloud->name, $user); $params = array($path, $cloud->name); $message = new ClientBusMessage('file', 'permissionDenied', $params); ClientMessageBusController::getInstance()->queueMessage($message); } } } } }