From 39321547c697cb95c8259595426f74ff0ac551ba Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sun, 8 Jan 2012 13:17:34 +0100 Subject: Repo administration and indtall from repo added. --- ratatoeskr/backend.php | 141 ++++++++++++++++++++- ratatoeskr/main.php | 2 +- ratatoeskr/sys/models.php | 8 +- .../src/systemtemplates/plugininstall.html | 49 +++++++ .../templates/src/systemtemplates/repos.html | 65 ++++++++++ ratatoeskr/translations/en.php | 22 +++- 6 files changed, 280 insertions(+), 7 deletions(-) create mode 100644 ratatoeskr/templates/src/systemtemplates/repos.html (limited to 'ratatoeskr') 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 @@
+ +

+ + + ~{$repos_n|gt|0} + +
+ : + : + + + +
+ + + +
+ + + $searchresults + + + + + + + + + + + + + + + + + + + + +
 
$searchresult[name]$searchresult[description]$searchresult[reponame]
+
+
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 @@ + + + $success + +
$success
+
+
+ $error + +
$error
+
+
+ +
+

+ +

:

+

+
+ +
+

+ + + + + + + + + + + + + + ~{$repos_n|gt|0} + + + + + + + + + + + + + + + + + +
 
$repo[name]$repo[description]$repo[baseurl]
+
+ + + | + +
+
+
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 add some repositories.", + "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." ); ?> -- cgit v1.2.3-54-g00ecf