예제 #1
0
파일: move.php 프로젝트: xafr/gallery3
 public function save($source_id)
 {
     access::verify_csrf();
     $source = ORM::factory("item", $source_id);
     $target = ORM::factory("item", $this->input->post("target_id"));
     item::move($source, $target);
     print json_encode(array("result" => "success", "location" => url::site("albums/{$target->id}")));
 }
예제 #2
0
파일: move.php 프로젝트: scarygary/gallery3
 public function save($source_id)
 {
     access::verify_csrf();
     $source = ORM::factory("item", $source_id);
     $target = ORM::factory("item", $this->input->post("target_id"));
     access::required("view", $source);
     access::required("edit", $source);
     access::required("view", $target);
     access::required("edit", $target);
     item::move($source, $target);
     print json_encode(array("result" => "success", "location" => $target->url()));
 }
예제 #3
0
파일: organize.php 프로젝트: roypa/bbg
 function move_to($target_album_id)
 {
     access::verify_csrf();
     $target_album = ORM::factory("item", $target_album_id);
     foreach ($this->input->post("source_ids") as $source_id) {
         $source = ORM::factory("item", $source_id);
         if (!$source->contains($target_album)) {
             item::move($source, $target_album);
         }
     }
     print json_encode(array("tree" => self::_expanded_tree(ORM::factory("item", 1), $album)->__toString(), "grid" => self::_get_micro_thumb_grid($album, 0)->__toString()));
 }
예제 #4
0
 static function run($task)
 {
     $context = unserialize($task->context);
     $taskType = $context["type"];
     try {
         $target = ORM::factory("item", $context["target"]);
         $total = count($context["items"]);
         $stop = min($total - $context["position"], $context["batch"]);
         $context["post_process"] = array();
         for ($offset = 0; $offset < $stop; $offset++) {
             $current_id = $context["position"] + $offset;
             $id = $context["items"][$current_id];
             switch ($taskType) {
                 case "move":
                     $source = ORM::factory("item", $id);
                     item::move($source, $target);
                     break;
                 case "rearrange":
                     Database::instance()->query("Update {items} set weight = {$context["position"]} where id={$id};");
                     break;
                 case "rotateCcw":
                 case "rotateCw":
                     $item = ORM::factory("item", $id);
                     if ($item->is_photo()) {
                         $context["post_process"]["reload"][] = self::_do_rotation($item, $taskType == "rotateCcw" ? -90 : 90);
                     }
                     break;
                 case "albumCover":
                     item::make_album_cover(ORM::factory("item", $id));
                     break;
                 case "delete":
                     $item = ORM::factory("item", $id);
                     $item->delete();
                     $context["post_process"]["remove"][] = array("id" => $id);
                     break;
                 default:
                     throw new Exception("Task '{$taskType}' is not implmented");
             }
         }
         $context["position"] += $stop;
         $task->state = "success";
     } catch (Exception $e) {
         $task->status = $e->getMessage();
         $task->state = "error";
         $task->save();
         throw $e;
     }
     $task->context = serialize($context);
     $total = count($context["items"]);
     $task->percent_complete = $context["position"] / (double) $total * 100;
     $task->done = $context["position"] == $total || $task->state == "error";
 }
예제 #5
0
 function move_to($target_album_id)
 {
     access::verify_csrf();
     $target_album = ORM::factory("item", $target_album_id);
     access::required("view", $target_album);
     access::required("add", $target_album);
     foreach (Input::instance()->post("source_ids") as $source_id) {
         $source = ORM::factory("item", $source_id);
         if (!$source->contains($target_album)) {
             access::required("edit", $source);
             item::move($source, $target_album);
         }
     }
     print json_encode(array("tree" => self::_expanded_tree(ORM::factory("item", 1), $target_album)->__toString(), "grid" => self::_get_micro_thumb_grid($target_album, 0)->__toString()));
 }
예제 #6
0
 function move_to($target_album_id)
 {
     access::verify_csrf();
     $target_album = ORM::factory("item", $target_album_id);
     $js = json_decode($_REQUEST["sourceids"]);
     $i = 0;
     foreach ($js as $source_id) {
         $source = ORM::factory("item", $source_id);
         if (!$source->contains($target_album)) {
             item::move($source, $target_album);
         }
         $i++;
     }
     print json_encode(array("result" => "success"));
 }
