diff --git a/modules/developer/config/developer.php b/modules/developer/config/developer.php index 1ad5c300..503f0125 100644 --- a/modules/developer/config/developer.php +++ b/modules/developer/config/developer.php @@ -32,6 +32,7 @@ $config["methods"] = array( "admin_page_bottom" => t("Bottom of administration page"), "admin_page_top" => t("Top of administration page"), "admin_head" => t("Adminstration page head"), + "body_attributes" => t("Body Attributes"), "credits" => t("Album or photo page credits"), "dynamic_bottom" => t("Bottom of dynamic page content"), "dynamic_top" => t("Top of dynamic page content"), @@ -44,27 +45,10 @@ $config["methods"] = array( "photo_blocks" => t("Photo block"), "photo_bottom" => t("Bottom of photo content"), "photo_top" => t("Top of photo content"), + "resize_bottom" => t("Bottom of the resize view"), + "resize_top" => t("Top of the resize view"), "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")), - "event" => array("admin_menu" => t("Add an admin menu element"), - "album_menu" => t("Add an album menu element"), - "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"), - "photo_menu" => t("Add a photo menu element"), - "site_menu" => t("Add a site menu element"), - "user_before_delete" => t("Before user deletion"), - "user_created" => t("User created"), - "user_login" => t("User login"), - "user_logout" => t("User logout"))); + "thumb_top" => t("Top of thumbnail display"))); diff --git a/modules/developer/controllers/admin_developer.php b/modules/developer/controllers/admin_developer.php index 36236d9a..bff5a51f 100644 --- a/modules/developer/controllers/admin_developer.php +++ b/modules/developer/controllers/admin_developer.php @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Admin_Developer_Controller extends Admin_Controller { + static $event_list = array(); + public function module() { $view = new Admin_View("admin.html"); $view->content = new View("admin_developer.html"); @@ -51,6 +53,8 @@ class Admin_Developer_Controller extends Admin_Controller { $post->add_rules("name", "required"); $post->add_rules("display_name", "required"); $post->add_rules("description", "required"); + $post->add_callbacks("theme", array($this, "_noop_validation")); + $post->add_callbacks("event", array($this, "_noop_validation")); $post->add_callbacks("name", array($this, "_is_module_defined")); if ($post->validate()) { @@ -58,14 +62,14 @@ class Admin_Developer_Controller extends Admin_Controller { ->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())); - $success_msg = t("Generation of %module completed successfully", array("module" => $post->name)); $error_msg = t("Generation of %module failed.", array("module" => $post->name)); + $task_context = array("step" => 0, "success_msg" => $success_msg, "error_msg" => $error_msg); + $task = task::create($task_def, array_merge($task_context, $post->as_array())); + print json_encode(array("result" => "started", "max_iterations" => 15, - "success_msg" => $success_msg, "error_msg" => $error_msg, "url" => url::site("admin/developer/run_task/{$task->id}?csrf=" . access::csrf_token()), "task" => $task->as_array())); @@ -77,6 +81,9 @@ class Admin_Developer_Controller extends Admin_Controller { } } + public function _noop_validation(Validation $array, $field) { + } + public function session($key) { access::verify_csrf(); $input = Input::instance(); @@ -85,8 +92,6 @@ class Admin_Developer_Controller extends Admin_Controller { } public function test_data_create() { - access::verify_csrf(); - list ($form, $errors) = $this->_get_test_data_form(); $post = new Validation($_POST); @@ -128,8 +133,6 @@ class Admin_Developer_Controller extends Admin_Controller { } public function run_task($task_id) { - access::verify_csrf(); - try { $task = task::run($task_id); } catch (Exception $e) { @@ -229,14 +232,50 @@ 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 = $config["theme"]; - $v->event = $config["event"]; + $v->event = $this->_get_events(); $v->form = $form; $v->errors = $errors; + $submit_attributes = array( + "id" => "g-generate-module", + "name" => "generate", + "class" => "ui-state-default ui-corner-all", + "style" => "clear:both!important"); + + if (!is_writable(MODPATH)) { + $submit_attributes["class"] .= " ui-state-disabled"; + $submit_attributes["disabled"] = "disabled"; + } + $v->submit_attributes = $submit_attributes; return $v; } + private function _get_events() { + if (empty(self::$event_list)) { + $dir = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator(MODPATH)); + foreach ($dir as $file) { + $file_as_string = file_get_contents($file); + if (preg_match_all('#module::event\("(.*?)"(.*)\);#mU', $file_as_string, $matches, PREG_SET_ORDER) > 0) { + foreach ($matches as $match) { + $event_name = $match[1]; + $parameters = array(); + if (!empty($match[2]) && + preg_match_all('#\$[a-zA-Z_]*#', $match[2], $param_names)) { + + foreach ($param_names[0] as $name) { + $parameters[] = $name != '$this' ? $name : '$' . $event_name; + } + } + self::$event_list["static function $event_name(" . implode(", ", $parameters) . ")"] = $event_name; + ksort(self::$event_list); + } + } + } + } + return self::$event_list; + } + private function _get_test_data_form() { $form = array("albums" => "10", "photos" => "10", "comments" => "10", "tags" => "10", "generate_albums" => ""); @@ -248,7 +287,6 @@ class Admin_Developer_Controller extends Admin_Controller { private function _get_test_data_view($form, $errors) { $v = new View("admin_developer_test_data.html"); $v->action = "admin/developer/test_data_create"; - $v->hidden = array("csrf" => access::csrf_token()); $album_count = ORM::factory("item")->where("type", "=", "album")->count_all(); $photo_count = ORM::factory("item")->where("type", "=", "photo")->count_all(); diff --git a/modules/developer/helpers/developer_task.php b/modules/developer/helpers/developer_task.php index 85f3ea8f..0110127e 100644 --- a/modules/developer/helpers/developer_task.php +++ b/modules/developer/helpers/developer_task.php @@ -25,6 +25,7 @@ class developer_task_Core { static function create_module($task) { $context = unserialize($task->context); + Kohana_Log::add("error", "task context:\n" . Kohana::debug($context)); if (empty($context["module"])) { $context["class_name"] = strtr($context["name"], " ", "_"); @@ -34,11 +35,11 @@ class developer_task_Core { switch ($context["step"]) { case 0: // Create directory tree - foreach (array("", "controllers", "helpers", "js", "views") as $dir) { + foreach (array("", "controllers", "helpers", "views") as $dir) { $path = "{$context['module_path']}/$dir"; if (!file_exists($path)) { mkdir($path); - chmod($path, 0777); + chmod($path, 0755); } } break; @@ -103,7 +104,19 @@ class developer_task_Core { file_put_contents($file, ob_get_contents()); ob_end_clean(); break; - case 9: // Generate module.info (do last) + case 9: // Generate dashboard block view + $file = "{$context['module_path']}/views/admin_{$context['module']}_block.html.php"; + ob_start(); + $v = new View("dashboard_block_html.txt"); + $v->name = $context["name"]; + $v->module = $context["module"]; + $v->class_name = $context["class_name"]; + $v->css_id = preg_replace("#\s+#", "", $context["name"]); + print $v->render(); + file_put_contents($file, ob_get_contents()); + ob_end_clean(); + break; + case 10: // Generate module.info (do last) $file = "{$context["module_path"]}/module.info"; ob_start(); $v = new View("module_info.txt"); @@ -115,7 +128,7 @@ class developer_task_Core { break; } if (isset($file)) { - chmod($file, 0666); + chmod($file, 0765); } $task->done = (++$context["step"]) >= 11; $task->context = serialize($context); @@ -128,7 +141,6 @@ class developer_task_Core { $config = Kohana::config("developer.methods"); $file = "{$context["module_path"]}/helpers/{$context["module"]}_{$helper}.php"; touch($file); - chmod($file, 0666); ob_start(); $v = new View("$helper.txt"); $v->helper = $helper; @@ -184,7 +196,7 @@ class developer_task_Core { private static function _add_album_or_photo($desired_type=null) { srand(time()); $parents = ORM::factory("item")->where("type", "=", "album")->find_all()->as_array(); - $owner_id = user::active()->id; + $owner_id = identity::active_user()->id; $test_images = glob(dirname(dirname(__FILE__)) . "/data/*.[Jj][Pp][Gg]"); @@ -207,7 +219,7 @@ class developer_task_Core { $parents[] = $item->save(); } else { $photo_index = rand(0, count($test_images) - 1); - $item = ORM:factory("item"); + $item = ORM::factory("item"); $item->type = "photo"; $item->parent_id = $parent->id; $item->set_data_file($test_images[$photo_index]); @@ -240,6 +252,7 @@ class developer_task_Core { $comment = ORM::factory("comment"); $comment->author_id = $author->id; + $comment->item_id = $photo->id; $comment->text = self::_random_phrase(rand(8, 500)); $comment->guest_name = $guest_name; $comment->guest_email = $guest_email; diff --git a/modules/developer/views/admin_developer_test_data.html.php b/modules/developer/views/admin_developer_test_data.html.php index de210e50..a29027ba 100644 --- a/modules/developer/views/admin_developer_test_data.html.php +++ b/modules/developer/views/admin_developer_test_data.html.php @@ -19,7 +19,7 @@ endif ?> }); -= form::open($action, array("method" => "post", "id" => "g-generate-test-data"), $hidden) ?> += form::open($action, array("method" => "post", "id" => "g-generate-test-data")) ?> if (!empty($album_count)): ?>
= t("Currently:") ?>
@@ -29,6 +29,7 @@