This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merged

  • Loading branch information...
huacnlee committed Apr 14, 2011
2 parents 183b555 + 83b0f98 commit 8dff887a848bb503697ce1410445619c199c5bb5
Showing with 76,943 additions and 127 deletions.
  1. +1 −0 .gitignore
  2. +34 −0 app/controllers/application_controller.rb
  3. +2 −0 app/controllers/asks_controller.rb
  4. +33 −0 app/controllers/cpanel/report_spams_controller.rb
  5. +14 −1 app/controllers/home_controller.rb
  6. +1 −0 app/controllers/users_controller.rb
  7. +5 −0 app/helpers/application_helper.rb
  8. +13 −1 app/helpers/asks_helper.rb
  9. +2 −0 app/helpers/cpanel/report_spams_helper.rb
  10. +1 −1 app/helpers/in_place_edit_helper.rb
  11. +6 −2 app/helpers/users_helper.rb
  12. +8 −0 app/mailers/user_mailer.rb
  13. +21 −6 app/models/ask.rb
  14. +5 −1 app/models/ask_invite.rb
  15. +7 −2 app/models/log.rb
  16. +16 −0 app/models/report_spam.rb
  17. +4 −1 app/models/user.rb
  18. +2 −2 app/uploaders/cover_uploader.rb
  19. +3 −3 app/views/asks/_ask.html.erb
  20. +1 −1 app/views/asks/_form.html.erb
  21. +13 −7 app/views/asks/show.html.erb
  22. +15 −0 app/views/cpanel/report_spams/_base.html.erb
  23. +14 −0 app/views/cpanel/report_spams/_form.html.erb
  24. +6 −0 app/views/cpanel/report_spams/edit.html.erb
  25. +22 −0 app/views/cpanel/report_spams/index.html.erb
  26. +5 −0 app/views/cpanel/report_spams/new.html.erb
  27. +18 −0 app/views/cpanel/report_spams/show.html.erb
  28. +3 −3 app/views/cpanel/users/index.html.erb
  29. +15 −0 app/views/layouts/application.html.erb
  30. +2 −1 app/views/layouts/cpanel.html.erb
  31. +12 −10 app/views/logs/_log.html.erb
  32. +3 −1 app/views/registrations/edit.html.erb
  33. +5 −0 app/views/user_mailer/ask_user.html.erb
  34. +1 −1 app/views/user_mailer/invite_to_answer.html.erb
  35. +2 −2 app/views/users/_answered_ask.html.erb
  36. +23 −0 app/views/users/_head.html.erb
  37. +2 −0 config/initializers/mime_types.rb
  38. +2 −0 config/routes.rb
  39. +2 −0 db/dict/build.sh
  40. +59 −0 db/dict/build_thesaurus.py
  41. +0 −36 db/dict/build_unigram.py
  42. BIN db/dict/thesaurus.lib
  43. +75,880 −0 db/dict/thesaurus.txt
  44. BIN db/dict/uni.lib
  45. +7 −3 public/javascripts/application.js
  46. +12 −5 public/javascripts/asks.js
  47. +1 −1 public/javascripts/facebox.js
  48. +1 −1 public/javascripts/jquery.autocomplete.js
  49. +18 −13 public/javascripts/jquery.qeditor.js
  50. +23 −3 public/stylesheets/application.css
  51. +2 −2 public/stylesheets/cpanel.css
  52. +16 −9 public/stylesheets/facebox.css
  53. +1 −1 public/stylesheets/font_no_cleartype.css
  54. +23 −3 public/stylesheets/front.css
  55. +4 −3 public/stylesheets/jquery.autocomplete.css
  56. +2 −1 public/stylesheets/jquery.jdialog.css
  57. +49 −0 test/functional/cpanel/report_spams_controller_test.rb
  58. +4 −0 test/unit/helpers/cpanel/report_spams_helper_test.rb
  59. +113 −0 vendor/plugins/mobile-fu/CHANGELOG
  60. +20 −0 vendor/plugins/mobile-fu/MIT-LICENSE
  61. +99 −0 vendor/plugins/mobile-fu/README.rdoc
  62. +22 −0 vendor/plugins/mobile-fu/Rakefile
  63. +7 −0 vendor/plugins/mobile-fu/init.rb
  64. 0 vendor/plugins/mobile-fu/install.rb
  65. +102 −0 vendor/plugins/mobile-fu/lib/mobile_fu.rb
  66. +24 −0 vendor/plugins/mobile-fu/lib/mobile_fu_helper.rb
  67. +70 −0 vendor/plugins/mobile-fu/lib/mobilized_styles.rb
  68. +39 −0 vendor/plugins/mobile-fu/spec/mobilized_styles_spec.rb
  69. 0 vendor/plugins/mobile-fu/spec/spec.opts
  70. +1 −0 vendor/plugins/mobile-fu/spec/spec_helper.rb
  71. 0 vendor/plugins/mobile-fu/uninstall.rb
