Ejemplo n.º 1
0
 /**
  * @param $action
  * @param $httpVars
  * @param $fileVars
  *
  */
 public function clientChannelMethod($action, $httpVars, $fileVars)
 {
     if (!$this->msgExchanger) {
         return;
     }
     switch ($action) {
         case "client_register_channel":
             $this->msgExchanger->suscribeToChannel($httpVars["channel"], $httpVars["client_id"]);
             break;
         case "client_unregister_channel":
             $this->msgExchanger->unsuscribeFromChannel($httpVars["channel"], $httpVars["client_id"]);
             break;
         case "client_consume_channel":
             if (AuthService::usersEnabled()) {
                 $user = AuthService::getLoggedUser();
                 if ($user == null) {
                     //throw new Exception("You must be logged in");
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::requireAuth();
                     AJXP_XMLWriter::close();
                     return;
                 }
                 $GROUP_PATH = $user->getGroupPath();
                 if ($GROUP_PATH == null) {
                     $GROUP_PATH = false;
                 }
                 $uId = $user->getId();
             } else {
                 $GROUP_PATH = '/';
                 $uId = 'shared';
             }
             //session_write_close();
             $startTime = time();
             $maxTime = $startTime + (30 - 3);
             //               while (true) {
             $data = $this->msgExchanger->consumeInstantChannel($httpVars["channel"], $httpVars["client_id"], $uId, $GROUP_PATH);
             if (count($data)) {
                 AJXP_XMLWriter::header();
                 ksort($data);
                 foreach ($data as $messageObject) {
                     echo $messageObject->content;
                 }
                 AJXP_XMLWriter::close();
             }
             //                       break;
             //                   } else if (time() >= $maxTime) {
             //                       break;
             //                   }
             //
             //                   sleep(3);
             //               }
             break;
         default:
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * @param $action
  * @param $httpVars
  * @param $fileVars
  *
  */
 public function clientChannelMethod($action, $httpVars, $fileVars)
 {
     if (!$this->msgExchanger) {
         return;
     }
     switch ($action) {
         case "client_register_channel":
             $this->msgExchanger->suscribeToChannel($httpVars["channel"], $httpVars["client_id"]);
             break;
         case "client_unregister_channel":
             $this->msgExchanger->unsuscribeFromChannel($httpVars["channel"], $httpVars["client_id"]);
             break;
         case "client_consume_channel":
             if (AuthService::usersEnabled()) {
                 $user = AuthService::getLoggedUser();
                 if ($user == null) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::requireAuth();
                     AJXP_XMLWriter::close();
                     return;
                 }
                 $GROUP_PATH = $user->getGroupPath();
                 if ($GROUP_PATH == null) {
                     $GROUP_PATH = false;
                 }
                 $uId = $user->getId();
             } else {
                 $GROUP_PATH = '/';
                 $uId = 'shared';
             }
             $currentRepository = ConfService::getCurrentRepositoryId();
             $currentRepoMasks = array();
             $regexp = null;
             AJXP_Controller::applyHook("role.masks", array($currentRepository, &$currentRepoMasks, AJXP_Permission::READ));
             if (count($currentRepoMasks)) {
                 $regexps = array();
                 foreach ($currentRepoMasks as $path) {
                     $regexps[] = '^' . preg_quote($path, '/');
                 }
                 $regexp = '/' . implode("|", $regexps) . '/';
             }
             $channelRepository = str_replace("nodes:", "", $httpVars["channel"]);
             if ($channelRepository != $currentRepository) {
                 AJXP_XMLWriter::header();
                 echo "<require_registry_reload repositoryId=\"{$currentRepository}\"/>";
                 AJXP_XMLWriter::close();
                 return;
             }
             $data = $this->msgExchanger->consumeInstantChannel($httpVars["channel"], $httpVars["client_id"], $uId, $GROUP_PATH);
             if (count($data)) {
                 AJXP_XMLWriter::header();
                 ksort($data);
                 foreach ($data as $messageObject) {
                     if (isset($regexp) && isset($messageObject->nodePathes)) {
                         $pathIncluded = false;
                         foreach ($messageObject->nodePathes as $nodePath) {
                             if (preg_match($regexp, $nodePath)) {
                                 $pathIncluded = true;
                                 break;
                             }
                         }
                         if (!$pathIncluded) {
                             continue;
                         }
                     }
                     echo $messageObject->content;
                 }
                 AJXP_XMLWriter::close();
             }
             break;
         default:
             break;
     }
 }