goldencobra 1.4.0 → 1.4.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +3 -2
- data/app/assets/images/goldencobra/Jcrop.gif +0 -0
- data/app/assets/javascripts/goldencobra/active_admin.js +145 -84
- data/app/assets/javascripts/goldencobra/jquery.Jcrop.min.js +22 -0
- data/app/assets/javascripts/goldencobra/jquery.color.js +661 -0
- data/app/assets/stylesheets/goldencobra/active_admin.css.scss +375 -252
- data/app/assets/stylesheets/goldencobra/{application.css → application.css.scss} +0 -0
- data/app/assets/stylesheets/goldencobra/ikusei_active_admin.scss +35 -26
- data/app/assets/stylesheets/goldencobra/jquery.Jcrop.min.css +29 -0
- data/app/controllers/goldencobra/api/v2/articles_controller.rb +221 -0
- data/app/controllers/goldencobra/api/v2/locales_controller.rb +31 -0
- data/app/controllers/goldencobra/api/v2/settings_controller.rb +31 -0
- data/app/controllers/goldencobra/articles_controller.rb +42 -16
- data/app/controllers/goldencobra/sessions_controller.rb +8 -1
- data/app/helpers/goldencobra/application_helper.rb +3 -1
- data/app/helpers/goldencobra/articles_helper.rb +14 -8
- data/app/middleware/goldencobra/handle_invalid_percent_encoding.rb +40 -0
- data/app/models/ability.rb +43 -48
- data/app/models/goldencobra/article.rb +292 -218
- data/app/models/goldencobra/article_author.rb +19 -0
- data/app/models/goldencobra/article_image.rb +2 -0
- data/app/models/goldencobra/articletype.rb +30 -28
- data/app/models/goldencobra/author.rb +5 -3
- data/app/models/goldencobra/domain.rb +2 -0
- data/app/models/goldencobra/import.rb +2 -2
- data/app/models/goldencobra/link_checker.rb +64 -0
- data/app/models/goldencobra/menue.rb +4 -2
- data/app/models/goldencobra/permission.rb +3 -1
- data/app/models/goldencobra/redirector.rb +131 -0
- data/app/models/goldencobra/setting.rb +29 -3
- data/app/models/goldencobra/upload.rb +60 -1
- data/app/models/goldencobra/url_builder.rb +58 -0
- data/app/models/goldencobra/vita.rb +4 -0
- data/app/models/goldencobra/widget.rb +10 -0
- data/app/models/user.rb +1 -1
- data/app/views/goldencobra/admin/articles/_article_type.html.erb +1 -1
- data/app/views/goldencobra/admin/articles/_articles_index.html.erb +3 -3
- data/app/views/goldencobra/admin/articles/_image_module_sidebar.html.erb +19 -7
- data/app/views/goldencobra/admin/articles/_layout_sidebar.html.erb +2 -2
- data/app/views/goldencobra/admin/articles/_link_checker.html.erb +4 -4
- data/app/views/goldencobra/admin/articles/_link_checker_index.html.erb +1 -1
- data/app/views/goldencobra/admin/articles/_select_article_type.html.erb +8 -8
- data/app/views/goldencobra/admin/articles/_sort_articles_index.html.erb +1 -1
- data/app/views/goldencobra/admin/articles/_widgets_sidebar.html.erb +2 -2
- data/app/views/goldencobra/admin/articles/toggle_expert_mode.js.erb +2 -2
- data/app/views/goldencobra/admin/settings/_index.html.erb +14 -0
- data/app/views/goldencobra/admin/settings/_key_value.html.erb +12 -0
- data/app/views/goldencobra/admin/settings/_settings_group.html.erb +14 -0
- data/app/views/goldencobra/admin/shared/_help.html.erb +12 -10
- data/app/views/goldencobra/admin/shared/_item.html.erb +4 -4
- data/app/views/goldencobra/admin/shared/_overview.html.erb +14 -4
- data/app/views/goldencobra/admin/shared/load_overviewtree.js.erb +6 -0
- data/app/views/goldencobra/admin/uploads/_jcrop.html.erb +23 -0
- data/app/views/goldencobra/articles/_edit_article_link.html.erb +1 -1
- data/app/views/goldencobra/articles/show.rss.builder +5 -0
- data/app/views/goldencobra/articles/sitemap.xml.builder +15 -1
- data/app/views/goldencobra/manage/_admin_article_management.html.erb +1 -1
- data/app/views/goldencobra/manage/_admin_article_management_content.html.erb +4 -4
- data/app/views/goldencobra/manage/render_admin_menue.html.erb +1 -0
- data/app/views/goldencobra/manage/render_admin_menue.js.erb +0 -1
- data/app/views/goldencobra/sessions/_login.html.erb +4 -4
- data/app/views/goldencobra/sessions/_register.html.erb +6 -6
- data/app/views/layouts/goldencobra/active_admin_resque.html.erb +1 -1
- data/app/worker/articles_cache_worker.rb +1 -1
- data/config/initializers/check_for_missing_articletypes.rb +40 -37
- data/config/initializers/devise.rb +3 -1
- data/config/initializers/http_validator.rb +9 -2
- data/config/initializers/liquid_tags.rb +2 -2
- data/config/locales/active_admin.de.yml +509 -3
- data/config/locales/active_admin.en.yml +580 -64
- data/config/locales/de.yml +478 -4
- data/config/locales/en.yml +406 -10
- data/config/pre-commit.rb +3 -0
- data/config/routes.rb +12 -1
- data/config/settings.yml +51 -50
- data/db/migrate/20130114154115_add_sorter_to_goldencobra_permissions.rb +4 -1
- data/db/migrate/20140204221345_add_operator_to_goldencobra_permissions.rb +5 -0
- data/db/migrate/20140411152728_add_creator_id_to_goldencobra_articles.rb +5 -0
- data/db/migrate/20140505144517_add_taggingcounter.rb +15 -0
- data/db/migrate/20140603084537_add_domain_to_goldencobra_permissions.rb +7 -0
- data/db/migrate/20140615200342_resize_link_checkfield.rb +13 -0
- data/db/migrate/20140626135753_add_externalreferee_to_goldencobra_articles.rb +6 -0
- data/db/migrate/20140702103024_add_externaldate_to_goldencobra_articles.rb +5 -0
- data/db/migrate/20140702105550_add_remoteurl_to_goldencobra_uploads.rb +5 -0
- data/db/migrate/20140702142818_add_image_gallery_type_to_goldencobra_articles.rb +5 -0
- data/db/migrate/20140819101033_add_urlpath_to_goldencobra_articles.rb +5 -0
- data/db/migrate/20141009104216_set_db_and_tables_to_utf8.rb +20 -0
- data/db/migrate/20141104115144_create_goldencobra_redirectors.rb +15 -0
- data/db/migrate/20141112124531_add_globalsorting_to_goldencobra_articles.rb +7 -0
- data/db/migrate/20141124170930_add_indiex_to_gc.rb +26 -0
- data/db/migrate/20150115111024_create_goldencobra_article_authors.rb +28 -0
- data/db/migrate/20150115134707_add_remove_author_stuff.rb +11 -0
- data/db/migrate/20150417153454_add_status_to_goldencobra_vita_steps.rb +5 -0
- data/db/seeds.rb +4 -153
- data/lib/generators/goldencobra/articletype/templates/edit_index.html.erb +1 -1
- data/lib/generators/goldencobra/articletype/templates/initializer.rb +4 -2
- data/lib/generators/goldencobra/install_generator.rb +3 -0
- data/lib/generators/goldencobra/server_generator.rb +67 -0
- data/lib/generators/goldencobra/templates/active_admin.rb.erb +3 -0
- data/lib/generators/goldencobra/templates/robots.txt +5 -0
- data/lib/generators/goldencobra/templates/views/articletypes/default/_edit_index.html.erb +9 -0
- data/lib/generators/goldencobra/templates/views/articletypes/default/_edit_show.html.erb +0 -0
- data/lib/generators/goldencobra/templates/views/articletypes/default/_index.html.erb +31 -18
- data/lib/generators/goldencobra/templates/views/articletypes/default/_show.html.erb +22 -15
- data/lib/goldencobra/engine.rb +19 -3
- data/lib/goldencobra/version.rb +1 -1
- data/lib/tasks/article_cache.rake +19 -0
- data/lib/tasks/i18n.rake +1 -1
- data/lib/tasks/import.rake +31 -3
- data/lib/tasks/link_checker.rake +4 -2
- metadata +217 -23
- data/config/locales/activerecord.de.yml +0 -227
- data/config/locales/activerecord.en.yml +0 -148
- data/config/locales/devise.de.yml +0 -54
- data/config/locales/devise.en.yml +0 -57
- data/config/locales/formtastic.de.yml +0 -10
- data/config/locales/formtastic.en.yml +0 -10
- data/config/locales/goldencobra.de.yml +0 -40
- data/config/locales/goldencobra.en.yml +0 -3
@@ -4,6 +4,7 @@ module Goldencobra
|
|
4
4
|
class SessionsController < Goldencobra::ApplicationController
|
5
5
|
layout "application"
|
6
6
|
|
7
|
+
|
7
8
|
def login
|
8
9
|
@errors = []
|
9
10
|
if params[:usermodel] && params[:usermodel].constantize && params[:usermodel].constantize.present? && params[:usermodel].constantize.attribute_method?(:email)
|
@@ -20,6 +21,7 @@ module Goldencobra
|
|
20
21
|
@usermodel.sign_in_count = @usermodel.sign_in_count.to_i + 1
|
21
22
|
@usermodel.last_sign_in_at = Time.now
|
22
23
|
@usermodel.save
|
24
|
+
flash[:notice] = I18n.translate("signed_in", :scope => ["devise", "sessions"])
|
23
25
|
@redirect_to = @usermodel.roles.try(:first).try(:redirect_after_login)
|
24
26
|
else
|
25
27
|
@usermodel.failed_attempts = @usermodel.failed_attempts.to_i + 1
|
@@ -36,8 +38,13 @@ module Goldencobra
|
|
36
38
|
if params[:usermodel] && params[:usermodel].constantize && params[:usermodel].constantize.present? && params[:usermodel].constantize.attribute_method?(:email)
|
37
39
|
sign_out
|
38
40
|
reset_session
|
41
|
+
flash[:notice] = I18n.translate("signed_out", :scope => ["devise", "sessions"])
|
42
|
+
end
|
43
|
+
if request.format == "html"
|
44
|
+
redirect_to "/"
|
45
|
+
else
|
46
|
+
render :js => "window.location.href = '/';"
|
39
47
|
end
|
40
|
-
render :js => "window.location.href = '/';"
|
41
48
|
end
|
42
49
|
|
43
50
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module Goldencobra
|
2
4
|
module ApplicationHelper
|
3
5
|
include Goldencobra::ArticlesHelper
|
@@ -14,7 +16,7 @@ module Goldencobra
|
|
14
16
|
user_mod = Goldencobra::Setting.for_key("goldencobra.bugherd.user")
|
15
17
|
role_mod = Goldencobra::Setting.for_key("goldencobra.bugherd.role")
|
16
18
|
bugherd_api = Goldencobra::Setting.for_key("goldencobra.bugherd.api")
|
17
|
-
if bugherd_api.present? && user_mod.present? && role_mod.present? && eval("#{user_mod} && #{user_mod}.present? && #{user_mod}.has_role?('#{role_mod}')")
|
19
|
+
if bugherd_api.present? && user_mod.present? && role_mod.present? && eval("!defined?(#{user_mod}).nil? && #{user_mod} && #{user_mod}.present? && #{user_mod}.has_role?('#{role_mod}')")
|
18
20
|
render :partial => "goldencobra/articles/bugherd", :locals => {:bugherd_api => bugherd_api}
|
19
21
|
end
|
20
22
|
end
|
@@ -9,9 +9,9 @@ module Goldencobra
|
|
9
9
|
def read_on(article)
|
10
10
|
target_window = article.redirection_target_in_new_window ? "_blank" : "_top"
|
11
11
|
if article.redirect_link_title.present?
|
12
|
-
link_to article.redirect_link_title, article.external_url_redirect, :class =>
|
12
|
+
link_to article.redirect_link_title, article.external_url_redirect, :class => "more", :target => target_window
|
13
13
|
else
|
14
|
-
link_to t(:read_on, scope: [:articles]), article.public_url, :class =>
|
14
|
+
link_to t(:read_on, scope: [:articles]), article.public_url, :class => "more", :target => target_window, :title => article.title
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -72,10 +72,12 @@ module Goldencobra
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def render_article_type_content(options={})
|
75
|
-
if @article
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
if @article
|
76
|
+
if @article.article_type.present? && @article.kind_of_article_type.present?
|
77
|
+
render :partial => "articletypes/#{@article.article_type_form_file.underscore.parameterize.downcase}/#{@article.kind_of_article_type.downcase}"
|
78
|
+
else
|
79
|
+
render :partial => "articletypes/default/show"
|
80
|
+
end
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
@@ -90,8 +92,12 @@ module Goldencobra
|
|
90
92
|
#Wenn format email, dann gibt es keinen realen webseit besucher
|
91
93
|
ability = Ability.new()
|
92
94
|
else
|
93
|
-
|
94
|
-
|
95
|
+
if !defined?(current_user).nil? || !defined?(current_visitor).nil?
|
96
|
+
operator = current_user || current_visitor
|
97
|
+
ability = Ability.new(operator)
|
98
|
+
else
|
99
|
+
ability = Ability.new()
|
100
|
+
end
|
95
101
|
end
|
96
102
|
if @article
|
97
103
|
widgets = @article.widgets.active
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'logger'
|
3
|
+
module Goldencobra
|
4
|
+
class HandleInvalidPercentEncoding
|
5
|
+
DEFAULT_CONTENT_TYPE = 'text/html'
|
6
|
+
DEFAULT_CHARSET = 'utf-8'
|
7
|
+
|
8
|
+
attr_reader :logger
|
9
|
+
def initialize(app, stdout=STDOUT)
|
10
|
+
@app = app
|
11
|
+
@logger = defined?(Rails.logger) ? Rails.logger : Logger.new(stdout)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
begin
|
16
|
+
# calling env.dup here prevents bad things from happening
|
17
|
+
request = Rack::Request.new(env.dup)
|
18
|
+
# calling request.params is sufficient to trigger the error
|
19
|
+
# see https://github.com/rack/rack/issues/337#issuecomment-46453404
|
20
|
+
request.params
|
21
|
+
@app.call(env)
|
22
|
+
rescue ArgumentError => e
|
23
|
+
raise unless e.message =~ /invalid %-encoding/
|
24
|
+
message = "BAD REQUEST: Returning 400 due to #{e.message} from request with env #{request.inspect}"
|
25
|
+
logger.info message
|
26
|
+
content_type = env['HTTP_ACCEPT'] || DEFAULT_CONTENT_TYPE
|
27
|
+
status = 400
|
28
|
+
body = "Bad Request"
|
29
|
+
return [
|
30
|
+
status,
|
31
|
+
{
|
32
|
+
'Content-Type' => "#{content_type}; charset=#{DEFAULT_CHARSET}",
|
33
|
+
'Content-Length' => body.bytesize.to_s
|
34
|
+
},
|
35
|
+
[body]
|
36
|
+
]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/app/models/ability.rb
CHANGED
@@ -3,78 +3,73 @@
|
|
3
3
|
class Ability
|
4
4
|
include CanCan::Ability
|
5
5
|
|
6
|
-
def initialize(operator=nil)
|
6
|
+
def initialize(operator=nil,current_domain=nil)
|
7
7
|
can :read, Goldencobra::Article
|
8
8
|
can :read, Goldencobra::Menue
|
9
9
|
can :read, Goldencobra::Widget
|
10
10
|
|
11
11
|
#Rechte die alle betreffen
|
12
12
|
Goldencobra::Permission.where("action IS NOT NULL").where("role_id IS NULL OR role_id = ''").each do |permission|
|
13
|
-
|
14
|
-
if permission.action.include?("not_")
|
15
|
-
cannot permission.action.gsub("not_", "").to_sym, permission.subject_class.constantize
|
16
|
-
else
|
17
|
-
can permission.action.to_sym, permission.subject_class.constantize
|
18
|
-
end
|
19
|
-
else
|
20
|
-
if permission.action.include?("not_")
|
21
|
-
cannot permission.action.gsub("not_", "").to_sym, permission.subject_class.constantize, :id => permission.subject_id.to_i
|
22
|
-
set_child_permissions("cannot",permission.action.gsub("not_", "").to_sym, permission.subject_class.constantize,permission.subject_id.to_i)
|
23
|
-
else
|
24
|
-
can permission.action.to_sym, permission.subject_class.constantize, :id => permission.subject_id.to_i
|
25
|
-
set_child_permissions("can",permission.action.to_sym, permission.subject_class.constantize,permission.subject_id.to_i)
|
26
|
-
end
|
27
|
-
end
|
13
|
+
set_permission(permission,current_domain)
|
28
14
|
end
|
29
15
|
|
30
16
|
#Rechte, die nur bestimmte nutzerrollen betreffen
|
31
17
|
if operator && operator.respond_to?(:roles)
|
32
18
|
operator.roles.each do |role|
|
33
19
|
role.permissions.each do |permission|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
if !permission.subject_class.include?(":all") && permission.subject_id.blank?
|
44
|
-
if permission.action.include?("not_")
|
45
|
-
cannot permission.action.gsub("not_", "").to_sym, permission.subject_class.constantize
|
46
|
-
else
|
47
|
-
can permission.action.to_sym, permission.subject_class.constantize
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
if !permission.subject_class.include?(":all") && permission.subject_id.present?
|
52
|
-
if permission.action.include?("not_")
|
53
|
-
cannot permission.action.to_s.gsub("not_", "").to_sym, permission.subject_class.constantize, :id => permission.subject_id.to_i
|
54
|
-
set_child_permissions("cannot",permission.action.gsub("not_", "").to_sym, permission.subject_class.constantize,permission.subject_id.to_i)
|
20
|
+
if check_for_domain_restrictions(permission,current_domain)
|
21
|
+
if permission.subject_class == ":all"
|
22
|
+
if permission.action.include?("not_")
|
23
|
+
cannot permission.action.gsub("not_", "").to_sym, :all
|
24
|
+
else
|
25
|
+
can permission.action.to_sym, :all
|
26
|
+
end
|
55
27
|
else
|
56
|
-
|
57
|
-
set_child_permissions("can",permission.action.to_sym, permission.subject_class.constantize,permission.subject_id.to_i)
|
28
|
+
set_permission(permission,current_domain)
|
58
29
|
end
|
59
30
|
end
|
60
31
|
end
|
61
32
|
end
|
62
33
|
end
|
63
|
-
|
64
34
|
end
|
65
35
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
36
|
+
def set_permission(permission,current_domain)
|
37
|
+
able = 'can'
|
38
|
+
action_name = permission.action.to_sym
|
39
|
+
model_name = permission.subject_class.constantize
|
40
|
+
|
41
|
+
if permission.action.include?("not_")
|
42
|
+
action_name = permission.action.gsub("not_", "").to_sym
|
43
|
+
able = 'cannot'
|
44
|
+
end
|
45
|
+
|
46
|
+
if check_for_domain_restrictions(permission,current_domain)
|
47
|
+
if permission.subject_id.present?
|
48
|
+
set_ability(able, action_name, model_name, permission.subject_id.to_i)
|
49
|
+
set_child_permissions(able, action_name, model_name, permission.subject_id.to_i)
|
50
|
+
else
|
51
|
+
set_ability(able, action_name, model_name)
|
70
52
|
end
|
71
53
|
end
|
72
|
-
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_ability(able, action_name, model_name, id_name=nil)
|
57
|
+
if id_name.present?
|
58
|
+
send(able, action_name, model_name, id: id_name)
|
59
|
+
else
|
60
|
+
send(able, action_name, model_name)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_child_permissions(able, action_name, model_name,id_name)
|
65
|
+
if %w(can cannot).include?(able) && model_name.new.respond_to?(:descendant_ids) && object = model_name.find_by_id(id_name)
|
73
66
|
object.descendant_ids.each do |child_id|
|
74
|
-
|
67
|
+
set_ability(able, action_name, model_name, child_id)
|
75
68
|
end
|
76
69
|
end
|
77
|
-
|
78
70
|
end
|
79
71
|
|
80
|
-
|
72
|
+
def check_for_domain_restrictions(permission,domain)
|
73
|
+
permission.domain.blank? || (domain.present? && permission.domain.present? && permission.domain == domain)
|
74
|
+
end
|
75
|
+
end
|
@@ -53,16 +53,17 @@ require "open-uri"
|
|
53
53
|
|
54
54
|
module Goldencobra
|
55
55
|
class Article < ActiveRecord::Base
|
56
|
+
|
56
57
|
extend FriendlyId
|
57
58
|
MetatagNames = ["Title Tag", "Meta Description", "Keywords", "OpenGraph Title", "OpenGraph Description", "OpenGraph Type", "OpenGraph URL", "OpenGraph Image"]
|
58
59
|
LiquidParser = {}
|
59
|
-
SortOptions = ["Created_at", "Updated_at", "Random", "Alphabetically"]
|
60
|
+
SortOptions = ["Created_at", "Updated_at", "Random", "Alphabetically", "GlobalSortID"]
|
60
61
|
DynamicRedirectOptions = [[:false,"deaktiviert"],[:latest,"neuester Untereintrag"], [:oldest, "ältester Untereintrag"]]
|
61
62
|
DisplayIndexTypes = [["Einzelseiten", "show"],["Übersichtsseiten", "index"], ["Alle Seiten", "all"]]
|
62
|
-
attr_accessor :hint_label, :manual_article_sort
|
63
|
+
attr_accessor :hint_label, :manual_article_sort, :create_redirection
|
63
64
|
ImportDataFunctions = []
|
64
65
|
|
65
|
-
serialize :link_checker
|
66
|
+
serialize :link_checker#, Hash
|
66
67
|
|
67
68
|
has_many :metatags
|
68
69
|
has_many :images, :through => :article_images, :class_name => Goldencobra::Upload
|
@@ -73,14 +74,15 @@ module Goldencobra
|
|
73
74
|
has_many :comments, :class_name => Goldencobra::Comment
|
74
75
|
has_many :permissions, :class_name => Goldencobra::Permission, :foreign_key => "subject_id", :conditions => {:subject_class => "Goldencobra::Article"}
|
75
76
|
belongs_to :articletype, :class_name => Goldencobra::Articletype, :foreign_key => "article_type", :primary_key => "name"
|
77
|
+
belongs_to :creator, :class_name => User, :foreign_key => "creator_id"
|
76
78
|
|
77
|
-
|
79
|
+
has_many :article_authors
|
80
|
+
has_many :authors, :through => :article_authors
|
78
81
|
|
79
82
|
accepts_nested_attributes_for :metatags, :allow_destroy => true, :reject_if => proc { |attributes| attributes['value'].blank? }
|
80
83
|
accepts_nested_attributes_for :article_images, :allow_destroy => true
|
81
84
|
accepts_nested_attributes_for :images, :allow_destroy => true
|
82
85
|
accepts_nested_attributes_for :permissions, :allow_destroy => true
|
83
|
-
accepts_nested_attributes_for :author, :allow_destroy => true
|
84
86
|
|
85
87
|
acts_as_taggable_on :tags, :frontend_tags #https://github.com/mbleigh/acts-as-taggable-on
|
86
88
|
has_ancestry :orphan_strategy => :restrict
|
@@ -90,21 +92,26 @@ module Goldencobra
|
|
90
92
|
liquid_methods :title, :created_at, :updated_at, :subtitle, :context_info, :id, :frontend_tags
|
91
93
|
|
92
94
|
validates_presence_of :title, :article_type
|
93
|
-
validates_format_of :url_name, :with => /\A[\w
|
95
|
+
validates_format_of :url_name, :with => /\A[\w\-]+\Z/, allow_blank: true
|
94
96
|
validates_presence_of :breadcrumb, :on => :create
|
95
97
|
validates_length_of :breadcrumb, :within => 1..70, :on => :create
|
96
98
|
|
99
|
+
attr_protected :startpage
|
100
|
+
|
101
|
+
before_update :set_redirection_step_1
|
97
102
|
after_create :set_active_since
|
98
103
|
after_create :notification_event_create
|
104
|
+
after_create :cleanup_redirections
|
99
105
|
before_save :parse_image_gallery_tags
|
100
106
|
before_save :set_url_name_if_blank
|
101
107
|
before_save :set_standard_application_template
|
102
108
|
after_save :set_default_meta_opengraph_values
|
103
109
|
after_save :verify_existence_of_opengraph_image
|
104
110
|
after_update :notification_event_update
|
111
|
+
after_update :update_parent_article_etag
|
112
|
+
after_save :set_url_path
|
105
113
|
before_destroy :update_parent_article_etag
|
106
|
-
|
107
|
-
attr_protected :startpage
|
114
|
+
after_update :set_redirection_step_2
|
108
115
|
|
109
116
|
scope :robots_index, where(:robots_no_index => false)
|
110
117
|
scope :robots_no_index, where(:robots_no_index => true)
|
@@ -116,18 +123,20 @@ module Goldencobra
|
|
116
123
|
scope :parent_ids_in_eq, lambda { |art_id| subtree_of(art_id) }
|
117
124
|
scope :parent_ids_in, lambda { |art_id| subtree_of(art_id) }
|
118
125
|
scope :modified_since, lambda{ |date| where("updated_at > ?", Date.parse(date))}
|
119
|
-
scope :for_sitemap, where('dynamic_redirection = "false" AND ( external_url_redirect IS NULL OR external_url_redirect = "") AND active = 1 AND robots_no_index = 0')
|
126
|
+
scope :for_sitemap, includes(:images).where('dynamic_redirection = "false" AND ( external_url_redirect IS NULL OR external_url_redirect = "") AND active = 1 AND robots_no_index = 0')
|
120
127
|
scope :frontend_tag_name_contains, lambda{|tag_name| tagged_with(tag_name.split(","), :on => :frontend_tags)}
|
121
128
|
scope :tag_name_contains, lambda{|tag_name| tagged_with(tag_name.split(","), :on => :tags)}
|
122
129
|
if ActiveRecord::Base.connection.table_exists?("goldencobra_metatags")
|
123
130
|
scope :no_title_tag, where("goldencobra_articles.id NOT IN (?)", Goldencobra::Metatag.where(:name => "Title Tag").where("value IS NOT NULL AND value <> ''").pluck(:article_id).uniq)
|
124
131
|
scope :no_meta_description, where("goldencobra_articles.id NOT IN (?)", Goldencobra::Metatag.where(:name => "Meta Description").where("value IS NOT NULL AND value <> ''").pluck(:article_id).uniq)
|
125
132
|
end
|
133
|
+
scope :fulltext_contains, lambda{ |name| where("content LIKE '%#{name}%' OR teaser LIKE '%#{name}%' OR url_name LIKE '%#{name}%' OR subtitle LIKE '%#{name}%' OR summary LIKE '%#{name}%' OR context_info LIKE '%#{name}%' OR breadcrumb LIKE '%#{name}%'")}
|
126
134
|
|
127
135
|
search_methods :frontend_tag_name_contains
|
128
136
|
search_methods :tag_name_contains
|
129
137
|
search_methods :parent_ids_in
|
130
138
|
search_methods :parent_ids_in_eq
|
139
|
+
search_methods :fulltext_contains
|
131
140
|
|
132
141
|
if ActiveRecord::Base.connection.table_exists?("goldencobra_settings")
|
133
142
|
if Goldencobra::Setting.for_key("goldencobra.use_solr") == "true"
|
@@ -152,98 +161,6 @@ module Goldencobra
|
|
152
161
|
# **************************
|
153
162
|
# **************************
|
154
163
|
|
155
|
-
def parent_path
|
156
|
-
self.path.map(&:title).join(" / ")
|
157
|
-
end
|
158
|
-
|
159
|
-
#scope for index articles, display show articles, index articless or both articles of an current type
|
160
|
-
def self.articletype_for_index(current_article)
|
161
|
-
if current_article.display_index_types == "show"
|
162
|
-
articletype("#{current_article.article_type_form_file} Show")
|
163
|
-
elsif current_article.display_index_types == "index"
|
164
|
-
articletype("#{current_article.article_type_form_file} Index")
|
165
|
-
else
|
166
|
-
where("article_type = '#{current_article.article_type_form_file} Show' OR article_type = '#{current_article.article_type_form_file} Index'")
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def render_html(layoutfile="application", localparams={})
|
171
|
-
av = ActionView::Base.new(ActionController::Base.view_paths + ["#{::Goldencobra::Engine.root}/app/views/goldencobra/articles/"])
|
172
|
-
av.request = ActionDispatch::Request.new(Rack::MockRequest.env_for(self.public_url))
|
173
|
-
av.request["format"] = "text/html"
|
174
|
-
av.controller = Goldencobra::ArticlesController.new
|
175
|
-
av.controller.request = av.request
|
176
|
-
av.params.merge!(localparams[:params])
|
177
|
-
av.assign({:article => self})
|
178
|
-
html_to_render = av.render(template: "/goldencobra/articles/show.html.erb", :layout => "layouts/#{layoutfile}", :locals => localparams, :content_type => "text/html" )
|
179
|
-
return html_to_render
|
180
|
-
end
|
181
|
-
|
182
|
-
|
183
|
-
#get all links of a page and make a check for response status and time
|
184
|
-
def set_link_checker
|
185
|
-
links_to_check = []
|
186
|
-
status_for_links = {}
|
187
|
-
doc = Nokogiri::HTML(open(self.absolute_public_url))
|
188
|
-
#find all links and stylesheets
|
189
|
-
doc.css('a,link').each do |link|
|
190
|
-
if add_link_to_checklist(link, "href").present?
|
191
|
-
links_to_check << {"link" => add_link_to_checklist(link, "href"), "pos" => link.path}
|
192
|
-
end
|
193
|
-
end
|
194
|
-
#find all images and javascripts
|
195
|
-
doc.css('img,script').each do |link|
|
196
|
-
if add_link_to_checklist(link,"src").present?
|
197
|
-
links_to_check << {"link" => add_link_to_checklist(link,"src"), "pos" => link.path}
|
198
|
-
end
|
199
|
-
end
|
200
|
-
links_to_check = links_to_check.compact.delete_if{|a| a.blank?}
|
201
|
-
links_to_check.each_with_index do |linkpos|
|
202
|
-
status_for_links[linkpos["link"]] = {"position" => linkpos["pos"]}
|
203
|
-
begin
|
204
|
-
start = Time.now
|
205
|
-
response = open(linkpos["link"])
|
206
|
-
status_for_links[linkpos["link"]]["response_code"] = response.status[0]
|
207
|
-
status_for_links[linkpos["link"]]["response_time"] = Time.now - start
|
208
|
-
rescue Exception => e
|
209
|
-
status_for_links[linkpos["link"]]["response_code"] = "404"
|
210
|
-
status_for_links[linkpos["link"]]["response_error"] = e.to_s
|
211
|
-
end
|
212
|
-
end
|
213
|
-
self.link_checker = status_for_links
|
214
|
-
end
|
215
|
-
|
216
|
-
#helper method for finding links in html document
|
217
|
-
def add_link_to_checklist(link, src_type)
|
218
|
-
begin
|
219
|
-
if link.blank? || link[src_type].blank?
|
220
|
-
return nil
|
221
|
-
elsif link[src_type][0 .. 6] == "http://" || link[src_type][0 .. 6] == "https:/"
|
222
|
-
return "#{link[src_type]}"
|
223
|
-
elsif link[src_type] && link[src_type][0 .. 1] == "//"
|
224
|
-
return "http:/#{link[src_type][/.(.*)/m,1]}"
|
225
|
-
elsif link[src_type] && link[src_type][0] == "/"
|
226
|
-
return "#{Goldencobra::Setting.absolute_base_url}/#{link[src_type][/.(.*)/m,1]}"
|
227
|
-
elsif link[src_type] && !link[src_type].include?("mailto:")
|
228
|
-
return "#{self.absolute_public_url}/#{link[src_type]}"
|
229
|
-
end
|
230
|
-
rescue
|
231
|
-
return nil
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
def comments_of_subarticles
|
236
|
-
Goldencobra::Comment.where("article_id in (?)", self.subtree_ids)
|
237
|
-
end
|
238
|
-
|
239
|
-
def find_related_subarticle
|
240
|
-
if self.dynamic_redirection == "latest"
|
241
|
-
self.descendants.order("id DESC").first
|
242
|
-
else
|
243
|
-
self.descendants.order("id ASC").first
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
164
|
|
248
165
|
#Das ist der Titel, der verwendet wird, wenn daraus ein Menüpunkt erstellt werden soll.
|
249
166
|
#der menue.title hat folgende vorgaben: validates_format_of :title, :with => /^[\w\d\?\.\'\!\s&üÜöÖäÄß\-\:\,\"]+$/
|
@@ -255,7 +172,7 @@ module Goldencobra
|
|
255
172
|
#@article.image_standard @article.image_logo @article.image_logo_medium
|
256
173
|
def self.init_image_methods
|
257
174
|
if ActiveRecord::Base.connection.table_exists?("goldencobra_settings")
|
258
|
-
Goldencobra::Setting.for_key("goldencobra.article.image_positions").split(",").map(&:strip).each do |image_type|
|
175
|
+
Goldencobra::Setting.for_key("goldencobra.article.image_positions").to_s.split(",").map(&:strip).each do |image_type|
|
259
176
|
define_method "image_#{image_type.underscore}" do
|
260
177
|
self.image(image_type,"original")
|
261
178
|
end
|
@@ -312,66 +229,6 @@ module Goldencobra
|
|
312
229
|
end
|
313
230
|
end
|
314
231
|
|
315
|
-
def index_articles(current_operator=nil, user_frontend_tags=nil)
|
316
|
-
if self.article_for_index_id.blank?
|
317
|
-
#Index aller Artikel anzeigen
|
318
|
-
@list_of_articles = Goldencobra::Article.active.articletype_for_index(self)
|
319
|
-
else
|
320
|
-
#Index aller Artikel anzeigen, die Kinder sind von einem Bestimmten artikel
|
321
|
-
parent_article = Goldencobra::Article.find_by_id(self.article_for_index_id)
|
322
|
-
if parent_article
|
323
|
-
@list_of_articles = parent_article.descendants.active.articletype_for_index(self)
|
324
|
-
else
|
325
|
-
@list_of_articles = Goldencobra::Article.active.articletype_for_index(self)
|
326
|
-
end
|
327
|
-
end
|
328
|
-
#include related models
|
329
|
-
@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)
|
330
|
-
#get articles with tag
|
331
|
-
if self.index_of_articles_tagged_with.present?
|
332
|
-
@list_of_articles = @list_of_articles.tagged_with(self.index_of_articles_tagged_with.split(",").map{|t| t.strip}, on: :tags, any: true)
|
333
|
-
end
|
334
|
-
#get articles without tag
|
335
|
-
if self.not_tagged_with.present?
|
336
|
-
@list_of_articles = @list_of_articles.tagged_with(self.not_tagged_with.split(",").map{|t| t.strip}, :exclude => true, on: :tags)
|
337
|
-
end
|
338
|
-
#get_articles_by_frontend_tags
|
339
|
-
if user_frontend_tags.present?
|
340
|
-
@list_of_articles = @list_of_articles.tagged_with(user_frontend_tags, on: :frontend_tags, any: true)
|
341
|
-
end
|
342
|
-
#filter with permissions
|
343
|
-
@list_of_articles = filter_with_permissions(@list_of_articles,current_operator)
|
344
|
-
|
345
|
-
#sort list of articles
|
346
|
-
if self.sort_order.present?
|
347
|
-
if self.sort_order == "Random"
|
348
|
-
@list_of_articles = @list_of_articles.flatten.shuffle
|
349
|
-
elsif self.sort_order == "Alphabetical"
|
350
|
-
@list_of_articles = @list_of_articles.flatten.sort_by{|article| article.title }
|
351
|
-
elsif self.respond_to?(self.sort_order.downcase)
|
352
|
-
sort_order = self.sort_order.downcase
|
353
|
-
@list_of_articles = @list_of_articles.flatten.sort_by{|article| article.respond_to?(sort_order) ? article.send(sort_order) : article }
|
354
|
-
elsif self.sort_order.include?(".")
|
355
|
-
sort_order = self.sort_order.downcase.split(".")
|
356
|
-
@unsortable = @list_of_articles.flatten.select{|a| !a.respond_to_all?(self.sort_order) }
|
357
|
-
@list_of_articles = @list_of_articles.flatten.delete_if{|a| !a.respond_to_all?(self.sort_order) }
|
358
|
-
@list_of_articles = @list_of_articles.sort_by{|a| eval("a.#{self.sort_order}") }
|
359
|
-
if @unsortable.count > 0
|
360
|
-
@list_of_articles = @unsortable + @list_of_articles
|
361
|
-
@list_of_articles = @list_of_articles.flatten
|
362
|
-
end
|
363
|
-
end
|
364
|
-
if self.reverse_sort
|
365
|
-
@list_of_articles = @list_of_articles.reverse
|
366
|
-
end
|
367
|
-
end
|
368
|
-
if self.sorter_limit && self.sorter_limit > 0
|
369
|
-
@list_of_articles = @list_of_articles[0..self.sorter_limit-1]
|
370
|
-
end
|
371
|
-
|
372
|
-
return @list_of_articles
|
373
|
-
end
|
374
|
-
|
375
232
|
|
376
233
|
# Methode filtert die @list_of_articles.
|
377
234
|
# Rückgabewert: Ein Array all der Artikel, die der operator lesen darf.
|
@@ -410,22 +267,6 @@ module Goldencobra
|
|
410
267
|
end
|
411
268
|
end
|
412
269
|
|
413
|
-
def public_url(with_prefix=true)
|
414
|
-
if self.startpage
|
415
|
-
if with_prefix
|
416
|
-
return "#{Goldencobra::Domain.current.try(:url_prefix)}/"
|
417
|
-
else
|
418
|
-
return "/"
|
419
|
-
end
|
420
|
-
else
|
421
|
-
a_url = "/#{self.path.select([:ancestry, :url_name, :startpage]).map{|a| a.url_name if !a.startpage}.compact.join("/")}"
|
422
|
-
if with_prefix
|
423
|
-
return "#{Goldencobra::Domain.current.try(:url_prefix)}#{a_url}"
|
424
|
-
else
|
425
|
-
return a_url
|
426
|
-
end
|
427
|
-
end
|
428
|
-
end
|
429
270
|
|
430
271
|
def date_of_last_modified_child
|
431
272
|
if self.children.length > 0
|
@@ -439,31 +280,6 @@ module Goldencobra
|
|
439
280
|
end
|
440
281
|
end
|
441
282
|
|
442
|
-
def absolute_base_url
|
443
|
-
if Goldencobra::Setting.for_key("goldencobra.use_ssl") == "true"
|
444
|
-
"https://#{Goldencobra::Setting.for_key('goldencobra.url')}"
|
445
|
-
else
|
446
|
-
"http://#{Goldencobra::Setting.for_key('goldencobra.url')}"
|
447
|
-
end
|
448
|
-
end
|
449
|
-
|
450
|
-
def absolute_public_url
|
451
|
-
if Goldencobra::Setting.for_key("goldencobra.use_ssl") == "true"
|
452
|
-
"https://#{Goldencobra::Setting.for_key('goldencobra.url')}#{self.public_url}"
|
453
|
-
else
|
454
|
-
"http://#{Goldencobra::Setting.for_key('goldencobra.url')}#{self.public_url}"
|
455
|
-
end
|
456
|
-
end
|
457
|
-
|
458
|
-
def for_friendly_name
|
459
|
-
if self.url_name.present?
|
460
|
-
self.url_name
|
461
|
-
elsif self.breadcrumb.present?
|
462
|
-
self.breadcrumb
|
463
|
-
else
|
464
|
-
self.title
|
465
|
-
end
|
466
|
-
end
|
467
283
|
|
468
284
|
# Gibt Consultant | Subsidiary | etc. zurück je nach Seitentyp
|
469
285
|
def article_type_form_file
|
@@ -562,6 +378,116 @@ module Goldencobra
|
|
562
378
|
|
563
379
|
end
|
564
380
|
|
381
|
+
def author
|
382
|
+
self.try(:authors).try(:first)
|
383
|
+
end
|
384
|
+
|
385
|
+
# **************************
|
386
|
+
# **************************
|
387
|
+
# Index Methods
|
388
|
+
# **************************
|
389
|
+
# **************************
|
390
|
+
|
391
|
+
|
392
|
+
#scope for index articles, display show articles, index articless or both articles of an current type
|
393
|
+
def self.articletype_for_index(current_article)
|
394
|
+
if current_article.display_index_types == "show"
|
395
|
+
articletype("#{current_article.article_type_form_file} Show")
|
396
|
+
elsif current_article.display_index_types == "index"
|
397
|
+
articletype("#{current_article.article_type_form_file} Index")
|
398
|
+
else
|
399
|
+
where("article_type = '#{current_article.article_type_form_file} Show' OR article_type = '#{current_article.article_type_form_file} Index'")
|
400
|
+
end
|
401
|
+
end
|
402
|
+
|
403
|
+
def render_html(layoutfile="application", localparams={})
|
404
|
+
av = ActionView::Base.new(ActionController::Base.view_paths + ["#{::Goldencobra::Engine.root}/app/views/goldencobra/articles/"])
|
405
|
+
av.request = ActionDispatch::Request.new(Rack::MockRequest.env_for(self.public_url))
|
406
|
+
av.request["format"] = "text/html"
|
407
|
+
av.controller = Goldencobra::ArticlesController.new
|
408
|
+
av.controller.request = av.request
|
409
|
+
if localparams.present? && localparams[:params].present?
|
410
|
+
av.params.merge!(localparams[:params])
|
411
|
+
end
|
412
|
+
av.assign({:article => self})
|
413
|
+
html_to_render = av.render(template: "/goldencobra/articles/show.html.erb", :layout => "layouts/#{layoutfile}", :locals => localparams, :content_type => "text/html" )
|
414
|
+
return html_to_render
|
415
|
+
end
|
416
|
+
|
417
|
+
def comments_of_subarticles
|
418
|
+
Goldencobra::Comment.where("article_id in (?)", self.subtree_ids)
|
419
|
+
end
|
420
|
+
|
421
|
+
def find_related_subarticle
|
422
|
+
if self.dynamic_redirection == "latest"
|
423
|
+
self.descendants.order("id DESC").first
|
424
|
+
else
|
425
|
+
self.descendants.order("id ASC").first
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
|
430
|
+
def index_articles(current_operator=nil, user_frontend_tags=nil)
|
431
|
+
if self.article_for_index_id.blank?
|
432
|
+
#Index aller Artikel anzeigen
|
433
|
+
@list_of_articles = Goldencobra::Article.active.articletype_for_index(self)
|
434
|
+
else
|
435
|
+
#Index aller Artikel anzeigen, die Kinder sind von einem Bestimmten artikel
|
436
|
+
parent_article = Goldencobra::Article.find_by_id(self.article_for_index_id)
|
437
|
+
if parent_article
|
438
|
+
@list_of_articles = parent_article.descendants.active.articletype_for_index(self)
|
439
|
+
else
|
440
|
+
@list_of_articles = Goldencobra::Article.active.articletype_for_index(self)
|
441
|
+
end
|
442
|
+
end
|
443
|
+
#include related models
|
444
|
+
@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)
|
445
|
+
#get articles with tag
|
446
|
+
if self.index_of_articles_tagged_with.present?
|
447
|
+
@list_of_articles = @list_of_articles.tagged_with(self.index_of_articles_tagged_with.split(",").map{|t| t.strip}, on: :tags, any: true)
|
448
|
+
end
|
449
|
+
#get articles without tag
|
450
|
+
if self.not_tagged_with.present?
|
451
|
+
@list_of_articles = @list_of_articles.tagged_with(self.not_tagged_with.split(",").map{|t| t.strip}, :exclude => true, on: :tags)
|
452
|
+
end
|
453
|
+
#get_articles_by_frontend_tags
|
454
|
+
if user_frontend_tags.present?
|
455
|
+
@list_of_articles = @list_of_articles.tagged_with(user_frontend_tags, on: :frontend_tags, any: true)
|
456
|
+
end
|
457
|
+
#filter with permissions
|
458
|
+
@list_of_articles = filter_with_permissions(@list_of_articles,current_operator)
|
459
|
+
|
460
|
+
#sort list of articles
|
461
|
+
if self.sort_order.present?
|
462
|
+
if self.sort_order == "Random"
|
463
|
+
@list_of_articles = @list_of_articles.flatten.shuffle
|
464
|
+
elsif self.sort_order == "Alphabetically"
|
465
|
+
@list_of_articles = @list_of_articles.flatten.sort_by{ |article| article.title }
|
466
|
+
elsif self.sort_order == "GlobalSortID"
|
467
|
+
@list_of_articles = @list_of_articles.flatten.sort_by{ |article| article.try(:global_sorting_id) }
|
468
|
+
elsif self.respond_to?(self.sort_order.downcase)
|
469
|
+
sort_order = self.sort_order.downcase
|
470
|
+
@list_of_articles = @list_of_articles.flatten.sort_by{ |article| article.respond_to?(sort_order) ? article.send(sort_order) : article }
|
471
|
+
elsif self.sort_order.include?(".")
|
472
|
+
sort_order = self.sort_order.downcase.split(".")
|
473
|
+
@unsortable = @list_of_articles.flatten.select{|a| !a.respond_to_all?(self.sort_order) }
|
474
|
+
@list_of_articles = @list_of_articles.flatten.delete_if{|a| !a.respond_to_all?(self.sort_order) }
|
475
|
+
@list_of_articles = @list_of_articles.sort_by{|a| eval("a.#{self.sort_order}") }
|
476
|
+
if @unsortable.count > 0
|
477
|
+
@list_of_articles = @unsortable + @list_of_articles
|
478
|
+
@list_of_articles = @list_of_articles.flatten
|
479
|
+
end
|
480
|
+
end
|
481
|
+
if self.reverse_sort
|
482
|
+
@list_of_articles = @list_of_articles.reverse
|
483
|
+
end
|
484
|
+
end
|
485
|
+
if self.sorter_limit && self.sorter_limit > 0
|
486
|
+
@list_of_articles = @list_of_articles[0..self.sorter_limit-1]
|
487
|
+
end
|
488
|
+
|
489
|
+
return @list_of_articles
|
490
|
+
end
|
565
491
|
|
566
492
|
# **************************
|
567
493
|
# **************************
|
@@ -569,7 +495,64 @@ module Goldencobra
|
|
569
495
|
# **************************
|
570
496
|
# **************************
|
571
497
|
|
572
|
-
|
498
|
+
def cleanup_redirections
|
499
|
+
Goldencobra::Redirector.where(:source_url => self.absolute_public_url).destroy_all
|
500
|
+
end
|
501
|
+
|
502
|
+
#bevor ein Artikle gespeichert wird , wird ein redirector unvollständig erstellt
|
503
|
+
def set_redirection_step_1
|
504
|
+
#Wenn der Artikle vor mehr als 24 Stunden erstellt wurde und sich an der URL etwas verändert hat, dann eine Weiterleitung anlegen.
|
505
|
+
modified_hours_since = ((Time.now - self.created_at) / 1.hour).round
|
506
|
+
if !self.new_record? && (self.url_path_changed? || self.url_name_changed? || self.ancestry_changed?) && modified_hours_since > 24
|
507
|
+
#Erstelle Redirector nur mit source
|
508
|
+
if self.url_path_changed?
|
509
|
+
old_url = "#{self.absolute_base_url}#{Goldencobra::Domain.current.try(:url_prefix)}#{self.url_path_change[0]}"
|
510
|
+
else
|
511
|
+
old_url = "#{self.absolute_base_url}#{Goldencobra::Domain.current.try(:url_prefix)}#{self.url_path}"
|
512
|
+
end
|
513
|
+
r = Goldencobra::Redirector.find_or_create_by_source_url(old_url)
|
514
|
+
r.active = false
|
515
|
+
r.save
|
516
|
+
self.create_redirection = r.id
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
def set_redirection_step_2
|
521
|
+
if self.create_redirection.present? && self.create_redirection.to_i > 0
|
522
|
+
#Suche Redirector nur mit source und vervollständige ihn
|
523
|
+
Goldencobra::Redirector.where(:source_url => self.absolute_public_url).destroy_all
|
524
|
+
r = Goldencobra::Redirector.find_by_id(self.create_redirection)
|
525
|
+
if r.present?
|
526
|
+
r.target_url = self.absolute_public_url
|
527
|
+
r.active = true
|
528
|
+
r.save
|
529
|
+
custom_children = Goldencobra::Article.find_all_by_ancestry("#{self.ancestry}/#{self.id}")
|
530
|
+
if custom_children.any?
|
531
|
+
if custom_children.count < 30
|
532
|
+
# wenn es nur wenige Kinderartikel gibt, dann gleich direkt machen
|
533
|
+
custom_children.each do |d|
|
534
|
+
d.updated_at = Time.now
|
535
|
+
d.url_path = d.get_url_from_path
|
536
|
+
d.save
|
537
|
+
end
|
538
|
+
else
|
539
|
+
#Ansosnten einen Raketask damit starten
|
540
|
+
system("cd #{::Rails.root} && RAILS_ENV=#{::Rails.env} bundle exec rake article_cache:recreate ID=#{self.id} &")
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
def set_url_path
|
548
|
+
self.update_column(:url_path, self.get_url_from_path)
|
549
|
+
end
|
550
|
+
|
551
|
+
def get_url_from_path
|
552
|
+
"/#{self.path.select([:ancestry, :url_name, :startpage, :id]).map{|a| a.url_name if !a.startpage}.compact.join("/")}"
|
553
|
+
end
|
554
|
+
|
555
|
+
#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
|
573
556
|
def update_parent_article_etag
|
574
557
|
if self.parent.present?
|
575
558
|
self.parent.update_attributes(:updated_at => Time.now)
|
@@ -591,7 +574,7 @@ module Goldencobra
|
|
591
574
|
#meta_description = Goldencobra::Setting.for_key('goldencobra.page.default_meta_description_tag')
|
592
575
|
|
593
576
|
if self.teaser.present?
|
594
|
-
meta_description = remove_html_tags(self.teaser)
|
577
|
+
meta_description = remove_html_tags(self.teaser.truncate(200))
|
595
578
|
else
|
596
579
|
meta_description = self.content.present? ? remove_html_tags(self.content).truncate(200) : self.title
|
597
580
|
end
|
@@ -660,28 +643,26 @@ module Goldencobra
|
|
660
643
|
end
|
661
644
|
|
662
645
|
def set_standard_application_template
|
663
|
-
if
|
664
|
-
if self.
|
665
|
-
self.
|
666
|
-
|
667
|
-
|
646
|
+
if ActiveRecord::Base.connection.table_exists?("goldencobra_articles") && ActiveRecord::Base.connection.table_exists?("goldencobra_articletypes")
|
647
|
+
if self.template_file.blank?
|
648
|
+
if self.articletype.present? && self.articletype.default_template_file.present?
|
649
|
+
self.template_file = self.articletype.default_template_file
|
650
|
+
else
|
651
|
+
self.template_file = "application"
|
652
|
+
end
|
668
653
|
end
|
669
654
|
end
|
670
655
|
end
|
671
656
|
|
657
|
+
|
658
|
+
|
659
|
+
|
672
660
|
# **************************
|
673
661
|
# **************************
|
674
|
-
#
|
662
|
+
# URL and Redirection Methods
|
675
663
|
# **************************
|
676
664
|
# **************************
|
677
665
|
|
678
|
-
def self.active
|
679
|
-
Goldencobra::Article.where("active = 1 AND active_since < '#{Time.now.strftime('%Y-%m-%d %H:%M:%S ')}'")
|
680
|
-
end
|
681
|
-
|
682
|
-
def active?
|
683
|
-
self.active && self.active_since < Time.now.utc
|
684
|
-
end
|
685
666
|
|
686
667
|
def self.search_by_url(url)
|
687
668
|
article = nil
|
@@ -693,6 +674,82 @@ module Goldencobra
|
|
693
674
|
return article
|
694
675
|
end
|
695
676
|
|
677
|
+
|
678
|
+
def parent_path
|
679
|
+
self.path.map(&:title).join(" / ")
|
680
|
+
end
|
681
|
+
|
682
|
+
|
683
|
+
def public_url(with_prefix=true)
|
684
|
+
if self.startpage
|
685
|
+
if with_prefix
|
686
|
+
return "#{Goldencobra::Domain.current.try(:url_prefix)}/"
|
687
|
+
else
|
688
|
+
return "/"
|
689
|
+
end
|
690
|
+
else
|
691
|
+
|
692
|
+
#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
|
693
|
+
if self.url_path.blank? || self.url_path_changed? || self.url_name_changed? || self.ancestry_changed?
|
694
|
+
a_url = self.get_url_from_path
|
695
|
+
else
|
696
|
+
a_url = self.url_path
|
697
|
+
end
|
698
|
+
|
699
|
+
if with_prefix
|
700
|
+
return "#{Goldencobra::Domain.current.try(:url_prefix)}#{a_url}"
|
701
|
+
else
|
702
|
+
return a_url
|
703
|
+
end
|
704
|
+
end
|
705
|
+
end
|
706
|
+
|
707
|
+
|
708
|
+
def absolute_base_url
|
709
|
+
if Goldencobra::Setting.for_key("goldencobra.use_ssl") == "true"
|
710
|
+
"https://#{Goldencobra::Setting.for_key('goldencobra.url')}"
|
711
|
+
else
|
712
|
+
"http://#{Goldencobra::Setting.for_key('goldencobra.url')}"
|
713
|
+
end
|
714
|
+
end
|
715
|
+
|
716
|
+
|
717
|
+
def absolute_public_url
|
718
|
+
if Goldencobra::Setting.for_key("goldencobra.use_ssl") == "true"
|
719
|
+
"https://#{Goldencobra::Setting.for_key('goldencobra.url')}#{self.public_url}"
|
720
|
+
else
|
721
|
+
"http://#{Goldencobra::Setting.for_key('goldencobra.url')}#{self.public_url}"
|
722
|
+
end
|
723
|
+
end
|
724
|
+
|
725
|
+
|
726
|
+
def for_friendly_name
|
727
|
+
if self.url_name.present?
|
728
|
+
self.url_name
|
729
|
+
elsif self.breadcrumb.present?
|
730
|
+
self.breadcrumb
|
731
|
+
else
|
732
|
+
self.title
|
733
|
+
end
|
734
|
+
end
|
735
|
+
|
736
|
+
|
737
|
+
# **************************
|
738
|
+
# **************************
|
739
|
+
# Class Methods
|
740
|
+
# **************************
|
741
|
+
# **************************
|
742
|
+
|
743
|
+
def self.active
|
744
|
+
Goldencobra::Article.where("active = 1 AND active_since < '#{Time.now.strftime('%Y-%m-%d %H:%M:%S ')}'")
|
745
|
+
end
|
746
|
+
|
747
|
+
def active?
|
748
|
+
self.active && self.active_since < Time.now.utc
|
749
|
+
end
|
750
|
+
|
751
|
+
|
752
|
+
|
696
753
|
def self.load_liquid_methods(options={})
|
697
754
|
|
698
755
|
end
|
@@ -743,6 +800,23 @@ module Goldencobra
|
|
743
800
|
def self.templates_for_select
|
744
801
|
Dir.glob(File.join(::Rails.root, "app", "views", "layouts", "*.html.erb")).map{|a| File.basename(a, ".html.erb")}.delete_if{|a| a =~ /^_/ }
|
745
802
|
end
|
803
|
+
|
804
|
+
def self.simple_search(q)
|
805
|
+
self.active.search(:title_or_subtitle_or_url_name_or_content_or_summary_or_teaser_contains => q).relation.map {
|
806
|
+
|article|
|
807
|
+
{
|
808
|
+
:id => article.id,
|
809
|
+
:absolute_public_url => article.absolute_public_url,
|
810
|
+
:title => article ? article.title : '',
|
811
|
+
:teaser => article ? article.teaser : '',
|
812
|
+
:article_type => article.article_type,
|
813
|
+
:updated_at => article.updated_at,
|
814
|
+
:parent_title => article.parent ? article.parent.title ? article.parent.title : '' : '',
|
815
|
+
:ancestry => article.ancestry ? article.ancestry : ''
|
816
|
+
}
|
817
|
+
}
|
818
|
+
end
|
819
|
+
|
746
820
|
end
|
747
821
|
end
|
748
822
|
|