require_once __ROOT__ . "/inc/api_users.php"; require_once __ROOT__ . "/inc/commons/url.php"; require_once __ROOT__ . "/inc/commons/http.php"; require_once __ROOT__ . "/inc/api_nuget.php"; $id = UrlUtils::GetRequestParamOrDefault("id", null); $version = UrlUtils::GetRequestParamOrDefault("version", null); if ($id == null || $version == null) { HttpUtils::ApiError(500, "Wrong data. Missing param."); } if (strlen($id) == 0 || strlen($version) == 0) { HttpUtils::ApiError(500, "Wrong data. Empty id or version."); } $query = "Id eq '" . $id . "' and Version eq '" . $version . "'"; $db = new NuGetDb(); $os = new PhpNugetObjectSearch(); $os->Parse($query, $db->GetAllColumns()); $allRows = $db->GetAllRows(1, 0, $os); if (sizeof($allRows) == 0) { HttpUtils::ApiError(404, "Not found."); } $file = $allRows[0]->Id . "." . $allRows[0]->Version . ".nupkg"; $path = Path::Combine(Settings::$PackagesRoot, $file); if (!file_exists($path)) { HttpUtils::ApiError(404, "Not found " . $file); } header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=' . basename($path)); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($path));
} } if ($originalOrderBy != null) { $originalOrderBy = "&orderBy=" . $originalOrderBy; } $pg->Skip = UrlUtils::GetRequestParamOrDefault("skip", 0); $pg->Top = UrlUtils::GetRequestParamOrDefault("top", 10); $os = null; if ($searchQuery != null) { if ($orderBy != null) { $orderBy = " orderby " . $orderBy; } else { $orderBy = " orderby Title asc,Version desc"; } $os = new PhpNugetObjectSearch(); $os->Parse("(" . $searchQuery . ") and Listed eq true " . $orderBy . $groupBy, $db->GetAllColumns()); } else { if ($orderBy != null) { $orderBy = "orderby " . $orderBy; $os = new PhpNugetObjectSearch(); $os->Parse("Listed eq true " . $orderBy . $groupBy, $db->GetAllColumns()); } else { $os = new PhpNugetObjectSearch(); $os->Parse("orderby Title asc, Version desc" . $groupBy, $db->GetAllColumns()); } } $next = Settings::$SiteRoot . "?specialType=packages"; if ($searchQuery != null) { $next .= "&searchQuery=" . urlencode($searchQuery); } $items = $db->GetAllRows(999999, 0, $os);
function _query($query) { $pg = $this->_getPagination(); $db = new NuGetDb(); $os = new PhpNugetObjectSearch(); if (strlen($query) > 0) { $os->Parse($query, $db->GetAllColumns()); } else { $os = null; } $count = UrlUtils::GetRequestParamOrDefault("count", "false"); if ($count == "true") { $allRows = $db->GetAllRows(999999, 0, $os); HttpUtils::WriteData(sizeof($allRows)); } $allRows = $db->GetAllRows($pg->Top + 1, $pg->Skip, $os); if (!UrlUtils::IsFake()) { header('Content-Type: application/atom+xml;type=feed;charset=utf-8'); } $baseUrl = UrlUtils::CurrentUrl(Settings::$SiteRoot); // $r = array(); $r["@BASEURL@"] = $baseUrl; $r["@NEXTITEM@"] = ""; echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; echo Utils::ReplaceInFile(Path::Combine($this->_path, "entrytemplatepre.xml"), $r); for ($i = 0; $i < sizeof($allRows) && $i < $pg->Top; $i++) { $row = $allRows[$i]; echo $this->_buildNuspecEntity($baseUrl, $row); } if (sizeof($allRows) >= $pg->Top) { $act = strtolower(UrlUtils::GetRequestParamOrDefault("action", null)); if ($act == "packages") { $act = "Packages"; } if ($act == "search") { $act = "Search"; } if ($act == "findpackagesbyd") { $act = "FindPackagesById"; } if ($act == "getupdates") { $act = "GetUpdates"; } $nq = $this->_setupLastQuery(); if ($act != "Search") { $nq = "\$skip=" . ($pg->Skip + $pg->Top) . "&\$top=" . $pg->Top . $nq; echo "<link rel=\"next\" href=\"" . $baseUrl . "/api/" . $this->_version . "/" . $act . "?" . $nq . "\"/>"; } /*?><link rel="next" href="http://localhost:8020/phpnuget/api/v2/Search?$skip=30&$top=30&searchTerm=''&$filter=IsAbsoluteLatestVersion&$orderby=DownloadCount+desc%2CId"/><?php*/ } echo Utils::ReplaceInFile(Path::Combine($this->_path, "entrytemplatepost.xml"), $r); die; }
public function SaveNuspec($nupkgFile, $e) { global $loginController; $nugetDb = new NuGetDb(); $os = new PhpNugetObjectSearch(); $query = "Id eq '" . $e->Id . "' orderby Version desc"; $os->Parse($query, $nugetDb->GetAllColumns()); $res = $nugetDb->GetAllRows(999999, 0, $os); if (sizeof($res) > 0 && !$loginController->Admin) { $id = $res[0]->UserId; if ($id != $e->UserId) { throw new Exception("Unauthorized!"); } } else { if (sizeof($res) > 0 && $loginController->Admin) { $e->UserId = $res[0]->UserId; } } $e->IsPreRelease = indexOf($e->Version, "-") > 0; if ($nugetDb->AddRow($e, false)) { $destination = Path::Combine(Settings::$PackagesRoot, $e->Id . "." . $e->Version . ".nupkg"); if (strtolower($nupkgFile) != strtolower($destination)) { if (file_exists($destination)) { unlink($destination); } rename($nupkgFile, $destination); } } else { if (strtlower($nupkgFile) != strtlower($destination)) { if (file_exists($nupkgFile)) { unlink($nupkgFile); } } } }