kit_cms 2.3.20 → 2.3.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. data/app/assets/images/kit/toolbar/smile.png +0 -0
  2. data/app/assets/images/kit/toolbar/wink.gif +0 -0
  3. data/app/assets/images/kit/toolbar/wink.png +0 -0
  4. data/app/assets/javascripts/codemirror/editor.js +55 -17
  5. data/app/assets/javascripts/codemirror/jquery.js +0 -1
  6. data/app/assets/javascripts/codemirror/ruby.js +196 -0
  7. data/app/assets/javascripts/jquery.js +3036 -2838
  8. data/app/assets/javascripts/kit/utilities.js +655 -586
  9. data/app/assets/stylesheets/codemirror/style.css +1 -1
  10. data/app/assets/stylesheets/codemirror/theme.css +23 -3
  11. data/app/assets/stylesheets/kit/calendar.css +6 -1
  12. data/app/assets/stylesheets/kit/cms/cms.css +36 -0
  13. data/app/assets/stylesheets/kit/forums.css +5 -1
  14. data/app/assets/stylesheets/kit/kit.css +3 -1
  15. data/app/controllers/account_controller.rb +306 -0
  16. data/app/controllers/ad_controller.rb +2 -0
  17. data/app/controllers/admin/ad_units_controller.rb +1 -1
  18. data/app/controllers/admin/ad_zones_controller.rb +15 -0
  19. data/app/controllers/admin/ads_controller.rb +5 -0
  20. data/app/controllers/admin/block_controller.rb +1 -65
  21. data/app/controllers/admin/blocks_controller.rb +2 -0
  22. data/app/controllers/admin/content_controller.rb +3 -1
  23. data/app/controllers/admin/dashboard_controller.rb +28 -4
  24. data/app/controllers/admin/dj_controller.rb +45 -0
  25. data/app/controllers/admin/help_controller.rb +1 -1
  26. data/app/controllers/admin/html_asset_controller.rb +0 -12
  27. data/app/controllers/admin/q_controller.rb +120 -0
  28. data/app/controllers/admin/user_controller.rb +4 -4
  29. data/app/controllers/api_controller.rb +34 -0
  30. data/app/controllers/calendar_controller.rb +1 -1
  31. data/app/controllers/form_controller.rb +3 -3
  32. data/app/controllers/forum_controller.rb +39 -29
  33. data/app/controllers/kit_controller.rb +42 -15
  34. data/app/controllers/pages_controller.rb +25 -5
  35. data/app/controllers/q_controller.rb +235 -0
  36. data/app/controllers/repo_controller.rb +7 -0
  37. data/app/controllers/user_controller.rb +14 -10
  38. data/app/controllers/utility_controller.rb +1 -1
  39. data/app/helpers/account_helper.rb +47 -0
  40. data/app/helpers/admin/layouts_helper.rb +8 -0
  41. data/app/helpers/admin/page_templates_helper.rb +8 -0
  42. data/app/helpers/ads_helper.rb +11 -12
  43. data/app/helpers/calendar_helper.rb +6 -2
  44. data/app/helpers/form_data_helper.rb +1 -1
  45. data/app/helpers/form_helper.rb +8 -0
  46. data/app/helpers/forum_helper.rb +5 -1
  47. data/app/helpers/kit_helper.rb +65 -35
  48. data/app/helpers/kit_modules_helper.rb +4 -0
  49. data/app/helpers/user_helper.rb +0 -28
  50. data/app/jobs/page_link_job.rb +34 -0
  51. data/app/jobs/queue_job.rb +134 -0
  52. data/app/mailers/notification.rb +10 -0
  53. data/app/mailers/queue_mailer.rb +13 -0
  54. data/app/models/ad.rb +6 -6
  55. data/app/models/ad_unit.rb +1 -1
  56. data/app/models/ad_zone.rb +4 -0
  57. data/app/models/block.rb +1 -1
  58. data/app/models/delayed_job.rb +3 -0
  59. data/app/models/form.rb +16 -4
  60. data/app/models/html_asset.rb +19 -4
  61. data/app/models/html_asset_usage.rb +3 -0
  62. data/app/models/html_assetable.rb +4 -0
  63. data/app/models/layout.rb +36 -6
  64. data/app/models/newsletter.rb +1 -1
  65. data/app/models/page.rb +36 -2
  66. data/app/models/page_link.rb +5 -0
  67. data/app/models/page_template.rb +22 -2
  68. data/app/models/preference.rb +1 -1
  69. data/app/models/q_event.rb +12 -0
  70. data/app/models/q_klass.rb +5 -0
  71. data/app/models/q_message.rb +9 -0
  72. data/app/models/q_publisher.rb +35 -0
  73. data/app/models/q_subscription.rb +7 -0
  74. data/app/models/q_user.rb +29 -0
  75. data/app/models/q_users_method.rb +6 -0
  76. data/app/models/q_users_publisher.rb +6 -0
  77. data/app/models/user.rb +127 -19
  78. data/app/models/user_login.rb +4 -0
  79. data/app/validators/email_validator.rb +14 -0
  80. data/app/views/account/_edit.html.haml +40 -0
  81. data/app/views/account/_edit_intro.html.haml +3 -0
  82. data/app/views/account/_forgotten.html.haml +20 -0
  83. data/app/views/account/_forgotten_intro.html.haml +5 -0
  84. data/app/views/account/_sign_in.html.haml +31 -0
  85. data/app/views/account/_sign_in_intro.html.haml +4 -0
  86. data/app/views/account/_sign_up.html.haml +51 -0
  87. data/app/views/account/_sign_up_intro.html.haml +4 -0
  88. data/app/views/account/edit.html.haml +1 -0
  89. data/app/views/account/forgotten.html.haml +1 -0
  90. data/app/views/account/sign_in.html.haml +2 -0
  91. data/app/views/account/sign_up.html.haml +1 -0
  92. data/app/views/ad/_buy.html.haml +2 -1
  93. data/app/views/admin/ad_zones/_form.html.haml +1 -1
  94. data/app/views/admin/ad_zones/show.html.haml +2 -0
  95. data/app/views/admin/blocks/_form.html.haml +11 -1
  96. data/app/views/admin/dashboard/broken_links.html.haml +9 -0
  97. data/app/views/admin/dashboard/system.html.haml +11 -0
  98. data/app/views/admin/dj/index.html.haml +43 -0
  99. data/app/views/admin/form/_form.html.haml +15 -10
  100. data/app/views/admin/group/index.html.haml +1 -1
  101. data/app/views/admin/help/edit.html.haml +1 -1
  102. data/app/views/admin/html_asset/show.html.haml +9 -2
  103. data/app/views/admin/layouts/show.html.haml +10 -16
  104. data/app/views/admin/page_templates/_form.html.haml +9 -17
  105. data/app/views/admin/page_templates/show.html.haml +5 -4
  106. data/app/views/admin/q/events.html.haml +26 -0
  107. data/app/views/admin/q/index.html.haml +28 -0
  108. data/app/views/admin/q/klasses.html.haml +61 -0
  109. data/app/views/admin/q/messages.html.haml +37 -0
  110. data/app/views/admin/q/show.html.haml +98 -0
  111. data/app/views/admin/q/subscriptions.html.haml +26 -0
  112. data/app/views/admin/q/users.html.haml +27 -0
  113. data/app/views/admin/snippet/edit.html.erb +1 -1
  114. data/app/views/admin/snippet/new.html.erb +1 -1
  115. data/app/views/admin/stylesheet/show.html.haml +1 -1
  116. data/app/views/admin/user/index.html.erb +15 -6
  117. data/app/views/admin/user/view.html.erb +5 -4
  118. data/app/views/admin/views/_form.html.haml +3 -3
  119. data/app/views/calendar/_buy_tickets.html.haml +1 -1
  120. data/app/views/calendar/_calendar_entry.html.haml +1 -1
  121. data/app/views/calendar/_month.html.haml +7 -7
  122. data/app/views/form/_show.html.haml +1 -1
  123. data/app/views/forum/_add_post.html.haml +7 -8
  124. data/app/views/forum/_mod_thread.js.erb +46 -6
  125. data/app/views/forum/_post_moderation.html.haml +2 -1
  126. data/app/views/forum/_post_preview.html.haml +1 -9
  127. data/app/views/forum/_post_scripts.js.erb +29 -5
  128. data/app/views/forum/fetch_raw.html.haml +1 -0
  129. data/app/views/forum/moderate.html.haml +1 -0
  130. data/app/views/forum/topic_index.html.haml +4 -0
  131. data/app/views/notification/{event.txt.erb → event.text.erb} +0 -0
  132. data/app/views/notification/forgotten_password.text.erb +2 -0
  133. data/app/views/pages/content_edit.html.haml +1 -1
  134. data/app/views/pages/info.html.erb +13 -2
  135. data/app/views/pages/links.html.haml +63 -0
  136. data/app/views/user/edit_profile.html.haml +1 -1
  137. data/app/views/utility/_cm_editor.html.erb +13 -10
  138. data/app/views/utility/_cm_toolbar_markdown.html.haml +8 -1
  139. data/app/views/utility/_menu.html.haml +4 -0
  140. data/app/views/utility/mercury_html.html.haml +1 -0
  141. data/config/initializers/elastic_search.rb +6 -3
  142. data/config/initializers/extend_controller.rb +3 -0
  143. data/config/initializers/string.rb +9 -6
  144. data/config/initializers/warden.rb +49 -0
  145. data/config/locales/en.yml +29 -1
  146. data/config/routes.rb +35 -2
  147. data/lib/kit_cms.rb +7 -2
  148. data/lib/tasks/kit.rake +90 -2
  149. metadata +139 -27
  150. data/app/controllers/user/confirmations_controller.rb +0 -11
  151. data/app/controllers/user/passwords_controller.rb +0 -13
  152. data/app/controllers/user/registrations_controller.rb +0 -110
  153. data/app/controllers/user/sessions_controller.rb +0 -33
  154. data/app/controllers/user/unlocks_controller.rb +0 -13
  155. data/app/views/devise/_links.erb +0 -25
  156. data/app/views/devise/confirmations/new.html.erb +0 -12
  157. data/app/views/devise/mailer/confirmation_instructions.html.erb +0 -5
  158. data/app/views/devise/mailer/reset_password_instructions.html.erb +0 -8
  159. data/app/views/devise/mailer/unlock_instructions.html.erb +0 -7
  160. data/app/views/devise/passwords/edit.html.erb +0 -16
  161. data/app/views/devise/passwords/new.html.erb +0 -12
  162. data/app/views/devise/registrations/edit.html.erb +0 -28
  163. data/app/views/devise/registrations/new.html.erb +0 -18
  164. data/app/views/devise/sessions/new.html.erb +0 -18
  165. data/app/views/devise/shared/_links.erb +0 -25
  166. data/app/views/devise/unlocks/new.html.erb +0 -12
  167. data/app/views/pages/links.html.erb +0 -8
  168. data/app/views/user/shared/_links.erb +0 -25
  169. data/config/initializers/devise.rb +0 -196
  170. data/config/initializers/devise_extender.rb +0 -39
