Пример #1
0
 /**
  * Store a newly created repository
  *
  * @param Repository $repositoryObject
  * @param Boolean $update
  * @return -1 if failed
  */
 public function saveRepository($repositoryObject, $update = false)
 {
     $repositories = AJXP_Utils::loadSerialFile($this->repoSerialFile);
     if (!$update) {
         $repositoryObject->writeable = true;
         $repositories[$repositoryObject->getUniqueId()] = $repositoryObject;
     } else {
         foreach ($repositories as $index => $repo) {
             if ($repo->getUniqueId() == $repositoryObject->getUniqueId()) {
                 $repositories[$index] = $repositoryObject;
                 break;
             }
         }
     }
     try {
         AJXP_Utils::saveSerialFile($this->repoSerialFile, $repositories);
     } catch (Exception $e) {
         return -1;
     }
     $this->updateAliasesIndex($repositoryObject->getUniqueId(), $repositoryObject->getSlug());
 }
Пример #2
0
 /**
  * @param Repository $repository
  * @return string
  */
 public static function getWorkspaceShortcutURL($repository)
 {
     $repoSlug = $repository->getSlug();
     $skipHistory = ConfService::getCoreConf("SKIP_USER_HISTORY", "conf");
     if ($skipHistory) {
         $prefix = "/ws-";
     } else {
         $prefix = "?goto=";
     }
     return trim(self::detectServerURL(true), "/") . $prefix . $repoSlug;
 }
Пример #3
0
 /**
  * @param string $repoId
  * @param Repository $repoObject
  * @param array $exposed
  * @param array $streams
  * @param AbstractAjxpUser $loggedUser
  * @param string $accessStatus
  * @return string
  * @throws Exception
  */
 public static function repositoryToXML($repoId, $repoObject, $exposed, $streams, $loggedUser, $accessStatus = "")
 {
     $statusString = " repository_type=\"" . $repoObject->getRepositoryType() . "\"";
     if (empty($accessStatus)) {
         $accessStatus = $repoObject->getAccessStatus();
     }
     if (!empty($accessStatus)) {
         $statusString .= " access_status=\"{$accessStatus}\" ";
     } else {
         if ($loggedUser != null) {
             $lastConnected = $loggedUser->getArrayPref("repository_last_connected", $repoId);
             if (!empty($lastConnected)) {
                 $statusString .= " last_connection=\"{$lastConnected}\" ";
             }
         }
     }
     $streamString = "";
     if (in_array($repoObject->accessType, $streams)) {
         $streamString = "allowCrossRepositoryCopy=\"true\"";
     }
     if ($repoObject->getUniqueUser()) {
         $streamString .= " user_editable_repository=\"true\" ";
     }
     if ($repoObject->hasContentFilter()) {
         $streamString .= " hasContentFilter=\"true\"";
     }
     $slugString = "";
     $slug = $repoObject->getSlug();
     if (!empty($slug)) {
         $slugString = "repositorySlug=\"{$slug}\"";
     }
     $isSharedString = "";
     $currentUserIsOwner = false;
     $ownerLabel = null;
     if ($repoObject->hasOwner()) {
         $uId = $repoObject->getOwner();
         if (AuthService::usersEnabled() && AuthService::getLoggedUser()->getId() == $uId) {
             $currentUserIsOwner = true;
         }
         $label = ConfService::getUserPersonalParameter("USER_DISPLAY_NAME", $uId, "core.conf", $uId);
         $ownerLabel = $label;
         $isSharedString = 'owner="' . AJXP_Utils::xmlEntities($label) . '"';
     }
     if ($repoObject->securityScope() == "USER" || $currentUserIsOwner) {
         $streamString .= " userScope=\"true\"";
     }
     $descTag = "";
     $public = false;
     if (!empty($_SESSION["CURRENT_MINISITE"])) {
         $public = true;
     }
     $description = $repoObject->getDescription($public, $ownerLabel);
     if (!empty($description)) {
         $descTag = '<description>' . AJXP_Utils::xmlEntities($description, true) . '</description>';
     }
     $roleString = "";
     if ($loggedUser != null) {
         $merged = $loggedUser->mergedRole;
         $params = array();
         foreach ($exposed as $exposed_prop) {
             $metaOptions = $repoObject->getOption("META_SOURCES");
             if (!isset($metaOptions[$exposed_prop["PLUGIN_ID"]])) {
                 continue;
             }
             $value = $exposed_prop["DEFAULT"];
             if (isset($metaOptions[$exposed_prop["PLUGIN_ID"]][$exposed_prop["NAME"]])) {
                 $value = $metaOptions[$exposed_prop["PLUGIN_ID"]][$exposed_prop["NAME"]];
             }
             $value = $merged->filterParameterValue($exposed_prop["PLUGIN_ID"], $exposed_prop["NAME"], $repoId, $value);
             if ($value !== null) {
                 if ($value === true || $value === false) {
                     $value = $value === true ? "true" : "false";
                 }
                 $params[] = '<repository_plugin_param plugin_id="' . $exposed_prop["PLUGIN_ID"] . '" name="' . $exposed_prop["NAME"] . '" value="' . AJXP_Utils::xmlEntities($value) . '"/>';
                 $roleString .= str_replace(".", "_", $exposed_prop["PLUGIN_ID"]) . "_" . $exposed_prop["NAME"] . '="' . AJXP_Utils::xmlEntities($value) . '" ';
             }
         }
         $roleString .= 'acl="' . $merged->getAcl($repoId) . '"';
         if ($merged->hasMask($repoId)) {
             $roleString .= ' hasMask="true" ';
         }
     }
     return "<repo access_type=\"" . $repoObject->accessType . "\" id=\"" . $repoId . "\"{$statusString} {$streamString} {$slugString} {$isSharedString} {$roleString}><label>" . SystemTextEncoding::toUTF8(AJXP_Utils::xmlEntities($repoObject->getDisplay())) . "</label>" . $descTag . $repoObject->getClientSettings() . "</repo>";
 }
