orange-more 0.5.8 → 0.6.0
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/lib/orange-more.rb +1 -7
- data/lib/orange-more/administration/cartons/user.rb +4 -1
- data/lib/orange-more/administration/middleware/access_control.rb +25 -13
- data/lib/orange-more/administration/middleware/site_load.rb +1 -1
- data/lib/orange-more/administration/resources/user_resource.rb +15 -1
- data/lib/orange-more/analytics/resources/analytics_resource.rb +2 -1
- data/lib/orange-more/assets/cartons/asset_carton.rb +26 -2
- data/lib/orange-more/assets/resources/asset_resource.rb +81 -15
- data/lib/orange-more/blog/cartons/blog_post.rb +3 -3
- data/lib/orange-more/contactforms/cartons/{contactforms_carton.rb → contactform_carton.rb} +2 -1
- data/lib/orange-more/contactforms/resources/contactforms_resource.rb +15 -13
- data/lib/orange-more/contactforms/views/contactforms/contactform.haml +1 -0
- data/lib/orange-more/debugger/assets/css/debug_bar.css +1 -0
- data/lib/orange-more/pages/resources/page_resource.rb +7 -0
- data/lib/orange-more/sitemap/resources/sitemap_resource.rb +6 -1
- data/lib/orange-more/slices/resources/slices.rb +9 -5
- metadata +6 -53
- data/lib/orange-more/adverts.rb +0 -1
- data/lib/orange-more/adverts/cartons/adverts_carton.rb +0 -14
- data/lib/orange-more/adverts/plugin.rb +0 -13
- data/lib/orange-more/adverts/resources/adverts_resource.rb +0 -27
- data/lib/orange-more/adverts/views/adverts/adverts.haml +0 -2
- data/lib/orange-more/donations.rb +0 -1
- data/lib/orange-more/donations/cartons/donation_carton.rb +0 -9
- data/lib/orange-more/donations/plugin.rb +0 -12
- data/lib/orange-more/donations/resources/donations_resource.rb +0 -51
- data/lib/orange-more/donations/views/donations/donate_form.haml +0 -21
- data/lib/orange-more/donations/views/donations/donate_thanks.haml +0 -2
- data/lib/orange-more/donations/views/donations/paypal_form.haml +0 -13
- data/lib/orange-more/events.rb +0 -1
- data/lib/orange-more/events/assets/js/events.js +0 -55
- data/lib/orange-more/events/cartons/orange_calendar.rb +0 -8
- data/lib/orange-more/events/cartons/orange_event.rb +0 -60
- data/lib/orange-more/events/plugin.rb +0 -14
- data/lib/orange-more/events/resources/calendar_resource.rb +0 -33
- data/lib/orange-more/events/resources/event_resource.rb +0 -147
- data/lib/orange-more/events/views/calendar/calendar.haml +0 -8
- data/lib/orange-more/events/views/events/create.haml +0 -55
- data/lib/orange-more/events/views/events/edit.haml +0 -59
- data/lib/orange-more/events/views/events/list.haml +0 -13
- data/lib/orange-more/events/views/events/show.haml +0 -4
- data/lib/orange-more/events/views/events/table_row.haml +0 -17
- data/lib/orange-more/members.rb +0 -1
- data/lib/orange-more/members/cartons/member_carton.rb +0 -38
- data/lib/orange-more/members/plugin.rb +0 -13
- data/lib/orange-more/members/resources/members_resource.rb +0 -327
- data/lib/orange-more/members/views/members/create.haml +0 -12
- data/lib/orange-more/members/views/members/edit.haml +0 -15
- data/lib/orange-more/members/views/members/live.show.haml +0 -1
- data/lib/orange-more/members/views/members/login.haml +0 -17
- data/lib/orange-more/members/views/members/logout.haml +0 -1
- data/lib/orange-more/members/views/members/profile.haml +0 -50
- data/lib/orange-more/members/views/members/register.haml +0 -37
- data/lib/orange-more/subsites.rb +0 -1
- data/lib/orange-more/subsites/cartons/subsite.rb +0 -8
- data/lib/orange-more/subsites/middleware/subsite_load.rb +0 -29
- data/lib/orange-more/subsites/plugin.rb +0 -17
- data/lib/orange-more/subsites/resources/subsite_resource.rb +0 -54
- data/lib/orange-more/subsites/views/subsites/index.haml +0 -2
- data/lib/orange-more/testimonials.rb +0 -1
- data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +0 -15
- data/lib/orange-more/testimonials/plugin.rb +0 -13
- data/lib/orange-more/testimonials/resources/testimonials_resource.rb +0 -42
- data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +0 -4
data/lib/orange-more.rb
CHANGED
|
@@ -11,13 +11,7 @@ require File.join(libdir, 'orange-more', 'slices')
|
|
|
11
11
|
require File.join(libdir, 'orange-more', 'blog')
|
|
12
12
|
require File.join(libdir, 'orange-more', 'news')
|
|
13
13
|
require File.join(libdir, 'orange-more', 'disqus')
|
|
14
|
-
require File.join(libdir, 'orange-more', 'testimonials')
|
|
15
|
-
require File.join(libdir, 'orange-more', 'adverts')
|
|
16
14
|
require File.join(libdir, 'orange-more', 'contactforms')
|
|
17
15
|
require File.join(libdir, 'orange-more', 'analytics')
|
|
18
|
-
require File.join(libdir, 'orange-more', 'donations')
|
|
19
16
|
require File.join(libdir, 'orange-more', 'cloud')
|
|
20
|
-
require File.join(libdir, 'orange-more', 'debugger')
|
|
21
|
-
require File.join(libdir, 'orange-more', 'subsites')
|
|
22
|
-
require File.join(libdir, 'orange-more', 'events')
|
|
23
|
-
require File.join(libdir, 'orange-more', 'members')
|
|
17
|
+
require File.join(libdir, 'orange-more', 'debugger')
|
|
@@ -33,6 +33,7 @@ module Orange::Middleware
|
|
|
33
33
|
|
|
34
34
|
def packet_call(packet)
|
|
35
35
|
packet['user.id'] ||= (packet.session['user.id'] || false)
|
|
36
|
+
packet['openid.profile'] ||= (packet.session['openid.profile'] || false)
|
|
36
37
|
packet['user'] = orange[:users].user_for(packet) unless packet['user.id'].blank?
|
|
37
38
|
if @openid && need_to_handle?(packet)
|
|
38
39
|
ret = handle_openid(packet)
|
|
@@ -56,26 +57,36 @@ module Orange::Middleware
|
|
|
56
57
|
|
|
57
58
|
def access_allowed?(packet)
|
|
58
59
|
return true unless @locked.include?(packet['route.context'])
|
|
59
|
-
if packet['user.id'] ||
|
|
60
|
-
if @single
|
|
61
|
-
true
|
|
62
|
-
elsif @single
|
|
60
|
+
if packet['user.id'] || orange.options['main_user'].blank?
|
|
61
|
+
if @single
|
|
62
|
+
return true if(main_user?(packet))
|
|
63
63
|
# Current id no good.
|
|
64
|
-
packet['user.id'] =
|
|
65
|
-
packet.session['user.id'] =
|
|
66
|
-
false
|
|
64
|
+
packet['user.id'] = nil
|
|
65
|
+
packet.session['user.id'] = nil
|
|
66
|
+
return false
|
|
67
67
|
# Main_user can always log in (root access)
|
|
68
|
-
elsif packet
|
|
68
|
+
elsif main_user?(packet)
|
|
69
69
|
orange[:users].new(packet, :open_id => packet['user.id'], :name => 'Main User') unless packet['user', false]
|
|
70
|
-
true
|
|
70
|
+
return true
|
|
71
71
|
else
|
|
72
|
-
orange[:users].access_allowed?(packet, packet['user.id'])
|
|
72
|
+
return orange[:users].access_allowed?(packet, packet['user.id'])
|
|
73
73
|
end
|
|
74
74
|
else
|
|
75
|
-
false
|
|
75
|
+
return false
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
+
def main_user?(packet)
|
|
80
|
+
id = packet['user.id'].gsub(/^https?:\/\//, '').gsub(/\/$/, '')
|
|
81
|
+
users = orange.options['main_users'] || []
|
|
82
|
+
users = users.dup.push(orange.options['main_user'])
|
|
83
|
+
users = users.flatten.compact
|
|
84
|
+
matches = users.select{|user|
|
|
85
|
+
(user == id) || (id == user.gsub(/^https?:\/\//, '').gsub(/\/$/, ''))
|
|
86
|
+
}
|
|
87
|
+
matches.length > 0 ? true : false
|
|
88
|
+
end
|
|
89
|
+
|
|
79
90
|
def need_to_handle?(packet)
|
|
80
91
|
@handle && ([@login, @logout].include? packet.request.path.gsub(/\/$/, ''))
|
|
81
92
|
end
|
|
@@ -108,13 +119,14 @@ module Orange::Middleware
|
|
|
108
119
|
profile_data.merge! data_response.from_success_response( resp ).data
|
|
109
120
|
end
|
|
110
121
|
end
|
|
111
|
-
|
|
122
|
+
packet.session['openid.profile'] = profile_data
|
|
123
|
+
packet['openid.profile'] = profile_data
|
|
112
124
|
if packet['user.id'] =~ /^https?:\/\/(www.)?google.com\/accounts/
|
|
113
125
|
packet['user.id'] = profile_data["http://axschema.org/contact/email"]
|
|
114
126
|
packet['user.id'] = packet['user.id'].first if packet['user.id'].kind_of?(Array)
|
|
115
127
|
end
|
|
116
128
|
|
|
117
|
-
if packet['user.id'] =~ /^https?:\/\/(www.)?yahoo.com/ || packet['user.id'] =~ /^https?:\/\/(me
|
|
129
|
+
if packet['user.id'] =~ /^https?:\/\/(www.)?yahoo.com/ || packet['user.id'] =~ /^https?:\/\/(my\.|me\.)?yahoo.com/
|
|
118
130
|
packet['user.id'] = profile_data["http://axschema.org/contact/email"]
|
|
119
131
|
packet['user.id'] = packet['user.id'].first if packet['user.id'].kind_of?(Array)
|
|
120
132
|
end
|
|
@@ -9,7 +9,7 @@ module Orange::Middleware
|
|
|
9
9
|
site = OrangeSite.first(:url.like => url)
|
|
10
10
|
if site
|
|
11
11
|
packet['site'] = site
|
|
12
|
-
elsif orange.options[:development_mode]
|
|
12
|
+
elsif orange.options[:development_mode] || OrangeSite.all.size == 0
|
|
13
13
|
s = OrangeSite.new({:url => packet['route.site_url'],
|
|
14
14
|
:name => 'An Orange Site'})
|
|
15
15
|
s.save
|
|
@@ -8,7 +8,21 @@ module Orange
|
|
|
8
8
|
|
|
9
9
|
def access_allowed?(packet, user)
|
|
10
10
|
u = model_class.first(:open_id => user)
|
|
11
|
-
|
|
11
|
+
unless u
|
|
12
|
+
users = model_class.all
|
|
13
|
+
# Deep open id search (take out trailing slash, etc.)
|
|
14
|
+
id = user.gsub(/^https?:\/\//, '').gsub(/\/$/, '')
|
|
15
|
+
matches = users.select{|u|
|
|
16
|
+
(id == u.open_id.gsub(/^https?:\/\//, '').gsub(/\/$/, ''))
|
|
17
|
+
}
|
|
18
|
+
if(matches.length > 0 && matches.first.allowed?(packet))
|
|
19
|
+
packet.session['user.id'] = matches.first.open_id
|
|
20
|
+
packet['user.id'] = matches.first.open_id
|
|
21
|
+
return true
|
|
22
|
+
else
|
|
23
|
+
return false
|
|
24
|
+
end
|
|
25
|
+
end
|
|
12
26
|
u.allowed?(packet)
|
|
13
27
|
end
|
|
14
28
|
|
|
@@ -6,6 +6,7 @@ module Orange
|
|
|
6
6
|
def stack_init
|
|
7
7
|
options[:email] = orange.options['ga_email']
|
|
8
8
|
options[:password] = orange.options['ga_password']
|
|
9
|
+
options[:profile] = orange.options['ga_profile']
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def gattica
|
|
@@ -23,7 +24,7 @@ module Orange
|
|
|
23
24
|
# authenticate with the API via email/password
|
|
24
25
|
ga = gattica
|
|
25
26
|
accounts = ga.accounts
|
|
26
|
-
ga.profile_id = accounts.first.profile_id
|
|
27
|
+
ga.profile_id = options[:profile] || accounts.first.profile_id
|
|
27
28
|
views = ""
|
|
28
29
|
data = ga.get({ :start_date => '2009-01-01',
|
|
29
30
|
:end_date => Time.now.localtime.strftime("%Y-%m-%d"),
|
|
@@ -10,9 +10,14 @@ class OrangeAsset < Orange::Carton
|
|
|
10
10
|
string :secondary_path, :length => 255, :required => false
|
|
11
11
|
string :secondary_mime_type
|
|
12
12
|
end
|
|
13
|
+
property :s3_bucket, String, :length => 64, :required => false
|
|
13
14
|
|
|
14
15
|
def file_path
|
|
15
|
-
|
|
16
|
+
if(s3_bucket)
|
|
17
|
+
"http://s3.amazonaws.com/#{s3_bucket}/#{path}"
|
|
18
|
+
else
|
|
19
|
+
File.join('', 'assets', 'uploaded', path)
|
|
20
|
+
end
|
|
16
21
|
end
|
|
17
22
|
|
|
18
23
|
def to_s
|
|
@@ -21,7 +26,26 @@ class OrangeAsset < Orange::Carton
|
|
|
21
26
|
DOC
|
|
22
27
|
end
|
|
23
28
|
|
|
29
|
+
def pdf?
|
|
30
|
+
mime_type =~ /^application\/pdf/
|
|
31
|
+
end
|
|
32
|
+
def image?
|
|
33
|
+
mime_type =~ /^image/
|
|
34
|
+
end
|
|
35
|
+
def file?
|
|
36
|
+
!(pdf? || image?)
|
|
37
|
+
end
|
|
38
|
+
|
|
24
39
|
def to_asset_tag(alt = "")
|
|
25
|
-
|
|
40
|
+
alt = alt.blank? ? caption : alt
|
|
41
|
+
alt = alt.blank? ? name : alt
|
|
42
|
+
case mime_type
|
|
43
|
+
when /^image/
|
|
44
|
+
"<img src='#{file_path}' border='0' alt='#{alt}' />"
|
|
45
|
+
when /^application\/pdf/
|
|
46
|
+
"<span class='pdf_link'><a href='#{file_path}'>#{alt}</a></span>"
|
|
47
|
+
else
|
|
48
|
+
"<span class='file_link'><a href='#{file_path}'>#{alt}</a></span>"
|
|
49
|
+
end
|
|
26
50
|
end
|
|
27
51
|
end
|
|
@@ -13,10 +13,21 @@ module Orange
|
|
|
13
13
|
call_me :assets
|
|
14
14
|
|
|
15
15
|
def stack_init
|
|
16
|
+
if orange.options[:s3_bucket]
|
|
17
|
+
require 'aws/s3'
|
|
18
|
+
options[:s3_bucket] = orange.options[:s3_bucket]
|
|
19
|
+
options[:s3_access_key_id] = orange.options[:s3_access_key_id]
|
|
20
|
+
options[:s3_secret_access_key] = orange.options[:s3_secret_access_key]
|
|
21
|
+
end
|
|
16
22
|
orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Assets')
|
|
17
23
|
orange[:radius, true].define_tag "asset" do |tag|
|
|
18
24
|
if tag.attr['id']
|
|
19
|
-
(m = model_class.first(:id => tag.attr['id'])) ? m.to_asset_tag : 'Invalid Asset'
|
|
25
|
+
ret = (m = model_class.first(:id => tag.attr['id'])) ? m.to_asset_tag : 'Invalid Asset'
|
|
26
|
+
if tag.attr['wrap']
|
|
27
|
+
ret = "<div class='#{tag.attr['wrap']}'>#{ret}</div>"
|
|
28
|
+
else
|
|
29
|
+
ret
|
|
30
|
+
end
|
|
20
31
|
else
|
|
21
32
|
''
|
|
22
33
|
end
|
|
@@ -42,31 +53,80 @@ module Orange
|
|
|
42
53
|
def onNew(packet, params = {})
|
|
43
54
|
m = false
|
|
44
55
|
if(file = params['file'][:tempfile])
|
|
45
|
-
file_path =
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
secondary_path = orange.app_dir('assets','uploaded', params['file2'][:filename])
|
|
56
|
+
file_path = handle_new_file(params['file'][:filename], file)
|
|
57
|
+
if(params['file2'] && secondary = params['file2'][:tempfile])
|
|
58
|
+
secondary_path = handle_new_file(params['file2'][:filename], secondary)
|
|
49
59
|
else
|
|
50
60
|
secondary_path = nil
|
|
51
61
|
end
|
|
52
|
-
# Move the files
|
|
53
|
-
FileUtils.cp(file.path, file_path)
|
|
54
|
-
FileUtils.chmod(0644, file_path)
|
|
55
|
-
FileUtils.cp(secondary.path, secondary_path) if secondary_path
|
|
56
|
-
FileUtils.chmod(0644, secondary_path) if secondary_path
|
|
57
62
|
|
|
58
|
-
params['path'] =
|
|
59
|
-
params['secondary_path'] =
|
|
63
|
+
params['path'] = file_path if file_path
|
|
64
|
+
params['secondary_path'] = secondary_path if secondary_path
|
|
60
65
|
params['mime_type'] = params['file'][:type] if file_path
|
|
61
66
|
params['secondary_mime_type'] = params['file2'][:type] if secondary_path
|
|
62
67
|
params.delete('file')
|
|
63
68
|
params.delete('file2')
|
|
64
|
-
|
|
69
|
+
params['s3_bucket'] = options[:s3_bucket] if options[:s3_bucket]
|
|
65
70
|
m = model_class.new(params)
|
|
66
71
|
end
|
|
67
72
|
m
|
|
68
73
|
end
|
|
69
74
|
|
|
75
|
+
def s3_connect!
|
|
76
|
+
if(options[:s3_bucket])
|
|
77
|
+
id = options[:s3_access_key_id] || ENV['S3_KEY']
|
|
78
|
+
secret = options[:s3_secret_access_key] || ENV['S3_SECRET']
|
|
79
|
+
AWS::S3::Base.establish_connection!(
|
|
80
|
+
:access_key_id => id,
|
|
81
|
+
:secret_access_key => secret
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def ensure_dir!
|
|
87
|
+
if(options[:s3_bucket])
|
|
88
|
+
AWS::S3::Bucket.create(options[:s3_bucket]) unless AWS::S3::Bucket.find(options[:s3_bucket])
|
|
89
|
+
else
|
|
90
|
+
FileUtils.mkdir_p(orange.app_dir('assets','uploaded')) unless File.exists?(orange.app_dir('assets','uploaded'))
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def handle_new_file(filename, file)
|
|
95
|
+
s3_connect!
|
|
96
|
+
ensure_dir!
|
|
97
|
+
if(options[:s3_bucket])
|
|
98
|
+
filename = unique_s3_name(filename)
|
|
99
|
+
AWS::S3::S3Object.store(filename, file, options[:s3_bucket], :access => :public_read)
|
|
100
|
+
else
|
|
101
|
+
filename = unique_local_name(filename)
|
|
102
|
+
FileUtils.cp(file.path, orange.app_dir('assets','uploaded', filename))
|
|
103
|
+
FileUtils.chmod(0644, orange.app_dir('assets','uploaded', filename))
|
|
104
|
+
end
|
|
105
|
+
return filename
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def unique_s3_name(filename)
|
|
109
|
+
return filename unless AWS::S3::S3Object.exists?(filename, options[:s3_bucket])
|
|
110
|
+
i = 1
|
|
111
|
+
extname = File.extname(filename)
|
|
112
|
+
basename = File.basename(filename, extname)
|
|
113
|
+
while AWS::S3::S3Object.exists?("#{basename}_#{i}#{extname}", options[:s3_bucket])
|
|
114
|
+
i += 1
|
|
115
|
+
end
|
|
116
|
+
"#{basename}_#{i}#{extname}"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def unique_local_name(filename)
|
|
120
|
+
return filename unless File.exists?(orange.app_dir('assets','uploaded', filename))
|
|
121
|
+
i = 1
|
|
122
|
+
extname = File.extname(filename)
|
|
123
|
+
basename = File.basename(filename, extname)
|
|
124
|
+
while File.exists?(orange.app_dir('assets', 'uploaded', "#{basename}_#{i}#{extname}"))
|
|
125
|
+
i += 1
|
|
126
|
+
end
|
|
127
|
+
"#{basename}_#{i}#{extname}"
|
|
128
|
+
end
|
|
129
|
+
|
|
70
130
|
# Creates a new model object and saves it (if a post), then reroutes to the main page
|
|
71
131
|
# @param [Orange::Packet] packet the packet being routed
|
|
72
132
|
def new(packet, opts = {})
|
|
@@ -98,8 +158,14 @@ module Orange
|
|
|
98
158
|
|
|
99
159
|
def onDelete(packet, m, opts = {})
|
|
100
160
|
begin
|
|
101
|
-
|
|
102
|
-
|
|
161
|
+
if(m.s3_bucket)
|
|
162
|
+
s3_connect!
|
|
163
|
+
AWS::S3::S3Object.delete(m.path, m.s3_bucket) if m.path
|
|
164
|
+
AWS::S3::S3Object.delete(m.secondary_path, m.s3_bucket) if m.secondary_path
|
|
165
|
+
else
|
|
166
|
+
FileUtils.rm(orange.app_dir('assets','uploaded', m.path)) if m.path
|
|
167
|
+
FileUtils.rm(orange.app_dir('assets','uploaded', m.secondary_path)) if m.secondary_path
|
|
168
|
+
end
|
|
103
169
|
rescue
|
|
104
170
|
# Problem deleting file
|
|
105
171
|
end
|
|
@@ -2,7 +2,7 @@ require 'dm-timestamps'
|
|
|
2
2
|
class OrangeBlogPost < Orange::Carton
|
|
3
3
|
id
|
|
4
4
|
front do
|
|
5
|
-
title :title
|
|
5
|
+
title :title, :length => 255
|
|
6
6
|
fulltext :body
|
|
7
7
|
end
|
|
8
8
|
admin do
|
|
@@ -10,7 +10,7 @@ class OrangeBlogPost < Orange::Carton
|
|
|
10
10
|
end
|
|
11
11
|
orange do
|
|
12
12
|
boolean :published, :default => false
|
|
13
|
-
text :slug
|
|
13
|
+
text :slug, :length => 255
|
|
14
14
|
text :author
|
|
15
15
|
end
|
|
16
16
|
|
|
@@ -21,7 +21,7 @@ class OrangeBlogPost < Orange::Carton
|
|
|
21
21
|
|
|
22
22
|
def title=(t)
|
|
23
23
|
self.attribute_set('title', t)
|
|
24
|
-
self.attribute_set('slug', t.downcase.gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "_"))
|
|
24
|
+
self.attribute_set('slug', t.downcase.gsub(/<\/?[^>]*>/, "").gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "_"))
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def published=(val)
|
|
@@ -2,20 +2,21 @@ require 'mail'
|
|
|
2
2
|
|
|
3
3
|
module Orange
|
|
4
4
|
class ContactFormsResource < Orange::ModelResource
|
|
5
|
-
use
|
|
5
|
+
use OrangeContactForm
|
|
6
6
|
call_me :contactforms
|
|
7
|
+
expose :mailer
|
|
7
8
|
def stack_init
|
|
8
9
|
orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Contact Forms')
|
|
9
10
|
orange[:radius].define_tag "contactform" do |tag|
|
|
10
|
-
|
|
11
|
+
if tag.attr["name"] && model_class.named(tag.attr["name"]).count >0
|
|
11
12
|
m = model_class.named(tag.attr["name"]).first #selects contactform based on title
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
elsif model_class.all.count > 0
|
|
14
|
+
if tag.attr["id"]
|
|
15
|
+
m = model_class.get(tag.attr["id"])
|
|
16
|
+
else
|
|
17
|
+
m = model_class.first
|
|
18
|
+
end
|
|
19
|
+
end
|
|
19
20
|
unless m.nil?
|
|
20
21
|
template = tag.attr["template"] || "contactform"
|
|
21
22
|
orange[:contactforms].contactform(tag.locals.packet, {:model => m, :template => template, :id => m.id})
|
|
@@ -34,17 +35,18 @@ module Orange
|
|
|
34
35
|
def mailer(packet, opts = {})
|
|
35
36
|
params = packet.request.params
|
|
36
37
|
route = params['r']
|
|
37
|
-
|
|
38
|
+
# The contact phone number is a honeypot field.
|
|
39
|
+
if params['contact_phone'] != '' || params['contact_from'].blank? || params['contact_email_address'].blank?
|
|
38
40
|
packet.flash['error'] = "An error has occurred. Please try your submission again."
|
|
39
41
|
packet.reroute(route)
|
|
40
42
|
end
|
|
41
|
-
path = packet['route.
|
|
43
|
+
path = packet['route.resource_path']
|
|
42
44
|
parts = path.split('/')
|
|
43
45
|
form = model_class.get(parts.last.to_i)
|
|
44
46
|
mail = Mail.new do
|
|
45
|
-
from
|
|
47
|
+
from "#{packet['site'].name} <#{form.from_address}>"
|
|
46
48
|
to form.to_address
|
|
47
|
-
subject
|
|
49
|
+
subject "E-mail contact from #{packet['site'].name}"
|
|
48
50
|
body "From: "+params['contact_from']+" ("+params['contact_email_address']+")\n\nMessage:\n"+params['contact_message']
|
|
49
51
|
end
|
|
50
52
|
mail.delivery_method :sendmail
|
|
@@ -64,6 +64,13 @@ module Orange
|
|
|
64
64
|
parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages", :orange_site_id => m.orange_site.id)
|
|
65
65
|
route_hash[:parent] = parents.first unless parents.blank?
|
|
66
66
|
orange[:sitemap].add_route_for(packet, route_hash)
|
|
67
|
+
elsif orange.loaded?(:sitemap)
|
|
68
|
+
r.each do |route|
|
|
69
|
+
if route.default_slug?
|
|
70
|
+
route.slug = orange[:sitemap].slug(m.title)
|
|
71
|
+
route.save
|
|
72
|
+
end
|
|
73
|
+
end
|
|
67
74
|
end
|
|
68
75
|
end
|
|
69
76
|
end
|