From 4eedf804e1f26d95de6803e48c608d893c53b7d0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 28 May 2009 07:15:00 +0800 Subject: Update all references to the core application to now point to the gallery module. This type of mass update is prone to some small bugs. Signed-off-by: Gallery Role Account --- modules/gallery/helpers/access.php | 4 +- modules/gallery/helpers/block_manager.php | 4 +- modules/gallery/helpers/core.php | 52 ----- modules/gallery/helpers/core_block.php | 100 --------- modules/gallery/helpers/core_event.php | 46 ----- modules/gallery/helpers/core_installer.php | 278 -------------------------- modules/gallery/helpers/core_menu.php | 162 --------------- modules/gallery/helpers/core_search.php | 24 --- modules/gallery/helpers/core_task.php | 166 --------------- modules/gallery/helpers/core_theme.php | 137 ------------- modules/gallery/helpers/gallery.php | 52 +++++ modules/gallery/helpers/gallery_block.php | 100 +++++++++ modules/gallery/helpers/gallery_event.php | 46 +++++ modules/gallery/helpers/gallery_installer.php | 278 ++++++++++++++++++++++++++ modules/gallery/helpers/gallery_menu.php | 162 +++++++++++++++ modules/gallery/helpers/gallery_search.php | 24 +++ modules/gallery/helpers/gallery_task.php | 166 +++++++++++++++ modules/gallery/helpers/gallery_theme.php | 137 +++++++++++++ modules/gallery/helpers/graphics.php | 28 +-- modules/gallery/helpers/l10n_client.php | 4 +- modules/gallery/helpers/locale.php | 8 +- modules/gallery/helpers/module.php | 28 +-- modules/gallery/helpers/movie.php | 4 +- modules/gallery/helpers/theme.php | 15 +- 24 files changed, 1013 insertions(+), 1012 deletions(-) delete mode 100644 modules/gallery/helpers/core.php delete mode 100644 modules/gallery/helpers/core_block.php delete mode 100644 modules/gallery/helpers/core_event.php delete mode 100644 modules/gallery/helpers/core_installer.php delete mode 100644 modules/gallery/helpers/core_menu.php delete mode 100644 modules/gallery/helpers/core_search.php delete mode 100644 modules/gallery/helpers/core_task.php delete mode 100644 modules/gallery/helpers/core_theme.php create mode 100644 modules/gallery/helpers/gallery.php create mode 100644 modules/gallery/helpers/gallery_block.php create mode 100644 modules/gallery/helpers/gallery_event.php create mode 100644 modules/gallery/helpers/gallery_installer.php create mode 100644 modules/gallery/helpers/gallery_menu.php create mode 100644 modules/gallery/helpers/gallery_search.php create mode 100644 modules/gallery/helpers/gallery_task.php create mode 100644 modules/gallery/helpers/gallery_theme.php (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index 64ce91fa..c48f0b79 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -389,7 +389,7 @@ class access_Core { * @return ORM_Iterator */ private static function _get_all_groups() { - // When we build the core package, it's possible that the user module is not installed yet. + // When we build the gallery package, it's possible that the user module is not installed yet. // This is ok at packaging time, so work around it. if (module::is_active("user")) { return ORM::factory("group")->find_all(); @@ -595,7 +595,7 @@ class access_Core { } static function private_key() { - return module::get_var("core", "private_key"); + return module::get_var("gallery", "private_key"); } /** diff --git a/modules/gallery/helpers/block_manager.php b/modules/gallery/helpers/block_manager.php index 022626e5..20b641d4 100644 --- a/modules/gallery/helpers/block_manager.php +++ b/modules/gallery/helpers/block_manager.php @@ -19,11 +19,11 @@ */ class block_manager_Core { static function get_active($location) { - return unserialize(module::get_var("core", "blocks_$location", "a:0:{}")); + return unserialize(module::get_var("gallery", "blocks_$location", "a:0:{}")); } static function set_active($location, $blocks) { - module::set_var("core", "blocks_$location", serialize($blocks)); + module::set_var("gallery", "blocks_$location", serialize($blocks)); } static function add($location, $module_name, $block_id) { diff --git a/modules/gallery/helpers/core.php b/modules/gallery/helpers/core.php deleted file mode 100644 index 63f51f86..00000000 --- a/modules/gallery/helpers/core.php +++ /dev/null @@ -1,52 +0,0 @@ -admin) { - Router::$controller = "maintenance"; - Router::$controller_path = APPPATH . "controllers/maintenance.php"; - Router::$method = "index"; - } - } - - /** - * This function is called when the Gallery is fully initialized. We relay it to modules as the - * "gallery_ready" event. Any module that wants to perform an action at the start of every - * request should implement the _event::gallery_ready() handler. - */ - static function ready() { - module::event("gallery_ready"); - } - - /** - * This function is called right before the Kohana framework shuts down. We relay it to modules - * as the "gallery_shutdown" event. Any module that wants to perform an action at the start of - * every request should implement the _event::gallery_shutdown() handler. - */ - static function shutdown() { - module::event("gallery_shutdown"); - } -} \ No newline at end of file diff --git a/modules/gallery/helpers/core_block.php b/modules/gallery/helpers/core_block.php deleted file mode 100644 index 0e2e9c54..00000000 --- a/modules/gallery/helpers/core_block.php +++ /dev/null @@ -1,100 +0,0 @@ - t("Welcome to Gallery 3!"), - "photo_stream" => t("Photo Stream"), - "log_entries" => t("Log Entries"), - "stats" => t("Gallery Stats"), - "platform_info" => t("Platform Information"), - "project_news" => t("Gallery Project News")); - } - - static function get($block_id) { - $block = new Block(); - switch($block_id) { - case "welcome": - $block->css_id = "gWelcome"; - $block->title = t("Welcome to Gallery3"); - $block->content = new View("admin_block_welcome.html"); - break; - - case "photo_stream": - $block->css_id = "gPhotoStream"; - $block->title = t("Photo Stream"); - $block->content = new View("admin_block_photo_stream.html"); - $block->content->photos = - ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10); - break; - - case "log_entries": - $block->css_id = "gLogEntries"; - $block->title = t("Log Entries"); - $block->content = new View("admin_block_log_entries.html"); - $block->content->entries = ORM::factory("log")->orderby("timestamp", "DESC")->find_all(5); - break; - - case "stats": - $block->css_id = "gStats"; - $block->title = t("Gallery Stats"); - $block->content = new View("admin_block_stats.html"); - $block->content->album_count = ORM::factory("item")->where("type", "album")->count_all(); - $block->content->photo_count = ORM::factory("item")->where("type", "photo")->count_all(); - break; - - case "platform_info": - $block->css_id = "gPlatform"; - $block->title = t("Platform Information"); - $block->content = new View("admin_block_platform.html"); - if (is_readable("/proc/loadavg")) { - $block->content->load_average = - join(" ", array_slice(split(" ", array_shift(file("/proc/loadavg"))), 0, 3)); - } else { - $block->content->load_average = t("Unavailable"); - } - break; - - case "project_news": - $block->css_id = "gProjectNews"; - $block->title = t("Gallery Project News"); - $block->content = new View("admin_block_news.html"); - $block->content->feed = feed::parse("http://gallery.menalto.com/node/feed", 3); - break; - - case "block_adder": - $block->css_id = "gBlockAdder"; - $block->title = t("Dashboard Content"); - $block->content = self::get_add_block_form(); - } - - return $block; - } - - static function get_add_block_form() { - $form = new Forge("admin/dashboard/add_block", "", "post", - array("id" => "gAddDashboardBlockForm")); - $group = $form->group("add_block")->label(t("Add Block")); - $group->dropdown("id")->label("Available Blocks")->options(block_manager::get_available()); - $group->submit("center")->value(t("Add to center")); - $group->submit("sidebar")->value(t("Add to sidebar")); - return $form; - } -} \ No newline at end of file diff --git a/modules/gallery/helpers/core_event.php b/modules/gallery/helpers/core_event.php deleted file mode 100644 index bbb53cc9..00000000 --- a/modules/gallery/helpers/core_event.php +++ /dev/null @@ -1,46 +0,0 @@ -admin && module::get_var("core", "choose_default_tookit", null)) { - graphics::choose_default_toolkit(); - module::clear_var("core", "choose_default_tookit"); - } - } -} diff --git a/modules/gallery/helpers/core_installer.php b/modules/gallery/helpers/core_installer.php deleted file mode 100644 index cffcbedb..00000000 --- a/modules/gallery/helpers/core_installer.php +++ /dev/null @@ -1,278 +0,0 @@ -query("CREATE TABLE {access_caches} ( - `id` int(9) NOT NULL auto_increment, - `item_id` int(9), - PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {access_intents} ( - `id` int(9) NOT NULL auto_increment, - `item_id` int(9), - PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {graphics_rules} ( - `id` int(9) NOT NULL auto_increment, - `active` BOOLEAN default 0, - `args` varchar(255) default NULL, - `module_name` varchar(64) NOT NULL, - `operation` varchar(64) NOT NULL, - `priority` int(9) NOT NULL, - `target` varchar(32) NOT NULL, - PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {items} ( - `id` int(9) NOT NULL auto_increment, - `album_cover_item_id` int(9) default NULL, - `captured` int(9) default NULL, - `created` int(9) default NULL, - `description` varchar(2048) default NULL, - `height` int(9) default NULL, - `left` int(9) NOT NULL, - `level` int(9) NOT NULL, - `mime_type` varchar(64) default NULL, - `name` varchar(255) default NULL, - `owner_id` int(9) default NULL, - `parent_id` int(9) NOT NULL, - `rand_key` float default NULL, - `relative_path_cache` varchar(255) default NULL, - `resize_dirty` boolean default 1, - `resize_height` int(9) default NULL, - `resize_width` int(9) default NULL, - `right` int(9) NOT NULL, - `sort_column` varchar(64) default NULL, - `sort_order` char(4) default 'ASC', - `thumb_dirty` boolean default 1, - `thumb_height` int(9) default NULL, - `thumb_width` int(9) default NULL, - `title` varchar(255) default NULL, - `type` varchar(32) NOT NULL, - `updated` int(9) default NULL, - `view_count` int(9) default 0, - `weight` int(9) NOT NULL default 0, - `width` int(9) default NULL, - PRIMARY KEY (`id`), - KEY `parent_id` (`parent_id`), - KEY `type` (`type`), - KEY `random` (`rand_key`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {logs} ( - `id` int(9) NOT NULL auto_increment, - `category` varchar(64) default NULL, - `html` varchar(255) default NULL, - `message` text default NULL, - `referer` varchar(255) default NULL, - `severity` int(9) default 0, - `timestamp` int(9) default 0, - `url` varchar(255) default NULL, - `user_id` int(9) default 0, - PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {messages} ( - `id` int(9) NOT NULL auto_increment, - `key` varchar(255) default NULL, - `severity` varchar(32) default NULL, - `value` varchar(255) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY(`key`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {modules} ( - `id` int(9) NOT NULL auto_increment, - `active` BOOLEAN default 0, - `name` varchar(64) default NULL, - `version` int(9) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {themes} ( - `id` int(9) NOT NULL auto_increment, - `name` varchar(64) default NULL, - `version` int(9) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {permissions} ( - `id` int(9) NOT NULL auto_increment, - `display_name` varchar(64) default NULL, - `name` varchar(64) default NULL, - PRIMARY KEY (`id`), - UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {incoming_translations} ( - `id` int(9) NOT NULL auto_increment, - `key` char(32) NOT NULL, - `locale` char(10) NOT NULL, - `message` text NOT NULL, - `revision` int(9) DEFAULT NULL, - `translation` text, - PRIMARY KEY (`id`), - UNIQUE KEY(`key`, `locale`), - KEY `locale_key` (`locale`, `key`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {outgoing_translations} ( - `id` int(9) NOT NULL auto_increment, - `base_revision` int(9) DEFAULT NULL, - `key` char(32) NOT NULL, - `locale` char(10) NOT NULL, - `message` text NOT NULL, - `translation` text, - PRIMARY KEY (`id`), - UNIQUE KEY(`key`, `locale`), - KEY `locale_key` (`locale`, `key`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {sessions} ( - `session_id` varchar(127) NOT NULL, - `data` text NOT NULL, - `last_activity` int(10) UNSIGNED NOT NULL, - PRIMARY KEY (`session_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {tasks} ( - `id` int(9) NOT NULL auto_increment, - `callback` varchar(128) default NULL, - `context` text NOT NULL, - `done` boolean default 0, - `name` varchar(128) default NULL, - `owner_id` int(9) default NULL, - `percent_complete` int(9) default 0, - `state` varchar(32) default NULL, - `status` varchar(255) default NULL, - `updated` int(9) default NULL, - PRIMARY KEY (`id`), - KEY (`owner_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - $db->query("CREATE TABLE {vars} ( - `id` int(9) NOT NULL auto_increment, - `module_name` varchar(64) NOT NULL, - `name` varchar(64) NOT NULL, - `value` text, - PRIMARY KEY (`id`), - UNIQUE KEY(`module_name`, `name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); - - foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) { - @mkdir(VARPATH . $dir); - } - - access::register_permission("view", "View"); - access::register_permission("view_full", "View Full Size"); - access::register_permission("edit", "Edit"); - access::register_permission("add", "Add"); - - $root = ORM::factory("item"); - $root->type = "album"; - $root->title = "Gallery"; - $root->description = ""; - $root->left = 1; - $root->right = 2; - $root->parent_id = 0; - $root->level = 1; - $root->thumb_dirty = 1; - $root->resize_dirty = 1; - $root->sort_column = "weight"; - $root->sort_order = "ASC"; - $root->save(); - access::add_item($root); - - module::set_var("core", "active_site_theme", "default"); - module::set_var("core", "active_admin_theme", "admin_default"); - module::set_var("core", "page_size", 9); - module::set_var("core", "thumb_size", 200); - module::set_var("core", "resize_size", 640); - module::set_var("core", "default_locale", "en_US"); - module::set_var("core", "image_quality", 75); - - // Add rules for generating our thumbnails and resizes - graphics::add_rule( - "core", "thumb", "resize", - array("width" => 200, "height" => 200, "master" => Image::AUTO), - 100); - graphics::add_rule( - "core", "resize", "resize", - array("width" => 640, "height" => 480, "master" => Image::AUTO), - 100); - - // Instantiate default themes (site and admin) - foreach (array("default", "admin_default") as $theme_name) { - $theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"), - ArrayObject::ARRAY_AS_PROPS); - $theme = ORM::factory("theme"); - $theme->name = $theme_name; - $theme->version = $theme_info->version; - $theme->save(); - } - - block_manager::add("dashboard_sidebar", "core", "block_adder"); - block_manager::add("dashboard_sidebar", "core", "stats"); - block_manager::add("dashboard_sidebar", "core", "platform_info"); - block_manager::add("dashboard_sidebar", "core", "project_news"); - block_manager::add("dashboard_center", "core", "welcome"); - block_manager::add("dashboard_center", "core", "photo_stream"); - block_manager::add("dashboard_center", "core", "log_entries"); - - module::set_version("core", 1); - module::set_var("core", "version", "3.0 pre-beta svn"); - module::set_var("core", "choose_default_tookit", 1); - } - } - - static function uninstall() { - $db = Database::instance(); - $db->query("DROP TABLE IF EXISTS {access_caches}"); - $db->query("DROP TABLE IF EXISTS {access_intents}"); - $db->query("DROP TABLE IF EXISTS {graphics_rules}"); - $db->query("DROP TABLE IF EXISTS {items}"); - $db->query("DROP TABLE IF EXISTS {logs}"); - $db->query("DROP TABLE IF EXISTS {messages}"); - $db->query("DROP TABLE IF EXISTS {modules}"); - $db->query("DROP TABLE IF EXISTS {themes}"); - $db->query("DROP TABLE IF EXISTS {incoming_translations}"); - $db->query("DROP TABLE IF EXISTS {outgoing_translations}"); - $db->query("DROP TABLE IF EXISTS {permissions}"); - $db->query("DROP TABLE IF EXISTS {sessions}"); - $db->query("DROP TABLE IF EXISTS {tasks}"); - $db->query("DROP TABLE IF EXISTS {vars}"); - foreach (array("albums", "resizes", "thumbs", "uploads", - "modules", "logs", "database.php") as $entry) { - system("/bin/rm -rf " . VARPATH . $entry); - } - } -} diff --git a/modules/gallery/helpers/core_menu.php b/modules/gallery/helpers/core_menu.php deleted file mode 100644 index eb208560..00000000 --- a/modules/gallery/helpers/core_menu.php +++ /dev/null @@ -1,162 +0,0 @@ -admin) { - $menu->append($scaffold_menu = Menu::factory("submenu") - ->id("scaffold") - ->label("Scaffold")); - $scaffold_menu->append(Menu::factory("link") - ->id("scaffold_home") - ->label("Dashboard") - ->url(url::site("scaffold"))); - } - - $menu->append(Menu::factory("link") - ->id("home") - ->label(t("Home")) - ->url(url::site("albums/1"))); - - $item = $theme->item(); - - if (user::active()->admin || ($item && access::can("edit", $item))) { - $menu->append($options_menu = Menu::factory("submenu") - ->id("options_menu") - ->label(t("Options"))); - - if ($item && access::can("edit", $item)) { - $options_menu - ->append(Menu::factory("dialog") - ->id("edit_item") - ->label($item->is_album() ? t("Edit album") : t("Edit photo")) - ->url(url::site("form/edit/{$item->type}s/$item->id"))); - - // @todo Move album options menu to the album quick edit pane - // @todo Create resized item quick edit pane menu - if ($item->is_album()) { - $options_menu - ->append(Menu::factory("dialog") - ->id("add_item") - ->label(t("Add a photo")) - ->url(url::site("simple_uploader/app/$item->id"))) - ->append(Menu::factory("dialog") - ->id("add_album") - ->label(t("Add an album")) - ->url(url::site("form/add/albums/$item->id?type=album"))) - ->append(Menu::factory("dialog") - ->id("edit_permissions") - ->label(t("Edit permissions")) - ->url(url::site("permissions/browse/$item->id"))); - } - } - } - - if (user::active()->admin) { - $menu->append($admin_menu = Menu::factory("submenu") - ->id("admin_menu") - ->label(t("Admin"))); - self::admin($admin_menu, $theme); - foreach (module::active() as $module) { - if ($module->name == "core") { - continue; - } - $class = "{$module->name}_menu"; - if (method_exists($class, "admin")) { - call_user_func_array(array($class, "admin"), array(&$admin_menu, $theme)); - } - } - } - } - - static function album($menu, $theme) { - } - - static function photo($menu, $theme) { - if (access::can("view_full", $theme->item())) { - $menu - ->append(Menu::factory("link") - ->id("fullsize") - ->label(t("View full size")) - ->url("#") - ->css_class("gFullSizeLink")); - } - $menu - ->append(Menu::factory("link") - ->id("album") - ->label(t("Return to album")) - ->url($theme->item()->parent()->url("show={$theme->item->id}")) - ->css_id("gAlbumLink")); - } - - static function admin($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("dashboard") - ->label(t("Dashboard")) - ->url(url::site("admin"))) - ->append(Menu::factory("submenu") - ->id("settings_menu") - ->label(t("Settings")) - ->append(Menu::factory("link") - ->id("graphics_toolkits") - ->label(t("Graphics")) - ->url(url::site("admin/graphics"))) - ->append(Menu::factory("link") - ->id("languages") - ->label(t("Languages")) - ->url(url::site("admin/languages"))) - ->append(Menu::factory("link") - ->id("l10n_mode") - ->label(Session::instance()->get("l10n_mode", false) - ? t("Stop translating") : t("Start translating")) - ->url(url::site("l10n_client/toggle_l10n_mode?csrf=" . - access::csrf_token()))) - ->append(Menu::factory("link") - ->id("advanced") - ->label("Advanced") - ->url(url::site("admin/advanced_settings")))) - ->append(Menu::factory("link") - ->id("modules") - ->label(t("Modules")) - ->url(url::site("admin/modules"))) - ->append(Menu::factory("submenu") - ->id("content_menu") - ->label(t("Content"))) - ->append(Menu::factory("submenu") - ->id("appearance_menu") - ->label(t("Appearance")) - ->append(Menu::factory("link") - ->id("themes") - ->label(t("Theme Choice")) - ->url(url::site("admin/themes"))) - ->append(Menu::factory("link") - ->id("theme_details") - ->label(t("Theme Options")) - ->url(url::site("admin/theme_details")))) - ->append(Menu::factory("link") - ->id("maintenance") - ->label(t("Maintenance")) - ->url(url::site("admin/maintenance"))) - ->append(Menu::factory("submenu") - ->id("statistics_menu") - ->label(t("Statistics")) - ->url("#")); - } -} diff --git a/modules/gallery/helpers/core_search.php b/modules/gallery/helpers/core_search.php deleted file mode 100644 index 9957a493..00000000 --- a/modules/gallery/helpers/core_search.php +++ /dev/null @@ -1,24 +0,0 @@ -description, $item->name, $item->title)); - } -} diff --git a/modules/gallery/helpers/core_task.php b/modules/gallery/helpers/core_task.php deleted file mode 100644 index e078192c..00000000 --- a/modules/gallery/helpers/core_task.php +++ /dev/null @@ -1,166 +0,0 @@ -count(); - $tasks = array(); - $tasks[] = Task_Definition::factory() - ->callback("core_task::rebuild_dirty_images") - ->name(t("Rebuild Images")) - ->description($dirty_count ? - t2("You have one out of date photo", - "You have %count out of date photos", - $dirty_count) - : t("All your photos are up to date")) - ->severity($dirty_count ? log::WARNING : log::SUCCESS); - - $tasks[] = Task_Definition::factory() - ->callback("core_task::update_l10n") - ->name(t("Update translations")) - ->description(t("Download new and updated translated strings")) - ->severity(log::SUCCESS); - - return $tasks; - } - - /** - * Task that rebuilds all dirty images. - * @param Task_Model the task - */ - static function rebuild_dirty_images($task) { - $result = graphics::find_dirty_images_query(); - $remaining = $result->count(); - $completed = $task->get("completed", 0); - - $i = 0; - foreach ($result as $row) { - $item = ORM::factory("item", $row->id); - if ($item->loaded) { - graphics::generate($item); - } - - $completed++; - $remaining--; - - if (++$i == 2) { - break; - } - } - - $task->status = t2("Updated: 1 image. Total: %total_count.", - "Updated: %count images. Total: %total_count.", - $completed, - array("total_count" => ($remaining + $completed))); - - if ($completed + $remaining > 0) { - $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); - } else { - $task->percent_complete = 100; - } - - $task->set("completed", $completed); - if ($remaining == 0) { - $task->done = true; - $task->state = "success"; - site_status::clear("graphics_dirty"); - } - } - - static function update_l10n(&$task) { - $start = microtime(true); - $dirs = $task->get("dirs"); - $files = $task->get("files"); - $cache = $task->get("cache", array()); - $i = 0; - - switch ($task->get("mode", "init")) { - case "init": // 0% - $dirs = array("core", "modules", "themes", "installer"); - $files = array(); - $task->set("mode", "find_files"); - $task->status = t("Finding files"); - break; - - case "find_files": // 0% - 10% - while (($dir = array_pop($dirs)) && microtime(true) - $start < 0.5) { - if (basename($dir) == "tests") { - continue; - } - - foreach (glob(DOCROOT . "$dir/*") as $path) { - $relative_path = str_replace(DOCROOT, "", $path); - if (is_dir($path)) { - $dirs[] = $relative_path; - } else { - $files[] = $relative_path; - } - } - } - - $task->status = t2("Finding files: found 1 file", - "Finding files: found %count files", count($files)); - - if (!$dirs) { - $task->set("mode", "scan_files"); - $task->set("total_files", count($files)); - $task->status = t("Scanning files"); - $task->percent_complete = 10; - } - break; - - case "scan_files": // 10% - 90% - while (($file = array_pop($files)) && microtime(true) - $start < 0.5) { - $file = DOCROOT . $file; - switch (pathinfo($file, PATHINFO_EXTENSION)) { - case "php": - l10n_scanner::scan_php_file($file, $cache); - break; - - case "info": - l10n_scanner::scan_info_file($file, $cache); - break; - } - } - - $total_files = $task->get("total_files"); - $task->status = t2("Scanning files: scanned 1 file", - "Scanning files: scanned %count files", $total_files - count($files)); - - $task->percent_complete = 10 + 80 * ($total_files - count($files)) / $total_files; - if (empty($files)) { - $task->set("mode", "fetch_updates"); - $task->status = t("Fetching updates"); - $task->percent_complete = 90; - } - break; - - case "fetch_updates": // 90% - 100% - l10n_client::fetch_updates(); - $task->done = true; - $task->state = "success"; - $task->status = t("Translations installed/updated"); - $task->percent_complete = 100; - } - - $task->set("files", $files); - $task->set("dirs", $dirs); - $task->set("cache", $cache); - } -} \ No newline at end of file diff --git a/modules/gallery/helpers/core_theme.php b/modules/gallery/helpers/core_theme.php deleted file mode 100644 index 28f544a1..00000000 --- a/modules/gallery/helpers/core_theme.php +++ /dev/null @@ -1,137 +0,0 @@ -get("debug")) { - $buf .= ""; - } - if (($theme->page_type == "album" || $theme->page_type == "photo") - && access::can("edit", $theme->item())) { - $buf .= ""; - $buf .= html::script("core/js/quick.js"); - } - if ($theme->page_type == "photo" && access::can("view_full", $theme->item())) { - $buf .= ""; - $buf .= html::script("core/js/fullsize.js"); - } - - if ($session->get("l10n_mode", false)) { - $buf .= ""; - $buf .= html::script("lib/jquery.cookie.js"); - $buf .= html::script("core/js/l10n_client.js"); - } - - return $buf; - } - - static function resize_top($theme, $item) { - if (access::can("edit", $item)) { - $edit_link = url::site("quick/pane/$item->id?page_type=photo"); - return "
"; - } - } - - static function resize_bottom($theme, $item) { - if (access::can("edit", $item)) { - return "
"; - } - } - - static function thumb_top($theme, $child) { - if (access::can("edit", $child)) { - $edit_link = url::site("quick/pane/$child->id?page_type=album"); - return "
"; - } - } - - static function thumb_bottom($theme, $child) { - if (access::can("edit", $child)) { - return "
"; - } - } - - static function admin_head($theme) { - $session = Session::instance(); - $buf = ""; - if ($session->get("debug")) { - $buf .= ""; - } - - if ($session->get("l10n_mode", false)) { - $buf .= ""; - $buf .= html::script("lib/jquery.cookie.js"); - $buf .= html::script("core/js/l10n_client.js"); - } - - return $buf; - } - - static function page_bottom($theme) { - $session = Session::instance(); - if ($session->get("profiler", false)) { - $profiler = new Profiler(); - $profiler->render(); - } - if ($session->get("l10n_mode", false)) { - return L10n_Client_Controller::l10n_form(); - } - - if ($session->get("after_install")) { - $session->delete("after_install"); - return new View("after_install_loader.html"); - } - } - - static function admin_page_bottom($theme) { - $session = Session::instance(); - if ($session->get("profiler", false)) { - $profiler = new Profiler(); - $profiler->render(); - } - if ($session->get("l10n_mode", false)) { - return L10n_Client_Controller::l10n_form(); - } - } - - static function credits() { - return "
  • " . - t("Powered by Gallery %version", - array("url" => "http://gallery.menalto.com", - "version" => module::get_var("core", "version"))) . - "
  • "; - } - - static function admin_credits() { - return core_theme::credits(); - } -} \ No newline at end of file diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php new file mode 100644 index 00000000..bf33fa2b --- /dev/null +++ b/modules/gallery/helpers/gallery.php @@ -0,0 +1,52 @@ +admin) { + Router::$controller = "maintenance"; + Router::$controller_path = APPPATH . "controllers/maintenance.php"; + Router::$method = "index"; + } + } + + /** + * This function is called when the Gallery is fully initialized. We relay it to modules as the + * "gallery_ready" event. Any module that wants to perform an action at the start of every + * request should implement the _event::gallery_ready() handler. + */ + static function ready() { + module::event("gallery_ready"); + } + + /** + * This function is called right before the Kohana framework shuts down. We relay it to modules + * as the "gallery_shutdown" event. Any module that wants to perform an action at the start of + * every request should implement the _event::gallery_shutdown() handler. + */ + static function shutdown() { + module::event("gallery_shutdown"); + } +} \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php new file mode 100644 index 00000000..abc8a195 --- /dev/null +++ b/modules/gallery/helpers/gallery_block.php @@ -0,0 +1,100 @@ + t("Welcome to Gallery 3!"), + "photo_stream" => t("Photo Stream"), + "log_entries" => t("Log Entries"), + "stats" => t("Gallery Stats"), + "platform_info" => t("Platform Information"), + "project_news" => t("Gallery Project News")); + } + + static function get($block_id) { + $block = new Block(); + switch($block_id) { + case "welcome": + $block->css_id = "gWelcome"; + $block->title = t("Welcome to Gallery3"); + $block->content = new View("admin_block_welcome.html"); + break; + + case "photo_stream": + $block->css_id = "gPhotoStream"; + $block->title = t("Photo Stream"); + $block->content = new View("admin_block_photo_stream.html"); + $block->content->photos = + ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10); + break; + + case "log_entries": + $block->css_id = "gLogEntries"; + $block->title = t("Log Entries"); + $block->content = new View("admin_block_log_entries.html"); + $block->content->entries = ORM::factory("log")->orderby("timestamp", "DESC")->find_all(5); + break; + + case "stats": + $block->css_id = "gStats"; + $block->title = t("Gallery Stats"); + $block->content = new View("admin_block_stats.html"); + $block->content->album_count = ORM::factory("item")->where("type", "album")->count_all(); + $block->content->photo_count = ORM::factory("item")->where("type", "photo")->count_all(); + break; + + case "platform_info": + $block->css_id = "gPlatform"; + $block->title = t("Platform Information"); + $block->content = new View("admin_block_platform.html"); + if (is_readable("/proc/loadavg")) { + $block->content->load_average = + join(" ", array_slice(split(" ", array_shift(file("/proc/loadavg"))), 0, 3)); + } else { + $block->content->load_average = t("Unavailable"); + } + break; + + case "project_news": + $block->css_id = "gProjectNews"; + $block->title = t("Gallery Project News"); + $block->content = new View("admin_block_news.html"); + $block->content->feed = feed::parse("http://gallery.menalto.com/node/feed", 3); + break; + + case "block_adder": + $block->css_id = "gBlockAdder"; + $block->title = t("Dashboard Content"); + $block->content = self::get_add_block_form(); + } + + return $block; + } + + static function get_add_block_form() { + $form = new Forge("admin/dashboard/add_block", "", "post", + array("id" => "gAddDashboardBlockForm")); + $group = $form->group("add_block")->label(t("Add Block")); + $group->dropdown("id")->label("Available Blocks")->options(block_manager::get_available()); + $group->submit("center")->value(t("Add to center")); + $group->submit("sidebar")->value(t("Add to sidebar")); + return $form; + } +} \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php new file mode 100644 index 00000000..aa11b7c0 --- /dev/null +++ b/modules/gallery/helpers/gallery_event.php @@ -0,0 +1,46 @@ +admin && module::get_var("gallery", "choose_default_tookit", null)) { + graphics::choose_default_toolkit(); + module::clear_var("gallery", "choose_default_tookit"); + } + } +} diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php new file mode 100644 index 00000000..e3aa403f --- /dev/null +++ b/modules/gallery/helpers/gallery_installer.php @@ -0,0 +1,278 @@ +query("CREATE TABLE {access_caches} ( + `id` int(9) NOT NULL auto_increment, + `item_id` int(9), + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {access_intents} ( + `id` int(9) NOT NULL auto_increment, + `item_id` int(9), + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {graphics_rules} ( + `id` int(9) NOT NULL auto_increment, + `active` BOOLEAN default 0, + `args` varchar(255) default NULL, + `module_name` varchar(64) NOT NULL, + `operation` varchar(64) NOT NULL, + `priority` int(9) NOT NULL, + `target` varchar(32) NOT NULL, + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {items} ( + `id` int(9) NOT NULL auto_increment, + `album_cover_item_id` int(9) default NULL, + `captured` int(9) default NULL, + `created` int(9) default NULL, + `description` varchar(2048) default NULL, + `height` int(9) default NULL, + `left` int(9) NOT NULL, + `level` int(9) NOT NULL, + `mime_type` varchar(64) default NULL, + `name` varchar(255) default NULL, + `owner_id` int(9) default NULL, + `parent_id` int(9) NOT NULL, + `rand_key` float default NULL, + `relative_path_cache` varchar(255) default NULL, + `resize_dirty` boolean default 1, + `resize_height` int(9) default NULL, + `resize_width` int(9) default NULL, + `right` int(9) NOT NULL, + `sort_column` varchar(64) default NULL, + `sort_order` char(4) default 'ASC', + `thumb_dirty` boolean default 1, + `thumb_height` int(9) default NULL, + `thumb_width` int(9) default NULL, + `title` varchar(255) default NULL, + `type` varchar(32) NOT NULL, + `updated` int(9) default NULL, + `view_count` int(9) default 0, + `weight` int(9) NOT NULL default 0, + `width` int(9) default NULL, + PRIMARY KEY (`id`), + KEY `parent_id` (`parent_id`), + KEY `type` (`type`), + KEY `random` (`rand_key`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {logs} ( + `id` int(9) NOT NULL auto_increment, + `category` varchar(64) default NULL, + `html` varchar(255) default NULL, + `message` text default NULL, + `referer` varchar(255) default NULL, + `severity` int(9) default 0, + `timestamp` int(9) default 0, + `url` varchar(255) default NULL, + `user_id` int(9) default 0, + PRIMARY KEY (`id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {messages} ( + `id` int(9) NOT NULL auto_increment, + `key` varchar(255) default NULL, + `severity` varchar(32) default NULL, + `value` varchar(255) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`key`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {modules} ( + `id` int(9) NOT NULL auto_increment, + `active` BOOLEAN default 0, + `name` varchar(64) default NULL, + `version` int(9) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`name`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {themes} ( + `id` int(9) NOT NULL auto_increment, + `name` varchar(64) default NULL, + `version` int(9) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`name`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {permissions} ( + `id` int(9) NOT NULL auto_increment, + `display_name` varchar(64) default NULL, + `name` varchar(64) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`name`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {incoming_translations} ( + `id` int(9) NOT NULL auto_increment, + `key` char(32) NOT NULL, + `locale` char(10) NOT NULL, + `message` text NOT NULL, + `revision` int(9) DEFAULT NULL, + `translation` text, + PRIMARY KEY (`id`), + UNIQUE KEY(`key`, `locale`), + KEY `locale_key` (`locale`, `key`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {outgoing_translations} ( + `id` int(9) NOT NULL auto_increment, + `base_revision` int(9) DEFAULT NULL, + `key` char(32) NOT NULL, + `locale` char(10) NOT NULL, + `message` text NOT NULL, + `translation` text, + PRIMARY KEY (`id`), + UNIQUE KEY(`key`, `locale`), + KEY `locale_key` (`locale`, `key`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {sessions} ( + `session_id` varchar(127) NOT NULL, + `data` text NOT NULL, + `last_activity` int(10) UNSIGNED NOT NULL, + PRIMARY KEY (`session_id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {tasks} ( + `id` int(9) NOT NULL auto_increment, + `callback` varchar(128) default NULL, + `context` text NOT NULL, + `done` boolean default 0, + `name` varchar(128) default NULL, + `owner_id` int(9) default NULL, + `percent_complete` int(9) default 0, + `state` varchar(32) default NULL, + `status` varchar(255) default NULL, + `updated` int(9) default NULL, + PRIMARY KEY (`id`), + KEY (`owner_id`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + $db->query("CREATE TABLE {vars} ( + `id` int(9) NOT NULL auto_increment, + `module_name` varchar(64) NOT NULL, + `name` varchar(64) NOT NULL, + `value` text, + PRIMARY KEY (`id`), + UNIQUE KEY(`module_name`, `name`)) + ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + + foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) { + @mkdir(VARPATH . $dir); + } + + access::register_permission("view", "View"); + access::register_permission("view_full", "View Full Size"); + access::register_permission("edit", "Edit"); + access::register_permission("add", "Add"); + + $root = ORM::factory("item"); + $root->type = "album"; + $root->title = "Gallery"; + $root->description = ""; + $root->left = 1; + $root->right = 2; + $root->parent_id = 0; + $root->level = 1; + $root->thumb_dirty = 1; + $root->resize_dirty = 1; + $root->sort_column = "weight"; + $root->sort_order = "ASC"; + $root->save(); + access::add_item($root); + + module::set_var("gallery", "active_site_theme", "default"); + module::set_var("gallery", "active_admin_theme", "admin_default"); + module::set_var("gallery", "page_size", 9); + module::set_var("gallery", "thumb_size", 200); + module::set_var("gallery", "resize_size", 640); + module::set_var("gallery", "default_locale", "en_US"); + module::set_var("gallery", "image_quality", 75); + + // Add rules for generating our thumbnails and resizes + graphics::add_rule( + "gallery", "thumb", "resize", + array("width" => 200, "height" => 200, "master" => Image::AUTO), + 100); + graphics::add_rule( + "gallery", "resize", "resize", + array("width" => 640, "height" => 480, "master" => Image::AUTO), + 100); + + // Instantiate default themes (site and admin) + foreach (array("default", "admin_default") as $theme_name) { + $theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"), + ArrayObject::ARRAY_AS_PROPS); + $theme = ORM::factory("theme"); + $theme->name = $theme_name; + $theme->version = $theme_info->version; + $theme->save(); + } + + block_manager::add("dashboard_sidebar", "gallery", "block_adder"); + block_manager::add("dashboard_sidebar", "gallery", "stats"); + block_manager::add("dashboard_sidebar", "gallery", "platform_info"); + block_manager::add("dashboard_sidebar", "gallery", "project_news"); + block_manager::add("dashboard_center", "gallery", "welcome"); + block_manager::add("dashboard_center", "gallery", "photo_stream"); + block_manager::add("dashboard_center", "gallery", "log_entries"); + + module::set_version("gallery", 1); + module::set_var("gallery", "version", "3.0 pre-beta git"); + module::set_var("gallery", "choose_default_tookit", 1); + } + } + + static function uninstall() { + $db = Database::instance(); + $db->query("DROP TABLE IF EXISTS {access_caches}"); + $db->query("DROP TABLE IF EXISTS {access_intents}"); + $db->query("DROP TABLE IF EXISTS {graphics_rules}"); + $db->query("DROP TABLE IF EXISTS {items}"); + $db->query("DROP TABLE IF EXISTS {logs}"); + $db->query("DROP TABLE IF EXISTS {messages}"); + $db->query("DROP TABLE IF EXISTS {modules}"); + $db->query("DROP TABLE IF EXISTS {themes}"); + $db->query("DROP TABLE IF EXISTS {incoming_translations}"); + $db->query("DROP TABLE IF EXISTS {outgoing_translations}"); + $db->query("DROP TABLE IF EXISTS {permissions}"); + $db->query("DROP TABLE IF EXISTS {sessions}"); + $db->query("DROP TABLE IF EXISTS {tasks}"); + $db->query("DROP TABLE IF EXISTS {vars}"); + foreach (array("albums", "resizes", "thumbs", "uploads", + "modules", "logs", "database.php") as $entry) { + system("/bin/rm -rf " . VARPATH . $entry); + } + } +} diff --git a/modules/gallery/helpers/gallery_menu.php b/modules/gallery/helpers/gallery_menu.php new file mode 100644 index 00000000..215fc420 --- /dev/null +++ b/modules/gallery/helpers/gallery_menu.php @@ -0,0 +1,162 @@ +admin) { + $menu->append($scaffold_menu = Menu::factory("submenu") + ->id("scaffold") + ->label("Scaffold")); + $scaffold_menu->append(Menu::factory("link") + ->id("scaffold_home") + ->label("Dashboard") + ->url(url::site("scaffold"))); + } + + $menu->append(Menu::factory("link") + ->id("home") + ->label(t("Home")) + ->url(url::site("albums/1"))); + + $item = $theme->item(); + + if (user::active()->admin || ($item && access::can("edit", $item))) { + $menu->append($options_menu = Menu::factory("submenu") + ->id("options_menu") + ->label(t("Options"))); + + if ($item && access::can("edit", $item)) { + $options_menu + ->append(Menu::factory("dialog") + ->id("edit_item") + ->label($item->is_album() ? t("Edit album") : t("Edit photo")) + ->url(url::site("form/edit/{$item->type}s/$item->id"))); + + // @todo Move album options menu to the album quick edit pane + // @todo Create resized item quick edit pane menu + if ($item->is_album()) { + $options_menu + ->append(Menu::factory("dialog") + ->id("add_item") + ->label(t("Add a photo")) + ->url(url::site("simple_uploader/app/$item->id"))) + ->append(Menu::factory("dialog") + ->id("add_album") + ->label(t("Add an album")) + ->url(url::site("form/add/albums/$item->id?type=album"))) + ->append(Menu::factory("dialog") + ->id("edit_permissions") + ->label(t("Edit permissions")) + ->url(url::site("permissions/browse/$item->id"))); + } + } + } + + if (user::active()->admin) { + $menu->append($admin_menu = Menu::factory("submenu") + ->id("admin_menu") + ->label(t("Admin"))); + self::admin($admin_menu, $theme); + foreach (module::active() as $module) { + if ($module->name == "gallery") { + continue; + } + $class = "{$module->name}_menu"; + if (method_exists($class, "admin")) { + call_user_func_array(array($class, "admin"), array(&$admin_menu, $theme)); + } + } + } + } + + static function album($menu, $theme) { + } + + static function photo($menu, $theme) { + if (access::can("view_full", $theme->item())) { + $menu + ->append(Menu::factory("link") + ->id("fullsize") + ->label(t("View full size")) + ->url("#") + ->css_class("gFullSizeLink")); + } + $menu + ->append(Menu::factory("link") + ->id("album") + ->label(t("Return to album")) + ->url($theme->item()->parent()->url("show={$theme->item->id}")) + ->css_id("gAlbumLink")); + } + + static function admin($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("dashboard") + ->label(t("Dashboard")) + ->url(url::site("admin"))) + ->append(Menu::factory("submenu") + ->id("settings_menu") + ->label(t("Settings")) + ->append(Menu::factory("link") + ->id("graphics_toolkits") + ->label(t("Graphics")) + ->url(url::site("admin/graphics"))) + ->append(Menu::factory("link") + ->id("languages") + ->label(t("Languages")) + ->url(url::site("admin/languages"))) + ->append(Menu::factory("link") + ->id("l10n_mode") + ->label(Session::instance()->get("l10n_mode", false) + ? t("Stop translating") : t("Start translating")) + ->url(url::site("l10n_client/toggle_l10n_mode?csrf=" . + access::csrf_token()))) + ->append(Menu::factory("link") + ->id("advanced") + ->label("Advanced") + ->url(url::site("admin/advanced_settings")))) + ->append(Menu::factory("link") + ->id("modules") + ->label(t("Modules")) + ->url(url::site("admin/modules"))) + ->append(Menu::factory("submenu") + ->id("content_menu") + ->label(t("Content"))) + ->append(Menu::factory("submenu") + ->id("appearance_menu") + ->label(t("Appearance")) + ->append(Menu::factory("link") + ->id("themes") + ->label(t("Theme Choice")) + ->url(url::site("admin/themes"))) + ->append(Menu::factory("link") + ->id("theme_details") + ->label(t("Theme Options")) + ->url(url::site("admin/theme_details")))) + ->append(Menu::factory("link") + ->id("maintenance") + ->label(t("Maintenance")) + ->url(url::site("admin/maintenance"))) + ->append(Menu::factory("submenu") + ->id("statistics_menu") + ->label(t("Statistics")) + ->url("#")); + } +} diff --git a/modules/gallery/helpers/gallery_search.php b/modules/gallery/helpers/gallery_search.php new file mode 100644 index 00000000..2a4029d3 --- /dev/null +++ b/modules/gallery/helpers/gallery_search.php @@ -0,0 +1,24 @@ +description, $item->name, $item->title)); + } +} diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php new file mode 100644 index 00000000..6046bfc4 --- /dev/null +++ b/modules/gallery/helpers/gallery_task.php @@ -0,0 +1,166 @@ +count(); + $tasks = array(); + $tasks[] = Task_Definition::factory() + ->callback("gallery_task::rebuild_dirty_images") + ->name(t("Rebuild Images")) + ->description($dirty_count ? + t2("You have one out of date photo", + "You have %count out of date photos", + $dirty_count) + : t("All your photos are up to date")) + ->severity($dirty_count ? log::WARNING : log::SUCCESS); + + $tasks[] = Task_Definition::factory() + ->callback("gallery_task::update_l10n") + ->name(t("Update translations")) + ->description(t("Download new and updated translated strings")) + ->severity(log::SUCCESS); + + return $tasks; + } + + /** + * Task that rebuilds all dirty images. + * @param Task_Model the task + */ + static function rebuild_dirty_images($task) { + $result = graphics::find_dirty_images_query(); + $remaining = $result->count(); + $completed = $task->get("completed", 0); + + $i = 0; + foreach ($result as $row) { + $item = ORM::factory("item", $row->id); + if ($item->loaded) { + graphics::generate($item); + } + + $completed++; + $remaining--; + + if (++$i == 2) { + break; + } + } + + $task->status = t2("Updated: 1 image. Total: %total_count.", + "Updated: %count images. Total: %total_count.", + $completed, + array("total_count" => ($remaining + $completed))); + + if ($completed + $remaining > 0) { + $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); + } else { + $task->percent_complete = 100; + } + + $task->set("completed", $completed); + if ($remaining == 0) { + $task->done = true; + $task->state = "success"; + site_status::clear("graphics_dirty"); + } + } + + static function update_l10n(&$task) { + $start = microtime(true); + $dirs = $task->get("dirs"); + $files = $task->get("files"); + $cache = $task->get("cache", array()); + $i = 0; + + switch ($task->get("mode", "init")) { + case "init": // 0% + $dirs = array("gallery", "modules", "themes", "installer"); + $files = array(); + $task->set("mode", "find_files"); + $task->status = t("Finding files"); + break; + + case "find_files": // 0% - 10% + while (($dir = array_pop($dirs)) && microtime(true) - $start < 0.5) { + if (basename($dir) == "tests") { + continue; + } + + foreach (glob(DOCROOT . "$dir/*") as $path) { + $relative_path = str_replace(DOCROOT, "", $path); + if (is_dir($path)) { + $dirs[] = $relative_path; + } else { + $files[] = $relative_path; + } + } + } + + $task->status = t2("Finding files: found 1 file", + "Finding files: found %count files", count($files)); + + if (!$dirs) { + $task->set("mode", "scan_files"); + $task->set("total_files", count($files)); + $task->status = t("Scanning files"); + $task->percent_complete = 10; + } + break; + + case "scan_files": // 10% - 90% + while (($file = array_pop($files)) && microtime(true) - $start < 0.5) { + $file = DOCROOT . $file; + switch (pathinfo($file, PATHINFO_EXTENSION)) { + case "php": + l10n_scanner::scan_php_file($file, $cache); + break; + + case "info": + l10n_scanner::scan_info_file($file, $cache); + break; + } + } + + $total_files = $task->get("total_files"); + $task->status = t2("Scanning files: scanned 1 file", + "Scanning files: scanned %count files", $total_files - count($files)); + + $task->percent_complete = 10 + 80 * ($total_files - count($files)) / $total_files; + if (empty($files)) { + $task->set("mode", "fetch_updates"); + $task->status = t("Fetching updates"); + $task->percent_complete = 90; + } + break; + + case "fetch_updates": // 90% - 100% + l10n_client::fetch_updates(); + $task->done = true; + $task->state = "success"; + $task->status = t("Translations installed/updated"); + $task->percent_complete = 100; + } + + $task->set("files", $files); + $task->set("dirs", $dirs); + $task->set("cache", $cache); + } +} \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php new file mode 100644 index 00000000..0acccb45 --- /dev/null +++ b/modules/gallery/helpers/gallery_theme.php @@ -0,0 +1,137 @@ +get("debug")) { + $buf .= ""; + } + if (($theme->page_type == "album" || $theme->page_type == "photo") + && access::can("edit", $theme->item())) { + $buf .= ""; + $buf .= html::script("gallery/js/quick.js"); + } + if ($theme->page_type == "photo" && access::can("view_full", $theme->item())) { + $buf .= ""; + $buf .= html::script("gallery/js/fullsize.js"); + } + + if ($session->get("l10n_mode", false)) { + $buf .= ""; + $buf .= html::script("lib/jquery.cookie.js"); + $buf .= html::script("gallery/js/l10n_client.js"); + } + + return $buf; + } + + static function resize_top($theme, $item) { + if (access::can("edit", $item)) { + $edit_link = url::site("quick/pane/$item->id?page_type=photo"); + return "
    "; + } + } + + static function resize_bottom($theme, $item) { + if (access::can("edit", $item)) { + return "
    "; + } + } + + static function thumb_top($theme, $child) { + if (access::can("edit", $child)) { + $edit_link = url::site("quick/pane/$child->id?page_type=album"); + return "
    "; + } + } + + static function thumb_bottom($theme, $child) { + if (access::can("edit", $child)) { + return "
    "; + } + } + + static function admin_head($theme) { + $session = Session::instance(); + $buf = ""; + if ($session->get("debug")) { + $buf .= ""; + } + + if ($session->get("l10n_mode", false)) { + $buf .= ""; + $buf .= html::script("lib/jquery.cookie.js"); + $buf .= html::script("gallery/js/l10n_client.js"); + } + + return $buf; + } + + static function page_bottom($theme) { + $session = Session::instance(); + if ($session->get("profiler", false)) { + $profiler = new Profiler(); + $profiler->render(); + } + if ($session->get("l10n_mode", false)) { + return L10n_Client_Controller::l10n_form(); + } + + if ($session->get("after_install")) { + $session->delete("after_install"); + return new View("after_install_loader.html"); + } + } + + static function admin_page_bottom($theme) { + $session = Session::instance(); + if ($session->get("profiler", false)) { + $profiler = new Profiler(); + $profiler->render(); + } + if ($session->get("l10n_mode", false)) { + return L10n_Client_Controller::l10n_form(); + } + } + + static function credits() { + return "
  • " . + t("Powered by Gallery %version", + array("url" => "http://gallery.menalto.com", + "version" => module::get_var("gallery", "version"))) . + "
  • "; + } + + static function admin_credits() { + return gallery_theme::credits(); + } +} \ No newline at end of file diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php index 805a95c0..605b9ff8 100644 --- a/modules/gallery/helpers/graphics.php +++ b/modules/gallery/helpers/graphics.php @@ -26,11 +26,11 @@ class graphics_Core { * Rules are applied to targets (thumbnails and resizes) in priority order. Rules are functions * in the graphics class. So for example, the following rule: * - * graphics::add_rule("core", "thumb", "resize", + * graphics::add_rule("gallery", "thumb", "resize", * array("width" => 200, "height" => 200, "master" => Image::AUTO), 100); * - * Specifies that "core" is adding a rule to resize thumbnails down to a max of 200px on - * the longest side. The core module adds default rules at a priority of 100. You can set + * Specifies that "gallery" is adding a rule to resize thumbnails down to a max of 200px on + * the longest side. The gallery module adds default rules at a priority of 100. You can set * higher and lower priorities to perform operations before or after this fires. * * @param string $module_name the module that added the rule @@ -194,7 +194,7 @@ class graphics_Core { } else { Image::factory($input_file) ->resize($options["width"], $options["height"], $options["master"]) - ->quality(module::get_var("core", "image_quality")) + ->quality(module::get_var("gallery", "image_quality")) ->save($output_file); } } @@ -212,7 +212,7 @@ class graphics_Core { } Image::factory($input_file) - ->quality(module::get_var("core", "image_quality")) + ->quality(module::get_var("gallery", "image_quality")) ->rotate($options["degrees"]) ->save($output_file); } @@ -262,7 +262,7 @@ class graphics_Core { Image::factory($input_file) ->composite($options["file"], $x, $y, $options["transparency"]) - ->quality(module::get_var("core", "image_quality")) + ->quality(module::get_var("gallery", "image_quality")) ->save($output_file); } @@ -302,7 +302,7 @@ class graphics_Core { $count, array("attrs" => sprintf( 'href="%s" class="gDialogLink"', - url::site("admin/maintenance/start/core_task::rebuild_dirty_images?csrf=__CSRF__")))), + url::site("admin/maintenance/start/gallery_task::rebuild_dirty_images?csrf=__CSRF__")))), "graphics_dirty"); } } @@ -332,12 +332,12 @@ class graphics_Core { $toolkits = graphics::detect_toolkits(); foreach (array("imagemagick", "graphicsmagick", "gd") as $tk) { if ($toolkits[$tk]) { - module::set_var("core", "graphics_toolkit", $tk); - module::set_var("core", "graphics_toolkit_path", $tk == "gd" ? "" : $toolkits[$tk]); + module::set_var("gallery", "graphics_toolkit", $tk); + module::set_var("gallery", "graphics_toolkit_path", $tk == "gd" ? "" : $toolkits[$tk]); break; } } - if (!module::get_var("core", "graphics_toolkit")) { + if (!module::get_var("gallery", "graphics_toolkit")) { site_status::warning( t("Graphics toolkit missing! Please choose a toolkit", array("url" => url::site("admin/graphics"))), @@ -349,7 +349,7 @@ class graphics_Core { * Choose which driver the Kohana Image library uses. */ static function init_toolkit() { - switch(module::get_var("core", "graphics_toolkit")) { + switch(module::get_var("gallery", "graphics_toolkit")) { case "gd": Kohana::config_set("image.driver", "GD"); break; @@ -357,13 +357,13 @@ class graphics_Core { case "imagemagick": Kohana::config_set("image.driver", "ImageMagick"); Kohana::config_set( - "image.params.directory", module::get_var("core", "graphics_toolkit_path")); + "image.params.directory", module::get_var("gallery", "graphics_toolkit_path")); break; case "graphicsmagick": Kohana::config_set("image.driver", "GraphicsMagick"); Kohana::config_set( - "image.params.directory", module::get_var("core", "graphics_toolkit_path")); + "image.params.directory", module::get_var("gallery", "graphics_toolkit_path")); break; } @@ -376,7 +376,7 @@ class graphics_Core { * @return boolean */ static function can($func) { - if (module::get_var("core", "graphics_toolkit") == "gd" && + if (module::get_var("gallery", "graphics_toolkit") == "gd" && $func == "rotate" && !function_exists("imagerotate")) { return false; diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php index ec4c5429..d26739f5 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -35,9 +35,9 @@ class l10n_client_Core { static function api_key($api_key=null) { if ($api_key !== null) { - module::set_var("core", "l10n_client_key", $api_key); + module::set_var("gallery", "l10n_client_key", $api_key); } - return module::get_var("core", "l10n_client_key", ""); + return module::get_var("gallery", "l10n_client_key", ""); } static function server_uid($api_key=null) { diff --git a/modules/gallery/helpers/locale.php b/modules/gallery/helpers/locale.php index b707637f..2ba0f255 100644 --- a/modules/gallery/helpers/locale.php +++ b/modules/gallery/helpers/locale.php @@ -37,8 +37,8 @@ class locale_Core { static function installed() { $available = self::available(); - $default = module::get_var("core", "default_locale"); - $codes = explode("|", module::get_var("core", "installed_locales", $default)); + $default = module::get_var("gallery", "default_locale"); + $codes = explode("|", module::get_var("gallery", "installed_locales", $default)); foreach ($codes as $code) { if (isset($available->$code)) { $installed[$code] = $available[$code]; @@ -49,10 +49,10 @@ class locale_Core { static function update_installed($locales) { // Ensure that the default is included... - $default = module::get_var("core", "default_locale"); + $default = module::get_var("gallery", "default_locale"); $locales = array_merge($locales, array($default)); - module::set_var("core", "installed_locales", join("|", $locales)); + module::set_var("gallery", "installed_locales", join("|", $locales)); } // @todo Might want to add a localizable language name as well. diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index a48c89ed..a6cc87ac 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -37,7 +37,7 @@ class module_Core { $module = self::get($module_name); if (!$module->loaded) { $module->name = $module_name; - $module->active = $module_name == "core"; // only core is active by default + $module->active = $module_name == "gallery"; // only gallery is active by default } $module->version = 1; $module->save(); @@ -75,7 +75,7 @@ class module_Core { */ static function available() { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); - foreach (array_merge(array("core/module.info"), glob(MODPATH . "*/module.info")) as $file) { + foreach (array_merge(array("gallery/module.info"), glob(MODPATH . "*/module.info")) as $file) { $module_name = basename(dirname($file)); $modules->$module_name = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); $modules->$module_name->installed = self::is_installed($module_name); @@ -85,7 +85,7 @@ class module_Core { } // Lock certain modules - $modules->core->locked = true; + $modules->gallery->locked = true; $modules->user->locked = true; $modules->ksort(); @@ -215,10 +215,10 @@ class module_Core { if ($module->active) { self::$active[] = $module; } - if ($module->name != "core") { - $kohana_modules[] = MODPATH . $module->name; - } + $kohana_modules[] = MODPATH . $module->name; + // @todo: force 'gallery' to be at the end } + Kohana::config_set("core.modules", $kohana_modules); } @@ -252,32 +252,32 @@ class module_Core { * @return the value */ static function get_var($module_name, $name, $default_value=null) { - // We cache all vars in core._cache so that we can load all vars at once for + // We cache all vars in gallery._cache so that we can load all vars at once for // performance. if (empty(self::$var_cache)) { $row = Database::instance() ->select("value") ->from("vars") - ->where(array("module_name" => "core", "name" => "_cache")) + ->where(array("module_name" => "gallery", "name" => "_cache")) ->get() ->current(); if ($row) { self::$var_cache = unserialize($row->value); } else { - // core._cache doesn't exist. Create it now. + // gallery._cache doesn't exist. Create it now. foreach (Database::instance() ->select("module_name", "name", "value") ->from("vars") ->orderby("module_name", "name") ->get() as $row) { - if ($row->module_name == "core" && $row->name == "_cache") { + if ($row->module_name == "gallery" && $row->name == "_cache") { // This could happen if there's a race condition continue; } self::$var_cache->{$row->module_name}->{$row->name} = $row->value; } $cache = ORM::factory("var"); - $cache->module_name = "core"; + $cache->module_name = "gallery"; $cache->name = "_cache"; $cache->value = serialize(self::$var_cache); $cache->save(); @@ -309,7 +309,7 @@ class module_Core { $var->value = $value; $var->save(); - Database::instance()->delete("vars", array("module_name" => "core", "name" => "_cache")); + Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache")); self::$var_cache = null; } @@ -325,7 +325,7 @@ class module_Core { "WHERE `module_name` = '$module_name' " . "AND `name` = '$name'"); - Database::instance()->delete("vars", array("module_name" => "core", "name" => "_cache")); + Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache")); self::$var_cache = null; } @@ -343,7 +343,7 @@ class module_Core { $var->delete(); } - Database::instance()->delete("vars", array("module_name" => "core", "name" => "_cache")); + Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache")); self::$var_cache = null; } diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 3293d4ac..15225fe7 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -140,11 +140,11 @@ class movie_Core { } static function find_ffmpeg() { - if (!$ffmpeg_path = module::get_var("core", "ffmpeg_path")) { + if (!$ffmpeg_path = module::get_var("gallery", "ffmpeg_path")) { if (function_exists("exec")) { $ffmpeg_path = exec("which ffmpeg"); if ($ffmpeg_path) { - module::set_var("core", "ffmpeg_path", $ffmpeg_path); + module::set_var("gallery", "ffmpeg_path", $ffmpeg_path); } } } diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index cbe224db..af340db6 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -31,10 +31,11 @@ class theme_Core { static function load_themes() { $modules = Kohana::config("core.modules"); if (Router::$controller == "admin") { - array_unshift($modules, THEMEPATH . module::get_var("core", "active_admin_theme")); + array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_admin_theme")); } else { - array_unshift($modules, THEMEPATH . module::get_var("core", "active_site_theme")); + array_unshift($modules, THEMEPATH . module::get_var("gallery", "active_site_theme")); } + Kohana::config_set("core.modules", $modules); } @@ -43,17 +44,17 @@ class theme_Core { $group = $form->group("edit_theme"); $group->input("page_size")->label(t("Items per page"))->id("gPageSize") ->rules("required|valid_digit") - ->value(module::get_var("core", "page_size")); + ->value(module::get_var("gallery", "page_size")); $group->input("thumb_size")->label(t("Thumbnail size (in pixels)"))->id("gThumbSize") ->rules("required|valid_digit") - ->value(module::get_var("core", "thumb_size")); + ->value(module::get_var("gallery", "thumb_size")); $group->input("resize_size")->label(t("Resized image size (in pixels)"))->id("gResizeSize") ->rules("required|valid_digit") - ->value(module::get_var("core", "resize_size")); + ->value(module::get_var("gallery", "resize_size")); $group->textarea("header_text")->label(t("Header text"))->id("gHeaderText") - ->value(module::get_var("core", "header_text")); + ->value(module::get_var("gallery", "header_text")); $group->textarea("footer_text")->label(t("Footer text"))->id("gFooterText") - ->value(module::get_var("core", "footer_text")); + ->value(module::get_var("gallery", "footer_text")); $group->submit("")->value(t("Save")); return $form; } -- cgit v1.2.3