Class: Goldencobra::Article
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Goldencobra::Article
- 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
-
#hint_label ⇒ Object
Returns the value of attribute hint_label.
-
#manual_article_sort ⇒ Object
Returns the value of attribute manual_article_sort.
Class Method Summary collapse
-
.active ⇒ Object
************************** ************************** Class Methods ************************** **************************.
- .article_types_for_search ⇒ Object
- .article_types_for_select ⇒ Object
-
.articletype_for_index(current_article) ⇒ Object
scope for index articles, display show articles, index articless or both articles of an current type.
- .init_image_methods ⇒ Object
- .load_liquid_methods(options = {}) ⇒ Object
- .recent(count) ⇒ Object
- .recreate_cache ⇒ Object
- .search_by_url(url) ⇒ Object
- .templates_for_select ⇒ Object
Instance Method Summary collapse
- #absolute_base_url ⇒ Object
- #absolute_public_url ⇒ Object
- #active? ⇒ Boolean
-
#add_link_to_checklist(link, src_type) ⇒ Object
helper method for finding links in html document.
- #article_for_index_limit ⇒ Object
-
#article_type_for_search ⇒ Object
Liefert Kategorienenamen für sie Suche unabhängig ob Die Seite eine show oder indexseite ist.
-
#article_type_form_file ⇒ Object
Gibt Consultant | Subsidiary | etc.
-
#article_type_xml_fields ⇒ Object
Returns a special article_typs customs rss fields as xml.
- #breadcrumb_name ⇒ Object
- #comments_of_subarticles ⇒ Object
- #complete_json ⇒ Object
- #date_of_last_modified_child ⇒ Object
-
#filter_with_permissions(list, current_operator) ⇒ Object
Methode filtert die @list_of_articles.
- #find_related_subarticle ⇒ Object
- #for_friendly_name ⇒ Object
-
#get_related_object ⇒ Object
Gets the related object by article_type.
- #image(position = "standard", size = "original") ⇒ Object
- #index_articles(current_operator = nil, user_frontend_tags = nil) ⇒ Object
- #is_startpage? ⇒ Boolean
-
#kind_of_article_type ⇒ Object
Gibt Index oder Show zurück, je nach Seitentyp.
- #linked_menues ⇒ Object
- #mark_as_startpage! ⇒ Object
- #metatag(name) ⇒ Object
-
#method_missing(meth, *args, &block) ⇒ Object
dynamic methods for article.event or article.consultant .…
- #notification_event_create ⇒ Object
- #notification_event_update ⇒ Object
- #parse_image_gallery_tags ⇒ Object
-
#parsed_title ⇒ Object
Das ist der Titel, der verwendet wird, wenn daraus ein Menüpunkt erstellt werden soll.
- #public_teaser ⇒ Object
- #public_url(with_prefix = true) ⇒ Object
-
#published_at ⇒ Object
Datum für den RSS reader, Datum ist created_at es sei denn ein Articletype hat ein published_at definiert.
-
#remove_html_tags(text) ⇒ Object
helper um links zu entfernen in text.
- #render_html(layoutfile = "application", localparams = {}) ⇒ Object
- #respond_to_all?(method_name) ⇒ Boolean
-
#searchable_in_article_type ⇒ Object
Gibt ein Textstring zurück der bei den speziellen Artiekltypen für die Volltextsuche durchsucht werden soll.
- #selected_layout ⇒ Object
- #set_active_since ⇒ Object
- #set_default_meta_opengraph_values ⇒ Object
-
#set_link_checker ⇒ Object
get all links of a page and make a check for response status and time.
- #set_standard_application_template ⇒ Object
- #set_url_name_if_blank ⇒ Object
-
#update_parent_article_etag ⇒ Object
Nachdem ein Artikel gelöscht wurde soll sein Elternelement aktualisiert werden, damit ein rss feed oder ähnliches mitbekommt wenn ein kindeintrag gelöscht wurde.
- #verify_existence_of_opengraph_image ⇒ Object
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
298 299 300 301 302 303 304 305 306 307 308 |
# File 'app/models/goldencobra/article.rb', line 298 def method_missing(meth, *args, &block) if meth.to_s.split(".").first == self..class.name.downcase if meth.to_s.split(".").count == 1 self. else self..send(meth.to_s.split(".").last) end else super end end |
Instance Attribute Details
#hint_label ⇒ Object
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_sort ⇒ Object
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
.active ⇒ Object
************************** ************************** Class Methods ************************** **************************
663 664 665 |
# File 'app/models/goldencobra/article.rb', line 663 def self.active Goldencobra::Article.where("active = 1 AND active_since < '#{Time.now.strftime('%Y-%m-%d %H:%M:%S ')}'") end |
.article_types_for_search ⇒ Object
717 718 719 720 721 722 723 724 725 726 |
# File 'app/models/goldencobra/article.rb', line 717 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_select ⇒ Object
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 |
# File 'app/models/goldencobra/article.rb', line 700 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
155 156 157 158 159 160 161 162 163 |
# File 'app/models/goldencobra/article.rb', line 155 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_methods ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'app/models/goldencobra/article.rb', line 251 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.[: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
681 682 683 |
# File 'app/models/goldencobra/article.rb', line 681 def self.load_liquid_methods(={}) end |
.recent(count) ⇒ Object
685 686 687 |
# File 'app/models/goldencobra/article.rb', line 685 def self.recent(count) Goldencobra::Article.where('title IS NOT NULL').order('created_at DESC').limit(count) end |
.recreate_cache ⇒ Object
689 690 691 692 693 694 695 696 697 698 |
# File 'app/models/goldencobra/article.rb', line 689 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
671 672 673 674 675 676 677 678 679 |
# File 'app/models/goldencobra/article.rb', line 671 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_select ⇒ Object
728 729 730 |
# File 'app/models/goldencobra/article.rb', line 728 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_url ⇒ Object
437 438 439 440 441 442 443 |
# File 'app/models/goldencobra/article.rb', line 437 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_url ⇒ Object
445 446 447 448 449 450 451 |
# File 'app/models/goldencobra/article.rb', line 445 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
667 668 669 |
# File 'app/models/goldencobra/article.rb', line 667 def active? self.active && self.active_since < Time.now.utc end |
#add_link_to_checklist(link, src_type) ⇒ Object
helper method for finding links in html document
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'app/models/goldencobra/article.rb', line 212 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_limit ⇒ Object
504 505 506 507 508 509 510 |
# File 'app/models/goldencobra/article.rb', line 504 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
474 475 476 477 478 479 480 |
# File 'app/models/goldencobra/article.rb', line 474 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
464 465 466 |
# File 'app/models/goldencobra/article.rb', line 464 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
401 402 403 404 405 406 |
# File 'app/models/goldencobra/article.rb', line 401 def article_type_xml_fields = self. if && .respond_to?(:custom_rss_fields) .custom_rss_fields end end |
#breadcrumb_name ⇒ Object
490 491 492 493 494 495 496 |
# File 'app/models/goldencobra/article.rb', line 490 def if self..present? return self. else return self.title end end |
#comments_of_subarticles ⇒ Object
230 231 232 |
# File 'app/models/goldencobra/article.rb', line 230 def Goldencobra::Comment.where("article_id in (?)", self.subtree_ids) end |
#complete_json ⇒ Object
550 551 552 |
# File 'app/models/goldencobra/article.rb', line 550 def complete_json end |
#date_of_last_modified_child ⇒ Object
425 426 427 428 429 430 431 432 433 434 435 |
# File 'app/models/goldencobra/article.rb', line 425 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.
373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'app/models/goldencobra/article.rb', line 373 def (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 |
#find_related_subarticle ⇒ Object
234 235 236 237 238 239 240 |
# File 'app/models/goldencobra/article.rb', line 234 def if self.dynamic_redirection == "latest" self.descendants.order("id DESC").first else self.descendants.order("id ASC").first end end |
#for_friendly_name ⇒ Object
453 454 455 456 457 458 459 460 461 |
# File 'app/models/goldencobra/article.rb', line 453 def for_friendly_name if self.url_name.present? self.url_name elsif self..present? self. else self.title end end |
#get_related_object ⇒ Object
Gets the related object by article_type
289 290 291 292 293 294 295 |
# File 'app/models/goldencobra/article.rb', line 289 def 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
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 |
# File 'app/models/goldencobra/article.rb', line 310 def index_articles(current_operator=nil, =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 .present? @list_of_articles = @list_of_articles.tagged_with(, on: :frontend_tags, any: true) end #filter with permissions @list_of_articles = (@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.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
521 522 523 |
# File 'app/models/goldencobra/article.rb', line 521 def is_startpage? self.startpage end |
#kind_of_article_type ⇒ Object
Gibt Index oder Show zurück, je nach Seitentyp
469 470 471 |
# File 'app/models/goldencobra/article.rb', line 469 def kind_of_article_type self.article_type.present? ? self.article_type.split(" ").last : "" end |
#linked_menues ⇒ Object
546 547 548 |
# File 'app/models/goldencobra/article.rb', line 546 def Goldencobra::Menue.where(:target => self.public_url) end |
#mark_as_startpage! ⇒ Object
512 513 514 515 516 517 518 519 |
# File 'app/models/goldencobra/article.rb', line 512 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
525 526 527 528 529 |
# File 'app/models/goldencobra/article.rb', line 525 def (name) return "" if !MetatagNames.include?(name) = self..find_by_name(name) .value if end |
#notification_event_create ⇒ Object
636 637 638 |
# File 'app/models/goldencobra/article.rb', line 636 def notification_event_create ActiveSupport::Notifications.instrument("goldencobra.article.created", :article_id => self.id) end |
#notification_event_update ⇒ Object
640 641 642 |
# File 'app/models/goldencobra/article.rb', line 640 def notification_event_update ActiveSupport::Notifications.instrument("goldencobra.article.updated", :article_id => self.id) end |
#parse_image_gallery_tags ⇒ Object
572 573 574 575 576 |
# File 'app/models/goldencobra/article.rb', line 572 def if self.respond_to?(:image_gallery_tags) self. = self..compact.delete_if{|a| a.blank?}.join(",") if self..class == Array end end |
#parsed_title ⇒ Object
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&üÜöÖäÄß-:,"]+$/
245 246 247 |
# File 'app/models/goldencobra/article.rb', line 245 def parsed_title self.title.to_s.gsub("/", " ") end |
#public_teaser ⇒ Object
498 499 500 501 502 |
# File 'app/models/goldencobra/article.rb', line 498 def return self. if self..present? return self.summary if self..blank? && self.summary.present? return self.content[0..200] if self..blank? && self.summary.blank? end |
#public_url(with_prefix = true) ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'app/models/goldencobra/article.rb', line 408 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_at ⇒ Object
Datum für den RSS reader, Datum ist created_at es sei denn ein Articletype hat ein published_at definiert
533 534 535 536 537 538 539 540 541 542 543 544 |
# File 'app/models/goldencobra/article.rb', line 533 def published_at if self.article_type.present? && self.article_type_form_file.present? && self.respond_to?(self.article_type_form_file.downcase) = self.send(self.article_type_form_file.downcase) if && .respond_to?(:published_at) .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
621 622 623 |
# File 'app/models/goldencobra/article.rb', line 621 def (text) text.gsub(/<[^<]+?>/, "") end |
#render_html(layoutfile = "application", localparams = {}) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/goldencobra/article.rb', line 165 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
280 281 282 283 284 285 286 |
# File 'app/models/goldencobra/article.rb', line 280 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
389 390 391 392 393 394 395 396 397 398 |
# File 'app/models/goldencobra/article.rb', line 389 def searchable_in_article_type @searchable_in_article_type_result ||= begin = self. if && .respond_to?(:fulltext_searchable_text) .fulltext_searchable_text else " " end end end |
#selected_layout ⇒ Object
482 483 484 485 486 487 488 |
# File 'app/models/goldencobra/article.rb', line 482 def selected_layout if self.template_file.blank? "application" else self.template_file end end |
#set_active_since ⇒ Object
568 569 570 |
# File 'app/models/goldencobra/article.rb', line 568 def set_active_since self.active_since = self.created_at end |
#set_default_meta_opengraph_values ⇒ Object
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 613 614 615 616 617 618 |
# File 'app/models/goldencobra/article.rb', line 578 def # 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..present? = (self.) else = self.content.present? ? (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: ) 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: ) 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_link_checker ⇒ Object
get all links of a page and make a check for response status and time
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 209 |
# File 'app/models/goldencobra/article.rb', line 179 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_template ⇒ Object
651 652 653 654 655 |
# File 'app/models/goldencobra/article.rb', line 651 def set_standard_application_template if self.template_file.blank? self.template_file = "application" end end |
#set_url_name_if_blank ⇒ Object
644 645 646 647 648 649 |
# File 'app/models/goldencobra/article.rb', line 644 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_etag ⇒ Object
Nachdem ein Artikel gelöscht wurde soll sein Elternelement aktualisiert werden, damit ein rss feed oder ähnliches mitbekommt wenn ein kindeintrag gelöscht wurde
562 563 564 565 566 |
# File 'app/models/goldencobra/article.rb', line 562 def update_parent_article_etag if self.parent.present? self.parent.update_attributes(:updated_at => Time.now) end end |
#verify_existence_of_opengraph_image ⇒ Object
625 626 627 628 629 630 631 632 633 634 |
# File 'app/models/goldencobra/article.rb', line 625 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 |