本文整理汇总了PHP中Image::by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::by_id方法的具体用法?PHP Image::by_id怎么用?PHP Image::by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_image
/**
* Generate the necessary DataUploadEvent for a given image and tags.
*/
private function add_image($tmpname, $filename, $tags, $source, $rating, $thumbfile)
{
assert(file_exists($tmpname));
$pathinfo = pathinfo($filename);
if (!array_key_exists('extension', $pathinfo)) {
throw new UploadException("File has no extension");
}
$metadata = array();
$metadata['filename'] = $pathinfo['basename'];
$metadata['extension'] = $pathinfo['extension'];
$metadata['tags'] = $tags;
$metadata['source'] = $source;
$event = new DataUploadEvent($tmpname, $metadata);
send_event($event);
if ($event->image_id == -1) {
throw new UploadException("File type not recognised");
} else {
if (class_exists("RatingSetEvent") && in_array($rating, array("s", "q", "e"))) {
$ratingevent = new RatingSetEvent(Image::by_id($event->image_id), $rating);
send_event($ratingevent);
}
if (file_exists($thumbfile)) {
copy($thumbfile, warehouse_path("thumbs", $event->hash));
}
}
}
示例2: onPageRequest
public function onPageRequest(PageRequestEvent $event)
{
global $page, $user;
if ($event->page_matches("regen_thumb") && $user->can("delete_image") && isset($_POST['image_id'])) {
$image = Image::by_id(int_escape($_POST['image_id']));
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
$this->theme->display_results($page, $image);
}
}
示例3: onPageRequest
public function onPageRequest($event)
{
global $config, $database, $page, $user;
if ($event->page_matches("regen_thumb") && $user->is_admin() && isset($_POST['image_id'])) {
$image = Image::by_id(int_escape($_POST['image_id']));
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext));
$this->theme->display_results($page, $image);
}
}
示例4: onPageRequest
public function onPageRequest(PageRequestEvent $event)
{
global $config, $database, $page;
if ($event->page_matches("get_svg")) {
$id = int_escape($event->get_arg(0));
$image = Image::by_id($id);
$hash = $image->hash;
$page->set_type("image/svg+xml");
$page->set_mode("data");
$page->set_data(file_get_contents(warehouse_path("images", $hash)));
}
}
示例5: display_resize_page
public function display_resize_page(Page $page, $image_id)
{
global $config;
$default_width = $config->get_int('resize_default_width');
$default_height = $config->get_int('resize_default_height');
$image = Image::by_id($image_id);
$thumbnail = $this->build_thumb_html($image, null);
$html = "<div style='clear:both;'></div>\n\t\t\t\t<p>Resize Image ID " . $image_id . "<br>" . $thumbnail . "</p>\n\t\t\t\t<p>Please note: You will have to refresh the image page, or empty your browser cache.</p>\n\t\t\t\t<p>Enter the new size for the image, or leave blank to scale the image automatically.</p><br>" . make_form(make_link('resize/' . $image_id), 'POST', $multipart = True, 'form_resize') . "\n\t\t\t\t<input type='hidden' name='image_id' value='{$image_id}'>\n\t\t\t\t<table id='large_upload_form'>\n\t\t\t\t\t<tr><td>New Width</td><td colspan='3'><input id='resize_width' name='resize_width' type='text' value='" . $default_width . "'></td></tr>\n\t\t\t\t\t<tr><td>New Height</td><td colspan='3'><input id='resize_height' name='resize_height' type='text' value='" . $default_height . "'></td></tr>\n\t\t\t\t\t<tr><td colspan='4'><input id='resizebutton' type='submit' value='Resize'></td></tr>\n\t\t\t\t</table>\n\t\t\t</form>\n\t\t";
$page->set_title("Resize Image");
$page->set_heading("Resize Image");
$page->add_block(new NavBlock());
$page->add_block(new Block("Resize Image", $html, "main", 20));
}
示例6: onPageRequest
public function onPageRequest(PageRequestEvent $event)
{
global $config, $database, $page, $user;
if ($event->page_matches("image_hash_ban")) {
if ($user->is_admin()) {
if ($event->get_arg(0) == "dnp") {
$image = Image::by_id(int_escape($event->get_arg(1)));
if ($image) {
send_event(new AddImageHashBanEvent($image->hash, "DNP"));
send_event(new ImageDeletionEvent($image));
}
$page->set_mode("redirect");
$page->set_redirect($_SERVER["HTTP_REFERER"]);
} else {
if ($event->get_arg(0) == "add") {
if (isset($_POST['hash']) && isset($_POST['reason'])) {
send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason']));
$page->set_mode("redirect");
$page->set_redirect(make_link("image_hash_ban/list/1"));
}
if (isset($_POST['image_id'])) {
$image = Image::by_id(int_escape($_POST['image_id']));
if ($image) {
send_event(new ImageDeletionEvent($image));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list"));
}
}
} else {
if ($event->get_arg(0) == "remove") {
if (isset($_POST['hash'])) {
send_event(new RemoveImageHashBanEvent($_POST['hash']));
$page->set_mode("redirect");
$page->set_redirect(make_link("image_hash_ban/list/1"));
}
} else {
if ($event->get_arg(0) == "list") {
$page_num = 0;
if ($event->count_args() == 2) {
$page_num = int_escape($event->get_arg(1));
}
$page_size = 100;
$page_count = ceil($database->get_one("SELECT COUNT(id) FROM image_bans") / $page_size);
$this->theme->display_Image_hash_Bans($page, $page_num, $page_count, $this->get_image_hash_bans($page_num, $page_size));
}
}
}
}
}
}
}
示例7: receive_event
public function receive_event(Event $event)
{
if (is_null($this->theme)) {
$this->theme = get_theme_object($this);
}
if ($event instanceof DataUploadEvent && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
$hash = $event->hash;
$ha = substr($hash, 0, 2);
if (!move_upload_to_archive($event)) {
return;
}
send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
$image = $this->create_image_from_data(warehouse_path("images", $hash), $event->metadata);
if (is_null($image)) {
throw new UploadException("SVG handler failed to create image object from data");
}
$iae = new ImageAdditionEvent($event->user, $image);
send_event($iae);
$event->image_id = $iae->image->id;
}
if ($event instanceof ThumbnailGenerationEvent && $this->supported_ext($event->type)) {
$hash = $event->hash;
$ha = substr($hash, 0, 2);
global $config;
// if($config->get_string("thumb_engine") == "convert") {
// $w = $config->get_int("thumb_width");
// $h = $config->get_int("thumb_height");
// $q = $config->get_int("thumb_quality");
// $mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB
//
// exec("convert images/{$ha}/{$hash}[0] -geometry {$w}x{$h} -quality {$q} jpg:thumbs/{$ha}/{$hash}");
// }
// else {
copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash));
// }
}
if ($event instanceof DisplayingImageEvent && $this->supported_ext($event->image->ext)) {
global $page;
$this->theme->display_image($page, $event->image);
}
if ($event instanceof PageRequestEvent && $event->page_matches("get_svg")) {
global $config, $database, $page;
$id = int_escape($event->get_arg(0));
$image = Image::by_id($id);
$hash = $image->hash;
$page->set_type("image/svg+xml");
$page->set_mode("data");
$page->set_data(file_get_contents(warehouse_path("images", $hash)));
}
}
示例8: onPostListBuilding
public function onPostListBuilding($event)
{
global $config, $page, $user;
$fid = $config->get_int("featured_id");
if ($fid > 0) {
$image = Image::by_id($fid);
if (!is_null($image)) {
if (class_exists("Ratings")) {
if (strpos(Ratings::get_user_privs($user), $image->rating) === FALSE) {
return;
}
}
$this->theme->display_featured($page, $image);
}
}
}
示例9: onPageRequest
public function onPageRequest(PageRequestEvent $event)
{
global $database, $page;
if ($event->page_matches("api/shimmie")) {
$page->set_mode("data");
$page->set_type("text/plain");
if ($event->page_matches("api/shimmie/get_tags")) {
if ($event->count_args() == 2) {
$all = $database->get_all("SELECT tag FROM tags WHERE tag LIKE ?", array($event->get_arg(0) . "%"));
} else {
$all = $database->get_all("SELECT tag FROM tags");
}
$res = array();
foreach ($all as $row) {
$res[] = $row["tag"];
}
$page->set_data(json_encode($res));
}
if ($event->page_matches("api/shimmie/get_image")) {
$image = Image::by_id(int_escape($event->get_arg(0)));
$image->get_tag_array();
// tag data isn't loaded into the object until necessary
$safe_image = new _SafeImage($image);
$page->set_data(json_encode($safe_image));
}
if ($event->page_matches("api/shimmie/find_images")) {
$search_terms = $event->get_search_terms();
$page_number = $event->get_page_number();
$page_size = $event->get_page_size();
$images = Image::find_images(($page_number - 1) * $page_size, $page_size, $search_terms);
$safe_images = array();
foreach ($images as $image) {
$image->get_tag_array();
$safe_images[] = new _SafeImage($image);
}
$page->set_data(json_encode($safe_images));
}
}
}
示例10: onPostListBuilding
public function onPostListBuilding(PostListBuildingEvent $event)
{
global $config, $database, $page, $user;
$fid = $config->get_int("featured_id");
if ($fid > 0) {
$image = $database->cache->get("featured_image_object:{$fid}");
if ($image === false) {
$image = Image::by_id($fid);
if ($image) {
// make sure the object is fully populated before saving
$image->get_tag_array();
}
$database->cache->set("featured_image_object:{$fid}", $image, 600);
}
if (!is_null($image)) {
if (class_exists("Ratings")) {
if (strpos(Ratings::get_user_privs($user), $image->rating) === FALSE) {
return;
}
}
$this->theme->display_featured($page, $image);
}
}
}
示例11: add_comment_wrapper
private function add_comment_wrapper($image_id, $user, $comment, $event)
{
global $database;
global $config;
// basic sanity checks
if (!$config->get_bool('comment_anon') && $user->is_anonymous()) {
throw new CommentPostingException("Anonymous posting has been disabled");
} else {
if (is_null(Image::by_id($image_id))) {
throw new CommentPostingException("The image does not exist");
} else {
if (trim($comment) == "") {
throw new CommentPostingException("Comments need text...");
} else {
if (strlen($comment) > 9000) {
throw new CommentPostingException("Comment too long~");
} else {
if (strlen($comment) / strlen(gzcompress($comment)) > 10) {
throw new CommentPostingException("Comment too repetitive~");
} else {
if ($user->is_anonymous() && !$this->hash_match()) {
throw new CommentPostingException("Comment submission form is out of date; refresh the " . "comment form to show you aren't a spammer~");
} else {
if ($this->is_comment_limit_hit()) {
throw new CommentPostingException("You've posted several comments recently; wait a minute and try again...");
} else {
if ($this->is_dupe($image_id, $comment)) {
throw new CommentPostingException("Someone already made that comment on that image -- try and be more original?");
} else {
if ($config->get_bool('comment_captcha') && !captcha_check()) {
throw new CommentPostingException("Error in captcha");
} else {
if ($user->is_anonymous() && $this->is_spam_akismet($comment)) {
throw new CommentPostingException("Akismet thinks that your comment is spam. Try rewriting the comment, or logging in.");
} else {
$database->Execute("INSERT INTO comments(image_id, owner_id, owner_ip, posted, comment) " . "VALUES(?, ?, ?, now(), ?)", array($image_id, $user->id, $_SERVER['REMOTE_ADDR'], $comment));
$cid = $database->db->Insert_ID();
log_info("comment", "Comment #{$cid} added to Image #{$image_id}");
}
}
}
}
}
}
}
}
}
}
}
示例12: process_revert_all_changes
/**
* This function attempts to revert all changes by a given IP within an (optional) timeframe.
*
* @param string $name
* @param string $ip
* @param string $date
*/
public function process_revert_all_changes($name, $ip, $date)
{
global $database;
$select_code = array();
$select_args = array();
if (!is_null($name)) {
$duser = User::by_name($name);
if (is_null($duser)) {
$this->theme->add_status($name, "user not found");
return;
} else {
$select_code[] = 'user_id = ?';
$select_args[] = $duser->id;
}
}
if (!is_null($date)) {
$select_code[] = 'date_set >= ?';
$select_args[] = $date;
}
if (!is_null($ip)) {
$select_code[] = 'user_ip = ?';
$select_args[] = $ip;
}
if (count($select_code) == 0) {
log_error("source_history", "Tried to mass revert without any conditions");
return;
}
log_info("source_history", 'Attempting to revert edits where ' . implode(" and ", $select_code) . " (" . implode(" / ", $select_args) . ")");
// Get all the images that the given IP has changed source on (within the timeframe) that were last editied by the given IP
$result = $database->get_col('
SELECT t1.image_id
FROM source_histories t1
LEFT JOIN source_histories t2 ON (t1.image_id = t2.image_id AND t1.date_set < t2.date_set)
WHERE t2.image_id IS NULL
AND t1.image_id IN ( select image_id from source_histories where ' . implode(" AND ", $select_code) . ')
ORDER BY t1.image_id
', $select_args);
foreach ($result as $image_id) {
// Get the first source history that was done before the given IP edit
$row = $database->get_row('
SELECT id, source
FROM source_histories
WHERE image_id=' . $image_id . '
AND NOT (' . implode(" AND ", $select_code) . ')
ORDER BY date_set DESC LIMIT 1
', $select_args);
if (empty($row)) {
// we can not revert this image based on the date restriction.
// Output a message perhaps?
} else {
$revert_id = $row['id'];
$result = $this->get_source_history_from_revert($revert_id);
if (empty($result)) {
// there is no history entry with that id so either the image was deleted
// while the user was viewing the history, or something messed up
/* calling die() is probably not a good idea, we should throw an Exception */
die('Error: No source history with specified id (' . $revert_id . ') was found in the database.' . "\n\n" . 'Perhaps the image was deleted while processing this request.');
}
// lets get the values out of the result
$stored_result_id = $result['id'];
$stored_image_id = $result['image_id'];
$stored_source = $result['source'];
log_debug("source_history", 'Reverting source of Image #' . $stored_image_id . ' to [' . $stored_source . ']');
$image = Image::by_id($stored_image_id);
if (is_null($image)) {
die('Error: No image with the id (' . $stored_image_id . ') was found. Perhaps the image was deleted while processing this request.');
}
// all should be ok so we can revert by firing the SetSources event.
send_event(new SourceSetEvent($image, $stored_source));
$this->theme->add_status('Reverted Change', 'Reverted Image #' . $image_id . ' to Source History #' . $stored_result_id . ' (' . $row['source'] . ')');
}
}
log_info("source_history", 'Reverted ' . count($result) . ' edits.');
}
示例13: delete_user
/**
* @param Page $page
* @param bool $with_images
* @param bool $with_comments
*/
private function delete_user(Page $page, $with_images = false, $with_comments = false)
{
global $user, $config, $database;
$page->set_title("Error");
$page->set_heading("Error");
$page->add_block(new NavBlock());
if (!$user->can("delete_user")) {
$page->add_block(new Block("Not Admin", "Only admins can delete accounts"));
} else {
if (!isset($_POST['id']) || !is_numeric($_POST['id'])) {
$page->add_block(new Block("No ID Specified", "You need to specify the account number to edit"));
} else {
log_warning("user", "Deleting user #{$_POST['id']}");
if ($with_images) {
log_warning("user", "Deleting user #{$_POST['id']}'s uploads");
$rows = $database->get_all("SELECT * FROM images WHERE owner_id = :owner_id", array("owner_id" => $_POST['id']));
foreach ($rows as $key => $value) {
$image = Image::by_id($value['id']);
if ($image) {
send_event(new ImageDeletionEvent($image));
}
}
} else {
$database->Execute("UPDATE images SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id", array("new_owner_id" => $config->get_int('anon_id'), "old_owner_id" => $_POST['id']));
}
if ($with_comments) {
log_warning("user", "Deleting user #{$_POST['id']}'s comments");
$database->execute("DELETE FROM comments WHERE owner_id = :owner_id", array("owner_id" => $_POST['id']));
} else {
$database->Execute("UPDATE comments SET owner_id = :new_owner_id WHERE owner_id = :old_owner_id", array("new_owner_id" => $config->get_int('anon_id'), "old_owner_id" => $_POST['id']));
}
send_event(new UserDeletionEvent($_POST['id']));
$database->execute("DELETE FROM users WHERE id = :id", array("id" => $_POST['id']));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list"));
}
}
}
示例14: receive_event
public function receive_event(Event $event)
{
global $config, $database, $page, $user;
if (is_null($this->theme)) {
$this->theme = get_theme_object($this);
}
// fucking PHP "security" measures -_-;;;
$free_num = @disk_free_space(realpath("./images/"));
if ($free_num === FALSE) {
$is_full = false;
} else {
$is_full = $free_num < 100 * 1024 * 1024;
}
if ($event instanceof InitExtEvent) {
$config->set_default_int('upload_count', 3);
$config->set_default_int('upload_size', '1MB');
$config->set_default_bool('upload_anon', false);
$config->set_default_bool('upload_replace', true);
}
if ($event instanceof PostListBuildingEvent) {
if ($this->can_upload($user)) {
if ($is_full) {
$this->theme->display_full($page);
} else {
$this->theme->display_block($page);
}
}
}
if ($event instanceof PageRequestEvent) {
if ($event->page_matches("upload/replace")) {
/* Upload & Replace Image Request */
if (!$config->get_bool("upload_replace")) {
throw new UploadException("Upload Replacing Images is not enabled.");
}
// check if the user is an administrator and can upload files.
if (!$user->is_admin()) {
$this->theme->display_permission_denied($page);
} else {
if ($is_full) {
throw new UploadException("Can not replace Image: disk nearly full");
}
// Try to get the image ID
$image_id = int_escape($event->get_arg(0));
if (empty($image_id)) {
$image_id = isset($_POST['image_id']) ? $_POST['image_id'] : null;
}
if (empty($image_id)) {
throw new UploadException("Can not replace Image: No valid Image ID given.");
}
$image_old = Image::by_id($image_id);
if (is_null($image_old)) {
$this->theme->display_error($page, "Image not found", "No image in the database has the ID #{$image_id}");
}
if (count($_FILES) + count($_POST) > 0) {
if (count($_FILES) > 1) {
throw new UploadException("Can not upload more than one image for replacing.");
}
$source = isset($_POST['source']) ? $_POST['source'] : null;
$tags = '';
// Tags aren't changed when uploading. Set to null to stop PHP warnings.
if (count($_FILES)) {
foreach ($_FILES as $file) {
$ok = $this->try_upload($file, $tags, $source, $image_id);
break;
// leave the foreach loop.
}
} else {
foreach ($_POST as $name => $value) {
if (substr($name, 0, 3) == "url" && strlen($value) > 0) {
$ok = $this->try_transload($value, $tags, $source, $image_id);
break;
// leave the foreach loop.
}
}
}
$this->theme->display_upload_status($page, $ok);
} else {
if (!empty($_GET['url'])) {
$url = $_GET['url'];
$ok = $this->try_transload($url, $tags, $url, $image_id);
$this->theme->display_upload_status($page, $ok);
} else {
$this->theme->display_replace_page($page, $image_id);
}
}
}
// END of if admin / can_upload
} else {
if ($event->page_matches("upload")) {
if (!$this->can_upload($user)) {
$this->theme->display_permission_denied($page);
} else {
/* Regular Upload Image */
if (count($_FILES) + count($_POST) > 0) {
$tags = Tag::explode($_POST['tags']);
$source = isset($_POST['source']) ? $_POST['source'] : null;
$ok = true;
foreach ($_FILES as $file) {
$ok = $ok & $this->try_upload($file, $tags, $source);
}
//.........这里部分代码省略.........
示例15: edit_posts
/**
* This function gets the current order of images from a given pool.
* @param int $poolID
* @return \Image[] Array of image objects.
*/
private function edit_posts($poolID)
{
global $database;
$result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid" => $poolID));
$images = array();
while ($row = $result->fetch()) {
$image = Image::by_id($row["image_id"]);
$images[] = array($image);
}
return $images;
}