Class: Goldencobra::Article

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/goldencobra/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", "GlobalSortID"]
DynamicRedirectOptions =
[[:false,"deaktiviert"],[:latest,"neuester Untereintrag"], [:oldest, "ältester Untereintrag"]]
DisplayIndexTypes =
[["Einzelseiten", "show"],["Übersichtsseiten", "index"], ["Alle Seiten", "all"]]
ImportDataFunctions =
[]

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



220
221
222
223
224
225
226
227
228
229
230
# File 'app/models/goldencobra/article.rb', line 220

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

#create_redirectionObject

Returns the value of attribute create_redirection.



63
64
65
# File 'app/models/goldencobra/article.rb', line 63

def create_redirection
  @create_redirection
end

#hint_labelObject

Returns the value of attribute hint_label.



63
64
65
# File 'app/models/goldencobra/article.rb', line 63

def hint_label
  @hint_label
end

#manual_article_sortObject

Returns the value of attribute manual_article_sort.



63
64
65
# File 'app/models/goldencobra/article.rb', line 63

def manual_article_sort
  @manual_article_sort
end

Class Method Details

.activeObject

************************** ************************** Class Methods ************************** **************************



743
744
745
# File 'app/models/goldencobra/article.rb', line 743

def self.active
  Goldencobra::Article.where("active = 1 AND active_since < '#{Time.now.strftime('%Y-%m-%d %H:%M:%S ')}'")
end

.article_types_for_searchObject



789
790
791
792
793
794
795
796
797
798
# File 'app/models/goldencobra/article.rb', line 789

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| #.map{|a| File.basename(a, ".html.erb")}.delete_if{|a| a =~ /^_edit/ }
      results << name.capitalize unless name.include?(".")
    end
  end
  return results
end

.article_types_for_selectObject



772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
# File 'app/models/goldencobra/article.rb', line 772

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| #.map{|a| File.basename(a, ".html.erb")}.delete_if{|a| a =~ /^_edit/ }.delete_if{|a| a[0] == "_"}
      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.titleize.gsub(' ','')}#{sub_name.titleize}" if File.exist?(File.join(file_name_path,sub_name)) && (sub_name =~ /^_(?!edit).*/) == 0
            results << file_name.split(".").first if file_name.present?
        end
      end
    end
  end
  return results
end

.articletype_for_index(current_article) ⇒ Object

scope for index articles, display show articles, index articless or both articles of an current type



393
394
395
396
397
398
399
400
401
# File 'app/models/goldencobra/article.rb', line 393

def self.articletype_for_index(current_article)
  if current_article.display_index_types == "show"
    articletype("#{current_article.article_type_form_file} Show")
  elsif current_article.display_index_types == "index"
    articletype("#{current_article.article_type_form_file} Index")
  else
    where("article_type = '#{current_article.article_type_form_file} Show' OR article_type = '#{current_article.article_type_form_file} Index'")
  end
end

.init_image_methodsObject



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'app/models/goldencobra/article.rb', line 173

def self.init_image_methods
  if ActiveRecord::Base.connection.table_exists?("goldencobra_settings")
    Goldencobra::Setting.for_key("goldencobra.article.image_positions").to_s.split(",").map(&:strip).each do |image_type|
      define_method "image_#{image_type.underscore}" do
        self.image(image_type,"original")
      end
      define_method "image_alt_#{image_type.underscore}" do
        self.article_images.where(position: image_type).first.image.alt_text || self.article_images.where(position: image_type).first.image.image_file_name
      end
      Goldencobra::Upload.attachment_definitions[:image][: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



753
754
755
# File 'app/models/goldencobra/article.rb', line 753

def self.load_liquid_methods(options={})

end

.recent(count) ⇒ Object



757
758
759
# File 'app/models/goldencobra/article.rb', line 757

def self.recent(count)
  Goldencobra::Article.where('title IS NOT NULL').order('created_at DESC').limit(count)
end

.recreate_cacheObject



761
762
763
764
765
766
767
768
769
770
# File 'app/models/goldencobra/article.rb', line 761

def self.recreate_cache
  if RUBY_VERSION.include?("1.9.")
    ArticlesCacheWorker.perform_async()
  else
    Goldencobra::Article.active.each do |article|
      article.updated_at = Time.now
      article.without_versioning :save
    end
  end
end

.search_by_url(url) ⇒ Object



667
668
669
670
671
672
673
674
675
# File 'app/models/goldencobra/article.rb', line 667

def self.search_by_url(url)
  article = nil
  articles = Goldencobra::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(false) == article_path}.first
  end
  return article