Пример #4
0
 /**
  * Store a newly created repository
  *
  * @param Repository $repositoryObject
  * @param Boolean $update
  * @return int -1 if failed
  */
 public function saveRepository($repositoryObject, $update = false)
 {
     try {
         if ($update) {
             $repositoryObject->setSlug($this->uniquifySlug($repositoryObject->getSlug(), $repositoryObject->getUniqueId()));
         } else {
             $repositoryObject->setSlug($this->uniquifySlug($repositoryObject->getSlug()));
         }
         $repository_array = $this->repoToArray($repositoryObject);
         $options = $repository_array['options'];
         if ($repositoryObject->hasContentFilter()) {
             $options["content_filter"] = $repositoryObject->getContentFilter();
         }
         unset($repository_array['options']);
         if (!$update) {
             dibi::query('INSERT INTO [ajxp_repo]', $repository_array);
             foreach ($options as $k => $v) {
                 if (!is_string($v)) {
                     $v = '$phpserial$' . serialize($v);
                 }
                 dibi::query('INSERT INTO [ajxp_repo_options] ([uuid],[name],[val]) VALUES (%s,%s,%bin)', $repositoryObject->getUniqueId(), $k, $v);
             }
         } else {
             dibi::query('DELETE FROM [ajxp_repo] WHERE [uuid] = %s', $repositoryObject->getUniqueId());
             dibi::query('DELETE FROM [ajxp_repo_options] WHERE [uuid] = %s', $repositoryObject->getUniqueId());
             dibi::query('INSERT INTO [ajxp_repo]', $repository_array);
             foreach ($options as $k => $v) {
                 if (!is_string($v)) {
                     $v = '$phpserial$' . serialize($v);
                 }
                 dibi::query('INSERT INTO [ajxp_repo_options] ([uuid],[name],[val]) VALUES (%s,%s,%bin)', $repositoryObject->getUniqueId(), $k, $v);
             }
         }
     } catch (DibiException $e) {
         echo get_class($e), ': ', $e->getMessage(), "\n";
         exit(1);
         return -1;
     }
 }