本文整理汇总了PHP中item::make_album_cover方法的典型用法代码示例。如果您正苦于以下问题:PHP item::make_album_cover方法的具体用法?PHP item::make_album_cover怎么用?PHP item::make_album_cover使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item
的用法示例。
在下文中一共展示了item::make_album_cover方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: make_album_cover
static function make_album_cover($item)
{
$parent = $item->parent();
access::required("view", $item);
access::required("view", $parent);
access::required("edit", $parent);
$old_album_cover_id = $parent->album_cover_item_id;
model_cache::clear();
$parent->album_cover_item_id = $item->is_album() ? $item->album_cover_item_id : $item->id;
$parent->save();
graphics::generate($parent);
// Walk up the parent hierarchy and set album covers if necessary
$grand_parent = $parent->parent();
if ($grand_parent && access::can("edit", $grand_parent) && $grand_parent->album_cover_item_id == null) {
item::make_album_cover($parent);
}
// When albums are album covers themselves, we hotlink directly to the target item. This
// means that when we change an album cover, the grandparent may have a deep link to the old
// album cover. So find any parent albums that had the old item as their album cover and
// switch them over to the new item.
if ($old_album_cover_id) {
foreach ($item->parents(array(array("album_cover_item_id", "=", $old_album_cover_id))) as $ancestor) {
if (access::can("edit", $ancestor)) {
$ancestor->album_cover_item_id = $parent->album_cover_item_id;
$ancestor->save();
graphics::generate($ancestor);
}
}
}
}
示例2: make_album_cover
public function make_album_cover($id)
{
access::verify_csrf();
$item = model_cache::get("item", $id);
access::required("view", $item);
access::required("view", $item->parent());
access::required("edit", $item->parent());
item::make_album_cover($item);
print json_encode(array("result" => "success"));
}
示例3: make_album_cover
public function make_album_cover($id)
{
access::verify_csrf();
$item = model_cache::get("item", $id);
access::required("view", $item);
access::required("view", $item->parent());
access::required("edit", $item->parent());
$msg = t("Made <b>%title</b> this album's cover", array("title" => html::purify($item->title)));
item::make_album_cover($item);
message::success($msg);
print json_encode(array("result" => "success", "reload" => 1));
}
示例4: run
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: make_album_cover
static function make_album_cover($item)
{
$parent = $item->parent();
access::required("edit", $parent);
model_cache::clear("item", $parent->album_cover_item_id);
$parent->album_cover_item_id = $item->is_album() ? $item->album_cover_item_id : $item->id;
$parent->thumb_dirty = 1;
$parent->save();
graphics::generate($parent);
$grand_parent = $parent->parent();
if ($grand_parent && $grand_parent->album_cover_item_id == null) {
item::make_album_cover($parent);
}
}
示例6: item_created
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);
}
}
}
示例7: save
public function save($source_id)
{
access::verify_csrf();
$source = ORM::factory("item", $source_id);
$target = ORM::factory("item", Input::instance()->post("target_id"));
access::required("view", $source);
access::required("view", $target);
access::required("edit", $target);
model_cache::clear();
$target->album_cover_item_id = $source->is_album() ? $source->album_cover_item_id : $source->id;
$target->thumb_dirty = 1;
$target->save();
graphics::generate($target);
$grand_parent = $target->parent();
if ($grand_parent && access::can("edit", $grand_parent) && $grand_parent->album_cover_item_id == null) {
item::make_album_cover($target);
}
$msg = t("Made <b>%title</b> album's cover for <b>%album</b>", array("title" => html::purify($source->title), "album" => html::purify($target->title)));
message::success($msg);
json::reply(array("result" => "success"));
}
示例8: create
/**
* Create a new photo.
* @param integer $parent_id id of parent album
* @param string $filename path to the photo file on disk
* @param string $name the filename to use for this photo in the album
* @param integer $title the title of the new photo
* @param string $description (optional) the longer description of this photo
* @return Item_Model
*/
static function create($parent, $filename, $name, $title, $description = null, $owner_id = null)
{
if (!$parent->loaded || !$parent->is_album()) {
throw new Exception("@todo INVALID_PARENT");
}
if (!is_file($filename)) {
throw new Exception("@todo MISSING_IMAGE_FILE");
}
if (strpos($name, "/")) {
throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
}
// We don't allow trailing periods as a security measure
// ref: http://dev.kohanaphp.com/issues/684
if (rtrim($name, ".") != $name) {
throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD");
}
if (filesize($filename) == 0) {
throw new Exception("@todo EMPTY_INPUT_FILE");
}
$image_info = getimagesize($filename);
// Force an extension onto the name
$pi = pathinfo($filename);
if (empty($pi["extension"])) {
$pi["extension"] = image_type_to_extension($image_info[2], false);
$name .= "." . $pi["extension"];
}
$photo = ORM::factory("item");
$photo->type = "photo";
$photo->title = $title;
$photo->description = $description;
$photo->name = $name;
$photo->owner_id = $owner_id ? $owner_id : user::active();
$photo->width = $image_info[0];
$photo->height = $image_info[1];
$photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime'];
$photo->thumb_dirty = 1;
$photo->resize_dirty = 1;
$photo->sort_column = "weight";
$photo->rand_key = (double) mt_rand() / (double) mt_getrandmax();
// Randomize the name if there's a conflict
while (ORM::factory("item")->where("parent_id", $parent->id)->where("name", $photo->name)->find()->id) {
// @todo Improve this. Random numbers are not user friendly
$photo->name = rand() . "." . $pi["extension"];
}
// This saves the photo
$photo->add_to_parent($parent);
/*
* If the thumb or resize already exists then rename it. We need to do this after the save
* because the resize_path and thumb_path both call relative_path which caches the
* path. Before add_to_parent the relative path will be incorrect.
*/
if (file_exists($photo->resize_path()) || file_exists($photo->thumb_path())) {
$photo->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"];
$photo->save();
}
copy($filename, $photo->file_path());
// @todo: publish this from inside Item_Model::save() when we refactor to the point where
// there's only one save() happening here.
module::event("item_created", $photo);
// Build our thumbnail/resizes. If we fail to build thumbnail/resize we assume that the image
// is bad in some way and discard it.
try {
graphics::generate($photo);
} catch (Exception $e) {
$photo->delete();
throw $e;
}
// If the parent has no cover item, make this it.
if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
item::make_album_cover($photo);
}
return $photo;
}
示例9: make_tag_album_cover
public function make_tag_album_cover($id, $tag_id, $album_id)
{
if (!identity::active_user()->admin) {
message::error(t("You do not have sufficient privileges to do this"));
url::redirect("tag_albums/show/" . $id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($item->name));
}
$item = ORM::factory("item", $id);
if ($album_id > 0 && $tag_id == 0) {
// If we are dealing with a dynamic album, set it's thumbnail to this pics.
// Based on modules/gallery/helpers/item.php
$album_tags = ORM::factory("tags_album_id")->where("id", "=", $album_id)->find_all();
if (count($album_tags) > 0) {
$parent = ORM::factory("item", $album_tags[0]->album_id);
$parent->album_cover_item_id = $item->id;
$parent->thumb_dirty = 1;
graphics::generate($parent);
$parent->save();
$grand_parent = $parent->parent();
if ($grand_parent && access::can("edit", $grand_parent) && $grand_parent->album_cover_item_id == null) {
item::make_album_cover($parent);
}
}
message::success(t("Made " . $item->title . " this album's cover"));
url::redirect("tag_albums/show/" . $id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($item->name));
} else {
// If setting a thumbnail for an auto-generated all tags->tag album.
$record = ORM::factory("tags_album_tag_cover")->where("tag_id", "=", $tag_id)->find();
if (!$record->loaded()) {
$record->tag_id = $tag_id;
}
$record->photo_id = $id;
$record->save();
message::success(t("Made " . $item->title . " this album's cover"));
url::redirect("tag_albums/show/" . $id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($item->name));
}
}
示例10: create
/**
* Create a new movie.
* @param integer $parent_id id of parent album
* @param string $filename path to the photo file on disk
* @param string $name the filename to use for this photo in the album
* @param integer $title the title of the new photo
* @param string $description (optional) the longer description of this photo
* @return Item_Model
*/
static function create($parent, $filename, $name, $title, $description = null, $owner_id = null)
{
if (!$parent->loaded || !$parent->is_album()) {
throw new Exception("@todo INVALID_PARENT");
}
if (!is_file($filename)) {
throw new Exception("@todo MISSING_MOVIE_FILE");
}
if (strpos($name, "/")) {
throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH");
}
// We don't allow trailing periods as a security measure
// ref: http://dev.kohanaphp.com/issues/684
if (rtrim($name, ".") != $name) {
throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD");
}
try {
$movie_info = movie::getmoviesize($filename);
} catch (Exception $e) {
// Assuming this is MISSING_FFMPEG for now
$movie_info = getimagesize(MODPATH . "gallery/images/missing_movie.png");
}
// Force an extension onto the name
$pi = pathinfo($filename);
if (empty($pi["extension"])) {
$pi["extension"] = image_type_to_extension($movie_info[2], false);
$name .= "." . $pi["extension"];
}
$movie = ORM::factory("item");
$movie->type = "movie";
$movie->title = $title;
$movie->description = $description;
$movie->name = $name;
$movie->owner_id = $owner_id ? $owner_id : user::active();
$movie->width = $movie_info[0];
$movie->height = $movie_info[1];
$movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv";
$movie->thumb_dirty = 1;
$movie->resize_dirty = 1;
$movie->sort_column = "weight";
$movie->rand_key = (double) mt_rand() / (double) mt_getrandmax();
// Randomize the name if there's a conflict
while (ORM::factory("item")->where("parent_id", $parent->id)->where("name", $movie->name)->find()->id) {
// @todo Improve this. Random numbers are not user friendly
$movie->name = rand() . "." . $pi["extension"];
}
// This saves the photo
$movie->add_to_parent($parent);
// If the thumb or resize already exists then rename it
if (file_exists($movie->resize_path()) || file_exists($movie->thumb_path())) {
$movie->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"];
$movie->save();
}
copy($filename, $movie->file_path());
// @todo: publish this from inside Item_Model::save() when we refactor to the point where
// there's only one save() happening here.
module::event("item_created", $movie);
// Build our thumbnail
graphics::generate($movie);
// If the parent has no cover item, make this it.
if (access::can("edit", $parent) && $parent->album_cover_item_id == null) {
item::make_album_cover($movie);
}
return $movie;
}
示例11: make_album_cover
static function make_album_cover($item)
{
$parent = $item->parent();
access::required("view", $item);
access::required("view", $parent);
access::required("edit", $parent);
model_cache::clear();
$parent->album_cover_item_id = $item->is_album() ? $item->album_cover_item_id : $item->id;
if ($item->thumb_dirty) {
$parent->thumb_dirty = 1;
graphics::generate($parent);
} else {
copy($item->thumb_path(), $parent->thumb_path());
$parent->thumb_width = $item->thumb_width;
$parent->thumb_height = $item->thumb_height;
}
$parent->save();
$grand_parent = $parent->parent();
if ($grand_parent && access::can("edit", $grand_parent) && $grand_parent->album_cover_item_id == null) {
item::make_album_cover($parent);
}
}
示例12: item_moved
static function item_moved($item, $old_parent)
{
if ($item->is_album()) {
access::recalculate_album_permissions($item->parent());
} else {
access::recalculate_photo_permissions($item);
}
// If the new parent doesn't have an album cover, make this it.
if (!$item->parent()->album_cover_item_id) {
item::make_album_cover($item);
}
}
示例13: make_album_cover
public function make_album_cover($id)
{
access::verify_csrf();
item::make_album_cover(ORM::factory("item", $id));
print json_encode(array("result" => "success"));
}