Beispiel #1
0
 static function item_created($item)
 {
     access::add_item($item);
     if ($item->is_photo() || $item->is_movie()) {
         // Build our thumbnail/resizes.
         try {
             graphics::generate($item);
         } catch (Exception $e) {
             log::error("graphics", t("Couldn't create a thumbnail or resize for %item_title", array("item_title" => $item->title)), html::anchor($item->abs_url(), t("details")));
             Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
         }
         // If the parent has no cover item, make this it.
         $parent = $item->parent();
         if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
             item::make_album_cover($item);
         }
     }
 }
Beispiel #2
0
 static function item_created($item)
 {
     access::add_item($item);
 }
Beispiel #3
0
 static function install()
 {
     $db = Database::instance();
     $db->query("CREATE TABLE {access_caches} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `item_id` int(9),\n                 PRIMARY KEY (`id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {access_intents} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `item_id` int(9),\n                 PRIMARY KEY (`id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {caches} (\n                `id` int(9) NOT NULL auto_increment,\n                `key` varchar(255) NOT NULL,\n                `tags` varchar(255),\n                `expiration` int(9) NOT NULL,\n                `cache` longblob,\n                PRIMARY KEY (`id`),\n                KEY (`tags`))\n                DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {graphics_rules} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `active` BOOLEAN default 0,\n                 `args` varchar(255) default NULL,\n                 `module_name` varchar(64) NOT NULL,\n                 `operation` varchar(64) NOT NULL,\n                 `priority` int(9) NOT NULL,\n                 `target`  varchar(32) NOT NULL,\n                 PRIMARY KEY (`id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {incoming_translations} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `key` char(32) NOT NULL,\n                 `locale` char(10) NOT NULL,\n                 `message` text NOT NULL,\n                 `revision` int(9) DEFAULT NULL,\n                 `translation` text,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`key`, `locale`),\n                 KEY `locale_key` (`locale`, `key`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {items} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `album_cover_item_id` int(9) default NULL,\n                 `captured` int(9) default NULL,\n                 `created` int(9) default NULL,\n                 `description` varchar(2048) default NULL,\n                 `height` int(9) default NULL,\n                 `left_ptr` int(9) NOT NULL,\n                 `level` int(9) NOT NULL,\n                 `mime_type` varchar(64) default NULL,\n                 `name` varchar(255) default NULL,\n                 `owner_id` int(9) default NULL,\n                 `parent_id` int(9) NOT NULL,\n                 `rand_key` float default NULL,\n                 `relative_path_cache` varchar(255) default NULL,\n                 `relative_url_cache` varchar(255) default NULL,\n                 `resize_dirty` boolean default 1,\n                 `resize_height` int(9) default NULL,\n                 `resize_width` int(9) default NULL,\n                 `right_ptr` int(9) NOT NULL,\n                 `slug` varchar(255) default NULL,\n                 `sort_column` varchar(64) default NULL,\n                 `sort_order` char(4) default 'ASC',\n                 `thumb_dirty` boolean default 1,\n                 `thumb_height` int(9) default NULL,\n                 `thumb_width` int(9) default NULL,\n                 `title` varchar(255) default NULL,\n                 `type` varchar(32) NOT NULL,\n                 `updated` int(9) default NULL,\n                 `view_count` int(9) default 0,\n                 `weight` int(9) NOT NULL default 0,\n                 `width` int(9) default NULL,\n                 PRIMARY KEY (`id`),\n                 KEY `parent_id` (`parent_id`),\n                 KEY `type` (`type`),\n                 KEY `random` (`rand_key`),\n                 KEY `weight` (`weight` DESC))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {logs} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `category` varchar(64) default NULL,\n                 `html` varchar(255) default NULL,\n                 `message` text default NULL,\n                 `referer` varchar(255) default NULL,\n                 `severity` int(9) default 0,\n                 `timestamp` int(9) default 0,\n                 `url` varchar(255) default NULL,\n                 `user_id` int(9) default 0,\n                 PRIMARY KEY (`id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {messages} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `key` varchar(255) default NULL,\n                 `severity` varchar(32) default NULL,\n                 `value` varchar(255) default NULL,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`key`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {modules} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `active` BOOLEAN default 0,\n                 `name` varchar(64) default NULL,\n                 `version` int(9) default NULL,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`name`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {outgoing_translations} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `base_revision` int(9) DEFAULT NULL,\n                 `key` char(32) NOT NULL,\n                 `locale` char(10) NOT NULL,\n                 `message` text NOT NULL,\n                 `translation` text,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`key`, `locale`),\n                 KEY `locale_key` (`locale`, `key`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {permissions} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `display_name` varchar(64) default NULL,\n                 `name` varchar(64) default NULL,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`name`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {sessions} (\n                `session_id` varchar(127) NOT NULL,\n                `data` text NOT NULL,\n                `last_activity` int(10) UNSIGNED NOT NULL,\n                PRIMARY KEY (`session_id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {tasks} (\n                `id` int(9) NOT NULL auto_increment,\n                `callback` varchar(128) default NULL,\n                `context` text NOT NULL,\n                `done` boolean default 0,\n                `name` varchar(128) default NULL,\n                `owner_id` int(9) default NULL,\n                `percent_complete` int(9) default 0,\n                `state` varchar(32) default NULL,\n                `status` varchar(255) default NULL,\n                `updated` int(9) default NULL,\n                PRIMARY KEY (`id`),\n                KEY (`owner_id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {themes} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `name` varchar(64) default NULL,\n                 `version` int(9) default NULL,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`name`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {vars} (\n                `id` int(9) NOT NULL auto_increment,\n                `module_name` varchar(64) NOT NULL,\n                `name` varchar(64) NOT NULL,\n                `value` text,\n                PRIMARY KEY (`id`),\n                UNIQUE KEY(`module_name`, `name`))\n               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");
     // Mark for translation (must be the same strings as used above)
     t("View full size");
     t("View");
     t("Edit");
     t("Add");
     $root = ORM::factory("item");
     $root->type = "album";
     $root->title = "Gallery";
     $root->description = "";
     $root->left_ptr = 1;
     $root->right_ptr = 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", "wind");
     module::set_var("gallery", "active_admin_theme", "admin_wind");
     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);
     module::set_var("gallery", "image_sharpen", 15);
     // Add rules for generating our thumbnails and resizes
     graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => 200, "height" => 200, "master" => Image::AUTO), 100);
     graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => 640, "height" => 480, "master" => Image::AUTO), 100);
     // Instantiate default themes (site and admin)
     foreach (array("wind", "admin_wind") 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_var("gallery", "choose_default_tookit", 1);
     module::set_var("gallery", "date_format", "Y-M-d");
     module::set_var("gallery", "date_time_format", "Y-M-d H:i:s");
     module::set_var("gallery", "time_format", "H:i:s");
     module::set_var("gallery", "show_credits", 1);
     // @todo this string needs to be picked up by l10n_scanner
     module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>");
     module::set_var("gallery", "simultaneous_upload_limit", 5);
     module::set_version("gallery", 21);
 }
