Inheritance: extends model
Example #1
0
 public function adicionarItem($quantidadeItem, $valorItem)
 {
     $item = new item();
     $item->setQuantidade($quantidadeItem);
     $item->setValor($valorItem);
     $this->itens[] = $item;
 }
Example #2
0
 public function onActivate(item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if ($tile instanceof FlowerPotTile) {
         if ($tile->getFlowerPotItem() === item::AIR) {
             switch ($item->getId()) {
                 case item::TALL_GRASS:
                     if ($item->getDamage() === 1) {
                         break;
                     }
                 case item::SAPLING:
                 case item::DEAD_BUSH:
                 case item::DANDELION:
                 case item::RED_FLOWER:
                 case item::BROWN_MUSHROOM:
                 case item::RED_MUSHROOM:
                 case item::CACTUS:
                     $tile->setFlowerPotData($item->getId(), $item->getDamage());
                     if ($player->isSurvival()) {
                         $item->count--;
                     }
                     return true;
                     break;
             }
         }
     }
     return false;
 }
Example #3
0
function show_overdue($template_name)
{
    global $db;
    global $TPL;
    $current_user =& singleton("current_user");
    $db = new db_alloc();
    $temp = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
    $today = date("Y", $temp) . "-" . date("m", $temp) . "-" . date("d", $temp);
    $q = prepare("SELECT itemName,itemType,item.itemID,dateBorrowed,dateToBeReturned,loan.personID \n                  FROM loan,item \n                 WHERE dateToBeReturned < '%s' \n\t\t\t\t\t         AND dateReturned = '0000-00-00' \n\t\t\t\t\t         AND item.itemID = loan.itemID\n               ", $today);
    if (!have_entity_perm("loan", PERM_READ, $current_user, false)) {
        $q .= prepare("AND loan.personID = %d", $current_user->get_id());
    }
    $db->query($q);
    while ($db->next_record()) {
        $i++;
        $item = new item();
        $loan = new loan();
        $item->read_db_record($db);
        $loan->read_db_record($db);
        $item->set_values();
        $loan->set_values();
        $person = new person();
        $person->set_id($loan->get_value("personID"));
        $person->select();
        $TPL["person"] = $person->get_name();
        $TPL["overdue"] = "<a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $item->get_id() . "&return=true\">Overdue!</a>";
        include_template($template_name);
    }
}
 /**
  * Adds item to the business table.
  */
 public function addItem()
 {
     $item = new item();
     $item->createItem($this->input->post(NULL, TRUE));
     $bname = $this->session->userdata('bname');
     $item->bname = $bname;
     if ($this->db->insert('chkitem', $item)) {
         $items = $this->item->getItems($bname);
         echo $this->load->view('templates/item_table', array('items' => $items));
     }
 }
 public function load()
 {
     $db = db::obtain();
     $items = array();
     $items_info = $db->fetch_array_pdo('SELECT * FROM ' . db::real_tablename('items'));
     foreach ($items_info as $item_info) {
         $item = new item();
         $item->set_array($item_info);
         $items[$item_info['id']] = $item;
     }
     return $items;
 }
Example #6
0
 /**
  * Ruft Liste von Text-Sperren ab
  * @return array
  */
 public function getItems()
 {
     $list = $this->dbcon->fetch($this->dbcon->select($this->table), true);
     $res = array();
     foreach ($list as $item) {
         $wbItem = new item();
         if ($wbItem->createFromDbObject($item)) {
             $res[$wbItem->getId()] = $wbItem;
         }
     }
     return $res;
 }