View
@@ -9,6 +9,7 @@ public/javascripts/cached_*
public/stylesheets/cached_*
public/about.html
db/sphinx
db/dict/*.lib
#以bundle install --path vendor/bundle方式安装,不影响开发者现有gems环境
vendor/bundle
@@ -2,6 +2,10 @@
class ApplicationController < ActionController::Base
protect_from_forgery
helper :all
# 暂时不使用mobile-fu的功能,仅仅使用其is_mobile_device?方法
include ActionController::MobileFu::InstanceMethods
helper_method :is_mobile_device?
# set page title, meta keywords, meta description
def set_seo_meta(title, options = {})
@@ -74,4 +78,34 @@ def require_user_text
require_user(:format => :text)
end
def tag_options(options, escape = true)
unless options.blank?
attrs = []
options.each_pair do |key, value|
if BOOLEAN_ATTRIBUTES.include?(key)
attrs << %(#{key}="#{key}") if value
elsif !value.nil?
final_value = value.is_a?(Array) ? value.join(" ") : value
final_value = html_escape(final_value) if escape
attrs << %(#{key}="#{final_value}")
end
end
" #{attrs.sort * ' '}".html_safe unless attrs.empty?
end
end
def tag(name, options = nil, open = false, escape = true)
"<#{name}#{tag_options(options, escape) if options}#{open ? ">" : " />"}".html_safe
end
def simple_format(text, html_options={}, options={})
text = ''.html_safe if text.nil?
start_tag = tag('p', html_options, true)
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</p><br />#{start_tag}") # 2+ newline -> paragraph
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
text.html_safe.safe_concat("</p>")
end
end
@@ -78,6 +78,8 @@ def answer
@answer.ask_id = params[:id]
@answer.user_id = current_user.id
@answer.body = simple_format(@answer.body.strip) if params[:did_editor_content_formatted] == "no"
if @answer.save
@success = true
else
@@ -0,0 +1,33 @@
# coding: UTF-8
class Cpanel::ReportSpamsController < CpanelController
def index
@report_spams = initialize_grid(ReportSpam,
:order => 'id',
:order_direction => 'desc')
respond_to do |format|
format.html # index.html.erb
format.json
end
end
def show
@report_spam = ReportSpam.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json
end
end
def destroy
@report_spam = ReportSpam.find(params[:id])
@report_spam.destroy
respond_to do |format|
format.html { redirect_to(cpanel_report_spams_path,:notice => "删除成功。") }
format.json
end
end
end
@@ -16,6 +16,7 @@ def index
when "FOLLOW" then @notifies[notify.target_id][:type] = "USER"
when "THANK_ANSWER" then @notifies[notify.target_id][:type] = "THANK_ANSWER"
when "INVITE_TO_ANSWER" then @notifies[notify.target_id][:type] = "INVITE_TO_ANSWER"
when "NEW_TO_USER" then @notifies[notify.target_id][:type] = "ASK_USER"
else
@notifies[notify.target_id][:type] = "ASK"
end
@@ -62,7 +63,7 @@ def index
def newbie
ask_logs = Log.any_of({:_type => "AskLog"}, {:_type => "UserLog", :action.in => ["FOLLOW_ASK", "UNFOLLOW_ASK"]}).where(:created_at.gte => (Time.now - 12.hours))
answer_logs = Log.any_of({:_type => "AnswerLog"}, {:_type => "UserLog", :action => "AGREE"}).where(:created_at.gte => (Time.now - 12.hours))
@asks = Ask.any_of({:_id.in => ask_logs.map {|l| l.target_id}.uniq}, {:_id.in => answer_logs.map {|l| l.target_parent_id}.uniq}).order_by(:answers_count.asc, :views_count.asc)
@asks = Ask.normal.any_of({:_id.in => ask_logs.map {|l| l.target_id}.uniq}, {:_id.in => answer_logs.map {|l| l.target_parent_id}.uniq}).order_by(:answers_count.asc, :views_count.asc)
h = {}
# 将回答次数*topic,以加入回答次数
@hot_topics = @asks.inject([]) { |memo, ask|
@@ -140,6 +141,8 @@ def update_in_place
case klass
when "user" then return if current_user.id.to_s != id
end
params[:value] = simple_format(params[:value].to_s.strip) if params[:did_editor_content_formatted] == "no"
object = klass.camelize.constantize.find(id)
update_hash = {field => params[:value]}
@@ -172,4 +175,14 @@ def mark_notifies_as_read
end
end
def report
name = "访客"
if current_user
name = current_user.name
end
ReportSpam.add(params[:url],params[:desc],name)
flash[:notice] = "举报信息已经提交,谢谢你。"
redirect_to params[:url]
end
end
@@ -8,6 +8,7 @@ def init_user
if @user.blank?
render_404
end
@ask_to_user = Ask.new
end
def answered
@@ -41,6 +41,11 @@ def ask_notification_tag(ask_id, log, a, show_ask = true)
if show_ask
tag += "<a href=\"#{ask_path(ask)}?nr=1\">#{ask.title}</a>"
end
when "ASK_USER"
tag += user_tag + "向你询问 "
if show_ask
tag += "<a href=\"#{ask_path(ask)}?nr=1\">#{ask.title}</a>"
end
end
return tag
end
View
@@ -1,3 +1,4 @@
# coding: utf-8
module AsksHelper
def topics_name_tag(topics,limit = 20)
html = []
@@ -11,9 +12,20 @@ def topics_name_tag(topics,limit = 20)
return raw html.join("")
end
def ask_title_tag(ask, options = {})
class_name = options[:class] || ""
prefix = ""
if !ask.to_user.blank?
prefix = "#{ask.to_user.name}"
end
raw "<a href=\"/asks/#{ask.id}\" class=\"#{class_name}\">#{prefix}#{ask.title}</a>"
end
def md_body(str)
return "" if str.blank?
str = sanitize(str,:tags => %w(strong b i u strike s ol ul li blockquote address br div), :attributes => %w(src))
# str = simple_format(str) if str =~ /\n/
# Rails.logger.info "str: #{str.inspect}"
str = sanitize(str,:tags => %w(strong b i u strike s ol ul li blockquote address br div p), :attributes => %w(src))
str = auto_link_urls(str,{:target => "_blank", :rel => "nofollow" }, {:limit => 80 })
return raw str
end
@@ -0,0 +1,2 @@
module Cpanel::ReportSpamsHelper
end
@@ -15,7 +15,7 @@ def in_place_edit_tag(object, field, options={})
:'data-type' => options[:type],
:'data-text-id' => options[:text_id],
:'data-rich' => options[:rich],
:onclick => "return App.inPlaceEdit(this);",
:onclick => "return App.inPlaceEdit(this, {'is_mobile_device': #{is_mobile_device? ? 'true' : 'false'}});",
:'data-url' => update_url}
if !options[:width].blank?
html_options[:"data-width"] = options[:width]
@@ -1,12 +1,16 @@
# coding: utf-8
module UsersHelper
def user_name_tag(user)
def user_name_tag(user, options = {})
options[:url] ||= false
return "" if user.blank?
raw "<a href=\"#{user_path(user.slug)}\" class=\"user\" title=\"#{user.name}\">#{user.name}</a>"
return user.name if user.slug.blank?
url = options[:url] == true ? user_url(user.slug) : user_path(user.slug)
raw "<a href=\"#{url}\" class=\"user\" title=\"#{user.name}\">#{user.name}</a>"
end
def user_avatar_tag(user,size)
return "" if user.blank?
return "" if user.slug.blank?
url = eval("user.avatar.#{size}.url")
if url.blank?
url = ""
@@ -53,5 +53,13 @@ def invite_to_answer(ask_id, user_id, invitor_ids)
mail(:to => @user.email, :subject => @title, :from => Setting.email_sender)
end
# 向用户提问
def ask_user(ask_id)
@ask = Ask.find(ask_id)
@user = @ask.to_user
@title = "#{@ask.user.name}对向你询问《#{@ask.title}"
mail(:to => @user.email, :subject => @title, :from => Setting.email_sender)
end
end
View
@@ -25,6 +25,8 @@ class Ask
# 提问人
belongs_to :user, :inverse_of => :asks
# 对指定人的提问
belongs_to :to_user, :class_name => "User"
# 回答
has_many :answers
@@ -55,21 +57,30 @@ class Ask
scope :only_ids, lambda { |id_array| any_in("_id" => (id_array ||= [])) }
# FullText indexes
search_index(:fields => [:title,:body],
:attributes => [:title, :topics],
search_index(:fields => [:title,:body, :topics],
:attributes => [],
:options => {} )
redis_search_index(:title_field => :title,:ext_fields => [:topics])
before_save :fill_default_values
after_create :create_log, :inc_counter_cache
after_create :create_log, :inc_counter_cache, :send_mails
after_destroy :dec_counter_cache
before_update :update_log
def view!
self.inc(:views_count, 1)
end
def send_mails
# 向某人提问
if !self.to_user.blank?
if self.to_user.mail_ask_me
UserMailer.ask_user(self.id).deliver
end
end
end
def inc_counter_cache
self.user.inc(:asks_count, 1)
end
@@ -128,7 +139,8 @@ def fill_default_values
# 参数 add true 增加, false 去掉
def update_topics(topics, add = true, current_user_id = nil)
self.topics = [] if self.topics.blank?
topics = [topics] if topics.class != [].class
# 分割逗号
topics = topics.split(/,|,/) if topics.class != [].class
# 去两边空格
topics = topics.collect { |t| t.strip if !t.blank? }.compact
action = nil
@@ -174,8 +186,7 @@ def self.mmseg_text(text)
def self.search_title(text,options = {})
limit = options[:limit] || 10
words = mmseg_text(text)
Ask.all_in(:title => words.collect { |w| /#{w}/i }).recent.normal.limit(limit)
Ask.search(text,:limit => limit)
end
def self.find_by_title(title)
@@ -227,6 +238,10 @@ def insert_action_log(action)
log.ask = self
log.target_id = self.id
log.target_attr = (self.title_changed? ? "TITLE" : (self.body_changed? ? "BODY" : "")) if action == "EDIT"
if(action == "NEW" and !self.to_user_id.blank?)
action = "NEW_TO_USER"
log.target_parent_id = self.to_user_id
end
log.action = action
log.diff = ""
log.save
View
@@ -30,6 +30,8 @@ def self.insert_log(ask_id, user_id, invitor_id)
def self.invite(ask_id,user_id,invitor_id)
item = find_or_create_by(:ask_id => ask_id,:user_id => user_id)
user = item.user
return -1 if user.blank?
item.invitor_ids ||= []
item.count ||= 0
return item if item.invitor_ids.include?(invitor_id)
@@ -38,7 +40,9 @@ def self.invite(ask_id,user_id,invitor_id)
# 发送邮件
if(item.mail_sent <= 1)
UserMailer.invite_to_answer(item.ask_id, item.user_id, item.invitor_ids).deliver
if item.user.mail_invite_to_ask
UserMailer.invite_to_answer(item.ask_id, item.user_id, item.invitor_ids).deliver
end
item.mail_sent += 1
end
View
@@ -27,10 +27,15 @@ class AskLog < Log
def send_notification
case self.action
when "INVITE_TO_ANSWER"
Notification.create(user_id: self.target_id,
Notification.create(user_id: self.target_parent_id,
log_id: self.id,
target_id: self.target_parent_id,
target_id: self.target_id,
action: "INVITE_TO_ANSWER")
when "NEW_TO_USER"
Notification.create(user_id: self.target_parent_id,
log_id: self.id,
target_id: self.target_id,
action: "ASK_USER")
end
end
end
View
@@ -0,0 +1,16 @@
class ReportSpam
include Mongoid::Document
include Mongoid::Timestamps
include BaseModel
field :url
field :descriptions, :type => Array, :default => []
index :url
def self.add(url, description, user_name)
report = find_or_create_by(:url => url)
report.descriptions << "#{user_name}:\n#{description}"
report.save
end
end
View
@@ -28,6 +28,8 @@ class User
# Email 提醒的状态
field :mail_be_followed, :type => Boolean, :default => true
field :mail_new_answer, :type => Boolean, :default => true
field :mail_invite_to_ask, :type => Boolean, :default => true
field :mail_ask_me, :type => Boolean, :default => true
field :thanked_answer_ids, :type => Array, :default => []
# 邀请字段
@@ -51,7 +53,8 @@ class User
has_many :logs, :class_name => "Log", :foreign_key => "target_id"
attr_accessor :password_confirmation
attr_accessible :email, :password,:name, :slug, :tagline, :bio, :avatar, :website, :girl, :mail_new_answer, :mail_be_followed
attr_accessible :email, :password,:name, :slug, :tagline, :bio, :avatar, :website, :girl,
:mail_new_answer, :mail_be_followed, :mail_invite_to_ask, :mail_ask_me
validates_presence_of :name, :slug
validates_uniqueness_of :slug
@@ -4,11 +4,11 @@ def default_url
end
version :small do
process :resize_to_fill => [25, 25]
process :resize_to_fit => [25, 25]
end
version :normal do
process :resize_to_fill => [100, 100]
process :resize_to_fit => [100, 100]
end
end
Oops, something went wrong.

0 comments on commit 8dff887

Please sign in to comment.