end

.simple_search(q) ⇒ Object



804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
# File 'app/models/goldencobra/article.rb', line 804

def self.simple_search(q)
  self.active.search(:title_or_subtitle_or_url_name_or_content_or_summary_or_teaser_contains => q).relation.map {
      |article|
    {
        :id => article.id,
        :absolute_public_url => article.absolute_public_url,
        :title => article ? article.title : '',
        :teaser => article ? article.teaser : '',
        :article_type => article.article_type,
        :updated_at => article.updated_at,
        :parent_title => article.parent ? article.parent.title ? article.parent.title : '' : '',
        :ancestry => article.ancestry ? article.ancestry : ''
    }
  }
end

.templates_for_selectObject



800
801
802
# File 'app/models/goldencobra/article.rb', line 800

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_base_urlObject



708
709
710
711
712
713
714
# File 'app/models/goldencobra/article.rb', line 708

def absolute_base_url
  if Goldencobra::Setting.for_key("goldencobra.use_ssl") == "true"
    "https://#{Goldencobra::Setting.for_key('goldencobra.url')}"
  else
    "http://#{Goldencobra::Setting.for_key('goldencobra.url')}"
  end
end

#absolute_public_urlObject



717
718
719
720
721
722
723
# File 'app/models/goldencobra/article.rb', line 717

def absolute_public_url
  if Goldencobra::Setting.for_key("goldencobra.use_ssl") == "true"
    "https://#{Goldencobra::Setting.for_key('goldencobra.url')}#{self.public_url}"
  else
    "http://#{Goldencobra::Setting.for_key('goldencobra.url')}#{self.public_url}"
  end
end

#active?Boolean

Returns:

  • (Boolean)


747
748
749
# File 'app/models/goldencobra/article.rb', line 747

def active?
  self.active && self.active_since < Time.now.utc
end

#article_for_index_limitObject



331
332
333
334
335
336
337
# File 'app/models/goldencobra/article.rb', line 331

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_searchObject

Liefert Kategorienenamen für sie Suche unabhängig ob Die Seite eine show oder indexseite ist



297
298
299
300
301
302
303
# File 'app/models/goldencobra/article.rb', line 297

def article_type_for_search
  if self.article_type.present?
    self.article_type.split(" ")[0..-2].join("")
  else
    "Article"
  end
end

#article_type_form_fileObject

Gibt Consultant | Subsidiary | etc. zurück je nach Seitentyp



285
286
287
288
289
# File 'app/models/goldencobra/article.rb', line 285

def article_type_form_file
  if self.article_type.present?
    self.article_type.split(" ")[0..-2].join("")
  end
end

#article_type_xml_fieldsObject

Returns a special article_typs customs rss fields as xml



263
264
265
266
267
268
# File 'app/models/goldencobra/article.rb', line 263

def article_type_xml_fields
  related_object = self.get_related_object
  if related_object && related_object.respond_to?(:custom_rss_fields)
    related_object.custom_rss_fields
  end
end

#authorObject



381
382
383
# File 'app/models/goldencobra/article.rb', line 381

def author
  self.try(:authors).try(:first)
end


317
318
319
320
321
322
323
# File 'app/models/goldencobra/article.rb', line 317

def breadcrumb_name
  if self.breadcrumb.present?
    return self.breadcrumb
  else
    return self.title
  end
end

#cleanup_redirectionsObject

************************** ************************** Callback Methods ************************** **************************



498
499
500
# File 'app/models/goldencobra/article.rb', line 498

def cleanup_redirections
  Goldencobra::Redirector.where(:source_url => self.absolute_public_url).destroy_all
end

#comments_of_subarticlesObject



417
418
419
# File 'app/models/goldencobra/article.rb', line 417

def comments_of_subarticles
  Goldencobra::Comment.where("article_id in (?)", self.subtree_ids)
end

#complete_jsonObject



377
378
379
# File 'app/models/goldencobra/article.rb', line 377

def complete_json

end

#date_of_last_modified_childObject



271
272
273
274
275
276
277
278
279
280
281
# File 'app/models/goldencobra/article.rb', line 271

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

