knitkit 2.0.0

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 (165) hide show
  1. data/GPL-3-LICENSE +674 -0
  2. data/README.md +6 -0
  3. data/Rakefile +30 -0
  4. data/app/assets/javascripts/knitkit/application.js +9 -0
  5. data/app/assets/stylesheets/knitkit/application.css +7 -0
  6. data/app/controllers/knitkit/articles_controller.rb +7 -0
  7. data/app/controllers/knitkit/base_controller.rb +45 -0
  8. data/app/controllers/knitkit/blogs_controller.rb +27 -0
  9. data/app/controllers/knitkit/comments_controller.rb +18 -0
  10. data/app/controllers/knitkit/erp_app/desktop/app_controller.rb +135 -0
  11. data/app/controllers/knitkit/erp_app/desktop/articles_controller.rb +144 -0
  12. data/app/controllers/knitkit/erp_app/desktop/comments_controller.rb +43 -0
  13. data/app/controllers/knitkit/erp_app/desktop/content_controller.rb +27 -0
  14. data/app/controllers/knitkit/erp_app/desktop/file_assets_controller.rb +145 -0
  15. data/app/controllers/knitkit/erp_app/desktop/image_assets_controller.rb +28 -0
  16. data/app/controllers/knitkit/erp_app/desktop/inquiries_controller.rb +68 -0
  17. data/app/controllers/knitkit/erp_app/desktop/position_controller.rb +20 -0
  18. data/app/controllers/knitkit/erp_app/desktop/theme_controller.rb +272 -0
  19. data/app/controllers/knitkit/erp_app/desktop/versions_controller.rb +135 -0
  20. data/app/controllers/knitkit/erp_app/desktop/website_controller.rb +177 -0
  21. data/app/controllers/knitkit/erp_app/desktop/website_nav_controller.rb +143 -0
  22. data/app/controllers/knitkit/erp_app/desktop/website_section_controller.rb +116 -0
  23. data/app/controllers/knitkit/unauthorized_controller.rb +8 -0
  24. data/app/controllers/knitkit/website_sections_controller.rb +17 -0
  25. data/app/helpers/application_helper.rb +132 -0
  26. data/app/models/article.rb +14 -0
  27. data/app/models/blog.rb +21 -0
  28. data/app/models/comment.rb +24 -0
  29. data/app/models/content.rb +158 -0
  30. data/app/models/extensions/user.rb +5 -0
  31. data/app/models/published_element.rb +9 -0
  32. data/app/models/published_website.rb +118 -0
  33. data/app/models/theme.rb +239 -0
  34. data/app/models/website.rb +457 -0
  35. data/app/models/website_host.rb +3 -0
  36. data/app/models/website_inquiry.rb +11 -0
  37. data/app/models/website_inquiry_mailer.rb +12 -0
  38. data/app/models/website_nav.rb +17 -0
  39. data/app/models/website_nav_item.rb +21 -0
  40. data/app/models/website_section.rb +152 -0
  41. data/app/models/website_section_content.rb +4 -0
  42. data/app/views/knitkit/articles/index.html.erb +3 -0
  43. data/app/views/knitkit/articles/show.html.erb +4 -0
  44. data/app/views/knitkit/blogs/_add_comment.html.erb +28 -0
  45. data/app/views/knitkit/blogs/_comment.html.erb +8 -0
  46. data/app/views/knitkit/blogs/index.html.erb +51 -0
  47. data/app/views/knitkit/blogs/index.rss.builder +23 -0
  48. data/app/views/knitkit/blogs/show.html.erb +22 -0
  49. data/app/views/knitkit/unauthorized/index.html.erb +4 -0
  50. data/app/views/knitkit/website_sections/index.html.erb +6 -0
  51. data/app/views/layouts/knitkit/base.html.erb +59 -0
  52. data/app/views/menus/knitkit/_default_menu.html.erb +23 -0
  53. data/app/views/menus/knitkit/_default_section_menu.html.erb +27 -0
  54. data/app/views/menus/knitkit/_default_sub_menu.html.erb +45 -0
  55. data/app/views/menus/knitkit/_default_sub_section_menu.html.erb +49 -0
  56. data/app/views/shared/knitkit/_bread_crumb.html.erb +7 -0
  57. data/app/views/shared/knitkit/_footer.html.erb +3 -0
  58. data/app/views/website_inquiry_mailer/inquiry.erb +3 -0
  59. data/app/widgets/contact_us/base.rb +86 -0
  60. data/app/widgets/contact_us/javascript/contact_us.js +13 -0
  61. data/app/widgets/contact_us/views/_contact_form.html.erb +36 -0
  62. data/app/widgets/contact_us/views/error.html.erb +10 -0
  63. data/app/widgets/contact_us/views/index.html.erb +1 -0
  64. data/app/widgets/contact_us/views/layouts/base.html.erb +7 -0
  65. data/app/widgets/contact_us/views/success.html.erb +4 -0
  66. data/app/widgets/google_map/base.rb +48 -0
  67. data/app/widgets/google_map/javascript/google_map.js +174 -0
  68. data/app/widgets/google_map/views/index.html.erb +41 -0
  69. data/app/widgets/login/base.rb +61 -0
  70. data/app/widgets/login/javascript/login.js +162 -0
  71. data/app/widgets/login/views/index.html.erb +37 -0
  72. data/app/widgets/login/views/layouts/base.html.erb +14 -0
  73. data/app/widgets/login/views/login_header.html.erb +9 -0
  74. data/app/widgets/login/views/reset_password.html.erb +26 -0
  75. data/app/widgets/manage_profile/base.rb +327 -0
  76. data/app/widgets/manage_profile/javascript/manage_profile.js +11 -0
  77. data/app/widgets/manage_profile/views/_contact_information_form.html.erb +180 -0
  78. data/app/widgets/manage_profile/views/_password_form.html.erb +20 -0
  79. data/app/widgets/manage_profile/views/_user_information_form.html.erb +30 -0
  80. data/app/widgets/manage_profile/views/contact_type_in_use.html.erb +4 -0
  81. data/app/widgets/manage_profile/views/default_type_error.html.erb +5 -0
  82. data/app/widgets/manage_profile/views/error.html.erb +3 -0
  83. data/app/widgets/manage_profile/views/index.html.erb +46 -0
  84. data/app/widgets/manage_profile/views/layouts/base.html.erb +1 -0
  85. data/app/widgets/manage_profile/views/password_blank.html.erb +4 -0
  86. data/app/widgets/manage_profile/views/password_invalid.html.erb +4 -0
  87. data/app/widgets/manage_profile/views/password_success.html.erb +3 -0
  88. data/app/widgets/manage_profile/views/success.html.erb +3 -0
  89. data/app/widgets/reset_password/base.rb +42 -0
  90. data/app/widgets/reset_password/javascript/reset_password.js +13 -0
  91. data/app/widgets/reset_password/views/index.html.erb +31 -0
  92. data/app/widgets/reset_password/views/layouts/base.html.erb +1 -0
  93. data/app/widgets/search/base.rb +80 -0
  94. data/app/widgets/search/javascript/search.js +31 -0
  95. data/app/widgets/search/views/_search.html.erb +39 -0
  96. data/app/widgets/search/views/index.html.erb +3 -0
  97. data/app/widgets/search/views/layouts/base.html.erb +24 -0
  98. data/app/widgets/search/views/show.html.erb +48 -0
  99. data/app/widgets/signup/base.rb +72 -0
  100. data/app/widgets/signup/javascript/signup.js +13 -0
  101. data/app/widgets/signup/views/_signup_form.html.erb +36 -0
  102. data/app/widgets/signup/views/error.html.erb +11 -0
  103. data/app/widgets/signup/views/index.html.erb +1 -0
  104. data/app/widgets/signup/views/layouts/base.html.erb +7 -0
  105. data/app/widgets/signup/views/success.html.erb +4 -0
  106. data/config/environment.rb +0 -0
  107. data/config/routes.rb +41 -0
  108. data/db/data_migrations/20110509223702_add_publisher_role.rb +11 -0
  109. data/db/data_migrations/20110816153456_add_knitkit_application.rb +31 -0
  110. data/db/data_migrations/upgrade/20111011203718_create_paths_for_sections.rb +13 -0
  111. data/db/data_migrations/upgrade/20111216192114_add_secured_models_to_menu_items.rb +18 -0
  112. data/db/data_migrations/upgrade/20111216202819_set_contents_iid_to_permalink_where_null.rb +12 -0
  113. data/db/migrate/20110211002317_setup_knitkit.rb +259 -0
  114. data/db/migrate/upgrade/20111014190442_update_contents.rb +25 -0
  115. data/db/migrate/upgrade/20111014201502_add_published_by_to_published_elements.rb +22 -0
  116. data/db/migrate/upgrade/20111017133851_add_iid_to_section.rb +21 -0
  117. data/db/migrate/upgrade/20111027145006_add_in_menu_to_section.rb +19 -0
  118. data/lib/knitkit.rb +12 -0
  119. data/lib/knitkit/engine.rb +26 -0
  120. data/lib/knitkit/extensions.rb +18 -0
  121. data/lib/knitkit/extensions/action_controller/theme_support/acts_as_themed_controller.rb +88 -0
  122. data/lib/knitkit/extensions/active_record/acts_as_commentable.rb +28 -0
  123. data/lib/knitkit/extensions/active_record/acts_as_publishable.rb +38 -0
  124. data/lib/knitkit/extensions/active_record/theme_support/has_many_themes.rb +34 -0
  125. data/lib/knitkit/extensions/compass/widgets/base.rb +53 -0
  126. data/lib/knitkit/extensions/core/array.rb +5 -0
  127. data/lib/knitkit/extensions/railties/action_view.rb +187 -0
  128. data/lib/knitkit/extensions/railties/theme_support/asset_tag_helper.rb +198 -0
  129. data/lib/knitkit/extensions/railties/theme_support/theme_file_resolver.rb +44 -0
  130. data/lib/knitkit/routing_filter/section_router.rb +55 -0
  131. data/lib/knitkit/syntax_validator.rb +32 -0
  132. data/lib/knitkit/version.rb +3 -0
  133. data/lib/tasks/knitkit_tasks.rake +4 -0
  134. data/public/images/knitkit/bullet.png +0 -0
  135. data/public/images/knitkit/content.png +0 -0
  136. data/public/images/knitkit/footer.png +0 -0
  137. data/public/images/knitkit/graphic.png +0 -0
  138. data/public/images/knitkit/greyFadeDown.png +0 -0
  139. data/public/images/knitkit/link.png +0 -0
  140. data/public/images/knitkit/logo.png +0 -0
  141. data/public/images/knitkit/menu.png +0 -0
  142. data/public/images/knitkit/menu_select.png +0 -0
  143. data/public/images/knitkit/search.png +0 -0
  144. data/public/javascripts/datepicker.js +440 -0
  145. data/public/javascripts/erp_app/desktop/applications/knitkit/articles_grid_panel.js +473 -0
  146. data/public/javascripts/erp_app/desktop/applications/knitkit/center_region.js +576 -0
  147. data/public/javascripts/erp_app/desktop/applications/knitkit/comments_grid_panel.js +217 -0
  148. data/public/javascripts/erp_app/desktop/applications/knitkit/east_region.js +26 -0
  149. data/public/javascripts/erp_app/desktop/applications/knitkit/file_assets_panel.js +109 -0
  150. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_data_view.js +30 -0
  151. data/public/javascripts/erp_app/desktop/applications/knitkit/image_assets_panel.js +160 -0
  152. data/public/javascripts/erp_app/desktop/applications/knitkit/inquiries_grid_panel.js +46 -0
  153. data/public/javascripts/erp_app/desktop/applications/knitkit/module.js +46 -0
  154. data/public/javascripts/erp_app/desktop/applications/knitkit/publish_window.js +92 -0
  155. data/public/javascripts/erp_app/desktop/applications/knitkit/published_grid_panel.js +220 -0
  156. data/public/javascripts/erp_app/desktop/applications/knitkit/section_articles_grid_panel.js +613 -0
  157. data/public/javascripts/erp_app/desktop/applications/knitkit/themes_tree_panel.js +573 -0
  158. data/public/javascripts/erp_app/desktop/applications/knitkit/versions_grid_panel.js +664 -0
  159. data/public/javascripts/erp_app/desktop/applications/knitkit/west_region.js +2161 -0
  160. data/public/javascripts/erp_app/desktop/applications/knitkit/widgets_panel.js +52 -0
  161. data/public/stylesheets/datepicker.css +121 -0
  162. data/public/stylesheets/erp_app/desktop/applications/knitkit/knitkit.css +114 -0
  163. data/public/stylesheets/extjs/resources/css/knitkit_extjs_4.css +219 -0
  164. data/public/stylesheets/knitkit/style.css +394 -0
  165. metadata +289 -0