@@ -1,8 +1,10 @@
1
1
  class Ad < ActiveRecord::Base
2
-
2
+ include ActionView::Helpers
3
3
  attr_accessor :duration
4
4
  attr_accessor :not_found
5
5
 
6
+ attr_accessible :impression_count, :start_date, :end_date, :user_id, :name, :is_house_ad, :weighting, :body, :allow_html, :creative, :link, :price_paid, :paid_at, :notes, :creative, :create_file_name
7
+
6
8
  has_many :order_items, :as=>:orderable
7
9
  belongs_to :sellable, :polymorphic=>true
8
10
 
@@ -13,7 +15,6 @@ class Ad < ActiveRecord::Base
13
15
  has_many :ad_clicks
14
16
 
15
17
  validates :system_id, :presence=>true
16
- validates :user_id, :presence=>true
17
18
  validates :start_date, :presence=>true
18
19
  validates :end_date, :presence=>true
19
20
  validates :name, :presence=>true
@@ -96,9 +97,9 @@ class Ad < ActiveRecord::Base
96
97
  ad = self
97
98
 
98
99
  if ad.creative_file_name
99
- content = image_tag ad.creative.url(options[:preview] ? :thumb : :display)
100
+ content = "<img src='#{ad.creative.url(options[:preview] ? :thumb : :display)}' />".html_safe
100
101
  else
