Пример #1
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));
 }
Пример #2
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;
 }
Пример #3
0
 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;
 }
Пример #4
0
 static function get($block_id, $theme)
 {
     $block = "";
     switch ($block_id) {
         case "random_image":
             $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current();
             if ($item && $item->loaded()) {
                 $block = new Block();
                 $block->css_id = "g-image-block";
                 $block->title = t("Random image");
                 $block->content = new View("image_block_block.html");
                 $block->content->item = $item;
             }
             break;
     }
     return $block;
 }
Пример #5
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".
  *     Also limits the types returned in the member collections (same behaviour as item_rest).
  */
 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", "%" . Database::escape_for_like($p->name) . "%");
     }
     if (isset($p->type)) {
         $orm->where("type", "IN", explode(",", $p->type));
     }
     // Apply the item's sort order, using id as the tie breaker.
     // See Item_Model::children()
     $order_by = array($item->sort_column => $item->sort_order);
     if ($item->sort_column != "id") {
         $order_by["id"] = "ASC";
     }
     $orm->order_by($order_by);
     $result = array("url" => $request->url, "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item));
     if ($item->is_album()) {
         $result["members"] = array();
         foreach ($orm->find_all() as $child) {
             $result["members"][] = rest::url("item", $child);
         }
     }
     return $result;
 }
Пример #6
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.
             $attempts = 0;
             do {
                 $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current();
             } while (!$item && $attempts++ < 3);
             if ($item && $item->loaded()) {
                 $block = new Block();
                 $block->css_id = "g-image-block";
                 $block->title = t("Random image");
                 $block->content = new View("image_block_block.html");
                 $block->content->item = $item;
             }
             break;
     }
     return $block;
 }