@@ -0,0 +1,116 @@
1
+ module Knitkit
2
+ module ErpApp
3
+ module Desktop
4
+ class WebsiteSectionController < Knitkit::ErpApp::Desktop::AppController
5
+ before_filter :set_website_section, :only => [:update, :update_security, :add_layout, :get_layout, :save_layout]
6
+
7
+ def new
8
+ website = Website.find(params[:website_id])
9
+ website_section = nil
10
+
11
+ if params[:title].to_s.downcase == 'blog' && params[:type] == 'Blog'
12
+ result = {:success => false, :message => 'Blog can not be the title of a Blog'}
13
+ else
14
+ website_section = WebsiteSection.new
15
+ website_section.website_id = website.id
16
+ website_section.in_menu = params[:in_menu] == 'yes'
17
+ website_section.title = params[:title]
18
+ website_section.type = params[:type] unless params[:type] == 'Page'
19
+ website_section.internal_identifier = params[:internal_identifier]
20
+
21
+ if website_section.save
22
+ if params[:website_section_id]
23
+ parent_website_section = WebsiteSection.find(params[:website_section_id])
24
+ website_section.move_to_child_of(parent_website_section)
25
+ end
26
+
27
+ website_section.update_path!
28
+ result = {:success => true, :node => build_section_hash(website_section, website_section.website)}
29
+ else
30
+ message = "<ul>"
31
+ website_section.errors.collect do |e, m|
32
+ message << "<li>#{e} #{m}</li>"
33
+ end
34
+ message << "</ul>"
35
+ result = {:success => false, :message => message}
36
+ end
37
+
38
+ end
39
+
40
+ render :json => result
41
+ end
42
+
43
+ def delete
44
+ render :json => WebsiteSection.destroy(params[:id]) ? {:success => true} : {:success => false}
45
+ end
46
+
47
+ def update_security
48
+ website = Website.find(params[:site_id])
49
+ if(params[:secure] == "true")
50
+ @website_section.add_role(website.role)
51
+ else
52
+ @website_section.remove_role(website.role)
53
+ end
54
+
55
+ render :json => {:success => true}
56
+ end
57
+
58
+ def update
59
+ @website_section.in_menu = params[:in_menu] == 'yes'
60
+ @website_section.title = params[:title]
61
+ @website_section.internal_identifier = params[:internal_identifier]
62
+
63
+ if @website_section.save
64
+ render :json => {:success => true}
65
+ else
66
+ render :json => {:success => false}
67
+ end
68
+ end
69
+
70
+ def add_layout
71
+ @website_section.create_layout
72
+ render :json => {:success => true}
73
+ end
74
+
75
+ def get_layout
76
+ render :text => @website_section.layout
77
+ end
78
+
79
+ def save_layout
80
+ result = Knitkit::SyntaxValidator.validate_content(:erb, params[:content])
81
+
82
+ unless result
83
+ @website_section.layout = params[:content]
84
+ render :json => @website_section.save ? {:success => true} : {:success => false}
85
+ else
86
+ render :json => {:success => false, :message => result}
87
+ end
88
+ end
89
+
90
+ def available_articles
91
+ current_articles = Article.joins("INNER JOIN website_section_contents ON website_section_contents.content_id = contents.id").where("website_section_id = #{params[:section_id]}").all
92
+ available_articles = Article.all - current_articles
93
+
94
+ render :inline => "{\"articles\":#{available_articles.to_json(:only => [:internal_identifier, :id])}}"
95
+ end
96
+
97
+ def existing_sections
98
+ website = Website.find(params[:website_id])
99
+ WebsiteSection.class_eval do
100
+ def title_permalink
101
+ "#{self.title} - #{self.path}"
102
+ end
103
+ end
104
+ render :inline => website.sections.to_json(:only => [:id], :methods => [:title_permalink])
105
+ end
106
+
107
+ protected
108
+
109
+ def set_website_section
110
+ @website_section = WebsiteSection.find(params[:id])
111
+ end
112
+
113
+ end#WebsiteSectionController
114
+ end#Desktop
115
+ end#ErpApp
116
+ end#Knitkit
@@ -0,0 +1,8 @@
1
+ module Knitkit
2
+ class UnauthorizedController < BaseController
3
+ #no section to set
4
+ def set_section
5
+ return false
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module Knitkit
2
+ class WebsiteSectionsController < BaseController
3
+
4
+ def index
5
+ if @website_section.has_access?(current_user)
6
+ @contents = Article.find_published_by_section(@active_publication, @website_section)
7
+ unless @website_section.layout.nil?
8
+ layout = @website_section.get_published_layout(@active_publication)
9
+ render :inline => layout, :layout => 'knitkit/base'
10
+ end
11
+ else
12
+ redirect_to '/unauthorized'
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,132 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ def theme_stylesheet_path(theme, source)
4
+ theme = @controller.website.themes.find_by_theme_id(theme) unless theme.is_a?(Theme)
5
+ theme_compute_public_path(theme, source, theme.url + '/stylesheets', 'css')
6
+ end
7
+ alias_method :theme_path_to_stylesheet, :theme_stylesheet_path
8
+
9
+ def theme_stylesheet_link_tag(theme_id, *sources)
10
+ theme = @controller.website.themes.find_by_theme_id(theme_id)
11
+ return("could not find theme with the id #{theme_id}") unless theme
12
+
13
+ options = sources.extract_options!.stringify_keys
14
+ cache = options.delete("cache")
15
+ recursive = options.delete("recursive")
16
+
17
+ if ActionController::Base.perform_caching && cache
18
+ joined_stylesheet_name = (cache == true ? "all" : cache) + ".css"
19
+ joined_stylesheet_path = File.join(theme.path + '/stylesheets', joined_stylesheet_name)
20
+
21
+ paths = theme_compute_stylesheet_paths(theme, sources, recursive)
22
+ theme_write_asset_file_contents(theme, joined_stylesheet_path, paths) unless File.exists?(joined_stylesheet_path)
23
+ theme_stylesheet_tag(theme, joined_stylesheet_name, options)
24
+ else
25
+ theme_expand_stylesheet_sources(theme, sources, recursive).collect do |source|
26
+ theme_stylesheet_tag(theme, source, options)
27
+ end.join("\n")
28
+ end
29
+ end
30
+
31
+ def theme_javascript_path(theme, source)
32
+ theme = @controller.website.themes.find_by_theme_id(theme) unless theme.is_a?(Theme)
33
+ theme_compute_public_path(theme, source, theme.url + '/javascripts', 'js')
34
+ end
35
+ alias_method :theme_path_to_javascript, :theme_javascript_path
36
+
37
+ def theme_javascript_include_tag(theme_id, *sources)
38
+ theme = @controller.website.themes.find_by_theme_id(theme_id)
39
+ return("could not find theme with the id #{theme_id}") unless theme
40
+
41
+ options = sources.extract_options!.stringify_keys
42
+ cache = options.delete("cache")
43
+ recursive = options.delete("recursive")
44
+
45
+ if ActionController::Base.perform_caching && cache
46
+ joined_javascript_name = (cache == true ? "all" : cache) + ".js"
47
+ joined_javascript_path = File.join(theme.path + '/javascripts', joined_javascript_name)
48
+
49
+ paths = theme_compute_javascript_paths(theme, sources, recursive)
50
+ theme_write_asset_file_contents(theme, joined_javascript_path, paths) unless File.exists?(joined_javascript_path)
51
+ theme_javascript_src_tag(theme, joined_javascript_name, options)
52
+ else
53
+ theme_expand_javascript_sources(theme, sources, recursive).collect do |source|
54
+ theme_javascript_src_tag(theme, source, options)
55
+ end.join("\n")
56
+ end
57
+ end
58
+
59
+ private
60
+ def theme_compute_public_path(theme, source, dir, ext = nil, include_host = true)
61
+ has_request = @controller.respond_to?(:request)
62
+
63
+ if ext && (File.extname(source).blank? || File.exist?(File.join(theme.path, dir, "#{source}.#{ext}")))
64
+ source += ".#{ext}"
65
+ end
66
+
67
+ unless source =~ %r{^[-a-z]+://}
68
+ source = "/#{dir}/#{source}" unless source[0] == ?/
69
+
70
+ source = theme_rewrite_asset_path(theme, source)
71
+
72
+ if has_request && include_host
73
+ unless source =~ %r{^#{ActionController::Base.relative_url_root}/}
74
+ source = "#{ActionController::Base.relative_url_root}#{source}"
75
+ end
76
+ end
77
+ end
78
+
79
+ if include_host && source !~ %r{^[-a-z]+://}
80
+ host = compute_asset_host(source)
81
+
82
+ if has_request && host.present? && host !~ %r{^[-a-z]+://}
83
+ host = "#{@controller.request.protocol}#{host}"
84
+ end
85
+
86
+ "#{host}#{source}"
87
+ else
88
+ source
89
+ end
90
+ end
91
+
92
+ def theme_stylesheet_tag(theme, source, options)
93
+ options = { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen",
94
+ "href" => html_escape(theme_path_to_stylesheet(theme, source)) }.merge(options)
95
+ tag("link", options, false, false)
96
+ end
97
+
98
+ def theme_javascript_src_tag(theme, source, options)
99
+ options = { "type" => Mime::JS, "src" => theme_path_to_javascript(theme, source) }.merge(options)
100
+ content_tag("script", "", options)
101
+ end
102
+
103
+ def theme_compute_stylesheet_paths(theme, *args)
104
+ theme_expand_stylesheet_sources(theme, *args).collect do |source|
105
+ theme_compute_public_path(theme, source, theme.url + '/stylesheets', 'css', false)
106
+ end
107
+ end
108
+
109
+ def theme_compute_javascript_paths(theme, *args)
110
+ theme_expand_javascript_sources(theme, *args).collect do |source|
111
+ theme_compute_public_path(theme, source, theme.url + '/javascripts', 'js', false)
112
+ end
113
+ end
114
+
115
+ def theme_expand_javascript_sources(theme, sources, recursive = false)
116
+ if sources.include?(:all)
117
+ all_javascript_files = collect_asset_files(theme.path + '/javascripts', ('**' if recursive), '*.js').uniq
118
+ else
119
+ sources.collect { |source| determine_source(source, {}) }.flatten
120
+ end
121
+ end
122
+
123
+ def theme_expand_stylesheet_sources(theme, sources, recursive)
124
+ if sources.first == :all
125
+ collect_asset_files(theme.path + '/stylesheets', ('**' if recursive), '*.css')
126
+ else
127
+ sources.collect do |source|
128
+ determine_source(source, {})
129
+ end.flatten
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,14 @@
1
+ class Article < Content
2
+ has_permalink :title
3
+
4
+ before_save :check_internal_indentifier
5
+
6
+ def to_param
7
+ permalink
8
+ end
9
+
10
+ def check_internal_indentifier
11
+ self.internal_identifier = self.permalink if self.internal_identifier.blank?
12
+ end
13
+
14
+ end
@@ -0,0 +1,21 @@
1
+ class Blog < WebsiteSection
2
+ def find_blog_posts
3
+ Article.find_by_website_section_id(self.id).sort_by{|article| article.created_at}.reverse
4
+ end
5
+
6
+ def find_published_blog_posts(active_publication)
7
+ Article.find_published_by_section(active_publication, self).sort_by{|article| article.created_at}.reverse
8
+ end
9
+
10
+ def find_published_blog_posts_with_tag(active_publication, tag)
11
+ Article.find_published_by_section_with_tag(active_publication, self, tag).sort_by{|article| article.created_at}.reverse
12
+ end
13
+
14
+ def find_blog_post(permalink)
15
+ Article.joins(:website_section_contents).where('website_section_contents.website_section_id = ? and permalink = ?',self.id, permalink).first
16
+ end
17
+
18
+ def find_published_blog_post(active_publication, permalink)
19
+ Article.find_published_by_section(active_publication, self).find{|item| item.permalink == permalink}
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :commented_record, :polymorphic => true
3
+ belongs_to :user
4
+
5
+ validates :comment, :presence => {:message => 'Comment cannot be blank'}
6
+
7
+ alias :approved_by :user
8
+
9
+ scope :in_order, order('created_at ASC')
10
+ scope :recent, order('created_at DESC')
11
+ scope :approved, where('approved = 1')
12
+
13
+ def approved?
14
+ self.approved == 1
15
+ end
16
+
17
+ def approve(user)
18
+ self.approved = 1
19
+ self.user = user
20
+ self.approved_at = Time.now
21
+ self.save
22
+ end
23
+
24
+ end
@@ -0,0 +1,158 @@
1
+ require 'will_paginate/array'
2
+
3
+ class Content < ActiveRecord::Base
4
+ acts_as_taggable
5
+ acts_as_commentable
6
+ acts_as_versioned :table_name => :content_versions
7
+ can_be_published
8
+
9
+ has_many :website_section_contents, :dependent => :destroy
10
+ has_many :website_sections, :through => :website_section_contents
11
+ belongs_to :created_by, :class_name => "User"
12
+ belongs_to :updated_by, :class_name => "User"
13
+
14
+ validates :type, :presence => {:message => 'Type cannot be blank'}
15
+ validates_uniqueness_of :internal_identifier
16
+
17
+ def self.search(options = {})
18
+ if options[:section_unique_name].nil? or options[:section_unique_name].empty?
19
+ section_scope = ''
20
+ else
21
+ section_scope = "website_sections.internal_identifier = '#{options[:section_unique_name]}' AND"
22
+ end
23
+
24
+ if options[:content_type].nil? or options[:content_type].empty?
25
+ content_type_scope = ''
26
+ else
27
+ content_type_scope = "website_sections.type = '#{options[:content_type]}' AND"
28
+ end
29
+
30
+ Content.includes([:website_sections]).where("#{content_type_scope} #{section_scope}
31
+ website_sections.website_id = #{options[:website_id]} AND
32
+ (UPPER(contents.title) LIKE UPPER('%#{options[:query]}%')
33
+ OR UPPER(contents.excerpt_html) LIKE UPPER('%#{options[:query]}%')
34
+ OR UPPER(contents.body_html) LIKE UPPER('%#{options[:query]}%') )").order("contents.created_at DESC").paginate(:page => options[:page], :per_page => options[:per_page])
35
+ end
36
+
37
+ def self.do_search(options = {})
38
+ @results = Content.search(options)
39
+
40
+ @search_results = build_search_results(@results)
41
+
42
+ @page_results = WillPaginate::Collection.create(options[:page], options[:per_page], @results.total_entries) do |pager|
43
+ pager.replace(@search_results)
44
+ end
45
+
46
+ return @page_results
47
+ end
48
+
49
+ def self.find_by_section_id( website_section_id )
50
+ Content.joins(:website_section_contents).where('website_section_id = ?', website_section_id).order("website_section_contents.position ASC, website_section_contents.created_at DESC").all
51
+ end
52
+
53
+ def self.find_by_section_id_filtered_by_id( website_section_id, id_filter_list )
54
+ Content.joins(:website_section_contents).where("website_section_id = ? AND contents.id IN (#{id_filter_list.join(',')})", website_section_id).all
55
+ end
56
+
57
+ def self.find_published_by_section(active_publication, website_section)
58
+ published_content = []
59
+ contents = self.find_by_section_id( website_section.id )
60
+ contents.each do |content|
61
+ content = get_published_version(active_publication, content)
62
+ published_content << content unless content.nil?
63
+ end
64
+
65
+ published_content
66
+ end
67
+
68
+ def self.find_published_by_section_with_tag(active_publication, website_section, tag)
69
+ published_content = []
70
+ id_filter_list = self.tagged_with(tag.name).collect{|t| t.id }
71
+ contents = self.find_by_section_id_filtered_by_id( website_section.id, id_filter_list )
72
+ contents.each do |content|
73
+ content = get_published_version(active_publication, content)
74
+ published_content << content unless content.nil?
75
+ end
76
+
77
+ published_content
78
+ end
79
+
80
+ def find_website_sections_by_site_id( website_id )
81
+ self.website_sections.where('website_id = ?',website_id).all
82
+ end
83
+
84
+ def position( website_section_id )
85
+ position = self.website_section_contents.find_by_website_section_id(website_section_id).position
86
+ position
87
+ end
88
+
89
+ def add_comment(options={})
90
+ self.comments.create(options)
91
+ end
92
+
93
+ def get_comments(limit)
94
+ self.commentable.comments.recent.limit(limit).all
95
+ end
96
+
97
+ def update_content_area_and_position_by_section(section, content_area, position)
98
+ website_section_content = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first
99
+ unless website_section_content.nil?
100
+ website_section_content.content_area = content_area
101
+ website_section_content.position = position
102
+ website_section_content.save
103
+ end
104
+ end
105
+
106
+ def content_area_by_website_section(section)
107
+ content_area = nil
108
+ unless WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.nil?
109
+ content_area = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.content_area
110
+ end
111
+ content_area
112
+ end
113
+
114
+ def position_by_website_section(section)
115
+ position = nil
116
+ unless WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.nil?
117
+ position = WebsiteSectionContent.where('content_id = ? and website_section_id = ?',self.id, section.id).first.position
118
+ end
119
+ position
120
+ end
121
+
122
+ protected
123
+
124
+ def self.build_search_results(results)
125
+ # and if it is a blog get the article link and title
126
+ results_array = []
127
+ results.each do |content|
128
+ section = content.website_sections.first
129
+
130
+ results_hash = {}
131
+ if section.attributes['type'] == 'Blog'
132
+ results_hash[:link] = section.permalink + '/' + content.permalink
133
+ results_hash[:title] = content.title
134
+ else
135
+ results_hash[:link] = section.permalink
136
+ results_hash[:title] = section.title
137
+ end
138
+ results_hash[:section] = section
139
+ results_hash[:content] = content
140
+
141
+ results_array << results_hash
142
+ end
143
+
144
+ results_array
145
+ end
146
+
147
+ private
148
+
149
+ def self.get_published_version(active_publication, content)
150
+ content_version = nil
151
+ published_website_id = active_publication.id
152
+ published_element = PublishedElement.includes([:published_website]).where('published_websites.id = ? and published_element_record_id = ? and published_element_record_type = ?', published_website_id, content.id, 'Content').first
153
+ unless published_element.nil?
154
+ content_version = Content::Version.where('version = ? and content_id = ?', published_element.version, published_element.published_element_record_id).first
155
+ end
156
+ content_version
157
+ end
158
+ end