#filter_with_permissions(list, current_operator) ⇒ Object

Methode filtert die @list_of_articles. Rückgabewert: Ein Array all der Artikel, die der operator lesen darf.



235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'app/models/goldencobra/article.rb', line 235

def filter_with_permissions(list, current_operator)
  if current_operator && current_operator.respond_to?(:has_role?) && current_operator.has_role?(Goldencobra::Setting.for_key("goldencobra.article.preview.roles").split(",").map{|a| a.strip})
    return list
  else
    a = Ability.new(current_operator)
    new_list = []
    list.each do |article|
      if a.can?(:read, article)
        new_list << article.id
      end
    end
  end
  return list.where('goldencobra_articles.id in (?)', new_list)
end


421
422
423
424
425
426
427
# File 'app/models/goldencobra/article.rb', line 421

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_nameObject



726
727
728
729
730
731
732
733
734
# File 'app/models/goldencobra/article.rb', line 726

def for_friendly_name
  if self.url_name.present?
    self.url_name
  elsif self.breadcrumb.present?
    self.breadcrumb
  else
    self.title
  end
end

Gets the related object by article_type



211
212
213
214
215
216
217
# File 'app/models/goldencobra/article.rb', line 211

def get_related_object
  if self.article_type.present? && self.article_type_form_file.present? && self.respond_to?(self.article_type_form_file.underscore.parameterize.downcase)
    return self.send(self.article_type_form_file.underscore.parameterize.downcase)
  else
    return nil
  end
end

#get_url_from_pathObject



551
552
553
# File 'app/models/goldencobra/article.rb', line 551

def get_url_from_path
  "/#{self.path.select([:ancestry, :url_name, :startpage, :id]).map{|a| a.url_name if !a.startpage}.compact.join("/")}"
end

#image(position = "standard", size = "original") ⇒ Object



192
193
194
195
196
197
198
199
# File 'app/models/goldencobra/article.rb', line 192

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

#index_articles(current_operator = nil, user_frontend_tags = nil) ⇒ Object



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'app/models/goldencobra/article.rb', line 430

def index_articles(current_operator=nil, user_frontend_tags=nil)
  if self.article_for_index_id.blank?
    #Index aller Artikel anzeigen
    @list_of_articles = Goldencobra::Article.active.articletype_for_index(self)
  else
    #Index aller Artikel anzeigen, die Kinder sind von einem Bestimmten artikel
    parent_article = Goldencobra::Article.find_by_id(self.article_for_index_id)
    if parent_article
      @list_of_articles = parent_article.descendants.active.articletype_for_index(self)
    else
      @list_of_articles = Goldencobra::Article.active.articletype_for_index(self)
    end
  end
  #include related models
  @list_of_articles = @list_of_articles.includes("#{self.article_type_form_file.underscore.parameterize.downcase}") if self.respond_to?(self.article_type_form_file.underscore.parameterize.downcase)
  #get articles with tag
  if self.index_of_articles_tagged_with.present?
    @list_of_articles = @list_of_articles.tagged_with(self.index_of_articles_tagged_with.split(",").map{|t| t.strip}, on: :tags, any: true)
  end
  #get articles without tag
  if self.not_tagged_with.present?
    @list_of_articles = @list_of_articles.tagged_with(self.not_tagged_with.split(",").map{|t| t.strip}, :exclude => true, on: :tags)
  end
  #get_articles_by_frontend_tags
  if user_frontend_tags.present?
    @list_of_articles = @list_of_articles.tagged_with(user_frontend_tags, on: :frontend_tags, any: true)
  end
  #filter with permissions
  @list_of_articles = filter_with_permissions(@list_of_articles,current_operator)

  #sort list of articles
  if self.sort_order.present?
    if self.sort_order == "Random"
      @list_of_articles = @list_of_articles.flatten.shuffle
    elsif self.sort_order == "Alphabetically"
      @list_of_articles = @list_of_articles.flatten.sort_by{ |article| article.title }
    elsif self.sort_order == "GlobalSortID"
      @list_of_articles = @list_of_articles.flatten.sort_by{ |article| article.try(:global_sorting_id) }
    elsif self.respond_to?(self.sort_order.downcase)
      sort_order = self.sort_order.downcase
      @list_of_articles = @list_of_articles.flatten.sort_by{ |article| article.respond_to?(sort_order) ? article.send(sort_order) : article }
    elsif self.sort_order.include?(".")
      sort_order = self.sort_order.downcase.split(".")
      @unsortable = @list_of_articles.flatten.select{|a| !a.respond_to_all?(self.sort_order) }
      @list_of_articles = @list_of_articles.flatten.delete_if{|a| !a.respond_to_all?(self.sort_order) }
      @list_of_articles = @list_of_articles.sort_by{|a| eval("a.#{self.sort_order}") }
      if @unsortable.count > 0
        @list_of_articles = @unsortable + @list_of_articles
        @list_of_articles = @list_of_articles.flatten
      end
    end
    if self.reverse_sort
      @list_of_articles = @list_of_articles.reverse
    end
  end
  if self.sorter_limit && self.sorter_limit > 0
    @list_of_articles = @list_of_articles[0..self.sorter_limit-1]
  end

  return @list_of_articles