101
- content = ad.not_found ? "[[ad not found]]" : (ad.allow_html==1 ? ad.body : (h ad.body))
102
+ content = ad.not_found ? "[[ad not found]]" : (ad.body.is_blank ? "[[no HTML]]" : (ad.allow_html==1 ? ad.body : (h ad.body)))
102
103
  end
103
104
 
104
105
  op = []
@@ -134,9 +135,8 @@ class Ad < ActiveRecord::Base
134
135
  adsa << ad
135
136
  end
136
137
  end
137
- rand_id = adsa[rand(adsa.length)].id
138
+ adsa[rand(adsa.length-1)]
138
139
 
139
- adsa[rand_id]
140
140
  end
141
141
 
142
142
  def impress
@@ -1,7 +1,7 @@
1
- # TODO: DB
2
1
  class AdUnit < ActiveRecord::Base
3
2
 
4
3
  has_many :ad_zones
4
+ attr_accessible :name, :height, :width, :content_type, :system_id
5
5
 
6
6
  validates :name, :presence=>true, :uniqueness=>{:scope=>:system_id}
7
7
  validates :width, :presence=>true
@@ -7,6 +7,10 @@ class AdZone < ActiveRecord::Base
7
7
  has_many :ad_zones_ads
8
8
  has_many :ads, :through=>:ad_zones_ads
