本文整理汇总了PHP中Image::count_images方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::count_images方法的具体用法?PHP Image::count_images怎么用?PHP Image::count_images使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::count_images方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_body
private function get_body()
{
// returns just the contents of the body
global $database;
global $config;
$base_href = $config->get_string('base_href');
$data_href = get_base_href();
$sitename = $config->get_string('title');
$contact_link = $config->get_string('contact_link');
$counter_dir = $config->get_string('home_counter', 'default');
$total = Image::count_images();
$strtotal = "{$total}";
$num_comma = number_format($total);
$counter_text = "";
for ($n = 0; $n < strlen($strtotal); $n++) {
$cur = $strtotal[$n];
$counter_text .= " <img alt='{$cur}' src='{$data_href}/ext/home/counters/{$counter_dir}/{$cur}.gif' /> ";
}
// get the homelinks and process them
$main_links = $config->get_string('home_links');
$main_links = str_replace('$base', $base_href, $main_links);
$main_links = preg_replace('#\\[(.*?)\\|(.*?)\\]#', "<a href='\\1'>\\2</a>", $main_links);
$main_links = str_replace('//', "/", $main_links);
$main_text = $config->get_string('home_text');
return $this->theme->build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text);
}
示例2: get_body
private function get_body()
{
// returns just the contents of the body
global $config;
$base_href = get_base_href();
$sitename = $config->get_string('title');
$contact_link = $config->get_string('contact_link');
$counter_dir = $config->get_string('home_counter', 'default');
$total = Image::count_images();
$strtotal = "{$total}";
$num_comma = number_format($total);
$counter_text = "";
$length = strlen($strtotal);
for ($n = 0; $n < $length; $n++) {
$cur = $strtotal[$n];
$counter_text .= " <img alt='{$cur}' src='{$base_href}/ext/home/counters/{$counter_dir}/{$cur}.gif' /> ";
}
// get the homelinks and process them
if (strlen($config->get_string('home_links', '')) > 0) {
$main_links = $config->get_string('home_links');
} else {
$main_links = '[url=site://post/list]Posts[/url] [url=site://comment/list]Comments[/url] [url=site://tags]Tags[/url]';
if (class_exists("Pools")) {
$main_links .= ' [url=site://pool]Pools[/url]';
}
if (class_exists("Wiki")) {
$main_links .= ' [url=site://wiki]Wiki[/url]';
}
$main_links .= ' [url=site://ext_doc]Documentation[/url]';
}
$main_links = format_text($main_links);
$main_text = $config->get_string('home_text');
return $this->theme->build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text);
}
示例3: onUserPageBuilding
public function onUserPageBuilding($event)
{
$i_favorites_count = Image::count_images(array("favorited_by={$event->display_user->name}"));
$i_days_old = (time() - strtotime($event->display_user->join_date)) / 86400 + 1;
$h_favorites_rate = sprintf("%.1f", $i_favorites_count / $i_days_old);
$favorites_link = make_link("post/list/favorited_by={$event->display_user->name}/1");
$event->add_stats("<a href='{$favorites_link}'>Images favorited</a>: {$i_favorites_count}, {$h_favorites_rate} per day");
}
示例4: count_pages
/**
* Count the number of pages for a given search
*
* @param string[] $tags
* @return float
*/
public static function count_pages($tags = array())
{
assert('is_array($tags)');
global $config;
return ceil(Image::count_images($tags) / $config->get_int('index_images'));
}
示例5: count_pages
/**
* Count the number of pages for a given search
*/
public static function count_pages($tags = array())
{
assert(is_array($tags));
global $config, $database;
$images_per_page = $config->get_int('index_width') * $config->get_int('index_height');
return ceil(Image::count_images($tags) / $images_per_page);
}
示例6: onUserPageBuilding
public function onUserPageBuilding(UserPageBuildingEvent $event)
{
$u_id = url_escape($event->display_user->id);
$i_image_count = Image::count_images(array("user_id={$event->display_user->id}"));
$i_days_old = (time() - strtotime($event->display_user->join_date)) / 86400 + 1;
$h_image_rate = sprintf("%.1f", $i_image_count / $i_days_old);
$images_link = make_link("post/list/user_id={$u_id}/1");
$event->add_stats("<a href='{$images_link}'>Images uploaded</a>: {$i_image_count}, {$h_image_rate} per day");
}
示例7: onPageRequest
public function onPageRequest(PageRequestEvent $event)
{
global $database, $page, $user;
if ($event->page_matches("api/shimmie")) {
$page->set_mode("data");
$page->set_type("text/plain");
if (!$event->page_matches("api/shimmie/get_tags") && !$event->page_matches("api/shimmie/get_image") && !$event->page_matches("api/shimmie/find_images") && !$event->page_matches("api/shimmie/get_user")) {
$page->set_mode("redirect");
$page->set_redirect(make_link("ext_doc/shimmie_api"));
}
if ($event->page_matches("api/shimmie/get_tags")) {
$arg = $event->get_arg(0);
if (!empty($arg)) {
$all = $database->get_all("SELECT tag FROM tags WHERE tag LIKE ?", array($arg . "%"));
} elseif (isset($_GET['tag'])) {
$all = $database->get_all("SELECT tag FROM tags WHERE tag LIKE ?", array($_GET['tag'] . "%"));
} 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")) {
$arg = $event->get_arg(0);
if (!empty($arg)) {
$image = Image::by_id(int_escape($event->get_arg(0)));
} elseif (isset($_GET['id'])) {
$image = Image::by_id(int_escape($_GET['id']));
}
// FIXME: handle null image
$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));
}
if ($event->page_matches("api/shimmie/get_user")) {
$query = $user->id;
$type = "id";
if ($event->count_args() == 1) {
$query = $event->get_arg(0);
} elseif (isset($_GET['id'])) {
$query = $_GET['id'];
} elseif (isset($_GET['name'])) {
$query = $_GET['name'];
$type = "name";
}
$all = $database->get_row("SELECT id,name,joindate,class FROM users WHERE " . $type . "=?", array($query));
if (!empty($all)) {
//FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice..
// - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...);
for ($i = 0; $i < 4; $i++) {
unset($all[$i]);
}
$all['uploadcount'] = Image::count_images(array("user_id=" . $all['id']));
$all['commentcount'] = $database->get_one("SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", array("owner_id" => $all['id']));
if (isset($_GET['recent'])) {
$recent = $database->get_all("SELECT * FROM images WHERE owner_id=? ORDER BY id DESC LIMIT 0, 5", array($all['id']));
$i = 0;
foreach ($recent as $all['recentposts'][$i]) {
unset($all['recentposts'][$i]['owner_id']);
//We already know the owners id..
unset($all['recentposts'][$i]['owner_ip']);
for ($x = 0; $x < 14; $x++) {
unset($all['recentposts'][$i][$x]);
}
if (empty($all['recentposts'][$i]['author'])) {
unset($all['recentposts'][$i]['author']);
}
if ($all['recentposts'][$i]['notes'] > 0) {
$all['recentposts'][$i]['has_notes'] = "Y";
} else {
$all['recentposts'][$i]['has_notes'] = "N";
}
unset($all['recentposts'][$i]['notes']);
$i += 1;
}
}
}
$page->set_data(json_encode($all));
}
}
}
示例8: api_danbooru
//.........这里部分代码省略.........
* page: page number
* after_id: limit results to posts added after this id
*/
if ($event->get_arg(1) == 'find_posts' || $event->get_arg(1) == 'post' && $event->get_arg(2) == 'index.xml') {
$this->authenticate_user();
$start = 0;
if (isset($_GET['md5'])) {
$md5list = explode(",", $_GET['md5']);
foreach ($md5list as $md5) {
$results[] = Image::by_hash($md5);
}
$count = count($results);
} elseif (isset($_GET['id'])) {
$idlist = explode(",", $_GET['id']);
foreach ($idlist as $id) {
$results[] = Image::by_id($id);
}
$count = count($results);
} else {
$limit = isset($_GET['limit']) ? int_escape($_GET['limit']) : 100;
// Calculate start offset.
if (isset($_GET['page'])) {
// Danbooru API uses 'page' >= 1
$start = (int_escape($_GET['page']) - 1) * $limit;
} else {
if (isset($_GET['pid'])) {
// Gelbooru API uses 'pid' >= 0
$start = int_escape($_GET['pid']) * $limit;
} else {
$start = 0;
}
}
$tags = isset($_GET['tags']) ? Tag::explode($_GET['tags']) : array();
$count = Image::count_images($tags);
$results = Image::find_images(max($start, 0), min($limit, 100), $tags);
}
// Now we have the array $results filled with Image objects
// Let's display them
$xml = "<posts count=\"{$count}\" offset=\"{$start}\">\n";
foreach ($results as $img) {
// Sanity check to see if $img is really an image object
// If it isn't (e.g. someone requested an invalid md5 or id), break out of the this
if (!is_object($img)) {
continue;
}
$taglist = $img->get_tag_list();
$owner = $img->get_owner();
$previewsize = get_thumbnail_size($img->width, $img->height);
$xml .= xml_tag("post", array("id" => $img->id, "md5" => $img->hash, "file_name" => $img->filename, "file_url" => $img->get_image_link(), "height" => $img->height, "width" => $img->width, "preview_url" => $img->get_thumb_link(), "preview_height" => $previewsize[1], "preview_width" => $previewsize[0], "rating" => "u", "date" => $img->posted, "is_warehoused" => false, "tags" => $taglist, "source" => $img->source, "score" => 0, "author" => $owner->name));
}
$xml .= "</posts>";
$page->set_data($xml);
}
/*
find_tags() Find all tags that match the search criteria.
Parameters
* id: A comma delimited list of tag id numbers.
* name: A comma delimited list of tag names.
* tags: any typical tag query. See Tag#parse_query for details.
* after_id: limit results to tags with an id number after after_id. Useful if you only want to refresh
*/
if ($event->get_arg(1) == 'find_tags') {
if (isset($_GET['id'])) {
$idlist = explode(",", $_GET['id']);
foreach ($idlist as $id) {
$sqlresult = $database->execute("SELECT id,tag,count FROM tags WHERE id = ?", array($id));
示例9: api_get_user
/**
* @param $type
* @param $query
* @return array
*/
private function api_get_user($type, $query)
{
global $database;
$all = $database->get_row("SELECT id, name, joindate, class FROM users WHERE {$type}=?", array($query));
if (!empty($all)) {
//FIXME?: For some weird reason, get_all seems to return twice. Unsetting second value to make things look nice..
// - it returns data as eg array(0=>1234, 'id'=>1234, 1=>'bob', 'name'=>bob, ...);
for ($i = 0; $i < 4; $i++) {
unset($all[$i]);
}
$all['uploadcount'] = Image::count_images(array("user_id=" . $all['id']));
$all['commentcount'] = $database->get_one("SELECT COUNT(*) AS count FROM comments WHERE owner_id=:owner_id", array("owner_id" => $all['id']));
if (isset($_GET['recent'])) {
$recent = $database->get_all("SELECT * FROM images WHERE owner_id=? ORDER BY id DESC LIMIT 0, 5", array($all['id']));
$i = 0;
foreach ($recent as $all['recentposts'][$i]) {
unset($all['recentposts'][$i]['owner_id']);
//We already know the owners id..
unset($all['recentposts'][$i]['owner_ip']);
for ($x = 0; $x < 14; $x++) {
unset($all['recentposts'][$i][$x]);
}
if (empty($all['recentposts'][$i]['author'])) {
unset($all['recentposts'][$i]['author']);
}
if ($all['recentposts'][$i]['notes'] > 0) {
$all['recentposts'][$i]['has_notes'] = "Y";
} else {
$all['recentposts'][$i]['has_notes'] = "N";
}
unset($all['recentposts'][$i]['notes']);
$i += 1;
}
}
}
return $all;
}
示例10: api_find_posts
/**
* find_posts()
* Find all posts that match the search criteria. Posts will be ordered by id descending.
*
* Parameters:
* - md5: md5 hash to search for (comma delimited)
* - id: id to search for (comma delimited)
* - tags: what tags to search for
* - limit: limit
* - page: page number
* - after_id: limit results to posts added after this id
*
* @return string
* @throws SCoreException
*/
private function api_find_posts()
{
$results = array();
$this->authenticate_user();
$start = 0;
if (isset($_GET['md5'])) {
$md5list = explode(",", $_GET['md5']);
foreach ($md5list as $md5) {
$results[] = Image::by_hash($md5);
}
$count = count($results);
} elseif (isset($_GET['id'])) {
$idlist = explode(",", $_GET['id']);
foreach ($idlist as $id) {
$results[] = Image::by_id($id);
}
$count = count($results);
} else {
$limit = isset($_GET['limit']) ? int_escape($_GET['limit']) : 100;
// Calculate start offset.
if (isset($_GET['page'])) {
// Danbooru API uses 'page' >= 1
$start = (int_escape($_GET['page']) - 1) * $limit;
} else {
if (isset($_GET['pid'])) {
// Gelbooru API uses 'pid' >= 0
$start = int_escape($_GET['pid']) * $limit;
} else {
$start = 0;
}
}
$tags = isset($_GET['tags']) ? Tag::explode($_GET['tags']) : array();
$count = Image::count_images($tags);
$results = Image::find_images(max($start, 0), min($limit, 100), $tags);
}
// Now we have the array $results filled with Image objects
// Let's display them
$xml = "<posts count=\"{$count}\" offset=\"{$start}\">\n";
foreach ($results as $img) {
// Sanity check to see if $img is really an image object
// If it isn't (e.g. someone requested an invalid md5 or id), break out of the this
if (!is_object($img)) {
continue;
}
$taglist = $img->get_tag_list();
$owner = $img->get_owner();
$previewsize = get_thumbnail_size($img->width, $img->height);
$xml .= xml_tag("post", array("id" => $img->id, "md5" => $img->hash, "file_name" => $img->filename, "file_url" => $img->get_image_link(), "height" => $img->height, "width" => $img->width, "preview_url" => $img->get_thumb_link(), "preview_height" => $previewsize[1], "preview_width" => $previewsize[0], "rating" => "u", "date" => $img->posted, "is_warehoused" => false, "tags" => $taglist, "source" => $img->source, "score" => 0, "author" => $owner->name));
}
$xml .= "</posts>";
return $xml;
}