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"]
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



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

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_labelObject

Returns the value of attribute hint_label.



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

def hint_label
  @hint_label
end

#manual_article_sortObject

Returns the value of attribute manual_article_sort.



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

def manual_article_sort
  @manual_article_sort
end

Class Method Details

.activeObject

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



664
665
666
# File 'app/models/goldencobra/article.rb', line 664

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



718
719
720
721
722
723
724
725
726
727
# File 'app/models/goldencobra/article.rb', line 718

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



701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# File 'app/models/goldencobra/article.rb', line 701

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}#{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

.articletype_for_index(current_article) ⇒ Object

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



154
155
156
157
158
159
160
161
162
# File 'app/models/goldencobra/article.rb', line 154

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



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'app/models/goldencobra/article.rb', line 250

def self.init_image_methods
  if ActiveRecord::Base.connection.table_exists?("goldencobra_settings")
    Goldencobra::Setting.for_key("goldencobra.article.image_positions").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



682
683
684
# File 'app/models/goldencobra/article.rb', line 682

def self.load_liquid_methods(options={})

end

.recent(count) ⇒ Object



686
687
688
# File 'app/models/goldencobra/article.rb', line 686

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

.recreate_cacheObject



690
691
692
693
694
695
696
697
698
699
# File 'app/models/goldencobra/article.rb', line 690

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.save
    end
  end
end

.search_by_url(url) ⇒ Object



672
673
674
675
676
677
678
679
680
# File 'app/models/goldencobra/article.rb', line 672

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

.templates_for_selectObject



729
730
731
# File 'app/models/goldencobra/article.rb', line 729

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



438
439
440
441
442
443
444
# File 'app/models/goldencobra/article.rb', line 438

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



446
447
448
449
450
451
452
# File 'app/models/goldencobra/article.rb', line 446

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)


668
669
670
# File 'app/models/goldencobra/article.rb', line 668

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

helper method for finding links in html document



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'app/models/goldencobra/article.rb', line 211

def add_link_to_checklist(link, src_type)
  begin
    if link.blank? || link[src_type].blank?
      return nil
    elsif link[src_type][0 .. 6] == "http://" || link[src_type][0 .. 6] == "https:/"
      return "#{link[src_type]}"
    elsif link[src_type] && link[src_type][0 .. 1] == "//"
      return "http:/#{link[src_type][/.(.*)/m,1]}"
    elsif link[src_type] && link[src_type][0] == "/"
      return "#{Goldencobra::Setting.absolute_base_url}/#{link[src_type][/.(.*)/m,1]}"
    elsif link[src_type] && !link[src_type].include?("mailto:")
      return "#{self.absolute_public_url}/#{link[src_type]}"
    end
  rescue
    return nil
  end
end

#article_for_index_limitObject



505
506
507
508
509
510
511
# File 'app/models/goldencobra/article.rb', line 505

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



475
476
477
478
479
480
481
# File 'app/models/goldencobra/article.rb', line 475

def article_type_for_search
  if self.article_type.present?
    self.article_type.split(" ").first
  else
    "Article"
  end
end

#article_type_form_fileObject

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



465
466
467
# File 'app/models/goldencobra/article.rb', line 465

def article_type_form_file
  self.article_type.split(" ").first if self.article_type.present?
end

#article_type_xml_fieldsObject

Returns a special article_typs customs rss fields as xml



402
403
404
405
406
407
# File 'app/models/goldencobra/article.rb', line 402

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


491
492
493
494
495
496
497
# File 'app/models/goldencobra/article.rb', line 491

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

#comments_of_subarticlesObject



229
230
231
# File 'app/models/goldencobra/article.rb', line 229

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

#complete_jsonObject



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

def complete_json

end

#date_of_last_modified_childObject



426
427
428
429
430
431
432
433
434
435
436
# File 'app/models/goldencobra/article.rb', line 426

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.



374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'app/models/goldencobra/article.rb', line 374

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


233
234
235
236
237
238
239
# File 'app/models/goldencobra/article.rb', line 233

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



454
455
456
457
458
459
460
461
462
# File 'app/models/goldencobra/article.rb', line 454

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



288
289
290
291
292
293
294
# File 'app/models/goldencobra/article.rb', line 288

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



270
271
272
273
274
275
276
277
# File 'app/models/goldencobra/article.rb', line 270

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



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'app/models/goldencobra/article.rb', line 309

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.downcase}") if self.respond_to?(self.article_type_form_file.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 == "Alphabetical"
      @list_of_articles = @list_of_articles.flatten.sort_by{|article| article.title }
    elsif self.sort_order == "Created_at"
      @list_of_articles = @list_of_articles.flatten.sort_by{|article| article.created_at.to_i }
    elsif self.respond_to?(self.sort_order)
      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)