Example #7
0
function show_items($template_name)
{
    global $TPL;
    global $db;
    global $db2;
    $current_user =& singleton("current_user");
    $today = date("Y") . "-" . date("m") . "-" . date("d");
    $dbUsername = new db_alloc();
    $db = new db_alloc();
    $db2 = new db_alloc();
    $db->query("select * from item order by itemName");
    while ($db->next_record()) {
        $i++;
        $item = new item();
        $item->read_db_record($db);
        $db2->query("select * from loan where itemID=" . $item->get_id() . " and dateReturned='0000-00-00'");
        $db2->next_record();
        $loan = new loan();
        $loan->read_db_record($db2);
        $item->set_values();
        // you need to have this repeated here for the a href bit below.
        if ($loan->get_value("dateReturned") == "0000-00-00") {
            if ($loan->have_perm(PERM_READ_WRITE)) {
                // if item is overdue
                if ($loan->get_value("dateToBeReturned") < $today) {
                    $ret = "Return Now!";
                } else {
                    $ret = "Return";
                }
                $TPL["itemAction"] = "<td><a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $TPL["itemID"] . "&return=true\">{$ret}</a></td>";
            } else {
                // if you don't have permission to borrow or return item.
                $TPL["itemAction"] = "<td>&nbsp;</td>";
            }
            $TPL["status"] = "Due " . $loan->get_value("dateToBeReturned");
            $dbUsername->query("select username from person where personID=" . $loan->get_value("personID"));
            $dbUsername->next_record();
            $TPL["person"] = "from " . $dbUsername->f("username");
        } else {
            // if the item is available
            $TPL["status"] = "Available";
            $TPL["person"] = "";
            $TPL["itemAction"] = "<td><a href=\"" . $TPL["url_alloc_item"] . "itemID=" . $TPL["itemID"] . "&borrow=true\">Borrow</a></td>";
            $TPL["dueBack"] = "";
        }
        $loan->set_values();
        $item->set_values();
        include_template($template_name);
    }
}
Example #8
0
 public function add_photo($id)
 {
     $album = ORM::factory("item", $id);
     access::required("view", $album);
     access::required("add", $album);
     access::verify_csrf();
     $file_validation = new Validation($_FILES);
     $file_validation->add_rules("Filedata", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]");
     if ($file_validation->validate()) {
         // SimpleUploader.swf does not yet call /start directly, so simulate it here for now.
         if (!batch::in_progress()) {
             batch::start();
         }
         $temp_filename = upload::save("Filedata");
         try {
             $name = substr(basename($temp_filename), 10);
             // Skip unique identifier Kohana adds
             $title = item::convert_filename_to_title($name);
             $path_info = pathinfo($temp_filename);
             if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
                 $movie = movie::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a movie"), html::anchor("movies/{$movie->id}", t("view movie")));
             } else {
                 $photo = photo::create($album, $temp_filename, $name, $title);
                 log::success("content", t("Added a photo"), html::anchor("photos/{$photo->id}", t("view photo")));
             }
         } catch (Exception $e) {
             unlink($temp_filename);
             throw $e;
         }
         unlink($temp_filename);
     }
     print "File Received";
 }
 public function index()
 {
     if (isset($_GET['cw'])) {
         setcookie('cw_agree', '1', time() + 60 * 60 * 24, '/');
         url::redirect(item::root()->abs_url());
     }
 }
 public function createFile($name, $data = null)
 {
     try {
         access::required("view", $this->item);
         access::required("add", $this->item);
     } catch (Kohana_404_Exception $e) {
         throw new Sabre_DAV_Exception_Forbidden("Access denied");
     }
     if (substr($name, 0, 1) == ".") {
         return true;
     }
     try {
         $tempfile = tempnam(TMPPATH, "dav");
         $target = fopen($tempfile, "wb");
         stream_copy_to_stream($data, $target);
         fclose($target);
         $item = ORM::factory("item");
         $item->name = $name;
         $item->title = item::convert_filename_to_title($item->name);
         $item->description = "";
         $item->parent_id = $this->item->id;
         $item->set_data_file($tempfile);
         $item->type = "photo";
         $item->save();
     } catch (Exception $e) {
         unlink($tempfile);
         throw $e;
     }
 }
Example #11
0
 public function random($item_id)
 {
     $item = ORM::factory("item", $item_id);
     access::required("view", $item);
     item::set_display_context_callback("Albums_Controller::get_display_context");
     url::redirect($item->abs_url());
 }
 /**
  * Create an album for the newly created user and give him view and edit permissions.
  */
 static function user_created($user)
 {
     // Create a group with the same name, if necessary
     $group_name = "auto: {$user->name}";
     $group = identity::lookup_group_by_name($group_name);
     if (!$group) {
         $group = identity::create_group($group_name);
         identity::add_user_to_group($user, $group);
     }
     // Create an album for the user, if it doesn't exist
     $album = ORM::factory("item")->where("parent_id", "=", item::root()->id)->where("name", "=", $user->name)->find();
     if (!$album->loaded()) {
         $album->type = "album";
         $album->name = $user->name;
         $album->title = "{$user->name}'s album";
         $album->parent_id = item::root()->id;
         $album->sort_column = "weight";
         $album->sort_order = "asc";
         $album->save();
         access::allow($group, "view", item::root());
         access::allow($group, "view_full", $album);
         access::allow($group, "edit", $album);
         access::allow($group, "add", $album);
     }
 }
 public function get_test()
 {
     $tag = tag::add(item::root(), "tag1")->reload();
     $request = new stdClass();
     $request->url = rest::url("tag", $tag);
     $this->assert_equal_array(array("url" => rest::url("tag", $tag), "entity" => $tag->as_array(), "relationships" => array("items" => array("url" => rest::url("tag_items", $tag), "members" => array(rest::url("tag_item", $tag, item::root()))))), tag_rest::get($request));
 }
