diff --git a/3.0/modules/user_chroot/helpers/MY_access.php b/3.0/modules/user_chroot/helpers/MY_access.php new file mode 100644 index 00000000..5f73b4ca --- /dev/null +++ b/3.0/modules/user_chroot/helpers/MY_access.php @@ -0,0 +1,61 @@ +id == identity::active_user()->id && user_chroot::album() ) { + if( $item->left_ptr < user_chroot::album()->left_ptr || user_chroot::album()->right_ptr < $item->right_ptr ) { + return false; + } + } + + return parent::user_can($user, $perm_name, $item); + } +} diff --git a/3.0/modules/user_chroot/helpers/MY_item.php b/3.0/modules/user_chroot/helpers/MY_item.php new file mode 100644 index 00000000..423b8ddc --- /dev/null +++ b/3.0/modules/user_chroot/helpers/MY_item.php @@ -0,0 +1,34 @@ +and_open() + ->and_where("items.left_ptr", ">=", user_chroot::album()->left_ptr) + ->and_where("items.right_ptr", "<=", user_chroot::album()->right_ptr) + ->close(); + } + + return $model; + } +} diff --git a/3.0/modules/user_chroot/helpers/MY_url.php b/3.0/modules/user_chroot/helpers/MY_url.php new file mode 100644 index 00000000..31818fa4 --- /dev/null +++ b/3.0/modules/user_chroot/helpers/MY_url.php @@ -0,0 +1,47 @@ +relative_url().'/'.Router::$current_uri, '/'); + } + + return parent::parse_url(); + } + + static function site($uri = '', $protocol = FALSE) { + if( user_chroot::album() ) { + $uri = preg_replace('#^'.user_chroot::album()->relative_url().'#', '', $uri); + } + + return parent::site($uri, $protocol); + } +} \ No newline at end of file diff --git a/3.0/modules/user_chroot/helpers/user_chroot.php b/3.0/modules/user_chroot/helpers/user_chroot.php new file mode 100644 index 00000000..4d0a8499 --- /dev/null +++ b/3.0/modules/user_chroot/helpers/user_chroot.php @@ -0,0 +1,41 @@ +id); + if( $user_chroot->loaded() && $user_chroot->album_id != 0 ) { + $item = ORM::factory("item", $user_chroot->album_id); + if( $item->loaded() ) { + self::$_album = $item; + } + } + } + + return self::$_album; + } +} \ No newline at end of file diff --git a/3.0/modules/user_chroot/helpers/user_chroot_event.php b/3.0/modules/user_chroot/helpers/user_chroot_event.php new file mode 100644 index 00000000..c43c6dc4 --- /dev/null +++ b/3.0/modules/user_chroot/helpers/user_chroot_event.php @@ -0,0 +1,112 @@ +delete($user->id); + } + + /** + * Called when admin is adding a user + */ + static function user_add_form_admin($user, $form) { + $form->add_user->dropdown("user_chroot") + ->label(t("Root Album")) + ->options(self::createGalleryArray()) + ->selected(0); + } + + /** + * Called after a user has been added + */ + static function user_add_form_admin_completed($user, $form) { + $user_chroot = ORM::factory("user_chroot")->where("id", "=", $user->id)->find(); + $user_chroot->id = $user->id; + $user_chroot->album_id = $form->add_user->user_chroot->value; + $user_chroot->save(); + } + + /** + * Called when admin is editing a user + */ + static function user_edit_form_admin($user, $form) { + $user_chroot = ORM::factory("user_chroot")->where("id", "=", $user->id)->find(); + if ($user_chroot->loaded()) { + $selected = $user_chroot->album_id; + } else { + $selected = 0; + } + $form->edit_user->dropdown("user_chroot") + ->label(t("Root Album")) + ->options(self::createGalleryArray()) + ->selected($selected); + } + + /** + * Called after a user had been edited by the admin + */ + static function user_edit_form_admin_completed($user, $form) { + $user_chroot = ORM::factory("user_chroot")->where("id", "=", $user->id)->find(); + if ($user_chroot->loaded()) { + $user_chroot->album_id = $form->edit_user->user_chroot->value; + } else { + $user_chroot->id = $user->id; + $user_chroot->album_id = $form->edit_user->user_chroot->value; + } + $user_chroot->save(); + } + + + /** + * Creates an array of galleries + */ + static function createGalleryArray() { + $array[0] = "none"; + $root = ORM::factory("item", 1); + self::tree($root, "", $array); + return $array; + } + + /** + * recursive function to build array for drop down list + */ + static function tree($parent, $dashes, &$array) { + if ($parent->id == "1") { + $array[$parent->id] = ORM::factory("item", 1)->title; + } else { + $array[$parent->id] = "$dashes $parent->name"; + } + + $albums = ORM::factory("item") + ->where("parent_id", "=", $parent->id) + ->where("type", "=", "album") + ->order_by("title", "ASC") + ->find_all(); + foreach ($albums as $album) { + self::tree($album, "-$dashes", $array); + } + return; + } +} diff --git a/3.0/modules/user_chroot/helpers/user_chroot_installer.php b/3.0/modules/user_chroot/helpers/user_chroot_installer.php new file mode 100644 index 00000000..ee89fb13 --- /dev/null +++ b/3.0/modules/user_chroot/helpers/user_chroot_installer.php @@ -0,0 +1,40 @@ +query("CREATE TABLE IF NOT EXISTS {user_chroots} ( + `id` int(9) NOT NULL, + `album_id` int(9) default NULL, + PRIMARY KEY (`id`), + UNIQUE KEY(`id`)) + DEFAULT CHARSET=utf8;"); + module::set_version("user_chroot", 1); + } + + /** + * Drops the table of user chroot when the module is uninstalled. + */ + static function uninstall() { + $db = Database::instance(); + $db->query("DROP TABLE IF EXISTS {user_chroots};"); + } +} diff --git a/3.0/modules/user_chroot/libraries/MY_ORM_MPTT.php b/3.0/modules/user_chroot/libraries/MY_ORM_MPTT.php new file mode 100644 index 00000000..e31124ca --- /dev/null +++ b/3.0/modules/user_chroot/libraries/MY_ORM_MPTT.php @@ -0,0 +1,61 @@ +model_name = inflector::singular($this->table_name); + } + + /** + * Return the parent of this node + * + * @return ORM + */ + /*function parent() { + if( user_chroot::album() && user_chroot::album()->id == $this->id ) { + return null; + } else { + return parent::parent(); + } + }*/ + + /** + * Return all the parents of this node, in order from root to this node's immediate parent. + * + * @return array ORM + */ + function parents() { + $select = $this + ->where("left_ptr", "<=", $this->left_ptr) + ->where("right_ptr", ">=", $this->right_ptr) + ->where("id", "<>", $this->id) + ->order_by("left_ptr", "ASC"); + + if( user_chroot::album() ) { + $select->where("left_ptr", ">=", user_chroot::album()->left_ptr); + $select->where("right_ptr", "<=", user_chroot::album()->right_ptr); + } + + return $select->find_all(); + } +} diff --git a/3.0/modules/user_chroot/models/user_chroot.php b/3.0/modules/user_chroot/models/user_chroot.php new file mode 100644 index 00000000..30184597 --- /dev/null +++ b/3.0/modules/user_chroot/models/user_chroot.php @@ -0,0 +1,22 @@ +