예제 #7
0
 function move_to($target_album_id)
 {
     access::verify_csrf();
     $target_album = ORM::factory("item", $target_album_id);
     access::required("view", $target_album);
     access::required("add", $target_album);
     $source_album = null;
     $js = json_decode($_REQUEST["sourceids"]);
     $i = 0;
     $source_album = null;
     foreach ($js as $source_id) {
         $source = ORM::factory("item", $source_id);
         if (empty($source_album)) {
             // get the source_album
             $source_album = $source->parent();
         }
         if (!$source->contains($target_album)) {
             access::required("edit", $source);
             item::move($source, $target_album);
         }
         $i++;
     }
     json::reply(array("result" => "success"));
 }
예제 #8
0
 public function moved_items_inherit_new_permissions_test()
 {
     identity::set_active_user(identity::lookup_user_by_name("admin"));
     $public_album = test::random_album();
     $public_photo = test::random_photo($public_album);
     access::allow(identity::everybody(), "view", $public_album);
     access::allow(identity::everybody(), "edit", $public_album);
     item::root()->reload();
     // Account for MPTT changes
     $private_album = test::random_album();
     access::deny(identity::everybody(), "view", $private_album);
     access::deny(identity::everybody(), "edit", $private_album);
     $private_photo = test::random_photo($private_album);
     // Make sure that we now have a public photo and private photo.
     $this->assert_true(access::group_can(identity::everybody(), "view", $public_photo));
     $this->assert_false(access::group_can(identity::everybody(), "view", $private_photo));
     // Swap the photos
     item::move($public_photo, $private_album);
     $private_album->reload();
     // Reload to get new MPTT pointers and cached perms.
     $public_album->reload();
     $private_photo->reload();
     $public_photo->reload();
     item::move($private_photo, $public_album);
     $private_album->reload();
     // Reload to get new MPTT pointers and cached perms.
     $public_album->reload();
     $private_photo->reload();
     $public_photo->reload();
     // Make sure that the public_photo is now private, and the private_photo is now public.
     $this->assert_false(access::group_can(identity::everybody(), "view", $public_photo));
     $this->assert_false(access::group_can(identity::everybody(), "edit", $public_photo));
     $this->assert_true(access::group_can(identity::everybody(), "view", $private_photo));
     $this->assert_true(access::group_can(identity::everybody(), "edit", $private_photo));
 }
예제 #9
0
 public function moved_items_inherit_new_permissions_test()
 {
     user::set_active(user::lookup_by_name("admin"));
     $root = ORM::factory("item", 1);
     $public_album = album::create($root, rand(), "public album");
     $public_photo = photo::create($public_album, MODPATH . "gallery/images/gallery.png", "", "");
     access::allow(group::everybody(), "view", $public_album);
     $root->reload();
     // Account for MPTT changes
     $private_album = album::create($root, rand(), "private album");
     access::deny(group::everybody(), "view", $private_album);
     $private_photo = photo::create($private_album, MODPATH . "gallery/images/gallery.png", "", "");
     // Make sure that we now have a public photo and private photo.
     $this->assert_true(access::group_can(group::everybody(), "view", $public_photo));
     $this->assert_false(access::group_can(group::everybody(), "view", $private_photo));
     // Swap the photos
     item::move($public_photo, $private_album);
     $private_album->reload();
     // Reload to get new MPTT pointers and cached perms.
     $public_album->reload();
     $private_photo->reload();
     $public_photo->reload();
     item::move($private_photo, $public_album);
     $private_album->reload();
     // Reload to get new MPTT pointers and cached perms.
     $public_album->reload();
     $private_photo->reload();
     $public_photo->reload();
     // Make sure that the public_photo is now private, and the private_photo is now public.
     $this->assert_false(access::group_can(group::everybody(), "view", $public_photo));
     $this->assert_true(access::group_can(group::everybody(), "view", $private_photo));
 }
예제 #10
0
 public function move_conflicts_result_in_a_rename_test()
 {
     $rand = random::int();
     $photo1 = test::random_photo_unsaved(item::root());
     $photo1->name = "{$rand}.jpg";
     $photo1->slug = (string) $rand;
     $photo1->save();
     $src_album = test::random_album();
     $photo2 = test::random_photo_unsaved($src_album);
     $photo2->name = "{$rand}.jpg";
     $photo2->slug = (string) $rand;
     $photo2->save();
     item::move($photo2, item::root());
     $this->assert_same(item::root()->id, $photo2->parent_id);
     $this->assert_not_same("{$rand}.jpg", $photo2->name);
     $this->assert_not_same($rand, $photo2->slug);
 }