From 7c5ba9d4229a6e3c258f6a80769e70c5dcd68578 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 15 Mar 2009 05:15:45 +0000 Subject: Refactored the developer module. When a new module is generated a skeleton adminstration page is generated as well. @todo is still generate a skeleton block and a skeleton dialog. --- modules/developer/config/developer.php | 76 ++++++---- modules/developer/controllers/admin_developer.php | 13 +- modules/developer/helpers/developer_task.php | 77 ++++++---- modules/developer/helpers/developer_theme.php | 25 ---- modules/developer/js/developer.js | 6 +- modules/developer/views/admin_controller.txt.php | 60 ++++++++ modules/developer/views/admin_html.txt.php | 10 ++ modules/developer/views/block.txt.php | 26 ++++ modules/developer/views/developer_module.html.php | 6 +- modules/developer/views/event.txt.php | 96 +++++++++++++ modules/developer/views/installer.txt.php | 9 +- modules/developer/views/menu.txt.php | 42 ++++++ modules/developer/views/theme.txt.php | 163 ++++++++++++++++++++++ 13 files changed, 515 insertions(+), 94 deletions(-) delete mode 100644 modules/developer/helpers/developer_theme.php create mode 100644 modules/developer/views/admin_controller.txt.php create mode 100644 modules/developer/views/admin_html.txt.php create mode 100644 modules/developer/views/block.txt.php create mode 100644 modules/developer/views/event.txt.php create mode 100644 modules/developer/views/menu.txt.php create mode 100644 modules/developer/views/theme.txt.php (limited to 'modules/developer') diff --git a/modules/developer/config/developer.php b/modules/developer/config/developer.php index eed26771..35ef0acd 100644 --- a/modules/developer/config/developer.php +++ b/modules/developer/config/developer.php @@ -17,30 +17,54 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + +/** + * Defines the available callback methods + */ $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 + "theme" => array("album_blocks" => t("Album block"), + "album_bottom" => t("Bottom of album content"), + "album_top" => t("Top of Album content"), + "admin_credits" => t("Administration page credits"), + "admin_footer" => t("Adminsitration page footer"), + "admin_header_top" => t("Top of administration page header"), + "admin_header_bottom" => t("Bottom of administration page header"), + "admin_page_bottom" => t("Bottom of administration page"), + "admin_page_top" => t("Top of administration page"), + "admin_head" => t("Adminstration page head"), + "credits" => t("Album or photo page credits"), + "dynamic_bottom" => t("Bottom of dynamic page content"), + "dynamic_top" => t("Top of dynamic page content"), + "footer" => t("Album or photo page footer"), + "head" => t("Album or photo page head"), + "header_bottom" => t("Album or photo header bottom"), + "header_top" => t("Album or photo header top"), + "page_bottom" => t("Album or photo bottom"), + "page_top" => t("Album or photo top"), + "photo_blocks" => t("Photo block"), + "photo_bottom" => t("Bottom of photo content"), + "photo_top" => t("Top of photo content"), + "sidebar_blocks" => t("Sidebar block"), + "sidebar_bottom" => t("Bottom of sidebar"), + "sidebar_top" => t("Top of sidebar"), + "thumb_bottom" => t("Bottom of thumbnail"), + "thumb_info" => t("Thumbnail information"), + "thumb_top" => t("Top of thumbnail display")), + "menu" => array("album" => t("Add an album menu element"), + "photo" => t("Add an photo menu element")), + "event" => array("batch_complete" => t("Batch completion"), + "comment_add_form" => t("Comment add form creation"), + "comment_created" => t("Comment created"), + "comment_updated" => t("Comment updated"), + "group_before_delete" => t("Before delete group"), + "group_created" => t("Group created"), + "item_before_delete" => t("Before album or photo deletion"), + "item_created" => t("Album or photo created"), + "item_related_update" => t("Photo meta data update"), + "item_related_update_batch" => t("Photo meta data update"), + "item_updated" => t("Album or photo update"), + "user_before_delete" => t("Before user deletion"), + "user_created" => t("User created"), + "user_login" => t("User login"), + "user_logout" => t("User logout"))); + \ No newline at end of file diff --git a/modules/developer/controllers/admin_developer.php b/modules/developer/controllers/admin_developer.php index 3811862e..0f4eb125 100644 --- a/modules/developer/controllers/admin_developer.php +++ b/modules/developer/controllers/admin_developer.php @@ -45,9 +45,7 @@ class Admin_Developer_Controller extends Admin_Controller { ->callback("developer_task::create_module") ->description(t("Create a new module")) ->name(t("Create Module")); - $path_part = strtr(strtolower($post->name), " ", "_"); - $task = task::create($task_def, array_merge(array("step" => 0, "path_part" => $path_part), - $post->as_array())); + $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=" . @@ -94,10 +92,9 @@ class Admin_Developer_Controller extends Admin_Controller { $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->theme = $config["theme"]; + $v->event = $config["event"]; + $v->menu = $config["menu"]; $v->form = $form; $v->errors = $errors; return $v; @@ -112,7 +109,7 @@ class Admin_Developer_Controller extends Admin_Controller { private function _get_module_form($name="", $description="") { $form = array("name" => "", "description" => "", "theme[]" => array(), "menu[]" => array(), - "block[]" => array(), "event[]" => array()); + "event[]" => array()); $errors = array_fill_keys(array_keys($form), ""); return array($form, $errors); diff --git a/modules/developer/helpers/developer_task.php b/modules/developer/helpers/developer_task.php index 532d3a8d..d1b8e288 100644 --- a/modules/developer/helpers/developer_task.php +++ b/modules/developer/helpers/developer_task.php @@ -25,68 +25,97 @@ class developer_task_Core { static function create_module($task) { $context = unserialize($task->context); - $module_path = (MODPATH . "{$context['path_part']}"); + + if (empty($context["module"])) { + $context["class_name"] = strtr($context["name"], " ", "_"); + $context["module"] = strtolower($context["class_name"]); + $context["module_path"] = (MODPATH . $context["module"]); + } switch ($context["step"]) { case 0: // Create directory tree + Kohana::log("debug", Kohana::debug($context)); foreach (array("", "controllers", "helpers", "js", "views") as $dir) { - $path = "$module_path/$dir"; + $path = "{$context['module_path']}/$dir"; if (!file_exists($path)) { - mkdir($path, 0774); - } + mkdir($path); + chmod($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(); + $context["installer"] = 1; + self::_render_helper_file($context, "installer"); break; case 2: // Generate theme helper self::_render_helper_file($context, "theme"); break; case 3: // Generate block helper + $context["block"] = 1; self::_render_helper_file($context, "block"); break; case 4: // Generate menu helper + $context["menu"] = empty($context["menu"]) ? 1 : $context["menu"]; 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) + case 6: // Generate admin controller + $file = "{$context['module_path']}/controllers/admin_{$context['module']}.php"; + ob_start(); + $v = new View("admin_controller.txt"); + $v->name = $context["name"]; + $v->module = $context["module"]; + $v->class_name = $context["class_name"]; + print $v->render(); + file_put_contents($file, ob_get_contents()); + ob_end_clean(); + break; + case 7: // Generate admin form + $file = "{$context['module_path']}/views/admin_{$context['module']}.html.php"; + Kohana::log("debug", $file); + ob_start(); + $v = new View("admin_html.txt"); + $v->name = $context["name"]; + $v->module = $context["module"]; + $v->class = strtr($context["name"], " ", ""); + Kohana::log("debug", Kohana::debug($v->render())); + print $v->render(); + file_put_contents($file, ob_get_contents()); + ob_end_clean(); + break; + case 8: // Generate module.info (do last) + $file = "{$context["module_path"]}/module.info"; ob_start(); $v = new View("module_info.txt"); - $v->module_name = $context['name']; + $v->module_name = $context["name"]; $v->module_description = $context["description"]; print $v->render(); - file_put_contents("$module_path/module.info", ob_get_contents()); + file_put_contents($file, ob_get_contents()); ob_end_clean(); break; } - $task->done = (++$context["step"]) >= 7; + $task->done = (++$context["step"]) >= 9; $task->context = serialize($context); $task->state = "success"; - $task->percent_complete = ($context["step"] / 7.0) * 100; + $task->percent_complete = ($context["step"] / 9.0) * 100; } private static function _render_helper_file($context, $helper) { if (!empty($context[$helper])) { $config = Kohana::config("developer.methods"); + $file = "{$context["module_path"]}/helpers/{$context["module"]}_{$helper}.php"; + touch($file); + chmod($file, 0772); ob_start(); - $v = new View("helpers.txt"); + $v = new View("$helper.txt"); $v->helper = $helper; - $v->module_name = $context['name']; - $v->callbacks = array(); - foreach ($context[$helper] as $callback) { - $v->callbacks[$callback] = $config[$helper][$callback]; - } + $v->module = $context["module"]; + $v->module_name = $context["name"]; + $v->callbacks = empty($context[$helper]) ? array() : array_fill_keys($context[$helper], 1); print $v->render(); - file_put_contents(MODPATH . "{$context['name']}/helpers/{$context['name']}_{$helper}.php", - ob_get_contents()); + file_put_contents($file, ob_get_contents()); ob_end_clean(); } } diff --git a/modules/developer/helpers/developer_theme.php b/modules/developer/helpers/developer_theme.php deleted file mode 100644 index 168b1e4c..00000000 --- a/modules/developer/helpers/developer_theme.php +++ /dev/null @@ -1,25 +0,0 @@ -"; - } -} \ No newline at end of file diff --git a/modules/developer/js/developer.js b/modules/developer/js/developer.js index 2440bad4..4d60b5da 100644 --- a/modules/developer/js/developer.js +++ b/modules/developer/js/developer.js @@ -3,12 +3,13 @@ $("#gDeveloperTools").ready(function() { }); var module_success = function(data) { - $("#gGenerateModule").after('
'); + $("#gGenerateModule").after('
'); $("#moduleProgress").progressbar(); var task = data.task; var url = data.url; var done = false; + var counter = 0; while (!done) { $.ajax({async: false, success: function(data, textStatus) { @@ -19,6 +20,7 @@ var module_success = function(data) { type: "POST", url: url }); + done = done || ++counter >= 10; } document.location.reload(); }; @@ -27,7 +29,7 @@ function ajaxify_developer_form(selector, success) { $(selector).ajaxForm({ dataType: "json", success: function(data) { - if (data.form && data.reseult != "started") { + if (data.form && data.result != "started") { $(selector).replaceWith(data.form); ajaxify_developer_form(selector, success); } diff --git a/modules/developer/views/admin_controller.txt.php b/modules/developer/views/admin_controller.txt.php new file mode 100644 index 00000000..42b5ff38 --- /dev/null +++ b/modules/developer/views/admin_controller.txt.php @@ -0,0 +1,60 @@ + + +/** + * 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__Controller extends Admin_Controller { + public function index() { + $view = new Admin_View("admin.html"); + $view->content = new View("admin_.html"); + $view->content->form = $this->_get_admin_form(); + + print $view; + } + + public function handler() { + access::verify_csrf(); + + $form = $this->_get_admin_form(); + if ($form->validate()) { + // @todo process the admin form + + message::success(t(" Adminstration Complete Successfully")); + + url::redirect("admin/"); + } + $view = new Admin_View("admin.html"); + $view->content = new View("admin_.html"); + $view->content->form = $form; + + print $view; + } + + private function _get_admin_view($form=null) { + } + + private function _get_admin_form() { + $form = new Forge("admin//handler", "", "post", + array("id" => "gAdminForm")); + $group = $form->group("group"); + $group->input("text")->label(t("Text"))->rules("required"); + $group->submit("submit")->value(t("Submit")); + + return $form; + } +} \ No newline at end of file diff --git a/modules/developer/views/admin_html.txt.php b/modules/developer/views/admin_html.txt.php new file mode 100644 index 00000000..34b699d7 --- /dev/null +++ b/modules/developer/views/admin_html.txt.php @@ -0,0 +1,10 @@ + +" ?> + +
+

+ " ?> +

+ " ?> + +
diff --git a/modules/developer/views/block.txt.php b/modules/developer/views/block.txt.php new file mode 100644 index 00000000..b8a96da0 --- /dev/null +++ b/modules/developer/views/block.txt.php @@ -0,0 +1,26 @@ + + +/** + * 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 _block { + static function get($block_id) { + } + static function get_list() { + } +} diff --git a/modules/developer/views/developer_module.html.php b/modules/developer/views/developer_module.html.php index d572ecfb..4ce28ff7 100644 --- a/modules/developer/views/developer_module.html.php +++ b/modules/developer/views/developer_module.html.php @@ -31,13 +31,9 @@ $("#gModuleCreateForm").ready(function() { "theme[]", "multiple" => true, "size" => 6), $theme, $form["theme[]"]) ?> -
  • - - "block[]", "multiple" => true, "size" => 6), $block, $form["block[]"]) ?> -
  • - "menu[]", "multiple" => true, "size" => 6), $menu, $form["block[]"]) ?> + "menu[]", "multiple" => true, "size" => 6), $menu, $form["menu[]"]) ?>
  • diff --git a/modules/developer/views/event.txt.php b/modules/developer/views/event.txt.php new file mode 100644 index 00000000..e2731f96 --- /dev/null +++ b/modules/developer/views/event.txt.php @@ -0,0 +1,96 @@ + + +/** + * 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 _event { + + static function batch_complete() { + } + + + + static function comment_add_form($form) { + } + + + + static function comment_created($theme, $args) { + } + + + + static function comment_updated($old, $new) { + } + + + + static function group_before_delete($group) { + } + + + + static function group_created($group) { + } + + + + static function item_before_delete($item) { + } + + + + static function item_created($item) { + } + + + + static function item_related_update($item) { + } + + + + static function item_related_update_batch($sql) { + } + + + + static function item_updated($old, $new) { + } + + + + static function user_before_delete($user) { + } + + + + static function user_created($user) { + } + + + + static function user_login($user) { + } + + + + static function user_logout($user) { + } + +} diff --git a/modules/developer/views/installer.txt.php b/modules/developer/views/installer.txt.php index 81d6d795..1ccc3327 100644 --- a/modules/developer/views/installer.txt.php +++ b/modules/developer/views/installer.txt.php @@ -18,16 +18,17 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class _installer { +class _installer { static function install() { - $version = module::get_version(""); + $version = module::get_version(""); if ($version == 0) { /* @todo Put database creation here */ - module::set_version("", 1); + module::set_version("", 1); } } static function uninstall() { - module::delete(""); + /* @todo Put database table drops here */ + module::delete(""); } } diff --git a/modules/developer/views/menu.txt.php b/modules/developer/views/menu.txt.php new file mode 100644 index 00000000..5404f6c5 --- /dev/null +++ b/modules/developer/views/menu.txt.php @@ -0,0 +1,42 @@ + + +/** + * 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 _menu { + static function admin($menu, $theme) { + $menu->get("settings_menu") + ->append(Menu::factory("link") + ->id("_menu") + ->label(t(" Administration")) + ->url(url::site("admin/"))); + } + + + static function album($menu, $theme) { + } + + + + static function photo($menu, $theme) { + } + + + static function site($menu, $theme) { + } +} diff --git a/modules/developer/views/theme.txt.php b/modules/developer/views/theme.txt.php new file mode 100644 index 00000000..df7b18e0 --- /dev/null +++ b/modules/developer/views/theme.txt.php @@ -0,0 +1,163 @@ + + +/** + * 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 _theme { + + + static function album_blocks() { + } + + + + static function album_bottom() { + } + + + + static function album_top() { + } + + + + static function admin_credits() { + } + + + + static function admin_footer() { + } + + + + static function admin_header_top() { + } + + + + static function admin_header_bottom() { + } + + + + static function admin_page_bottom() { + } + + + + static function admin_page_top() { + } + + + + static function admin_head() { + } + + + + static function credits() { + } + + + + static function dynamic_bottom() { + } + + + + static function dynamic_top() { + } + + + + static function footer() { + } + + + + static function head() { + } + + + + static function header_bottom() { + } + + + + static function header_top() { + } + + + + static function page_bottom() { + } + + + + static function page_top() { + } + + + + static function photo_blocks() { + } + + + + static function photo_bottom() { + } + + + + static function photo_top() { + } + + + + static function sidebar_blocks() { + } + + + + static function sidebar_bottom() { + } + + + + static function sidebar_top() { + } + + + + static function thumb_bottom($child) { + } + + + + static function thumb_info($child) { + } + + + + static function thumb_top($child) { + } + + +} -- cgit v1.2.3