2014-05-05 11:33:35 +00:00
|
|
|
# encoding: utf-8
|
2014-05-05 08:20:37 +00:00
|
|
|
class WebLink
|
|
|
|
include Mongoid::Document
|
2014-05-05 11:33:35 +00:00
|
|
|
include Mongoid::Timestamps
|
|
|
|
|
|
|
|
include OrbitModel::Status
|
2014-05-21 08:07:53 +00:00
|
|
|
include OrbitModel::Impression
|
2014-05-05 11:33:35 +00:00
|
|
|
include OrbitTag::Taggable
|
|
|
|
include OrbitCategory::Categorizable
|
|
|
|
|
|
|
|
field :title, localize: true
|
|
|
|
field :context, localize: true
|
|
|
|
|
|
|
|
field :url, localize: true
|
|
|
|
field :create_user_id
|
|
|
|
field :update_user_id
|
2014-06-16 09:18:11 +00:00
|
|
|
field :rss2_id, type: String
|
2014-05-05 11:33:35 +00:00
|
|
|
|
2014-06-06 11:14:59 +00:00
|
|
|
scope :can_display, ->{where(is_hidden: false).order_by([:is_top,:desc],[:created_at,:desc])}
|
2014-05-05 11:33:35 +00:00
|
|
|
|
2014-06-06 11:06:02 +00:00
|
|
|
before_save :add_http
|
2014-05-05 11:33:35 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def add_http
|
2014-06-06 11:06:02 +00:00
|
|
|
temp_url = {}
|
|
|
|
Site.first.in_use_locales.each do |locale|
|
|
|
|
locale = locale.to_s
|
|
|
|
temp_url[locale] = self.url_translations[locale]
|
|
|
|
unless /https?:\/\/[\S]+/.match(self.url_translations[locale]) || self.url_translations[locale].blank?
|
|
|
|
temp_url[locale] = 'http://' + self.url_translations[locale]
|
|
|
|
end
|
2014-05-05 11:33:35 +00:00
|
|
|
end
|
2014-06-06 11:06:02 +00:00
|
|
|
self.url_translations = temp_url
|
2014-05-05 11:33:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|