end

#is_startpage?Boolean

Returns:

  • (Boolean)


348
349
350
# File 'app/models/goldencobra/article.rb', line 348

def is_startpage?
  self.startpage
end

#kind_of_article_typeObject

Gibt Index oder Show zurück, je nach Seitentyp



292
293
294
# File 'app/models/goldencobra/article.rb', line 292

def kind_of_article_type
  self.article_type.present? ? self.article_type.split(" ").last : ""
end

#linked_menuesObject



373
374
375
# File 'app/models/goldencobra/article.rb', line 373

def linked_menues
  Goldencobra::Menue.where(:target => self.public_url)
end

#mark_as_startpage!Object



339
340
341
342
343
344
345
346
# File 'app/models/goldencobra/article.rb', line 339

def mark_as_startpage!
  Goldencobra::Article.startpage.each do |a|
    a.startpage = false
    a.save
  end
  self.startpage = true
  self.save
end

#metatag(name) ⇒ Object



352
353
354
355
356
# File 'app/models/goldencobra/article.rb', line 352

def metatag(name)
  return "" if !MetatagNames.include?(name)
  metatag = self.metatags.find_by_name(name)
  metatag.value if metatag
end

#notification_event_createObject



630
631
632
# File 'app/models/goldencobra/article.rb', line 630

def notification_event_create
  ActiveSupport::Notifications.instrument("goldencobra.article.created", :article_id => self.id)
end

#notification_event_updateObject



634
635
636
# File 'app/models/goldencobra/article.rb', line 634

def notification_event_update
  ActiveSupport::Notifications.instrument("goldencobra.article.updated", :article_id => self.id)
end

#parent_pathObject



678
679
680
# File 'app/models/goldencobra/article.rb', line 678

def parent_path
  self.path.map(&:title).join(" / ")
end


566
567
568
569
570
# File 'app/models/goldencobra/article.rb', line 566

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

#parsed_titleObject