9
9
 
10
+ def block_name
11
+ "Ad from zone '#{self.name}'"
12
+ end
13
+
10
14
  def display_name_with_price
11
15
  "#{self.name} (#{self.width}x#{self.height}) @ &pound;#{('%.2f' % self.price_per_period)}/#{self.period.singularize}".html_safe
12
16
  end
@@ -1,7 +1,7 @@
1
1
  class Block < ActiveRecord::Base
2
2
  has_and_belongs_to_many :page_templates
3
3
 
4
- attr_accessible :name, :show_editors, :all_templates, :page_template_ids, :description, :body, :system_id
4
+ attr_accessible :name, :show_editors, :all_templates, :page_template_ids, :description, :body, :system_id, :user_id
5
5
  validates :name, :presence=>true, :length=>{:minimum=>1, :maximum=>80}
6
6
  belongs_to :user
7
7
 
@@ -0,0 +1,3 @@
1
+ class DelayedJob < ActiveRecord::Base
2
+
3
+ end
@@ -3,10 +3,14 @@ require 'net/http'
3
3
  require 'digest/md5'
4
4
 
5
5
  class Form < ActiveRecord::Base
6
+ has_many :html_assetable, :as=>:html_assetable
7
+ has_many :html_assets, :through=>:html_assetable
8
+
6
9
  has_many :form_fields, :dependent => :destroy, :order=>:display_order
7
10
  has_many :form_field_groups, :order=>:order_by
8
11
  has_many :form_submissions, :dependent => :destroy
9
12
 
13
+ belongs_to :layout
10
14
  has_many :ungrouped_form_fields, :class_name=>"FormField", :conditions=>"form_fields.form_field_group_id is null"
11
15
  validates :title, :uniqueness=>{:scope=>:system_id}, :presence=>true
12
16
  validates :url, :uniqueness=>true, :allow_blank=>true
@@ -16,9 +20,16 @@ class Form < ActiveRecord::Base
16
20
  self.form_fields.joins(:form_field_type).where("form_field_types.field_type in ('line','paragraph','select','multiselect')").all
17
21
  end
18
22
 
19
- def include_stylesheets
20
- return ["application"] if self.stylesheets.is_blank?
21
- return self.stylesheets.split(',').uniq
23
+ def javascripts
24
+ self.html_assets.where(:file_type=>"js").all
25
+ end
26
+
27
+ def stylesheets
28
+ self.html_assets.where(:file_type=>"css").all
29
+ end
30
+
31
+ def old_stylesheets
32
+ self.read_attribute(:stylesheets)
22
33
  end
23
34
 
24
35
  def field_by_name(name)
