Class: Article
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Article
show all
- Extended by:
- FriendlyId
- Defined in:
- app/models/article.rb
Constant Summary
collapse
- MetatagNames =
["Title Tag", "Meta Description", "Keywords", "OpenGraph Title", "OpenGraph Description", "OpenGraph Type", "OpenGraph URL", "OpenGraph Image"]
- LiquidParser =
{}
- SortOptions =
["Created_at", "Updated_at", "Random", "Alphabetically"]
- DynamicRedirectOptions =
[[:false,"disabled"],[:latest,"latest subentry"], [:oldest, "eldest subentry"]]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
dynamic methods for article.event or article.consultant .… depending on related object type
198
199
200
201
202
203
204
205
206
207
208
|
# File 'app/models/article.rb', line 198
def method_missing(meth, *args, &block)
if meth.to_s.split(".").first == self.get_related_object.class.name.downcase
if meth.to_s.split(".").count == 1
self.get_related_object
else
self.get_related_object.send(meth.to_s.split(".").last)
end
else
super
end
end
|
Instance Attribute Details
#hint_label ⇒ Object
Returns the value of attribute hint_label.
55
56
57
|
# File 'app/models/article.rb', line 55
def hint_label
@hint_label
end
|
Class Method Details
.active ⇒ Object
Class Methods **************************
424
425
426
|
# File 'app/models/article.rb', line 424
def self.active
Article.where("active = 1 AND active_since < '#{Time.now.utc}'")
end
|
.article_types_for_search ⇒ Object
474
475
476
477
478
479
480
481
482
483
|
# File 'app/models/article.rb', line 474
def self.article_types_for_search
results = []
path_to_articletypes = File.join(::Rails.root, "app", "views", "articletypes")
if Dir.exist?(path_to_articletypes)
Dir.foreach(path_to_articletypes) do |name| results << name.capitalize unless name.include?(".")
end
end
return results
end
|
.article_types_for_select ⇒ Object
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
# File 'app/models/article.rb', line 457
def self.article_types_for_select
results = []
path_to_articletypes = File.join(::Rails.root, "app", "views", "articletypes")
if Dir.exist?(path_to_articletypes)
Dir.foreach(path_to_articletypes) do |name| file_name_path = File.join(path_to_articletypes,name)
if File.directory?(file_name_path)
Dir.foreach(file_name_path) do |sub_name|
file_name = "#{name}#{sub_name}" if File.exist?(File.join(file_name_path,sub_name)) && (sub_name =~ /^_(?!edit).*/) == 0
results << file_name.split(".").first.to_s.titleize if file_name.present?
end
end
end
end
return results
end
|
.init_image_methods ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'app/models/article.rb', line 153
def self.init_image_methods
if ActiveRecord::Base.connection.table_exists?("settings")
Setting.for_key("rdcms.article.image_positions").split(",").each do |image_type|
define_method "image_#{image_type.underscore}" do
self.image(image_type,"original")
end
Upload.attachment_definitions[:upload][:styles].keys.each do |style_name|
define_method "image_#{image_type.underscore}_#{style_name.to_s}" do
self.image(image_type,style_name)
end
end
end
end
end
|
.load_liquid_methods(options = {}) ⇒ Object
438
439
440
|
# File 'app/models/article.rb', line 438
def self.load_liquid_methods(options={})
end
|
.recent(count) ⇒ Object
442
443
444
|
# File 'app/models/article.rb', line 442
def self.recent(count)
Article.where('title IS NOT NULL').order('updated_at DESC').limit(count)
end
|
.recreate_cache ⇒ Object
446
447
448
449
450
451
452
453
454
455
|
# File 'app/models/article.rb', line 446
def self.recreate_cache
if RUBY_VERSION.include?("1.9.")
ArticlesCacheWorker.perform_async()
else
Article.active.each do |article|
article.updated_at = Time.now
article.save
end
end
end
|
.search_by_url(url) ⇒ Object
428
429
430
431
432
433
434
435
436
|
# File 'app/models/article.rb', line 428
def self.search_by_url(url)
article = nil
articles = Article.where(:url_name => url.split("/").last.to_s.split(".").first)
article_path = "/#{url.split('.').first}"
if articles.count > 0
article = articles.select{|a| a.public_url == article_path}.first
end
return article
end
|
.templates_for_select ⇒ Object
485
486
487
|
# File 'app/models/article.rb', line 485
def self.templates_for_select
Dir.glob(File.join(::Rails.root, "app", "views", "layouts", "*.html.erb")).map{|a| File.basename(a, ".html.erb")}.delete_if{|a| a =~ /^_/ }
end
|
Instance Method Details
#absolute_public_url ⇒ Object
257
258
259
260
261
262
263
|
# File 'app/models/article.rb', line 257
def absolute_public_url
if Setting.for_key("rdcms.use_ssl") == "true"
"https://#{Setting.for_key('rdcms.url')}#{self.public_url}"
else
"http://#{Setting.for_key('rdcms.url')}#{self.public_url}"
end
end
|
#article_for_index_limit ⇒ Object
359
360
361
362
363
364
365
|
# File 'app/models/article.rb', line 359
def article_for_index_limit
if self.article_for_index_count.to_i <= 0
return 1000
else
self.article_for_index_count.to_i
end
end
|
#article_type_for_search ⇒ Object
Liefert Kategorienenamen für sie Suche unabhängig ob Die Seite eine show oder indexseite ist
329
330
331
332
333
334
335
|
# File 'app/models/article.rb', line 329
def article_type_for_search
if self.article_type.present?
self.article_type.split(" ").first
else
"Article"
end
end
|
#article_type_form_file ⇒ Object
Gibt Consultant | Subsidiary | etc. zurück je nach Seitentyp
319
320
321
|
# File 'app/models/article.rb', line 319
def article_type_form_file
self.article_type.split(" ").first if self.article_type.present?
end
|
#article_type_xml_fields ⇒ Object
Returns a special article_typs customs rss fields as xml
224
225
226
227
228
229
|
# File 'app/models/article.rb', line 224
def article_type_xml_fields
related_object = self.get_related_object
if related_object && related_object.respond_to?(:custom_rss_fields)
related_object.
end
end
|
#breadcrumb_name ⇒ Object
345
346
347
348
349
350
351
|
# File 'app/models/article.rb', line 345
def breadcrumb_name
if self.breadcrumb.present?
return self.breadcrumb
else
return self.title
end
end
|
#comments_of_subarticles ⇒ Object
141
142
143
|
# File 'app/models/article.rb', line 141
def comments_of_subarticles
Comment.where("article_id in (?)", self.subtree_ids)
end
|
#complete_json ⇒ Object
405
406
407
|
# File 'app/models/article.rb', line 405
def complete_json
end
|
#date_of_last_modified_child ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
|
# File 'app/models/article.rb', line 245
def date_of_last_modified_child
if self.children.length > 0
if self.children.order("updated_at DESC").first.updated_at.utc > self.updated_at.utc
self.children.order("updated_at DESC").first.updated_at.utc
else
self.updated_at.utc
end
else
self.updated_at.utc
end
end
|
#find_related_subarticle ⇒ Object
145
146
147
148
149
150
151
|
# File 'app/models/article.rb', line 145
def find_related_subarticle
if self.dynamic_redirection == "latest"
self.descendants.order("id DESC").first
else
self.descendants.order("id ASC").first
end
end
|
#for_friendly_name ⇒ Object
310
311
312
313
314
315
316
|
# File 'app/models/article.rb', line 310
def for_friendly_name
if self.url_name.present?
self.url_name
else
self.title
end
end
|
Gets the related object by article_type
189
190
191
192
193
194
195
|
# File 'app/models/article.rb', line 189
def get_related_object
if self.article_type.present? && self.article_type_form_file.present? && self.respond_to?(self.article_type_form_file.downcase)
return self.send(self.article_type_form_file.downcase)
else
return nil
end
end
|
#image(position = "standard", size = "original") ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'app/models/article.rb', line 171
def image(position="standard", size="original")
any_images = self.article_images.where(position: position)
if any_images.any? && any_images.first.image && any_images.first.image.image
return any_images.first.image.image.url(size.to_sym)
else
return ""
end
end
|
#is_startpage? ⇒ Boolean
376
377
378
|
# File 'app/models/article.rb', line 376
def is_startpage?
self.startpage
end
|
#kind_of_article_type ⇒ Object
Gibt Index oder Show zurück, je nach Seitentyp
324
325
326
|
# File 'app/models/article.rb', line 324
def kind_of_article_type
self.article_type.present? ? self.article_type.split(" ").last : ""
end
|
401
402
403
|
# File 'app/models/article.rb', line 401
def
Menu.where(:target => self.public_url)
end
|
#mark_as_startpage! ⇒ Object
367
368
369
370
371
372
373
374
|
# File 'app/models/article.rb', line 367
def mark_as_startpage!
Article.startpage.each do |a|
a.startpage = false
a.save
end
self.startpage = true
self.save
end
|
380
381
382
383
384
|
# File 'app/models/article.rb', line 380
def metatag(name)
return "" if !MetatagNames.include?(name)
metatag = self.metatags.find_by_name(name)
metatag.value if metatag
end
|
#notification_event_create ⇒ Object
413
414
415
|
# File 'app/models/article.rb', line 413
def notification_event_create
ActiveSupport::Notifications.instrument("rdcms.article.created", :article_id => self.id)
end
|
#notification_event_update ⇒ Object
417
418
419
|
# File 'app/models/article.rb', line 417
def notification_event_update
ActiveSupport::Notifications.instrument("rdcms.article.updated", :article_id => self.id)
end
|
265
266
267
268
269
|
# File 'app/models/article.rb', line 265
def parse_image_gallery_tags
if self.respond_to?(:image_gallery_tags)
self.image_gallery_tags = self.image_gallery_tags.compact.delete_if{|a| a.blank?}.join(",") if self.image_gallery_tags.class == Array
end
end
|
#public_teaser ⇒ Object
353
354
355
356
357
|
# File 'app/models/article.rb', line 353
def public_teaser
return self.teaser if self.teaser.present?
return self.summary if self.teaser.blank? && self.summary.present?
return self.content[0..200] if self.teaser.blank? && self.summary.blank?
end
|
#public_url ⇒ Object
231
232
233
234
235
236
237
|
# File 'app/models/article.rb', line 231
def public_url
end
|
#published_at ⇒ Object
Datum für den RSS reader, Datum ist created_at es sei denn ein Articletype hat ein published_at definiert
388
389
390
391
392
393
394
395
396
397
398
399
|
# File 'app/models/article.rb', line 388
def published_at
if self.article_type.present? && self.article_type_form_file.present? && self.respond_to?(self.article_type_form_file.downcase)
related_object = self.send(self.article_type_form_file.downcase)
if related_object && related_object.respond_to?(:published_at)
related_object.published_at
else
self.created_at
end
else
self.created_at
end
end
|
#render_html(layoutfile = "application", localparams = {}) ⇒ Object
Instance Methods **************************
129
130
131
132
133
134
135
136
137
138
139
|
# File 'app/models/article.rb', line 129
def render_html(layoutfile="application", localparams={})
av = ActionView::Base.new(ActionController::Base.view_paths + ["#{::Rdcms::Engine.root}/app/views/articles/"])
av.request = ActionDispatch::Request.new(Rack::MockRequest.env_for(self.public_url))
av.request["format"] = "text/html"
av.controller = ArticlesController.new
av.controller.request = av.request
av.params.merge!(localparams[:params])
av.assign({:article => self})
html_to_render = av.render(template: "/articles/show.html.erb", :layout => "layouts/#{layoutfile}", :locals => localparams, :content_type => "text/html" )
return html_to_render
end
|
#respond_to_all?(method_name) ⇒ Boolean
180
181
182
183
184
185
186
|
# File 'app/models/article.rb', line 180
def respond_to_all?(method_name)
begin
return eval("self.#{method_name}.present?")
rescue
return false
end
end
|
#searchable_in_article_type ⇒ Object
Gibt ein Textstring zurück der bei den speziellen Artiekltypen für die Volltextsuche durchsucht werden soll
212
213
214
215
216
217
218
219
220
221
|
# File 'app/models/article.rb', line 212
def searchable_in_article_type
@searchable_in_article_type_result ||= begin
related_object = self.get_related_object
if related_object && related_object.respond_to?(:fulltext_searchable_text)
related_object.fulltext_searchable_text
else
" "
end
end
end
|
#selected_layout ⇒ Object
337
338
339
340
341
342
343
|
# File 'app/models/article.rb', line 337
def selected_layout
if self.template_file.blank?
"application"
else
self.template_file
end
end
|
#set_active_since ⇒ Object
409
410
411
|
# File 'app/models/article.rb', line 409
def set_active_since
self.active_since = self.created_at
end
|
#set_default_opengraph_values ⇒ Object
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
# File 'app/models/article.rb', line 285
def set_default_opengraph_values
if Metatag.where(article_id: self.id, name: 'OpenGraph Title').none?
Metatag.create(name: 'OpenGraph Title',
article_id: self.id,
value: self.title)
end
if Metatag.where(article_id: self.id, name: 'OpenGraph URL').none?
Metatag.create(name: 'OpenGraph URL',
article_id: self.id,
value: self.absolute_public_url)
end
if Metatag.where(article_id: self.id, name: 'OpenGraph Description').none?
if self.teaser.present?
value = self.teaser
else
value = self.content.present? ? self.content.truncate(200) : self.title
end
Metatag.create(name: 'OpenGraph Description',
article_id: self.id,
value: value)
end
end
|
#set_url_name_if_blank ⇒ Object
239
240
241
242
243
|
# File 'app/models/article.rb', line 239
def set_url_name_if_blank
if self.url_name.blank?
self.url_name = self.friendly_id.split("--")[0]
end
end
|
#verify_existence_of_opengraph_image ⇒ Object
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'app/models/article.rb', line 271
def verify_existence_of_opengraph_image
if Metatag.where("article_id = ? AND name = 'OpenGraph Image'", self.id).count == 0
Metatag.create( article_id: self.id,
name: "OpenGraph Image",
value: Setting.for_key("rdcms.facebook.opengraph_default_image"))
end
if self.article_images.any? && self.article_images.first.present? && self.article_images.first.image.present? && self.article_images.first.image.image.present?
meta_tag = Metatag.where(article_id: self.id, name: "OpenGraph Image").first
meta_tag.value = "http://#{Setting.for_key('rdcms.url')}#{self.article_images.first.image.image.url}"
meta_tag.save
end
end
|