aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-01-08 13:17:34 +0100
committerKevin Chabowski <kevin@kch42.de>2012-01-08 13:17:34 +0100
commit39321547c697cb95c8259595426f74ff0ac551ba (patch)
tree92121109a4520e66e852a309428c85c0c7b0941c
parentfbc25b825c26eea168d24c5ec6df971eba650d70 (diff)
downloadratatoeskr-cms-39321547c697cb95c8259595426f74ff0ac551ba.tar.gz
ratatoeskr-cms-39321547c697cb95c8259595426f74ff0ac551ba.tar.bz2
ratatoeskr-cms-39321547c697cb95c8259595426f74ff0ac551ba.zip
Repo administration and indtall from repo added.
-rw-r--r--ratatoeskr/backend.php141
-rw-r--r--ratatoeskr/main.php2
-rw-r--r--ratatoeskr/sys/models.php8
-rw-r--r--ratatoeskr/templates/src/systemtemplates/plugininstall.html49
-rw-r--r--ratatoeskr/templates/src/systemtemplates/repos.html65
-rw-r--r--ratatoeskr/translations/en.php22
6 files changed, 280 insertions, 7 deletions
diff --git a/ratatoeskr/backend.php b/ratatoeskr/backend.php
index 0316589..80fbc26 100644
--- a/ratatoeskr/backend.php
+++ b/ratatoeskr/backend.php
@@ -1543,7 +1543,80 @@ $backend_subactions = url_action_subactions(array(
$ste->vars["submenu"] = "repos";
$ste->vars["pagetitle"] = $translation["menu_plugin_repos"];
+ /* Add a repo? */
+ if(isset($_POST["add_repo"]))
+ {
+ try
+ {
+ $repo = Repository::create($_POST["repo_baseurl"]);
+ $ste->vars["success"] = $translation["successfully_added_repo"];
+ }
+ catch(RepositoryUnreachableOrInvalid $e)
+ {
+ $ste->vars["error"] = $translation["repository_unreachable_or_invalid"];
+ }
+ }
+
+ /* Delete repos? */
+ if(isset($_POST["delete_repos"]) and ($_POST["really_delete"] == "yes"))
+ {
+ foreach($_POST["repos_multiselect"] as $repo_id)
+ {
+ try
+ {
+ $repo = Repository::by_id($repo_id);
+ $repo->delete();
+ }
+ catch(DoesNotExistError $e)
+ {
+ continue;
+ }
+ }
+ $ste->vars["success"] = $translation["repos_deleted"];
+ }
+
+ /* Force refresh? */
+ if(isset($_POST["force_repo_refresh"]))
+ {
+ $failed = array();
+ foreach($_POST["repos_multiselect"] as $repo_id)
+ {
+ try
+ {
+ $repo = Repository::by_id($repo_id);
+ $repo->refresh(True);
+ }
+ catch(DoesNotExistError $e)
+ {
+ continue;
+ }
+ catch(RepositoryUnreachableOrInvalid $e)
+ {
+ $failed[] = $repo->get_name();
+ }
+ }
+ $ste->vars["success"] = $translation["successfully_refreshed_repos"];
+ if(!empty($failed))
+ $ste->vars["error"] = str_replace("[[REPOS]]", implode(", ", $failed), $translation["repo_refresh_failed_on"]);
+ }
+ /* Fill data */
+ $all_repos = Repository::all();
+ $ste->vars["repos"] = array_map(
+ function($r)
+ {
+ try
+ {
+ $r->refresh();
+ }
+ catch(RepositoryUnreachableOrInvalid $e){}
+ return array(
+ "id" => $r->get_id(),
+ "name" => $r->get_name(),
+ "description" => $r->get_description(),
+ "baseurl" => $r->get_baseurl()
+ );
+ }, $all_repos);
echo $ste->exectemplate("systemtemplates/repos.html");
}
@@ -1627,7 +1700,7 @@ $backend_subactions = url_action_subactions(array(
if(!empty($plugin->updatepath))
{
$update_info = @unserialize(@file_get_contents($plugin->updatepath, False, $stream_ctx));
- if(is_array($update_info) and ($update_info["current-version"] > $plugin->versioncount))
+ if(is_array($update_info) and (($update_info["current-version"]+0) > ($plugin->versioncount+0)))
{
$pkg = PluginPackage::load(@file_get_contents($update_info["dl-path"], False, $stream_ctx));
$plugin->fill_from_pluginpackage($pkg);
@@ -1709,6 +1782,19 @@ $backend_subactions = url_action_subactions(array(
$ste->vars["submenu"] = "installplugins";
$ste->vars["pagetitle"] = $translation["menu_plugininstall"];
+ $all_repos = Repository::all();
+ foreach($all_repos as $repo)
+ {
+ try
+ {
+ $repo->refresh();
+ }
+ catch(RepositoryUnreachableOrInvalid $e)
+ {
+ continue;
+ }
+ }
+
if(isset($_POST["installpackage"]))
{
if(is_uploaded_file($_FILES["pluginpackage"]["tmp_name"]))
@@ -1740,8 +1826,61 @@ $backend_subactions = url_action_subactions(array(
$ste->vars["error"] = $translation["upload_failed"];
}
+ if(isset($_POST["search_in_repos"]))
+ {
+ $ste->vars["searchresults"] = array();
+ $repos_to_scan = ($_POST["searchin"] == "*") ? $all_repos : Repository::by_id($_POST["searchin"]);
+ $searchfor = strtolower($_POST["searchfor"]);
+ foreach($repos_to_scan as $repo)
+ {
+ foreach($repo->packages as $pkg)
+ {
+ if(empty($searchfor) or (strpos(strtolower($pkg[0]), $searchfor) !== False) or (strpos(strtolower($pkg[2]), $searchfor) !== False))
+ $ste->vars["searchresults"][] = array(
+ "name" => $pkg[0],
+ "description" => $pkg[2],
+ "reponame" => $repo->get_name(),
+ "repoid" => $repo->get_id()
+ );
+ }
+ }
+ }
+
+ $ste->vars["repos"] = array_map(function($r) { return array(
+ "id" => $r->get_id(),
+ "name" => $r->get_name()
+ ); }, $all_repos);
+
echo $ste->exectemplate("systemtemplates/plugininstall.html");
},
+ "repoinstall" => function(&$data, $url_now, &$url_next)
+ {
+ global $ste, $translation, $rel_path_to_root;
+
+ $stream_ctx = stream_context_create(array("http" => array("timeout" => 5)));
+
+ try
+ {
+ $repo = Repository::by_id($_GET["repo"]);
+ $pkg = $repo->download_package($_GET["pkg"]);
+ $plugin = Plugin::create();
+ $plugin->fill_from_pluginpackage($pkg);
+ $plugin->installed = False;
+ $plugin->active = False;
+ $plugin->save();
+ $url_next = array("confirminstall", (string) $plugin->get_id());
+ }
+ catch(DoesNotExistError $e)
+ {
+ $ste->vars["error"] = $translation["package_or_repo_not_found"];
+ $url_next = array("install");
+ }
+ catch(InvalidPackage $e)
+ {
+ $ste->vars["error"] = $translation["invalid_package"];
+ $url_next = array("install");
+ }
+ },
"confirminstall" => function(&$data, $url_now, &$url_next)
{
global $ste, $translation, $languages, $rel_path_to_root;
diff --git a/ratatoeskr/main.php b/ratatoeskr/main.php
index df1672c..b3235b4 100644
--- a/ratatoeskr/main.php
+++ b/ratatoeskr/main.php
@@ -57,7 +57,7 @@ function ratatoeskr()
register_url_handler("_notfound", url_action_simple(function($data)
{
global $ste;
- //header("HTTP/1.1 404 Not Found");
+ header("HTTP/1.1 404 Not Found");
$ste->vars["title"] = "404 Not Found";
$ste->vars["details"] = str_replace("[[URL]]", $_SERVER["REQUEST_URI"], (isset($translation) ? $translation["e404_details"] : "The page [[URL]] could not be found. Sorry."));
echo $ste->exectemplate("systemtemplates/error.html");
diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php
index cefe79d..d371f9f 100644
--- a/ratatoeskr/sys/models.php
+++ b/ratatoeskr/sys/models.php
@@ -1349,7 +1349,7 @@ class Plugin extends BySQLRowEnabled
public function save()
{
qdb("UPDATE `PREFIX_plugins` SET `name` = '%s', `author` = '%s', `code` = '%s', `classname` = '%s', `active` = %d, `versiontext` = '%s', `versioncount` = %d, `short_description` = '%s', `updatepath` = '%s', `web` = '%s', `help` = '%s', `installed` = %d, `update` = %d, `license` = '%s' WHERE `id` = %d",
- $this->name, $this>author, $this->code, $this->classname, ($this->active ? 1 : 0), $this->versiontext, $this->versioncount, $this->short_description, $this->updatepath, $this->web, $this->help, ($this->installed ? 1 : 0), ($this->update ? 1 : 0), $this->license, $this->id);
+ $this->name, $this->author, $this->code, $this->classname, ($this->active ? 1 : 0), $this->versiontext, $this->versioncount, $this->short_description, $this->updatepath, $this->web, $this->help, ($this->installed ? 1 : 0), ($this->update ? 1 : 0), $this->license, $this->id);
}
/*
@@ -1973,7 +1973,7 @@ class Image extends BySQLRowEnabled
}
/*
- * Class RepositoryUnreachableOrInvalid
+ * Class: RepositoryUnreachableOrInvalid
* A Exception that will be thrown, if the repository is aunreachable or seems to be an invalid repository.
*/
class RepositoryUnreachableOrInvalid extends Exception { }
@@ -2063,7 +2063,7 @@ class Repository extends BySQLRowEnabled
*/
public static function by_id($id)
{
- $result = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` WHERE id` = %d", $this->id);
+ $result = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` FROM `PREFIX_repositories` WHERE `id` = %d", $id);
$sqlrow = mysql_fetch_assoc($result);
if(!$sqlrow)
throw new DoesNotExistError();
@@ -2081,7 +2081,7 @@ class Repository extends BySQLRowEnabled
public static function all()
{
$rv = array();
- $result = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` WHERE 1");
+ $result = qdb("SELECT `id`, `name`, `description`, `baseurl`, `pkgcache`, `lastrefresh` FROM `PREFIX_repositories` WHERE 1");
while($sqlrow = mysql_fetch_assoc($result))
$rv[] = self::by_sqlrow($sqlrow);
return $rv;
diff --git a/ratatoeskr/templates/src/systemtemplates/plugininstall.html b/ratatoeskr/templates/src/systemtemplates/plugininstall.html
index 039feef..2bee9d5 100644
--- a/ratatoeskr/templates/src/systemtemplates/plugininstall.html
+++ b/ratatoeskr/templates/src/systemtemplates/plugininstall.html
@@ -15,4 +15,53 @@
<form action="$rel_path_to_root/backend/plugin/install" method="POST" accept-charset="UTF-8" enctype="multipart/form-data">
<input type="file" name="pluginpackage" /> <input type="submit" name="installpackage" />
</form>
+
+ <h2><ste:get_translation for="install_from_repo" /></h2>
+ <ste:set var="repos_n"><ste:arraylen array="repos" /></ste:set>
+ <ste:if>
+ ~{$repos_n|gt|0}
+ <ste:then>
+ <form action="$rel_path_to_root/backend/plugin/install" method="POST" accept-charset="UTF-8">
+ <ste:get_translation for="search" />: <input type="text" name="searchfor" />
+ <ste:get_translation for="repo_plugin_search_in" />:
+ <select name="searchin">
+ <option value="*" selected="selected"><ste:get_translation for="search_in_all_repos" /></option>
+ <option value="*">-----------</option>
+ <ste:foreach array="repos" value="repo">
+ <option value="$repo[id]"><ste:escape>$repo[name]</ste:escape></option>
+ </ste:foreach>
+ </select>
+ <input type="submit" name="search_in_repos" />
+ </form>
+ </ste:then>
+ <ste:else>
+ <ste:l10n_replace URL="$rel_path_to_root/backend/admin/repos"><ste:get_translation for="no_repos_add_some" raw="y" /></ste:l10n_replace>
+ </ste:else>
+ </ste:if>
+
+ <ste:if>
+ $searchresults
+ <ste:then>
+ <table class="listtab fullwidth">
+ <thead>
+ <tr>
+ <th><ste:get_translation for="plugin_name" /></th>
+ <th><ste:get_translation for="plugin_description" /></th>
+ <th><ste:get_translation for="repo" /></th>
+ <th>&nbsp;</th>
+ </tr>
+ </thead>
+ <tbody>
+ <ste:foreach array="searchresults" value="searchresult">
+ <tr>
+ <td><ste:escape>$searchresult[name]</ste:escape></td>
+ <td><ste:escape>$searchresult[description]</ste:escape></td>
+ <td><ste:escape>$searchresult[reponame]</ste:escape></td>
+ <td><a href="$rel_path_to_root/backend/plugin/repoinstall?repo=$searchresult[repoid]&pkg=$searchresult[name]"><ste:get_translation for="install" /></a></td>
+ </tr>
+ </ste:foreach>
+ </tbody>
+ </table>
+ </ste:then>
+ </ste:if>
</ste:block>
diff --git a/ratatoeskr/templates/src/systemtemplates/repos.html b/ratatoeskr/templates/src/systemtemplates/repos.html
new file mode 100644
index 0000000..c7a5267
--- /dev/null
+++ b/ratatoeskr/templates/src/systemtemplates/repos.html
@@ -0,0 +1,65 @@
+<ste:load name="master.html" />
+<ste:block name="content">
+ <ste:if>$success
+ <ste:then>
+ <div class="success"><ste:escape>$success</ste:escape></div>
+ </ste:then>
+ </ste:if>
+ <ste:if>$error
+ <ste:then>
+ <div class="error"><ste:escape>$error</ste:escape></div>
+ </ste:then>
+ </ste:if>
+
+ <form action="$rel_path_to_root/backend/admin/repos" method="POST" accept-charset="UTF-8">
+ <h2><ste:get_translation for="add_repo" /></h2>
+
+ <p><strong><ste:get_translation for="repo_baseurl" />:</strong> <input type="text" name="repo_baseurl" /></p>
+ <p><input type="submit" name="add_repo" /></p>
+ </form>
+
+ <form action="$rel_path_to_root/backend/admin/repos" method="POST" accept-charset="UTF-8">
+ <h2><ste:get_translation for="repo_list" /></h2>
+
+ <table class="listtab fullwidth">
+ <thead>
+ <tr>
+ <th>&nbsp;</th>
+ <th><ste:get_translation for="repo_name" /></th>
+ <th><ste:get_translation for="repo_description" /></th>
+ <th><ste:get_translation for="repo_baseurl" /></th>
+ </tr>
+ </thead>
+ <tbody>
+ <ste:set var="repos_n"><ste:arraylen array="repos" /></ste:set>
+ <ste:if>
+ ~{$repos_n|gt|0}
+ <ste:then>
+ <ste:foreach array="repos" value="repo">
+ <tr>
+ <td><input type="checkbox" name="repos_multiselect[]" value="$repo[id]" /></td>
+ <td><ste:escape>$repo[name]</ste:escape></td>
+ <td><ste:escape>$repo[description]</ste:escape></td>
+ <td><ste:escape>$repo[baseurl]</ste:escape></td>
+ </tr>
+ </ste:foreach>
+ </ste:then>
+ <ste:else>
+ <tr>
+ <td colspan="4" style="font-style: italic; text-align: center;"><ste:get_translation for="no_repos" /></td>
+ </tr>
+ </ste:else>
+ </ste:if>
+ </tbody>
+ </table>
+ <div>
+ <input type="submit" name="delete_repos" value="<ste:get_translation for='delete' />" />
+ <select name="really_delete">
+ <option value="no" selected="selected"><ste:get_translation for="no" /></option>
+ <option value="yes"><ste:get_translation for="yes" /></option>
+ </select>
+ |
+ <input type="submit" name="force_repo_refresh" value="<ste:get_translation for='force_repo_refresh' />" />
+ </div>
+ </form>
+</ste:block>
diff --git a/ratatoeskr/translations/en.php b/ratatoeskr/translations/en.php
index fb96479..26c6488 100644
--- a/ratatoeskr/translations/en.php
+++ b/ratatoeskr/translations/en.php
@@ -224,7 +224,27 @@ $translation = array(
"plugins_activated" => "Plugins activated.",
"plugins_deactivated" => "Plugins deactivated.",
"successfully_updated_plugins" => "These plugins were updated: [[PLUGINS]]",
- "nothing_to_update" => "Nothing to update."
+ "nothing_to_update" => "Nothing to update.",
+ "add_repo" => "Add a repository",
+ "repo_baseurl" => "Repository base URL",
+ "repo_list" => "Repository List",
+ "repo_name" => "Name",
+ "repo_description" => "Description",
+ "no_repos" => "No repositories found.",
+ "force_repo_refresh" => "Force refresh",
+ "successfully_added_repo" => "Successfully added repository.",
+ "repository_unreachable_or_invalid" => "Repository is unreachable or is invalid.",
+ "repos_deleted" => "Repositories deleted.",
+ "successfully_refreshed_repos" => "Successfully refreshed.",
+ "repo_refresh_failed_on" => "Repository refresh failed on these repositories: [[REPOS]]",
+ "no_repos_add_some" => "No repositories found. You should <a href=\"[[URL]]\">add some repositories</a>.",
+ "install_from_repo" => "Install from repository",
+ "search" => "Search",
+ "repo_plugin_search_in" => "Search in",
+ "search_in_all_repos" => "all repositories",
+ "repo" => "Repository",
+ "install" => "Install",
+ "package_or_repo_not_found" => "Package or repository not found."
);
?>