@@ -156,7 +167,8 @@ class Form < ActiveRecord::Base
156
167
  end
157
168
 
158
169
  def self.get_textcaptcha_qa
159
- xml = Net::HTTP.get(URI::Parser.new.parse("http://textcaptcha.com/api/7zsxcgrbaacc4cs4swsswk4sk863uwld"))
170
+ xml = Net::HTTP.get(URI::Parser.new.parse("http://textcaptcha.com/api/7zsxcgrbaacc4cs4swsswk4sk863uwld")) rescue nil
171
+ return unless xml
160
172
  if xml.empty?
161
173
  raise Textcaptcha::BadResponse
162
174
  else
@@ -1,4 +1,18 @@
1
1
  class HtmlAsset < ActiveRecord::Base
2
+ # has_many :page_template_html_assets
3
+ # has_many :layout_html_assets
4
+ # has_many :page_templates, :through=>:page_template_html_assets
5
+ # has_many :layouts, :through=>:layout_html_assets
6
+ # has_many :form_html_assets
7
+ # has_many :forms, :through=>:form_html_assets
8
+
9
+ has_many :html_assetables
10
+
11
+ has_many :layouts, :through=>:html_assetables, :source=>:html_assetable, :source_type=>"Layout"
12
+ has_many :page_templates, :through=>:html_assetables, :source=>:html_assetable, :source_type=>"PageTemplate"
13
+ has_many :forms, :through=>:html_assetables, :source=>:html_assetable, :source_type=>"Form"
14
+
15
+
2
16
  belongs_to :user
3
17
  validates :name, :presence=>true, :length=>{:minimum=>1, :maximum=>80}
4
18
  before_save :generate_fingerprint
@@ -7,6 +21,7 @@ class HtmlAsset < ActiveRecord::Base
7
21
  attr_accessor :compiled
8
22
 
9
23
  before_save :record_history
24
+ after_save :write_to_file
10
25
 
11
26
  def display_name
12
27
  full_type
@@ -23,7 +38,7 @@ class HtmlAsset < ActiveRecord::Base
23
38
  end
24
39
 
25
40
  def self.fetch(system_id, name, type)
26
- Rails.cache.fetch(HtmlAsset.cache_key(system_id, name.downcase, type), :expires_in=>5.minutes) do
41
+ Rails.cache.fetch(HtmlAsset.cache_key(system_id, name.downcase, type), :expires_in=>1.second) do
27
42
  asset = HtmlAsset.sys(system_id).where(:name=>name.downcase).where(:file_type=>type).first
28
43
  asset.write_to_file if asset
29
44
  asset
@@ -35,11 +50,11 @@ class HtmlAsset < ActiveRecord::Base
35
50
  end
36
51
 
37
52
  def write_to_file
38
- parent = File.join(Rails.root, "public", "kit", self.file_type)
53
+ parent = File.join(Rails.root, "public", "kit", self.system_id.to_s, self.file_type)
39
54
  FileUtils.mkdir_p(parent) unless File.exists?(parent)
40
55
 
41
- path = File.join(Rails.root, "public", "kit", self.file_type, self.kit_name)
42
- dir = File.join(Rails.root, "public", "kit", self.file_type)
56
+ path = File.join(Rails.root, "public", "kit", self.system_id.to_s, self.file_type, self.kit_name)
57
+ dir = File.join(Rails.root, "public", "kit", self.system_id.to_s, self.file_type)
43
58
  found = false
44
59
  Dir.glob(dir + "/#{self.name.downcase}*") do |f|
45
60
  if f==path
@@ -0,0 +1,3 @@
1
+ class HtmlAssetUsage < ActiveRecord::Base
2
+ belongs_to :html_assetable, :polymorphic => true
3
+ end
@@ -0,0 +1,4 @@
1
+ class HtmlAssetable < ActiveRecord::Base
2
+ belongs_to :html_asset
3
+ belongs_to :html_assetable, :polymorphic=>true
4
+ end
@@ -1,9 +1,12 @@
1
1
  class Layout < ActiveRecord::Base
2
+ has_many :html_assetable, :as=>:html_assetable
3
+ has_many :html_assets, :through=>:html_assetable
4
+
2
5
  store_templates
