private function do_rss($images, $search_terms, $page_number) { global $page; global $config; $page->set_mode("data"); $page->set_type("application/rss+xml"); $data = ""; foreach ($images as $image) { $link = make_http(make_link("post/view/{$image->id}")); $tags = $image->get_tag_list(); $owner = $image->get_owner(); $thumb_url = $image->get_thumb_link(); $image_url = $image->get_image_link(); $posted = date(DATE_RSS, $image->posted_timestamp); $content = html_escape("<p>" . Themelet::build_thumb_html($image) . "</p>" . "<p>Uploaded by " . $owner->name . "</p>"); $data .= "\n\t\t<item>\n\t\t\t<title>{$image->id} - {$tags}</title>\n\t\t\t<link>{$link}</link>\n\t\t\t<guid isPermaLink=\"true\">{$link}</guid>\n\t\t\t<pubDate>{$posted}</pubDate>\n\t\t\t<description>{$content}</description>\n\t\t\t<media:thumbnail url=\"{$thumb_url}\"/>\n\t\t\t<media:content url=\"{$image_url}\"/>\n\t\t</item>\n\t\t\t"; } $title = $config->get_string('title'); $base_href = make_http($config->get_string('base_href')); $search = ""; if (count($search_terms) > 0) { $search = html_escape(implode(" ", $search_terms)) . "/"; } if ($page_number > 1) { $prev_url = make_link("rss/images/{$search}" . ($page_number - 1)); $prev_link = "<atom:link rel=\"previous\" href=\"{$prev_url}\" />"; } else { $prev_link = ""; } $next_url = make_link("rss/images/{$search}" . ($page_number + 1)); $next_link = "<atom:link rel=\"next\" href=\"{$next_url}\" />"; // no end... $version = VERSION; $xml = "<" . "?xml version=\"1.0\" encoding=\"utf-8\" ?" . ">\n<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n <channel>\n <title>{$title}</title>\n <description>The latest uploads to the image board</description>\n\t\t<link>{$base_href}</link>\n\t\t<generator>Shimmie-{$version}</generator>\n\t\t<copyright>(c) 2007 Shish</copyright>\n\t\t{$prev_link}\n\t\t{$next_link}\n\t\t{$data}\n\t</channel>\n</rss>"; $page->set_data($xml); }
private function add_image($image) { global $page; global $user; global $database; global $config; /* * Validate things */ if (strlen(trim($image->source)) == 0) { $image->source = null; } if (!empty($image->source)) { if (!preg_match("#^(https?|ftp)://#", $image->source)) { throw new ImageAdditionException("Image's source isn't a valid URL"); } } /* * Check for an existing image */ $existing = Image::by_hash($image->hash); if (!is_null($existing)) { $handler = $config->get_string("upload_collision_handler"); if ($handler == "merge") { $merged = array_merge($image->get_tag_array(), $existing->get_tag_array()); send_event(new TagSetEvent($existing, $merged)); return null; } else { $error = "Image <a href='" . make_link("post/view/{$existing->id}") . "'>{$existing->id}</a> " . "already has hash {$image->hash}:<p>" . Themelet::build_thumb_html($existing); throw new ImageAdditionException($error); } } // actually insert the info $database->Execute("INSERT INTO images(\n\t\t\t\t\towner_id, owner_ip, filename, filesize,\n\t\t\t\t\thash, ext, width, height, posted, source)\n\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?, now(), ?)", array($user->id, $_SERVER['REMOTE_ADDR'], $image->filename, $image->filesize, $image->hash, $image->ext, $image->width, $image->height, $image->source)); if ($database->engine->name == "pgsql") { $database->Execute("UPDATE users SET image_count = image_count+1 WHERE id = ? ", array($user->id)); $image->id = $database->db->GetOne("SELECT id FROM images WHERE hash=?", array($image->hash)); } else { $image->id = $database->db->Insert_ID(); } log_info("image", "Uploaded Image #{$image->id} ({$image->hash})"); # at this point in time, the image's tags haven't really been set, # and so, having $image->tag_array set to something is a lie (but # a useful one, as we want to know what the tags are /supposed/ to # be). Here we correct the lie, by first nullifying the wrong tags # then using the standard mechanism to set them properly. $tags_to_set = $image->get_tag_array(); $image->tag_array = array(); send_event(new TagSetEvent($image, $tags_to_set)); }