Das ist der Titel, der verwendet wird, wenn daraus ein Menüpunkt erstellt werden soll. der menue.title hat folgende vorgaben: validates_format_of :title, :with => /^[wd?.'!s&üÜöÖäÄß-:,"]+$/



167
168
169
# File 'app/models/goldencobra/article.rb', line 167

def parsed_title
  self.title.to_s.gsub("/", " ")
end

#public_teaserObject



325
326
327
328
329
# File 'app/models/goldencobra/article.rb', line 325

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(with_prefix = true) ⇒ Object



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
# File 'app/models/goldencobra/article.rb', line 683

def public_url(with_prefix=true)
  if self.startpage
    if with_prefix
      return "#{Goldencobra::Domain.current.try(:url_prefix)}/"
    else
      return "/"
    end
  else

    #url_path in der Datenbank als string speichern und beim update von ancestry neu berechnen... ansosnten den urlpafh aus dem string holen statt jedesmal über alle eltern iterierne
    if self.url_path.blank? || self.url_path_changed? || self.url_name_changed? || self.ancestry_changed?
      a_url = self.get_url_from_path
    else
      a_url = self.url_path
    end

    if with_prefix
      return "#{Goldencobra::Domain.current.try(:url_prefix)}#{a_url}"
    else
      return a_url
    end
  end
end

#published_atObject

Datum für den RSS reader, Datum ist created_at es sei denn ein Articletype hat ein published_at definiert



360
361
362
363
364
365
366
367
368
369
370
371
# File 'app/models/goldencobra/article.rb', line 360

def published_at
  if self.article_type.present? && self.article_type_form_file.present? && self.respond_to?(self.article_type_form_file.underscore.parameterize.downcase)
    related_object = self.send(self.article_type_form_file.underscore.parameterize.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

#remove_html_tags(text) ⇒ Object

helper um links zu entfernen in text



615
616
617
# File 'app/models/goldencobra/article.rb', line 615

def remove_html_tags(text)
  text.gsub(/<[^<]+?>/, "")
end

#render_html(layoutfile = "application", localparams = {}) ⇒ Object



403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'app/models/goldencobra/article.rb', line 403

def render_html(layoutfile="application", localparams={})
  av = ActionView::Base.new(ActionController::Base.view_paths + ["#{::Goldencobra::Engine.root}/app/views/goldencobra/articles/"])
  av.request = ActionDispatch::Request.new(Rack::MockRequest.env_for(self.public_url))
  av.request["format"] = "text/html"
  av.controller = Goldencobra::ArticlesController.new
  av.controller.request = av.request
  if localparams.present? && localparams[:params].present?
    av.params.merge!(localparams[:params])
  end
  av.assign({:article => self})
  html_to_render = av.render(template: "/goldencobra/articles/show.html.erb", :layout => "layouts/#{layoutfile}", :locals => localparams, :content_type => "text/html" )
  return html_to_render
end

#respond_to_all?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


202
203
204
205
206
207
208
# File 'app/models/goldencobra/article.rb', line 202

def respond_to_all?(method_name)
  begin
    return eval("self.#{method_name}.present?")
  rescue
    return false
  end
end

#searchable_in_article_typeObject

Gibt ein Textstring zurück der bei den speziellen Artiekltypen für die Volltextsuche durchsucht werden soll



251
252
253
254
255
256
257
258
259
260
# File 'app/models/goldencobra/article.rb', line 251

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_layoutObject



305
306
307
308
309
310
311
312
313
314
315
# File 'app/models/goldencobra/article.rb', line 305

def selected_layout
  if self.template_file.blank?
    if self.articletype.present? && self.articletype.default_template_file.present?
      self.articletype.default_template_file
    else
      "application"
    end
  else
    self.template_file
  end
end

#set_active_sinceObject



562
563
564
# File 'app/models/goldencobra/article.rb', line 562

def set_active_since
  self.active_since = self.created_at
end

#set_default_meta_opengraph_valuesObject



572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'app/models/goldencobra/article.rb', line 572

def set_default_meta_opengraph_values
  # Diese Zeile schein Überflüssig geworden zu sein, da nun der teaser, description oder title als defaultwerte genommen werden
  #meta_description = Goldencobra::Setting.for_key('goldencobra.page.default_meta_description_tag')

  if self.teaser.present?
    meta_description = remove_html_tags(self.teaser.truncate(200))
  else
    meta_description = self.content.present? ? remove_html_tags(self.content).truncate(200) : self.title
  end

  if Goldencobra::Metatag.where(article_id: self.id, name: 'Meta Description').none?
    Goldencobra::Metatag.create(name: 'Meta Description',
                                article_id: self.id,
                                value: meta_description)
  end

  if Goldencobra::Metatag.where(article_id: self.id, name: 'Title Tag').none?
    Goldencobra::Metatag.create(name: 'Title Tag',
                                article_id: self.id,
                                #value: self.breadcrumb.present? ? self.breadcrumb : self.title)
                                value: self.title)
  end

  if Goldencobra::Metatag.where(article_id: self.id, name: 'OpenGraph Description').none?
    Goldencobra::Metatag.create(name: 'OpenGraph Description',
                                article_id: self.id,
                                value: meta_description)
  end

  if Goldencobra::Metatag.where(article_id: self.id, name: 'OpenGraph Title').none?
    Goldencobra::Metatag.create(name: 'OpenGraph Title',
                                article_id: self.id,
                                value: self.title)
  end

  if Goldencobra::Metatag.where(article_id: self.id, name: 'OpenGraph URL').none?
    Goldencobra::Metatag.create(name: 'OpenGraph URL',
                                article_id: self.id,
                                value: self.absolute_public_url)
  end
end

#set_redirection_step_1Object

bevor ein Artikle gespeichert wird , wird ein redirector unvollständig erstellt



503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'app/models/goldencobra/article.rb', line 503

def set_redirection_step_1
  #Wenn der Artikle vor mehr als 24 Stunden erstellt wurde und sich an der URL etwas verändert hat, dann eine Weiterleitung anlegen.
  modified_hours_since = ((Time.now - self.created_at) / 1.hour).round
  if !self.new_record? && (self.url_path_changed? || self.url_name_changed? || self.ancestry_changed?) && modified_hours_since > 24
    #Erstelle Redirector nur mit source
    if self.url_path_changed?
      old_url = "#{self.absolute_base_url}#{Goldencobra::Domain.current.try(:url_prefix)}#{self.url_path_change[0]}"
    else
      old_url = "#{self.absolute_base_url}#{Goldencobra::Domain.current.try(:url_prefix)}#{self.url_path}"
    end
    r = Goldencobra::Redirector.find_or_create_by_source_url(old_url)
    r.active = false
    r.save
    self.create_redirection = r.id
  end
end

#set_redirection_step_2Object



520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'app/models/goldencobra/article.rb', line 520

def set_redirection_step_2
  if self.create_redirection.present? && self.create_redirection.to_i > 0
    #Suche Redirector nur mit source und vervollständige ihn
    Goldencobra::Redirector.where(:source_url => self.absolute_public_url).destroy_all
    r = Goldencobra::Redirector.find_by_id(self.create_redirection)
    if r.present?
      r.target_url = self.absolute_public_url
      r.active = true
      r.save
      custom_children = Goldencobra::Article.find_all_by_ancestry("#{self.ancestry}/#{self.id}")
      if custom_children.any?
        if custom_children.count < 30
          # wenn es nur wenige Kinderartikel gibt, dann gleich direkt machen
          custom_children.each do |d|
            d.updated_at = Time.now
            d.url_path = d.get_url_from_path
            d.save
          end
        else
          #Ansosnten einen Raketask damit starten
          system("cd #{::Rails.root} && RAILS_ENV=#{::Rails.env} bundle exec rake article_cache:recreate ID=#{self.id} &")
        end
      end
    end
  end
end

#set_standard_application_templateObject



645
646
647
648
649
650
651
652
653
654
655
# File 'app/models/goldencobra/article.rb', line 645

def set_standard_application_template
  if ActiveRecord::Base.connection.table_exists?("goldencobra_articles") && ActiveRecord::Base.connection.table_exists?("goldencobra_articletypes")
    if self.template_file.blank?
      if self.articletype.present? && self.articletype.default_template_file.present?
        self.template_file = self.articletype.default_template_file
      else
        self.template_file = "application"
      end
    end
  end
end

#set_url_name_if_blankObject



638
639
640
641
642
643
# File 'app/models/goldencobra/article.rb', line 638

def set_url_name_if_blank
  if self.url_name.blank?
    #self.url_name = self.breadcrumb
    self.url_name = self.friendly_id.split("--")[0]
  end
end

#set_url_pathObject



547
548
549
# File 'app/models/goldencobra/article.rb', line 547

def set_url_path
  self.update_column(:url_path, self.get_url_from_path)
end

#update_parent_article_etagObject

Nachdem ein Artikel gelöscht oder aktualsisiert wurde soll sein Elternelement aktualisiert werden, damit ein rss feed oder ähnliches mitbekommt wenn ein kindeintrag gelöscht oder bearbeitet wurde



556
557
558
559
560
# File 'app/models/goldencobra/article.rb', line 556

def update_parent_article_etag
  if self.parent.present?
    self.parent.update_attributes(:updated_at => Time.now)
  end
end

#verify_existence_of_opengraph_imageObject



619
620
621
622
623
624
625
626
627
628
# File 'app/models/goldencobra/article.rb', line 619

def verify_existence_of_opengraph_image
  if Goldencobra::Metatag.where(article_id: self.id, name: "OpenGraph Image").none?
    if self.article_images.any? && self.article_images.first.present? && self.article_images.first.image.present? && self.article_images.first.image.image.present?
      og_img_val = "#{self.absolute_base_url}#{self.article_images.first.image.image.url}"
    else
      og_img_val = Goldencobra::Setting.for_key("goldencobra.facebook.opengraph_default_image")
    end
    Goldencobra::Metatag.create(name: "OpenGraph Image", article_id: self.id, value: og_img_val)
  end
end