522
523
524
# File 'app/models/goldencobra/article.rb', line 522

def is_startpage?
  self.startpage
end

#kind_of_article_typeObject

Gibt Index oder Show zurück, je nach Seitentyp



470
471
472
# File 'app/models/goldencobra/article.rb', line 470

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

#linked_menuesObject



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

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

#mark_as_startpage!Object



513
514
515
516
517
518
519
520
# File 'app/models/goldencobra/article.rb', line 513

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



526
527
528
529
530
# File 'app/models/goldencobra/article.rb', line 526

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

#notification_event_createObject



637
638
639
# File 'app/models/goldencobra/article.rb', line 637

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

#notification_event_updateObject



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

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


573
574
575
576
577
# File 'app/models/goldencobra/article.rb', line 573

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&üÜöÖäÄß-:,"]+$/



244
245
246
# File 'app/models/goldencobra/article.rb', line 244

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

#public_teaserObject



499
500
501
502
503
# File 'app/models/goldencobra/article.rb', line 499

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



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'app/models/goldencobra/article.rb', line 409

def public_url(with_prefix=true)
  if self.startpage
    if with_prefix
      return "#{Goldencobra::Domain.current.try(:url_prefix)}/"
    else
      return "/"
    end
  else
    a_url = "/#{self.path.select([:ancestry, :url_name, :startpage]).map{|a| a.url_name if !a.startpage}.compact.join("/")}"
    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



534
535
536
537
538
539
540
541
542
543
544
545
# File 'app/models/goldencobra/article.rb', line 534

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

#remove_html_tags(text) ⇒ Object

helper um links zu entfernen in text



622
623
624
# File 'app/models/goldencobra/article.rb', line 622

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

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



164
165
166
167
168
169
170
171
172
173
174
# File 'app/models/goldencobra/article.rb', line 164

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
  av.params.merge!(localparams[:params])
  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)


279
280
281
282
283
284
285
# File 'app/models/goldencobra/article.rb', line 279

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



390
391
392
393
394
395
396
397
398
399
# File 'app/models/goldencobra/article.rb', line 390

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



483
484
485
486
487
488
489
# File 'app/models/goldencobra/article.rb', line 483

def selected_layout
  if self.template_file.blank?
    "application"
  else
    self.template_file
  end
end

#set_active_sinceObject



569
570
571
# File 'app/models/goldencobra/article.rb', line 569

def set_active_since
  self.active_since = self.created_at
end

#set_default_meta_opengraph_valuesObject



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
613
614
615
616
617
618
619
# File 'app/models/goldencobra/article.rb', line 579

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)
  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

get all links of a page and make a check for response status and time



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'app/models/goldencobra/article.rb', line 178

def set_link_checker
  links_to_check = []
  status_for_links = {}
  doc = Nokogiri::HTML(open(self.absolute_public_url))
  #find all links and stylesheets
  doc.css('a,link').each do |link|
    if add_link_to_checklist(link, "href").present?
      links_to_check << {"link" => add_link_to_checklist(link, "href"), "pos" => link.path}
    end
  end
  #find all images and javascripts
  doc.css('img,script').each do |link|
    if add_link_to_checklist(link,"src").present?
      links_to_check << {"link" => add_link_to_checklist(link,"src"), "pos" => link.path}
    end
  end
  links_to_check = links_to_check.compact.delete_if{|a| a.blank?}
  links_to_check.each_with_index do |linkpos|
    status_for_links[linkpos["link"]] = {"position" => linkpos["pos"]}
    begin
      start = Time.now
      response = open(linkpos["link"])
      status_for_links[linkpos["link"]]["response_code"] = response.status[0]
      status_for_links[linkpos["link"]]["response_time"] = Time.now - start
    rescue Exception  => e
      status_for_links[linkpos["link"]]["response_code"] = "404"
      status_for_links[linkpos["link"]]["response_error"] = e.to_s
    end
  end
  self.link_checker = status_for_links
end

#set_standard_application_templateObject



652
653
654
655
656
# File 'app/models/goldencobra/article.rb', line 652

def set_standard_application_template
  if self.template_file.blank?
    self.template_file = "application"
  end
end

#set_url_name_if_blankObject



645
646
647
648
649
650
# File 'app/models/goldencobra/article.rb', line 645

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

#update_parent_article_etagObject

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



563
564
565
566
567
# File 'app/models/goldencobra/article.rb', line 563

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

#verify_existence_of_opengraph_imageObject



626
627
628
629
630
631
632
633
634
635
# File 'app/models/goldencobra/article.rb', line 626

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