public function loadUserFeed($actionName, $httpVars, $fileVars)
 {
     if (!$this->eventStore) {
         return array();
     }
     $u = AuthService::getLoggedUser();
     if ($u == null) {
         if ($httpVars["format"] == "html") {
             return array();
         }
         AJXP_XMLWriter::header();
         AJXP_XMLWriter::close();
         return array();
     }
     $userId = $u->getId();
     $userGroup = $u->getGroupPath();
     $authRepos = array();
     $crtRepId = ConfService::getCurrentRepositoryId();
     if (isset($httpVars["repository_id"]) && $u->mergedRole->canRead($httpVars["repository_id"])) {
         $authRepos[] = $httpVars["repository_id"];
     } else {
         if (isset($httpVars["current_repository"])) {
             $authRepos[] = $crtRepId;
         } else {
             $accessibleRepos = ConfService::getAccessibleRepositories(AuthService::getLoggedUser(), false, true, false);
             $authRepos = array_keys($accessibleRepos);
         }
     }
     $offset = isset($httpVars["offset"]) ? intval($httpVars["offset"]) : 0;
     $limit = isset($httpVars["limit"]) ? intval($httpVars["limit"]) : 15;
     if (!isset($httpVars["feed_type"]) || $httpVars["feed_type"] == "notif" || $httpVars["feed_type"] == "all") {
         $res = $this->eventStore->loadEvents($authRepos, isset($httpVars["path"]) ? $httpVars["path"] : "", $userGroup, $offset, $limit, false, $userId);
     } else {
         $res = array();
     }
     $mess = ConfService::getMessages();
     $format = "html";
     if (isset($httpVars["format"])) {
         $format = $httpVars["format"];
     }
     if ($format == "html") {
         echo "<h2>" . $mess["notification_center.4"] . "</h2>";
         echo "<ul class='notification_list'>";
     } else {
         if ($format == "json") {
             $jsonNodes = array();
         } else {
             if ($format != 'array') {
                 AJXP_XMLWriter::header();
             }
         }
     }
     // APPEND USER ALERT IN THE SAME QUERY FOR NOW
     if (!isset($httpVars["feed_type"]) || $httpVars["feed_type"] == "alert" || $httpVars["feed_type"] == "all") {
         $this->loadUserAlerts("", array_merge($httpVars, array("skip_container_tags" => "true")), $fileVars);
     }
     restore_error_handler();
     $index = 1;
     foreach ($res as $n => $object) {
         $args = $object->arguments;
         $oldNode = isset($args[0]) ? $args[0] : null;
         $newNode = isset($args[1]) ? $args[1] : null;
         $copy = isset($args[2]) && $args[2] === true ? true : null;
         $notif = $this->generateNotificationFromChangeHook($oldNode, $newNode, $copy, "unify");
         if ($notif !== false && $notif->getNode() !== false) {
             $notif->setAuthor($object->author);
             $notif->setDate(intval($object->date));
             if ($format == "html") {
                 $p = $notif->getNode()->getPath();
                 echo "<li data-ajxpNode='{$p}'>";
                 echo $notif->getDescriptionShort(true);
                 echo "</li>";
             } else {
                 $node = $notif->getNode();
                 if ($node == null) {
                     $this->logInfo("Warning", "Empty node stored in notification " . $notif->getAuthor() . "/ " . $notif->getAction());
                     continue;
                 }
                 try {
                     $node->loadNodeInfo();
                 } catch (Exception $e) {
                     continue;
                 }
                 $node->event_description = ucfirst($notif->getDescriptionBlock()) . " " . $mess["notification.tpl.block.user_link"] . " " . $notif->getAuthorLabel();
                 $node->event_description_long = $notif->getDescriptionLong(true);
                 $node->event_date = SystemTextEncoding::fromUTF8(AJXP_Utils::relativeDate($notif->getDate(), $mess));
                 $node->short_date = AJXP_Utils::relativeDate($notif->getDate(), $mess, true);
                 $node->event_time = $notif->getDate();
                 $node->event_type = "notification";
                 $node->event_id = $object->event_id;
                 if ($node->getRepository() != null) {
                     $node->repository_id = '' . $node->getRepository()->getId();
                     if ($node->repository_id != $crtRepId && $node->getRepository()->getDisplay() != null) {
                         $node->event_repository_label = "[" . $node->getRepository()->getDisplay() . "]";
                     }
                 }
                 $node->event_author = $notif->getAuthor();
                 // Replace PATH, to make sure they will be distinct children of the loader node
                 $node->real_path = $node->getPath();
                 $node->setLabel(basename($node->getPath()));
                 if (isset($httpVars["merge_description"]) && $httpVars["merge_description"] == "true") {
                     if (isset($httpVars["description_as_label"]) && $httpVars["description_as_label"] == "true") {
                         $node->setLabel($node->event_description . " " . $node->event_date);
                     } else {
                         $node->setLabel(basename($node->getPath()) . " <small class='notif_desc'>" . $node->event_description . " " . $node->event_date . "</small>");
                     }
                 }
                 $url = parse_url($node->getUrl());
                 $node->setUrl($url["scheme"] . "://" . $url["host"] . "/notification_" . $index);
                 $index++;
                 if ($format == "json" || $format == "array") {
                     $keys = $node->listMetaKeys();
                     $data = array();
                     foreach ($keys as $k) {
                         $data[$k] = $node->{$k};
                     }
                     if ($format == "json") {
                         $jsonNodes[] = json_encode($data);
                     } else {
                         $jsonNodes[] = $data;
                     }
                 } else {
                     AJXP_XMLWriter::renderAjxpNode($node);
                 }
             }
         }
     }
     if ($format == "html") {
         echo "</ul>";
     } else {
         if ($format == "json") {
             HTMLWriter::charsetHeader("application/json");
             echo '[' . implode(",", $jsonNodes) . ']';
         } else {
             if ($format == "array") {
                 return $jsonNodes;
             } else {
                 AJXP_XMLWriter::close();
             }
         }
     }
 }
 public function loadUserFeed($actionName, $httpVars, $fileVars)
 {
     if (!$this->eventStore) {
         return;
     }
     $u = AuthService::getLoggedUser();
     if ($u == null) {
         if ($httpVars["format"] == "html") {
             return;
         }
         AJXP_XMLWriter::header();
         AJXP_XMLWriter::close();
         return;
     }
     $userId = $u->getId();
     $userGroup = $u->getGroupPath();
     $authRepos = array();
     $crtRepId = ConfService::getCurrentRepositoryId();
     if (isset($httpVars["repository_id"]) && $u->mergedRole->canRead($httpVars["repository_id"])) {
         $authRepos[] = $httpVars["repository_id"];
     } else {
         $acls = AuthService::getLoggedUser()->mergedRole->listAcls();
         foreach ($acls as $repoId => $rightString) {
             if ($rightString == "r" | $rightString == "rw") {
                 $authRepos[] = $repoId;
             }
         }
     }
     $offset = isset($httpVars["offset"]) ? intval($httpVars["offset"]) : 0;
     $limit = isset($httpVars["limit"]) ? intval($httpVars["limit"]) : 15;
     $res = $this->eventStore->loadEvents($authRepos, $userId, $userGroup, $offset, $limit, isset($httpVars["repository_id"]) ? false : true);
     $mess = ConfService::getMessages();
     $format = "html";
     if (isset($httpVars["format"])) {
         $format = $httpVars["format"];
     }
     if ($format == "html") {
         echo "<h2>" . $mess["notification_center.4"] . "</h2>";
         echo "<ul class='notification_list'>";
     } else {
         AJXP_XMLWriter::header();
     }
     // APPEND USER ALERT IN THE SAME QUERY FOR NOW
     $this->loadUserAlerts("", array_merge($httpVars, array("skip_container_tags" => "true")), $fileVars);
     restore_error_handler();
     $index = 1;
     foreach ($res as $n => $object) {
         $args = $object->arguments;
         $oldNode = isset($args[0]) ? $args[0] : null;
         $newNode = isset($args[1]) ? $args[1] : null;
         $copy = isset($args[2]) && $args[2] === true ? true : null;
         $notif = $this->generateNotificationFromChangeHook($oldNode, $newNode, $copy, "unify");
         if ($notif !== false && $notif->getNode() !== false) {
             $notif->setAuthor($object->author);
             $notif->setDate(intval($object->date));
             if ($format == "html") {
                 $p = $notif->getNode()->getPath();
                 echo "<li data-ajxpNode='{$p}'>";
                 echo $notif->getDescriptionShort(true);
                 echo "</li>";
             } else {
                 $node = $notif->getNode();
                 if ($node == null) {
                     $this->logInfo("Warning", "Empty node stored in notification " . $notif->getAuthor() . "/ " . $notif->getAction());
                     continue;
                 }
                 try {
                     $node->loadNodeInfo();
                 } catch (Exception $e) {
                     continue;
                 }
                 $node->event_description = ucfirst($notif->getDescriptionBlock()) . " " . $mess["notification.tpl.block.user_link"] . " " . $notif->getAuthor();
                 $node->event_description_long = $notif->getDescriptionLong(true);
                 $node->event_date = AJXP_Utils::relativeDate($notif->getDate(), $mess);
                 $node->event_id = $object->event_id;
                 if ($node->getRepository() != null) {
                     $node->repository_id = '' . $node->getRepository()->getId();
                     if ($node->repository_id != $crtRepId && $node->getRepository()->getDisplay() != null) {
                         $node->event_repository_label = "[" . $node->getRepository()->getDisplay() . "]";
                     }
                 }
                 $node->event_author = $notif->getAuthor();
                 // Replace PATH, to make sure they will be distinct children of the loader node
                 $node->real_path = $node->getPath();
                 $node->setLabel(basename($node->getPath()));
                 $url = parse_url($node->getUrl());
                 $node->setUrl($url["scheme"] . "://" . $url["host"] . "/notification_" . $index);
                 $index++;
                 AJXP_XMLWriter::renderAjxpNode($node);
             }
         }
     }
     if ($format == "html") {
         echo "</ul>";
     } else {
         AJXP_XMLWriter::close();
     }
 }