3
6
 
4
7
  use_kit_caching
5
8
 
6
- attr_accessible :name, :handler, :stylesheets, :javascripts, :body
9
+ attr_accessible :name, :handler, :body, :html_asset_ids, :path, :format, :locale, :system_id, :user_id
7
10
  before_save :make_path
8
11
  before_save :set_format
9
12
  has_many :page_templates
@@ -32,7 +35,7 @@ class Layout < ActiveRecord::Base
32
35
  end
33
36
 
34
37
  def make_path
35
- self.path = "layouts/" + self.name.urlise
38
+ self.path = "layouts/#{self.system_id}/#{self.name.urlise}"
36
39
  end
37
40
 
38
41
  def set_format
@@ -47,15 +50,19 @@ class Layout < ActiveRecord::Base
47
50
  ['haml', 'erb', 'builder']
48
51
  end
49
52
 
50
- def self.name_exists?(name)
51
- Layout.where("name = '#{name}'").count > 0
53
+ def self.name_exists?(sid, name)
54
+ Layout.sys(sid).where("name = '#{name}'").count > 0
55
+ end
56
+
57
+ def self.default(sid)
58
+ Layout.sys(sid).order(:id).first
52
59
  end
53
60
 
54
61
  def self.create_default(sid, user_id)
55
- layout = Layout.new(:stylesheets=>"application", :javascripts=>"", :path=>"layouts/application", :handler=>"haml", :format=>"html", :locale=>"en", :system_id=>sid, :user_id=>user_id, :name=>"application-#{sid}", :body=><<eos
62
+ layout = Layout.new(:path=>"layouts/#{sid}/application", :handler=>"haml", :format=>"html", :locale=>"en", :system_id=>sid, :user_id=>user_id, :name=>"application", :body=><<eos
56
63
  !!!
57
64
  %html
58
- / Layout: application-#{sid}
65
+ / Layout: application [#{sid}]
59
66
  %head
60
67
  = render :partial=>"layouts/kit_header"
61
68
  %style(type="text/css")
@@ -67,4 +74,27 @@ eos
67
74
 
68
75
  layout.save!
69
76
  end
77
+
78
+ def javascripts
79
+ self.html_assets.where(:file_type=>"js").all
80
+ end
81
+
82
+ def stylesheets
83
+ self.html_assets.where(:file_type=>"css").all
84
+ end
85
+
86
+ def old_stylesheets
87
+ self.read_attribute(:stylesheets)
88
+ end
89
+
90
+ def old_javascripts
91
+ self.read_attribute(:javascripts)
92
+ end
93
+
94
+ def self.preference(sid, name)
95
+ l = Layout.sys(sid).where(:id=>Preference.get_cached(sid, name)).first rescue nil
96
+ return l if l
97
+ Layout.sys(sid).order("created_at").first
98
+ end
99
+
70
100
  end
@@ -39,7 +39,7 @@ class Newsletter < ActiveRecord::Base
39
39
  job.send_id = ns.id
40
40
  job.test_mode = test
41
41
 
42
- Delayed::Job.enqueue job
42
+ Delayed::Job.enqueue job, :queue=>sid
43
43
 
44
44
  self.status = test ? "test" : "sent"
45
45
  self.save
@@ -1,6 +1,6 @@
1
1
  class Page < KitIndexed
2
2
 
3
- attr_accessible :full_path, :category_id, :status_id, :name, :title, :page_template_id, :created_by, :updated_by, :system_id, :tags, :meta_description, :meta_keywords, :header
3
+ attr_accessible :full_path, :category_id, :status_id, :name, :title, :page_template_id, :created_by, :updated_by, :system_id, :tags, :meta_description, :meta_keywords, :header, :status, :needs_crawl, :updated_crawl
4
4
 
5
5
  @@index_def = [
6
6
  {:name=>:id, :index=>:not_analyzed, :include_in_all=>false},
@@ -15,7 +15,7 @@ class Page < KitIndexed
15
15
  {:name=>:terms, :as=>"concatenated_terms", :user=>true},
16
16
  {:name=>:created_by, :as=>"user.email"},
17
17
  {:name=>:updated_at, :type=>'date', :include_in_all=>false},
18
- {:name=>:status, :as=>"status.name", :index=>:not_analyzed},
18
+ {:name=>:status, :as=>"status.name.downcase", :index=>:not_analyzed},
19
19
  {:name=>:is_deleted, :index=>:not_analyzed},
20
20
  {:name=>:content, :as=>"concatenated_content(:current)", :user=>true},
21
21
  {:name=>:old_content, :as=>"concatenated_content(:old)", :include_in_all=>false},
@@ -93,6 +93,7 @@ class Page < KitIndexed
93
93
  belongs_to :status
94
94
  belongs_to :user, :class_name=>"User", :foreign_key=>"created_by"
95
95
 
96
+ has_many :page_links
96
97
  has_many :comments
97
98
  has_many :block_instances, :dependent=>:destroy
98
99
  has_many :page_histories, :dependent=>:destroy
@@ -108,8 +109,10 @@ class Page < KitIndexed
108
109
  before_save { self.name.downcase! }
109
110
  before_save :history_start
110
111
  before_save :change_full_path
112
+
111
113
  after_save :history_end
112
114
  after_save :clear_cache
115
+
113
116
  after_destroy :clear_cache
114
117
  after_create :set_page_template_defaults
115
118
 
@@ -123,6 +126,37 @@ class Page < KitIndexed
123
126
  validate :path_must_be_unique
124
127
 
125
128
 
129
+ def full_url
130
+ "#{Preference.get_cached(self.system_id, "host")}#{self.full_path}"
131
+ end
132
+
133
+ def queue_crawl(start_crawl = true)
134
+ logger.debug "Queueing crawl for page #{self.id}"
135
+ self.needs_crawl = Time.now
136
+ self.save
137
+ Delayed::Job.enqueue PageLinkJob.new(self.system_id), :queue=>self.system_id if start_crawl
138
+ end
139
+
140
+ def crawl(force = false)
141
+ return unless force || self.needs_crawl
142
+ self.update_attributes(:needs_crawl=>nil)
143
+ PageLink.delete_all("page_id = #{self.id}")
144
+
145
+ Anemone.crawl(full_url, :depth_limit=>1, :read_timeout=>2, :discard_page_bodies=>true) do |anemone|
146
+ first_page = true
147
+ anemone.on_every_page do |page|
148
+ if first_page
149
+ first_page = false
150
+ next
151
+ end
152
+
153
+ uri = URI.parse(page.url.to_s)
154
+ PageLink.create(:page_id=>self.id, :url=>uri.path, :http_status=>page.code, :system_id=>self.system_id)
155
+ end
156
+ end
157
+ self.update_attributes(:updated_crawl=>Time.now)
158
+ end
159
+
126
160
  attr_writer :editable
127
161
  def editable
128
162
  @editable || false
@@ -0,0 +1,5 @@
1
+ class PageLink < ActiveRecord::Base
2
+
3
+ belongs_to :page
4
+
5
+ end
@@ -1,4 +1,7 @@
1
1
  class PageTemplate < ActiveRecord::Base
2
+ has_many :html_assetable, :as=>:html_assetable
3
+ has_many :html_assets, :through=>:html_assetable
4
+
2
5
  has_many :pages
3
6
  belongs_to :layout
4
7
  has_and_belongs_to_many :blocks
@@ -6,7 +9,7 @@ class PageTemplate < ActiveRecord::Base
6
9
  has_many :page_template_terms
7
10
  belongs_to :user
8
11
 
9
- attr_accessible :name, :template_type, :layout_id, :allow_anonymous_comments, :allow_user_comments, :hidden, :is_mobile, :mobile_version_id, :body, :stylesheets, :javascripts
12
+ attr_accessible :name, :template_type, :layout_id, :allow_anonymous_comments, :allow_user_comments, :hidden, :is_mobile, :mobile_version_id, :body, :system_id, :html_asset_ids, :header, :footer, :is_default, :page_type
10
13
 
11
14
  use_kit_caching
12
15
 
@@ -83,7 +86,24 @@ class PageTemplate < ActiveRecord::Base
83
86
  end
84
87
 
85
88
  def self.create_default(sid, user_id)
86
- PageTemplate.create(:system_id=>sid, :stylesheets=>"application", :header=>'', :footer=>'', :layout_id=>Layout.sys(sid).first.id, :template_type=>"haml", :is_mobile=>0, :is_default=>1, :page_type=>"default", :name=>"default", :body=>"= field('body')")
89
+ PageTemplate.create(:system_id=>sid, :header=>'', :footer=>'', :layout_id=>Layout.sys(sid).first.id, :template_type=>"haml", :is_mobile=>0, :is_default=>1, :page_type=>"default", :name=>"default", :body=>"= field('body')")
90
+ end
91
+
92
+ def javascripts
93
+ self.html_assets.where(:file_type=>"js").all
94
+ end
95
+
96
+ def stylesheets
97
+ self.html_assets.where(:file_type=>"css").all
87
98
  end
88
99
 
100
+ def old_stylesheets
101
+ self.read_attribute(:stylesheets)
102
+ end
103
+
104
+ def old_javascripts
105
+ self.read_attribute(:javascripts)
106
+ end
107
+
108
+
89
109
  end
@@ -75,7 +75,7 @@ class Preference < ActiveRecord::Base
75
75
  end
76
76
 
77
77
  def Preference.licensed?(sid, name)
78
- licensed = Rails.cache.fetch("licenses_#{sid}_#{name}", :expires_in=>10.minutes) do
78
+ licensed = Rails.cache.fetch("licenses_#{sid}_#{name}", :expires_in=>1.minutes) do
79
79
  Preference.get_cached(sid, "feature_#{name}")=="true" || Preference.get_cached(sid, "feature_*")=="true"
80
80
  end
81
81
 
@@ -0,0 +1,12 @@
1
+ class QEvent < ActiveRecord::Base
2
+
3
+ belongs_to :q_publisher
4
+
5
+ before_save { self.topic = self.topic.downcase }
6
+
7
+ after_create :run_queue
8
+
9
+ def run_queue
10
+ Delayed::Job.enqueue QueueJob.new(self.id), :queue=>self.system_id
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class QKlass < ActiveRecord::Base
2
+
3
+ belongs_to :q_publisher
4
+
5
+ end
@@ -0,0 +1,9 @@
1
+ class QMessage < ActiveRecord::Base
2
+
3
+ attr_accessible :q_publisher, :q_publisher_id, :q_event, :q_subscription, :q_user, :system_id , :status, :body, :h1, :h2
4
+
5
+ belongs_to :q_publisher
6
+ belongs_to :q_user
7
+ belongs_to :q_event
8
+ belongs_to :q_subscription
9
+ end
@@ -0,0 +1,35 @@
1
+ require 'bcrypt'
2
+ require 'digest/md5'
3
+
4
+ class QPublisher < ActiveRecord::Base
5
+ include BCrypt
6
+
7
+ attr_accessible :name, :token, :auth_method, :auth_id, :encrypted_auth_secret, :auth_secret, :twitter_consumer_key, :twitter_consumer_secret, :twitter_oauth_token, :twitter_oauth_token_secret, :mail_from
8
+ belongs_to :system
9
+ has_many :q_subscriptions, :dependent => :destroy
10
+ has_many :q_users_publishers, :dependent=>:destroy
11
+ has_many :q_users, :through=>:q_users_publishers
12
+ has_many :q_events, :dependent => :destroy
13
+ has_many :q_klasses, :dependent => :destroy
14
+ has_many :q_messages, :dependent => :destroy
15
+
16
+ def auth_secret
17
+ @auth_secret ||= Password.new(encrypted_auth_secret)
18
+ end
19
+
20
+ def auth_secret=(new_secret)
21
+ @auth_secret = Password.create(new_secret)
22
+ self.encrypted_auth_secret = @auth_secret
23
+ end
24
+
25
+ def generate_auth_secret
26
+ gen = QPublisher.generate_random
27
+ puts "Generate auth secret: #{gen}"
28
+ self.auth_secret = gen
29
+ self.save
30
+ end
31
+
32
+ def QPublisher.generate_random
33
+ Digest::MD5.hexdigest(Time.now.to_s + rand(10000000).to_s)
34
+ end
35
+ end