diff options
-rw-r--r-- | core/controllers/scaffold.php | 288 | ||||
-rw-r--r-- | core/helpers/core_menu.php | 2 | ||||
-rw-r--r-- | core/views/scaffold.html.php | 311 | ||||
-rw-r--r-- | core/views/scaffold_syscheck.html.php | 68 |
4 files changed, 11 insertions, 658 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php index b89c27ce..2454b400 100644 --- a/core/controllers/scaffold.php +++ b/core/controllers/scaffold.php @@ -26,19 +26,14 @@ class Scaffold_Controller extends Template_Controller { } catch (Exception $e) { } - $this->template->syscheck = new View("scaffold_syscheck.html"); - $this->template->syscheck->errors = $this->_get_config_errors(); - $this->template->syscheck->modules = array(); - + if (!user::active()->admin) { + throw new Exception("@todo FORBIDDEN", 503); + } + set_error_handler(array("Scaffold_Controller", "_error_handler")); try { - $this->template->syscheck->modules = module::available(); $this->template->album_count = ORM::factory("item")->where("type", "album")->count_all(); $this->template->photo_count = ORM::factory("item")->where("type", "photo")->count_all(); - $this->template->deepest_photo = ORM::factory("item") - ->where("type", "photo")->orderby("level", "desc")->find(); - $this->template->deepest_album = ORM::factory("item") - ->where("type", "album")->orderby("level", "desc")->find(); $this->template->album_tree = $this->_load_album_tree(); $this->template->add_photo_html = $this->_get_add_photo_html(); } catch (Exception $e) { @@ -49,13 +44,10 @@ class Scaffold_Controller extends Template_Controller { $this->template->add_photo_html = ""; } - $this->_load_user_info(); - $this->_load_group_info(); $this->_load_comment_info(); $this->_load_tag_info(); - restore_error_handler(); - $this->_create_directories(); + restore_error_handler(); if (!empty($session) && $session->get("profiler", false)) { $profiler = new Profiler(); @@ -63,135 +55,6 @@ class Scaffold_Controller extends Template_Controller { } } - function install($module_name, $redirect=true) { - $to_install = array(); - if ($module_name == "*") { - foreach (module::available() as $module_name => $info) { - if (empty($info->installed)) { - $to_install[] = $module_name; - } - } - } else { - $to_install[] = $module_name; - } - - foreach ($to_install as $module_name) { - if ($module_name != "core") { - require_once(DOCROOT . "modules/${module_name}/helpers/${module_name}_installer.php"); - } - module::install($module_name); - } - - if ($redirect) { - url::redirect("scaffold"); - } - } - - function uninstall($module_name, $redirect=true) { - $clean = true; - if ($module_name == "core") { - // We have to uninstall all other modules first, else their tables, etc don't - // get cleaned up. - $old_handler = set_error_handler(array("scaffold_Controller", "_error_handler")); - try { - foreach (ORM::factory("module")->find_all() as $module) { - if ($module->name != "core" && $module->version) { - try { - call_user_func(array("{$module->name}_installer", "uninstall")); - } catch (Exception $e) { - print $e; - } - } - } - core_installer::uninstall(); - } catch (Exception $e) { - print $e; - } - - - // Since we're in a state of flux, it's possible that other stuff went wrong with the - // uninstall, so back off and nuke it from orbit. It's the only way to be sure. - $db = Database::instance(); - foreach ($db->list_tables() as $table) { - $db->query("DROP TABLE `$table`"); - } - set_error_handler($old_handler); - } else { - module::uninstall($module_name); - } - if ($redirect) { - url::redirect("scaffold"); - } - } - - function mptt() { - $this->auto_render = false; - $items = ORM::factory("item")->orderby("id")->find_all(); - $data = "digraph G {\n"; - foreach ($items as $item) { - $data .= " $item->parent_id -> $item->id\n"; - $data .= " $item->id [label=\"$item->id [$item->level] <$item->left, $item->right>\"]\n"; - } - $data .= "}\n"; - - if ($this->input->get("type") == "text") { - print "<pre>$data"; - } else { - $proc = proc_open("/usr/bin/dot -Tsvg", - array(array("pipe", "r"), - array("pipe", "w")), - $pipes, - VARPATH . "tmp"); - fwrite($pipes[0], $data); - fclose($pipes[0]); - - header("Content-Type: image/svg+xml"); - print(stream_get_contents($pipes[1])); - fclose($pipes[1]); - proc_close($proc); - } - } - - function i18n($action) { - $translation_file = VARPATH . "translation.php"; - - switch($action) { - case "build": - $t = array(); - for ($i = 0; $i < 500; $i++) { - $t["this is message $i of many"] = "localized version of $i"; - } - - $fp = fopen($translation_file, "wb"); - fwrite($fp, "<? \$t = "); - fwrite($fp, var_export($t, 1)); - fwrite($fp, ";"); - fclose($fp); - url::redirect("scaffold"); - break; - - case "run": - Benchmark::start("load_translation"); - include $translation_file; - Benchmark::stop("load_translation"); - - $count = 500; - Benchmark::start("loop_overhead_$count"); - for ($i = 0; $i < $count; $i++) { - } - Benchmark::stop("loop_overhead_$count"); - - $count = 500; - Benchmark::start("translations_$count"); - for ($i = 0; $i < $count; $i++) { - $value = $t["this is message $i of many"]; - } - Benchmark::stop("loop_overhead_$count"); - - $profiler = new Profiler(); - $this->auto_render = false; - } - } function add_photos() { $path = trim($this->input->post("path")); @@ -365,82 +228,9 @@ class Scaffold_Controller extends Template_Controller { return $results; } - private function _get_config_errors() { - $errors = array(); - if (!file_exists(VARPATH)) { - $error = new stdClass(); - $error->message = "Missing: " . VARPATH; - $error->instructions[] = "mkdir " . VARPATH; - $error->instructions[] = "chmod 777 " . VARPATH; - $errors[] = $error; - } else if (!is_writable(VARPATH)) { - $error = new stdClass(); - $error->message = "Not writable: " . VARPATH; - $error->instructions[] = "chmod 777 " . VARPATH; - $errors[] = $error; - } - - $db_php = VARPATH . "database.php"; - if (!file_exists($db_php)) { - $error = new stdClass(); - $error->message = "Missing: $db_php <br/> Run the following commands..."; - $error->instructions[] = "cp " . DOCROOT . "kohana/config/database.php $db_php"; - $error->instructions[] = "chmod 644 $db_php"; - $error->message2 = "...then edit this file and enter your database configuration settings."; - $errors[] = $error; - } else if (!is_readable($db_php)) { - $error = new stdClass(); - $error->message = "Not readable: $db_php"; - $error->instructions[] = "chmod 644 $db_php"; - $error->message2 = "Then edit this file and enter your database configuration settings."; - $errors[] = $error; - } else { - $old_handler = set_error_handler(array("Scaffold_Controller", "_error_handler")); - try { - Database::instance()->connect(); - } catch (Exception $e) { - $error = new stdClass(); - $error->message = "Database error: {$e->getMessage()}"; - $db_name = Kohana::config("database.default.connection.database"); - if (strchr($error->message, "Unknown database")) { - $error->instructions[] = "mysqladmin -uroot create $db_name"; - } else { - $error->instructions = array(); - $error->message2 = "Check " . VARPATH . "database.php"; - } - $errors[] = $error; - } - set_error_handler($old_handler); - } - - return $errors; - } - function _error_handler($x) { } - function _create_directories() { - foreach (array("logs", "uploads") as $dir) { - @mkdir(VARPATH . "$dir"); - } - } - - private function _load_group_info() { - if (class_exists("Group_Model")) { - $this->template->groups = ORM::factory("group")->find_all(); - } else { - $this->template->groups = array(); - } - } - - private function _load_user_info() { - if (class_exists("User_Model")) { - $this->template->users = ORM::factory("user")->find_all(); - } else { - $this->template->users = array(); - } - } - private function _load_comment_info() { if (class_exists("Comment_Model")) { $this->template->comment_count = ORM::factory("comment")->count_all(); @@ -466,6 +256,7 @@ class Scaffold_Controller extends Template_Controller { } } + public function package() { $this->auto_render = false; @@ -560,54 +351,6 @@ class Scaffold_Controller extends Template_Controller { url::redirect("scaffold"); } - public function add_user() { - $name = $this->input->post("user_name"); - $isAdmin = (bool)$this->input->post("admin"); - $user = user::create($name, $name, $name); - if ($isAdmin) { - $user->admin = true; - $user->save(); - } - url::redirect("scaffold"); - } - - public function delete_user($id) { - ORM::factory("user", $id)->delete(); - url::redirect("scaffold"); - } - - public function add_group() { - $name = $this->input->post("group_name"); - group::create($name); - url::redirect("scaffold"); - } - - public function delete_group($id) { - ORM::factory("group", $id)->delete(); - url::redirect("scaffold"); - } - - public function remove_from_group($group_id, $user_id) { - $group = ORM::factory("group", $group_id); - $user = ORM::factory("user", $user_id); - if ($group->loaded && $user->loaded) { - $group->remove($user); - $group->save(); - } - url::redirect("scaffold"); - } - - public function add_to_group($user_id) { - $group_name = $this->input->post("group_name"); - $group = ORM::factory("group")->where("name", $group_name)->find(); - $user = ORM::factory("user", $user_id); - if ($group->loaded && $user->loaded) { - $group->add($user); - $group->save(); - } - url::redirect("scaffold"); - } - private function _load_album_tree() { $tree = array(); foreach (ORM::factory("item")->where("type", "album")->find_all() as $album) { @@ -621,25 +364,6 @@ class Scaffold_Controller extends Template_Controller { return $tree; } - public function add_perm($group_id, $perm, $item_id) { - access::allow(ORM::factory("group", $group_id), $perm, ORM::factory("item", $item_id)); - url::redirect("scaffold"); - } - - public function deny_perm($group_id, $perm, $item_id) { - access::deny(ORM::factory("group", $group_id), $perm, ORM::factory("item", $item_id)); - url::redirect("scaffold"); - } - - public function reset_all_perms($group_id, $item_id) { - $group = ORM::factory("group", $group_id); - $item = ORM::factory("item", $item_id); - foreach (ORM::factory("permission")->find_all() as $perm) { - access::reset($group, $perm->name, $item); - } - url::redirect("scaffold"); - } - public function form($arg1, $arg2) { if ($arg1 == "add" && $arg2 == "photos") { print $this->_get_add_photo_html(); diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php index c0e94f94..e372cc72 100644 --- a/core/helpers/core_menu.php +++ b/core/helpers/core_menu.php @@ -19,7 +19,7 @@ */ class core_menu_Core { static function site($menu, $theme) { - if (file_exists(APPPATH . "controllers/scaffold.php")) { + if (file_exists(APPPATH . "controllers/scaffold.php") && user::active()->admin) { $menu->append($scaffold_menu = Menu::factory("submenu") ->id("scaffold") ->label("Scaffold")); diff --git a/core/views/scaffold.html.php b/core/views/scaffold.html.php index 028acd02..765464b5 100644 --- a/core/views/scaffold.html.php +++ b/core/views/scaffold.html.php @@ -62,65 +62,12 @@ margin-top: -.25em; } - div#activities { - margin-bottom: 1em; - } - - div.activity { - display: none; - } - - ul.tabs { - margin-left: 0; - padding: 1em 0 2px 1em; - white-space: nowrap; - border-bottom: 1px solid black; - } - - ul.tabs li { - display: inline; - list-style-type: none; - } - - ul.tabs a { - padding: 3px 10px; - color: #fff; - background-color: #036; - text-decoration: none; - } - - div#access { - margin-top: -20px; - padding: 0px; - padding-left: 20px; - } - - div#access ul.tabs a { - background-color: #830; - border: 1px solid white; - } - - ul.tabs a:hover { - background-color: #369; - } - fieldset { margin-left: 1em; + margin-bottom: 1em; padding-bottom: 0; } - div#photo_upload_wrap { - display: inline; - } - - div#photo_upload_wrap { - display: inline; - } - - tr.core td { - border-bottom: 1px solid black; - } - a { text-decoration: none; } @@ -129,11 +76,6 @@ text-decoration: underline; } - span.understate { - font-size: 70%; - font-style: italic; - } - a.allowed { color: green; font-size: 110%; @@ -144,11 +86,6 @@ font-size: 90%; } - ul#permissions ul { - margin-left: -1.5em; - list-style-type: none; - } - .gHide { display: none; } @@ -161,10 +98,6 @@ margin: 5px 0px 0px 1em; } </style> - <?= html::script("lib/jquery.js") ?> - <?= html::script("lib/jquery.form.js") ?> - <?= html::script("lib/jquery.cookie.js") ?> - <?= html::script("lib/jquery.MultiFile.js") ?> </head> <body> <div class="outer"> @@ -193,58 +126,9 @@ </div> <? endif ?> - <ul class="tabs"> - <li><a href="javascript:show('config')">Configuration</a></li> - <? if ($album_count > 0): ?> - <li><a href="javascript:show('actions')">Actions</a></li> - <? if (module::is_installed("user")): ?> - <li><a href="javascript:show('access')">Access</a></li> - <? endif ?> - <li><a href="javascript:show('info')">Info</a></li> - <li><a href="javascript:show('benchmarks')">Benchmarks</a></li> - <li><a href="javascript:show('docs')">Docs</a></li> - <? endif ?> - </ul> - - <div id="activities"> - <script> - show = function(show1, show2, immediate) { - if (!show1) { - show1 = "configuration"; - } else if (show1 == "access" && !show2) { - show2 = "access_users"; - } - var acts = $("div.activity"); - for (var i = 0; i < acts.length; i++) { - act = acts[i]; - if (act.id != show1 && act.id != show2) { - if (immediate) { - $("#" + act.id).hide(); - } else { - $("#" + act.id).slideUp(); - } - } else { - if (immediate) { - $("#" + act.id).show(); - } else { - $("#" + act.id).slideDown(); - } - } - } - $.cookie("show1", show1); - $.cookie("show2", show2); - } - $(document).ready(function(){ - show($.cookie("show1"), $.cookie("show2"), true); - $("#photo_upload").MultiFile(); - }); - </script> - - <div id="config" class="activity"> - <?= $syscheck ?> - </div> - - <div id="actions" class="activity"> + <div id="actions" class="activity"> + <fieldset> + <legend>Generate Test Data</legend> <p> add: [ <? foreach (array(1, 10, 50, 100, 500, 1000) as $count): ?> @@ -273,198 +157,11 @@ <? endforeach ?> ] tags </p> - <?= $add_photo_html ?> - <fieldset> - <legend>Server Side Photos</legend> - <form method="post" action="<?= url::site("scaffold/add_photos") ?>"> - <input type="submit" value="upload"/> - <input type="text" name="path" size="70" - value="<?= cookie::get("add_photos_path") ?>" /> - <br> - Album id: <input name="parent_id" type="text" size="3" value="1"/> - </form> - </fieldset> - <fieldset> - <legend>Albums</legend> - <form method="post" action="<?= url::site("albums/1") ?>"> - <input type="submit" value="create"/> - <input type="text" name="name"/> - <input type="hidden" name="type" value="album"/> - </form> </fieldset> <fieldset> <legend>Packaging</legend> <a href="<?= url::site("scaffold/package") ?>">Make Package</a> </fieldset> - </div> - - <? if (module::is_installed("user")): ?> - <div id="access" class="activity"> - <ul class="tabs"> - <li><a href="javascript:show('access', 'access_users')">Users</a></li> - <li><a href="javascript:show('access', 'access_groups')">Groups</a></li> - <li><a href="javascript:show('access', 'access_permissions')">Guest Permissions</a></li> - </ul> - - <div id="access_users" class="activity"> - <ul> - <? foreach ($users as $user): ?> - <li> - <?= $user->name ?> - <? if (!$user->admin): ?> - <?= html::anchor("scaffold/delete_user/$user->id", "[x]") ?> - <? endif ?> - <ul> - <? foreach ($user->groups as $group): ?> - <li> - <?= $group->name ?> - <? if (!$group->special): ?> - <?= html::anchor("scaffold/remove_from_group/$group->id/$user->id", "[x]") ?> - <? endif ?> - </li> - <? endforeach ?> - <li> - <form method="post" action="<?= url::site("scaffold/add_to_group/$user->id") ?>"> - <input type="text" name="group_name"/> - </form> - </li> - </ul> - </li> - <? endforeach ?> - </ul> - <fieldset> - <legend>Add User</legend> - <form method="post" action="<?= url::site("scaffold/add_user") ?>"> - <input name="user_name" type="text"/> - <input type="submit" value="create"/> - <input type="checkbox" name="admin"/> Admin - </form> - </fieldset> - </div> - - <div id="access_groups" class="activity"> - <ul> - <? foreach ($groups as $group): ?> - <li> - <?= $group->name ?> - <? if (!$group->special): ?> - <?= html::anchor("scaffold/delete_group/$group->id", "[x]") ?> - <? endif ?> - </li> - <? endforeach ?> - </ul> - <fieldset> - <legend>Add Group</legend> - <form method="post" action="<?= url::site("scaffold/add_group") ?>"> - <input name="group_name" type="text"/> - <input type="submit" value="create"/> - </form> - </fieldset> - </div> - - <div id="access_permissions" class="activity"> - <? if ($album_tree): ?> - <? $stack = array(1); // hardcoded to the root album ?> - <? while ($stack): ?> - <? $current = array_pop($stack); ?> - <? if ($current != "CLOSE"): ?> - <? $current = $album_tree[$current]; ?> - <ul id="permissions"> - <li> - <span class="understate">(<?= $current->album->id ?>)</span> - <?= html::anchor("albums/{$current->album->id}", $current->album->title) ?> - » - <? foreach (array("view", "view_full", "edit") as $perm): ?> - <?= $perm != "view" ? " ---- " : "" ?> - <? if (access::group_can(group::everybody(), $perm, $current->album)): ?> - <?= html::anchor("scaffold/deny_perm/1/$perm/{$current->album->id}", strtoupper($perm), array("class" => "allowed")) ?> - <? else: ?> - <?= html::anchor("scaffold/add_perm/1/$perm/{$current->album->id}", strtolower($perm), array("class" => "denied")) ?> - <? endif ?> - <? endforeach ?> - <? if ($current->album->id != 1): ?> - <span class="understate"> - (<?= html::anchor("scaffold/reset_all_perms/1/{$current->album->id}", "reset") ?>) - </span> - <? endif; ?> - <? $stack[] = "CLOSE"; ?> - <? if ($current->children): ?> - <? $stack = array_merge($stack, $current->children) ?> - <? endif ?> - <? else: ?> - </li> - </ul> - <? endif ?> - <? endwhile ?> - <? endif ?> - </div> - </div> - <? endif ?> - - <div id="info" class="activity"> - <ul> - <li> <?= html::anchor("scaffold/mptt?type=text", "MPTT tree (text)") ?> </li> - <li> - <?= html::anchor("scaffold/mptt", "MPTT tree (graph)") ?> - <i>(requires /usr/bin/dot from the graphviz package)</i> - </li> - <? if ($deepest_photo): ?> - <li> - <?= html::anchor("photos/{$deepest_photo->id}", "Deepest photo") ?> - <i>(<?= $deepest_photo->level ?> levels deep)</i> - </li> - <? endif ?> - <? if ($deepest_album): ?> - <li> - <?= html::anchor("albums/{$deepest_album->id}", "Deepest album") ?> - <i>(<?= $deepest_album->level ?> levels deep)</i> - </li> - <? endif ?> - <? if ($most_tagged): ?> - <li> - <?= html::anchor("items/{$most_tagged->id}", "Most tagged item") ?> - <i>(<?= $most_tagged->count ?> tags)</i> - </li> - <? endif ?> - </ul> - </div> - - <div id="benchmarks" class="activity"> - <ul> - <li> - <?= html::anchor("scaffold/i18n/build", "Make Translation") ?> - </li> - <li> - <?= html::anchor("scaffold/i18n/run", "Run Translation") ?> - </li> - </ul> - </div> - - <div id="docs" class="activity"> - <ul> - <li> - <a href="http://codex.gallery2.org/Gallery3:Features">Gallery3: Features</a> - </li> - <li> - <a href="http://gallery.svn.sourceforge.net/viewvc/gallery/trunk/eval/gx/ui/HTML/index.html">Mockups</a> - </li> - <li> - <a href="http://www.nabble.com/Rough-Gallery-3-time-line-td20240153.html">Rough Timeline</a> (as of Oct 29, 2008) - </li> - <li> - <a href="http://codex.gallery2.org/Gallery3:About">Gallery3: About Page</a> - </li> - <li> - <a href="http://codex.gallery2.org/Gallery3:Coding_Standards">Gallery3: Coding Standards</a> - </li> - <li> - <a href="http://docs.kohanaphp.com/">Kohana Documentation</a> - </li> - <li> - <a href="http://jkwebs.de/gallery/gx_admin/">Admin wireframes</a> - </li> - </ul> - </div> </div> </div> </div> diff --git a/core/views/scaffold_syscheck.html.php b/core/views/scaffold_syscheck.html.php deleted file mode 100644 index 7dbb4b9f..00000000 --- a/core/views/scaffold_syscheck.html.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<? foreach ($errors as $error): ?> -<div class="block"> - <p class="error"> - <?= $error->message ?> - </p> - <? foreach ($error->instructions as $line): ?> - <pre><?= $line ?></pre> - <? endforeach ?> - - <? if (!empty($error->message2)): ?> - <p class="error"> - <?= $error->message2 ?> - </p> - <? endif ?> -</div> -<? endforeach ?> - -<? if (empty($errors)): ?> -<div class="block"> - <? if (!module::is_installed("core")): ?> - <p class="success"> - Your system is ready, but Gallery is not yet installed. - </p> - <p> - <?= html::anchor("scaffold/install/core", "install gallery") ?> - </p> - <? else: ?> - <p class="success"> - Your Gallery is ready with the following modules installed: - </p> - <table style="width: 400px"> - <tr> - <th align="left">Name</th> - <th align="left">Installed</th> - <th align="left">Available</th> - <th align="left">Action</th> - </tr> - <tr class="core"> - <td> <b> core </b> </td> - <td> <b> <?= module::get_version("core") ?> </b> </td> - <td> <b> <?= module::get_version("core") ?> </b> </td> - <td> <b> <?= html::anchor("scaffold/uninstall/core", "reset install") ?> </b> </td> - </tr> - <? foreach ($modules as $module_name => $info): ?> - <? if ($module_name == "core") continue; ?> - <tr> - <td><?= $module_name ?></td> - <td><?= $info->installed ?></td> - <td><?= $info->version ?></td> - <td> - <? if ($info->installed): ?> - <?= html::anchor("scaffold/uninstall/{$module_name}", "uninstall") ?> - <? else: ?> - <?= html::anchor("scaffold/install/{$module_name}", "install") ?> - <? endif ?> - </td> - </tr> - <? endforeach; ?> - <tr> - <td colspan="3" align="center"> - <button onclick="document.location.href='<?= url::site("scaffold/install/*") ?>'">Install All Plugins</button> - </td> - </tr> - </table> - <? endif; ?> -</div> -<? endif ?> |