Beispiel #4
0
 static function install()
 {
     $db = Database::instance();
     $db->query("CREATE TABLE {access_caches} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `item_id` int(9),\n                 PRIMARY KEY (`id`),\n                 KEY (`item_id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {access_intents} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `item_id` int(9),\n                 PRIMARY KEY (`id`))\n               DEFAULT CHARSET=utf8;");
     // Using a simple index instead of a unique key for the
     // key column to avoid handling of concurrency issues
     // on insert. Thus allowing concurrent inserts on the
     // same cache key, as does Memcache / xcache.
     $db->query("CREATE TABLE {caches} (\n                `id` int(9) NOT NULL auto_increment,\n                `key` varchar(255) NOT NULL,\n                `tags` varchar(255),\n                `expiration` int(9) NOT NULL,\n                `cache` longblob,\n                PRIMARY KEY (`id`),\n                UNIQUE KEY (`key`),\n                KEY (`tags`))\n                DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {failed_auths} (\n                `id` int(9) NOT NULL auto_increment,\n                `count` int(9) NOT NULL,\n                `name` varchar(255) NOT NULL,\n                `time` int(9) NOT NULL,\n                PRIMARY KEY (`id`))\n                DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {graphics_rules} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `active` BOOLEAN default 0,\n                 `args` varchar(255) default NULL,\n                 `module_name` varchar(64) NOT NULL,\n                 `operation` varchar(64) NOT NULL,\n                 `priority` int(9) NOT NULL,\n                 `target`  varchar(32) NOT NULL,\n                 PRIMARY KEY (`id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {incoming_translations} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `key` char(32) NOT NULL,\n                 `locale` char(10) NOT NULL,\n                 `message` text NOT NULL,\n                 `revision` int(9) DEFAULT NULL,\n                 `translation` text,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`key`, `locale`),\n                 KEY `locale_key` (`locale`, `key`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {items} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `album_cover_item_id` int(9) default NULL,\n                 `captured` int(9) default NULL,\n                 `created` int(9) default NULL,\n                 `description` text default NULL,\n                 `height` int(9) default NULL,\n                 `left_ptr` int(9) NOT NULL,\n                 `level` int(9) NOT NULL,\n                 `mime_type` varchar(64) default NULL,\n                 `name` varchar(255) default NULL,\n                 `owner_id` int(9) default NULL,\n                 `parent_id` int(9) NOT NULL,\n                 `rand_key` decimal(11,10) default NULL,\n                 `relative_path_cache` varchar(255) default NULL,\n                 `relative_url_cache` varchar(255) default NULL,\n                 `resize_dirty` boolean default 1,\n                 `resize_height` int(9) default NULL,\n                 `resize_width` int(9) default NULL,\n                 `right_ptr` int(9) NOT NULL,\n                 `slug` varchar(255) default NULL,\n                 `sort_column` varchar(64) default NULL,\n                 `sort_order` char(4) default 'ASC',\n                 `thumb_dirty` boolean default 1,\n                 `thumb_height` int(9) default NULL,\n                 `thumb_width` int(9) default NULL,\n                 `title` varchar(255) default NULL,\n                 `type` varchar(32) NOT NULL,\n                 `updated` int(9) default NULL,\n                 `view_count` int(9) default 0,\n                 `weight` int(9) NOT NULL default 0,\n                 `width` int(9) default NULL,\n                 PRIMARY KEY (`id`),\n                 KEY `parent_id` (`parent_id`),\n                 KEY `type` (`type`),\n                 KEY `random` (`rand_key`),\n                 KEY `weight` (`weight` DESC),\n                 KEY `left_ptr` (`left_ptr`),\n                 KEY `relative_path_cache` (`relative_path_cache`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {logs} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `category` varchar(64) default NULL,\n                 `html` varchar(255) default NULL,\n                 `message` text default NULL,\n                 `referer` varchar(255) default NULL,\n                 `severity` int(9) default 0,\n                 `timestamp` int(9) default 0,\n                 `url` varchar(255) default NULL,\n                 `user_id` int(9) default 0,\n                 PRIMARY KEY (`id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {messages} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `key` varchar(255) default NULL,\n                 `severity` varchar(32) default NULL,\n                 `value` text default NULL,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`key`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {modules} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `active` BOOLEAN default 0,\n                 `name` varchar(64) default NULL,\n                 `version` int(9) default NULL,\n                 `weight` int(9) default NULL,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`name`),\n                 KEY (`weight`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {outgoing_translations} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `base_revision` int(9) DEFAULT NULL,\n                 `key` char(32) NOT NULL,\n                 `locale` char(10) NOT NULL,\n                 `message` text NOT NULL,\n                 `translation` text,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`key`, `locale`),\n                 KEY `locale_key` (`locale`, `key`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {permissions} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `display_name` varchar(64) default NULL,\n                 `name` varchar(64) default NULL,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`name`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {sessions} (\n                `session_id` varchar(127) NOT NULL,\n                `data` text NOT NULL,\n                `last_activity` int(10) UNSIGNED NOT NULL,\n                PRIMARY KEY (`session_id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {tasks} (\n                `id` int(9) NOT NULL auto_increment,\n                `callback` varchar(128) default NULL,\n                `context` text NOT NULL,\n                `done` boolean default 0,\n                `name` varchar(128) default NULL,\n                `owner_id` int(9) default NULL,\n                `percent_complete` int(9) default 0,\n                `state` varchar(32) default NULL,\n                `status` varchar(255) default NULL,\n                `updated` int(9) default NULL,\n                PRIMARY KEY (`id`),\n                KEY (`owner_id`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {themes} (\n                 `id` int(9) NOT NULL auto_increment,\n                 `name` varchar(64) default NULL,\n                 `version` int(9) default NULL,\n                 PRIMARY KEY (`id`),\n                 UNIQUE KEY(`name`))\n               DEFAULT CHARSET=utf8;");
     $db->query("CREATE TABLE {vars} (\n                `id` int(9) NOT NULL auto_increment,\n                `module_name` varchar(64) NOT NULL,\n                `name` varchar(64) NOT NULL,\n                `value` text,\n                PRIMARY KEY (`id`),\n                UNIQUE KEY(`module_name`, `name`))\n               DEFAULT CHARSET=utf8;");
     foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) {
         @mkdir(VARPATH . $dir);
         if (in_array($dir, array("logs", "tmp", "uploads"))) {
             self::_protect_directory(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");
     // Mark for translation (must be the same strings as used above)
     t("View full size");
     t("View");
     t("Edit");
     t("Add");
     // Hardcode the first item to sidestep ORM validation rules
     $now = time();
     db::build()->insert("items", array("created" => $now, "description" => "", "left_ptr" => 1, "level" => 1, "parent_id" => 0, "resize_dirty" => 1, "right_ptr" => 2, "sort_column" => "weight", "sort_order" => "ASC", "thumb_dirty" => 1, "title" => "Gallery", "type" => "album", "updated" => $now, "weight" => 1))->execute();
     $root = ORM::factory("item", 1);
     access::add_item($root);
     module::set_var("gallery", "active_site_theme", "wind");
     module::set_var("gallery", "active_admin_theme", "admin_wind");
     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);
     module::set_var("gallery", "image_sharpen", 15);
     module::set_var("gallery", "upgrade_checker_auto_enabled", true);
     // Add rules for generating our thumbnails and resizes
     graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => 200, "height" => 200, "master" => Image::AUTO), 100);
     graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => 640, "height" => 640, "master" => Image::AUTO), 100);
     // Instantiate default themes (site and admin)
     foreach (array("wind", "admin_wind") 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", "upgrade_checker");
     block_manager::add("dashboard_center", "gallery", "photo_stream");
     block_manager::add("dashboard_center", "gallery", "log_entries");
     module::set_var("gallery", "choose_default_tookit", 1);
     module::set_var("gallery", "date_format", "Y-M-d");
     module::set_var("gallery", "date_time_format", "Y-M-d H:i:s");
     module::set_var("gallery", "time_format", "H:i:s");
     module::set_var("gallery", "show_credits", 1);
     // Mark string for translation
     $powered_by_string = t("Powered by <a href=\"%url\">%gallery_version</a>", array("locale" => "root"));
     module::set_var("gallery", "credits", (string) $powered_by_string);
     module::set_var("gallery", "simultaneous_upload_limit", 5);
     module::set_var("gallery", "admin_area_timeout", 90 * 60);
     module::set_var("gallery", "maintenance_mode", 0);
     module::set_var("gallery", "visible_title_length", 15);
     module::set_var("gallery", "favicon_url", "lib/images/favicon.ico");
     module::set_var("gallery", "apple_touch_icon_url", "lib/images/apple-touch-icon.png");
     module::set_var("gallery", "email_from", "");
     module::set_var("gallery", "email_reply_to", "");
     module::set_var("gallery", "email_line_length", 70);
     module::set_var("gallery", "email_header_separator", serialize("\n"));
     module::set_var("gallery", "show_user_profiles_to", "registered_users");
     module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin");
     module::set_var("gallery", "timezone", null);
     module::set_var("gallery", "lock_timeout", 1);
     module::set_var("gallery", "movie_extract_frame_time", 3);
     module::set_var("gallery", "movie_allow_uploads", "autodetect");
 }