Пример #7
0
 public function get_thumb_element($item, $addcontext = FALSE, $linkonly = FALSE)
 {
     $thumb_item = $item;
     if ($this->thumb_random) {
         if ($item->is_album() && ($rnd = item::random_query()->where("parent_id", "=", $item->id)->find()) && $rnd->loaded()) {
             $thumb_item = $rnd;
         }
     }
     $item_class = $item->is_album() ? "g-album" : "g-photo";
     $content = '<li id="g-item-id-' . $item->id . '" class="g-item ' . $item_class . ' ' . $this->thumb_type;
     if ($item->is_album()) {
         $_thumb_descmode = $this->thumb_descmode_a;
     } else {
         $_thumb_descmode = $this->thumb_descmode;
     }
     $content .= $_thumb_descmode == "bottom" ? " g-expanded" : " g-default";
     if ($thumb_item->has_thumb()) {
         $is_portrait = $thumb_item->thumb_height > $thumb_item->thumb_width;
         $_shift = "";
         switch ($this->thumb_imgalign) {
             case "center":
                 if ($this->crop_factor == 1 and !$is_portrait) {
                     $_shift = 'style="margin-top: ' . intval(($this->_thumb_size_y - $thumb_item->thumb_height) / 2) . 'px;"';
                 } elseif ($this->crop_factor > 0) {
                     $_shift = 'style="margin-top: -' . intval(($thumb_item->thumb_height - $this->_thumb_size_y) / 2) . 'px;"';
                 }
                 break;
             case "bottom":
                 if ($this->crop_factor == 1 and !$is_portrait) {
                     $_shift = 'style="margin-top: ' . intval($this->_thumb_size_y - $thumb_item->thumb_height) . 'px;"';
                 } elseif ($this->crop_factor > 0) {
                     $_shift = 'style="margin-top: -' . intval($thumb_item->thumb_height - $this->_thumb_size_y) . 'px;"';
                 }
                 break;
             case "fit":
                 break;
             case "top":
             default:
                 break;
         }
     } else {
         $is_portrait = FALSE;
         $_shift = 'style="margin-top: 0px;"';
     }
     $content .= $is_portrait ? " g-portrait" : " g-landscape";
     $content .= '">' . $this->thumb_top($item);
     $content .= '<div class="g-thumbslide">';
     $thumb_content = '<p class="g-thumbcrop">';
     $use_direct_link = $this->disablephotopage && !$item->is_album();
     $class_name = "g-thumblink";
     if ($use_direct_link) {
         $class_name .= ' g-sb-preview" rel="g-preview';
         if (access::can("view_full", $item)) {
             $direct_link = $item->file_url();
         } else {
             $direct_link = $item->resize_url();
         }
     } else {
         $direct_link = $item->url();
     }
     if ($use_direct_link && module::is_active("exif") && module::info("exif")) {
         $thumb_content .= '<a class="g-meta-exif-link g-dialog-link" href="' . url::site("exif/show/{$item->id}") . '" title="' . t("Photo details")->for_html_attr() . '">&nbsp;</a>';
     }
     $thumb_content .= '<a title="' . $this->get_item_title($item) . '" ' . $_shift . ' class="' . $class_name . '" href="' . $direct_link . '">';
     if ($thumb_item->has_thumb()) {
         if ($this->crop_factor > 1 && $this->thumb_imgalign == "fit") {
             if ($thumb_item->thumb_height > $this->_thumb_size_y) {
                 if ($is_portrait) {
                     $_max = $this->_thumb_size_y;
                 } else {
                     $_max = intval($this->_thumb_size_x * ($this->_thumb_size_y / $thumb_item->thumb_height));
                 }
             } else {
                 $_max = $this->_thumb_size_x;
             }
             $_max = min($thumb_item->thumb_width, $_max);
             $thumb_content .= $thumb_item->thumb_img(array(), $_max);
         } else {
             $thumb_content .= $thumb_item->thumb_img();
         }
     } else {
         $thumb_content .= '<img title="No Image" alt="No Image" src="' . $this->url("images/missing-img.png") . '"/>';
     }
     $thumb_content .= '</a></p>';
     if ($this->thumb_metamode != "hide" and $_thumb_descmode == "overlay_bottom") {
         $_thumb_metamode = "merged";
     } else {
         $_thumb_metamode = $this->thumb_metamode;
     }
     if ($_thumb_descmode == "overlay" or $_thumb_descmode == "overlay_top" or $_thumb_descmode == "overlay_bottom") {
         $thumb_content .= '<ul class="g-description ';
         if ($_thumb_descmode == "overlay_top") {
             $thumb_content .= 'g-overlay-top';
         }
         if ($_thumb_descmode == "overlay_bottom") {
             $thumb_content .= 'g-overlay-bottom';
         }
         $thumb_content .= '"><li class="g-title">' . $this->get_item_title($item, FALSE, $this->visible_title_length) . '</li>';
         if ($_thumb_metamode == "merged") {
             $thumb_content .= $this->thumb_info($item);
         }
         $thumb_content .= '</ul>';
     }
     if ($_thumb_metamode == "default" and $_thumb_descmode != "overlay_bottom") {
         $thumb_content .= '<ul class="g-metadata">' . $this->thumb_info($item) . '</ul>';
     }
     if ($_thumb_descmode == "bottom") {
         $thumb_content .= '<ul class="g-description">';
         $thumb_content .= '<li class="g-title">' . $this->get_item_title($item) . '</li>';
         if ($_thumb_metamode == "merged") {
             $thumb_content .= $this->thumb_info($item);
         }
         $thumb_content .= '</ul>';
     }
     if ($addcontext) {
         $_text = $this->context_menu($item, "#g-item-id-{$item->id} .g-thumbnail");
         $thumb_content .= stripos($_text, '<li>') ? $_text : null;
     }
     try {
         $view = new View("frame.html");
         $view->thumb_content = $thumb_content;
         $content .= $view;
     } catch (Exception $e) {
         $content .= $thumb_content;
     }
     $content .= '</div>';
     $content .= $this->thumb_bottom($item);
     $content .= '</li>';
     return $content;
 }