diff options
author | Kevin Chabowski <kevin@kch42.de> | 2012-01-06 01:07:16 +0100 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2012-01-06 01:07:16 +0100 |
commit | 484b1d09adf46f94fb409bf125ceb156be267e31 (patch) | |
tree | 34a9e9a50169e8c540831377eb2fffd940e475cc /r7r_repo/main.php | |
parent | 0be7711b7c673cb086da798cd080de3d55f75a1f (diff) | |
download | r7r-repo-484b1d09adf46f94fb409bf125ceb156be267e31.tar.gz r7r-repo-484b1d09adf46f94fb409bf125ceb156be267e31.tar.bz2 r7r-repo-484b1d09adf46f94fb409bf125ceb156be267e31.zip |
package viewer and upload implemented.
Diffstat (limited to 'r7r_repo/main.php')
-rw-r--r-- | r7r_repo/main.php | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/r7r_repo/main.php b/r7r_repo/main.php index 6c097a8..8554d3c 100644 --- a/r7r_repo/main.php +++ b/r7r_repo/main.php @@ -364,6 +364,133 @@ $url_handlers = array( echo $ste->exectemplate("account.html"); }, + "p" => function(&$data, $url_now, &$url_next) + { + global $ste, $user; + + list($pkgname) = $url_next; + $url_next = array(); + + if(empty($pkgname)) + throw new NotFoundError(); + + try + { + $pkg = Package::by_name($pkgname); + } + catch(DoesNotExistError $e) + { + throw new NotFoundError(); + } + + $ste->vars["title"] = $pkg->get_name(); + $admin_mode = (($user !== NULL) and (($user->isadmin) or ($user->get_id() == $pkg->get_user()->get_id()))); + + if($admin_mode) + { + if(isset($_POST["delete_package"]) and ($_POST["really_delete"] == "yes")) + { + $pkg->delete(); + $ste->vars["success"] = "Package deleted."; + $url_next = array("index"); + return; + } + + if(isset($_POST["new_version"])) + { + if(is_uploaded_file($_FILES["pkgfile"]["tmp_name"])) + { + $raw_pkg = @file_get_contents($_FILES["pkgfile"]["tmp_name"]); + @unlink($_FILES["pkgfile"]["tmp_name"]); + if($raw_pkg === False) + $ste->vars["error"] = "Upload failed."; + else + { + try + { + $newpkg = PluginPackage::load($raw_pkg); + $pkg->newversion($newpkg); + $ste->vars["success"] = "Successfully uploaded new version."; + } + catch(InvalidPackage $e) + { + $ste->vars["error"] = "Invalid package. Reason: " . $e->getMessage(); + } + catch(NotAllowedError $e) + { + $ste->vars["error"] = "This is not allowed. Reason: " . $e->getMessage(); + } + } + } + else + $ste->vars["error"] = "Upload failed."; + } + } + + $ste->vars["package"] = array( + "name" => $pkg->get_name(), + "description" => $pkg->description, + "author" => $pkg->author, + "admin_mode" => $admin_mode, + "version" => $pkg->txtversion + ); + + echo $ste->exectemplate("package.html"); + }, + "upload" => function(&$data, $url_now, &$url_next) + { + global $ste, $settings, $user; + + if(($user === NULL) or ((!$user->isadmin) and ($settings["repo_mode"] == "private"))) + throw new NotFoundError(); + + $url_now = array(); + $ste->vars["menu"] = "upload"; + $ste->vars["title"] = "Upload new package"; + + if(isset($_POST["upload_package"])) + { + if(is_uploaded_file($_FILES["pkgfile"]["tmp_name"])) + { + $raw_pkg = @file_get_contents($_FILES["pkgfile"]["tmp_name"]); + @unlink($_FILES["pkgfile"]["tmp_name"]); + if($raw_pkg === False) + $ste->vars["error"] = "Upload failed."; + else + { + try + { + $newpkg = PluginPackage::load($raw_pkg); + $pkg = Package::create($newpkg->name, $user); + $pkg->newversion($newpkg); + $ste->vars["success"] = "Successfully uploaded new package."; + $url_next = array("p", $newpkg->name); + return; + } + catch(InvalidPackage $e) + { + $ste->vars["error"] = "Invalid package. Reason: " . $e->getMessage(); + } + catch(NotAllowedError $e) + { + $ste->vars["error"] = "This is not allowed. Reason: " . $e->getMessage(); + } + catch(InvalidArgumentException $e) + { + $ste->vars["error"] = $e->getMessage(); + } + catch(AlreadyExistsError $e) + { + $ste->vars["error"] = "A package with this name already exists."; + } + } + } + else + $ste->vars["error"] = "Upload failed."; + } + + echo $ste->exectemplate("upload.html"); + }, "setup" => function(&$data, $url_now, &$url_next) { global $settings, $ste; |