Beispiel #5
0
 public function non_view_permissions_can_be_revoked_lower_down_test()
 {
     $root = ORM::factory("item", 1);
     $outer = album::create($root, rand(), "test album");
     $outer_photo = ORM::factory("item");
     $outer_photo->type = "photo";
     $outer_photo->add_to_parent($outer);
     access::add_item($outer_photo);
     $inner = album::create($outer, rand(), "test album");
     $inner_photo = ORM::factory("item");
     $inner_photo->type = "photo";
     $inner_photo->add_to_parent($inner);
     access::add_item($inner_photo);
     $outer->reload();
     $inner->reload();
     access::allow(group::everybody(), "edit", $root);
     access::deny(group::everybody(), "edit", $outer);
     access::allow(group::everybody(), "edit", $inner);
     // Outer album is not editable, inner one is.
     $this->assert_false(access::group_can(group::everybody(), "edit", $outer_photo));
     $this->assert_true(access::group_can(group::everybody(), "edit", $inner_photo));
 }
 static function install()
 {
     $db = Database::instance();
     $version = 0;
     try {
         $version = module::get_version("core");
     } catch (Exception $e) {
         if ($e->getCode() != E_DATABASE_ERROR) {
             Kohana::log("error", $e);
             throw $e;
         }
     }
     if ($version == 0) {
         $db->query("CREATE TABLE `access_caches` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `item_id` int(9),\n                   PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `access_intents` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `item_id` int(9),\n                   PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `graphics_rules` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `priority` int(9) NOT NULL,\n                   `module_name` varchar(64) NOT NULL,\n                   `target`  varchar(32) NOT NULL,\n                   `operation` varchar(64) NOT NULL,\n                   `args` varchar(255) default NULL,\n                   PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `items` (\n                   `album_cover_item_id` int(9) default NULL,\n                   `created` int(9) default NULL,\n                   `description` varchar(255) default NULL,\n                   `height` int(9) default NULL,\n                   `id` int(9) NOT NULL auto_increment,\n                   `left` int(9) NOT NULL,\n                   `level` int(9) NOT NULL,\n                   `mime_type` varchar(64) default NULL,\n                   `name` varchar(255) default NULL,\n                   `owner_id` int(9) default NULL,\n                   `parent_id` int(9) NOT NULL,\n                   `resize_height` int(9) default NULL,\n                   `resize_width` int(9) default NULL,\n                   `resize_dirty` boolean default 1,\n                   `right` int(9) NOT NULL,\n                   `thumb_height` int(9) default NULL,\n                   `thumb_width` int(9) default NULL,\n                   `thumb_dirty` boolean default 1,\n                   `title` varchar(255) default NULL,\n                   `type` varchar(32) NOT NULL,\n                   `updated` int(9) default NULL,\n                   `view_count` int(9) default 0,\n                   `width` int(9) default NULL,\n                   PRIMARY KEY (`id`),\n                   KEY `parent_id` (`parent_id`),\n                   KEY `type` (`type`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `logs` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `category` varchar(64) default NULL,\n                   `html` varchar(255) default NULL,\n                   `message` text default NULL,\n                   `referer` varchar(255) default NULL,\n                   `severity` int(9) default 0,\n                   `timestamp` int(9) default 0,\n                   `url` varchar(255) default NULL,\n                   `user_id` int(9) default 0,\n                   PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `messages` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `key` varchar(255) default NULL,\n                   `value` varchar(255) default NULL,\n                   `severity` varchar(32) default NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`key`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `modules` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `name` varchar(64) default NULL,\n                   `version` int(9) default NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`name`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `themes` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `name` varchar(64) default NULL,\n                   `version` int(9) default NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`name`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `permissions` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `name` varchar(64) default NULL,\n                   `display_name` varchar(64) default NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`name`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `incoming_translations` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `key` binary(16) NOT NULL,\n                   `locale` char(10) NOT NULL,\n                   `message` text NOT NULL,\n                   `translation` text,\n                   `revision` int(9) DEFAULT NULL,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`key`, `locale`),\n                   KEY `locale_key` (`locale`, `key`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `sessions` (\n                  `session_id` varchar(127) NOT NULL,\n                  `last_activity` int(10) UNSIGNED NOT NULL,\n                  `data` text NOT NULL,\n                  PRIMARY KEY (`session_id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `tasks` (\n                  `callback` varchar(128) default NULL,\n                  `context` text NOT NULL,\n                  `done` boolean default 0,\n                  `id` int(9) NOT NULL auto_increment,\n                  `updated` int(9) default NULL,\n                  `name` varchar(128) default NULL,\n                  `percent_complete` int(9) default 0,\n                  `state` varchar(32) default NULL,\n                  `status` varchar(255) default NULL,\n                  PRIMARY KEY (`id`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         $db->query("CREATE TABLE `vars` (\n                   `id` int(9) NOT NULL auto_increment,\n                   `module_name` varchar(64) NOT NULL,\n                   `name` varchar(64) NOT NULL,\n                   `value` text,\n                   PRIMARY KEY (`id`),\n                   UNIQUE KEY(`module_name`, `name`))\n                 ENGINE=InnoDB DEFAULT CHARSET=utf8;");
         foreach (array("albums", "resizes", "thumbs", "uploads", "modules") as $dir) {
             @mkdir(VARPATH . $dir);
         }
         access::register_permission("view", "View");
         access::register_permission("view_full", "View Full Size");
         access::register_permission("edit", "Edit");
         $root = ORM::factory("item");
         $root->type = 'album';
         $root->title = "Gallery";
         $root->description = "Welcome to your Gallery3";
         $root->left = 1;
         $root->right = 2;
         $root->parent_id = 0;
         $root->level = 1;
         $root->thumb_dirty = 1;
         $root->resize_dirty = 1;
         $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);
         // 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);
         // Detect a graphics toolkit
         $toolkits = graphics::detect_toolkits();
         foreach (array("imagemagick", "graphicsmagick", "gd") as $tk) {
             if ($toolkits[$tk]) {
                 module::set_var("core", "graphics_toolkit", $tk);
                 if ($tk != "gd") {
                     module::set_var("core", "graphics_toolkit_path", $toolkits[$tk]);
                 }
                 break;
             }
         }
         if (!module::get_var("core", "graphics_toolkit")) {
             site_status::warning(t("Graphics toolkit missing!  Please <a href=\"%url\">choose a toolkit</a>", array("url" => url::site("admin/graphics"))), "missing_graphics_toolkit");
         }
         // 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");
     }
 }