aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-01-06 01:07:16 +0100
committerKevin Chabowski <kevin@kch42.de>2012-01-06 01:07:16 +0100
commit484b1d09adf46f94fb409bf125ceb156be267e31 (patch)
tree34a9e9a50169e8c540831377eb2fffd940e475cc
parent0be7711b7c673cb086da798cd080de3d55f75a1f (diff)
downloadr7r-repo-484b1d09adf46f94fb409bf125ceb156be267e31.tar.gz
r7r-repo-484b1d09adf46f94fb409bf125ceb156be267e31.tar.bz2
r7r-repo-484b1d09adf46f94fb409bf125ceb156be267e31.zip
package viewer and upload implemented.
-rw-r--r--r7r_repo/main.php127
-rw-r--r--r7r_repo/models.php2
-rw-r--r--r7r_repo/pluginpackage.php40
-rw-r--r--r7r_repo/templates/src/package.html37
-rw-r--r--r7r_repo/templates/src/upload.html12
5 files changed, 197 insertions, 21 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;
diff --git a/r7r_repo/models.php b/r7r_repo/models.php
index b35a604..cd1ae2b 100644
--- a/r7r_repo/models.php
+++ b/r7r_repo/models.php
@@ -367,7 +367,7 @@ class Package extends BySQLRowEnabled
$update_info = array(
"current-version" => $this->lastversion,
- "dl-path" => $settings["root_url"] . "/packages/" . urlencode($this->name) . "/versions/" . $this->lastversion
+ "dl-path" => $settings["repo_baseurl"] . "/packages/" . urlencode($this->name) . "/versions/" . $this->lastversion
);
file_put_contents(dirname(__FILE__) . "/../packages/" . urlencode($this->name) . "/update", serialize($update_info));
diff --git a/r7r_repo/pluginpackage.php b/r7r_repo/pluginpackage.php
index d8ce170..cf667cc 100644
--- a/r7r_repo/pluginpackage.php
+++ b/r7r_repo/pluginpackage.php
@@ -61,6 +61,23 @@ function array2dir($a, $dir)
}
}
+function validate_url ($u) { return preg_match("/^http[s]{0,1}:\\/\\/.*$/", $u) != 0; }
+function validate_arraydir($a)
+{
+ if(!is_array($a))
+ return False;
+ foreach($a as $k=>$v)
+ {
+ if(!is_string($k))
+ return False;
+ if(is_array($v) and (!validate_arraydir($v)))
+ return False;
+ elseif(!is_string($v))
+ return False;
+ }
+ return True;
+}
+
/*
* Class: InvalidPackage
* An Exception that <PluginPackage>'s function can throw, if the package is invalid.
@@ -122,23 +139,6 @@ class PluginPackage
*/
public function validate()
{
- function validate_url ($u) { return preg_match("/^http[s]{0,1}:\\/\\/.*$/", $u) != 0; }
- function validate_arraydir($a)
- {
- if(!is_array($a))
- return False;
- foreach($a as $k=>$v)
- {
- if(!is_string($k))
- return False;
- if(is_array($v) and (!validate_arraydir($v)))
- return False;
- elseif(!is_string($v))
- return False;
- }
- return True;
- }
-
if(!is_string($this->code))
throw new InvalidPackage("Invalid code value.");
if(!is_string($this->classname))
@@ -156,9 +156,9 @@ class PluginPackage
if(!is_string($this->short_description))
throw new InvalidPackage("Invalid short_description value.");
- if(($this->updatepath !== NULL) and (!validate_url($this->updatepath)))
- throw new InvalidPackage("Invalid updatepath value. Must be an URL.");
- if(($this->web !== NULL) and (!validate_url($this->web)))
+ if((!empty($this->updatepath)) and (!validate_url($this->updatepath)))
+ throw new InvalidPackage("Invalid updatepath value. Must be an URL. " .$this->updatepath);
+ if((!empty($this->web)) and (!validate_url($this->web)))
throw new InvalidPackage("Invalid web value. Must be an URL.");
if(($this->license !== NULL) and (!is_string($this->license)))
throw new InvalidPackage("Invalid license value.");
diff --git a/r7r_repo/templates/src/package.html b/r7r_repo/templates/src/package.html
new file mode 100644
index 0000000..b40f583
--- /dev/null
+++ b/r7r_repo/templates/src/package.html
@@ -0,0 +1,37 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:default_error />
+ <ste:default_success />
+
+ <h2><ste:escape>$package[name]</ste:escape></h2>
+ <ste:escape>$package[description]</ste:escape>
+
+ <p><a href="$rel_path_to_root/packages/<ste:escape>$package[name]</ste:escape>/versions/current">Download package.</a></p>
+
+ <p><strong>Current version:</strong> <ste:escape>$package[version]</ste:escape></p>
+ <p><strong>Author:</strong> <ste:escape>$package[author]</ste:escape></p>
+</ste:block>
+<ste:if>
+ $package[admin_mode]
+ <ste:then>
+ <ste:block name="additional_metabar_modules">
+ <div class="metabar_module">
+ <form action="$rel_path_to_root/p/<ste:escape>$package[name]</ste:escape>" method="POST" accept-charset="UTF-8" enctype="multipart/form-data">
+ <h2>Upload a new version</h2>
+ <input type="file" name="pkgfile" /><br />
+ <input type="submit" name="new_version" />
+ </form>
+ </div>
+ <div class="metabar_module">
+ <form action="$rel_path_to_root/p/<ste:escape>$package[name]</ste:escape>" method="POST" accept-charset="UTF-8">
+ <h2>Delete package</h2>
+ <input type="submit" name="delete_package" />
+ <select name="really_delete">
+ <option value="yes">Yes</option>
+ <option value="no" selected="selected">No</option>
+ </select>
+ </form>
+ </div>
+ </ste:block>
+ </ste:then>
+</ste:if>
diff --git a/r7r_repo/templates/src/upload.html b/r7r_repo/templates/src/upload.html
new file mode 100644
index 0000000..5b46da1
--- /dev/null
+++ b/r7r_repo/templates/src/upload.html
@@ -0,0 +1,12 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:default_error />
+ <ste:default_success />
+
+ <form action="$rel_path_to_root/upload" method="POST" accept-charset="UTF-8" enctype="multipart/form-data">
+ <h2>Upload a new package</h2>
+
+ <strong>Package file:</strong> <input type="file" name="pkgfile" /><br />
+ <input type="submit" name="upload_package" />
+ </form>
+</ste:block>