本文整理汇总了PHP中Tag::implode方法的典型用法代码示例。如果您正苦于以下问题:PHP Tag::implode方法的具体用法?PHP Tag::implode怎么用?PHP Tag::implode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tag
的用法示例。
在下文中一共展示了Tag::implode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: display_history_page
/**
* @param Page $page
* @param int $image_id
* @param array $history
*/
public function display_history_page(Page $page, $image_id, $history)
{
global $user;
$start_string = "\n\t\t\t<div style='text-align: left'>\n\t\t\t\t" . make_form(make_link("tag_history/revert")) . "\n\t\t\t\t\t<ul style='list-style-type:none;'>\n\t\t";
$history_list = "";
$n = 0;
foreach ($history as $fields) {
$n++;
$current_id = $fields['id'];
$current_tags = html_escape($fields['tags']);
$name = $fields['name'];
$h_ip = $user->can("view_ip") ? " " . show_ip($fields['user_ip'], "Tagging Image #{$image_id} as '{$current_tags}'") : "";
$setter = "<a href='" . make_link("user/" . url_escape($name)) . "'>" . html_escape($name) . "</a>{$h_ip}";
$selected = $n == 2 ? " checked" : "";
$current_tags = Tag::explode($current_tags);
$taglinks = array();
foreach ($current_tags as $tag) {
$taglinks[] = "<a href='" . make_link("post/list/" . $tag . "/1") . "'>" . $tag . "</a>";
}
$current_tags = Tag::implode($taglinks);
$history_list .= "\n\t\t\t\t<li>\n\t\t\t\t\t<input type='radio' name='revert' id='{$current_id}' value='{$current_id}'{$selected}>\n\t\t\t\t\t<label for='{$current_id}'>{$current_tags} (Set by {$setter})</label>\n\t\t\t\t</li>\n\t\t\t\t";
}
$end_string = "\n\t\t\t\t\t</ul>\n\t\t\t\t\t<input type='submit' value='Revert To'>\n\t\t\t\t</form>\n\t\t\t</div>\n\t\t";
$history_html = $start_string . $history_list . $end_string;
$page->set_title('Image ' . $image_id . ' Tag History');
$page->set_heading('Tag History: ' . $image_id);
$page->add_block(new NavBlock());
$page->add_block(new Block("Tag History", $history_html, "main", 10));
}
示例2: add_refine_block
/**
* @param Page $page
* @param string[] $search
*/
private function add_refine_block(Page $page, $search)
{
global $database, $config;
$wild_tags = Tag::explode($search);
$str_search = Tag::implode($search);
$related_tags = $database->cache->get("related_tags:{$str_search}");
if (empty($related_tags)) {
// $search_tags = array();
$tag_id_array = array();
$tags_ok = true;
foreach ($wild_tags as $tag) {
$tag = str_replace("*", "%", $tag);
$tag = str_replace("?", "_", $tag);
$tag_ids = $database->get_col("SELECT id FROM tags WHERE tag LIKE :tag", array("tag" => $tag));
// $search_tags = array_merge($search_tags,
// $database->get_col("SELECT tag FROM tags WHERE tag LIKE :tag", array("tag"=>$tag)));
$tag_id_array = array_merge($tag_id_array, $tag_ids);
$tags_ok = count($tag_ids) > 0;
if (!$tags_ok) {
break;
}
}
$tag_id_list = join(', ', $tag_id_array);
if ($tags_ok) {
$query = "\n\t\t\t\t\tSELECT t2.tag AS tag, COUNT(it2.image_id) AS calc_count\n\t\t\t\t\tFROM\n\t\t\t\t\t\timage_tags AS it1,\n\t\t\t\t\t\timage_tags AS it2,\n\t\t\t\t\t\ttags AS t1,\n\t\t\t\t\t\ttags AS t2\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tt1.id IN({$tag_id_list})\n\t\t\t\t\t\tAND it1.image_id=it2.image_id\n\t\t\t\t\t\tAND it1.tag_id = t1.id\n\t\t\t\t\t\tAND it2.tag_id = t2.id\n\t\t\t\t\tGROUP BY t2.tag\n\t\t\t\t\tORDER BY calc_count\n\t\t\t\t\tDESC LIMIT :limit\n\t\t\t\t";
$args = array("limit" => $config->get_int('tag_list_length'));
$related_tags = $database->get_all($query, $args);
$database->cache->set("related_tags:{$str_search}", $related_tags, 60 * 60);
}
}
if (!empty($related_tags)) {
$this->theme->display_refine_block($page, $related_tags, $wild_tags);
}
}
示例3: get_tag_list
/**
* Get this image's tags as a string.
*
* @return string
*/
public function get_tag_list()
{
return Tag::implode($this->get_tag_array());
}
示例4: __construct
/**
* Initialize an OuroborosPost for creation
* Mainly just acts as a wrapper and validation layer
* @param array $post
* @param string $md5
*/
public function __construct(array $post, $md5 = '')
{
if (array_key_exists('tags', $post)) {
$this->tags = Tag::implode(array_map(array('Tag', 'sanitise'), Tag::explode(urldecode($post['tags']))));
}
if (array_key_exists('file', $post)) {
if (!is_null($post['file'])) {
assert(is_array($post['file']));
assert(array_key_exists('tmp_name', $post['file']));
assert(array_key_exists('name', $post['file']));
$this->file = $post['file'];
}
}
if (array_key_exists('rating', $post)) {
assert($post['rating'] == 's' || $post['rating'] == 'q' || $post['rating'] == 'e');
$this->rating = $post['rating'];
}
if (array_key_exists('source', $post)) {
$this->file_url = filter_var(urldecode($post['source']), FILTER_SANITIZE_URL);
}
if (array_key_exists('sourceurl', $post)) {
$this->source = filter_var(urldecode($post['sourceurl']), FILTER_SANITIZE_URL);
}
if (array_key_exists('description', $post)) {
$this->description = filter_var($post['description'], FILTER_SANITIZE_STRING);
}
if (array_key_exists('is_rating_locked', $post)) {
assert($post['is_rating_locked'] == 'true' || $post['is_rating_locked'] == 'false' || $post['is_rating_locked'] == '1' || $post['is_rating_locked'] == '0');
$this->is_rating_locked = $post['is_rating_locked'];
}
if (array_key_exists('is_note_locked', $post)) {
assert($post['is_note_locked'] == 'true' || $post['is_note_locked'] == 'false' || $post['is_note_locked'] == '1' || $post['is_note_locked'] == '0');
$this->is_note_locked = $post['is_note_locked'];
}
if (array_key_exists('parent_id', $post)) {
$this->parent_id = filter_var($post['parent_id'], FILTER_SANITIZE_NUMBER_INT);
}
}
示例5: onTagSet
public function onTagSet(TagSetEvent $event)
{
$this->test_text(Tag::implode($event->tags), new SCoreException("Tags contain banned terms"));
}
示例6: add_tag_history
private function add_tag_history($image, $tags)
{
global $database;
global $config;
global $user;
$new_tags = Tag::implode($tags);
$old_tags = Tag::implode($image->get_tag_array());
log_debug("tag_history", "adding tag history: [{$old_tags}] -> [{$new_tags}]");
if ($new_tags == $old_tags) {
return;
}
// add a history entry
$allowed = $config->get_int("history_limit");
if ($allowed == 0) {
return;
}
$row = $database->execute("\n\t\t\t\tINSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set)\n\t\t\t\tVALUES (?, ?, ?, ?, now())", array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR']));
// if needed remove oldest one
if ($allowed == -1) {
return;
}
$entries = $database->db->GetOne("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id));
if ($entries > $allowed) {
// TODO: Make these queries better
$min_id = $database->db->GetOne("SELECT MIN(id) FROM tag_histories WHERE image_id = ?", array($image->id));
$database->execute("DELETE FROM tag_histories WHERE id = ?", array($min_id));
}
}
示例7: onPageRequest
public function onPageRequest(PageRequestEvent $event)
{
global $config, $database, $page, $user;
if ($event->page_matches("post/list")) {
if (isset($_GET['search'])) {
$search = url_escape(Tag::implode(Tag::resolve_aliases(Tag::explode($_GET['search'], false))));
if (empty($search)) {
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list/1"));
} else {
$page->set_mode("redirect");
$page->set_redirect(make_link('post/list/' . $search . '/1'));
}
return;
}
$search_terms = $event->get_search_terms();
$page_number = $event->get_page_number();
$page_size = $event->get_page_size();
$count_search_terms = count($search_terms);
try {
#log_debug("index", "Search for ".implode(" ", $search_terms), false, array("terms"=>$search_terms));
$total_pages = Image::count_pages($search_terms);
if (SPEED_HAX && $count_search_terms === 0 && $page_number < 10) {
// extra caching for the first few post/list pages
$images = $database->cache->get("post-list:{$page_number}");
if (!$images) {
$images = Image::find_images(($page_number - 1) * $page_size, $page_size, $search_terms);
$database->cache->set("post-list:{$page_number}", $images, 600);
}
} else {
$images = Image::find_images(($page_number - 1) * $page_size, $page_size, $search_terms);
}
} catch (SearchTermParseException $stpe) {
// FIXME: display the error somewhere
$total_pages = 0;
$images = array();
}
$count_images = count($images);
if ($count_search_terms === 0 && $count_images === 0 && $page_number === 1) {
$this->theme->display_intro($page);
send_event(new PostListBuildingEvent($search_terms));
} else {
if ($count_search_terms > 0 && $count_images === 1 && $page_number === 1) {
$page->set_mode("redirect");
$page->set_redirect(make_link('post/view/' . $images[0]->id));
} else {
$plbe = new PostListBuildingEvent($search_terms);
send_event($plbe);
$this->theme->set_page($page_number, $total_pages, $search_terms);
$this->theme->display_page($page, $images);
if (count($plbe->parts) > 0) {
$this->theme->display_admin_block($plbe->parts);
}
}
}
}
}
示例8: add_tag_history
/**
* This function is called just before an images tag are changed.
*
* @param Image $image
* @param string|string[] $tags
*/
private function add_tag_history(Image $image, $tags)
{
global $database, $config, $user;
$new_tags = Tag::implode($tags);
$old_tags = Tag::implode($image->get_tag_array());
if ($new_tags == $old_tags) {
return;
}
if (empty($old_tags)) {
/* no old tags, so we are probably adding the image for the first time */
log_debug("tag_history", "adding new tag history: [{$new_tags}]", false, array("image_id" => $image->id));
} else {
log_debug("tag_history", "adding tag history: [{$old_tags}] -> [{$new_tags}]", false, array("image_id" => $image->id));
}
$allowed = $config->get_int("history_limit");
if ($allowed == 0) {
return;
}
// if the image has no history, make one with the old tags
$entries = $database->get_one("SELECT COUNT(*) FROM tag_histories WHERE image_id = ?", array($image->id));
if ($entries == 0 && !empty($old_tags)) {
$database->execute("\n\t\t\t\tINSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set)\n\t\t\t\tVALUES (?, ?, ?, ?, now())", array($image->id, $old_tags, $config->get_int('anon_id'), '127.0.0.1'));
$entries++;
}
// add a history entry
$database->execute("\n\t\t\t\tINSERT INTO tag_histories(image_id, tags, user_id, user_ip, date_set)\n\t\t\t\tVALUES (?, ?, ?, ?, now())", array($image->id, $new_tags, $user->id, $_SERVER['REMOTE_ADDR']));
$entries++;
// if needed remove oldest one
if ($allowed == -1) {
return;
}
if ($entries > $allowed) {
// TODO: Make these queries better
/*
MySQL does NOT allow you to modify the same table which you use in the SELECT part.
Which means that these will probably have to stay as TWO separate queries...
http://dev.mysql.com/doc/refman/5.1/en/subquery-restrictions.html
http://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause
*/
$min_id = $database->get_one("SELECT MIN(id) FROM tag_histories WHERE image_id = ?", array($image->id));
$database->execute("DELETE FROM tag_histories WHERE id = ?", array($min_id));
}
}