Example #14
0
 static function site_menu($menu, $theme)
 {
     if ($theme->page_type != "login") {
         $menu->append(Menu::factory("link")->id("home")->label(t("Home"))->url(item::root()->url()));
         $item = $theme->item();
         $can_edit = $item && access::can("edit", $item);
         $can_add = $item && access::can("add", $item);
         if ($can_add) {
             $menu->append($add_menu = Menu::factory("submenu")->id("add_menu")->label(t("Add")));
             $add_menu->append(Menu::factory("dialog")->id("add_photos_item")->label(t("Add photos"))->url(url::site("simple_uploader/app/{$item->id}")));
             if ($item->is_album()) {
                 $add_menu->append(Menu::factory("dialog")->id("add_album_item")->label(t("Add an album"))->url(url::site("form/add/albums/{$item->id}?type=album")));
             }
         }
         $menu->append($options_menu = Menu::factory("submenu")->id("options_menu")->label(t("Photo options")));
         if ($item && ($can_edit || $can_add)) {
             if ($can_edit) {
                 $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}")));
             }
             if ($item->is_album()) {
                 $options_menu->label(t("Album options"));
                 if ($can_edit) {
                     $options_menu->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")));
             gallery::admin_menu($admin_menu, $theme);
             module::event("admin_menu", $admin_menu, $theme);
         }
         module::event("site_menu", $menu, $theme);
     }
 }
Example #15
0
 static function get($block_id, $theme)
 {
     $block = "";
     switch ($block_id) {
         case "random_image":
             // The random_query approach is flawed and doesn't always return a
             // result when there actually is one. Retry a *few* times.
             // @todo Consider another fallback if further optimizations are necessary.
             $image_count = module::get_var("image_block", "image_count");
             $items = array();
             for ($i = 0; $i < $image_count; $i++) {
                 $attempts = 0;
                 $item = null;
                 do {
                     $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current();
                 } while (!$item && $attempts++ < 3);
                 if ($item) {
                     $items[] = $item;
                 }
             }
             if ($items) {
                 $block = new Block();
                 $block->css_id = "g-image-block";
                 $block->title = t2("Random image", "Random images", $image_count);
                 $block->content = new View("image_block_block.html");
                 $block->content->items = $items;
             }
             break;
     }
     return $block;
 }
Example #16
0
 static function feed($feed_id, $offset, $limit, $id)
 {
     $feed = new stdClass();
     switch ($feed_id) {
         case "latest":
             $feed->items = ORM::factory("item")->viewable()->where("type", "<>", "album")->order_by("created", "DESC")->find_all($limit, $offset);
             $all_items = ORM::factory("item")->viewable()->where("type", "<>", "album")->order_by("created", "DESC");
             $feed->max_pages = ceil($all_items->find_all()->count() / $limit);
             $feed->title = t("%site_title - Recent updates", array("site_title" => item::root()->title));
             $feed->description = t("Recent updates");
             return $feed;
         case "album":
             $item = ORM::factory("item", $id);
             access::required("view", $item);
             $feed->items = $item->viewable()->descendants($limit, $offset, array(array("type", "=", "photo")));
             $feed->max_pages = ceil($item->viewable()->descendants_count(array(array("type", "=", "photo"))) / $limit);
             if ($item->id == item::root()->id) {
                 $feed->title = html::purify($item->title);
             } else {
                 $feed->title = t("%site_title - %item_title", array("site_title" => item::root()->title, "item_title" => $item->title));
             }
             $feed->description = nl2br(html::purify($item->description));
             return $feed;
     }
 }
Example #17
0
 /**
  * For items that are collections, you can specify the following additional query parameters to
  * query the collection.  You can specify them in any combination.
  *
  *   scope=direct
  *     only return items that are immediately under this one
  *   scope=all
  *     return items anywhere under this one
  *
  *   name=<substring>
  *     only return items where the name contains this substring
  *
  *   random=true
  *     return a single random item
  *
  *   type=<comma separate list of photo, movie or album>
  *     limit the type to types in this list.  eg, "type=photo,movie"
  */
 static function get($request)
 {
     $item = rest::resolve($request->url);
     access::required("view", $item);
     $p = $request->params;
     if (isset($p->random)) {
         $orm = item::random_query()->offset(0)->limit(1);
     } else {
         $orm = ORM::factory("item")->viewable();
     }
     if (empty($p->scope)) {
         $p->scope = "direct";
     }
     if (!in_array($p->scope, array("direct", "all"))) {
         throw new Rest_Exception("Bad Request", 400);
     }
     if ($p->scope == "direct") {
         $orm->where("parent_id", "=", $item->id);
     } else {
         $orm->where("left_ptr", ">", $item->left_ptr);
         $orm->where("right_ptr", "<", $item->right_ptr);
     }
     if (isset($p->name)) {
         $orm->where("name", "LIKE", "%{$p->name}%");
     }
     if (isset($p->type)) {
         $orm->where("type", "IN", explode(",", $p->type));
     }
     $members = array();
     foreach ($orm->find_all() as $child) {
         $members[] = rest::url("item", $child);
     }
     return array("url" => $request->url, "entity" => $item->as_array(), "members" => $members, "relationships" => rest::relationships("item", $item));
 }
 public function get_test()
 {
     $t1 = tag::add(item::root(), "t1");
     $t2 = tag::add(item::root(), "t2");
     $request = new stdClass();
     $this->assert_equal_array(array("url" => rest::url("tags"), "members" => array(rest::url("tag", $t1), rest::url("tag", $t2))), tags_rest::get($request));
 }
 static function get($block_id, $theme)
 {
     if (identity::active_user()->guest) {
         return;
     }
     $block = "";
     switch ($block_id) {
         case "untagged_photo":
             $attempts = 0;
             do {
                 $item = item::random_query()->join("items_tags", "items.id", "items_tags.item_id", "left")->where("items.type", "!=", "album")->where("items_tags.item_id", "IS", null)->find_all(1)->current();
             } while (!$item && $attempts++ < 3);
             if ($item && $item->loaded()) {
                 $block = new Block();
                 $block->css_id = "g-tag-it-block";
                 $block->title = t("Tag it");
                 $block->content = new View("tag_it_block.html");
                 $block->content->item = $item;
                 $form = new Forge("tags/create/{$item->id}", "", "post", array("id" => "g-tag-it-add-tag-form", "class" => "g-short-form"));
                 $label = $item->is_album() ? t("Add tag to album") : ($item->is_photo() ? t("Add tag to photo") : t("Add tag to movie"));
                 $group = $form->group("add_tag")->label("Add Tag");
                 $group->input("name")->label($label)->rules("required")->id("name");
                 $group->hidden("item_id")->value($item->id);
                 $group->submit("")->value(t("Add Tag"));
                 $block->content->form = $form;
             }
             break;
     }
     return $block;
 }
Example #20
0
 public function add_item($item, $amount = 1)
 {
     $it = null;
     if ($it instanceof item) {
         $it = $item;
     } else {
         if (is_numeric($item)) {
             $it = item::load_one($item);
         } else {
             if (is_string($item)) {
                 $it = item::load_one($item, 'name');
             } else {
                 return false;
             }
         }
     }
     $iit = new inventory_item();
     $iit->item_id = $it->id;
     $iit->inventory_id = $this->id;
     $iit->amount = $amount;
     $iit->refine_level = 0;
     $iit->enchantment_id = null;
     $iit->save();
     return $iit;
 }
Example #21
0
 public function create_comment_for_user_test()
 {
     $admin = identity::admin_user();
     $comment = ORM::factory("comment");
     $comment->item_id = item::root()->id;
     $comment->text = "text";
     $comment->author_id = $admin->id;
     $comment->save();
     $this->assert_equal($admin->full_name, $comment->author_name());
     $this->assert_equal($admin->email, $comment->author_email());
     $this->assert_equal($admin->url, $comment->author_url());
     $this->assert_equal("text", $comment->text);
     $this->assert_equal(1, $comment->item_id);
     $this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
     $this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
     $this->assert_equal("HTTP_ACCEPT", $comment->server_http_accept);
     $this->assert_equal("HTTP_ACCEPT_CHARSET", $comment->server_http_accept_charset);
     $this->assert_equal("HTTP_ACCEPT_ENCODING", $comment->server_http_accept_encoding);
     $this->assert_equal("HTTP_ACCEPT_LANGUAGE", $comment->server_http_accept_language);
     $this->assert_equal("HTTP_CONNECTION", $comment->server_http_connection);
     $this->assert_equal("HTTP_HOST", $comment->server_http_host);
     $this->assert_equal("HTTP_REFERER", $comment->server_http_referer);
     $this->assert_equal("HTTP_USER_AGENT", $comment->server_http_user_agent);
     $this->assert_equal("QUERY_STRING", $comment->server_query_string);
     $this->assert_equal("REMOTE_ADDR", $comment->server_remote_addr);
     $this->assert_equal("REMOTE_HOST", $comment->server_remote_host);
     $this->assert_equal("REMOTE_PORT", $comment->server_remote_port);
     $this->assert_true(!empty($comment->created));
 }
 public function delete_test()
 {
     $tag = tag::add(item::root(), "tag1")->reload();
     $request->url = rest::url("tag_item", $tag, item::root());
     tag_item_rest::delete($request);
     $this->assert_false($tag->reload()->has(item::root()));
 }
Example #23
0
 public function change()
 {
     access::verify_csrf();
     $active_provider = module::get_var("gallery", "identity_provider", "user");
     $providers = identity::providers();
     $new_provider = Input::instance()->post("provider");
     if ($new_provider != $active_provider) {
         module::deactivate($active_provider);
         // Switch authentication
         identity::reset();
         module::set_var("gallery", "identity_provider", $new_provider);
         module::install($new_provider);
         module::activate($new_provider);
         module::event("identity_provider_changed", $active_provider, $new_provider);
         module::uninstall($active_provider);
         message::success(t("Changed to %description", array("description" => $providers->{$new_provider})));
         try {
             Session::instance()->destroy();
         } catch (Exception $e) {
             // We don't care if there was a problem destroying the session.
         }
         url::redirect(item::root()->abs_url());
     }
     message::info(t("The selected provider \"%description\" is already active.", array("description" => $providers->{$new_provider})));
     url::redirect("admin/identity");
 }
Example #24
0
 static function fix_internet_addresses($task)
 {
     $start = microtime(true);
     $total = $task->get("total");
     if (empty($total)) {
         $task->set("total", $total = db::build()->count_records("items"));
         $task->set("last_id", 0);
         $task->set("completed", 0);
     }
     $last_id = $task->get("last_id");
     $completed = $task->get("completed");
     foreach (ORM::factory("item")->where("id", ">", $last_id)->find_all(100) as $item) {
         $item->slug = item::convert_filename_to_slug($item->slug);
         $item->save();
         $last_id = $item->id;
         $completed++;
         if ($completed == $total || microtime(true) - $start > 1.5) {
             break;
         }
     }
     $task->set("completed", $completed);
     $task->set("last_id", $last_id);
     if ($total == $completed) {
         $task->done = true;
         $task->state = "success";
         $task->percent_complete = 100;
         db::build()->update("items")->set("relative_path_cache", null)->set("relative_url_cache", null)->execute();
     } else {
         $task->percent_complete = round(100 * $completed / $total);
     }
     $task->status = t2("One row updated", "%count / %total rows updated", $completed, array("total" => $total));
 }
Example #25
0
 public function show($page_name)
 {
     // Display the page specified by $page_name, or a 404 error if it doesn't exist.
     // Run a database search to look up the page.
     $existing_page = ORM::factory("px_static_page")->where("name", "=", $page_name)->find_all();
     // If it doesn't exist, display a 404 error.
     if (count($existing_page) == 0) {
         throw new Kohana_404_Exception();
     }
     // Set up breadcrumbs.
     $breadcrumbs = array();
     $root = item::root();
     $breadcrumbs[] = Breadcrumb::instance($root->title, $root->url())->set_first();
     $breadcrumbs[] = Breadcrumb::instance(t($existing_page[0]->title), url::site("pages_xtra/show/{$page_name}"))->set_last();
     // Display the page.
     $template = new Theme_View("page.html", "other", "Pages");
     $template->set_global(array("breadcrumbs" => $breadcrumbs));
     //  Call database variables into page header (off-page content).
     $site_title = module::get_var("pages_xtra", "site_title");
     //  Next line can be used as alternative to the following line
     //  $template->page_title = t("Gallery :: ") . t($existing_page[0]->title);
     $template->page_title = t($existing_page[0]->title) . t(" :: {$site_title}");
     $template->page_tags = $existing_page[0]->tags;
     $page_tags = trim(nl2br(html::purify($existing_page[0]->tags)));
     $template->page_description = $existing_page[0]->description;
     $page_description = trim(nl2br(html::purify($existing_page[0]->description)));
     //  Set a new View and call database variables into page (on-page content).
     $template->content = new View("pages_xtra_display.html");
     $template->content->title = $existing_page[0]->title;
     $template->content->body = $existing_page[0]->html_code;
     print $template;
 }
Example #26
0
 /**
  * Redirect Gallery 2 urls to their appropriate matching Gallery 3 url.
  *
  * We use mod_rewrite to create this path, so Gallery2 urls like this:
  *   /gallery2/v/Family/Wedding.jpg.html
  *   /gallery2/main.php?g2_view=core.ShowItem&g2_itemId=1234
  *
  * Show up here like this:
  *   /g2/map?path=v/Family/Wedding.jpg.html
  *   /g2/map?g2_view=core.ShowItem&g2_itemId=1931
  */
 public function map()
 {
     $input = Input::instance();
     $path = $input->get("path");
     $id = $input->get("g2_itemId");
     if ($path && $path != 'index.php' && $path != 'main.php' || $id) {
         if ($id) {
             // Requests by id are either core.DownloadItem or core.ShowItem requests. Later versions of
             // Gallery 2 don't specify g2_view if it's the default (core.ShowItem). And in some cases
             // (bbcode, embedding) people are using the id style URLs although URL rewriting is enabled.
             $where = array(array("g2_id", "=", $id));
             $view = $input->get("g2_view");
             if ($view == "core.DownloadItem") {
                 $where[] = array("resource_type", "IN", array("file", "resize", "thumbnail", "full"));
             } else {
                 if ($view) {
                     $where[] = array("g2_url", "like", "%g2_view={$view}%");
                 }
             }
             // else: Assuming that the first search hit is sufficiently good.
         } else {
             if ($path) {
                 $where = array(array("g2_url", "IN", array($path, str_replace(" ", "+", $path))));
             } else {
                 throw new Kohana_404_Exception();
             }
         }
         $g2_map = ORM::factory("g2_map")->merge_where($where)->find();
         if (!$g2_map->loaded()) {
             throw new Kohana_404_Exception();
         }
         $item = ORM::factory("item", $g2_map->g3_id);
         if (!$item->loaded()) {
             throw new Kohana_404_Exception();
         }
         $resource_type = $g2_map->resource_type;
     } else {
         $item = item::root();
         $resource_type = "album";
     }
     access::required("view", $item);
     // Redirect the user to the new url
     switch ($resource_type) {
         case "thumbnail":
             url::redirect($item->thumb_url(true));
         case "resize":
             url::redirect($item->resize_url(true));
         case "file":
         case "full":
             url::redirect($item->file_url(true));
         case "item":
         case "album":
             url::redirect($item->abs_url());
         case "group":
         case "user":
         default:
             throw new Kohana_404_Exception();
     }
 }
Example #27
0
 public function item()
 {
     static $item = null;
     if (!$item) {
         $item = item::load_one($this->item_id);
     }
     return $item;
 }
Example #28
0
 public function post_test()
 {
     access::allow(identity::everybody(), "edit", item::root());
     $request = new stdClass();
     $request->params = new stdClass();
     $request->params->name = "test tag";
     $this->assert_equal(array("url" => url::site("rest/tag/1")), tags_rest::post($request));
 }
Example #29
0
 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}")));
 }
Example #30
0
function bag_get($member_id, $slot)
{
    $item = item::fetchOneItem($member_id, $slot);
    if ($item) {
        return new bag($item->data);
    } else {
        return null;
    }
}