diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-13 22:15:16 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-03-13 22:15:16 +0000 |
commit | 74768e4cea35051b346eb8009e016f71cd02d0bf (patch) | |
tree | c3cce77d4ffa1bce1553e2edac012e61024a5622 | |
parent | 70390e83f867716d4bc919c4937b649ce7a3fdfb (diff) |
The first incarnation of the developer tools. This allows the user to
enter a module name, a description and pick the call backs and or
events they want to support and generate the basic module skeleton
with one click.
@todo: clone a module, clone a theme, generate skeleton controller,
view,
-rw-r--r-- | modules/developer/config/developer.php | 46 | ||||
-rw-r--r-- | modules/developer/controllers/admin_developer.php | 120 | ||||
-rw-r--r-- | modules/developer/helpers/developer_installer.php | 35 | ||||
-rw-r--r-- | modules/developer/helpers/developer_menu.php | 28 | ||||
-rw-r--r-- | modules/developer/helpers/developer_task.php | 93 | ||||
-rw-r--r-- | modules/developer/helpers/developer_theme.php | 25 | ||||
-rw-r--r-- | modules/developer/js/developer.js | 40 | ||||
-rw-r--r-- | modules/developer/module.info | 3 | ||||
-rw-r--r-- | modules/developer/views/admin_developer.html.php | 15 | ||||
-rw-r--r-- | modules/developer/views/developer_module.html.php | 53 | ||||
-rw-r--r-- | modules/developer/views/helpers.txt.php | 26 | ||||
-rw-r--r-- | modules/developer/views/installer.txt.php | 33 | ||||
-rw-r--r-- | modules/developer/views/module_info.txt.php | 5 | ||||
-rw-r--r-- | themes/admin_default/css/fix-ie.css | 1 | ||||
-rw-r--r-- | themes/admin_default/css/screen.css | 2 |
15 files changed, 525 insertions, 0 deletions
diff --git a/modules/developer/config/developer.php b/modules/developer/config/developer.php new file mode 100644 index 00000000..eed26771 --- /dev/null +++ b/modules/developer/config/developer.php @@ -0,0 +1,46 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +$config["methods"] = array( + "theme" => array("album_blocks" => "", "album_bottom" => "", + "album_top" => "", "admin_credits" => "", + "admin_footer" => "", "admin_header_top" => "", + "admin_header_bottom" => "", "admin_page_bottom" => "", + "admin_page_top" => "", "admin_head" => "", + "credits" => "", "dynamic_bottom" => "", + "dynamic_top" => "", "footer" => "", + "head" => "", "header_bottom" => "", + "header_top" => "", "page_bottom" => "", + "page_top" => "", "photo_blocks" => "", + "photo_bottom" => "", "photo_top" => "", + "sidebar_blocks" => "", "sidebar_bottom" => "", + "sidebar_top" => "", "thumb_bottom" => "\$child", + "thumb_info" => "\$child", "thumb_top" => "\$child"), + "menu" => array("admin" => "\$menu, \$theme", "album" => "\$menu, \$theme", + "photo" => "\$menu, \$theme", "site" => "\$menu, \$theme"), + "block" => array("get" => "\$block_id", "get_list" => ""), + "event" => array("batch_complete" => "", "comment_add_form" => "\$form", + "comment_created" => "\$theme, \$args", "comment_updated" => "\$old, \$new", + "group_before_delete" => "\$group", "group_created" => "\$group", + "item_before_delete" => "\$item", "item_created" => "\$item", + "item_related_update" => "\$item", "item_related_update_batch" => "\$sql", + "item_updated" => "\$old, \$new", "user_before_delete" => "\$user", + "user_created" => "\$user", "user_login" => "\$user", + "user_logout" => "\$user" ), + "installer" => array("install" => "", "uninstall" => ""));
\ No newline at end of file diff --git a/modules/developer/controllers/admin_developer.php b/modules/developer/controllers/admin_developer.php new file mode 100644 index 00000000..cf4548d4 --- /dev/null +++ b/modules/developer/controllers/admin_developer.php @@ -0,0 +1,120 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Admin_Developer_Controller extends Admin_Controller { + public function index() { + $view = new Admin_View("admin.html"); + $view->content = new View("admin_developer.html"); + if (!is_writable(MODPATH)) { + message::warning( + t("The module directory is not writable. Please insure that it is writable by the web server")); + } + list ($form, $errors) = $this->_get_module_form(); + $view->content->module_create = $this->_get_module_create_content($form, $errors); + print $view; + } + + public function module_create() { + access::verify_csrf(); + + list ($form, $errors) = $this->_get_module_form(); + + $post = new Validation($_POST); + $post->pre_filter("strtolower", "name"); + $post->add_rules("name", "required"); + $post->add_rules("description", "required"); + $post->add_callbacks("name", array($this, "_is_module_defined")); + + if ($post->validate()) { + + $task_def = Task_Definition::factory() + ->callback("developer_task::create_module") + ->description(t("Create a new module")) + ->name(t("Create Module")); + $task = task::create($task_def, array_merge(array("step" => 0), $post->as_array())); + + print json_encode(array("result" => "started", + "url" => url::site("admin/developer/run_create/{$task->id}?csrf=" . + access::csrf_token()), + "task" => $task->as_array())); + } else { + $v = $this->_get_module_create_content(arr::overwrite($form, $post->as_array()), + arr::overwrite($errors, $post->errors())); + print json_encode(array("result" => "error", + "form" => $v->__toString())); + } + } + + public function run_create($task_id) { + access::verify_csrf(); + + $task = task::run($task_id); + + if ($task->done) { + $context = unserialize($task->context); + switch ($task->state) { + case "success": + message::success(t("Generation of %module completed successfully", + array("module" => $context["name"]))); + break; + + case "error": + message::success(t("Generation of %module failed.", + array("module" => $context["name"]))); + break; + } + print json_encode(array("result" => "success", + "task" => $task->as_array())); + + } else { + print json_encode(array("result" => "in_progress", + "task" => $task->as_array())); + } + } + + private function _get_module_create_content($form, $errors) { + $config = Kohana::config("developer.methods"); + + $v = new View("developer_module.html"); + $v->action = "admin/developer/module_create"; + $v->hidden = array("csrf" => access::csrf_token()); + $v->theme = array_combine(array_keys($config["theme"]), array_keys($config["theme"])); + $v->block = array_combine(array_keys($config["block"]), array_keys($config["block"])); + $v->event = array_combine(array_keys($config["event"]), array_keys($config["event"])); + $v->menu = array_combine(array_keys($config["menu"]), array_keys($config["menu"])); + $v->form = $form; + $v->errors = $errors; + return $v; + } + + public function _is_module_defined(Validation $post, $field) { + $module_name = $post[$field]; + if (file_exists(MODPATH . "$module_name/module.info")) { + $post->add_error($field, "module_exists"); + } + } + + private function _get_module_form($name="", $description="") { + $form = array("name" => "", "description" => "", "theme[]" => array(), "menu[]" => array(), + "block[]" => array(), "event[]" => array()); + $errors = array_fill_keys(array_keys($form), ""); + + return array($form, $errors); + } +} diff --git a/modules/developer/helpers/developer_installer.php b/modules/developer/helpers/developer_installer.php new file mode 100644 index 00000000..8a49ffa6 --- /dev/null +++ b/modules/developer/helpers/developer_installer.php @@ -0,0 +1,35 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class developer_installer { + static function install() { + $config = Kohana::config("developer.methods"); + Kohana::log(Kohana::debug($config)); + $version = module::get_version("developer"); + if ($version == 0) { + module::set_version("developer", 1); + } + } + + static function uninstall() { + $config = Kohana::config("developer.methods"); + Kohana::log(Kohana::debug($config)); + module::delete("developer"); + } +} diff --git a/modules/developer/helpers/developer_menu.php b/modules/developer/helpers/developer_menu.php new file mode 100644 index 00000000..903464be --- /dev/null +++ b/modules/developer/helpers/developer_menu.php @@ -0,0 +1,28 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class developer_menu_Core { + static function admin($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("developer_menu") + ->label(t("Developer Tools")) + ->url(url::site("admin/developer"))); + } +} diff --git a/modules/developer/helpers/developer_task.php b/modules/developer/helpers/developer_task.php new file mode 100644 index 00000000..3fff6fc2 --- /dev/null +++ b/modules/developer/helpers/developer_task.php @@ -0,0 +1,93 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class developer_task_Core { + static function available_tasks() { + // Return empty array so nothing appears in the maintenance screen + return array(); + } + + static function create_module($task) { + $context = unserialize($task->context); + $module_path = (MODPATH . "{$context['name']}"); + + switch ($context["step"]) { + case 0: // Create directory tree + foreach (array("", "controllers", "helpers", "js", "views") as $dir) { + $path = "$module_path/$dir"; + if (!file_exists($path)) { + mkdir($path, 0774); + } + } + break; + case 1: // Generate installer + ob_start(); + $v = new View("installer.txt"); + $v->module_name = $context['name']; + $v->callbacks = $context["theme"]; + print $v->render(); + file_put_contents("$module_path/helpers/{$context['name']}_installer.php", ob_get_contents()); + ob_end_clean(); + break; + case 2: // Generate theme helper + self::_render_helper_file($context, "theme"); + break; + case 3: // Generate block helper + self::_render_helper_file($context, "block"); + break; + case 4: // Generate menu helper + self::_render_helper_file($context, "menu"); + break; + case 5: // Generate event helper + self::_render_helper_file($context, "event"); + break; + case 6: // Generate module.info (do last) + ob_start(); + $v = new View("module_info.txt"); + $v->module_name = $context['name']; + $v->module_description = $context["description"]; + print $v->render(); + file_put_contents("$module_path/module.info", ob_get_contents()); + ob_end_clean(); + break; + } + $task->done = (++$context["step"]) >= 7; + $task->context = serialize($context); + $task->state = "success"; + $task->percent_complete = ($context["step"] / 7.0) * 100; + } + + private static function _render_helper_file($context, $helper) { + if (!empty($context[$helper])) { + $config = Kohana::config("developer.methods"); + ob_start(); + $v = new View("helpers.txt"); + $v->helper = $helper; + $v->module_name = $context['name']; + $v->callbacks = array(); + foreach ($context[$helper] as $callback) { + $v->callbacks[$callback] = $config[$helper][$callback]; + } + print $v->render(); + file_put_contents(MODPATH . "{$context['name']}/helpers/{$context['name']}_{$helper}.php", + ob_get_contents()); + ob_end_clean(); + } + } +}
\ No newline at end of file diff --git a/modules/developer/helpers/developer_theme.php b/modules/developer/helpers/developer_theme.php new file mode 100644 index 00000000..168b1e4c --- /dev/null +++ b/modules/developer/helpers/developer_theme.php @@ -0,0 +1,25 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class developer_theme_Core { + static function admin_head($theme) { + $url = url::file("modules/developer/js/developer.js"); + return "<script src=\"$url\" type=\"text/javascript\"></script>"; + } +}
\ No newline at end of file diff --git a/modules/developer/js/developer.js b/modules/developer/js/developer.js new file mode 100644 index 00000000..88b0626a --- /dev/null +++ b/modules/developer/js/developer.js @@ -0,0 +1,40 @@ +$("#gDeveloperTools").ready(function() { + $("#gDeveloperTools").tabs(); +}); + +var module_success = function(data) { + //alert(data); + $("#gGenerateModule").after('<div id="moduleProgress" style="margin-left: 5em;"></div>'); + $("#moduleProgress").progressbar(); + + var task = data.task; + var url = data.url; + var done = false; + while (!done) { + $.ajax({async: false, + success: function(data, textStatus) { + $("#moduleProgress").progressbar("value", data.task.percent_complete); + done = data.task.done; + }, + dataType: "json", + type: "POST", + url: url + }); + } + document.location.reload(); +}; + +function ajaxify_developer_form(selector, success) { + $(selector).ajaxForm({ + dataType: "json", + success: function(data) { + if (data.form && data.reseult != "started") { + $(selector).replaceWith(data.form); + ajaxify_developer_form(selector, success); + } + if (data.result == "started") { + success(data); + } + } + }); +} diff --git a/modules/developer/module.info b/modules/developer/module.info new file mode 100644 index 00000000..4a8adef7 --- /dev/null +++ b/modules/developer/module.info @@ -0,0 +1,3 @@ +name = Developer +description = Tools to assist module and theme developers +version = 1 diff --git a/modules/developer/views/admin_developer.html.php b/modules/developer/views/admin_developer.html.php new file mode 100644 index 00000000..eeebaa03 --- /dev/null +++ b/modules/developer/views/admin_developer.html.php @@ -0,0 +1,15 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<?= html::script("modules/developer/js/developer.js") ?> +<div id="gDeveloper"> + <h2> + <?= t("Developer Tools") ?> + </h2> + <div id="gDeveloperTools"> + <ul> + <li><a href="#create-module"><span><?= t("Create new module") ?></span></a></li> + </ul> + <div id="#create-module"> + <?= $module_create ?> + </div> + </div> +</div> diff --git a/modules/developer/views/developer_module.html.php b/modules/developer/views/developer_module.html.php new file mode 100644 index 00000000..d572ecfb --- /dev/null +++ b/modules/developer/views/developer_module.html.php @@ -0,0 +1,53 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<script> +$("#gModuleCreateForm").ready(function() { + ajaxify_developer_form("#gModuleCreateForm form", module_success); +}); + +</script> +<div id="gModuleCreateForm"> + <?= form::open($action, array("method" => "post"), $hidden) ?> + <ul> + <li <? if (!empty($errors["name"])): ?> class="gError"<? endif ?>> + <?= form::label("name", t("Name")) ?> + <?= form::input("name", $form["name"]) ?> + <? if (!empty($errors["name"]) && $errors["name"] == "required"): ?> + <p class="gError"><?= t("Module name is required") ?></p> + <? endif ?> + <? if (!empty($errors["name"]) && $errors["name"] == "module_exists"): ?> + <p class="gError"><?= t("Module is already implemented") ?></p> + <? endif ?> + </li> + <li <? if (!empty($errors["description"])): ?> class="gError"<? endif ?>> + <?= form::label("description", t("Description")) ?> + <?= form::input("description", $form["description"]) ?> + <? if (!empty($errors["description"]) && $errors["description"] == "required"): ?> + <p class="gError"><?= t("Module description is required")?></p> + <? endif ?> + </li> + <li> + <ul> + <li> + <?= form::label("theme[]", t("Theme Callbacks")) ?> + <?= form::dropdown(array("name" => "theme[]", "multiple" => true, "size" => 6), $theme, $form["theme[]"]) ?> + </li> + <li> + <?= form::label("block[]", t("Block Callbacks")) ?> + <?= form::dropdown(array("name" => "block[]", "multiple" => true, "size" => 6), $block, $form["block[]"]) ?> + </li> + <li> + <?= form::label("menu[]", t("Menu Callback")) ?> + <?= form::dropdown(array("name" => "menu[]", "multiple" => true, "size" => 6), $menu, $form["block[]"]) ?> + </li> + <li> + <?= form::label("event[]", t("Gallery Event Handlers")) ?> + <?= form::dropdown(array("name" => "event[]", "multiple" => true, "size" => 6), $event, $form["event[]"]) ?> + </li> + </ul> + </li> + <li> + <?= form::submit(array("id" => "gGenerateModule", "name" => "generate", "class" => "submit"), t("Generate")) ?> + </li> + </ul> + <?= form::close() ?> +</div> diff --git a/modules/developer/views/helpers.txt.php b/modules/developer/views/helpers.txt.php new file mode 100644 index 00000000..648015d0 --- /dev/null +++ b/modules/developer/views/helpers.txt.php @@ -0,0 +1,26 @@ +<?php defined("SYSPATH") or die("No direct script access."); ?> +<?= "<?php defined(\"SYSPATH\") or die(\"No direct script access.\");" ?> +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class <?= $module_name ?>_<?= $helper ?> { +<? foreach ($callbacks as $callback => $args): ?> + static function <?= $callback ?>(<?= $args ?>) { + } +<? endforeach ?> +} diff --git a/modules/developer/views/installer.txt.php b/modules/developer/views/installer.txt.php new file mode 100644 index 00000000..81d6d795 --- /dev/null +++ b/modules/developer/views/installer.txt.php @@ -0,0 +1,33 @@ +<?php defined("SYSPATH") or die("No direct script access."); ?> +<?= "<?php defined(\"SYSPATH\") or die(\"No direct script access.\");" ?> +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class <?= $module_name ?>_installer { + static function install() { + $version = module::get_version("<?= $module_name ?>"); + if ($version == 0) { + /* @todo Put database creation here */ + module::set_version("<?= $module_name ?>", 1); + } + } + + static function uninstall() { + module::delete("<?= $module_name ?>"); + } +} diff --git a/modules/developer/views/module_info.txt.php b/modules/developer/views/module_info.txt.php new file mode 100644 index 00000000..4c4b4280 --- /dev/null +++ b/modules/developer/views/module_info.txt.php @@ -0,0 +1,5 @@ +name = <?= $module_name ?> + +description = <?= $module_description ?> + +version = 1 diff --git a/themes/admin_default/css/fix-ie.css b/themes/admin_default/css/fix-ie.css index 08716978..97c619eb 100644 --- a/themes/admin_default/css/fix-ie.css +++ b/themes/admin_default/css/fix-ie.css @@ -5,6 +5,7 @@ #gHeader, #gAdminMenu, #gGroupAdmin, +#gDeveloperTools, .gAvailable .gBlock { zoom: 1; } diff --git a/themes/admin_default/css/screen.css b/themes/admin_default/css/screen.css index e5d7391d..5bc90704 100644 --- a/themes/admin_default/css/screen.css +++ b/themes/admin_default/css/screen.css @@ -213,6 +213,8 @@ li.gGroup { #gGroupAdmin:after, .gSelected:after, .gAvailable .gBlock:after, +#gModuleCreateForm ul li ul:after, +#gDeveloperTools:after, #gPhotoStream:after { clear: both; content: "."; |