} $limit > 1000 && $limit == 1000; $count = 0; // begin // count = Post.fast_count(tags) // rescue => x // respond_to_error("Error: #{x}", :action => "error") // return // end set_title('/' . str_replace('_', ' ', $tags)); $tag_suggestions = array(); // if ($count < 16 && count($split_tags) == 1) // $tag_suggestions = Tag::find_suggestions($tags); $ambiguous_tags = array(); // $ambiguous_tags = Tag::select_ambiguous($split_tags); $searching_pool = isset($q['pool']) && is_int($q['pool']) ? Pool::find_by_id($q['pool']) : null; $from_api = Request::$format == "json" || Request::$format == "xml"; // @posts = WillPaginate::Collection.new(page, limit, count) // offset = @posts.offset // posts_to_load = @posts.per_page if (!$from_api) { # For forward preloading: // posts_to_load += @posts.per_page # If we're not on the first page, load the previous page for prefetching. Prefetching # the previous page when the user is scanning forward should be free, since it'll already # be in cache, so this makes scanning the index from back to front as responsive as from # front to back. // if page and page > 1 then // offset -= @posts.per_page // posts_to_load += @posts.per_page // end
function commit_tags() { if ($this->is_empty_model()) { return; } $this->tags = array_filter(explode(' ', str_replace(array("\r", "\n"), '', $this->tags))); $this->current_tags = array_keys($this->parsed_cached_tags); if (empty($this->old_tags)) { $this->old_tags = $this->tags; } elseif (!is_array($this->old_tags)) { $this->old_tags = array_filter(explode(' ', $this->old_tags)); } $this->commit_metatags(); foreach ($this->tags as $k => $tag) { if (!preg_match('~^(-pool|pool|rating|parent|child):|^[qse]$~', $tag)) { continue; } if (in_array($tag, array('q', 's', 'e'))) { $tag = "rating:{$tag}"; } $subparam = explode(':', $tag); $metatag = array_shift($subparam); $param = array_shift($subparam); $subparam = empty($subparam) ? null : array_shift($subparam); switch ($metatag) { case 'rating': # Change rating. This will override rating selected on radio buttons. if (in_array($param, array('q', 's', 'e'))) { $this->rating = $param; } unset($this->tags[$k]); break; case 'pool': try { $name = $param; $seq = $subparam; # Workaround: I don't understand how can the pool be found when finding_by_name # using the id. if (ctype_digit($name)) { $pool = Pool::find_by_id($name); } else { $pool = Pool::find_by_name($name); } # Set :ignore_already_exists, so pool:1:2 can be used to change the sequence number # of a post that already exists in the pool. $options = array('user' => User::find($this->updater_user_id), 'ignore_already_exists' => true); if ($seq) { $options['sequence'] = $seq; } if (!$pool and !ctype_digit($name)) { $pool = Pool::create(array('name' => $name, 'is_public' => false, 'user_id' => $this->updater_user_id)); } if (!$pool) { continue; } if (!$pool->can_change(User::$current, null)) { continue; } $pool->add_post($this->id, $options); } catch (PostAlreadyExistsError $e) { } catch (AccessDeniedError $e) { } unset($this->tags[$k]); break; case '-pool': unset($this->tags[$k]); $name = $param; $cmd = $subparam; $pool = Pool::find_by_name($name); if (!$pool->can_change(User::$current, null)) { break; } if ($cmd == "parent") { # If we have a parent, remove ourself from the pool and add our parent in # our place. If we have no parent, do nothing and leave us in the pool. if (!empty($this->parent_id)) { $pool->transfer_post_to_parent($this->id, $this->parent_id); break; } } $pool && $pool->remove_post($id); break; case 'source': $this->source = $param; unset($this->tags[$k]); break; case 'parent': if (is_numeric($param)) { $this->parent_id = (int) $param; } unset($this->tags[$k]); break; case 'child': unset($this->tags[$k]); break; default: unset($this->tags[$k]); break; } } $new_tags = array_diff($this->tags, $this->old_tags); $new_tags = array_merge($new_tags, TagAlias::to_aliased($new_tags)); $new_tags = array_merge($new_tags, TagImplication::with_implied($new_tags)); $new_tags = array_values(array_unique($new_tags)); $old_tags = array_diff($this->old_tags, $this->tags); if (empty($new_tags) && $old_tags == $this->current_tags) { if (!in_array('tagme', $new_tags)) { $new_tags[] = 'tagme'; } if (in_array('tagme', $old_tags)) { unset($old_tags[array_search('tagme', $old_tags)]); } } foreach ($old_tags as $tag) { if (array_key_exists($tag, $this->parsed_cached_tags)) { unset($this->parsed_cached_tags[$tag]); } $tag = Tag::find_by_name($tag); if ($tag) { DB::delete('posts_tags WHERE post_id = ? AND tag_id = ?', $this->id, $tag->id); } } foreach ($new_tags as $tag) { $tag = Tag::find_or_create_by_name($tag); $this->parsed_cached_tags[$tag->name] = $tag->type_name; DB::insert_ignore('posts_tags VALUES (?, ?)', $this->id, $tag->id); } $this->tags = $this->tag_names(); $this->generate_cached_tags(); }