content_function.rb
6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
require 'cgi'
module Kanjai
module ContentFunction
def get_page_url
url = ''
req_url = request.original_fullpath if req_url.blank?
req_url = req_url.split('.')[0]
if req_url.split('?').length > 1
req_url = req_url.split('?')[0]
end
req_url.split('/').each {|item|
unless item.empty?
if /^[\d]+$/ === item
url += '/'
url += ':d'
elsif item.length == 2
#I18n.available_locales.collect{|locale| locale.to_s }.include?(item)
else
url += '/'
url += item
end
end
}
url = '/' if url.empty?
return url
end
=begin
def get_page_content(req_url = '', opts = nil)
lang = I18n.locale.to_s
content = {}
if @page
@page.contents.find(:all,:conditions => ['lang = ? and (hide = ? or hide is null)', lang, false], :order => 'position').each{|item|
if ContentPage.type?(item.name)
if(ContentPage.content_element(item.name)[:type] == 'plugin')
content[ContentPage.content_element(item.name)[:page_part]] ||= ''
content[ContentPage.content_element(item.name)[:page_part]] = content[ContentPage.content_element(item.name)[:page_part]] + (render_cell ContentPage.content_element(item.name)[:cells], ContentPage.content_element(item.name)[:action], {:content_id => item.id, :lang => lang, :host => request.host, :scheme => request.protocol.to_s.downcase, :params => params})
else
content_part = ContentPage.content_element(item.name)[:page_part]
content_part = 'default' if content_part.nil?
content[content_part] ||= ''
content[content_part] = content[content_part] + CGI.unescapeHTML(render_to_string :template => 'admin/contents/templates/' + item.name,:layout=>false,:locals=>{:content => item, :opts => opts})
end
end
}
end
content
end
def get_another_page_by_id(id)
lang = I18n.locale.to_s
if id.to_i > 0
page = Page.find_by_id(id.to_i)
if page
return page.page_datas.find_by_lang(lang)
end
end
end
def get_anather_page(url)
lang = I18n.locale.to_s
page = PageData.find_by_url(url).try(:page)
page.page_datas.find_by_lang(lang)
end
def get_another_page_content_by_id(id, opts = nil)
lang = I18n.locale.to_s
content = ''
if id.to_i > 0
@another_page = Page.find_by_id(id.to_i)
if @another_page
@another_page.contents.find(:all,:conditions => ['lang = ?', lang],:order => 'position').each{|item|
if ContentPage.type?(item.name)
if(ContentPage.content_element(item.name)[:type] == 'plugin')
content = content + (render_cell ContentPage.content_element(item.name)[:cells], ContentPage.content_element(item.name)[:action], {:content_id => item.id, :lang => lang, :host => request.host, :scheme => request.protocol.to_s.downcase, :params => params} )
else
content = content + CGI.unescapeHTML( (render_to_string :template => 'admin/contents/templates/' + item.name,:layout=>false,:locals=>{:content => item, :opts => opts}).to_str)
end
end
}
@page_data = @another_page.page_datas.find_by_lang(lang)
if @page_data
content = ("<div style='#{ @page_data.background_image_file_name.present? ? 'background:url(' + @page_data.background_image.expiring_url(ADMIN_CONFIG['expiring_time'],:original) + ') no-repeat top center' : '' }'>" + content + "</div>").html_safe
end
end
end
content
end
def get_another_page_content(url, opts = nil)
lang = I18n.locale.to_s
content = ''
@anather_page = PageData.find_by_url(url).try(:page)
if @anather_page
@anather_page.contents.find(:all,:conditions => ['lang = ?', lang],:order => 'position').each{|item|
if item.hide.nil? or item.hide == false
if ContentPage.type?(item.name)
if(ContentPage.content_element(item.name)[:type] == 'plugin')
content = content + (render_cell ContentPage.content_element(item.name)[:cells], ContentPage.content_element(item.name)[:action], {:content_id => item.id, :lang => lang, :host => request.host, :scheme => request.protocol.to_s.downcase, :params => params} )
else
content = content + CGI.unescapeHTML( (render_to_string :template => 'admin/contents/templates/' + item.name,:layout=>false,:locals=>{:content => item, :opts => opts}).to_str)
end
end
end
}
@page_data = @anather_page.page_datas.find_by_lang(lang)
if @page_data
content = ("<div style='#{ @page_data.background_image_file_name.present? ? 'background:url(' + @page_data.background_image.expiring_url(ADMIN_CONFIG['expiring_time'],:original) + ') no-repeat top center' : '' }'>" + content + "</div>").html_safe
end
end
content
end
def get_another_page_content2(url, opts = nil)
lang = I18n.locale.to_s
content = {}
@anather_page = PageData.find_by_url(url).try(:page)
if @anather_page
@anather_page.contents.find(:all,:conditions => ['lang = ?', lang],:order => 'position').each{|item|
if ContentPage.type?(item.name)
if(ContentPage.content_element(item.name)[:type] == 'plugin')
content[ContentPage.content_element(item.name)[:page_part]] ||= ''
content[ContentPage.content_element(item.name)[:page_part]] = content[ContentPage.content_element(item.name)[:page_part]] + (render_cell ContentPage.content_element(item.name)[:cells], ContentPage.content_element(item.name)[:action], {:content_id => item.id, :lang => lang, :host => request.host, :scheme => request.protocol.to_s.downcase, :params => params} )
else
content_part = ContentPage.content_element(item.name)[:page_part]
content_part = 'default' if content_part.nil?
content[content_part] ||= ''
content[content_part] = content[content_part] + CGI.unescapeHTML(render_to_string :template => 'admin/contents/templates/' + item.name,:layout=>false,:locals=>{:content => item, :opts => opts})
end
end
}
end
content
end
=end
end
end